map.cpp 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941
  1. #define VCMI_DLL
  2. #include "stdafx.h"
  3. #include "map.h"
  4. #include "hch/CObjectHandler.h"
  5. #include "hch/CDefObjInfoHandler.h"
  6. #include "lib/VCMI_Lib.h"
  7. #include <zlib.h>
  8. #include <boost/crc.hpp>
  9. std::set<si32> convertBuildings(const std::set<si32> h3m, int castleID)
  10. {
  11. std::map<int,int> mapa;
  12. std::set<si32> ret;
  13. std::ifstream b5("config/buildings5.txt");
  14. while(!b5.eof())
  15. {
  16. int a, b;
  17. b5 >> a >> b;
  18. if(castleID==8 && b==17) //magic university ID 17 (h3m) => 21 (vcmi)
  19. b=21;
  20. mapa[a]=b;
  21. }
  22. for(std::set<si32>::const_iterator i=h3m.begin();i!=h3m.end();i++)
  23. {
  24. if(mapa[*i]>=0)
  25. ret.insert(mapa[*i]);
  26. else if(mapa[*i] >= (-CREATURES_PER_TOWN)) // horde buildings
  27. {
  28. int level = (-mapa[*i]);
  29. if(h3m.find(20+(level*3)) != h3m.end()) //upgraded creature horde building
  30. {
  31. if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5)))
  32. ret.insert(25);
  33. else
  34. ret.insert(19);
  35. }
  36. else
  37. {
  38. if(((castleID==1) || (castleID==3)) && ((level==3) || (level==5)))
  39. ret.insert(24);
  40. else
  41. ret.insert(18);
  42. }
  43. }
  44. else
  45. {
  46. tlog3<<"Conversion warning: unknown building "<<*i<<" in castle "<<castleID<<std::endl;
  47. }
  48. }
  49. ret.insert(10); //village hall is always present
  50. ret.insert(-1); //houses near v.hall / eyecandies
  51. ret.insert(-2); //terrain eyecandy, if -1 is used
  52. if(ret.find(11)!=ret.end())
  53. ret.insert(27);
  54. if(ret.find(12)!=ret.end())
  55. ret.insert(28);
  56. if(ret.find(13)!=ret.end())
  57. ret.insert(29);
  58. return ret;
  59. }
  60. unsigned int intPow(unsigned int a, unsigned int b)
  61. {
  62. unsigned int ret=1;
  63. for(int i=0; i<b; ++i)
  64. ret*=a;
  65. return ret;
  66. }
  67. unsigned char reverse(unsigned char arg)
  68. {
  69. unsigned char ret = 0;
  70. for (int i=0; i<8;i++)
  71. {
  72. if(((arg)&(1<<i))>>i)
  73. {
  74. ret |= (128>>i);
  75. }
  76. }
  77. return ret;
  78. }
  79. EDefType getDefType(CGDefInfo * a)
  80. {
  81. switch(a->id)
  82. {
  83. case 5: case 65: case 66: case 67: case 68: case 69:
  84. return ARTIFACT_DEF; //handled
  85. case 6:
  86. return PANDORA_DEF; //hanled
  87. case 26:
  88. return EVENTOBJ_DEF; //handled
  89. case 33:
  90. return GARRISON_DEF; //handled
  91. case 34: case 70: case 62: //70 - random hero //62 - prison
  92. return HERO_DEF; //handled
  93. case 36:
  94. return GRAIL_DEF; //hanled
  95. case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
  96. return PLAYERONLY_DEF; //handled
  97. case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
  98. return CREATURES_DEF; //handled
  99. case 59:
  100. return SIGN_DEF; //handled
  101. case 77:
  102. return TOWN_DEF; //can be problematic, but handled
  103. case 79: case 76:
  104. return RESOURCE_DEF; //handled
  105. case 81:
  106. return SCHOLAR_DEF; //handled
  107. case 83:
  108. return SEERHUT_DEF; //handled
  109. case 91:
  110. return SIGN_DEF; //handled
  111. case 88: case 89: case 90:
  112. return SHRINE_DEF; //handled
  113. case 93:
  114. return SPELLSCROLL_DEF; //handled
  115. case 98:
  116. return TOWN_DEF; //handled
  117. case 113:
  118. return WITCHHUT_DEF; //handled
  119. case 214:
  120. return HEROPLACEHOLDER_DEF; //partially handled
  121. case 215:
  122. return BORDERGUARD_DEF; //handled by analogy to seer huts ;]
  123. case 216:
  124. return CREGEN2_DEF; //handled
  125. case 217:
  126. return CREGEN_DEF; //handled
  127. case 218:
  128. return CREGEN3_DEF; //handled
  129. case 219:
  130. return GARRISON_DEF; //handled
  131. default:
  132. return TERRAINOBJ_DEF; // nothing to be handled
  133. }
  134. }
  135. int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4, bool cyclic = false)
  136. {
  137. int ret=0;
  138. int amp=1;
  139. for (int ir=0; ir<bytCon; ir++)
  140. {
  141. ret+=bufor[pos+ir]*amp;
  142. amp*=256;
  143. }
  144. if(cyclic && bytCon<4 && ret>=amp/2)
  145. {
  146. ret = ret-amp;
  147. }
  148. return ret;
  149. }
  150. char readChar(unsigned char * bufor, int &i)
  151. {
  152. return bufor[i++];
  153. }
  154. std::string readString(unsigned char * bufor, int &i)
  155. {
  156. int len = readNormalNr(bufor,i); i+=4;
  157. std::string ret; ret.reserve(len);
  158. for(int gg=0; gg<len; ++gg)
  159. {
  160. ret += bufor[i++];
  161. }
  162. return ret;
  163. }
  164. CCreatureSet readCreatureSet(unsigned char * bufor, int &i, int number, bool version) //version==true for >RoE maps
  165. {
  166. if(version)
  167. {
  168. CCreatureSet ret;
  169. std::pair<ui32,si32> ins;
  170. for(int ir=0;ir<number;ir++)
  171. {
  172. int rettt = readNormalNr(bufor,i+ir*4, 2);
  173. if(rettt==0xffff) continue;
  174. if(rettt>32768)
  175. rettt = 65536-rettt+VLC->creh->creatures.size()-16;
  176. ins.first = rettt;
  177. ins.second = readNormalNr(bufor,i+ir*4+2, 2);
  178. std::pair<si32,std::pair<ui32,si32> > tt(ir,ins);
  179. ret.slots.insert(tt);
  180. }
  181. i+=number*4;
  182. return ret;
  183. }
  184. else
  185. {
  186. CCreatureSet ret;
  187. std::pair<ui32,si32> ins;
  188. for(int ir=0;ir<number;ir++)
  189. {
  190. int rettt = readNormalNr(bufor,i+ir*3, 1);
  191. if(rettt==0xff) continue;
  192. if(rettt>220)
  193. rettt = 256-rettt+VLC->creh->creatures.size()-16;
  194. ins.first = rettt;
  195. ins.second = readNormalNr(bufor,i+ir*3+1, 2);
  196. std::pair<si32,std::pair<ui32,si32> > tt(ir,ins);
  197. ret.slots.insert(tt);
  198. }
  199. i+=number*3;
  200. return ret;
  201. }
  202. }
  203. CMapHeader::CMapHeader(unsigned char *map)
  204. {
  205. int i=0;
  206. initFromMemory(map,i);
  207. }
  208. CMapHeader::CMapHeader()
  209. {
  210. areAnyPLayers = difficulty = levelLimit = howManyTeams = 0;
  211. height = width = twoLevel = -1;
  212. }
  213. void CMapHeader::initFromMemory( unsigned char *bufor, int &i )
  214. {
  215. version = (Eformat)(readNormalNr(bufor,i)); i+=4; //map version
  216. areAnyPLayers = readChar(bufor,i); //invalid on some maps
  217. height = width = (readNormalNr(bufor,i)); i+=4; // wymiary mapy
  218. twoLevel = readChar(bufor,i); //czy sa lochy
  219. int pom;
  220. name = readString(bufor,i);
  221. description= readString(bufor,i);
  222. difficulty = readChar(bufor,i); // reading map difficulty
  223. if(version != RoE)
  224. levelLimit = readChar(bufor,i); // hero level limit
  225. else
  226. levelLimit = 0;
  227. loadPlayerInfo(pom, bufor, i);
  228. loadViCLossConditions(bufor, i);
  229. howManyTeams=bufor[i++]; //read number of teams
  230. if(howManyTeams>0) //read team numbers
  231. {
  232. for(int rr=0; rr<8; ++rr)
  233. {
  234. players[rr].team=bufor[i++];
  235. }
  236. }
  237. }
  238. void CMapHeader::loadPlayerInfo( int &pom, unsigned char * bufor, int &i )
  239. {
  240. players.resize(8);
  241. for (pom=0;pom<8;pom++)
  242. {
  243. players[pom].canHumanPlay = bufor[i++];
  244. players[pom].canComputerPlay = bufor[i++];
  245. if ((!(players[pom].canHumanPlay || players[pom].canComputerPlay)))
  246. {
  247. memset(&players[pom],0,sizeof(PlayerInfo));
  248. switch(version)
  249. {
  250. case SoD: case WoG:
  251. i+=13;
  252. break;
  253. case AB:
  254. i+=12;
  255. break;
  256. case RoE:
  257. i+=6;
  258. break;
  259. }
  260. continue;
  261. }
  262. players[pom].AITactic = bufor[i++];
  263. if(version == SoD || version == WoG)
  264. players[pom].p7= bufor[i++];
  265. else
  266. players[pom].p7= -1;
  267. players[pom].allowedFactions = 0;
  268. players[pom].allowedFactions += bufor[i++];
  269. if(version != RoE)
  270. players[pom].allowedFactions += (bufor[i++])*256;
  271. players[pom].isFactionRandom = bufor[i++];
  272. players[pom].hasMainTown = bufor[i++];
  273. if (players[pom].hasMainTown)
  274. {
  275. if(version != RoE)
  276. {
  277. players[pom].generateHeroAtMainTown = bufor[i++];
  278. players[pom].generateHero = bufor[i++];
  279. }
  280. else
  281. {
  282. players[pom].generateHeroAtMainTown = false;
  283. players[pom].generateHero = false;
  284. }
  285. players[pom].posOfMainTown.x = bufor[i++];
  286. players[pom].posOfMainTown.y = bufor[i++];
  287. players[pom].posOfMainTown.z = bufor[i++];
  288. }
  289. players[pom].p8= bufor[i++];
  290. players[pom].p9= bufor[i++];
  291. if(players[pom].p9!=0xff)
  292. {
  293. players[pom].mainHeroPortrait = bufor[i++];
  294. int nameLength = bufor[i++];
  295. i+=3;
  296. for (int pp=0;pp<nameLength;pp++)
  297. players[pom].mainHeroName+=bufor[i++];
  298. }
  299. if(version != RoE)
  300. {
  301. i++; ////unknown byte
  302. int heroCount = bufor[i++];
  303. i+=3;
  304. for (int pp=0;pp<heroCount;pp++)
  305. {
  306. SheroName vv;
  307. vv.heroID=bufor[i++];
  308. int hnl = bufor[i++];
  309. i+=3;
  310. for (int zz=0;zz<hnl;zz++)
  311. {
  312. vv.heroName+=bufor[i++];
  313. }
  314. players[pom].heroesNames.push_back(vv);
  315. }
  316. }
  317. }
  318. }
  319. void CMapHeader::loadViCLossConditions( unsigned char * bufor, int &i)
  320. {
  321. victoryCondition.condition = (EvictoryConditions)bufor[i++];
  322. if (victoryCondition.condition != winStandard) //specific victory conditions
  323. {
  324. int nr;
  325. switch (victoryCondition.condition) //read victory conditions
  326. {
  327. case artifact:
  328. {
  329. victoryCondition.ID = bufor[i+2];
  330. nr=(version==RoE ? 1 : 2);
  331. break;
  332. }
  333. case gatherTroop:
  334. {
  335. int temp1 = bufor[i+2];
  336. int temp2 = bufor[i+3];
  337. victoryCondition.ID = bufor[i+2];
  338. victoryCondition.count = readNormalNr(bufor, i+(version==RoE ? 3 : 4));
  339. nr=(version==RoE ? 5 : 6);
  340. break;
  341. }
  342. case gatherResource:
  343. {
  344. victoryCondition.ID = bufor[i+2];
  345. victoryCondition.count = readNormalNr(bufor, i+3);
  346. nr=5;
  347. break;
  348. }
  349. case buildCity:
  350. {
  351. victoryCondition.pos.x = bufor[i+2];
  352. victoryCondition.pos.y = bufor[i+3];
  353. victoryCondition.pos.z = bufor[i+4];
  354. victoryCondition.count = bufor[i+5];
  355. victoryCondition.ID = bufor[i+6];
  356. nr=5;
  357. break;
  358. }
  359. case buildGrail:
  360. {
  361. if (bufor[i+4]>2)
  362. victoryCondition.pos = int3(-1,-1,-1);
  363. else
  364. {
  365. victoryCondition.pos.x = bufor[i+2];
  366. victoryCondition.pos.y = bufor[i+3];
  367. victoryCondition.pos.z = bufor[i+4];
  368. }
  369. nr=3;
  370. break;
  371. }
  372. case beatHero:
  373. case captureCity:
  374. case beatMonster:
  375. {
  376. victoryCondition.pos.x = bufor[i+2];
  377. victoryCondition.pos.y = bufor[i+3];
  378. victoryCondition.pos.z = bufor[i+4];
  379. nr=3;
  380. break;
  381. }
  382. case takeDwellings:
  383. case takeMines:
  384. {
  385. nr=3;
  386. break;
  387. }
  388. case transportItem:
  389. {
  390. victoryCondition.ID = bufor[i+2];
  391. victoryCondition.pos.x = bufor[i+3];
  392. victoryCondition.pos.y = bufor[i+4];
  393. victoryCondition.pos.z = bufor[i+5];
  394. nr=4;
  395. break;
  396. }
  397. }
  398. victoryCondition.allowNormalVictory = bufor[i++];
  399. victoryCondition.appliesToAI = bufor[i++];
  400. i+=nr;
  401. }
  402. lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
  403. switch (lossCondition.typeOfLossCon) //read loss conditions
  404. {
  405. case lossCastle:
  406. {
  407. lossCondition.castlePos.x=bufor[i++];
  408. lossCondition.castlePos.y=bufor[i++];
  409. lossCondition.castlePos.z=bufor[i++];
  410. break;
  411. }
  412. case lossHero:
  413. {
  414. lossCondition.heroPos.x=bufor[i++];
  415. lossCondition.heroPos.y=bufor[i++];
  416. lossCondition.heroPos.z=bufor[i++];
  417. break;
  418. }
  419. case timeExpires:
  420. {
  421. lossCondition.timeLimit = readNormalNr(bufor,i++,2);
  422. i++;
  423. break;
  424. }
  425. }
  426. }
  427. void Mapa::initFromBytes(unsigned char * bufor)
  428. {
  429. int i=0;
  430. initFromMemory(bufor,i);
  431. timeHandler th;
  432. th.getDif();
  433. readHeader(bufor, i);
  434. tlog0<<"\tReading header: "<<th.getDif()<<std::endl;
  435. readRumors(bufor, i);
  436. tlog0<<"\tReading rumors: "<<th.getDif()<<std::endl;
  437. readPredefinedHeroes(bufor, i);
  438. tlog0<<"\tReading predefined heroes: "<<th.getDif()<<std::endl;
  439. readTerrain(bufor, i);
  440. tlog0<<"\tReading terrain: "<<th.getDif()<<std::endl;
  441. readDefInfo(bufor, i);
  442. tlog0<<"\tReading defs info: "<<th.getDif()<<std::endl;
  443. readObjects(bufor, i);
  444. tlog0<<"\tReading objects: "<<th.getDif()<<std::endl;
  445. readEvents(bufor, i);
  446. tlog0<<"\tReading events: "<<th.getDif()<<std::endl;
  447. //map readed, bufor no longer needed
  448. for(int f=0; f<objects.size(); ++f) //calculationg blocked / visitable positions
  449. {
  450. if(!objects[f]->defInfo)
  451. continue;
  452. addBlockVisTiles(objects[f]);
  453. }
  454. tlog0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl;
  455. }
  456. void Mapa::removeBlockVisTiles(CGObjectInstance * obj)
  457. {
  458. for(int fx=0; fx<8; ++fx)
  459. {
  460. for(int fy=0; fy<6; ++fy)
  461. {
  462. int xVal = obj->pos.x + fx - 7;
  463. int yVal = obj->pos.y + fy - 5;
  464. int zVal = obj->pos.z;
  465. if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
  466. {
  467. TerrainTile & curt = terrain[xVal][yVal][zVal];
  468. if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
  469. {
  470. curt.visitableObjects -= obj;
  471. curt.visitable = curt.visitableObjects.size();
  472. }
  473. if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
  474. {
  475. curt.blockingObjects -= obj;
  476. curt.blocked = curt.blockingObjects.size();
  477. }
  478. }
  479. }
  480. }
  481. }
  482. void Mapa::addBlockVisTiles(CGObjectInstance * obj)
  483. {
  484. for(int fx=0; fx<8; ++fx)
  485. {
  486. for(int fy=0; fy<6; ++fy)
  487. {
  488. int xVal = obj->pos.x + fx - 7;
  489. int yVal = obj->pos.y + fy - 5;
  490. int zVal = obj->pos.z;
  491. if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
  492. {
  493. TerrainTile & curt = terrain[xVal][yVal][zVal];
  494. if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
  495. {
  496. curt.visitableObjects.push_back(obj);
  497. curt.visitable = true;
  498. }
  499. if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
  500. {
  501. curt.blockingObjects.push_back(obj);
  502. curt.blocked = true;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. Mapa::Mapa(std::string filename)
  509. {
  510. tlog0<<"Opening map file: "<<filename<<"\t "<<std::flush;
  511. gzFile map = gzopen(filename.c_str(),"rb");
  512. std::vector<unsigned char> mapstr; int pom;
  513. while((pom=gzgetc(map))>=0)
  514. {
  515. mapstr.push_back(pom);
  516. }
  517. gzclose(map);
  518. unsigned char *initTable = new unsigned char[mapstr.size()];
  519. for(int ss=0; ss<mapstr.size(); ++ss)
  520. {
  521. initTable[ss] = mapstr[ss];
  522. }
  523. tlog0<<"done."<<std::endl;
  524. boost::crc_32_type result;
  525. result.process_bytes(initTable,mapstr.size());
  526. checksum = result.checksum();
  527. tlog0 << "\tOur map checksum: "<<result.checksum() << std::endl;
  528. initFromBytes(initTable);
  529. delete [] initTable;
  530. }
  531. Mapa::Mapa()
  532. {
  533. terrain = NULL;
  534. }
  535. Mapa::~Mapa()
  536. {
  537. if(terrain)
  538. {
  539. for (int ii=0;ii<width;ii++)
  540. {
  541. for(int jj=0;jj<height;jj++)
  542. delete [] terrain[ii][jj];
  543. delete [] terrain[ii];
  544. }
  545. delete [] terrain;
  546. }
  547. }
  548. CGHeroInstance * Mapa::getHero(int ID, int mode)
  549. {
  550. if (mode != 0)
  551. #ifndef __GNUC__
  552. throw new std::exception("gs->getHero: This mode is not supported!");
  553. #else
  554. throw new std::exception();
  555. #endif
  556. for(int i=0; i<heroes.size();i++)
  557. if(heroes[i]->subID == ID)
  558. return heroes[i];
  559. return NULL;
  560. }
  561. int Mapa::loadSeerHut( unsigned char * bufor, int i, CGObjectInstance *& nobj )
  562. {
  563. CGSeerHut *hut = new CGSeerHut();
  564. nobj = hut;
  565. if(version>RoE)
  566. {
  567. loadQuest(hut,bufor,i);
  568. }
  569. else //RoE
  570. {
  571. int artID = bufor[i]; ++i;
  572. if(artID!=255) //not none quest
  573. {
  574. hut->m5arts.push_back(artID);
  575. hut->missionType = 5;
  576. }
  577. else
  578. {
  579. hut->missionType = 255;
  580. }
  581. }
  582. if(hut->missionType!=255)
  583. {
  584. unsigned char rewardType = bufor[i]; ++i;
  585. hut->rewardType = rewardType;
  586. switch(rewardType)
  587. {
  588. case 1:
  589. {
  590. hut->rVal = readNormalNr(bufor,i); i+=4;
  591. break;
  592. }
  593. case 2:
  594. {
  595. hut->rVal = readNormalNr(bufor,i); i+=4;
  596. break;
  597. }
  598. case 3:
  599. {
  600. hut->rVal = bufor[i]; ++i;
  601. break;
  602. }
  603. case 4:
  604. {
  605. hut->rVal = bufor[i]; ++i;
  606. break;
  607. }
  608. case 5:
  609. {
  610. hut->rID = bufor[i]; ++i;
  611. hut->rVal = readNormalNr(bufor,i, 3); i+=3;
  612. i+=1;
  613. break;
  614. }
  615. case 6:
  616. {
  617. hut->rID = bufor[i]; ++i;
  618. hut->rVal = bufor[i]; ++i;
  619. break;
  620. }
  621. case 7:
  622. {
  623. hut->rID = bufor[i]; ++i;
  624. hut->rVal = bufor[i]; ++i;
  625. break;
  626. }
  627. case 8:
  628. {
  629. hut->rID = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2);
  630. break;
  631. }
  632. case 9:
  633. {
  634. hut->rID = bufor[i]; ++i;
  635. break;
  636. }
  637. case 10:
  638. {
  639. if(version>RoE)
  640. {
  641. hut->rID = readNormalNr(bufor,i, 2); i+=2;
  642. hut->rVal = readNormalNr(bufor,i, 2); i+=2;
  643. }
  644. else
  645. {
  646. hut->rID = bufor[i]; ++i;
  647. hut->rVal = readNormalNr(bufor,i, 2); i+=2;
  648. }
  649. break;
  650. }
  651. }// end of internal switch
  652. i+=2;
  653. }
  654. else //missionType==255
  655. {
  656. i+=3;
  657. }
  658. return i;
  659. }
  660. void Mapa::loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
  661. {
  662. CGTownInstance * nt = new CGTownInstance();
  663. //(*(static_cast<CGObjectInstance*>(nt))) = *nobj;
  664. //delete nobj;
  665. nobj = nt;
  666. nt->identifier = 0;
  667. if(version>RoE)
  668. {
  669. readNormalNr(bufor,i); i+=4;
  670. }
  671. nt->tempOwner = bufor[i]; ++i;
  672. if(readChar(bufor,i)) //has name
  673. nt->name = readString(bufor,i);
  674. if(readChar(bufor,i))//true if garrison isn't empty
  675. nt->army = readCreatureSet(bufor,i,7,(version>RoE));
  676. nt->army.formation = bufor[i]; ++i;
  677. if(readChar(bufor,i)) //unusualBuildings
  678. {
  679. //built buildings
  680. for(int byte=0;byte<6;byte++)
  681. {
  682. for(int bit=0;bit<8;bit++)
  683. if(bufor[i] & (1<<bit))
  684. nt->builtBuildings.insert(byte*8+bit);
  685. i++;
  686. }
  687. //forbidden buildings
  688. for(int byte=6;byte<12;byte++)
  689. {
  690. for(int bit=0;bit<8;bit++)
  691. if(bufor[i] & (1<<bit))
  692. nt->forbiddenBuildings.insert((byte-6)*8+bit);
  693. i++;
  694. }
  695. nt->builtBuildings = convertBuildings(nt->builtBuildings,nt->subID);
  696. nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID);
  697. }
  698. else //standard buildings
  699. {
  700. if(readChar(bufor,i)) //has fort
  701. nt->builtBuildings.insert(7);
  702. nt->builtBuildings.insert(-50); //means that set of standard building should be included
  703. }
  704. int ist = i;
  705. if(version>RoE)
  706. {
  707. for(i; i<ist+9; ++i)
  708. {
  709. unsigned char c = bufor[i];
  710. for(int yy=0; yy<8; ++yy)
  711. {
  712. if((i-ist)*8+yy < SPELLS_QUANTITY)
  713. {
  714. if(c == (c|((unsigned char)intPow(2, yy))))
  715. nt->obligatorySpells.push_back((i-ist)*8+yy);
  716. }
  717. }
  718. }
  719. }
  720. ist = i;
  721. for(i; i<ist+9; ++i)
  722. {
  723. unsigned char c = bufor[i];
  724. for(int yy=0; yy<8; ++yy)
  725. {
  726. if((i-ist)*8+yy < SPELLS_QUANTITY)
  727. {
  728. if(c != (c|((unsigned char)intPow(2, yy))))
  729. nt->possibleSpells.push_back((i-ist)*8+yy);
  730. }
  731. }
  732. }
  733. /////// reading castle events //////////////////////////////////
  734. int numberOfEvent = readNormalNr(bufor,i); i+=4;
  735. for(int gh = 0; gh<numberOfEvent; ++gh)
  736. {
  737. CCastleEvent nce;
  738. nce.name = readString(bufor,i);
  739. nce.message = readString(bufor,i);
  740. nce.resources.resize(RESOURCE_QUANTITY);
  741. for(int x=0; x < 7; x++)
  742. {
  743. nce.resources[x] = readNormalNr(bufor,i);
  744. i+=4;
  745. }
  746. nce.players = bufor[i]; ++i;
  747. if(version > AB)
  748. {
  749. nce.forHuman = bufor[i]; ++i;
  750. }
  751. else
  752. nce.forHuman = true;
  753. nce.forComputer = bufor[i]; ++i;
  754. nce.firstShow = readNormalNr(bufor,i, 2); i+=2;
  755. nce.forEvery = bufor[i]; ++i;
  756. i+=17;
  757. for(int kk=0; kk<6; ++kk)
  758. {
  759. nce.bytes[kk] = bufor[i]; ++i;
  760. }
  761. for(int vv=0; vv<7; ++vv)
  762. {
  763. nce.gen[vv] = readNormalNr(bufor,i, 2); i+=2;
  764. }
  765. i+=4;
  766. nt->events.insert(nce);
  767. }//castle events have been read
  768. if(version > AB)
  769. {
  770. nt->alignment = bufor[i]; ++i;
  771. }
  772. else
  773. nt->alignment = 0xff;
  774. i+=3;
  775. nt->builded = 0;
  776. nt->destroyed = 0;
  777. nt->garrisonHero = NULL;
  778. }
  779. void Mapa::loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
  780. {
  781. CGHeroInstance * nhi = new CGHeroInstance;
  782. nobj=nhi;
  783. int identifier = 0;
  784. if(version>RoE)
  785. {
  786. identifier = readNormalNr(bufor,i, 4); i+=4;
  787. }
  788. ui8 owner = bufor[i++];
  789. nobj->subID = readNormalNr(bufor,i, 1); ++i;
  790. for(int j=0; j<predefinedHeroes.size(); j++)
  791. {
  792. if(predefinedHeroes[j]->subID == nobj->subID)
  793. {
  794. *nhi = *predefinedHeroes[j];
  795. break;
  796. }
  797. }
  798. nobj->setOwner(owner);
  799. //(*(static_cast<CGObjectInstance*>(nhi))) = *nobj;
  800. //delete nobj;
  801. nhi->portrait = nhi->subID;
  802. for(int j=0; j<disposedHeroes.size(); j++)
  803. {
  804. if(disposedHeroes[j].ID == nhi->subID)
  805. {
  806. nhi->name = disposedHeroes[j].name;
  807. nhi->portrait = disposedHeroes[j].portrait;
  808. break;
  809. }
  810. }
  811. nhi->identifier = identifier;
  812. if(readChar(bufor,i))//true if hero has nonstandard name
  813. nhi->name = readString(bufor,i);
  814. if(version>AB)
  815. {
  816. if(readChar(bufor,i))//true if hore's experience is greater than 0
  817. { nhi->exp = readNormalNr(bufor,i); i+=4; }
  818. else
  819. nhi->exp = 0xffffffff;
  820. }
  821. else
  822. { nhi->exp = readNormalNr(bufor,i); i+=4; }
  823. bool portrait=bufor[i]; ++i;
  824. if (portrait)
  825. nhi->portrait = readChar(bufor,i);
  826. if(readChar(bufor,i))//true if hero has specified abilities
  827. {
  828. int howMany = readNormalNr(bufor,i); i+=4;
  829. nhi->secSkills.resize(howMany);
  830. for(int yy=0; yy<howMany; ++yy)
  831. {
  832. nhi->secSkills[yy].first = readNormalNr(bufor,i, 1); ++i;
  833. nhi->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i;
  834. }
  835. }
  836. if(readChar(bufor,i))//true if hero has nonstandard garrison
  837. nhi->army = readCreatureSet(bufor,i,7,(version>RoE));
  838. nhi->army.formation =bufor[i]; ++i; //formation
  839. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  840. int artmask = version == RoE ? 0xff : 0xffff;
  841. int artidlen = version == RoE ? 1 : 2;
  842. if(artSet)
  843. {
  844. for(int pom=0;pom<16;pom++)
  845. {
  846. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  847. if(id!=artmask)
  848. nhi->artifWorn[pom] = id;
  849. }
  850. //misc5 art //17
  851. if(version>=SoD)
  852. {
  853. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  854. if(id!=artmask)
  855. nhi->artifWorn[16] = id;
  856. }
  857. //spellbook
  858. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  859. if(id!=artmask)
  860. nhi->artifWorn[17] = id;
  861. //19 //???what is that? gap in file or what? - it's probably fifth slot..
  862. if(version>RoE)
  863. {
  864. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  865. if(id!=artmask)
  866. nhi->artifWorn[18] = id;
  867. }
  868. else
  869. i+=1;
  870. //bag artifacts //20
  871. int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag
  872. if(amount>0)
  873. {
  874. for(int ss=0; ss<amount; ++ss)
  875. {
  876. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  877. if(id!=artmask)
  878. nhi->artifacts.push_back(id);
  879. }
  880. }
  881. } //artifacts
  882. nhi->patrol.patrolRadious = readNormalNr(bufor,i, 1); ++i;
  883. if(nhi->patrol.patrolRadious == 0xff)
  884. nhi->patrol.patrolling = false;
  885. else
  886. nhi->patrol.patrolling = true;
  887. if(version>RoE)
  888. {
  889. if(readChar(bufor,i))//true if hero has nonstandard (mapmaker defined) biography
  890. nhi->biography = readString(bufor,i);
  891. nhi->sex = !(bufor[i]); ++i;
  892. }
  893. //spells
  894. if(version>AB)
  895. {
  896. bool areSpells = bufor[i]; ++i;
  897. if(areSpells) //TODO: sprawdziæ //seems to be ok - tow
  898. {
  899. int ist = i;
  900. for(i; i<ist+9; ++i)
  901. {
  902. unsigned char c = bufor[i];
  903. for(int yy=0; yy<8; ++yy)
  904. {
  905. if((i-ist)*8+yy < SPELLS_QUANTITY)
  906. {
  907. if(c == (c|((unsigned char)intPow(2, yy))))
  908. nhi->spells.insert((i-ist)*8+yy);
  909. }
  910. }
  911. }
  912. }
  913. }
  914. else if(version==AB) //we can read one spell
  915. {
  916. unsigned char buff = bufor[i]; ++i;
  917. if(buff!=254)
  918. {
  919. nhi->spells.insert(buff);
  920. }
  921. }
  922. //spells loaded
  923. if(version>AB)
  924. {
  925. if(readChar(bufor,i))//customPrimSkills
  926. {
  927. nhi->primSkills.resize(4);
  928. for(int xx=0;xx<4;xx++)
  929. nhi->primSkills[xx] = bufor[i++];
  930. }
  931. }
  932. i+=16;
  933. nhi->moveDir = 4;
  934. nhi->isStanding = true;
  935. nhi->level = -1;
  936. nhi->mana = -1;
  937. nhi->movement = -1;
  938. }
  939. void Mapa::readRumors( unsigned char * bufor, int &i)
  940. {
  941. int rumNr = readNormalNr(bufor,i,4);i+=4;
  942. for (int it=0;it<rumNr;it++)
  943. {
  944. Rumor ourRumor;
  945. int nameL = readNormalNr(bufor,i,4);i+=4; //read length of name of rumor
  946. for (int zz=0; zz<nameL; zz++)
  947. ourRumor.name+=bufor[i++];
  948. nameL = readNormalNr(bufor,i,4);i+=4; //read length of rumor
  949. for (int zz=0; zz<nameL; zz++)
  950. ourRumor.text+=bufor[i++];
  951. rumors.push_back(ourRumor); //add to our list
  952. }
  953. }
  954. void Mapa::readHeader( unsigned char * bufor, int &i)
  955. {
  956. //reading allowed heroes (20 bytes)
  957. int ist;
  958. ist=i; //starting i for loop
  959. allowedHeroes.resize(HEROES_QUANTITY);
  960. for(int xx=0;xx<HEROES_QUANTITY;xx++)
  961. allowedHeroes[xx] = true;
  962. for(i; i<ist+ (version == RoE ? 16 : 20) ; ++i)
  963. {
  964. unsigned char c = bufor[i];
  965. for(int yy=0; yy<8; ++yy)
  966. if((i-ist)*8+yy < HEROES_QUANTITY)
  967. if(c != (c|((unsigned char)intPow(2, yy))))
  968. allowedHeroes[(i-ist)*8+yy] = false;
  969. }
  970. if(version>RoE) //probably reserved for further heroes
  971. i+=4;
  972. unsigned char disp = 0;
  973. if(version>=SoD)
  974. {
  975. disp = bufor[i++];
  976. disposedHeroes.resize(disp);
  977. for(int g=0; g<disp; ++g)
  978. {
  979. disposedHeroes[g].ID = bufor[i++];
  980. disposedHeroes[g].portrait = bufor[i++];
  981. int lenbuf = readNormalNr(bufor,i); i+=4;
  982. for (int zz=0; zz<lenbuf; zz++)
  983. disposedHeroes[g].name+=bufor[i++];
  984. disposedHeroes[g].players = bufor[i++];
  985. //int players = bufor[i++];
  986. //for(int zz=0;zz<8;zz++)
  987. //{
  988. // int por = (1<<zz);
  989. // if(players & por)
  990. // disposedHeroes[g].players[zz] = true;
  991. // else
  992. // disposedHeroes[g].players[zz] = false;
  993. //}
  994. }
  995. }
  996. i+=31; //omitting NULLS
  997. allowedArtifact.resize(ARTIFACTS_QUANTITY);
  998. for(int x=0;x<allowedArtifact.size();x++)
  999. allowedArtifact[x] = true;
  1000. //reading allowed artifacts: 17 or 18 bytes
  1001. if(version!=RoE)
  1002. {
  1003. ist=i; //starting i for loop
  1004. for(i; i<ist+(version==AB ? 17 : 18); ++i)
  1005. {
  1006. unsigned char c = bufor[i];
  1007. for(int yy=0; yy<8; ++yy)
  1008. {
  1009. if((i-ist)*8+yy < ARTIFACTS_QUANTITY)
  1010. {
  1011. if(c == (c|((unsigned char)intPow(2, yy))))
  1012. allowedArtifact[(i-ist)*8+yy] = false;
  1013. }
  1014. }
  1015. }//allowed artifacts have been read
  1016. }
  1017. allowedSpell.resize(SPELLS_QUANTITY);
  1018. for(int x=0;x<allowedSpell.size();x++)
  1019. allowedSpell[x] = true;
  1020. allowedAbilities.resize(SKILL_QUANTITY);
  1021. for(int x=0;x<allowedAbilities.size();x++)
  1022. allowedAbilities[x] = true;
  1023. if(version>=SoD)
  1024. {
  1025. //reading allowed spells (9 bytes)
  1026. ist=i; //starting i for loop
  1027. for(i; i<ist+9; ++i)
  1028. {
  1029. unsigned char c = bufor[i];
  1030. for(int yy=0; yy<8; ++yy)
  1031. if((i-ist)*8+yy < SPELLS_QUANTITY)
  1032. if(c == (c|((unsigned char)intPow(2, yy))))
  1033. allowedSpell[(i-ist)*8+yy] = false;
  1034. }
  1035. //allowed hero's abilities (4 bytes)
  1036. ist=i; //starting i for loop
  1037. for(i; i<ist+4; ++i)
  1038. {
  1039. unsigned char c = bufor[i];
  1040. for(int yy=0; yy<8; ++yy)
  1041. {
  1042. if((i-ist)*8+yy < SKILL_QUANTITY)
  1043. {
  1044. if(c == (c|((unsigned char)intPow(2, yy))))
  1045. allowedAbilities[(i-ist)*8+yy] = false;
  1046. }
  1047. }
  1048. }
  1049. }
  1050. }
  1051. void Mapa::readPredefinedHeroes( unsigned char * bufor, int &i)
  1052. {
  1053. switch(version)
  1054. {
  1055. case WoG: case SoD:
  1056. {
  1057. for(int z=0;z<HEROES_QUANTITY;z++) //disposed heroes
  1058. {
  1059. int custom = bufor[i++];
  1060. if(!custom)
  1061. continue;
  1062. CGHeroInstance * cgh = new CGHeroInstance;
  1063. cgh->ID = 34;
  1064. cgh->subID = z;
  1065. if(readChar(bufor,i))//true if hore's experience is greater than 0
  1066. { cgh->exp = readNormalNr(bufor,i); i+=4; }
  1067. else
  1068. cgh->exp = 0;
  1069. if(readChar(bufor,i))//true if hero has specified abilities
  1070. {
  1071. int howMany = readNormalNr(bufor,i); i+=4;
  1072. cgh->secSkills.resize(howMany);
  1073. for(int yy=0; yy<howMany; ++yy)
  1074. {
  1075. cgh->secSkills[yy].first = readNormalNr(bufor,i, 1); ++i;
  1076. cgh->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i;
  1077. }
  1078. }
  1079. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  1080. int artmask = version == RoE ? 0xff : 0xffff;
  1081. int artidlen = version == RoE ? 1 : 2;
  1082. if(artSet)
  1083. {
  1084. for(int pom=0;pom<16;pom++)
  1085. {
  1086. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1087. if(id!=artmask)
  1088. cgh->artifWorn[pom] = id;
  1089. }
  1090. //misc5 art //17
  1091. if(version>=SoD)
  1092. {
  1093. i+=2;
  1094. //int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1095. //if(id!=artmask)
  1096. // spec->artifWorn[16] = id;
  1097. }
  1098. //spellbook
  1099. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1100. if(id!=artmask)
  1101. cgh->artifWorn[17] = id;
  1102. //19 //???what is that? gap in file or what? - it's probably fifth slot..
  1103. if(version>RoE)
  1104. {
  1105. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1106. if(id!=artmask)
  1107. cgh->artifWorn[18] = id;
  1108. }
  1109. else
  1110. i+=1;
  1111. //bag artifacts //20
  1112. int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag
  1113. if(amount>0)
  1114. {
  1115. for(int ss=0; ss<amount; ++ss)
  1116. {
  1117. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1118. if(id!=artmask)
  1119. cgh->artifacts.push_back(id);
  1120. }
  1121. }
  1122. } //artifacts
  1123. if(readChar(bufor,i))//customBio
  1124. cgh->biography = readString(bufor,i);
  1125. int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female
  1126. if(readChar(bufor,i))//are spells
  1127. {
  1128. int ist = i;
  1129. for(i; i<ist+9; ++i)
  1130. {
  1131. unsigned char c = bufor[i];
  1132. for(int yy=0; yy<8; ++yy)
  1133. {
  1134. if((i-ist)*8+yy < SPELLS_QUANTITY)
  1135. {
  1136. if(c == (c|((unsigned char)intPow(2, yy))))
  1137. cgh->spells.insert((i-ist)*8+yy);
  1138. }
  1139. }
  1140. }
  1141. }
  1142. if(readChar(bufor,i))//customPrimSkills
  1143. {
  1144. cgh->primSkills.resize(4);
  1145. for(int xx=0;xx<4;xx++)
  1146. cgh->primSkills[xx] = bufor[i++];
  1147. }
  1148. predefinedHeroes.push_back(cgh);
  1149. }
  1150. break;
  1151. }
  1152. case RoE:
  1153. i+=0;
  1154. break;
  1155. }
  1156. }
  1157. void Mapa::readTerrain( unsigned char * bufor, int &i)
  1158. {
  1159. terrain = new TerrainTile**[width]; // allocate memory
  1160. for (int ii=0;ii<width;ii++)
  1161. {
  1162. terrain[ii] = new TerrainTile*[height]; // allocate memory
  1163. for(int jj=0;jj<height;jj++)
  1164. terrain[ii][jj] = new TerrainTile[twoLevel+1];
  1165. }
  1166. for (int c=0; c<width; c++) // reading terrain
  1167. {
  1168. for (int z=0; z<height; z++)
  1169. {
  1170. terrain[z][c][0].tertype = (EterrainType)(bufor[i++]);
  1171. terrain[z][c][0].terview = bufor[i++];
  1172. terrain[z][c][0].nuine = (Eriver)bufor[i++];
  1173. terrain[z][c][0].rivDir = bufor[i++];
  1174. terrain[z][c][0].malle = (Eroad)bufor[i++];
  1175. terrain[z][c][0].roadDir = bufor[i++];
  1176. terrain[z][c][0].siodmyTajemniczyBajt = bufor[i++];
  1177. terrain[z][c][0].blocked = 0;
  1178. terrain[z][c][0].visitable = 0;
  1179. }
  1180. }
  1181. if (twoLevel) // read underground terrain
  1182. {
  1183. for (int c=0; c<width; c++) // reading terrain
  1184. {
  1185. for (int z=0; z<height; z++)
  1186. {
  1187. terrain[z][c][1].tertype = (EterrainType)(bufor[i++]);
  1188. terrain[z][c][1].terview = bufor[i++];
  1189. terrain[z][c][1].nuine = (Eriver)bufor[i++];
  1190. terrain[z][c][1].rivDir = bufor[i++];
  1191. terrain[z][c][1].malle = (Eroad)bufor[i++];
  1192. terrain[z][c][1].roadDir = bufor[i++];
  1193. terrain[z][c][1].siodmyTajemniczyBajt = bufor[i++];
  1194. terrain[z][c][1].blocked = 0;
  1195. terrain[z][c][1].visitable = 0;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. void Mapa::readDefInfo( unsigned char * bufor, int &i)
  1201. {
  1202. int defAmount = readNormalNr(bufor,i); i+=4;
  1203. defy.reserve(defAmount);
  1204. for (int idd = 0 ; idd<defAmount; idd++) // reading defs
  1205. {
  1206. CGDefInfo * vinya = new CGDefInfo(); // info about new def
  1207. //reading name
  1208. int nameLength = readNormalNr(bufor,i,4);i+=4;
  1209. vinya->name.reserve(nameLength);
  1210. for (int cd=0;cd<nameLength;cd++)
  1211. {
  1212. vinya->name += bufor[i++];
  1213. }
  1214. std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper);
  1215. unsigned char bytes[12];
  1216. for (int v=0; v<12; v++) // read info
  1217. {
  1218. bytes[v] = bufor[i++];
  1219. }
  1220. vinya->terrainAllowed = readNormalNr(bufor,i,2);i+=2;
  1221. vinya->terrainMenu = readNormalNr(bufor,i,2);i+=2;
  1222. vinya->id = readNormalNr(bufor,i,4);i+=4;
  1223. vinya->subid = readNormalNr(bufor,i,4);i+=4;
  1224. vinya->type = bufor[i++];
  1225. vinya->printPriority = bufor[i++];
  1226. for (int zi=0; zi<6; zi++)
  1227. {
  1228. vinya->blockMap[zi] = reverse(bytes[zi]);
  1229. }
  1230. for (int zi=0; zi<6; zi++)
  1231. {
  1232. vinya->visitMap[zi] = reverse(bytes[6+zi]);
  1233. }
  1234. i+=16;
  1235. if(vinya->id!=34 && vinya->id!=70)
  1236. vinya->visitDir = VLC->dobjinfo->gobjs[vinya->id][vinya->subid]->visitDir;
  1237. else
  1238. vinya->visitDir = 0xff;
  1239. defy.push_back(vinya); // add this def to the vector
  1240. }
  1241. }
  1242. void Mapa::readObjects( unsigned char * bufor, int &i)
  1243. {
  1244. int howManyObjs = readNormalNr(bufor,i, 4); i+=4;
  1245. for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
  1246. {
  1247. CGObjectInstance * nobj = 0;
  1248. int3 pos;
  1249. pos.x = bufor[i++];
  1250. pos.y = bufor[i++];
  1251. pos.z = bufor[i++];
  1252. int defnum = readNormalNr(bufor,i, 4); i+=4;
  1253. CGDefInfo * defInfo = defy[defnum];
  1254. i+=5;
  1255. switch(defInfo->id)
  1256. {
  1257. case 26: //for event objects
  1258. {
  1259. CGEvent *evnt = new CGEvent();
  1260. nobj = evnt;
  1261. bool guardMess = bufor[i]; ++i;
  1262. if(guardMess)
  1263. {
  1264. int messLong = readNormalNr(bufor,i, 4); i+=4;
  1265. if(messLong>0)
  1266. {
  1267. for(int yy=0; yy<messLong; ++yy)
  1268. {
  1269. evnt->message +=bufor[i+yy];
  1270. }
  1271. i+=messLong;
  1272. }
  1273. if(bufor[i++])
  1274. {
  1275. evnt->guarders = readCreatureSet(bufor,i,7,(version>RoE));
  1276. }
  1277. i+=4;
  1278. }
  1279. evnt->gainedExp = readNormalNr(bufor,i, 4); i+=4;
  1280. evnt->manaDiff = readNormalNr(bufor,i, 4); i+=4;
  1281. evnt->moraleDiff = readNormalNr(bufor,i, 1, true); ++i;
  1282. evnt->luckDiff = readNormalNr(bufor,i, 1, true); ++i;
  1283. evnt->resources.resize(RESOURCE_QUANTITY);
  1284. for(int x=0; x<7; x++)
  1285. {
  1286. evnt->resources[x] = readNormalNr(bufor,i);
  1287. i+=4;
  1288. }
  1289. evnt->primskills.resize(PRIMARY_SKILLS);
  1290. for(int x=0; x<4; x++)
  1291. {
  1292. evnt->primskills[x] = readNormalNr(bufor,i, 1);
  1293. i++;
  1294. }
  1295. int gabn; //number of gained abilities
  1296. gabn = readNormalNr(bufor,i, 1); ++i;
  1297. for(int oo = 0; oo<gabn; ++oo)
  1298. {
  1299. evnt->abilities.push_back(readNormalNr(bufor,i, 1)); ++i;
  1300. evnt->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i;
  1301. }
  1302. int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts
  1303. for(int oo = 0; oo<gart; ++oo)
  1304. {
  1305. evnt->artifacts.push_back(readNormalNr(bufor,i, (version == RoE ? 1 : 2))); i+=(version == RoE ? 1 : 2);
  1306. }
  1307. int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells
  1308. for(int oo = 0; oo<gspel; ++oo)
  1309. {
  1310. evnt->spells.push_back(readNormalNr(bufor,i, 1)); ++i;
  1311. }
  1312. int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures
  1313. evnt->creatures = readCreatureSet(bufor,i,gcre,(version>RoE));
  1314. i+=8;
  1315. evnt->availableFor = readNormalNr(bufor,i, 1); ++i;
  1316. evnt->computerActivate = readNormalNr(bufor,i, 1); ++i;
  1317. evnt->humanActivate = readNormalNr(bufor,i, 1); ++i;
  1318. i+=4;
  1319. break;
  1320. }
  1321. case 34: case 70: case 62: //34 - hero; 70 - random hero; 62 - prison
  1322. {
  1323. loadHero(nobj, bufor, i);
  1324. break;
  1325. }
  1326. case 4: //arena
  1327. case 51: //Mercenary Camp
  1328. case 23: //Marletto Tower
  1329. case 61: // Star Axis
  1330. case 32: // Garden of Revelation
  1331. case 100: //Learning Stone
  1332. case 102: //Tree of Knowledge
  1333. case 41: //Library of Enlightenment
  1334. {
  1335. nobj = new CGVisitableOPH();
  1336. break;
  1337. }
  1338. case 55: //mystical garden
  1339. case 112://windmill
  1340. case 109://water wheel
  1341. {
  1342. nobj = new CGVisitableOPW();
  1343. break;
  1344. }
  1345. case 43: //teleport
  1346. case 44: //teleport
  1347. case 45: //teleport
  1348. case 103://subterranean gate
  1349. {
  1350. nobj = new CGTeleport();
  1351. break;
  1352. }
  1353. case 12: //campfire
  1354. case 101: //treasure chest
  1355. {
  1356. nobj = new CGPickable();
  1357. break;
  1358. }
  1359. case 54: //Monster
  1360. case 71: case 72: case 73: case 74: case 75: // Random Monster 1 - 4
  1361. case 162: case 163: case 164: // Random Monster 5 - 7
  1362. {
  1363. CGCreature *cre = new CGCreature();
  1364. nobj = cre;
  1365. if(version>RoE)
  1366. {
  1367. cre->identifier = readNormalNr(bufor,i); i+=4;
  1368. }
  1369. cre->army.slots[0].second = readNormalNr(bufor,i, 2); i+=2;
  1370. cre->character = bufor[i]; ++i;
  1371. bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
  1372. if(isMesTre)
  1373. {
  1374. cre->message = readString(bufor,i);
  1375. cre->resources.resize(RESOURCE_QUANTITY);
  1376. for(int j=0; j<7; j++)
  1377. {
  1378. cre->resources[j] = readNormalNr(bufor,i); i+=4;
  1379. }
  1380. int artID = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2);
  1381. if(version==RoE)
  1382. {
  1383. if(artID!=0xff)
  1384. cre->gainedArtifact = artID;
  1385. else
  1386. cre->gainedArtifact = -1;
  1387. }
  1388. else
  1389. {
  1390. if(artID!=0xffff)
  1391. cre->gainedArtifact = artID;
  1392. else
  1393. cre->gainedArtifact = -1;
  1394. }
  1395. }
  1396. cre->neverFlees = bufor[i]; ++i;
  1397. cre->notGrowingTeam = bufor[i]; ++i;
  1398. i+=2;;
  1399. break;
  1400. }
  1401. case 59: case 91: //ocean bottle and sign
  1402. {
  1403. CGSignBottle *sb = new CGSignBottle();
  1404. nobj = sb;
  1405. sb->message = readString(bufor,i);
  1406. i+=4;
  1407. break;
  1408. }
  1409. case 83: //seer's hut
  1410. {
  1411. i = loadSeerHut(bufor, i, nobj);
  1412. break;
  1413. }
  1414. case 113: //witch hut
  1415. {
  1416. CGWitchHut *wh = new CGWitchHut();
  1417. nobj = wh;
  1418. if(version>RoE) //in reo we cannot specify it - all are allowed (I hope)
  1419. {
  1420. int ist=i; //starting i for loop
  1421. for(i; i<ist+4; ++i)
  1422. {
  1423. unsigned char c = bufor[i];
  1424. for(int yy=0; yy<8; ++yy)
  1425. {
  1426. if((i-ist)*8+yy < SKILL_QUANTITY)
  1427. {
  1428. if(c == (c|((unsigned char)intPow(2, yy))))
  1429. wh->allowedAbilities.push_back((i-ist)*8+yy);
  1430. }
  1431. }
  1432. }
  1433. }
  1434. else //(RoE map)
  1435. {
  1436. for(int gg=0; gg<SKILL_QUANTITY; ++gg)
  1437. {
  1438. wh->allowedAbilities.push_back(gg);
  1439. }
  1440. }
  1441. break;
  1442. }
  1443. case 81: //scholar
  1444. {
  1445. CGScholar *sch = new CGScholar();
  1446. nobj = sch;
  1447. sch->bonusType = bufor[i]; ++i;
  1448. switch(sch->bonusType)
  1449. {
  1450. case 0xff:
  1451. ++i;
  1452. break;
  1453. case 0:
  1454. sch->r0type = bufor[i]; ++i;
  1455. break;
  1456. case 1:
  1457. sch->r1 = bufor[i]; ++i;
  1458. break;
  1459. case 2:
  1460. sch->r2 = bufor[i]; ++i;
  1461. break;
  1462. }
  1463. i+=6;
  1464. break;
  1465. }
  1466. case 33: case 219: //garrison
  1467. {
  1468. CGGarrison *gar = new CGGarrison();
  1469. nobj = gar;
  1470. nobj->setOwner(bufor[i++]);
  1471. i+=3;
  1472. gar->army = readCreatureSet(bufor,i,7,(version>RoE));
  1473. if(version > RoE)
  1474. {
  1475. gar->removableUnits = bufor[i]; ++i;
  1476. }
  1477. else
  1478. gar->removableUnits = true;
  1479. i+=8;
  1480. break;
  1481. }
  1482. case 5: //artifact
  1483. case 65: case 66: case 67: case 68: case 69: //random artifact
  1484. case 93: //spell scroll
  1485. {
  1486. CGArtifact *art = new CGArtifact();
  1487. nobj = art;
  1488. bool areSettings = bufor[i]; ++i;
  1489. if(areSettings)
  1490. {
  1491. art->message = readString(bufor,i);
  1492. bool areGuards = bufor[i]; ++i;
  1493. if(areGuards)
  1494. {
  1495. art->army = readCreatureSet(bufor,i,7,(version>RoE));
  1496. }
  1497. }
  1498. if(areSettings || defInfo->id==93)
  1499. {
  1500. art->spell = readNormalNr(bufor,i);
  1501. i+=4;
  1502. }
  1503. break;
  1504. }
  1505. case 76: case 79: //random resource; resource
  1506. {
  1507. CGResource *res = new CGResource();
  1508. nobj = res;
  1509. bool isMessGuard = bufor[i]; ++i;
  1510. if(isMessGuard)
  1511. {
  1512. res->message = readString(bufor,i);
  1513. if(bufor[i++])
  1514. {
  1515. res->army = readCreatureSet(bufor,i,7,(version>RoE));
  1516. }
  1517. i+=4;
  1518. }
  1519. res->amount = readNormalNr(bufor,i); i+=4;
  1520. i+=4;
  1521. break;
  1522. }
  1523. case 77: case 98: //random town; town
  1524. {
  1525. loadTown(nobj, bufor, i);
  1526. break;
  1527. }
  1528. case 53:
  1529. {
  1530. nobj = new CGMine();
  1531. nobj->setOwner(bufor[i++]);
  1532. i+=3;
  1533. break;
  1534. }
  1535. case 17: case 18: case 19: case 20: //dwellings
  1536. case 42: //lighthouse
  1537. case 87: //shipyard
  1538. case 220://mine (?)
  1539. {
  1540. nobj = new CGObjectInstance();
  1541. nobj->setOwner(bufor[i++]);
  1542. i+=3;
  1543. break;
  1544. }
  1545. case 88: case 89: case 90: //spell shrine
  1546. {
  1547. CGShrine * shr = new CGShrine();
  1548. nobj = shr;
  1549. shr->spell = bufor[i]; i+=4;
  1550. break;
  1551. }
  1552. case 6:
  1553. {
  1554. CGPandoraBox *box = new CGPandoraBox();
  1555. nobj = box;
  1556. bool messg = bufor[i]; ++i;
  1557. if(messg)
  1558. {
  1559. box->message = readString(bufor,i);
  1560. if(bufor[i++])
  1561. {
  1562. box->army = readCreatureSet(bufor,i,7,(version>RoE));
  1563. }
  1564. i+=4;
  1565. }
  1566. box->gainedExp = readNormalNr(bufor,i, 4); i+=4;
  1567. box->manaDiff = readNormalNr(bufor,i, 4); i+=4;
  1568. box->moraleDiff = readNormalNr(bufor,i, 1, true); ++i;
  1569. box->luckDiff = readNormalNr(bufor,i, 1, true); ++i;
  1570. box->resources.resize(RESOURCE_QUANTITY);
  1571. for(int x=0; x<7; x++)
  1572. {
  1573. box->resources[x] = readNormalNr(bufor,i);
  1574. i+=4;
  1575. }
  1576. box->primskills.resize(PRIMARY_SKILLS);
  1577. for(int x=0; x<4; x++)
  1578. {
  1579. box->primskills[x] = readNormalNr(bufor,i, 1);
  1580. i++;
  1581. }
  1582. int gabn; //number of gained abilities
  1583. gabn = readNormalNr(bufor,i, 1); ++i;
  1584. for(int oo = 0; oo<gabn; ++oo)
  1585. {
  1586. box->abilities.push_back(readNormalNr(bufor,i, 1)); ++i;
  1587. box->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i;
  1588. }
  1589. int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts
  1590. for(int oo = 0; oo<gart; ++oo)
  1591. {
  1592. if(version > RoE)
  1593. {
  1594. box->artifacts.push_back(readNormalNr(bufor,i, 2)); i+=2;
  1595. }
  1596. else
  1597. {
  1598. box->artifacts.push_back(readNormalNr(bufor,i, 1)); i+=1;
  1599. }
  1600. }
  1601. int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells
  1602. for(int oo = 0; oo<gspel; ++oo)
  1603. {
  1604. box->spells.push_back(readNormalNr(bufor,i, 1)); ++i;
  1605. }
  1606. int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures
  1607. box->creatures = readCreatureSet(bufor,i,gcre,(version>RoE));
  1608. i+=8;
  1609. break;
  1610. }
  1611. case 36:
  1612. {
  1613. grailPos = pos;
  1614. grailRadious = readNormalNr(bufor,i); i+=4;
  1615. continue;
  1616. }
  1617. case 217:
  1618. {
  1619. nobj = new CGObjectInstance();
  1620. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1621. spec->player = readNormalNr(bufor,i); i+=4;
  1622. spec->identifier = readNormalNr(bufor,i); i+=4;
  1623. if(!spec->identifier)
  1624. {
  1625. spec->asCastle = false;
  1626. spec->castles[0] = bufor[i]; ++i;
  1627. spec->castles[1] = bufor[i]; ++i;
  1628. }
  1629. else
  1630. {
  1631. spec->asCastle = true;
  1632. }
  1633. nobj->setOwner(spec->player);
  1634. nobj->info = spec;
  1635. break;
  1636. }
  1637. case 216:
  1638. {
  1639. nobj = new CGObjectInstance();
  1640. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1641. spec->player = readNormalNr(bufor,i); i+=4;
  1642. spec->identifier = readNormalNr(bufor,i); i+=4;
  1643. if(!spec->identifier)
  1644. {
  1645. spec->asCastle = false;
  1646. spec->castles[0] = bufor[i]; ++i;
  1647. spec->castles[1] = bufor[i]; ++i;
  1648. }
  1649. else
  1650. {
  1651. spec->asCastle = true;
  1652. }
  1653. spec->minLevel = bufor[i]; ++i;
  1654. spec->maxLevel = bufor[i]; ++i;
  1655. nobj->setOwner(spec->player);
  1656. nobj->info = spec;
  1657. break;
  1658. }
  1659. case 218:
  1660. {
  1661. nobj = new CGObjectInstance();
  1662. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1663. spec->player = bufor[i]; ++i;
  1664. i+=3;
  1665. spec->minLevel = bufor[i]; ++i;
  1666. spec->maxLevel = bufor[i]; ++i;
  1667. if(spec->maxLevel>7)
  1668. spec->maxLevel = 7;
  1669. if(spec->minLevel<1)
  1670. spec->minLevel = 1;
  1671. nobj->setOwner(spec->player);
  1672. nobj->info = spec;
  1673. break;
  1674. }
  1675. case 215:
  1676. {
  1677. CGQuestGuard *guard = new CGQuestGuard();
  1678. nobj = guard;
  1679. loadQuest(guard, bufor, i);
  1680. break;
  1681. }
  1682. case 214: //hero placeholder
  1683. {
  1684. i+=3; //TODO: handle it more properly
  1685. break;
  1686. }
  1687. default:
  1688. nobj = new CGObjectInstance();
  1689. } //end of main switch
  1690. nobj->pos = pos;
  1691. nobj->ID = defInfo->id;
  1692. nobj->id = objects.size();
  1693. if(nobj->ID != 34)
  1694. nobj->subID = defInfo->subid;
  1695. nobj->defInfo = defInfo;
  1696. objects.push_back(nobj);
  1697. if(nobj->ID==98)
  1698. towns.push_back(static_cast<CGTownInstance*>(nobj));
  1699. if(nobj->ID==34)
  1700. heroes.push_back(static_cast<CGHeroInstance*>(nobj));
  1701. }
  1702. }
  1703. void Mapa::readEvents( unsigned char * bufor, int &i )
  1704. {
  1705. int numberOfEvents = readNormalNr(bufor,i); i+=4;
  1706. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  1707. {
  1708. CMapEvent ne;
  1709. ne.name = std::string();
  1710. ne.message = std::string();
  1711. int nameLen = readNormalNr(bufor,i); i+=4;
  1712. for(int qq=0; qq<nameLen; ++qq)
  1713. {
  1714. ne.name += bufor[i]; ++i;
  1715. }
  1716. int messLen = readNormalNr(bufor,i); i+=4;
  1717. for(int qq=0; qq<messLen; ++qq)
  1718. {
  1719. ne.message +=bufor[i]; ++i;
  1720. }
  1721. ne.wood = readNormalNr(bufor,i); i+=4;
  1722. ne.mercury = readNormalNr(bufor,i); i+=4;
  1723. ne.ore = readNormalNr(bufor,i); i+=4;
  1724. ne.sulfur = readNormalNr(bufor,i); i+=4;
  1725. ne.crystal = readNormalNr(bufor,i); i+=4;
  1726. ne.gems = readNormalNr(bufor,i); i+=4;
  1727. ne.gold = readNormalNr(bufor,i); i+=4;
  1728. ne.players = bufor[i]; ++i;
  1729. if(version>AB)
  1730. {
  1731. ne.humanAffected = bufor[i]; ++i;
  1732. }
  1733. else
  1734. ne.humanAffected = true;
  1735. ne.computerAffected = bufor[i]; ++i;
  1736. ne.firstOccurence = bufor[i]; ++i;
  1737. ne.nextOccurence = bufor[i]; ++i;
  1738. i+=18;
  1739. events.push_back(ne);
  1740. }
  1741. }
  1742. bool Mapa::isInTheMap( int3 pos )
  1743. {
  1744. if(pos.x<0 || pos.y<0 || pos.z<0 || pos.x >= width || pos.y >= height || pos.z > twoLevel)
  1745. return false;
  1746. else return true;
  1747. }
  1748. void Mapa::loadQuest(CQuest * guard, unsigned char * bufor, int & i)
  1749. {
  1750. guard->missionType = bufor[i]; ++i;
  1751. int len1, len2, len3;
  1752. switch(guard->missionType)
  1753. {
  1754. case 0:
  1755. return;
  1756. case 2:
  1757. {
  1758. guard->m2stats.resize(4);
  1759. for(int x=0; x<4; x++)
  1760. {
  1761. guard->m2stats[x] = bufor[i++];
  1762. }
  1763. }
  1764. break;
  1765. case 1:
  1766. case 3:
  1767. case 4:
  1768. {
  1769. guard->m13489val = readNormalNr(bufor,i); i+=4;
  1770. break;
  1771. }
  1772. case 5:
  1773. {
  1774. int artNumber = bufor[i]; ++i;
  1775. for(int yy=0; yy<artNumber; ++yy)
  1776. {
  1777. guard->m5arts.push_back(readNormalNr(bufor,i, 2)); i+=2;
  1778. }
  1779. break;
  1780. }
  1781. case 6:
  1782. {
  1783. int typeNumber = bufor[i]; ++i;
  1784. for(int hh=0; hh<typeNumber; ++hh)
  1785. {
  1786. ui32 creType = readNormalNr(bufor,i, 2); i+=2;
  1787. ui32 creNumb = readNormalNr(bufor,i, 2); i+=2;
  1788. guard->m6creatures.push_back(std::make_pair(creType,creNumb));
  1789. }
  1790. break;
  1791. }
  1792. case 7:
  1793. {
  1794. guard->m7resources.resize(7);
  1795. for(int x=0; x<7; x++)
  1796. {
  1797. guard->m7resources[x] = readNormalNr(bufor,i);
  1798. i+=4;
  1799. }
  1800. break;
  1801. }
  1802. case 8:
  1803. case 9:
  1804. {
  1805. guard->m13489val = bufor[i]; ++i;
  1806. break;
  1807. }
  1808. }
  1809. int limit = readNormalNr(bufor,i); i+=4;
  1810. if(limit == ((int)0xffffffff))
  1811. {
  1812. guard->lastDay = -1;
  1813. }
  1814. else
  1815. {
  1816. guard->lastDay = limit;
  1817. }
  1818. guard->firstVisitText = readString(bufor,i);
  1819. guard->nextVisitText = readString(bufor,i);
  1820. guard->completedText = readString(bufor,i);
  1821. }
  1822. void CMapInfo::countPlayers()
  1823. {
  1824. playerAmnt=humenPlayers=0;
  1825. for (int i=0;i<PLAYER_LIMIT;i++)
  1826. {
  1827. if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
  1828. else if (players[i].canComputerPlay) {playerAmnt++;}
  1829. }
  1830. }
  1831. CMapInfo::CMapInfo( std::string fname, unsigned char *map )
  1832. :CMapHeader(map),filename(fname)
  1833. {
  1834. countPlayers();
  1835. }