map.cpp 6.6 KB

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