Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

Region.cpp 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "resource/Region.h"
  19. #include "BinReader.h"
  20. #include "Core.h"
  21. #include "ResourceCache.h"
  22. static const uint32_t kRegionVersion = 3;
  23. static void readAlphaTex(BinReader& reader)
  24. {
  25. uint32_t numAlphaTex = reader.readInt();
  26. for(uint32_t i = 0; i < numAlphaTex; i++)
  27. {
  28. uint32_t tcode = reader.readInt();
  29. assert(tcode == 8 || tcode == 9 || tcode == 10);
  30. UNUSED(tcode);
  31. uint32_t texId = reader.readInt();
  32. assert((texId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kImgTex));
  33. UNUSED(texId);
  34. }
  35. }
  36. static void read(BinReader& reader, Region::SceneType& sceneType)
  37. {
  38. /*uint32_t sceneTypeUnk = */reader.readInt();
  39. uint32_t sceneCount = reader.readInt();
  40. sceneType.scenes.resize(sceneCount);
  41. for(ResourcePtr& scene : sceneType.scenes)
  42. {
  43. uint32_t resourceId = reader.readInt();
  44. assert((resourceId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kScene));
  45. scene = Core::get().resourceCache().get(resourceId);
  46. }
  47. }
  48. static void read(BinReader& reader, Region::TerrainType& terrainType)
  49. {
  50. string terrainName = reader.readString();
  51. /*terrainColor*/ reader.readInt();
  52. uint32_t numSceneTypes = reader.readInt();
  53. terrainType.sceneTypes.resize(numSceneTypes);
  54. for(uint32_t& sceneType : terrainType.sceneTypes)
  55. {
  56. sceneType = reader.readInt();
  57. }
  58. }
  59. static void read(BinReader& reader, Region::TerrainTex& terrainTex)
  60. {
  61. terrainTex.resourceId = reader.readInt();
  62. assert((terrainTex.resourceId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kImgTex));
  63. /*texTiling*/ reader.readInt();
  64. uint32_t maxVertBright = reader.readInt();
  65. uint32_t minVertBright = reader.readInt();
  66. assert(maxVertBright >= minVertBright);
  67. UNUSED(maxVertBright);
  68. UNUSED(minVertBright);
  69. uint32_t maxVertSaturate = reader.readInt();
  70. uint32_t minVertSaturate = reader.readInt();
  71. assert(maxVertSaturate >= minVertSaturate);
  72. UNUSED(maxVertSaturate);
  73. UNUSED(minVertSaturate);
  74. uint32_t maxVertHue = reader.readInt();
  75. uint32_t minVertHue = reader.readInt();
  76. assert(maxVertHue >= minVertHue);
  77. UNUSED(maxVertHue);
  78. UNUSED(minVertHue);
  79. /*detailTexTiling*/ reader.readInt();
  80. uint32_t detailTexId = reader.readInt();
  81. assert((detailTexId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kImgTex));
  82. UNUSED(detailTexId);
  83. }
  84. Region::Region(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  85. {
  86. BinReader reader(data, size);
  87. uint32_t resourceId = reader.readInt();
  88. assert(resourceId == id);
  89. UNUSED(resourceId);
  90. uint32_t regionNumber = reader.readInt();
  91. assert(regionNumber == 1);
  92. UNUSED(regionNumber);
  93. uint32_t regionVersion = reader.readInt();
  94. assert(regionVersion == kRegionVersion);
  95. UNUSED(regionVersion);
  96. string regionName = reader.readString();
  97. assert(regionName == "Dereth");
  98. uint32_t unk1 = reader.readInt();
  99. assert(unk1 == 0xFF);
  100. UNUSED(unk1);
  101. uint32_t unk2 = reader.readInt();
  102. assert(unk2 == 0xFF);
  103. UNUSED(unk2);
  104. reader.readRaw(24);
  105. // AC: LandDef's Land_Height_Table
  106. for(fp_t& height : landHeights)
  107. {
  108. height = reader.readFloat();
  109. }
  110. reader.readRaw(28);
  111. uint32_t numHours = reader.readInt();
  112. for(uint32_t i = 0; i < numHours; i++)
  113. {
  114. float startTime = reader.readFloat();
  115. assert(startTime >= 0.0 && startTime <= 1.0);
  116. UNUSED(startTime);
  117. uint32_t nightTime = reader.readInt();
  118. assert(nightTime == 0 || nightTime == 1);
  119. UNUSED(nightTime);
  120. string hourName = reader.readString();
  121. }
  122. uint32_t numHolidays = reader.readInt();
  123. for(uint32_t i = 0; i < numHolidays; i++)
  124. {
  125. string holidayName = reader.readString();
  126. }
  127. uint32_t numSeasons = reader.readInt();
  128. for(uint32_t i = 0; i < numSeasons; i++)
  129. {
  130. uint32_t startDay = reader.readInt();
  131. assert(startDay <= 365);
  132. UNUSED(startDay);
  133. string seasonName = reader.readString();
  134. }
  135. reader.readRaw(49400);
  136. // AC: CSceneDesc
  137. uint32_t numSceneTypes = reader.readInt();
  138. sceneTypes.resize(numSceneTypes);
  139. for(SceneType& sceneType : sceneTypes)
  140. {
  141. read(reader, sceneType);
  142. }
  143. // AC: CTerrainDesc
  144. uint32_t numTerrainTypes = reader.readInt();
  145. terrainTypes.resize(numTerrainTypes);
  146. for(TerrainType& terrainType : terrainTypes)
  147. {
  148. read(reader, terrainType);
  149. }
  150. uint32_t unk3 = reader.readInt();
  151. assert(unk3 == 0);
  152. UNUSED(unk3);
  153. uint32_t unk4 = reader.readInt();
  154. assert(unk4 == 0x400);
  155. UNUSED(unk4);
  156. readAlphaTex(reader);
  157. readAlphaTex(reader);
  158. readAlphaTex(reader);
  159. uint32_t numTerrainTex = reader.readInt();
  160. terrainTextures.resize(numTerrainTex);
  161. for(uint32_t i = 0; i < numTerrainTex; i++)
  162. {
  163. uint32_t terrainTexNum = reader.readInt();
  164. assert(terrainTexNum == i);
  165. UNUSED(terrainTexNum);
  166. read(reader, terrainTextures[i]);
  167. }
  168. uint32_t unk5 = reader.readInt();
  169. assert(unk5 == 1);
  170. UNUSED(unk5);
  171. /*smallMap*/ reader.readInt();
  172. /*largeMap*/ reader.readInt();
  173. reader.readRaw(12);
  174. assert(reader.remaining() == 0);
  175. }