CAmbarCendamo.cpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  1. #include "stdafx.h"
  2. #include "CAmbarCendamo.h"
  3. #include "CSemiDefHandler.h"
  4. #include "CGameInfo.h"
  5. #include "CObjectHandler.h"
  6. #include "CCastleHandler.h"
  7. #include "SDL_Extensions.h"
  8. #include "boost\filesystem.hpp"
  9. #include <set>
  10. #define CGI (CGameInfo::mainObj)
  11. unsigned int intPow(unsigned int a, unsigned int b)
  12. {
  13. unsigned int ret=1;
  14. for(int i=0; i<b; ++i)
  15. ret*=a;
  16. return ret;
  17. }
  18. CAmbarCendamo::CAmbarCendamo (unsigned char * map)
  19. {
  20. bufor=map;
  21. }
  22. CAmbarCendamo::CAmbarCendamo (const char * tie)
  23. {
  24. is = new std::ifstream();
  25. is -> open(tie,std::ios::binary);
  26. is->seekg(0,std::ios::end); // na koniec
  27. andame = is->tellg(); // read length
  28. is->seekg(0,std::ios::beg); // wracamy na poczatek
  29. bufor = new unsigned char[andame]; // allocate memory
  30. is->read((char*)bufor, andame); // read map file to buffer
  31. is->close();
  32. delete is;
  33. }
  34. CAmbarCendamo::~CAmbarCendamo ()
  35. {// free memory
  36. for (int ii=0;ii<map.width;ii++)
  37. delete map.terrain[ii] ;
  38. delete map.terrain;
  39. delete bufor;
  40. }
  41. void CAmbarCendamo::teceDef()
  42. {
  43. for (int i=0; i<map.defy.size(); i++)
  44. {
  45. std::ofstream * of = new std::ofstream(map.defy[i].name.c_str());
  46. for (int j=0;j<46;j++)
  47. {
  48. (*of) << map.defy[i].bytes[j]<<std::endl;
  49. }
  50. of->close();
  51. delete of;
  52. }
  53. }
  54. void CAmbarCendamo::deh3m()
  55. {
  56. THC timeHandler th;
  57. map.version = (Eformat)bufor[0]; //wersja mapy
  58. map.areAnyPLayers = bufor[4]; //invalid on some maps
  59. map.height = map.width = bufor[5]; // wymiary mapy
  60. map.twoLevel = bufor[9]; //czy sa lochy
  61. map.terrain = new TerrainTile*[map.width]; // allocate memory
  62. for (int ii=0;ii<map.width;ii++)
  63. map.terrain[ii] = new TerrainTile[map.height]; // allocate memory
  64. if (map.twoLevel)
  65. {
  66. map.undergroungTerrain = new TerrainTile*[map.width]; // allocate memory
  67. for (int ii=0;ii<map.width;ii++)
  68. map.undergroungTerrain[ii] = new TerrainTile[map.height]; // allocate memory
  69. }
  70. int length = bufor[10]; //name length
  71. int i=14, pom;
  72. while (i-14<length) //read name
  73. map.name+=bufor[i++];
  74. length = bufor[i] + bufor[i+1]*256; //description length
  75. i+=4;
  76. for (pom=0;pom<length;pom++)
  77. map.description+=bufor[i++];
  78. map.difficulty = bufor[i++]; // reading map difficulty
  79. map.levelLimit = bufor[i++]; // hero level limit
  80. for (pom=0;pom<8;pom++)
  81. {
  82. map.players[pom].canHumanPlay = bufor[i++];
  83. map.players[pom].canComputerPlay = bufor[i++];
  84. if ((!(map.players[pom].canHumanPlay || map.players[pom].canComputerPlay)))
  85. {
  86. i+=13;
  87. continue;
  88. }
  89. map.players[pom].AITactic = bufor[i++];
  90. if (bufor[i++])
  91. {
  92. map.players[pom].allowedFactions = 0;
  93. map.players[pom].allowedFactions += bufor[i++];
  94. map.players[pom].allowedFactions += (bufor[i++])*256;
  95. }
  96. else
  97. {
  98. map.players[pom].allowedFactions = 511;
  99. i+=2;
  100. }
  101. map.players[pom].isFactionRandom = bufor[i++];
  102. map.players[pom].hasMainTown = bufor[i++];
  103. if (map.players[pom].hasMainTown)
  104. {
  105. map.players[pom].generateHeroAtMainTown = bufor[i++];
  106. i++; //unknown byte
  107. map.players[pom].posOfMainTown.x = bufor[i++];
  108. map.players[pom].posOfMainTown.y = bufor[i++];
  109. map.players[pom].posOfMainTown.z = bufor[i++];
  110. }
  111. i++; //unknown byte
  112. int unknown = bufor[i++];
  113. if (unknown == 255)
  114. {
  115. map.players[pom].mainHeroPortrait = 255;
  116. i+=5;
  117. continue;
  118. }
  119. map.players[pom].mainHeroPortrait = bufor[i++];
  120. int nameLength = bufor[i++];
  121. i+=3;
  122. for (int pp=0;pp<nameLength;pp++)
  123. map.players[pom].mainHeroName+=bufor[i++];
  124. i++; ////unknown byte
  125. int heroCount = bufor[i++];
  126. i+=3;
  127. for (int pp=0;pp<heroCount;pp++)
  128. {
  129. SheroName vv;
  130. vv.heroID=bufor[i++];
  131. int hnl = bufor[i++];
  132. i+=3;
  133. for (int zz=0;zz<hnl;zz++)
  134. {
  135. vv.heroName+=bufor[i++];
  136. }
  137. map.players[pom].heroesNames.push_back(vv);
  138. }
  139. }
  140. map.victoryCondition = (EvictoryConditions)bufor[i++];
  141. if (map.victoryCondition != winStandard) //specific victory conditions
  142. {
  143. int nr;
  144. switch (map.victoryCondition) //read victory conditions
  145. {
  146. case artifact:
  147. {
  148. map.vicConDetails = new VicCon0();
  149. ((VicCon0*)map.vicConDetails)->ArtifactID = bufor[i+2];
  150. nr=2;
  151. break;
  152. }
  153. case gatherTroop:
  154. {
  155. map.vicConDetails = new VicCon1();
  156. int temp1 = bufor[i+2];
  157. int temp2 = bufor[i+3];
  158. ((VicCon1*)map.vicConDetails)->monsterID = bufor[i+2];
  159. ((VicCon1*)map.vicConDetails)->neededQuantity=readNormalNr(i+4);
  160. nr=6;
  161. break;
  162. }
  163. case gatherResource:
  164. {
  165. map.vicConDetails = new VicCon2();
  166. ((VicCon2*)map.vicConDetails)->resourceID = bufor[i+2];
  167. ((VicCon2*)map.vicConDetails)->neededQuantity=readNormalNr(i+3);
  168. nr=5;
  169. break;
  170. }
  171. case buildCity:
  172. {
  173. map.vicConDetails = new VicCon3();
  174. ((VicCon3*)map.vicConDetails)->posOfCity.x = bufor[i+2];
  175. ((VicCon3*)map.vicConDetails)->posOfCity.y = bufor[i+3];
  176. ((VicCon3*)map.vicConDetails)->posOfCity.z = bufor[i+4];
  177. ((VicCon3*)map.vicConDetails)->councilNeededLevel = bufor[i+5];
  178. ((VicCon3*)map.vicConDetails)->fortNeededLevel = bufor[i+6];
  179. nr=5;
  180. break;
  181. }
  182. case buildGrail:
  183. {
  184. map.vicConDetails = new VicCon4();
  185. if (bufor[i+4]>2)
  186. ((VicCon4*)map.vicConDetails)->anyLocation = true;
  187. else
  188. {
  189. ((VicCon4*)map.vicConDetails)->whereBuildGrail.x = bufor[i+2];
  190. ((VicCon4*)map.vicConDetails)->whereBuildGrail.y = bufor[i+3];
  191. ((VicCon4*)map.vicConDetails)->whereBuildGrail.z = bufor[i+4];
  192. }
  193. nr=3;
  194. break;
  195. }
  196. case beatHero:
  197. {
  198. map.vicConDetails = new VicCon5();
  199. ((VicCon5*)map.vicConDetails)->locationOfHero.x = bufor[i+2];
  200. ((VicCon5*)map.vicConDetails)->locationOfHero.y = bufor[i+3];
  201. ((VicCon5*)map.vicConDetails)->locationOfHero.z = bufor[i+4];
  202. nr=3;
  203. break;
  204. }
  205. case captureCity:
  206. {
  207. map.vicConDetails = new VicCon6();
  208. ((VicCon6*)map.vicConDetails)->locationOfTown.x = bufor[i+2];
  209. ((VicCon6*)map.vicConDetails)->locationOfTown.y = bufor[i+3];
  210. ((VicCon6*)map.vicConDetails)->locationOfTown.z = bufor[i+4];
  211. nr=3;
  212. break;
  213. }
  214. case beatMonster:
  215. {
  216. map.vicConDetails = new VicCon7();
  217. ((VicCon7*)map.vicConDetails)->locationOfMonster.x = bufor[i+2];
  218. ((VicCon7*)map.vicConDetails)->locationOfMonster.y = bufor[i+3];
  219. ((VicCon7*)map.vicConDetails)->locationOfMonster.z = bufor[i+4];
  220. nr=3;
  221. break;
  222. }
  223. case takeDwellings:
  224. {
  225. map.vicConDetails = new CspecificVictoryConidtions();
  226. nr=3;
  227. break;
  228. }
  229. case takeMines:
  230. {
  231. map.vicConDetails = new CspecificVictoryConidtions();
  232. nr=3;
  233. break;
  234. }
  235. case transportItem:
  236. {
  237. map.vicConDetails = new VicCona();
  238. ((VicCona*)map.vicConDetails)->artifactID = bufor[i+2];
  239. ((VicCona*)map.vicConDetails)->destinationPlace.x = bufor[i+3];
  240. ((VicCona*)map.vicConDetails)->destinationPlace.y = bufor[i+4];
  241. ((VicCona*)map.vicConDetails)->destinationPlace.z = bufor[i+5];
  242. nr=3;
  243. break;
  244. }
  245. }
  246. map.vicConDetails->allowNormalVictory = bufor[i++];
  247. map.vicConDetails->appliesToAI = bufor[i++];
  248. i+=nr;
  249. }
  250. map.lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
  251. switch (map.lossCondition.typeOfLossCon) //read loss conditions
  252. {
  253. case lossCastle:
  254. {
  255. map.lossCondition.castlePos.x=bufor[i++];
  256. map.lossCondition.castlePos.y=bufor[i++];
  257. map.lossCondition.castlePos.z=bufor[i++];
  258. break;
  259. }
  260. case lossHero:
  261. {
  262. map.lossCondition.heroPos.x=bufor[i++];
  263. map.lossCondition.heroPos.y=bufor[i++];
  264. map.lossCondition.heroPos.z=bufor[i++];
  265. break;
  266. }
  267. case timeExpires:
  268. {
  269. map.lossCondition.timeLimit = readNormalNr(i++,2);
  270. i++;
  271. break;
  272. }
  273. }
  274. map.howManyTeams=bufor[i++]; //read number of teams
  275. if(map.howManyTeams>0) //read team numbers
  276. {
  277. for(int rr=0; rr<8; ++rr)
  278. {
  279. map.players[rr].team=bufor[i++];
  280. }
  281. }
  282. //reading allowed heroes (20 bytes)
  283. int ist=i; //starting i for loop
  284. for(i; i<ist+20; ++i)
  285. {
  286. unsigned char c = bufor[i];
  287. for(int yy=0; yy<8; ++yy)
  288. {
  289. if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size())
  290. {
  291. if(c == (c|((unsigned char)intPow(2, yy))))
  292. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = true;
  293. else
  294. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = false;
  295. }
  296. }
  297. }
  298. //allowed heroes have been read
  299. i+=36;
  300. //reading allowed artifacts //18 bytes
  301. ist=i; //starting i for loop
  302. for(i; i<ist+18; ++i)
  303. {
  304. unsigned char c = bufor[i];
  305. for(int yy=0; yy<8; ++yy)
  306. {
  307. if((i-ist)*8+yy < CGameInfo::mainObj->arth->artifacts.size())
  308. {
  309. if(c != (c|((unsigned char)intPow(2, yy))))
  310. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true;
  311. else
  312. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false;
  313. }
  314. }
  315. }//allowed artifacts have been read
  316. //reading allowed spells (9 bytes)
  317. ist=i; //starting i for loop
  318. for(i; i<ist+9; ++i)
  319. {
  320. unsigned char c = bufor[i];
  321. for(int yy=0; yy<8; ++yy)
  322. {
  323. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  324. {
  325. if(c != (c|((unsigned char)intPow(2, yy))))
  326. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true;
  327. else
  328. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false;
  329. }
  330. }
  331. }
  332. //allowed spells have been read
  333. //allowed hero's abilities (4 bytes)
  334. ist=i; //starting i for loop
  335. for(i; i<ist+4; ++i)
  336. {
  337. unsigned char c = bufor[i];
  338. for(int yy=0; yy<8; ++yy)
  339. {
  340. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  341. {
  342. if(c != (c|((unsigned char)intPow(2, yy))))
  343. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = true;
  344. else
  345. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = false;
  346. }
  347. }
  348. }
  349. //allowed hero's abilities have been read
  350. THC std::cout<<"Reading header: "<<th.getDif()<<std::endl;
  351. int rumNr = readNormalNr(i,4);i+=4;
  352. for (int it=0;it<rumNr;it++)
  353. {
  354. Rumor ourRumor;
  355. int nameL = readNormalNr(i,4);i+=4; //read length of name of rumor
  356. for (int zz=0; zz<nameL; zz++)
  357. ourRumor.name+=bufor[i++];
  358. nameL = readNormalNr(i,4);i+=4; //read length of rumor
  359. for (int zz=0; zz<nameL; zz++)
  360. ourRumor.text+=bufor[i++];
  361. map.rumors.push_back(ourRumor); //add to our list
  362. }
  363. THC std::cout<<"Reading rumors: "<<th.getDif()<<std::endl;
  364. i+=156;
  365. for (int c=0; c<map.width; c++) // reading terrain
  366. {
  367. for (int z=0; z<map.height; z++)
  368. {
  369. map.terrain[z][c].tertype = (EterrainType)(bufor[i++]);
  370. map.terrain[z][c].terview = bufor[i++];
  371. map.terrain[z][c].nuine = (Eriver)bufor[i++];
  372. map.terrain[z][c].rivDir = bufor[i++];
  373. map.terrain[z][c].malle = (Eroad)bufor[i++];
  374. map.terrain[z][c].roadDir = bufor[i++];
  375. map.terrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  376. }
  377. }
  378. if (map.twoLevel) // read underground terrain
  379. {
  380. for (int c=0; c<map.width; c++) // reading terrain
  381. {
  382. for (int z=0; z<map.height; z++)
  383. {
  384. map.undergroungTerrain[z][c].tertype = (EterrainType)(bufor[i++]);
  385. map.undergroungTerrain[z][c].terview = bufor[i++];
  386. map.undergroungTerrain[z][c].nuine = (Eriver)bufor[i++];
  387. map.undergroungTerrain[z][c].rivDir = bufor[i++];
  388. map.undergroungTerrain[z][c].malle = (Eroad)bufor[i++];
  389. map.undergroungTerrain[z][c].roadDir = bufor[i++];
  390. map.undergroungTerrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  391. }
  392. }
  393. }
  394. THC std::cout<<"Reading terrain: "<<th.getDif()<<std::endl;
  395. int defAmount = bufor[i]; // liczba defow
  396. defAmount = readNormalNr(i);
  397. i+=4;
  398. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  399. int srmask = 0xff000000;
  400. int sgmask = 0x00ff0000;
  401. int sbmask = 0x0000ff00;
  402. int samask = 0x000000ff;
  403. #else
  404. int srmask = 0x000000ff;
  405. int sgmask = 0x0000ff00;
  406. int sbmask = 0x00ff0000;
  407. int samask = 0xff000000;
  408. #endif
  409. SDL_Surface * alphaTransSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 12, 12, 32, srmask, sgmask, sbmask, samask);
  410. std::vector<std::string> defsToUnpack;
  411. for (int idd = 0 ; idd<defAmount; idd++) // reading defs
  412. {
  413. int nameLength = readNormalNr(i,4);i+=4;
  414. DefInfo vinya; // info about new def
  415. for (int cd=0;cd<nameLength;cd++)
  416. {
  417. vinya.name += bufor[i++];
  418. }
  419. for (int v=0; v<42; v++) // read info
  420. {
  421. vinya.bytes[v] = bufor[i++];
  422. }
  423. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  424. vinya.name);
  425. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  426. {
  427. vinya.isOnDefList = false;
  428. }
  429. else
  430. {
  431. vinya.printPriority = pit->priority;
  432. vinya.isOnDefList = true;
  433. }
  434. map.defy.push_back(vinya); // add this def to the vector
  435. defsToUnpack.push_back(vinya.name);
  436. //testing - only fragment//////////////////////////////////////////////////////////////
  437. /*map.defy[idd].handler = new CDefHandler();
  438. CGameInfo::mainObj->lodh->extractFile(std::string("newH3sprite.lod"), map.defy[idd].name);
  439. map.defy[idd].handler->openDef( std::string("newH3sprite\\")+map.defy[idd].name);
  440. for(int ff=0; ff<map.defy[idd].handler->ourImages.size(); ++ff) //adding shadows and transparency
  441. {
  442. map.defy[idd].handler->ourImages[ff].bitmap = CSDL_Ext::alphaTransform(map.defy[idd].handler->ourImages[ff].bitmap);
  443. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[idd].handler->ourImages[ff].bitmap, alphaTransSurf);
  444. SDL_FreeSurface(map.defy[idd].handler->ourImages[ff].bitmap);
  445. map.defy[idd].handler->ourImages[ff].bitmap = bufs;
  446. }
  447. boost::filesystem::remove(boost::filesystem::path(std::string("newH3sprite\\")+map.defy[idd].name));*/
  448. //system((std::string("DEL newH3sprite\\")+map.defy[idd].name).c_str());
  449. //end fo testing - only fragment///////////////////////////////////////////////////////
  450. //teceDef();
  451. }
  452. std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack);
  453. for (int i=0;i<dhandlers.size();i++)
  454. map.defy[i].handler=dhandlers[i];
  455. for(int vv=0; vv<map.defy.size(); ++vv)
  456. {
  457. for(int yy=0; yy<map.defy[vv].handler->ourImages.size(); ++yy)
  458. {
  459. map.defy[vv].handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv].handler->ourImages[yy].bitmap);
  460. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv].handler->ourImages[yy].bitmap, alphaTransSurf);
  461. SDL_FreeSurface(map.defy[vv].handler->ourImages[yy].bitmap);
  462. map.defy[vv].handler->ourImages[yy].bitmap = bufs;
  463. }
  464. }
  465. SDL_FreeSurface(alphaTransSurf);
  466. THC std::cout<<"Reading defs: "<<th.getDif()<<std::endl;
  467. ////loading objects
  468. int howManyObjs = readNormalNr(i, 4); i+=4;
  469. for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
  470. {
  471. std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
  472. CObjectInstance nobj; //we will read this object
  473. nobj.id = CGameInfo::mainObj->objh->objInstances.size();
  474. nobj.x = bufor[i++];
  475. nobj.y = bufor[i++];
  476. nobj.z = bufor[i++];
  477. nobj.defNumber = readNormalNr(i, 4); i+=4;
  478. //if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
  479. // std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
  480. i+=5;
  481. unsigned char buff [30];
  482. for(int ccc=0; ccc<30; ++ccc)
  483. {
  484. buff[ccc] = bufor[i+ccc];
  485. }
  486. EDefType uu = getDefType(map.defy[nobj.defNumber]);
  487. int j = map.defy[nobj.defNumber].bytes[16];
  488. int p = 99;
  489. switch(getDefType(map.defy[nobj.defNumber]))
  490. {
  491. case EDefType::EVENTOBJ_DEF: //for event - objects
  492. {
  493. CEventObjInfo * spec = new CEventObjInfo;
  494. bool guardMess;
  495. guardMess = bufor[i]; ++i;
  496. if(guardMess)
  497. {
  498. int messLong = readNormalNr(i, 4); i+=4;
  499. if(messLong>0)
  500. {
  501. spec->isMessage = true;
  502. for(int yy=0; yy<messLong; ++yy)
  503. {
  504. spec->message +=bufor[i+yy];
  505. }
  506. i+=messLong;
  507. }
  508. spec->areGuarders = bufor[i]; ++i;
  509. if(spec->areGuarders)
  510. {
  511. spec->guarders = readCreatureSet(i); i+=28;
  512. }
  513. i+=4;
  514. }
  515. else
  516. {
  517. spec->isMessage = false;
  518. spec->areGuarders = false;
  519. spec->message = std::string("");
  520. }
  521. spec->gainedExp = readNormalNr(i, 4); i+=4;
  522. spec->manaDiff = readNormalNr(i, 4); i+=4;
  523. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  524. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  525. spec->wood = readNormalNr(i); i+=4;
  526. spec->mercury = readNormalNr(i); i+=4;
  527. spec->ore = readNormalNr(i); i+=4;
  528. spec->sulfur = readNormalNr(i); i+=4;
  529. spec->crystal = readNormalNr(i); i+=4;
  530. spec->gems = readNormalNr(i); i+=4;
  531. spec->gold = readNormalNr(i); i+=4;
  532. spec->attack = readNormalNr(i, 1); ++i;
  533. spec->defence = readNormalNr(i, 1); ++i;
  534. spec->power = readNormalNr(i, 1); ++i;
  535. spec->knowledge = readNormalNr(i, 1); ++i;
  536. int gabn; //number of gained abilities
  537. gabn = readNormalNr(i, 1); ++i;
  538. for(int oo = 0; oo<gabn; ++oo)
  539. {
  540. spec->abilities.push_back(&((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)])); ++i;
  541. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  542. }
  543. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  544. for(int oo = 0; oo<gart; ++oo)
  545. {
  546. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  547. }
  548. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  549. for(int oo = 0; oo<gspel; ++oo)
  550. {
  551. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  552. }
  553. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  554. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  555. i+=8;
  556. spec->availableFor = readNormalNr(i, 1); ++i;
  557. spec->computerActivate = readNormalNr(i, 1); ++i;
  558. spec->humanActivate = readNormalNr(i, 1); ++i;
  559. i+=4;
  560. nobj.info = spec;
  561. break;
  562. }
  563. case EDefType::HERO_DEF:
  564. {
  565. CHeroObjInfo * spec = new CHeroObjInfo;
  566. spec->bytes[0] = bufor[i]; ++i;
  567. spec->bytes[1] = bufor[i]; ++i;
  568. spec->bytes[2] = bufor[i]; ++i;
  569. spec->bytes[3] = bufor[i]; ++i;
  570. spec->player = bufor[i]; ++i;
  571. spec->type = &(CGameInfo::mainObj->heroh->heroes[readNormalNr(i, 1)]); ++i;
  572. bool isName = bufor[i]; ++i; //true if hero has nonstandard name
  573. if(isName)
  574. {
  575. int length = readNormalNr(i, 4); i+=4;
  576. for(int gg=0; gg<length; ++gg)
  577. {
  578. spec->name+=bufor[i]; ++i;
  579. }
  580. }
  581. else
  582. spec->name = std::string("");
  583. bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0
  584. if(isExp)
  585. {
  586. spec->experience = readNormalNr(i); i+=4;
  587. }
  588. else spec->experience = 0;
  589. bool portrait=bufor[i]; ++i;
  590. if (portrait)
  591. i++; //TODO read portrait nr, save, open
  592. bool nonstandardAbilities = bufor[i]; ++i; //true if hero has specified abilities
  593. if(nonstandardAbilities)
  594. {
  595. int howMany = readNormalNr(i); i+=4;
  596. for(int yy=0; yy<howMany; ++yy)
  597. {
  598. spec->abilities.push_back(&(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)])); ++i;
  599. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  600. }
  601. }
  602. bool standGarrison = bufor[i]; ++i; //true if hero has nonstandard garrison
  603. spec->standardGarrison = standGarrison;
  604. if(standGarrison)
  605. {
  606. spec->garrison = readCreatureSet(i); i+=28; //4 bytes per slot
  607. }
  608. bool form = bufor[i]; ++i; //formation
  609. spec->garrison.formation = form;
  610. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  611. if(artSet)
  612. {
  613. //head art //1
  614. int id = readNormalNr(i, 2); i+=2;
  615. if(id!=0xffff)
  616. spec->artHead = &(CGameInfo::mainObj->arth->artifacts[id]);
  617. else
  618. spec->artHead = NULL;
  619. //shoulders art //2
  620. id = readNormalNr(i, 2); i+=2;
  621. if(id!=0xffff)
  622. spec->artShoulders = &(CGameInfo::mainObj->arth->artifacts[id]);
  623. else
  624. spec->artShoulders = NULL;
  625. //neck art //3
  626. id = readNormalNr(i, 2); i+=2;
  627. if(id!=0xffff)
  628. spec->artNeck = &(CGameInfo::mainObj->arth->artifacts[id]);
  629. else
  630. spec->artNeck = NULL;
  631. //right hand art //4
  632. id = readNormalNr(i, 2); i+=2;
  633. if(id!=0xffff)
  634. spec->artRhand = &(CGameInfo::mainObj->arth->artifacts[id]);
  635. else
  636. spec->artRhand = NULL;
  637. //left hand art //5
  638. id = readNormalNr(i, 2); i+=2;
  639. if(id!=0xffff)
  640. spec->artLHand = &(CGameInfo::mainObj->arth->artifacts[id]);
  641. else
  642. spec->artLHand = NULL;
  643. //torso art //6
  644. id = readNormalNr(i, 2); i+=2;
  645. if(id!=0xffff)
  646. spec->artTorso = &(CGameInfo::mainObj->arth->artifacts[id]);
  647. else
  648. spec->artTorso = NULL;
  649. //right hand ring //7
  650. id = readNormalNr(i, 2); i+=2;
  651. if(id!=0xffff)
  652. spec->artRRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  653. else
  654. spec->artRRing = NULL;
  655. //left hand ring //8
  656. id = readNormalNr(i, 2); i+=2;
  657. if(id!=0xffff)
  658. spec->artLRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  659. else
  660. spec->artLRing = NULL;
  661. //feet art //9
  662. id = readNormalNr(i, 2); i+=2;
  663. if(id!=0xffff)
  664. spec->artFeet = &(CGameInfo::mainObj->arth->artifacts[id]);
  665. else
  666. spec->artFeet = NULL;
  667. //misc1 art //10
  668. id = readNormalNr(i, 2); i+=2;
  669. if(id!=0xffff)
  670. spec->artMisc1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  671. else
  672. spec->artMisc1 = NULL;
  673. //misc2 art //11
  674. id = readNormalNr(i, 2); i+=2;
  675. if(id!=0xffff)
  676. spec->artMisc2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  677. else
  678. spec->artMisc2 = NULL;
  679. //misc3 art //12
  680. id = readNormalNr(i, 2); i+=2;
  681. if(id!=0xffff)
  682. spec->artMisc3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  683. else
  684. spec->artMisc3 = NULL;
  685. //misc4 art //13
  686. id = readNormalNr(i, 2); i+=2;
  687. if(id!=0xffff)
  688. spec->artMisc4 = &(CGameInfo::mainObj->arth->artifacts[id]);
  689. else
  690. spec->artMisc4 = NULL;
  691. //machine1 art //14
  692. id = readNormalNr(i, 2); i+=2;
  693. if(id!=0xffff)
  694. spec->artMach1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  695. else
  696. spec->artMach1 = NULL;
  697. //machine2 art //15
  698. id = readNormalNr(i, 2); i+=2;
  699. if(id!=0xffff)
  700. spec->artMach2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  701. else
  702. spec->artMach2 = NULL;
  703. //machine3 art //16
  704. id = readNormalNr(i, 2); i+=2;
  705. if(id!=0xffff)
  706. spec->artMach3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  707. else
  708. spec->artMach3 = NULL;
  709. //misc5 art //17
  710. id = readNormalNr(i, 2); i+=2;
  711. if(id!=0xffff)
  712. spec->artMisc5 = &(CGameInfo::mainObj->arth->artifacts[id]);
  713. else
  714. spec->artMisc5 = NULL;
  715. //spellbook
  716. id = readNormalNr(i, 2); i+=2;
  717. if(id!=0xffff)
  718. spec->artSpellBook = &(CGameInfo::mainObj->arth->artifacts[id]);
  719. else
  720. spec->artSpellBook = NULL;
  721. //19 //???what is that? gap in file or what?
  722. i+=2;
  723. //bag artifacts //20
  724. int amount = readNormalNr(i, 2); i+=2; //number of artifacts in hero's bag
  725. if(amount>0)
  726. {
  727. for(int ss=0; ss<amount; ++ss)
  728. {
  729. id = readNormalNr(i, 2); i+=2;
  730. if(id!=0xffff)
  731. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[id]));
  732. else
  733. spec->artifacts.push_back(NULL);
  734. }
  735. }
  736. } //artifacts
  737. spec->guardRange = readNormalNr(i, 1); ++i;
  738. if(spec->guardRange == 0xff)
  739. spec->isGuarding = false;
  740. else
  741. spec->isGuarding = true;
  742. bool hasBiography = bufor[i]; ++i; //true if hero has nonstandard (mapmaker defined) biography
  743. if(hasBiography)
  744. {
  745. int length = readNormalNr(i); i+=4;
  746. int iStart = i;
  747. i+=length;
  748. for(int bb=0; bb<length; ++bb)
  749. {
  750. spec->biography+=bufor[iStart+bb];
  751. }
  752. }
  753. spec->sex = !(bufor[i]); ++i;
  754. //spells
  755. bool areSpells = bufor[i]; ++i;
  756. if(areSpells) //TODO: sprawdziæ //seems to be ok - tow
  757. {
  758. int ist = i;
  759. for(i; i<ist+9; ++i)
  760. {
  761. unsigned char c = bufor[i];
  762. for(int yy=0; yy<8; ++yy)
  763. {
  764. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  765. {
  766. if(c == (c|((unsigned char)intPow(2, yy))))
  767. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  768. }
  769. }
  770. }
  771. }
  772. //spells loaded
  773. spec->defaultMianStats = bufor[i]; ++i;
  774. if(spec->defaultMianStats)
  775. {
  776. spec->attack = bufor[i]; ++i;
  777. spec->defence = bufor[i]; ++i;
  778. spec->power = bufor[i]; ++i;
  779. spec->knowledge = bufor[i]; ++i;
  780. }
  781. i+=16;
  782. nobj.info = spec;
  783. break;
  784. }
  785. case CREATURES_DEF:
  786. {
  787. CCreatureObjInfo * spec = new CCreatureObjInfo;
  788. spec->bytes[0] = bufor[i]; ++i;
  789. spec->bytes[1] = bufor[i]; ++i;
  790. spec->bytes[2] = bufor[i]; ++i;
  791. spec->bytes[3] = bufor[i]; ++i;
  792. spec->number = readNormalNr(i, 2); i+=2;
  793. spec->character = bufor[i]; ++i;
  794. bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
  795. if(isMesTre)
  796. {
  797. int messLength = readNormalNr(i); i+=4;
  798. if(messLength>0)
  799. {
  800. for(int tt=0; tt<messLength; ++tt)
  801. {
  802. spec->message += bufor[i]; ++i;
  803. }
  804. }
  805. spec->wood = readNormalNr(i); i+=4;
  806. spec->mercury = readNormalNr(i); i+=4;
  807. spec->ore = readNormalNr(i); i+=4;
  808. spec->sulfur = readNormalNr(i); i+=4;
  809. spec->crytal = readNormalNr(i); i+=4;
  810. spec->gems = readNormalNr(i); i+=4;
  811. spec->gold = readNormalNr(i); i+=4;
  812. int artID = readNormalNr(i, 2); i+=2;
  813. if(artID!=0xffff)
  814. spec->gainedArtifact = &(CGameInfo::mainObj->arth->artifacts[artID]);
  815. else
  816. spec->gainedArtifact = NULL;
  817. }
  818. spec->neverFlees = bufor[i]; ++i;
  819. spec->notGrowingTeam = bufor[i]; ++i;
  820. i+=2;
  821. nobj.info = spec;
  822. break;
  823. }
  824. case EDefType::SIGN_DEF:
  825. {
  826. CSignObjInfo * spec = new CSignObjInfo;
  827. int length = readNormalNr(i); i+=4;
  828. for(int rr=0; rr<length; ++rr)
  829. {
  830. spec->message += bufor[i]; ++i;
  831. }
  832. i+=4;
  833. nobj.info = spec;
  834. break;
  835. }
  836. case EDefType::SEERHUT_DEF:
  837. {
  838. CSeerHutObjInfo * spec = new CSeerHutObjInfo;
  839. spec->missionType = bufor[i]; ++i;
  840. switch(spec->missionType)
  841. {
  842. case 1:
  843. {
  844. spec->m1level = readNormalNr(i); i+=4;
  845. int limit = readNormalNr(i); i+=4;
  846. if(limit == ((int)0xffffffff))
  847. {
  848. spec->isDayLimit = false;
  849. spec->lastDay = -1;
  850. }
  851. else
  852. {
  853. spec->isDayLimit = true;
  854. spec->lastDay = limit;
  855. }
  856. break;
  857. }
  858. case 2:
  859. {
  860. spec->m2attack = bufor[i]; ++i;
  861. spec->m2defence = bufor[i]; ++i;
  862. spec->m2power = bufor[i]; ++i;
  863. spec->m2knowledge = bufor[i]; ++i;
  864. int limit = readNormalNr(i); i+=4;
  865. if(limit == ((int)0xffffffff))
  866. {
  867. spec->isDayLimit = false;
  868. spec->lastDay = -1;
  869. }
  870. else
  871. {
  872. spec->isDayLimit = true;
  873. spec->lastDay = limit;
  874. }
  875. break;
  876. }
  877. case 3:
  878. {
  879. spec->m3bytes[0] = bufor[i]; ++i;
  880. spec->m3bytes[1] = bufor[i]; ++i;
  881. spec->m3bytes[2] = bufor[i]; ++i;
  882. spec->m3bytes[3] = bufor[i]; ++i;
  883. int limit = readNormalNr(i); i+=4;
  884. if(limit == ((int)0xffffffff))
  885. {
  886. spec->isDayLimit = false;
  887. spec->lastDay = -1;
  888. }
  889. else
  890. {
  891. spec->isDayLimit = true;
  892. spec->lastDay = limit;
  893. }
  894. break;
  895. }
  896. case 4:
  897. {
  898. spec->m4bytes[0] = bufor[i]; ++i;
  899. spec->m4bytes[1] = bufor[i]; ++i;
  900. spec->m4bytes[2] = bufor[i]; ++i;
  901. spec->m4bytes[3] = bufor[i]; ++i;
  902. int limit = readNormalNr(i); i+=4;
  903. if(limit == ((int)0xffffffff))
  904. {
  905. spec->isDayLimit = false;
  906. spec->lastDay = -1;
  907. }
  908. else
  909. {
  910. spec->isDayLimit = true;
  911. spec->lastDay = limit;
  912. }
  913. break;
  914. }
  915. case 5:
  916. {
  917. int artNumber = bufor[i]; ++i;
  918. for(int yy=0; yy<artNumber; ++yy)
  919. {
  920. int artid = readNormalNr(i, 2); i+=2;
  921. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  922. }
  923. int limit = readNormalNr(i); i+=4;
  924. if(limit == ((int)0xffffffff))
  925. {
  926. spec->isDayLimit = false;
  927. spec->lastDay = -1;
  928. }
  929. else
  930. {
  931. spec->isDayLimit = true;
  932. spec->lastDay = limit;
  933. }
  934. break;
  935. }
  936. case 6:
  937. {
  938. int typeNumber = bufor[i]; ++i;
  939. for(int hh=0; hh<typeNumber; ++hh)
  940. {
  941. int creType = readNormalNr(i, 2); i+=2;
  942. int creNumb = readNormalNr(i, 2); i+=2;
  943. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  944. spec->m6number.push_back(creNumb);
  945. }
  946. int limit = readNormalNr(i); i+=4;
  947. if(limit == ((int)0xffffffff))
  948. {
  949. spec->isDayLimit = false;
  950. spec->lastDay = -1;
  951. }
  952. else
  953. {
  954. spec->isDayLimit = true;
  955. spec->lastDay = limit;
  956. }
  957. break;
  958. }
  959. case 7:
  960. {
  961. spec->m7wood = readNormalNr(i); i+=4;
  962. spec->m7mercury = readNormalNr(i); i+=4;
  963. spec->m7ore = readNormalNr(i); i+=4;
  964. spec->m7sulfur = readNormalNr(i); i+=4;
  965. spec->m7crystal = readNormalNr(i); i+=4;
  966. spec->m7gems = readNormalNr(i); i+=4;
  967. spec->m7gold = readNormalNr(i); i+=4;
  968. int limit = readNormalNr(i); i+=4;
  969. if(limit == ((int)0xffffffff))
  970. {
  971. spec->isDayLimit = false;
  972. spec->lastDay = -1;
  973. }
  974. else
  975. {
  976. spec->isDayLimit = true;
  977. spec->lastDay = limit;
  978. }
  979. break;
  980. }
  981. case 8:
  982. {
  983. int heroType = bufor[i]; ++i;
  984. spec->m8hero = &(CGameInfo::mainObj->heroh->heroes[heroType]);
  985. int limit = readNormalNr(i); i+=4;
  986. if(limit == ((int)0xffffffff))
  987. {
  988. spec->isDayLimit = false;
  989. spec->lastDay = -1;
  990. }
  991. else
  992. {
  993. spec->isDayLimit = true;
  994. spec->lastDay = limit;
  995. }
  996. break;
  997. }
  998. case 9:
  999. {
  1000. spec->m9player = bufor[i]; ++i;
  1001. int limit = readNormalNr(i); i+=4;
  1002. if(limit == ((int)0xffffffff))
  1003. {
  1004. spec->isDayLimit = false;
  1005. spec->lastDay = -1;
  1006. }
  1007. else
  1008. {
  1009. spec->isDayLimit = true;
  1010. spec->lastDay = limit;
  1011. }
  1012. break;
  1013. }
  1014. }//internal switch end (seer huts)
  1015. int len1 = readNormalNr(i); i+=4;
  1016. for(int ee=0; ee<len1; ++ee)
  1017. {
  1018. spec->firstVisitText += bufor[i]; ++i;
  1019. }
  1020. int len2 = readNormalNr(i); i+=4;
  1021. for(int ee=0; ee<len2; ++ee)
  1022. {
  1023. spec->nextVisitText += bufor[i]; ++i;
  1024. }
  1025. int len3 = readNormalNr(i); i+=4;
  1026. for(int ee=0; ee<len3; ++ee)
  1027. {
  1028. spec->completedText += bufor[i]; ++i;
  1029. }
  1030. unsigned char rewardType = bufor[i]; ++i;
  1031. spec->rewardType = rewardType;
  1032. switch(rewardType)
  1033. {
  1034. case 1:
  1035. {
  1036. spec->r1exp = readNormalNr(i); i+=4;
  1037. break;
  1038. }
  1039. case 2:
  1040. {
  1041. spec->r2mana = readNormalNr(i); i+=4;
  1042. break;
  1043. }
  1044. case 3:
  1045. {
  1046. spec->r3morale = bufor[i]; ++i;
  1047. break;
  1048. }
  1049. case 4:
  1050. {
  1051. spec->r4luck = bufor[i]; ++i;
  1052. break;
  1053. }
  1054. case 5:
  1055. {
  1056. spec->r5type = bufor[i]; ++i;
  1057. spec->r5amount = readNormalNr(i, 3); i+=3;
  1058. i+=1;
  1059. break;
  1060. }
  1061. case 6:
  1062. {
  1063. spec->r6type = bufor[i]; ++i;
  1064. spec->r6amount = bufor[i]; ++i;
  1065. break;
  1066. }
  1067. case 7:
  1068. {
  1069. int abid = bufor[i]; ++i;
  1070. spec->r7ability = &(CGameInfo::mainObj->abilh->abilities[abid]);
  1071. spec->r7level = bufor[i]; ++i;
  1072. break;
  1073. }
  1074. case 8:
  1075. {
  1076. int artid = readNormalNr(i, 2); i+=2;
  1077. spec->r8art = &(CGameInfo::mainObj->arth->artifacts[artid]);
  1078. break;
  1079. }
  1080. case 9:
  1081. {
  1082. int spellid = bufor[i]; ++i;
  1083. spec->r9spell = &(CGameInfo::mainObj->spellh->spells[spellid]);
  1084. break;
  1085. }
  1086. case 10:
  1087. {
  1088. int creid = readNormalNr(i, 2); i+=2;
  1089. spec->r10creature = &(CGameInfo::mainObj->creh->creatures[creid]);
  1090. spec->r10amount = readNormalNr(i, 2); i+=2;
  1091. break;
  1092. }
  1093. }// end of internal switch
  1094. i+=2;
  1095. nobj.info = spec;
  1096. break;
  1097. }
  1098. case EDefType::WITCHHUT_DEF:
  1099. {
  1100. CWitchHutObjInfo * spec = new CWitchHutObjInfo;
  1101. ist=i; //starting i for loop
  1102. for(i; i<ist+4; ++i)
  1103. {
  1104. unsigned char c = bufor[i];
  1105. for(int yy=0; yy<8; ++yy)
  1106. {
  1107. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  1108. {
  1109. if(c == (c|((unsigned char)intPow(2, yy))))
  1110. spec->allowedAbilities.push_back(&(CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]));
  1111. }
  1112. }
  1113. }
  1114. nobj.info = spec;
  1115. break;
  1116. }
  1117. case EDefType::SCHOLAR_DEF:
  1118. {
  1119. CScholarObjInfo * spec = new CScholarObjInfo;
  1120. spec->bonusType = bufor[i]; ++i;
  1121. switch(spec->bonusType)
  1122. {
  1123. case 0xff:
  1124. ++i;
  1125. break;
  1126. case 0:
  1127. spec->r0type = bufor[i]; ++i;
  1128. break;
  1129. case 1:
  1130. spec->r1 = &(CGameInfo::mainObj->abilh->abilities[bufor[i]]); ++i;
  1131. break;
  1132. case 2:
  1133. spec->r2 = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1134. break;
  1135. }
  1136. i+=6;
  1137. nobj.info = spec;
  1138. break;
  1139. }
  1140. case EDefType::GARRISON_DEF:
  1141. {
  1142. CGarrisonObjInfo * spec = new CGarrisonObjInfo;
  1143. spec->player = bufor[i]; ++i;
  1144. i+=3;
  1145. spec->units = readCreatureSet(i); i+=28;
  1146. spec->movableUnits = bufor[i]; ++i;
  1147. i+=8;
  1148. nobj.info = spec;
  1149. break;
  1150. }
  1151. case EDefType::ARTIFACT_DEF:
  1152. {
  1153. CArtifactObjInfo * spec = new CArtifactObjInfo;
  1154. bool areSettings = bufor[i]; ++i;
  1155. if(areSettings)
  1156. {
  1157. int messLength = readNormalNr(i, 4); i+=4;
  1158. for(int hh=0; hh<messLength; ++hh)
  1159. {
  1160. spec->message += bufor[i]; ++i;
  1161. }
  1162. bool areGuards = bufor[i]; ++i;
  1163. if(areGuards)
  1164. {
  1165. spec->areGuards = true;
  1166. spec->guards = readCreatureSet(i); i+=28;
  1167. }
  1168. else
  1169. spec->areGuards = false;
  1170. i+=4;
  1171. }
  1172. nobj.info = spec;
  1173. break;
  1174. }
  1175. case EDefType::RESOURCE_DEF:
  1176. {
  1177. CResourceObjInfo * spec = new CResourceObjInfo;
  1178. bool isMessGuard = bufor[i]; ++i;
  1179. if(isMessGuard)
  1180. {
  1181. int messLength = readNormalNr(i); i+=4;
  1182. for(int mm=0; mm<messLength; ++mm)
  1183. {
  1184. spec->message+=bufor[i]; ++i;
  1185. }
  1186. spec->areGuards = bufor[i]; ++i;
  1187. if(spec->areGuards)
  1188. {
  1189. spec->guards = readCreatureSet(i); i+=28;
  1190. }
  1191. i+=4;
  1192. }
  1193. else
  1194. {
  1195. spec->areGuards = false;
  1196. }
  1197. spec->amount = readNormalNr(i); i+=4;
  1198. i+=4;
  1199. nobj.info = spec;
  1200. break;
  1201. }
  1202. case EDefType::TOWN_DEF:
  1203. {
  1204. CCastleObjInfo * spec = new CCastleObjInfo;
  1205. spec->bytes[0] = bufor[i]; ++i;
  1206. spec->bytes[1] = bufor[i]; ++i;
  1207. spec->bytes[2] = bufor[i]; ++i;
  1208. spec->bytes[3] = bufor[i]; ++i;
  1209. spec->player = bufor[i]; ++i;
  1210. bool hasName = bufor[i]; ++i;
  1211. if(hasName)
  1212. {
  1213. int len = readNormalNr(i); i+=4;
  1214. for(int gg=0; gg<len; ++gg)
  1215. {
  1216. spec->name += bufor[i]; ++i;
  1217. }
  1218. }
  1219. bool stGarr = bufor[i]; ++i; //true if garrison isn't empty
  1220. if(stGarr)
  1221. {
  1222. spec->garrison = readCreatureSet(i); i+=28;
  1223. }
  1224. spec->garrison.formation = bufor[i]; ++i;
  1225. spec->unusualBuildins = bufor[i]; ++i;
  1226. if(spec->unusualBuildins)
  1227. {
  1228. for(int ff=0; ff<12; ++ff)
  1229. {
  1230. spec->buildingSettings[ff] = bufor[i]; ++i;
  1231. }
  1232. }
  1233. else
  1234. {
  1235. spec->hasFort = bufor[i]; ++i;
  1236. }
  1237. int ist = i;
  1238. for(i; i<ist+9; ++i)
  1239. {
  1240. unsigned char c = bufor[i];
  1241. for(int yy=0; yy<8; ++yy)
  1242. {
  1243. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  1244. {
  1245. if(c == (c|((unsigned char)intPow(2, yy))))
  1246. spec->obligatorySpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  1247. }
  1248. }
  1249. }
  1250. ist = i;
  1251. for(i; i<ist+9; ++i)
  1252. {
  1253. unsigned char c = bufor[i];
  1254. for(int yy=0; yy<8; ++yy)
  1255. {
  1256. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  1257. {
  1258. if(c != (c|((unsigned char)intPow(2, yy))))
  1259. spec->possibleSpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  1260. }
  1261. }
  1262. }
  1263. /////// reading castle events //////////////////////////////////
  1264. int numberOfEvent = readNormalNr(i); i+=4;
  1265. for(int gh = 0; gh<numberOfEvent; ++gh)
  1266. {
  1267. CCastleEvent nce;
  1268. int nameLen = readNormalNr(i); i+=4;
  1269. for(int ll=0; ll<nameLen; ++ll)
  1270. {
  1271. nce.name += bufor[i]; ++i;
  1272. }
  1273. int messLen = readNormalNr(i); i+=4;
  1274. for(int ll=0; ll<messLen; ++ll)
  1275. {
  1276. nce.message += bufor[i]; ++i;
  1277. }
  1278. nce.wood = readNormalNr(i); i+=4;
  1279. nce.mercury = readNormalNr(i); i+=4;
  1280. nce.ore = readNormalNr(i); i+=4;
  1281. nce.sulfur = readNormalNr(i); i+=4;
  1282. nce.crystal = readNormalNr(i); i+=4;
  1283. nce.gems = readNormalNr(i); i+=4;
  1284. nce.gold = readNormalNr(i); i+=4;
  1285. nce.players = bufor[i]; ++i;
  1286. nce.forHuman = bufor[i]; ++i;
  1287. nce.forComputer = bufor[i]; ++i;
  1288. nce.firstShow = readNormalNr(i, 2); i+=2;
  1289. nce.forEvery = bufor[i]; ++i;
  1290. i+=17;
  1291. for(int kk=0; kk<6; ++kk)
  1292. {
  1293. nce.bytes[kk] = bufor[i]; ++i;
  1294. }
  1295. for(int vv=0; vv<7; ++vv)
  1296. {
  1297. nce.gen[vv] = readNormalNr(i, 2); i+=2;
  1298. }
  1299. i+=4;
  1300. spec->events.push_back(nce);
  1301. }
  1302. /////// castle events have been read ///////////////////////////
  1303. spec->alignment = bufor[i]; ++i;
  1304. i+=3;
  1305. nobj.info = spec;
  1306. break;
  1307. }
  1308. case EDefType::PLAYERONLY_DEF:
  1309. {
  1310. CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
  1311. spec->player = bufor[i]; ++i;
  1312. i+=3;
  1313. nobj.info = spec;
  1314. break;
  1315. }
  1316. case EDefType::SHRINE_DEF:
  1317. {
  1318. CShrineObjInfo * spec = new CShrineObjInfo;
  1319. spec->spell = bufor[i]; i+=4;
  1320. nobj.info = spec;
  1321. break;
  1322. }
  1323. case EDefType::SPELLSCROLL_DEF:
  1324. {
  1325. CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
  1326. bool messg = bufor[i]; ++i;
  1327. if(messg)
  1328. {
  1329. int mLength = readNormalNr(i); i+=4;
  1330. for(int vv=0; vv<mLength; ++vv)
  1331. {
  1332. spec->message += bufor[i]; ++i;
  1333. }
  1334. spec->areGuarders = bufor[i]; ++i;
  1335. if(spec->areGuarders)
  1336. {
  1337. spec->guarders = readCreatureSet(i); i+=28;
  1338. }
  1339. i+=4;
  1340. }
  1341. spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1342. i+=3;
  1343. nobj.info = spec;
  1344. break;
  1345. }
  1346. case EDefType::PANDORA_DEF:
  1347. {
  1348. CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
  1349. bool messg = bufor[i]; ++i;
  1350. if(messg)
  1351. {
  1352. int mLength = readNormalNr(i); i+=4;
  1353. for(int vv=0; vv<mLength; ++vv)
  1354. {
  1355. spec->message += bufor[i]; ++i;
  1356. }
  1357. spec->areGuarders = bufor[i]; ++i;
  1358. if(spec->areGuarders)
  1359. {
  1360. spec->guarders = readCreatureSet(i); i+=28;
  1361. }
  1362. i+=4;
  1363. }
  1364. ////// copied form event handling (seems to be similar)
  1365. spec->gainedExp = readNormalNr(i, 4); i+=4;
  1366. spec->manaDiff = readNormalNr(i, 4); i+=4;
  1367. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  1368. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  1369. spec->wood = readNormalNr(i); i+=4;
  1370. spec->mercury = readNormalNr(i); i+=4;
  1371. spec->ore = readNormalNr(i); i+=4;
  1372. spec->sulfur = readNormalNr(i); i+=4;
  1373. spec->crystal = readNormalNr(i); i+=4;
  1374. spec->gems = readNormalNr(i); i+=4;
  1375. spec->gold = readNormalNr(i); i+=4;
  1376. spec->attack = readNormalNr(i, 1); ++i;
  1377. spec->defence = readNormalNr(i, 1); ++i;
  1378. spec->power = readNormalNr(i, 1); ++i;
  1379. spec->knowledge = readNormalNr(i, 1); ++i;
  1380. int gabn; //number of gained abilities
  1381. gabn = readNormalNr(i, 1); ++i;
  1382. for(int oo = 0; oo<gabn; ++oo)
  1383. {
  1384. spec->abilities.push_back(&((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)])); ++i;
  1385. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  1386. }
  1387. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  1388. for(int oo = 0; oo<gart; ++oo)
  1389. {
  1390. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  1391. }
  1392. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  1393. for(int oo = 0; oo<gspel; ++oo)
  1394. {
  1395. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  1396. }
  1397. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  1398. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  1399. i+=8;
  1400. nobj.info = spec;
  1401. ///////end of copied fragment
  1402. break;
  1403. }
  1404. case EDefType::GRAIL_DEF:
  1405. {
  1406. CGrailObjInfo * spec = new CGrailObjInfo;
  1407. spec->radius = readNormalNr(i); i+=4;
  1408. nobj.info = spec;
  1409. break;
  1410. }
  1411. case EDefType::CREGEN_DEF:
  1412. {
  1413. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1414. spec->player = bufor[i]; ++i;
  1415. i+=3;
  1416. for(int ggg=0; ggg<4; ++ggg)
  1417. {
  1418. spec->bytes[ggg] = bufor[i]; ++i;
  1419. }
  1420. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1421. {
  1422. spec->asCastle = false;
  1423. spec->castles[0] = bufor[i]; ++i;
  1424. spec->castles[1] = bufor[i]; ++i;
  1425. }
  1426. else
  1427. {
  1428. spec->asCastle = true;
  1429. }
  1430. nobj.info = spec;
  1431. break;
  1432. }
  1433. case EDefType::CREGEN2_DEF:
  1434. {
  1435. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1436. spec->player = bufor[i]; ++i;
  1437. i+=3;
  1438. for(int ggg=0; ggg<4; ++ggg)
  1439. {
  1440. spec->bytes[ggg] = bufor[i]; ++i;
  1441. }
  1442. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1443. {
  1444. spec->asCastle = false;
  1445. spec->castles[0] = bufor[i]; ++i;
  1446. spec->castles[1] = bufor[i]; ++i;
  1447. }
  1448. else
  1449. {
  1450. spec->asCastle = true;
  1451. }
  1452. spec->minLevel = bufor[i]; ++i;
  1453. spec->maxLevel = bufor[i]; ++i;
  1454. nobj.info = spec;
  1455. break;
  1456. }
  1457. case EDefType::CREGEN3_DEF:
  1458. {
  1459. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1460. spec->player = bufor[i]; ++i;
  1461. i+=3;
  1462. spec->minLevel = bufor[i]; ++i;
  1463. spec->maxLevel = bufor[i]; ++i;
  1464. nobj.info = spec;
  1465. break;
  1466. }
  1467. case EDefType::BORDERGUARD_DEF:
  1468. {
  1469. CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
  1470. spec->missionType = bufor[i]; ++i;
  1471. switch(spec->missionType)
  1472. {
  1473. case 1:
  1474. {
  1475. spec->m1level = readNormalNr(i); i+=4;
  1476. int limit = readNormalNr(i); i+=4;
  1477. if(limit == ((int)0xffffffff))
  1478. {
  1479. spec->isDayLimit = false;
  1480. spec->lastDay = -1;
  1481. }
  1482. else
  1483. {
  1484. spec->isDayLimit = true;
  1485. spec->lastDay = limit;
  1486. }
  1487. break;
  1488. }
  1489. case 2:
  1490. {
  1491. spec->m2attack = bufor[i]; ++i;
  1492. spec->m2defence = bufor[i]; ++i;
  1493. spec->m2power = bufor[i]; ++i;
  1494. spec->m2knowledge = bufor[i]; ++i;
  1495. int limit = readNormalNr(i); i+=4;
  1496. if(limit == ((int)0xffffffff))
  1497. {
  1498. spec->isDayLimit = false;
  1499. spec->lastDay = -1;
  1500. }
  1501. else
  1502. {
  1503. spec->isDayLimit = true;
  1504. spec->lastDay = limit;
  1505. }
  1506. break;
  1507. }
  1508. case 3:
  1509. {
  1510. spec->m3bytes[0] = bufor[i]; ++i;
  1511. spec->m3bytes[1] = bufor[i]; ++i;
  1512. spec->m3bytes[2] = bufor[i]; ++i;
  1513. spec->m3bytes[3] = bufor[i]; ++i;
  1514. int limit = readNormalNr(i); i+=4;
  1515. if(limit == ((int)0xffffffff))
  1516. {
  1517. spec->isDayLimit = false;
  1518. spec->lastDay = -1;
  1519. }
  1520. else
  1521. {
  1522. spec->isDayLimit = true;
  1523. spec->lastDay = limit;
  1524. }
  1525. break;
  1526. }
  1527. case 4:
  1528. {
  1529. spec->m4bytes[0] = bufor[i]; ++i;
  1530. spec->m4bytes[1] = bufor[i]; ++i;
  1531. spec->m4bytes[2] = bufor[i]; ++i;
  1532. spec->m4bytes[3] = bufor[i]; ++i;
  1533. int limit = readNormalNr(i); i+=4;
  1534. if(limit == ((int)0xffffffff))
  1535. {
  1536. spec->isDayLimit = false;
  1537. spec->lastDay = -1;
  1538. }
  1539. else
  1540. {
  1541. spec->isDayLimit = true;
  1542. spec->lastDay = limit;
  1543. }
  1544. break;
  1545. }
  1546. case 5:
  1547. {
  1548. int artNumber = bufor[i]; ++i;
  1549. for(int yy=0; yy<artNumber; ++yy)
  1550. {
  1551. int artid = readNormalNr(i, 2); i+=2;
  1552. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  1553. }
  1554. int limit = readNormalNr(i); i+=4;
  1555. if(limit == ((int)0xffffffff))
  1556. {
  1557. spec->isDayLimit = false;
  1558. spec->lastDay = -1;
  1559. }
  1560. else
  1561. {
  1562. spec->isDayLimit = true;
  1563. spec->lastDay = limit;
  1564. }
  1565. break;
  1566. }
  1567. case 6:
  1568. {
  1569. int typeNumber = bufor[i]; ++i;
  1570. for(int hh=0; hh<typeNumber; ++hh)
  1571. {
  1572. int creType = readNormalNr(i, 2); i+=2;
  1573. int creNumb = readNormalNr(i, 2); i+=2;
  1574. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  1575. spec->m6number.push_back(creNumb);
  1576. }
  1577. int limit = readNormalNr(i); i+=4;
  1578. if(limit == ((int)0xffffffff))
  1579. {
  1580. spec->isDayLimit = false;
  1581. spec->lastDay = -1;
  1582. }
  1583. else
  1584. {
  1585. spec->isDayLimit = true;
  1586. spec->lastDay = limit;
  1587. }
  1588. break;
  1589. }
  1590. case 7:
  1591. {
  1592. spec->m7wood = readNormalNr(i); i+=4;
  1593. spec->m7mercury = readNormalNr(i); i+=4;
  1594. spec->m7ore = readNormalNr(i); i+=4;
  1595. spec->m7sulfur = readNormalNr(i); i+=4;
  1596. spec->m7crystal = readNormalNr(i); i+=4;
  1597. spec->m7gems = readNormalNr(i); i+=4;
  1598. spec->m7gold = readNormalNr(i); i+=4;
  1599. int limit = readNormalNr(i); i+=4;
  1600. if(limit == ((int)0xffffffff))
  1601. {
  1602. spec->isDayLimit = false;
  1603. spec->lastDay = -1;
  1604. }
  1605. else
  1606. {
  1607. spec->isDayLimit = true;
  1608. spec->lastDay = limit;
  1609. }
  1610. break;
  1611. }
  1612. case 8:
  1613. {
  1614. int heroType = bufor[i]; ++i;
  1615. spec->m8hero = &(CGameInfo::mainObj->heroh->heroes[heroType]);
  1616. int limit = readNormalNr(i); i+=4;
  1617. if(limit == ((int)0xffffffff))
  1618. {
  1619. spec->isDayLimit = false;
  1620. spec->lastDay = -1;
  1621. }
  1622. else
  1623. {
  1624. spec->isDayLimit = true;
  1625. spec->lastDay = limit;
  1626. }
  1627. break;
  1628. }
  1629. case 9:
  1630. {
  1631. spec->m9player = bufor[i]; ++i;
  1632. int limit = readNormalNr(i); i+=4;
  1633. if(limit == ((int)0xffffffff))
  1634. {
  1635. spec->isDayLimit = false;
  1636. spec->lastDay = -1;
  1637. }
  1638. else
  1639. {
  1640. spec->isDayLimit = true;
  1641. spec->lastDay = limit;
  1642. }
  1643. break;
  1644. }
  1645. }//internal switch end (seer huts)
  1646. int len1 = readNormalNr(i); i+=4;
  1647. for(int ee=0; ee<len1; ++ee)
  1648. {
  1649. spec->firstVisitText += bufor[i]; ++i;
  1650. }
  1651. int len2 = readNormalNr(i); i+=4;
  1652. for(int ee=0; ee<len2; ++ee)
  1653. {
  1654. spec->nextVisitText += bufor[i]; ++i;
  1655. }
  1656. int len3 = readNormalNr(i); i+=4;
  1657. for(int ee=0; ee<len3; ++ee)
  1658. {
  1659. spec->completedText += bufor[i]; ++i;
  1660. }
  1661. nobj.info = spec;
  1662. break;
  1663. }
  1664. } //end of main switch
  1665. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  1666. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  1667. }//*/ //end of loading objects; commented to make application work until it will be finished
  1668. ////objects loaded
  1669. //loading events
  1670. int numberOfEvents = readNormalNr(i); i+=4;
  1671. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  1672. {
  1673. CMapEvent ne;
  1674. ne.name = std::string();
  1675. ne.message = std::string();
  1676. int nameLen = readNormalNr(i); i+=4;
  1677. for(int qq=0; qq<nameLen; ++qq)
  1678. {
  1679. ne.name += bufor[i]; ++i;
  1680. }
  1681. int messLen = readNormalNr(i); i+=4;
  1682. for(int qq=0; qq<messLen; ++qq)
  1683. {
  1684. ne.message +=bufor[i]; ++i;
  1685. }
  1686. ne.wood = readNormalNr(i); i+=4;
  1687. ne.mercury = readNormalNr(i); i+=4;
  1688. ne.ore = readNormalNr(i); i+=4;
  1689. ne.sulfur = readNormalNr(i); i+=4;
  1690. ne.crystal = readNormalNr(i); i+=4;
  1691. ne.gems = readNormalNr(i); i+=4;
  1692. ne.gold = readNormalNr(i); i+=4;
  1693. ne.players = bufor[i]; ++i;
  1694. ne.humanAffected = bufor[i]; ++i;
  1695. ne.computerAffected = bufor[i]; ++i;
  1696. ne.firstOccurence = bufor[i]; ++i;
  1697. ne.nextOccurence = bufor[i]; ++i;
  1698. i+=18;
  1699. map.events.push_back(ne);
  1700. }
  1701. }
  1702. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  1703. {
  1704. int ret=0;
  1705. int amp=1;
  1706. for (int i=0; i<bytCon; i++)
  1707. {
  1708. ret+=bufor[pos+i]*amp;
  1709. amp*=256;
  1710. }
  1711. if(cyclic && bytCon<4 && ret>=amp/2)
  1712. {
  1713. ret = ret-amp;
  1714. }
  1715. return ret;
  1716. }
  1717. void CAmbarCendamo::loadDefs()
  1718. {
  1719. std::set<int> loadedTypes;
  1720. for (int i=0; i<map.width; i++)
  1721. {
  1722. for (int j=0; j<map.width; j++)
  1723. {
  1724. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  1725. {
  1726. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str());
  1727. loadedTypes.insert(map.terrain[i][j].tertype);
  1728. defs.push_back(sdh);
  1729. }
  1730. if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  1731. {
  1732. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str());
  1733. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  1734. defs.push_back(sdh);
  1735. }
  1736. }
  1737. }
  1738. }
  1739. EDefType CAmbarCendamo::getDefType(DefInfo &a)
  1740. {
  1741. switch(a.bytes[16])
  1742. {
  1743. case 5: case 65: case 66: case 67: case 68: case 69:
  1744. return EDefType::ARTIFACT_DEF; //handled
  1745. case 6:
  1746. return EDefType::PANDORA_DEF; //hanled
  1747. case 26:
  1748. return EDefType::EVENTOBJ_DEF; //handled
  1749. case 33:
  1750. return EDefType::GARRISON_DEF; //handled
  1751. case 34: case 70: case 62: //70 - random hero //62 - prison
  1752. return EDefType::HERO_DEF; //handled
  1753. case 36:
  1754. return EDefType::GRAIL_DEF; //hanled
  1755. case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
  1756. return EDefType::PLAYERONLY_DEF; //handled
  1757. case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
  1758. return EDefType::CREATURES_DEF; //handled
  1759. case 59:
  1760. return EDefType::SIGN_DEF; //handled
  1761. case 77:
  1762. return EDefType::TOWN_DEF; //can be problematic, but handled
  1763. case 79: case 76:
  1764. return EDefType::RESOURCE_DEF; //handled
  1765. case 81:
  1766. return EDefType::SCHOLAR_DEF; //handled
  1767. case 83:
  1768. return EDefType::SEERHUT_DEF; //handled
  1769. case 91:
  1770. return EDefType::SIGN_DEF; //handled
  1771. case 88: case 89: case 90:
  1772. return SHRINE_DEF; //handled
  1773. case 93:
  1774. return SPELLSCROLL_DEF; //handled
  1775. case 98:
  1776. return EDefType::TOWN_DEF; //handled
  1777. case 113:
  1778. return EDefType::WITCHHUT_DEF; //handled
  1779. case 215:
  1780. return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;]
  1781. case 216:
  1782. return EDefType::CREGEN2_DEF; //handled
  1783. case 217:
  1784. return EDefType::CREGEN_DEF; //handled
  1785. case 218:
  1786. return EDefType::CREGEN3_DEF; //handled
  1787. case 219:
  1788. return EDefType::GARRISON_DEF; //handled
  1789. default:
  1790. return EDefType::TERRAINOBJ_DEF; // nothing to be handled
  1791. }
  1792. }
  1793. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  1794. {
  1795. CCreatureSet ret;
  1796. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  1797. {
  1798. int rettt = readNormalNr(pos, 2);
  1799. if(rettt>32768)
  1800. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1801. ret.slot1 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1802. ret.s1 = readNormalNr(pos+2, 2);
  1803. }
  1804. else
  1805. {
  1806. ret.slot1 = NULL;
  1807. ret.s1 = 0;
  1808. }
  1809. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  1810. {
  1811. int rettt = readNormalNr(pos+4, 2);
  1812. if(rettt>32768)
  1813. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1814. ret.slot2 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1815. ret.s2 = readNormalNr(pos+6, 2);
  1816. }
  1817. else
  1818. {
  1819. ret.slot2 = NULL;
  1820. ret.s2 = 0;
  1821. }
  1822. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  1823. {
  1824. int rettt = readNormalNr(pos+8, 2);
  1825. if(rettt>32768)
  1826. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1827. ret.slot3 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1828. ret.s3 = readNormalNr(pos+10, 2);
  1829. }
  1830. else
  1831. {
  1832. ret.slot3 = NULL;
  1833. ret.s3 = 0;
  1834. }
  1835. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  1836. {
  1837. int rettt = readNormalNr(pos+12, 2);
  1838. if(rettt>32768)
  1839. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1840. ret.slot4 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1841. ret.s4 = readNormalNr(pos+14, 2);
  1842. }
  1843. else
  1844. {
  1845. ret.slot4 = NULL;
  1846. ret.s4 = 0;
  1847. }
  1848. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  1849. {
  1850. int rettt = readNormalNr(pos+16, 2);
  1851. if(rettt>32768)
  1852. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1853. ret.slot5 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1854. ret.s5 = readNormalNr(pos+18, 2);
  1855. }
  1856. else
  1857. {
  1858. ret.slot5 = NULL;
  1859. ret.s5 = 0;
  1860. }
  1861. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  1862. {
  1863. int rettt = readNormalNr(pos+20, 2);
  1864. if(rettt>32768)
  1865. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1866. ret.slot6 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1867. ret.s6 = readNormalNr(pos+22, 2);
  1868. }
  1869. else
  1870. {
  1871. ret.slot6 = NULL;
  1872. ret.s6 = 0;
  1873. }
  1874. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  1875. {
  1876. int rettt = readNormalNr(pos+24, 2);
  1877. if(rettt>32768)
  1878. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1879. ret.slot7 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1880. ret.s7 = readNormalNr(pos+26, 2);
  1881. }
  1882. else
  1883. {
  1884. ret.slot7 = NULL;
  1885. ret.s7 = 0;
  1886. }
  1887. return ret;
  1888. }