map.cpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954
  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. i+=4;
  1498. }
  1499. if(defInfo->id==93)
  1500. {
  1501. art->spell = readNormalNr(bufor,i);
  1502. i+=4;
  1503. }
  1504. break;
  1505. }
  1506. case 76: case 79: //random resource; resource
  1507. {
  1508. CGResource *res = new CGResource();
  1509. nobj = res;
  1510. bool isMessGuard = bufor[i]; ++i;
  1511. if(isMessGuard)
  1512. {
  1513. res->message = readString(bufor,i);
  1514. if(bufor[i++])
  1515. {
  1516. res->army = readCreatureSet(bufor,i,7,(version>RoE));
  1517. }
  1518. i+=4;
  1519. }
  1520. res->amount = readNormalNr(bufor,i); i+=4;
  1521. i+=4;
  1522. break;
  1523. }
  1524. case 77: case 98: //random town; town
  1525. {
  1526. loadTown(nobj, bufor, i);
  1527. break;
  1528. }
  1529. case 53:
  1530. {
  1531. nobj = new CGMine();
  1532. nobj->setOwner(bufor[i++]);
  1533. i+=3;
  1534. break;
  1535. }
  1536. case 17: case 18: case 19: case 20: //dwellings
  1537. case 42: //lighthouse
  1538. case 87: //shipyard
  1539. case 220://mine (?)
  1540. {
  1541. nobj = new CGObjectInstance();
  1542. nobj->setOwner(bufor[i++]);
  1543. i+=3;
  1544. break;
  1545. }
  1546. case 88: case 89: case 90: //spell shrine
  1547. {
  1548. CGShrine * shr = new CGShrine();
  1549. nobj = shr;
  1550. shr->spell = bufor[i]; i+=4;
  1551. break;
  1552. }
  1553. case 6:
  1554. {
  1555. CGPandoraBox *box = new CGPandoraBox();
  1556. nobj = box;
  1557. bool messg = bufor[i]; ++i;
  1558. if(messg)
  1559. {
  1560. box->message = readString(bufor,i);
  1561. if(bufor[i++])
  1562. {
  1563. box->army = readCreatureSet(bufor,i,7,(version>RoE));
  1564. }
  1565. i+=4;
  1566. }
  1567. box->gainedExp = readNormalNr(bufor,i, 4); i+=4;
  1568. box->manaDiff = readNormalNr(bufor,i, 4); i+=4;
  1569. box->moraleDiff = readNormalNr(bufor,i, 1, true); ++i;
  1570. box->luckDiff = readNormalNr(bufor,i, 1, true); ++i;
  1571. box->resources.resize(RESOURCE_QUANTITY);
  1572. for(int x=0; x<7; x++)
  1573. {
  1574. box->resources[x] = readNormalNr(bufor,i);
  1575. i+=4;
  1576. }
  1577. box->primskills.resize(PRIMARY_SKILLS);
  1578. for(int x=0; x<4; x++)
  1579. {
  1580. box->primskills[x] = readNormalNr(bufor,i, 1);
  1581. i++;
  1582. }
  1583. int gabn; //number of gained abilities
  1584. gabn = readNormalNr(bufor,i, 1); ++i;
  1585. for(int oo = 0; oo<gabn; ++oo)
  1586. {
  1587. box->abilities.push_back(readNormalNr(bufor,i, 1)); ++i;
  1588. box->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i;
  1589. }
  1590. int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts
  1591. for(int oo = 0; oo<gart; ++oo)
  1592. {
  1593. if(version > RoE)
  1594. {
  1595. box->artifacts.push_back(readNormalNr(bufor,i, 2)); i+=2;
  1596. }
  1597. else
  1598. {
  1599. box->artifacts.push_back(readNormalNr(bufor,i, 1)); i+=1;
  1600. }
  1601. }
  1602. int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells
  1603. for(int oo = 0; oo<gspel; ++oo)
  1604. {
  1605. box->spells.push_back(readNormalNr(bufor,i, 1)); ++i;
  1606. }
  1607. int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures
  1608. box->creatures = readCreatureSet(bufor,i,gcre,(version>RoE));
  1609. i+=8;
  1610. break;
  1611. }
  1612. case 36:
  1613. {
  1614. grailPos = pos;
  1615. grailRadious = readNormalNr(bufor,i); i+=4;
  1616. continue;
  1617. }
  1618. case 217:
  1619. {
  1620. nobj = new CGObjectInstance();
  1621. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1622. spec->player = readNormalNr(bufor,i); i+=4;
  1623. spec->identifier = readNormalNr(bufor,i); i+=4;
  1624. if(!spec->identifier)
  1625. {
  1626. spec->asCastle = false;
  1627. spec->castles[0] = bufor[i]; ++i;
  1628. spec->castles[1] = bufor[i]; ++i;
  1629. }
  1630. else
  1631. {
  1632. spec->asCastle = true;
  1633. }
  1634. nobj->setOwner(spec->player);
  1635. nobj->info = spec;
  1636. break;
  1637. }
  1638. case 216:
  1639. {
  1640. nobj = new CGObjectInstance();
  1641. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1642. spec->player = readNormalNr(bufor,i); i+=4;
  1643. spec->identifier = readNormalNr(bufor,i); i+=4;
  1644. if(!spec->identifier)
  1645. {
  1646. spec->asCastle = false;
  1647. spec->castles[0] = bufor[i]; ++i;
  1648. spec->castles[1] = bufor[i]; ++i;
  1649. }
  1650. else
  1651. {
  1652. spec->asCastle = true;
  1653. }
  1654. spec->minLevel = bufor[i]; ++i;
  1655. spec->maxLevel = bufor[i]; ++i;
  1656. nobj->setOwner(spec->player);
  1657. nobj->info = spec;
  1658. break;
  1659. }
  1660. case 218:
  1661. {
  1662. nobj = new CGObjectInstance();
  1663. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1664. spec->player = bufor[i]; ++i;
  1665. i+=3;
  1666. spec->minLevel = bufor[i]; ++i;
  1667. spec->maxLevel = bufor[i]; ++i;
  1668. if(spec->maxLevel>7)
  1669. spec->maxLevel = 7;
  1670. if(spec->minLevel<1)
  1671. spec->minLevel = 1;
  1672. nobj->setOwner(spec->player);
  1673. nobj->info = spec;
  1674. break;
  1675. }
  1676. case 215:
  1677. {
  1678. CGQuestGuard *guard = new CGQuestGuard();
  1679. nobj = guard;
  1680. loadQuest(guard, bufor, i);
  1681. break;
  1682. }
  1683. case 28: //faerie ring
  1684. case 14: //Swan pond
  1685. case 38: //idol of fortune
  1686. case 30: //Fountain of Fortune
  1687. case 64: //Rally Flag
  1688. case 56: //oasis
  1689. case 96: //temple
  1690. case 110://Watering Hole
  1691. case 31: //Fountain of Youth
  1692. {
  1693. nobj = new CGBonusingObject();
  1694. break;
  1695. }
  1696. case 214: //hero placeholder
  1697. {
  1698. i+=3; //TODO: handle it more properly
  1699. }
  1700. default:
  1701. nobj = new CGObjectInstance();
  1702. } //end of main switch
  1703. nobj->pos = pos;
  1704. nobj->ID = defInfo->id;
  1705. nobj->id = objects.size();
  1706. if(nobj->ID != 34)
  1707. nobj->subID = defInfo->subid;
  1708. nobj->defInfo = defInfo;
  1709. objects.push_back(nobj);
  1710. if(nobj->ID==98)
  1711. towns.push_back(static_cast<CGTownInstance*>(nobj));
  1712. if(nobj->ID==34)
  1713. heroes.push_back(static_cast<CGHeroInstance*>(nobj));
  1714. }
  1715. }
  1716. void Mapa::readEvents( unsigned char * bufor, int &i )
  1717. {
  1718. int numberOfEvents = readNormalNr(bufor,i); i+=4;
  1719. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  1720. {
  1721. CMapEvent ne;
  1722. ne.name = std::string();
  1723. ne.message = std::string();
  1724. int nameLen = readNormalNr(bufor,i); i+=4;
  1725. for(int qq=0; qq<nameLen; ++qq)
  1726. {
  1727. ne.name += bufor[i]; ++i;
  1728. }
  1729. int messLen = readNormalNr(bufor,i); i+=4;
  1730. for(int qq=0; qq<messLen; ++qq)
  1731. {
  1732. ne.message +=bufor[i]; ++i;
  1733. }
  1734. ne.wood = readNormalNr(bufor,i); i+=4;
  1735. ne.mercury = readNormalNr(bufor,i); i+=4;
  1736. ne.ore = readNormalNr(bufor,i); i+=4;
  1737. ne.sulfur = readNormalNr(bufor,i); i+=4;
  1738. ne.crystal = readNormalNr(bufor,i); i+=4;
  1739. ne.gems = readNormalNr(bufor,i); i+=4;
  1740. ne.gold = readNormalNr(bufor,i); i+=4;
  1741. ne.players = bufor[i]; ++i;
  1742. if(version>AB)
  1743. {
  1744. ne.humanAffected = bufor[i]; ++i;
  1745. }
  1746. else
  1747. ne.humanAffected = true;
  1748. ne.computerAffected = bufor[i]; ++i;
  1749. ne.firstOccurence = bufor[i]; ++i;
  1750. ne.nextOccurence = bufor[i]; ++i;
  1751. i+=18;
  1752. events.push_back(ne);
  1753. }
  1754. }
  1755. bool Mapa::isInTheMap( int3 pos )
  1756. {
  1757. if(pos.x<0 || pos.y<0 || pos.z<0 || pos.x >= width || pos.y >= height || pos.z > twoLevel)
  1758. return false;
  1759. else return true;
  1760. }
  1761. void Mapa::loadQuest(CQuest * guard, unsigned char * bufor, int & i)
  1762. {
  1763. guard->missionType = bufor[i]; ++i;
  1764. int len1, len2, len3;
  1765. switch(guard->missionType)
  1766. {
  1767. case 0:
  1768. return;
  1769. case 2:
  1770. {
  1771. guard->m2stats.resize(4);
  1772. for(int x=0; x<4; x++)
  1773. {
  1774. guard->m2stats[x] = bufor[i++];
  1775. }
  1776. }
  1777. break;
  1778. case 1:
  1779. case 3:
  1780. case 4:
  1781. {
  1782. guard->m13489val = readNormalNr(bufor,i); i+=4;
  1783. break;
  1784. }
  1785. case 5:
  1786. {
  1787. int artNumber = bufor[i]; ++i;
  1788. for(int yy=0; yy<artNumber; ++yy)
  1789. {
  1790. guard->m5arts.push_back(readNormalNr(bufor,i, 2)); i+=2;
  1791. }
  1792. break;
  1793. }
  1794. case 6:
  1795. {
  1796. int typeNumber = bufor[i]; ++i;
  1797. for(int hh=0; hh<typeNumber; ++hh)
  1798. {
  1799. ui32 creType = readNormalNr(bufor,i, 2); i+=2;
  1800. ui32 creNumb = readNormalNr(bufor,i, 2); i+=2;
  1801. guard->m6creatures.push_back(std::make_pair(creType,creNumb));
  1802. }
  1803. break;
  1804. }
  1805. case 7:
  1806. {
  1807. guard->m7resources.resize(7);
  1808. for(int x=0; x<7; x++)
  1809. {
  1810. guard->m7resources[x] = readNormalNr(bufor,i);
  1811. i+=4;
  1812. }
  1813. break;
  1814. }
  1815. case 8:
  1816. case 9:
  1817. {
  1818. guard->m13489val = bufor[i]; ++i;
  1819. break;
  1820. }
  1821. }
  1822. int limit = readNormalNr(bufor,i); i+=4;
  1823. if(limit == ((int)0xffffffff))
  1824. {
  1825. guard->lastDay = -1;
  1826. }
  1827. else
  1828. {
  1829. guard->lastDay = limit;
  1830. }
  1831. guard->firstVisitText = readString(bufor,i);
  1832. guard->nextVisitText = readString(bufor,i);
  1833. guard->completedText = readString(bufor,i);
  1834. }
  1835. void CMapInfo::countPlayers()
  1836. {
  1837. playerAmnt=humenPlayers=0;
  1838. for (int i=0;i<PLAYER_LIMIT;i++)
  1839. {
  1840. if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
  1841. else if (players[i].canComputerPlay) {playerAmnt++;}
  1842. }
  1843. }
  1844. CMapInfo::CMapInfo( std::string fname, unsigned char *map )
  1845. :CMapHeader(map),filename(fname)
  1846. {
  1847. countPlayers();
  1848. }