CAmbarCendamo.cpp 52 KB

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