CAmbarCendamo.cpp 52 KB

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