map.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #include "stdafx.h"
  2. #include "map.h"
  3. int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4)
  4. {
  5. int ret=0;
  6. int amp=1;
  7. for (int i=0; i<bytCon; i++)
  8. {
  9. ret+=bufor[pos+i]*amp;
  10. amp<<=8;
  11. }
  12. return ret;
  13. }
  14. CMapHeader::CMapHeader(unsigned char *map)
  15. {
  16. this->version = (Eformat)map[0]; //wersja mapy
  17. this->areAnyPLayers = map[4]; //seems to be invalid
  18. this->height = this->width = map[5]; // wymiary mapy
  19. this->twoLevel = map[9]; //czy sa lochy
  20. int length = map[10]; //name length
  21. int i=14, pom;
  22. while (i-14<length) //read name
  23. this->name+=map[i++];
  24. length = map[i] + map[i+1]*256; //description length
  25. i+=4;
  26. for (pom=0;pom<length;pom++)
  27. this->description+=map[i++];
  28. this->difficulty = map[i++]; // reading map difficulty
  29. if(version!=Eformat::RoE)
  30. {
  31. this->levelLimit = map[i++]; // hero level limit
  32. }
  33. else
  34. {
  35. levelLimit = 0;
  36. }
  37. for (pom=0;pom<8;pom++)
  38. {
  39. this->players[pom].canHumanPlay = map[i++];
  40. this->players[pom].canComputerPlay = map[i++];
  41. if ((!(this->players[pom].canHumanPlay || this->players[pom].canComputerPlay)))
  42. {
  43. switch(version)
  44. {
  45. case Eformat::SoD: case Eformat::WoG:
  46. i+=13;
  47. break;
  48. case Eformat::AB:
  49. i+=12;
  50. break;
  51. case Eformat::RoE:
  52. i+=6;
  53. break;
  54. }
  55. continue;
  56. }
  57. this->players[pom].AITactic = map[i++];
  58. if(version == Eformat::SoD || version == Eformat::WoG)
  59. i++;
  60. this->players[pom].allowedFactions = 0;
  61. this->players[pom].allowedFactions += map[i++];
  62. if(version != Eformat::RoE)
  63. this->players[pom].allowedFactions += (map[i++])*256;
  64. this->players[pom].isFactionRandom = map[i++];
  65. this->players[pom].hasMainTown = map[i++];
  66. if (this->players[pom].hasMainTown)
  67. {
  68. if(version != Eformat::RoE)
  69. {
  70. this->players[pom].generateHeroAtMainTown = map[i++];
  71. this->players[pom].generateHero = map[i++];
  72. }
  73. this->players[pom].posOfMainTown.x = map[i++];
  74. this->players[pom].posOfMainTown.y = map[i++];
  75. this->players[pom].posOfMainTown.z = map[i++];
  76. }
  77. players[pom].p8= map[i++];
  78. players[pom].p9= map[i++];
  79. if(players[pom].p9!=0xff)
  80. {
  81. players[pom].mainHeroPortrait = map[i++];
  82. int nameLength = map[i++];
  83. i+=3;
  84. for (int pp=0;pp<nameLength;pp++)
  85. players[pom].mainHeroName+=map[i++];
  86. }
  87. if(version!=Eformat::RoE)
  88. {
  89. i++; ////heroes placeholders //domostwa
  90. int heroCount = map[i++];
  91. i+=3;
  92. for (int pp=0;pp<heroCount;pp++)
  93. {
  94. SheroName vv;
  95. vv.heroID=map[i++];
  96. int hnl = map[i++];
  97. i+=3;
  98. for (int zz=0;zz<hnl;zz++)
  99. {
  100. vv.heroName+=map[i++];
  101. }
  102. this->players[pom].heroesNames.push_back(vv);
  103. }
  104. }
  105. }
  106. this->victoryCondition = (EvictoryConditions)map[i++];
  107. if (this->victoryCondition != winStandard) //specific victory conditions
  108. {
  109. int nr;
  110. switch (this->victoryCondition) //read victory conditions
  111. {
  112. case artifact:
  113. {
  114. this->vicConDetails = new VicCon0();
  115. ((VicCon0*)this->vicConDetails)->ArtifactID = map[i+2];
  116. nr=(version==RoE ? 1 : 2);
  117. break;
  118. }
  119. case gatherTroop:
  120. {
  121. this->vicConDetails = new VicCon1();
  122. int temp1 = map[i+2];
  123. int temp2 = map[i+3];
  124. ((VicCon1*)this->vicConDetails)->monsterID = map[i+2];
  125. ((VicCon1*)this->vicConDetails)->neededQuantity=readNormalNr(map, i+(version==RoE ? 3 : 4));
  126. nr=(version==RoE ? 5 : 6);
  127. break;
  128. }
  129. case gatherResource:
  130. {
  131. this->vicConDetails = new VicCon2();
  132. ((VicCon2*)this->vicConDetails)->resourceID = map[i+2];
  133. ((VicCon2*)this->vicConDetails)->neededQuantity=readNormalNr(map, i+3);
  134. nr=5;
  135. break;
  136. }
  137. case buildCity:
  138. {
  139. this->vicConDetails = new VicCon3();
  140. ((VicCon3*)this->vicConDetails)->posOfCity.x = map[i+2];
  141. ((VicCon3*)this->vicConDetails)->posOfCity.y = map[i+3];
  142. ((VicCon3*)this->vicConDetails)->posOfCity.z = map[i+4];
  143. ((VicCon3*)this->vicConDetails)->councilNeededLevel = map[i+5];
  144. ((VicCon3*)this->vicConDetails)->fortNeededLevel = map[i+6];
  145. nr=5;
  146. break;
  147. }
  148. case buildGrail:
  149. {
  150. this->vicConDetails = new VicCon4();
  151. if (map[i+4]>2)
  152. ((VicCon4*)this->vicConDetails)->anyLocation = true;
  153. else
  154. {
  155. ((VicCon4*)this->vicConDetails)->whereBuildGrail.x = map[i+2];
  156. ((VicCon4*)this->vicConDetails)->whereBuildGrail.y = map[i+3];
  157. ((VicCon4*)this->vicConDetails)->whereBuildGrail.z = map[i+4];
  158. }
  159. nr=3;
  160. break;
  161. }
  162. case beatHero:
  163. {
  164. this->vicConDetails = new VicCon5();
  165. ((VicCon5*)this->vicConDetails)->locationOfHero.x = map[i+2];
  166. ((VicCon5*)this->vicConDetails)->locationOfHero.y = map[i+3];
  167. ((VicCon5*)this->vicConDetails)->locationOfHero.z = map[i+4];
  168. nr=3;
  169. break;
  170. }
  171. case captureCity:
  172. {
  173. this->vicConDetails = new VicCon6();
  174. ((VicCon6*)this->vicConDetails)->locationOfTown.x = map[i+2];
  175. ((VicCon6*)this->vicConDetails)->locationOfTown.y = map[i+3];
  176. ((VicCon6*)this->vicConDetails)->locationOfTown.z = map[i+4];
  177. nr=3;
  178. break;
  179. }
  180. case beatMonster:
  181. {
  182. this->vicConDetails = new VicCon7();
  183. ((VicCon7*)this->vicConDetails)->locationOfMonster.x = map[i+2];
  184. ((VicCon7*)this->vicConDetails)->locationOfMonster.y = map[i+3];
  185. ((VicCon7*)this->vicConDetails)->locationOfMonster.z = map[i+4];
  186. nr=3;
  187. break;
  188. }
  189. case takeDwellings:
  190. {
  191. this->vicConDetails = new CspecificVictoryConidtions();
  192. nr=3;
  193. break;
  194. }
  195. case takeMines:
  196. {
  197. this->vicConDetails = new CspecificVictoryConidtions();
  198. nr=3;
  199. break;
  200. }
  201. case transportItem:
  202. {
  203. this->vicConDetails = new VicCona();
  204. ((VicCona*)this->vicConDetails)->artifactID = map[i+2];
  205. ((VicCona*)this->vicConDetails)->destinationPlace.x = map[i+3];
  206. ((VicCona*)this->vicConDetails)->destinationPlace.y = map[i+4];
  207. ((VicCona*)this->vicConDetails)->destinationPlace.z = map[i+5];
  208. nr=4;
  209. break;
  210. }
  211. }
  212. this->vicConDetails->allowNormalVictory = map[i++];
  213. this->vicConDetails->appliesToAI = map[i++];
  214. i+=nr;
  215. }
  216. this->lossCondition.typeOfLossCon = (ElossCon)map[i++];
  217. switch (this->lossCondition.typeOfLossCon) //read loss conditions
  218. {
  219. case lossCastle:
  220. {
  221. this->lossCondition.castlePos.x=map[i++];
  222. this->lossCondition.castlePos.y=map[i++];
  223. this->lossCondition.castlePos.z=map[i++];
  224. }
  225. case lossHero:
  226. {
  227. this->lossCondition.heroPos.x=map[i++];
  228. this->lossCondition.heroPos.y=map[i++];
  229. this->lossCondition.heroPos.z=map[i++];
  230. }
  231. case timeExpires:
  232. {
  233. this->lossCondition.timeLimit = readNormalNr(map, i++,2);
  234. i++;
  235. }
  236. }
  237. this->howManyTeams=map[i++]; //read number of teams
  238. if(this->howManyTeams>0) //read team numbers
  239. {
  240. for(int rr=0; rr<8; ++rr)
  241. {
  242. this->players[rr].team=map[i++];
  243. }
  244. }
  245. }