map.cpp 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464
  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. std::cout<<"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. this->version = (Eformat)map[0]; //wersja mapy
  206. this->areAnyPLayers = map[4]; //seems to be invalid
  207. this->height = this->width = map[5]; // wymiary mapy
  208. this->twoLevel = map[9]; //czy sa lochy
  209. int length = map[10]; //name length
  210. int i=14, pom;
  211. while (i-14<length) //read name
  212. this->name+=map[i++];
  213. length = map[i] + map[i+1]*256; //description length
  214. i+=4;
  215. for (pom=0;pom<length;pom++)
  216. this->description+=map[i++];
  217. this->difficulty = map[i++]; // reading map difficulty
  218. if(version!=RoE)
  219. {
  220. this->levelLimit = map[i++]; // hero level limit
  221. }
  222. else
  223. {
  224. levelLimit = 0;
  225. }
  226. for (pom=0;pom<8;pom++)
  227. {
  228. this->players[pom].canHumanPlay = map[i++];
  229. this->players[pom].canComputerPlay = map[i++];
  230. if ((!(this->players[pom].canHumanPlay || this->players[pom].canComputerPlay)))
  231. {
  232. switch(version)
  233. {
  234. case SoD: case WoG:
  235. i+=13;
  236. break;
  237. case AB:
  238. i+=12;
  239. break;
  240. case RoE:
  241. i+=6;
  242. break;
  243. }
  244. continue;
  245. }
  246. this->players[pom].AITactic = map[i++];
  247. if(version == SoD || version == WoG)
  248. i++;
  249. this->players[pom].allowedFactions = 0;
  250. this->players[pom].allowedFactions += map[i++];
  251. if(version != RoE)
  252. this->players[pom].allowedFactions += (map[i++])*256;
  253. this->players[pom].isFactionRandom = map[i++];
  254. this->players[pom].hasMainTown = map[i++];
  255. if (this->players[pom].hasMainTown)
  256. {
  257. if(version != RoE)
  258. {
  259. this->players[pom].generateHeroAtMainTown = map[i++];
  260. this->players[pom].generateHero = map[i++];
  261. }
  262. this->players[pom].posOfMainTown.x = map[i++];
  263. this->players[pom].posOfMainTown.y = map[i++];
  264. this->players[pom].posOfMainTown.z = map[i++];
  265. }
  266. players[pom].p8= map[i++];
  267. players[pom].p9= map[i++];
  268. if(players[pom].p9!=0xff)
  269. {
  270. players[pom].mainHeroPortrait = map[i++];
  271. int nameLength = map[i++];
  272. i+=3;
  273. for (int pp=0;pp<nameLength;pp++)
  274. players[pom].mainHeroName+=map[i++];
  275. }
  276. if(version!=RoE)
  277. {
  278. i++; ////heroes placeholders //domostwa
  279. int heroCount = map[i++];
  280. i+=3;
  281. for (int pp=0;pp<heroCount;pp++)
  282. {
  283. SheroName vv;
  284. vv.heroID=map[i++];
  285. int hnl = map[i++];
  286. i+=3;
  287. for (int zz=0;zz<hnl;zz++)
  288. {
  289. vv.heroName+=map[i++];
  290. }
  291. this->players[pom].heroesNames.push_back(vv);
  292. }
  293. }
  294. }
  295. this->victoryCondition = (EvictoryConditions)map[i++];
  296. if (this->victoryCondition != winStandard) //specific victory conditions
  297. {
  298. int nr;
  299. switch (this->victoryCondition) //read victory conditions
  300. {
  301. case artifact:
  302. {
  303. this->vicConDetails = new VicCon0();
  304. ((VicCon0*)this->vicConDetails)->ArtifactID = map[i+2];
  305. nr=(version==RoE ? 1 : 2);
  306. break;
  307. }
  308. case gatherTroop:
  309. {
  310. this->vicConDetails = new VicCon1();
  311. int temp1 = map[i+2];
  312. int temp2 = map[i+3];
  313. ((VicCon1*)this->vicConDetails)->monsterID = map[i+2];
  314. ((VicCon1*)this->vicConDetails)->neededQuantity=readNormalNr(map, i+(version==RoE ? 3 : 4));
  315. nr=(version==RoE ? 5 : 6);
  316. break;
  317. }
  318. case gatherResource:
  319. {
  320. this->vicConDetails = new VicCon2();
  321. ((VicCon2*)this->vicConDetails)->resourceID = map[i+2];
  322. ((VicCon2*)this->vicConDetails)->neededQuantity=readNormalNr(map, i+3);
  323. nr=5;
  324. break;
  325. }
  326. case buildCity:
  327. {
  328. this->vicConDetails = new VicCon3();
  329. ((VicCon3*)this->vicConDetails)->posOfCity.x = map[i+2];
  330. ((VicCon3*)this->vicConDetails)->posOfCity.y = map[i+3];
  331. ((VicCon3*)this->vicConDetails)->posOfCity.z = map[i+4];
  332. ((VicCon3*)this->vicConDetails)->councilNeededLevel = map[i+5];
  333. ((VicCon3*)this->vicConDetails)->fortNeededLevel = map[i+6];
  334. nr=5;
  335. break;
  336. }
  337. case buildGrail:
  338. {
  339. this->vicConDetails = new VicCon4();
  340. if (map[i+4]>2)
  341. ((VicCon4*)this->vicConDetails)->anyLocation = true;
  342. else
  343. {
  344. ((VicCon4*)this->vicConDetails)->whereBuildGrail.x = map[i+2];
  345. ((VicCon4*)this->vicConDetails)->whereBuildGrail.y = map[i+3];
  346. ((VicCon4*)this->vicConDetails)->whereBuildGrail.z = map[i+4];
  347. }
  348. nr=3;
  349. break;
  350. }
  351. case beatHero:
  352. {
  353. this->vicConDetails = new VicCon5();
  354. ((VicCon5*)this->vicConDetails)->locationOfHero.x = map[i+2];
  355. ((VicCon5*)this->vicConDetails)->locationOfHero.y = map[i+3];
  356. ((VicCon5*)this->vicConDetails)->locationOfHero.z = map[i+4];
  357. nr=3;
  358. break;
  359. }
  360. case captureCity:
  361. {
  362. this->vicConDetails = new VicCon6();
  363. ((VicCon6*)this->vicConDetails)->locationOfTown.x = map[i+2];
  364. ((VicCon6*)this->vicConDetails)->locationOfTown.y = map[i+3];
  365. ((VicCon6*)this->vicConDetails)->locationOfTown.z = map[i+4];
  366. nr=3;
  367. break;
  368. }
  369. case beatMonster:
  370. {
  371. this->vicConDetails = new VicCon7();
  372. ((VicCon7*)this->vicConDetails)->locationOfMonster.x = map[i+2];
  373. ((VicCon7*)this->vicConDetails)->locationOfMonster.y = map[i+3];
  374. ((VicCon7*)this->vicConDetails)->locationOfMonster.z = map[i+4];
  375. nr=3;
  376. break;
  377. }
  378. case takeDwellings:
  379. {
  380. this->vicConDetails = new CspecificVictoryConidtions();
  381. nr=3;
  382. break;
  383. }
  384. case takeMines:
  385. {
  386. this->vicConDetails = new CspecificVictoryConidtions();
  387. nr=3;
  388. break;
  389. }
  390. case transportItem:
  391. {
  392. this->vicConDetails = new VicCona();
  393. ((VicCona*)this->vicConDetails)->artifactID = map[i+2];
  394. ((VicCona*)this->vicConDetails)->destinationPlace.x = map[i+3];
  395. ((VicCona*)this->vicConDetails)->destinationPlace.y = map[i+4];
  396. ((VicCona*)this->vicConDetails)->destinationPlace.z = map[i+5];
  397. nr=4;
  398. break;
  399. }
  400. }
  401. this->vicConDetails->allowNormalVictory = map[i++];
  402. this->vicConDetails->appliesToAI = map[i++];
  403. i+=nr;
  404. }
  405. this->lossCondition.typeOfLossCon = (ElossCon)map[i++];
  406. switch (this->lossCondition.typeOfLossCon) //read loss conditions
  407. {
  408. case lossCastle:
  409. {
  410. this->lossCondition.castlePos.x=map[i++];
  411. this->lossCondition.castlePos.y=map[i++];
  412. this->lossCondition.castlePos.z=map[i++];
  413. }
  414. case lossHero:
  415. {
  416. this->lossCondition.heroPos.x=map[i++];
  417. this->lossCondition.heroPos.y=map[i++];
  418. this->lossCondition.heroPos.z=map[i++];
  419. }
  420. case timeExpires:
  421. {
  422. this->lossCondition.timeLimit = readNormalNr(map, i++,2);
  423. i++;
  424. }
  425. }
  426. this->howManyTeams=map[i++]; //read number of teams
  427. if(this->howManyTeams>0) //read team numbers
  428. {
  429. for(int rr=0; rr<8; ++rr)
  430. {
  431. this->players[rr].team=map[i++];
  432. }
  433. }
  434. }
  435. void Mapa::initFromBytes(unsigned char * bufor)
  436. {
  437. timeHandler th;
  438. th.getDif();
  439. int i=0;
  440. readHeader(bufor, i);
  441. std::cout<<"\tReading header: "<<th.getDif()<<std::endl;
  442. readRumors(bufor, i);
  443. std::cout<<"\tReading rumors: "<<th.getDif()<<std::endl;
  444. readPredefinedHeroes(bufor, i);
  445. std::cout<<"\tReading predefined heroes: "<<th.getDif()<<std::endl;
  446. readTerrain(bufor, i);
  447. std::cout<<"\tReading terrain: "<<th.getDif()<<std::endl;
  448. readDefInfo(bufor, i);
  449. std::cout<<"\tReading defs info: "<<th.getDif()<<std::endl;
  450. readObjects(bufor, i);
  451. std::cout<<"\tReading objects: "<<th.getDif()<<std::endl;
  452. readEvents(bufor, i);
  453. std::cout<<"\tReading events: "<<th.getDif()<<std::endl;
  454. //map readed, bufor no longer needed
  455. delete[] bufor; bufor=NULL;
  456. for(int f=0; f<objects.size(); ++f) //calculationg blocked / visitable positions
  457. {
  458. if(!objects[f]->defInfo)
  459. continue;
  460. addBlockVisTiles(objects[f]);
  461. }
  462. }
  463. void Mapa::removeBlockVisTiles(CGObjectInstance * obj)
  464. {
  465. for(int fx=0; fx<8; ++fx)
  466. {
  467. for(int fy=0; fy<6; ++fy)
  468. {
  469. int xVal = obj->pos.x + fx - 7;
  470. int yVal = obj->pos.y + fy - 5;
  471. int zVal = obj->pos.z;
  472. if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
  473. {
  474. TerrainTile & curt = terrain[xVal][yVal][zVal];
  475. if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
  476. {
  477. curt.visitableObjects -= obj;
  478. curt.visitable = curt.visitableObjects.size();
  479. }
  480. if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
  481. {
  482. curt.blockingObjects -= obj;
  483. curt.blocked = curt.visitableObjects.size();
  484. }
  485. }
  486. }
  487. }
  488. }
  489. void Mapa::addBlockVisTiles(CGObjectInstance * obj)
  490. {
  491. for(int fx=0; fx<8; ++fx)
  492. {
  493. for(int fy=0; fy<6; ++fy)
  494. {
  495. int xVal = obj->pos.x + fx - 7;
  496. int yVal = obj->pos.y + fy - 5;
  497. int zVal = obj->pos.z;
  498. if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
  499. {
  500. TerrainTile & curt = terrain[xVal][yVal][zVal];
  501. if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
  502. {
  503. curt.visitableObjects.push_back(obj);
  504. curt.visitable = true;
  505. }
  506. if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
  507. {
  508. curt.blockingObjects.push_back(obj);
  509. curt.blocked = true;
  510. }
  511. }
  512. }
  513. }
  514. }
  515. Mapa::Mapa(std::string filename)
  516. {
  517. std::cout<<"Opening map file: "<<filename<<"\t "<<std::flush;
  518. gzFile map = gzopen(filename.c_str(),"rb");
  519. std::vector<unsigned char> mapstr; int pom;
  520. while((pom=gzgetc(map))>=0)
  521. {
  522. mapstr.push_back(pom);
  523. }
  524. gzclose(map);
  525. unsigned char *initTable = new unsigned char[mapstr.size()];
  526. for(int ss=0; ss<mapstr.size(); ++ss)
  527. {
  528. initTable[ss] = mapstr[ss];
  529. }
  530. std::cout<<"done."<<std::endl;
  531. boost::crc_32_type result;
  532. result.process_bytes(initTable,mapstr.size());
  533. checksum = result.checksum();
  534. std::cout << "\tOur map checksum: "<<result.checksum() << std::endl;
  535. initFromBytes(initTable);
  536. }
  537. CGHeroInstance * Mapa::getHero(int ID, int mode)
  538. {
  539. if (mode != 0)
  540. #ifndef __GNUC__
  541. throw new std::exception("gs->getHero: This mode is not supported!");
  542. #else
  543. throw new std::exception();
  544. #endif
  545. for(int i=0; i<heroes.size();i++)
  546. if(heroes[i]->subID == ID)
  547. return heroes[i];
  548. return NULL;
  549. }
  550. int Mapa::loadSeerHut( unsigned char * bufor, int i, CGObjectInstance * nobj )
  551. {
  552. CSeerHutObjInfo * spec = new CSeerHutObjInfo;
  553. if(version>RoE)
  554. {
  555. spec->missionType = bufor[i]; ++i;
  556. switch(spec->missionType)
  557. {
  558. case 0:
  559. i+=3;
  560. return i;
  561. case 1:
  562. {
  563. spec->m1level = readNormalNr(bufor,i); i+=4;
  564. int limit = readNormalNr(bufor,i); i+=4;
  565. if(limit == ((int)0xffffffff))
  566. {
  567. spec->isDayLimit = false;
  568. spec->lastDay = -1;
  569. }
  570. else
  571. {
  572. spec->isDayLimit = true;
  573. spec->lastDay = limit;
  574. }
  575. break;
  576. }
  577. case 2:
  578. {
  579. spec->m2attack = bufor[i]; ++i;
  580. spec->m2defence = bufor[i]; ++i;
  581. spec->m2power = bufor[i]; ++i;
  582. spec->m2knowledge = bufor[i]; ++i;
  583. int limit = readNormalNr(bufor,i); i+=4;
  584. if(limit == ((int)0xffffffff))
  585. {
  586. spec->isDayLimit = false;
  587. spec->lastDay = -1;
  588. }
  589. else
  590. {
  591. spec->isDayLimit = true;
  592. spec->lastDay = limit;
  593. }
  594. break;
  595. }
  596. case 3:
  597. {
  598. spec->m3bytes[0] = bufor[i]; ++i;
  599. spec->m3bytes[1] = bufor[i]; ++i;
  600. spec->m3bytes[2] = bufor[i]; ++i;
  601. spec->m3bytes[3] = bufor[i]; ++i;
  602. int limit = readNormalNr(bufor,i); i+=4;
  603. if(limit == ((int)0xffffffff))
  604. {
  605. spec->isDayLimit = false;
  606. spec->lastDay = -1;
  607. }
  608. else
  609. {
  610. spec->isDayLimit = true;
  611. spec->lastDay = limit;
  612. }
  613. break;
  614. }
  615. case 4:
  616. {
  617. spec->m4bytes[0] = bufor[i]; ++i;
  618. spec->m4bytes[1] = bufor[i]; ++i;
  619. spec->m4bytes[2] = bufor[i]; ++i;
  620. spec->m4bytes[3] = bufor[i]; ++i;
  621. int limit = readNormalNr(bufor,i); i+=4;
  622. if(limit == ((int)0xffffffff))
  623. {
  624. spec->isDayLimit = false;
  625. spec->lastDay = -1;
  626. }
  627. else
  628. {
  629. spec->isDayLimit = true;
  630. spec->lastDay = limit;
  631. }
  632. break;
  633. }
  634. case 5:
  635. {
  636. int artNumber = bufor[i]; ++i;
  637. for(int yy=0; yy<artNumber; ++yy)
  638. {
  639. int artid = readNormalNr(bufor,i, 2); i+=2;
  640. spec->m5arts.push_back(artid);
  641. }
  642. int limit = readNormalNr(bufor,i); i+=4;
  643. if(limit == ((int)0xffffffff))
  644. {
  645. spec->isDayLimit = false;
  646. spec->lastDay = -1;
  647. }
  648. else
  649. {
  650. spec->isDayLimit = true;
  651. spec->lastDay = limit;
  652. }
  653. break;
  654. }
  655. case 6:
  656. {
  657. int typeNumber = bufor[i]; ++i;
  658. for(int hh=0; hh<typeNumber; ++hh)
  659. {
  660. int creType = readNormalNr(bufor,i, 2); i+=2;
  661. int creNumb = readNormalNr(bufor,i, 2); i+=2;
  662. spec->m6cre.push_back(&(VLC->creh->creatures[creType]));
  663. spec->m6number.push_back(creNumb);
  664. }
  665. int limit = readNormalNr(bufor,i); i+=4;
  666. if(limit == ((int)0xffffffff))
  667. {
  668. spec->isDayLimit = false;
  669. spec->lastDay = -1;
  670. }
  671. else
  672. {
  673. spec->isDayLimit = true;
  674. spec->lastDay = limit;
  675. }
  676. break;
  677. }
  678. case 7:
  679. {
  680. spec->m7wood = readNormalNr(bufor,i); i+=4;
  681. spec->m7mercury = readNormalNr(bufor,i); i+=4;
  682. spec->m7ore = readNormalNr(bufor,i); i+=4;
  683. spec->m7sulfur = readNormalNr(bufor,i); i+=4;
  684. spec->m7crystal = readNormalNr(bufor,i); i+=4;
  685. spec->m7gems = readNormalNr(bufor,i); i+=4;
  686. spec->m7gold = readNormalNr(bufor,i); i+=4;
  687. int limit = readNormalNr(bufor,i); i+=4;
  688. if(limit == ((int)0xffffffff))
  689. {
  690. spec->isDayLimit = false;
  691. spec->lastDay = -1;
  692. }
  693. else
  694. {
  695. spec->isDayLimit = true;
  696. spec->lastDay = limit;
  697. }
  698. break;
  699. }
  700. case 8:
  701. {
  702. int heroType = bufor[i]; ++i;
  703. spec->m8hero = heroType;
  704. int limit = readNormalNr(bufor,i); i+=4;
  705. if(limit == ((int)0xffffffff))
  706. {
  707. spec->isDayLimit = false;
  708. spec->lastDay = -1;
  709. }
  710. else
  711. {
  712. spec->isDayLimit = true;
  713. spec->lastDay = limit;
  714. }
  715. break;
  716. }
  717. case 9:
  718. {
  719. spec->m9player = bufor[i]; ++i;
  720. int limit = readNormalNr(bufor,i); i+=4;
  721. if(limit == ((int)0xffffffff))
  722. {
  723. spec->isDayLimit = false;
  724. spec->lastDay = -1;
  725. }
  726. else
  727. {
  728. spec->isDayLimit = true;
  729. spec->lastDay = limit;
  730. }
  731. break;
  732. }
  733. }//internal switch end (seer huts)
  734. int len1 = readNormalNr(bufor,i); i+=4;
  735. for(int ee=0; ee<len1; ++ee)
  736. {
  737. spec->firstVisitText += bufor[i]; ++i;
  738. }
  739. int len2 = readNormalNr(bufor,i); i+=4;
  740. for(int ee=0; ee<len2; ++ee)
  741. {
  742. spec->nextVisitText += bufor[i]; ++i;
  743. }
  744. int len3 = readNormalNr(bufor,i); i+=4;
  745. for(int ee=0; ee<len3; ++ee)
  746. {
  747. spec->completedText += bufor[i]; ++i;
  748. }
  749. }
  750. else //RoE
  751. {
  752. int artID = bufor[i]; ++i;
  753. if(artID!=255) //not none quest
  754. {
  755. spec->m5arts.push_back(artID);
  756. spec->missionType = 5;
  757. }
  758. else
  759. {
  760. spec->missionType = 255;
  761. }
  762. }
  763. if(spec->missionType!=255)
  764. {
  765. unsigned char rewardType = bufor[i]; ++i;
  766. spec->rewardType = rewardType;
  767. switch(rewardType)
  768. {
  769. case 1:
  770. {
  771. spec->r1exp = readNormalNr(bufor,i); i+=4;
  772. break;
  773. }
  774. case 2:
  775. {
  776. spec->r2mana = readNormalNr(bufor,i); i+=4;
  777. break;
  778. }
  779. case 3:
  780. {
  781. spec->r3morale = bufor[i]; ++i;
  782. break;
  783. }
  784. case 4:
  785. {
  786. spec->r4luck = bufor[i]; ++i;
  787. break;
  788. }
  789. case 5:
  790. {
  791. spec->r5type = bufor[i]; ++i;
  792. spec->r5amount = readNormalNr(bufor,i, 3); i+=3;
  793. i+=1;
  794. break;
  795. }
  796. case 6:
  797. {
  798. spec->r6type = bufor[i]; ++i;
  799. spec->r6amount = bufor[i]; ++i;
  800. break;
  801. }
  802. case 7:
  803. {
  804. spec->r7ability = bufor[i]; ++i;
  805. spec->r7level = bufor[i]; ++i;
  806. break;
  807. }
  808. case 8:
  809. {
  810. spec->r8art = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2);
  811. break;
  812. }
  813. case 9:
  814. {
  815. spec->r9spell = bufor[i]; ++i;
  816. break;
  817. }
  818. case 10:
  819. {
  820. if(version>RoE)
  821. {
  822. spec->r10creature = readNormalNr(bufor,i, 2); i+=2;
  823. spec->r10amount = readNormalNr(bufor,i, 2); i+=2;
  824. }
  825. else
  826. {
  827. spec->r10creature = bufor[i]; ++i;
  828. spec->r10amount = readNormalNr(bufor,i, 2); i+=2;
  829. }
  830. break;
  831. }
  832. }// end of internal switch
  833. i+=2;
  834. }
  835. else //missionType==255
  836. {
  837. i+=3;
  838. }
  839. nobj->info = spec;
  840. return i;
  841. }
  842. void Mapa::loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
  843. {
  844. CGTownInstance * nt = new CGTownInstance();
  845. (*(static_cast<CGObjectInstance*>(nt))) = *nobj;
  846. delete nobj;
  847. nobj = nt;
  848. nt->identifier = 0;
  849. if(version>RoE)
  850. {
  851. readNormalNr(bufor,i); i+=4;
  852. }
  853. nt->tempOwner = bufor[i]; ++i;
  854. if(readChar(bufor,i)) //has name
  855. nt->name = readString(bufor,i);
  856. if(readChar(bufor,i))//true if garrison isn't empty
  857. nt->army = readCreatureSet(bufor,i,7,(version>RoE));
  858. nt->army.formation = bufor[i]; ++i;
  859. if(readChar(bufor,i)) //unusualBuildings
  860. {
  861. //built buildings
  862. for(int byte=0;byte<6;byte++)
  863. {
  864. for(int bit=0;bit<8;bit++)
  865. if(bufor[i] & (1<<bit))
  866. nt->builtBuildings.insert(byte*8+bit);
  867. i++;
  868. }
  869. //forbidden buildings
  870. for(int byte=6;byte<12;byte++)
  871. {
  872. for(int bit=0;bit<8;bit++)
  873. if(bufor[i] & (1<<bit))
  874. nt->forbiddenBuildings.insert((byte-6)*8+bit);
  875. i++;
  876. }
  877. nt->builtBuildings = convertBuildings(nt->builtBuildings,nt->subID);
  878. nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID);
  879. }
  880. else //standard buildings
  881. {
  882. if(readChar(bufor,i)) //has fort
  883. nt->builtBuildings.insert(7);
  884. nt->builtBuildings.insert(-50); //means that set of standard building should be included
  885. }
  886. int ist = i;
  887. if(version>RoE)
  888. {
  889. for(i; i<ist+9; ++i)
  890. {
  891. unsigned char c = bufor[i];
  892. for(int yy=0; yy<8; ++yy)
  893. {
  894. if((i-ist)*8+yy < SPELLS_QUANTITY)
  895. {
  896. if(c == (c|((unsigned char)intPow(2, yy))))
  897. nt->obligatorySpells.push_back((i-ist)*8+yy);
  898. }
  899. }
  900. }
  901. }
  902. ist = i;
  903. for(i; i<ist+9; ++i)
  904. {
  905. unsigned char c = bufor[i];
  906. for(int yy=0; yy<8; ++yy)
  907. {
  908. if((i-ist)*8+yy < SPELLS_QUANTITY)
  909. {
  910. if(c != (c|((unsigned char)intPow(2, yy))))
  911. nt->possibleSpells.push_back((i-ist)*8+yy);
  912. }
  913. }
  914. }
  915. /////// reading castle events //////////////////////////////////
  916. int numberOfEvent = readNormalNr(bufor,i); i+=4;
  917. for(int gh = 0; gh<numberOfEvent; ++gh)
  918. {
  919. CCastleEvent nce;
  920. int nameLen = readNormalNr(bufor,i); i+=4;
  921. for(int ll=0; ll<nameLen; ++ll)
  922. {
  923. nce.name += bufor[i]; ++i;
  924. }
  925. int messLen = readNormalNr(bufor,i); i+=4;
  926. for(int ll=0; ll<messLen; ++ll)
  927. {
  928. nce.message += bufor[i]; ++i;
  929. }
  930. nce.wood = readNormalNr(bufor,i); i+=4;
  931. nce.mercury = readNormalNr(bufor,i); i+=4;
  932. nce.ore = readNormalNr(bufor,i); i+=4;
  933. nce.sulfur = readNormalNr(bufor,i); i+=4;
  934. nce.crystal = readNormalNr(bufor,i); i+=4;
  935. nce.gems = readNormalNr(bufor,i); i+=4;
  936. nce.gold = readNormalNr(bufor,i); i+=4;
  937. nce.players = bufor[i]; ++i;
  938. if(version > AB)
  939. {
  940. nce.forHuman = bufor[i]; ++i;
  941. }
  942. else
  943. nce.forHuman = true;
  944. nce.forComputer = bufor[i]; ++i;
  945. nce.firstShow = readNormalNr(bufor,i, 2); i+=2;
  946. nce.forEvery = bufor[i]; ++i;
  947. i+=17;
  948. for(int kk=0; kk<6; ++kk)
  949. {
  950. nce.bytes[kk] = bufor[i]; ++i;
  951. }
  952. for(int vv=0; vv<7; ++vv)
  953. {
  954. nce.gen[vv] = readNormalNr(bufor,i, 2); i+=2;
  955. }
  956. i+=4;
  957. nt->events.insert(nce);
  958. }//castle events have been read
  959. if(version > AB)
  960. {
  961. nt->alignment = bufor[i]; ++i;
  962. }
  963. else
  964. nt->alignment = 0xff;
  965. i+=3;
  966. nt->builded = 0;
  967. nt->destroyed = 0;
  968. nt->garrisonHero = NULL;
  969. if(nt->ID==98)
  970. towns.push_back(nt);
  971. }
  972. void Mapa::loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
  973. {
  974. CGHeroInstance * nhi = new CGHeroInstance;
  975. (*(static_cast<CGObjectInstance*>(nhi))) = *nobj;
  976. delete nobj;
  977. nobj=nhi;
  978. if(version>RoE)
  979. {
  980. nhi->identifier = readNormalNr(bufor,i, 4); i+=4;
  981. }
  982. nhi->setOwner(bufor[i]); ++i;
  983. nhi->subID = readNormalNr(bufor,i, 1); ++i;
  984. if(readChar(bufor,i))//true if hero has nonstandard name
  985. nhi->name = readString(bufor,i);
  986. if(version>AB)
  987. {
  988. if(readChar(bufor,i))//true if hore's experience is greater than 0
  989. { nhi->exp = readNormalNr(bufor,i); i+=4; }
  990. else
  991. nhi->exp = -1;
  992. }
  993. else
  994. { nhi->exp = readNormalNr(bufor,i); i+=4; }
  995. bool portrait=bufor[i]; ++i;
  996. if (portrait)
  997. i++; //TODO read portrait nr, save, open
  998. else
  999. nhi->portrait = nhi->subID;
  1000. if(readChar(bufor,i))//true if hero has specified abilities
  1001. {
  1002. int howMany = readNormalNr(bufor,i); i+=4;
  1003. nhi->secSkills.resize(howMany);
  1004. for(int yy=0; yy<howMany; ++yy)
  1005. {
  1006. nhi->secSkills[yy].first = readNormalNr(bufor,i, 1); ++i;
  1007. nhi->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i;
  1008. }
  1009. }
  1010. if(readChar(bufor,i))//true if hero has nonstandard garrison
  1011. nhi->army = readCreatureSet(bufor,i,7,(version>RoE));
  1012. nhi->army.formation =bufor[i]; ++i; //formation
  1013. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  1014. int artmask = version == RoE ? 0xff : 0xffff;
  1015. int artidlen = version == RoE ? 1 : 2;
  1016. if(artSet)
  1017. {
  1018. for(int pom=0;pom<16;pom++)
  1019. {
  1020. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1021. if(id!=artmask)
  1022. nhi->artifWorn[pom] = id;
  1023. }
  1024. //misc5 art //17
  1025. if(version>=SoD)
  1026. {
  1027. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1028. if(id!=artmask)
  1029. nhi->artifWorn[16] = id;
  1030. }
  1031. //spellbook
  1032. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1033. if(id!=artmask)
  1034. nhi->artifWorn[17] = id;
  1035. //19 //???what is that? gap in file or what? - it's probably fifth slot..
  1036. if(version>RoE)
  1037. {
  1038. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1039. if(id!=artmask)
  1040. nhi->artifWorn[18] = id;
  1041. }
  1042. else
  1043. i+=1;
  1044. //bag artifacts //20
  1045. int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag
  1046. if(amount>0)
  1047. {
  1048. for(int ss=0; ss<amount; ++ss)
  1049. {
  1050. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1051. if(id!=artmask)
  1052. nhi->artifacts.push_back(id);
  1053. }
  1054. }
  1055. } //artifacts
  1056. nhi->patrol.patrolRadious = readNormalNr(bufor,i, 1); ++i;
  1057. if(nhi->patrol.patrolRadious == 0xff)
  1058. nhi->patrol.patrolling = false;
  1059. else
  1060. nhi->patrol.patrolling = true;
  1061. if(version>RoE)
  1062. {
  1063. if(readChar(bufor,i))//true if hero has nonstandard (mapmaker defined) biography
  1064. nhi->biography = readString(bufor,i);
  1065. nhi->sex = !(bufor[i]); ++i;
  1066. }
  1067. //spells
  1068. if(version>AB)
  1069. {
  1070. bool areSpells = bufor[i]; ++i;
  1071. if(areSpells) //TODO: sprawdziæ //seems to be ok - tow
  1072. {
  1073. int ist = i;
  1074. for(i; i<ist+9; ++i)
  1075. {
  1076. unsigned char c = bufor[i];
  1077. for(int yy=0; yy<8; ++yy)
  1078. {
  1079. if((i-ist)*8+yy < SPELLS_QUANTITY)
  1080. {
  1081. if(c == (c|((unsigned char)intPow(2, yy))))
  1082. nhi->spells.insert((i-ist)*8+yy);
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. else if(version==AB) //we can read one spell
  1089. {
  1090. unsigned char buff = bufor[i]; ++i;
  1091. if(buff!=254)
  1092. {
  1093. nhi->spells.insert(buff);
  1094. }
  1095. }
  1096. //spells loaded
  1097. if(version>AB)
  1098. {
  1099. if(readChar(bufor,i))//customPrimSkills
  1100. {
  1101. nhi->primSkills.resize(4);
  1102. for(int xx=0;xx<4;xx++)
  1103. nhi->primSkills[xx] = bufor[i++];
  1104. }
  1105. }
  1106. i+=16;
  1107. nhi->moveDir = 4;
  1108. nhi->isStanding = true;
  1109. nhi->level = -1;
  1110. nhi->mana = -1;
  1111. nhi->movement = -1;
  1112. if(nhi->ID==34)
  1113. heroes.push_back(nhi);
  1114. }
  1115. void Mapa::loadPlayerInfo( int &pom, unsigned char * bufor, int &i )
  1116. {
  1117. for (pom=0;pom<8;pom++)
  1118. {
  1119. players[pom].canHumanPlay = bufor[i++];
  1120. players[pom].canComputerPlay = bufor[i++];
  1121. if ((!(players[pom].canHumanPlay || players[pom].canComputerPlay)))
  1122. {
  1123. memset(&players[pom],0,sizeof(PlayerInfo));
  1124. switch(version)
  1125. {
  1126. case SoD: case WoG:
  1127. i+=13;
  1128. break;
  1129. case AB:
  1130. i+=12;
  1131. break;
  1132. case RoE:
  1133. i+=6;
  1134. break;
  1135. }
  1136. continue;
  1137. }
  1138. players[pom].AITactic = bufor[i++];
  1139. if(version == SoD || version == WoG)
  1140. players[pom].p7= bufor[i++];
  1141. else
  1142. players[pom].p7= -1;
  1143. players[pom].allowedFactions = 0;
  1144. players[pom].allowedFactions += bufor[i++];
  1145. if(version != RoE)
  1146. players[pom].allowedFactions += (bufor[i++])*256;
  1147. players[pom].isFactionRandom = bufor[i++];
  1148. players[pom].hasMainTown = bufor[i++];
  1149. if (players[pom].hasMainTown)
  1150. {
  1151. if(version != RoE)
  1152. {
  1153. players[pom].generateHeroAtMainTown = bufor[i++];
  1154. players[pom].generateHero = bufor[i++];
  1155. }
  1156. else
  1157. {
  1158. players[pom].generateHeroAtMainTown = false;
  1159. players[pom].generateHero = false;
  1160. }
  1161. players[pom].posOfMainTown.x = bufor[i++];
  1162. players[pom].posOfMainTown.y = bufor[i++];
  1163. players[pom].posOfMainTown.z = bufor[i++];
  1164. }
  1165. players[pom].p8= bufor[i++];
  1166. players[pom].p9= bufor[i++];
  1167. if(players[pom].p9!=0xff)
  1168. {
  1169. players[pom].mainHeroPortrait = bufor[i++];
  1170. int nameLength = bufor[i++];
  1171. i+=3;
  1172. for (int pp=0;pp<nameLength;pp++)
  1173. players[pom].mainHeroName+=bufor[i++];
  1174. }
  1175. if(version != RoE)
  1176. {
  1177. i++; ////unknown byte
  1178. int heroCount = bufor[i++];
  1179. i+=3;
  1180. for (int pp=0;pp<heroCount;pp++)
  1181. {
  1182. SheroName vv;
  1183. vv.heroID=bufor[i++];
  1184. int hnl = bufor[i++];
  1185. i+=3;
  1186. for (int zz=0;zz<hnl;zz++)
  1187. {
  1188. vv.heroName+=bufor[i++];
  1189. }
  1190. players[pom].heroesNames.push_back(vv);
  1191. }
  1192. }
  1193. }
  1194. }
  1195. void Mapa::loadViCLossConditions( unsigned char * bufor, int &i)
  1196. {
  1197. victoryCondition = (EvictoryConditions)bufor[i++];
  1198. if (victoryCondition != winStandard) //specific victory conditions
  1199. {
  1200. int nr;
  1201. switch (victoryCondition) //read victory conditions
  1202. {
  1203. case artifact:
  1204. {
  1205. vicConDetails = new VicCon0();
  1206. ((VicCon0*)vicConDetails)->ArtifactID = bufor[i+2];
  1207. nr=(version==RoE ? 1 : 2);
  1208. break;
  1209. }
  1210. case gatherTroop:
  1211. {
  1212. vicConDetails = new VicCon1();
  1213. int temp1 = bufor[i+2];
  1214. int temp2 = bufor[i+3];
  1215. ((VicCon1*)vicConDetails)->monsterID = bufor[i+2];
  1216. ((VicCon1*)vicConDetails)->neededQuantity=readNormalNr(bufor,i+(version==RoE ? 3 : 4));
  1217. nr=(version==RoE ? 5 : 6);
  1218. break;
  1219. }
  1220. case gatherResource:
  1221. {
  1222. vicConDetails = new VicCon2();
  1223. ((VicCon2*)vicConDetails)->resourceID = bufor[i+2];
  1224. ((VicCon2*)vicConDetails)->neededQuantity=readNormalNr(bufor,i+3);
  1225. nr=5;
  1226. break;
  1227. }
  1228. case buildCity:
  1229. {
  1230. vicConDetails = new VicCon3();
  1231. ((VicCon3*)vicConDetails)->posOfCity.x = bufor[i+2];
  1232. ((VicCon3*)vicConDetails)->posOfCity.y = bufor[i+3];
  1233. ((VicCon3*)vicConDetails)->posOfCity.z = bufor[i+4];
  1234. ((VicCon3*)vicConDetails)->councilNeededLevel = bufor[i+5];
  1235. ((VicCon3*)vicConDetails)->fortNeededLevel = bufor[i+6];
  1236. nr=5;
  1237. break;
  1238. }
  1239. case buildGrail:
  1240. {
  1241. vicConDetails = new VicCon4();
  1242. if (bufor[i+4]>2)
  1243. ((VicCon4*)vicConDetails)->anyLocation = true;
  1244. else
  1245. {
  1246. ((VicCon4*)vicConDetails)->whereBuildGrail.x = bufor[i+2];
  1247. ((VicCon4*)vicConDetails)->whereBuildGrail.y = bufor[i+3];
  1248. ((VicCon4*)vicConDetails)->whereBuildGrail.z = bufor[i+4];
  1249. }
  1250. nr=3;
  1251. break;
  1252. }
  1253. case beatHero:
  1254. {
  1255. vicConDetails = new VicCon5();
  1256. ((VicCon5*)vicConDetails)->locationOfHero.x = bufor[i+2];
  1257. ((VicCon5*)vicConDetails)->locationOfHero.y = bufor[i+3];
  1258. ((VicCon5*)vicConDetails)->locationOfHero.z = bufor[i+4];
  1259. nr=3;
  1260. break;
  1261. }
  1262. case captureCity:
  1263. {
  1264. vicConDetails = new VicCon6();
  1265. ((VicCon6*)vicConDetails)->locationOfTown.x = bufor[i+2];
  1266. ((VicCon6*)vicConDetails)->locationOfTown.y = bufor[i+3];
  1267. ((VicCon6*)vicConDetails)->locationOfTown.z = bufor[i+4];
  1268. nr=3;
  1269. break;
  1270. }
  1271. case beatMonster:
  1272. {
  1273. vicConDetails = new VicCon7();
  1274. ((VicCon7*)vicConDetails)->locationOfMonster.x = bufor[i+2];
  1275. ((VicCon7*)vicConDetails)->locationOfMonster.y = bufor[i+3];
  1276. ((VicCon7*)vicConDetails)->locationOfMonster.z = bufor[i+4];
  1277. nr=3;
  1278. break;
  1279. }
  1280. case takeDwellings:
  1281. {
  1282. vicConDetails = new CspecificVictoryConidtions();
  1283. nr=0;
  1284. break;
  1285. }
  1286. case takeMines:
  1287. {
  1288. vicConDetails = new CspecificVictoryConidtions();
  1289. nr=0;
  1290. break;
  1291. }
  1292. case transportItem:
  1293. {
  1294. vicConDetails = new VicCona();
  1295. ((VicCona*)vicConDetails)->artifactID = bufor[i+2];
  1296. ((VicCona*)vicConDetails)->destinationPlace.x = bufor[i+3];
  1297. ((VicCona*)vicConDetails)->destinationPlace.y = bufor[i+4];
  1298. ((VicCona*)vicConDetails)->destinationPlace.z = bufor[i+5];
  1299. nr=4;
  1300. break;
  1301. }
  1302. }
  1303. vicConDetails->allowNormalVictory = bufor[i++];
  1304. vicConDetails->appliesToAI = bufor[i++];
  1305. i+=nr;
  1306. }
  1307. lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
  1308. switch (lossCondition.typeOfLossCon) //read loss conditions
  1309. {
  1310. case lossCastle:
  1311. {
  1312. lossCondition.castlePos.x=bufor[i++];
  1313. lossCondition.castlePos.y=bufor[i++];
  1314. lossCondition.castlePos.z=bufor[i++];
  1315. break;
  1316. }
  1317. case lossHero:
  1318. {
  1319. lossCondition.heroPos.x=bufor[i++];
  1320. lossCondition.heroPos.y=bufor[i++];
  1321. lossCondition.heroPos.z=bufor[i++];
  1322. break;
  1323. }
  1324. case timeExpires:
  1325. {
  1326. lossCondition.timeLimit = readNormalNr(bufor,i++,2);
  1327. i++;
  1328. break;
  1329. }
  1330. }
  1331. }
  1332. void Mapa::readRumors( unsigned char * bufor, int &i)
  1333. {
  1334. int rumNr = readNormalNr(bufor,i,4);i+=4;
  1335. for (int it=0;it<rumNr;it++)
  1336. {
  1337. Rumor ourRumor;
  1338. int nameL = readNormalNr(bufor,i,4);i+=4; //read length of name of rumor
  1339. for (int zz=0; zz<nameL; zz++)
  1340. ourRumor.name+=bufor[i++];
  1341. nameL = readNormalNr(bufor,i,4);i+=4; //read length of rumor
  1342. for (int zz=0; zz<nameL; zz++)
  1343. ourRumor.text+=bufor[i++];
  1344. rumors.push_back(ourRumor); //add to our list
  1345. }
  1346. }
  1347. void Mapa::readHeader( unsigned char * bufor, int &i)
  1348. {
  1349. version = (Eformat)(readNormalNr(bufor,i)); i+=4; //map version
  1350. areAnyPLayers = readChar(bufor,i); //invalid on some maps
  1351. height = width = (readNormalNr(bufor,i)); i+=4; // wymiary mapy
  1352. twoLevel = readChar(bufor,i); //czy sa lochy
  1353. terrain = new TerrainTile**[width]; // allocate memory
  1354. for (int ii=0;ii<width;ii++)
  1355. {
  1356. terrain[ii] = new TerrainTile*[height]; // allocate memory
  1357. for(int jj=0;jj<height;jj++)
  1358. terrain[ii][jj] = new TerrainTile[twoLevel+1];
  1359. }
  1360. int pom;
  1361. name = readString(bufor,i);
  1362. description= readString(bufor,i);
  1363. difficulty = readChar(bufor,i); // reading map difficulty
  1364. if(version != RoE)
  1365. levelLimit = readChar(bufor,i); // hero level limit
  1366. else
  1367. levelLimit = 0;
  1368. loadPlayerInfo(pom, bufor, i);
  1369. loadViCLossConditions(bufor, i);
  1370. howManyTeams=bufor[i++]; //read number of teams
  1371. if(howManyTeams>0) //read team numbers
  1372. {
  1373. for(int rr=0; rr<8; ++rr)
  1374. {
  1375. players[rr].team=bufor[i++];
  1376. }
  1377. }
  1378. //reading allowed heroes (20 bytes)
  1379. int ist;
  1380. ist=i; //starting i for loop
  1381. allowedHeroes.resize(HEROES_QUANTITY);
  1382. for(int xx=0;xx<HEROES_QUANTITY;xx++)
  1383. allowedHeroes[xx] = true;
  1384. for(i; i<ist+ (version == RoE ? 16 : 20) ; ++i)
  1385. {
  1386. unsigned char c = bufor[i];
  1387. for(int yy=0; yy<8; ++yy)
  1388. if((i-ist)*8+yy < HEROES_QUANTITY)
  1389. if(c != (c|((unsigned char)intPow(2, yy))))
  1390. allowedHeroes[(i-ist)*8+yy] = false;
  1391. }
  1392. if(version>RoE) //probably reserved for further heroes
  1393. i+=4;
  1394. unsigned char disp = 0;
  1395. if(version>=SoD)
  1396. {
  1397. disp = bufor[i++];
  1398. disposedHeroes.resize(disp);
  1399. for(int g=0; g<disp; ++g)
  1400. {
  1401. disposedHeroes[g].ID = bufor[i++];
  1402. disposedHeroes[g].portrait = bufor[i++];
  1403. int lenbuf = readNormalNr(bufor,i); i+=4;
  1404. for (int zz=0; zz<lenbuf; zz++)
  1405. disposedHeroes[g].name+=bufor[i++];
  1406. int players = bufor[i++];
  1407. for(int zz=0;zz<8;zz++)
  1408. {
  1409. int por = (1<<zz);
  1410. if(players & por)
  1411. disposedHeroes[g].players[zz] = true;
  1412. else
  1413. disposedHeroes[g].players[zz] = false;
  1414. }
  1415. }
  1416. }
  1417. i+=31; //omitting NULLS
  1418. allowedArtifact.resize(ARTIFACTS_QUANTITY);
  1419. for(int x=0;x<allowedArtifact.size();x++)
  1420. allowedArtifact[x] = true;
  1421. //reading allowed artifacts: 17 or 18 bytes
  1422. if(version!=RoE)
  1423. {
  1424. ist=i; //starting i for loop
  1425. for(i; i<ist+(version==AB ? 17 : 18); ++i)
  1426. {
  1427. unsigned char c = bufor[i];
  1428. for(int yy=0; yy<8; ++yy)
  1429. {
  1430. if((i-ist)*8+yy < ARTIFACTS_QUANTITY)
  1431. {
  1432. if(c == (c|((unsigned char)intPow(2, yy))))
  1433. allowedArtifact[(i-ist)*8+yy] = false;
  1434. }
  1435. }
  1436. }//allowed artifacts have been read
  1437. }
  1438. allowedSpell.resize(SPELLS_QUANTITY);
  1439. for(int x=0;x<allowedSpell.size();x++)
  1440. allowedSpell[x] = true;
  1441. allowedAbilities.resize(SKILL_QUANTITY);
  1442. for(int x=0;x<allowedAbilities.size();x++)
  1443. allowedAbilities[x] = true;
  1444. if(version>=SoD)
  1445. {
  1446. //reading allowed spells (9 bytes)
  1447. ist=i; //starting i for loop
  1448. for(i; i<ist+9; ++i)
  1449. {
  1450. unsigned char c = bufor[i];
  1451. for(int yy=0; yy<8; ++yy)
  1452. if((i-ist)*8+yy < SPELLS_QUANTITY)
  1453. if(c == (c|((unsigned char)intPow(2, yy))))
  1454. allowedSpell[(i-ist)*8+yy] = false;
  1455. }
  1456. //allowed hero's abilities (4 bytes)
  1457. ist=i; //starting i for loop
  1458. for(i; i<ist+4; ++i)
  1459. {
  1460. unsigned char c = bufor[i];
  1461. for(int yy=0; yy<8; ++yy)
  1462. {
  1463. if((i-ist)*8+yy < SKILL_QUANTITY)
  1464. {
  1465. if(c == (c|((unsigned char)intPow(2, yy))))
  1466. allowedAbilities[(i-ist)*8+yy] = false;
  1467. }
  1468. }
  1469. }
  1470. }
  1471. }
  1472. void Mapa::readPredefinedHeroes( unsigned char * bufor, int &i)
  1473. {
  1474. switch(version)
  1475. {
  1476. case WoG: case SoD:
  1477. {
  1478. for(int z=0;z<HEROES_QUANTITY;z++) //disposed heroes
  1479. {
  1480. int custom = bufor[i++];
  1481. if(!custom)
  1482. continue;
  1483. CGHeroInstance * cgh = new CGHeroInstance;
  1484. cgh->ID = 34;
  1485. cgh->subID = z;
  1486. if(readChar(bufor,i))//true if hore's experience is greater than 0
  1487. { cgh->exp = readNormalNr(bufor,i); i+=4; }
  1488. else
  1489. cgh->exp = 0;
  1490. if(readChar(bufor,i))//true if hero has specified abilities
  1491. {
  1492. int howMany = readNormalNr(bufor,i); i+=4;
  1493. cgh->secSkills.resize(howMany);
  1494. for(int yy=0; yy<howMany; ++yy)
  1495. {
  1496. cgh->secSkills[yy].first = readNormalNr(bufor,i, 1); ++i;
  1497. cgh->secSkills[yy].second = readNormalNr(bufor,i, 1); ++i;
  1498. }
  1499. }
  1500. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  1501. int artmask = version == RoE ? 0xff : 0xffff;
  1502. int artidlen = version == RoE ? 1 : 2;
  1503. if(artSet)
  1504. {
  1505. for(int pom=0;pom<16;pom++)
  1506. {
  1507. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1508. if(id!=artmask)
  1509. cgh->artifWorn[pom] = id;
  1510. }
  1511. //misc5 art //17
  1512. if(version>=SoD)
  1513. {
  1514. i+=2;
  1515. //int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1516. //if(id!=artmask)
  1517. // spec->artifWorn[16] = id;
  1518. }
  1519. //spellbook
  1520. int id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1521. if(id!=artmask)
  1522. cgh->artifWorn[17] = id;
  1523. //19 //???what is that? gap in file or what? - it's probably fifth slot..
  1524. if(version>RoE)
  1525. {
  1526. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1527. if(id!=artmask)
  1528. cgh->artifWorn[18] = id;
  1529. }
  1530. else
  1531. i+=1;
  1532. //bag artifacts //20
  1533. int amount = readNormalNr(bufor,i, 2); i+=2; //number of artifacts in hero's bag
  1534. if(amount>0)
  1535. {
  1536. for(int ss=0; ss<amount; ++ss)
  1537. {
  1538. id = readNormalNr(bufor,i, artidlen); i+=artidlen;
  1539. if(id!=artmask)
  1540. cgh->artifacts.push_back(id);
  1541. }
  1542. }
  1543. } //artifacts
  1544. if(readChar(bufor,i))//customBio
  1545. cgh->biography = readString(bufor,i);
  1546. int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female
  1547. if(readChar(bufor,i))//are spells
  1548. {
  1549. int ist = i;
  1550. for(i; i<ist+9; ++i)
  1551. {
  1552. unsigned char c = bufor[i];
  1553. for(int yy=0; yy<8; ++yy)
  1554. {
  1555. if((i-ist)*8+yy < SPELLS_QUANTITY)
  1556. {
  1557. if(c == (c|((unsigned char)intPow(2, yy))))
  1558. cgh->spells.insert((i-ist)*8+yy);
  1559. }
  1560. }
  1561. }
  1562. }
  1563. if(readChar(bufor,i))//customPrimSkills
  1564. {
  1565. cgh->primSkills.resize(4);
  1566. for(int xx=0;xx<4;xx++)
  1567. cgh->primSkills[xx] = bufor[i++];
  1568. }
  1569. predefinedHeroes.push_back(cgh);
  1570. }
  1571. break;
  1572. }
  1573. case RoE:
  1574. i+=0;
  1575. break;
  1576. }
  1577. }
  1578. void Mapa::readTerrain( unsigned char * bufor, int &i)
  1579. {
  1580. for (int c=0; c<width; c++) // reading terrain
  1581. {
  1582. for (int z=0; z<height; z++)
  1583. {
  1584. terrain[z][c][0].tertype = (EterrainType)(bufor[i++]);
  1585. terrain[z][c][0].terview = bufor[i++];
  1586. terrain[z][c][0].nuine = (Eriver)bufor[i++];
  1587. terrain[z][c][0].rivDir = bufor[i++];
  1588. terrain[z][c][0].malle = (Eroad)bufor[i++];
  1589. terrain[z][c][0].roadDir = bufor[i++];
  1590. terrain[z][c][0].siodmyTajemniczyBajt = bufor[i++];
  1591. terrain[z][c][0].blocked = 0;
  1592. terrain[z][c][0].visitable = 0;
  1593. }
  1594. }
  1595. if (twoLevel) // read underground terrain
  1596. {
  1597. for (int c=0; c<width; c++) // reading terrain
  1598. {
  1599. for (int z=0; z<height; z++)
  1600. {
  1601. terrain[z][c][1].tertype = (EterrainType)(bufor[i++]);
  1602. terrain[z][c][1].terview = bufor[i++];
  1603. terrain[z][c][1].nuine = (Eriver)bufor[i++];
  1604. terrain[z][c][1].rivDir = bufor[i++];
  1605. terrain[z][c][1].malle = (Eroad)bufor[i++];
  1606. terrain[z][c][1].roadDir = bufor[i++];
  1607. terrain[z][c][1].siodmyTajemniczyBajt = bufor[i++];
  1608. terrain[z][c][1].blocked = 0;
  1609. terrain[z][c][1].visitable = 0;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. void Mapa::readDefInfo( unsigned char * bufor, int &i)
  1615. {
  1616. int defAmount = readNormalNr(bufor,i); i+=4;
  1617. defy.reserve(defAmount);
  1618. for (int idd = 0 ; idd<defAmount; idd++) // reading defs
  1619. {
  1620. CGDefInfo * vinya = new CGDefInfo(); // info about new def
  1621. //reading name
  1622. int nameLength = readNormalNr(bufor,i,4);i+=4;
  1623. vinya->name.reserve(nameLength);
  1624. for (int cd=0;cd<nameLength;cd++)
  1625. {
  1626. vinya->name += bufor[i++];
  1627. }
  1628. std::transform(vinya->name.begin(),vinya->name.end(),vinya->name.begin(),(int(*)(int))toupper);
  1629. unsigned char bytes[12];
  1630. for (int v=0; v<12; v++) // read info
  1631. {
  1632. bytes[v] = bufor[i++];
  1633. }
  1634. vinya->terrainAllowed = readNormalNr(bufor,i,2);i+=2;
  1635. vinya->terrainMenu = readNormalNr(bufor,i,2);i+=2;
  1636. vinya->id = readNormalNr(bufor,i,4);i+=4;
  1637. vinya->subid = readNormalNr(bufor,i,4);i+=4;
  1638. vinya->type = bufor[i++];
  1639. vinya->printPriority = bufor[i++];
  1640. for (int zi=0; zi<6; zi++)
  1641. {
  1642. vinya->blockMap[zi] = reverse(bytes[zi]);
  1643. }
  1644. for (int zi=0; zi<6; zi++)
  1645. {
  1646. vinya->visitMap[zi] = reverse(bytes[6+zi]);
  1647. }
  1648. i+=16;
  1649. defy.push_back(vinya); // add this def to the vector
  1650. }
  1651. }
  1652. void Mapa::readObjects( unsigned char * bufor, int &i)
  1653. {
  1654. int howManyObjs = readNormalNr(bufor,i, 4); i+=4;
  1655. for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
  1656. {
  1657. //std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
  1658. CGObjectInstance * nobj = new CGObjectInstance(); //we will read this object
  1659. nobj->id = objects.size();
  1660. nobj->pos.x = bufor[i++];
  1661. nobj->pos.y = bufor[i++];
  1662. nobj->pos.z = bufor[i++];
  1663. int tempd = readNormalNr(bufor,i, 4); i+=4;
  1664. nobj->defInfo = defy[tempd];
  1665. nobj->ID = nobj->defInfo->id;
  1666. nobj->subID = nobj->defInfo->subid;
  1667. //if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>width || nobj.y>height || nobj.z>1 || nobj.defNumber>defy.size()) std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
  1668. i+=5;
  1669. unsigned char buff [30];
  1670. for(int ccc=0; ccc<30; ++ccc)
  1671. {
  1672. buff[ccc] = bufor[i+ccc];
  1673. }
  1674. int j = nobj->defInfo->id;
  1675. int p = 99;
  1676. switch(getDefType(nobj->defInfo))
  1677. {
  1678. case EVENTOBJ_DEF: //for event - objects
  1679. {
  1680. CEventObjInfo * spec = new CEventObjInfo;
  1681. bool guardMess;
  1682. guardMess = bufor[i]; ++i;
  1683. if(guardMess)
  1684. {
  1685. int messLong = readNormalNr(bufor,i, 4); i+=4;
  1686. if(messLong>0)
  1687. {
  1688. spec->isMessage = true;
  1689. for(int yy=0; yy<messLong; ++yy)
  1690. {
  1691. spec->message +=bufor[i+yy];
  1692. }
  1693. i+=messLong;
  1694. }
  1695. spec->areGuarders = bufor[i]; ++i;
  1696. if(spec->areGuarders)
  1697. {
  1698. spec->guarders = readCreatureSet(bufor,i,7,(version>RoE));
  1699. }
  1700. i+=4;
  1701. }
  1702. else
  1703. {
  1704. spec->isMessage = false;
  1705. spec->areGuarders = false;
  1706. spec->message = std::string("");
  1707. }
  1708. spec->gainedExp = readNormalNr(bufor,i, 4); i+=4;
  1709. spec->manaDiff = readNormalNr(bufor,i, 4); i+=4;
  1710. spec->moraleDiff = readNormalNr(bufor,i, 1, true); ++i;
  1711. spec->luckDiff = readNormalNr(bufor,i, 1, true); ++i;
  1712. spec->wood = readNormalNr(bufor,i); i+=4;
  1713. spec->mercury = readNormalNr(bufor,i); i+=4;
  1714. spec->ore = readNormalNr(bufor,i); i+=4;
  1715. spec->sulfur = readNormalNr(bufor,i); i+=4;
  1716. spec->crystal = readNormalNr(bufor,i); i+=4;
  1717. spec->gems = readNormalNr(bufor,i); i+=4;
  1718. spec->gold = readNormalNr(bufor,i); i+=4;
  1719. spec->attack = readNormalNr(bufor,i, 1); ++i;
  1720. spec->defence = readNormalNr(bufor,i, 1); ++i;
  1721. spec->power = readNormalNr(bufor,i, 1); ++i;
  1722. spec->knowledge = readNormalNr(bufor,i, 1); ++i;
  1723. int gabn; //number of gained abilities
  1724. gabn = readNormalNr(bufor,i, 1); ++i;
  1725. for(int oo = 0; oo<gabn; ++oo)
  1726. {
  1727. spec->abilities.push_back(readNormalNr(bufor,i, 1)); ++i;
  1728. spec->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i;
  1729. }
  1730. int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts
  1731. for(int oo = 0; oo<gart; ++oo)
  1732. {
  1733. spec->artifacts.push_back(readNormalNr(bufor,i, (version == RoE ? 1 : 2))); i+=(version == RoE ? 1 : 2);
  1734. }
  1735. int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells
  1736. for(int oo = 0; oo<gspel; ++oo)
  1737. {
  1738. spec->spells.push_back(readNormalNr(bufor,i, 1)); ++i;
  1739. }
  1740. int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures
  1741. spec->creatures = readCreatureSet(bufor,i,gcre,(version>RoE));
  1742. i+=8;
  1743. spec->availableFor = readNormalNr(bufor,i, 1); ++i;
  1744. spec->computerActivate = readNormalNr(bufor,i, 1); ++i;
  1745. spec->humanActivate = readNormalNr(bufor,i, 1); ++i;
  1746. i+=4;
  1747. nobj->info = spec;
  1748. break;
  1749. }
  1750. case HERO_DEF:
  1751. {
  1752. loadHero(nobj, bufor, i);
  1753. break;
  1754. }
  1755. case CREATURES_DEF:
  1756. {
  1757. CCreatureObjInfo * spec = new CCreatureObjInfo;
  1758. if(version>RoE)
  1759. {
  1760. spec->bytes[0] = bufor[i]; ++i;
  1761. spec->bytes[1] = bufor[i]; ++i;
  1762. spec->bytes[2] = bufor[i]; ++i;
  1763. spec->bytes[3] = bufor[i]; ++i;
  1764. }
  1765. spec->number = readNormalNr(bufor,i, 2); i+=2;
  1766. spec->character = bufor[i]; ++i;
  1767. bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
  1768. if(isMesTre)
  1769. {
  1770. int messLength = readNormalNr(bufor,i); i+=4;
  1771. if(messLength>0)
  1772. {
  1773. for(int tt=0; tt<messLength; ++tt)
  1774. {
  1775. spec->message += bufor[i]; ++i;
  1776. }
  1777. }
  1778. spec->wood = readNormalNr(bufor,i); i+=4;
  1779. spec->mercury = readNormalNr(bufor,i); i+=4;
  1780. spec->ore = readNormalNr(bufor,i); i+=4;
  1781. spec->sulfur = readNormalNr(bufor,i); i+=4;
  1782. spec->crytal = readNormalNr(bufor,i); i+=4;
  1783. spec->gems = readNormalNr(bufor,i); i+=4;
  1784. spec->gold = readNormalNr(bufor,i); i+=4;
  1785. int artID = readNormalNr(bufor,i, (version == RoE ? 1 : 2)); i+=(version == RoE ? 1 : 2);
  1786. if(version==RoE)
  1787. {
  1788. if(artID!=0xff)
  1789. spec->gainedArtifact = artID;
  1790. else
  1791. spec->gainedArtifact = -1;
  1792. }
  1793. else
  1794. {
  1795. if(artID!=0xffff)
  1796. spec->gainedArtifact = artID;
  1797. else
  1798. spec->gainedArtifact = -1;
  1799. }
  1800. }
  1801. spec->neverFlees = bufor[i]; ++i;
  1802. spec->notGrowingTeam = bufor[i]; ++i;
  1803. i+=2;
  1804. nobj->info = spec;
  1805. break;
  1806. }
  1807. case SIGN_DEF:
  1808. {
  1809. CSignObjInfo * spec = new CSignObjInfo;
  1810. int length = readNormalNr(bufor,i); i+=4;
  1811. for(int rr=0; rr<length; ++rr)
  1812. {
  1813. spec->message += bufor[i]; ++i;
  1814. }
  1815. i+=4;
  1816. nobj->info = spec;
  1817. break;
  1818. }
  1819. case SEERHUT_DEF:
  1820. {
  1821. i = loadSeerHut(bufor, i, nobj);
  1822. break;
  1823. }
  1824. case WITCHHUT_DEF:
  1825. {
  1826. CWitchHutObjInfo * spec = new CWitchHutObjInfo;
  1827. if(version>RoE) //in reo we cannot specify it - all are allowed (I hope)
  1828. {
  1829. int ist=i; //starting i for loop
  1830. for(i; i<ist+4; ++i)
  1831. {
  1832. unsigned char c = bufor[i];
  1833. for(int yy=0; yy<8; ++yy)
  1834. {
  1835. if((i-ist)*8+yy < SKILL_QUANTITY)
  1836. {
  1837. if(c == (c|((unsigned char)intPow(2, yy))))
  1838. spec->allowedAbilities.push_back((i-ist)*8+yy);
  1839. }
  1840. }
  1841. }
  1842. }
  1843. else //(RoE map)
  1844. {
  1845. for(int gg=0; gg<SKILL_QUANTITY; ++gg)
  1846. {
  1847. spec->allowedAbilities.push_back(gg);
  1848. }
  1849. }
  1850. nobj->info = spec;
  1851. break;
  1852. }
  1853. case SCHOLAR_DEF:
  1854. {
  1855. CScholarObjInfo * spec = new CScholarObjInfo;
  1856. spec->bonusType = bufor[i]; ++i;
  1857. switch(spec->bonusType)
  1858. {
  1859. case 0xff:
  1860. ++i;
  1861. break;
  1862. case 0:
  1863. spec->r0type = bufor[i]; ++i;
  1864. break;
  1865. case 1:
  1866. spec->r1 = bufor[i]; ++i;
  1867. break;
  1868. case 2:
  1869. spec->r2 = bufor[i]; ++i;
  1870. break;
  1871. }
  1872. i+=6;
  1873. nobj->info = spec;
  1874. break;
  1875. }
  1876. case GARRISON_DEF:
  1877. {
  1878. CGarrisonObjInfo * spec = new CGarrisonObjInfo;
  1879. spec->player = bufor[i]; ++i;
  1880. i+=3;
  1881. spec->units = readCreatureSet(bufor,i,7,(version>RoE));
  1882. if(version > RoE)
  1883. {
  1884. spec->movableUnits = bufor[i]; ++i;
  1885. }
  1886. else
  1887. spec->movableUnits = true;
  1888. i+=8;
  1889. nobj->setOwner(spec->player);
  1890. nobj->info = spec;
  1891. break;
  1892. }
  1893. case ARTIFACT_DEF:
  1894. {
  1895. CArtifactObjInfo * spec = new CArtifactObjInfo;
  1896. bool areSettings = bufor[i]; ++i;
  1897. if(areSettings)
  1898. {
  1899. int messLength = readNormalNr(bufor,i, 4); i+=4;
  1900. for(int hh=0; hh<messLength; ++hh)
  1901. {
  1902. spec->message += bufor[i]; ++i;
  1903. }
  1904. bool areGuards = bufor[i]; ++i;
  1905. if(areGuards)
  1906. {
  1907. spec->areGuards = true;
  1908. spec->guards = readCreatureSet(bufor,i,7,(version>RoE));
  1909. }
  1910. else
  1911. spec->areGuards = false;
  1912. i+=4;
  1913. }
  1914. nobj->info = spec;
  1915. break;
  1916. }
  1917. case RESOURCE_DEF:
  1918. {
  1919. CResourceObjInfo * spec = new CResourceObjInfo;
  1920. bool isMessGuard = bufor[i]; ++i;
  1921. if(isMessGuard)
  1922. {
  1923. int messLength = readNormalNr(bufor,i); i+=4;
  1924. for(int mm=0; mm<messLength; ++mm)
  1925. {
  1926. spec->message+=bufor[i]; ++i;
  1927. }
  1928. spec->areGuards = bufor[i]; ++i;
  1929. if(spec->areGuards)
  1930. {
  1931. spec->guards = readCreatureSet(bufor,i,7,(version>RoE));
  1932. }
  1933. i+=4;
  1934. }
  1935. else
  1936. {
  1937. spec->areGuards = false;
  1938. }
  1939. spec->amount = readNormalNr(bufor,i); i+=4;
  1940. i+=4;
  1941. nobj->info = spec;
  1942. break;
  1943. }
  1944. case TOWN_DEF:
  1945. {
  1946. loadTown(nobj, bufor, i);
  1947. break;
  1948. }
  1949. case PLAYERONLY_DEF:
  1950. {
  1951. CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
  1952. spec->player = bufor[i]; ++i;
  1953. i+=3;
  1954. nobj->setOwner(spec->player);
  1955. nobj->info = spec;
  1956. break;
  1957. }
  1958. case SHRINE_DEF:
  1959. {
  1960. CShrineObjInfo * spec = new CShrineObjInfo;
  1961. spec->spell = bufor[i]; i+=4;
  1962. nobj->info = spec;
  1963. break;
  1964. }
  1965. case SPELLSCROLL_DEF:
  1966. {
  1967. CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
  1968. bool messg = bufor[i]; ++i;
  1969. if(messg)
  1970. {
  1971. int mLength = readNormalNr(bufor,i); i+=4;
  1972. for(int vv=0; vv<mLength; ++vv)
  1973. {
  1974. spec->message += bufor[i]; ++i;
  1975. }
  1976. spec->areGuarders = bufor[i]; ++i;
  1977. if(spec->areGuarders)
  1978. {
  1979. spec->guarders = readCreatureSet(bufor,i,7,(version>RoE));
  1980. }
  1981. i+=4;
  1982. }
  1983. spec->spell = bufor[i]; ++i;
  1984. i+=3;
  1985. nobj->info = spec;
  1986. break;
  1987. }
  1988. case PANDORA_DEF:
  1989. {
  1990. CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
  1991. bool messg = bufor[i]; ++i;
  1992. if(messg)
  1993. {
  1994. int mLength = readNormalNr(bufor,i); i+=4;
  1995. for(int vv=0; vv<mLength; ++vv)
  1996. {
  1997. spec->message += bufor[i]; ++i;
  1998. }
  1999. spec->areGuarders = bufor[i]; ++i;
  2000. if(spec->areGuarders)
  2001. {
  2002. spec->guarders = readCreatureSet(bufor,i,7,(version>RoE));
  2003. }
  2004. i+=4;
  2005. }
  2006. ////// copied form event handling (seems to be similar)
  2007. spec->gainedExp = readNormalNr(bufor,i, 4); i+=4;
  2008. spec->manaDiff = readNormalNr(bufor,i, 4); i+=4;
  2009. spec->moraleDiff = readNormalNr(bufor,i, 1, true); ++i;
  2010. spec->luckDiff = readNormalNr(bufor,i, 1, true); ++i;
  2011. spec->wood = readNormalNr(bufor,i); i+=4;
  2012. spec->mercury = readNormalNr(bufor,i); i+=4;
  2013. spec->ore = readNormalNr(bufor,i); i+=4;
  2014. spec->sulfur = readNormalNr(bufor,i); i+=4;
  2015. spec->crystal = readNormalNr(bufor,i); i+=4;
  2016. spec->gems = readNormalNr(bufor,i); i+=4;
  2017. spec->gold = readNormalNr(bufor,i); i+=4;
  2018. spec->attack = readNormalNr(bufor,i, 1); ++i;
  2019. spec->defence = readNormalNr(bufor,i, 1); ++i;
  2020. spec->power = readNormalNr(bufor,i, 1); ++i;
  2021. spec->knowledge = readNormalNr(bufor,i, 1); ++i;
  2022. int gabn; //number of gained abilities
  2023. gabn = readNormalNr(bufor,i, 1); ++i;
  2024. for(int oo = 0; oo<gabn; ++oo)
  2025. {
  2026. spec->abilities.push_back(readNormalNr(bufor,i, 1)); ++i;
  2027. spec->abilityLevels.push_back(readNormalNr(bufor,i, 1)); ++i;
  2028. }
  2029. int gart = readNormalNr(bufor,i, 1); ++i; //number of gained artifacts
  2030. for(int oo = 0; oo<gart; ++oo)
  2031. {
  2032. if(version > RoE)
  2033. {
  2034. spec->artifacts.push_back(readNormalNr(bufor,i, 2)); i+=2;
  2035. }
  2036. else
  2037. {
  2038. spec->artifacts.push_back(readNormalNr(bufor,i, 1)); i+=1;
  2039. }
  2040. }
  2041. int gspel = readNormalNr(bufor,i, 1); ++i; //number of gained spells
  2042. for(int oo = 0; oo<gspel; ++oo)
  2043. {
  2044. spec->spells.push_back(readNormalNr(bufor,i, 1)); ++i;
  2045. }
  2046. int gcre = readNormalNr(bufor,i, 1); ++i; //number of gained creatures
  2047. spec->creatures = readCreatureSet(bufor,i,gcre,(version>RoE));
  2048. i+=8;
  2049. nobj->info = spec;
  2050. ///////end of copied fragment
  2051. break;
  2052. }
  2053. case GRAIL_DEF:
  2054. {
  2055. CGrailObjInfo * spec = new CGrailObjInfo;
  2056. spec->radius = readNormalNr(bufor,i); i+=4;
  2057. nobj->info = spec;
  2058. break;
  2059. }
  2060. case CREGEN_DEF:
  2061. {
  2062. CCreGenObjInfo * spec = new CCreGenObjInfo;
  2063. spec->player = readNormalNr(bufor,i); i+=4;
  2064. spec->identifier = readNormalNr(bufor,i); i+=4;
  2065. if(!spec->identifier)
  2066. {
  2067. spec->asCastle = false;
  2068. spec->castles[0] = bufor[i]; ++i;
  2069. spec->castles[1] = bufor[i]; ++i;
  2070. }
  2071. else
  2072. {
  2073. spec->asCastle = true;
  2074. }
  2075. nobj->setOwner(spec->player);
  2076. nobj->info = spec;
  2077. break;
  2078. }
  2079. case CREGEN2_DEF:
  2080. {
  2081. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  2082. spec->player = readNormalNr(bufor,i); i+=4;
  2083. spec->identifier = readNormalNr(bufor,i); i+=4;
  2084. if(!spec->identifier)
  2085. {
  2086. spec->asCastle = false;
  2087. spec->castles[0] = bufor[i]; ++i;
  2088. spec->castles[1] = bufor[i]; ++i;
  2089. }
  2090. else
  2091. {
  2092. spec->asCastle = true;
  2093. }
  2094. spec->minLevel = bufor[i]; ++i;
  2095. spec->maxLevel = bufor[i]; ++i;
  2096. //if(spec->maxLevel>7)
  2097. // spec->maxLevel = 7;
  2098. //if(spec->minLevel<1)
  2099. // spec->minLevel = 1;
  2100. nobj->setOwner(spec->player);
  2101. nobj->info = spec;
  2102. break;
  2103. }
  2104. case CREGEN3_DEF:
  2105. {
  2106. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  2107. spec->player = bufor[i]; ++i;
  2108. i+=3;
  2109. spec->minLevel = bufor[i]; ++i;
  2110. spec->maxLevel = bufor[i]; ++i;
  2111. if(spec->maxLevel>7)
  2112. spec->maxLevel = 7;
  2113. if(spec->minLevel<1)
  2114. spec->minLevel = 1;
  2115. nobj->setOwner(spec->player);
  2116. nobj->info = spec;
  2117. break;
  2118. }
  2119. case BORDERGUARD_DEF:
  2120. {
  2121. CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
  2122. spec->missionType = bufor[i]; ++i;
  2123. int len1, len2, len3;
  2124. switch(spec->missionType)
  2125. {
  2126. case 0:
  2127. {
  2128. goto borderguardend;
  2129. break;
  2130. }
  2131. case 1:
  2132. {
  2133. spec->m1level = readNormalNr(bufor,i); i+=4;
  2134. int limit = readNormalNr(bufor,i); i+=4;
  2135. if(limit == ((int)0xffffffff))
  2136. {
  2137. spec->isDayLimit = false;
  2138. spec->lastDay = -1;
  2139. }
  2140. else
  2141. {
  2142. spec->isDayLimit = true;
  2143. spec->lastDay = limit;
  2144. }
  2145. break;
  2146. }
  2147. case 2:
  2148. {
  2149. spec->m2attack = bufor[i]; ++i;
  2150. spec->m2defence = bufor[i]; ++i;
  2151. spec->m2power = bufor[i]; ++i;
  2152. spec->m2knowledge = bufor[i]; ++i;
  2153. int limit = readNormalNr(bufor,i); i+=4;
  2154. if(limit == ((int)0xffffffff))
  2155. {
  2156. spec->isDayLimit = false;
  2157. spec->lastDay = -1;
  2158. }
  2159. else
  2160. {
  2161. spec->isDayLimit = true;
  2162. spec->lastDay = limit;
  2163. }
  2164. break;
  2165. }
  2166. case 3:
  2167. {
  2168. spec->m3bytes[0] = bufor[i]; ++i;
  2169. spec->m3bytes[1] = bufor[i]; ++i;
  2170. spec->m3bytes[2] = bufor[i]; ++i;
  2171. spec->m3bytes[3] = bufor[i]; ++i;
  2172. int limit = readNormalNr(bufor,i); i+=4;
  2173. if(limit == ((int)0xffffffff))
  2174. {
  2175. spec->isDayLimit = false;
  2176. spec->lastDay = -1;
  2177. }
  2178. else
  2179. {
  2180. spec->isDayLimit = true;
  2181. spec->lastDay = limit;
  2182. }
  2183. break;
  2184. }
  2185. case 4:
  2186. {
  2187. spec->m4bytes[0] = bufor[i]; ++i;
  2188. spec->m4bytes[1] = bufor[i]; ++i;
  2189. spec->m4bytes[2] = bufor[i]; ++i;
  2190. spec->m4bytes[3] = bufor[i]; ++i;
  2191. int limit = readNormalNr(bufor,i); i+=4;
  2192. if(limit == ((int)0xffffffff))
  2193. {
  2194. spec->isDayLimit = false;
  2195. spec->lastDay = -1;
  2196. }
  2197. else
  2198. {
  2199. spec->isDayLimit = true;
  2200. spec->lastDay = limit;
  2201. }
  2202. break;
  2203. }
  2204. case 5:
  2205. {
  2206. int artNumber = bufor[i]; ++i;
  2207. for(int yy=0; yy<artNumber; ++yy)
  2208. {
  2209. spec->m5arts.push_back(readNormalNr(bufor,i, 2)); i+=2;
  2210. }
  2211. int limit = readNormalNr(bufor,i); i+=4;
  2212. if(limit == ((int)0xffffffff))
  2213. {
  2214. spec->isDayLimit = false;
  2215. spec->lastDay = -1;
  2216. }
  2217. else
  2218. {
  2219. spec->isDayLimit = true;
  2220. spec->lastDay = limit;
  2221. }
  2222. break;
  2223. }
  2224. case 6:
  2225. {
  2226. int typeNumber = bufor[i]; ++i;
  2227. for(int hh=0; hh<typeNumber; ++hh)
  2228. {
  2229. int creType = readNormalNr(bufor,i, 2); i+=2;
  2230. int creNumb = readNormalNr(bufor,i, 2); i+=2;
  2231. spec->m6cre.push_back(&(VLC->creh->creatures[creType]));
  2232. spec->m6number.push_back(creNumb);
  2233. }
  2234. int limit = readNormalNr(bufor,i); i+=4;
  2235. if(limit == ((int)0xffffffff))
  2236. {
  2237. spec->isDayLimit = false;
  2238. spec->lastDay = -1;
  2239. }
  2240. else
  2241. {
  2242. spec->isDayLimit = true;
  2243. spec->lastDay = limit;
  2244. }
  2245. break;
  2246. }
  2247. case 7:
  2248. {
  2249. spec->m7wood = readNormalNr(bufor,i); i+=4;
  2250. spec->m7mercury = readNormalNr(bufor,i); i+=4;
  2251. spec->m7ore = readNormalNr(bufor,i); i+=4;
  2252. spec->m7sulfur = readNormalNr(bufor,i); i+=4;
  2253. spec->m7crystal = readNormalNr(bufor,i); i+=4;
  2254. spec->m7gems = readNormalNr(bufor,i); i+=4;
  2255. spec->m7gold = readNormalNr(bufor,i); i+=4;
  2256. int limit = readNormalNr(bufor,i); i+=4;
  2257. if(limit == ((int)0xffffffff))
  2258. {
  2259. spec->isDayLimit = false;
  2260. spec->lastDay = -1;
  2261. }
  2262. else
  2263. {
  2264. spec->isDayLimit = true;
  2265. spec->lastDay = limit;
  2266. }
  2267. break;
  2268. }
  2269. case 8:
  2270. {
  2271. int heroType = bufor[i]; ++i;
  2272. spec->m8hero = heroType;
  2273. int limit = readNormalNr(bufor,i); i+=4;
  2274. if(limit == ((int)0xffffffff))
  2275. {
  2276. spec->isDayLimit = false;
  2277. spec->lastDay = -1;
  2278. }
  2279. else
  2280. {
  2281. spec->isDayLimit = true;
  2282. spec->lastDay = limit;
  2283. }
  2284. break;
  2285. }
  2286. case 9:
  2287. {
  2288. spec->m9player = bufor[i]; ++i;
  2289. int limit = readNormalNr(bufor,i); i+=4;
  2290. if(limit == ((int)0xffffffff))
  2291. {
  2292. spec->isDayLimit = false;
  2293. spec->lastDay = -1;
  2294. }
  2295. else
  2296. {
  2297. spec->isDayLimit = true;
  2298. spec->lastDay = limit;
  2299. }
  2300. break;
  2301. }
  2302. }//internal switch end (seer huts)
  2303. len1 = readNormalNr(bufor,i); i+=4;
  2304. for(int ee=0; ee<len1; ++ee)
  2305. {
  2306. spec->firstVisitText += bufor[i]; ++i;
  2307. }
  2308. len2 = readNormalNr(bufor,i); i+=4;
  2309. for(int ee=0; ee<len2; ++ee)
  2310. {
  2311. spec->nextVisitText += bufor[i]; ++i;
  2312. }
  2313. len3 = readNormalNr(bufor,i); i+=4;
  2314. for(int ee=0; ee<len3; ++ee)
  2315. {
  2316. spec->completedText += bufor[i]; ++i;
  2317. }
  2318. nobj->info = spec;
  2319. borderguardend:
  2320. break;
  2321. }
  2322. case HEROPLACEHOLDER_DEF:
  2323. {
  2324. i+=3; //TODO: handle it more properly
  2325. break;
  2326. }
  2327. } //end of main switch
  2328. objects.push_back(nobj);
  2329. }
  2330. }
  2331. void Mapa::readEvents( unsigned char * bufor, int &i )
  2332. {
  2333. int numberOfEvents = readNormalNr(bufor,i); i+=4;
  2334. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  2335. {
  2336. CMapEvent ne;
  2337. ne.name = std::string();
  2338. ne.message = std::string();
  2339. int nameLen = readNormalNr(bufor,i); i+=4;
  2340. for(int qq=0; qq<nameLen; ++qq)
  2341. {
  2342. ne.name += bufor[i]; ++i;
  2343. }
  2344. int messLen = readNormalNr(bufor,i); i+=4;
  2345. for(int qq=0; qq<messLen; ++qq)
  2346. {
  2347. ne.message +=bufor[i]; ++i;
  2348. }
  2349. ne.wood = readNormalNr(bufor,i); i+=4;
  2350. ne.mercury = readNormalNr(bufor,i); i+=4;
  2351. ne.ore = readNormalNr(bufor,i); i+=4;
  2352. ne.sulfur = readNormalNr(bufor,i); i+=4;
  2353. ne.crystal = readNormalNr(bufor,i); i+=4;
  2354. ne.gems = readNormalNr(bufor,i); i+=4;
  2355. ne.gold = readNormalNr(bufor,i); i+=4;
  2356. ne.players = bufor[i]; ++i;
  2357. if(version>AB)
  2358. {
  2359. ne.humanAffected = bufor[i]; ++i;
  2360. }
  2361. else
  2362. ne.humanAffected = true;
  2363. ne.computerAffected = bufor[i]; ++i;
  2364. ne.firstOccurence = bufor[i]; ++i;
  2365. ne.nextOccurence = bufor[i]; ++i;
  2366. i+=18;
  2367. events.push_back(ne);
  2368. }
  2369. }
  2370. bool Mapa::isInTheMap( int3 pos )
  2371. {
  2372. if(pos.x<0 || pos.y<0 || pos.z<0 || pos.x >= width || pos.y >= height || pos.z > twoLevel)
  2373. return false;
  2374. else return true;
  2375. }