CAmbarCendamo.cpp 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  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); i+=2;
  1291. }
  1292. i+=4;
  1293. spec->events.push_back(nce);
  1294. }
  1295. /////// castle events have been read ///////////////////////////
  1296. spec->alignment = bufor[i]; ++i;
  1297. i+=3;
  1298. nobj.info = spec;
  1299. break;
  1300. }
  1301. case EDefType::PLAYERONLY_DEF:
  1302. {
  1303. CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
  1304. spec->player = bufor[i]; ++i;
  1305. i+=3;
  1306. nobj.info = spec;
  1307. break;
  1308. }
  1309. case EDefType::SHRINE_DEF:
  1310. {
  1311. CShrineObjInfo * spec = new CShrineObjInfo;
  1312. spec->spell = bufor[i]; i+=4;
  1313. nobj.info = spec;
  1314. break;
  1315. }
  1316. case EDefType::SPELLSCROLL_DEF:
  1317. {
  1318. CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
  1319. bool messg = bufor[i]; ++i;
  1320. if(messg)
  1321. {
  1322. int mLength = readNormalNr(i); i+=4;
  1323. for(int vv=0; vv<mLength; ++vv)
  1324. {
  1325. spec->message += bufor[i]; ++i;
  1326. }
  1327. spec->areGuarders = bufor[i]; ++i;
  1328. if(spec->areGuarders)
  1329. {
  1330. spec->guarders = readCreatureSet(i); i+=28;
  1331. }
  1332. i+=4;
  1333. }
  1334. spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1335. i+=3;
  1336. nobj.info = spec;
  1337. break;
  1338. }
  1339. case EDefType::PANDORA_DEF:
  1340. {
  1341. CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
  1342. bool messg = bufor[i]; ++i;
  1343. if(messg)
  1344. {
  1345. int mLength = readNormalNr(i); i+=4;
  1346. for(int vv=0; vv<mLength; ++vv)
  1347. {
  1348. spec->message += bufor[i]; ++i;
  1349. }
  1350. spec->areGuarders = bufor[i]; ++i;
  1351. if(spec->areGuarders)
  1352. {
  1353. spec->guarders = readCreatureSet(i); i+=28;
  1354. }
  1355. i+=4;
  1356. }
  1357. ////// copied form event handling (seems to be similar)
  1358. spec->gainedExp = readNormalNr(i, 4); i+=4;
  1359. spec->manaDiff = readNormalNr(i, 4); i+=4;
  1360. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  1361. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  1362. spec->wood = readNormalNr(i); i+=4;
  1363. spec->mercury = readNormalNr(i); i+=4;
  1364. spec->ore = readNormalNr(i); i+=4;
  1365. spec->sulfur = readNormalNr(i); i+=4;
  1366. spec->crystal = readNormalNr(i); i+=4;
  1367. spec->gems = readNormalNr(i); i+=4;
  1368. spec->gold = readNormalNr(i); i+=4;
  1369. spec->attack = readNormalNr(i, 1); ++i;
  1370. spec->defence = readNormalNr(i, 1); ++i;
  1371. spec->power = readNormalNr(i, 1); ++i;
  1372. spec->knowledge = readNormalNr(i, 1); ++i;
  1373. int gabn; //number of gained abilities
  1374. gabn = readNormalNr(i, 1); ++i;
  1375. for(int oo = 0; oo<gabn; ++oo)
  1376. {
  1377. spec->abilities.push_back(&((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)])); ++i;
  1378. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  1379. }
  1380. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  1381. for(int oo = 0; oo<gart; ++oo)
  1382. {
  1383. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  1384. }
  1385. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  1386. for(int oo = 0; oo<gspel; ++oo)
  1387. {
  1388. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  1389. }
  1390. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  1391. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  1392. i+=8;
  1393. nobj.info = spec;
  1394. ///////end of copied fragment
  1395. break;
  1396. }
  1397. case EDefType::GRAIL_DEF:
  1398. {
  1399. CGrailObjInfo * spec = new CGrailObjInfo;
  1400. spec->radius = readNormalNr(i); i+=4;
  1401. nobj.info = spec;
  1402. break;
  1403. }
  1404. case EDefType::CREGEN_DEF:
  1405. {
  1406. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1407. spec->player = bufor[i]; ++i;
  1408. i+=3;
  1409. for(int ggg=0; ggg<4; ++ggg)
  1410. {
  1411. spec->bytes[ggg] = bufor[i]; ++i;
  1412. }
  1413. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1414. {
  1415. spec->asCastle = false;
  1416. spec->castles[0] = bufor[i]; ++i;
  1417. spec->castles[1] = bufor[i]; ++i;
  1418. }
  1419. else
  1420. {
  1421. spec->asCastle = true;
  1422. }
  1423. nobj.info = spec;
  1424. break;
  1425. }
  1426. case EDefType::CREGEN2_DEF:
  1427. {
  1428. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1429. spec->player = bufor[i]; ++i;
  1430. i+=3;
  1431. for(int ggg=0; ggg<4; ++ggg)
  1432. {
  1433. spec->bytes[ggg] = bufor[i]; ++i;
  1434. }
  1435. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1436. {
  1437. spec->asCastle = false;
  1438. spec->castles[0] = bufor[i]; ++i;
  1439. spec->castles[1] = bufor[i]; ++i;
  1440. }
  1441. else
  1442. {
  1443. spec->asCastle = true;
  1444. }
  1445. spec->minLevel = bufor[i]; ++i;
  1446. spec->maxLevel = bufor[i]; ++i;
  1447. nobj.info = spec;
  1448. break;
  1449. }
  1450. case EDefType::CREGEN3_DEF:
  1451. {
  1452. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1453. spec->player = bufor[i]; ++i;
  1454. i+=3;
  1455. spec->minLevel = bufor[i]; ++i;
  1456. spec->maxLevel = bufor[i]; ++i;
  1457. nobj.info = spec;
  1458. break;
  1459. }
  1460. case EDefType::BORDERGUARD_DEF:
  1461. {
  1462. CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
  1463. spec->missionType = bufor[i]; ++i;
  1464. switch(spec->missionType)
  1465. {
  1466. case 1:
  1467. {
  1468. spec->m1level = readNormalNr(i); i+=4;
  1469. int limit = readNormalNr(i); i+=4;
  1470. if(limit == ((int)0xffffffff))
  1471. {
  1472. spec->isDayLimit = false;
  1473. spec->lastDay = -1;
  1474. }
  1475. else
  1476. {
  1477. spec->isDayLimit = true;
  1478. spec->lastDay = limit;
  1479. }
  1480. break;
  1481. }
  1482. case 2:
  1483. {
  1484. spec->m2attack = bufor[i]; ++i;
  1485. spec->m2defence = bufor[i]; ++i;
  1486. spec->m2power = bufor[i]; ++i;
  1487. spec->m2knowledge = bufor[i]; ++i;
  1488. int limit = readNormalNr(i); i+=4;
  1489. if(limit == ((int)0xffffffff))
  1490. {
  1491. spec->isDayLimit = false;
  1492. spec->lastDay = -1;
  1493. }
  1494. else
  1495. {
  1496. spec->isDayLimit = true;
  1497. spec->lastDay = limit;
  1498. }
  1499. break;
  1500. }
  1501. case 3:
  1502. {
  1503. spec->m3bytes[0] = bufor[i]; ++i;
  1504. spec->m3bytes[1] = bufor[i]; ++i;
  1505. spec->m3bytes[2] = bufor[i]; ++i;
  1506. spec->m3bytes[3] = bufor[i]; ++i;
  1507. int limit = readNormalNr(i); i+=4;
  1508. if(limit == ((int)0xffffffff))
  1509. {
  1510. spec->isDayLimit = false;
  1511. spec->lastDay = -1;
  1512. }
  1513. else
  1514. {
  1515. spec->isDayLimit = true;
  1516. spec->lastDay = limit;
  1517. }
  1518. break;
  1519. }
  1520. case 4:
  1521. {
  1522. spec->m4bytes[0] = bufor[i]; ++i;
  1523. spec->m4bytes[1] = bufor[i]; ++i;
  1524. spec->m4bytes[2] = bufor[i]; ++i;
  1525. spec->m4bytes[3] = bufor[i]; ++i;
  1526. int limit = readNormalNr(i); i+=4;
  1527. if(limit == ((int)0xffffffff))
  1528. {
  1529. spec->isDayLimit = false;
  1530. spec->lastDay = -1;
  1531. }
  1532. else
  1533. {
  1534. spec->isDayLimit = true;
  1535. spec->lastDay = limit;
  1536. }
  1537. break;
  1538. }
  1539. case 5:
  1540. {
  1541. int artNumber = bufor[i]; ++i;
  1542. for(int yy=0; yy<artNumber; ++yy)
  1543. {
  1544. int artid = readNormalNr(i, 2); i+=2;
  1545. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  1546. }
  1547. int limit = readNormalNr(i); i+=4;
  1548. if(limit == ((int)0xffffffff))
  1549. {
  1550. spec->isDayLimit = false;
  1551. spec->lastDay = -1;
  1552. }
  1553. else
  1554. {
  1555. spec->isDayLimit = true;
  1556. spec->lastDay = limit;
  1557. }
  1558. break;
  1559. }
  1560. case 6:
  1561. {
  1562. int typeNumber = bufor[i]; ++i;
  1563. for(int hh=0; hh<typeNumber; ++hh)
  1564. {
  1565. int creType = readNormalNr(i, 2); i+=2;
  1566. int creNumb = readNormalNr(i, 2); i+=2;
  1567. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  1568. spec->m6number.push_back(creNumb);
  1569. }
  1570. int limit = readNormalNr(i); i+=4;
  1571. if(limit == ((int)0xffffffff))
  1572. {
  1573. spec->isDayLimit = false;
  1574. spec->lastDay = -1;
  1575. }
  1576. else
  1577. {
  1578. spec->isDayLimit = true;
  1579. spec->lastDay = limit;
  1580. }
  1581. break;
  1582. }
  1583. case 7:
  1584. {
  1585. spec->m7wood = readNormalNr(i); i+=4;
  1586. spec->m7mercury = readNormalNr(i); i+=4;
  1587. spec->m7ore = readNormalNr(i); i+=4;
  1588. spec->m7sulfur = readNormalNr(i); i+=4;
  1589. spec->m7crystal = readNormalNr(i); i+=4;
  1590. spec->m7gems = readNormalNr(i); i+=4;
  1591. spec->m7gold = readNormalNr(i); i+=4;
  1592. int limit = readNormalNr(i); i+=4;
  1593. if(limit == ((int)0xffffffff))
  1594. {
  1595. spec->isDayLimit = false;
  1596. spec->lastDay = -1;
  1597. }
  1598. else
  1599. {
  1600. spec->isDayLimit = true;
  1601. spec->lastDay = limit;
  1602. }
  1603. break;
  1604. }
  1605. case 8:
  1606. {
  1607. int heroType = bufor[i]; ++i;
  1608. spec->m8hero = &(CGameInfo::mainObj->heroh->heroes[heroType]);
  1609. int limit = readNormalNr(i); i+=4;
  1610. if(limit == ((int)0xffffffff))
  1611. {
  1612. spec->isDayLimit = false;
  1613. spec->lastDay = -1;
  1614. }
  1615. else
  1616. {
  1617. spec->isDayLimit = true;
  1618. spec->lastDay = limit;
  1619. }
  1620. break;
  1621. }
  1622. case 9:
  1623. {
  1624. spec->m9player = bufor[i]; ++i;
  1625. int limit = readNormalNr(i); i+=4;
  1626. if(limit == ((int)0xffffffff))
  1627. {
  1628. spec->isDayLimit = false;
  1629. spec->lastDay = -1;
  1630. }
  1631. else
  1632. {
  1633. spec->isDayLimit = true;
  1634. spec->lastDay = limit;
  1635. }
  1636. break;
  1637. }
  1638. }//internal switch end (seer huts)
  1639. int len1 = readNormalNr(i); i+=4;
  1640. for(int ee=0; ee<len1; ++ee)
  1641. {
  1642. spec->firstVisitText += bufor[i]; ++i;
  1643. }
  1644. int len2 = readNormalNr(i); i+=4;
  1645. for(int ee=0; ee<len2; ++ee)
  1646. {
  1647. spec->nextVisitText += bufor[i]; ++i;
  1648. }
  1649. int len3 = readNormalNr(i); i+=4;
  1650. for(int ee=0; ee<len3; ++ee)
  1651. {
  1652. spec->completedText += bufor[i]; ++i;
  1653. }
  1654. nobj.info = spec;
  1655. break;
  1656. }
  1657. } //end of main switch
  1658. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  1659. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  1660. }//*/ //end of loading objects; commented to make application work until it will be finished
  1661. ////objects loaded
  1662. //loading events
  1663. int numberOfEvents = readNormalNr(i); i+=4;
  1664. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  1665. {
  1666. CMapEvent ne;
  1667. ne.name = std::string();
  1668. ne.message = std::string();
  1669. int nameLen = readNormalNr(i); i+=4;
  1670. for(int qq=0; qq<nameLen; ++qq)
  1671. {
  1672. ne.name += bufor[i]; ++i;
  1673. }
  1674. int messLen = readNormalNr(i); i+=4;
  1675. for(int qq=0; qq<messLen; ++qq)
  1676. {
  1677. ne.message +=bufor[i]; ++i;
  1678. }
  1679. ne.wood = readNormalNr(i); i+=4;
  1680. ne.mercury = readNormalNr(i); i+=4;
  1681. ne.ore = readNormalNr(i); i+=4;
  1682. ne.sulfur = readNormalNr(i); i+=4;
  1683. ne.crystal = readNormalNr(i); i+=4;
  1684. ne.gems = readNormalNr(i); i+=4;
  1685. ne.gold = readNormalNr(i); i+=4;
  1686. ne.players = bufor[i]; ++i;
  1687. ne.humanAffected = bufor[i]; ++i;
  1688. ne.computerAffected = bufor[i]; ++i;
  1689. ne.firstOccurence = bufor[i]; ++i;
  1690. ne.nextOccurence = bufor[i]; ++i;
  1691. i+=18;
  1692. map.events.push_back(ne);
  1693. }
  1694. }
  1695. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  1696. {
  1697. int ret=0;
  1698. int amp=1;
  1699. for (int i=0; i<bytCon; i++)
  1700. {
  1701. ret+=bufor[pos+i]*amp;
  1702. amp*=256;
  1703. }
  1704. if(cyclic && bytCon<4 && ret>=amp/2)
  1705. {
  1706. ret = ret-amp;
  1707. }
  1708. return ret;
  1709. }
  1710. void CAmbarCendamo::loadDefs()
  1711. {
  1712. std::set<int> loadedTypes;
  1713. for (int i=0; i<map.width; i++)
  1714. {
  1715. for (int j=0; j<map.width; j++)
  1716. {
  1717. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  1718. {
  1719. CSemiDefHandler *sdh = new CSemiDefHandler();
  1720. sdh->openDef((sdh->nameFromType(map.terrain[i][j].tertype)).c_str(),"H3sprite.lod");
  1721. loadedTypes.insert(map.terrain[i][j].tertype);
  1722. defs.push_back(sdh);
  1723. }
  1724. if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  1725. {
  1726. CSemiDefHandler *sdh = new CSemiDefHandler();
  1727. sdh->openDef((sdh->nameFromType(map.undergroungTerrain[i][j].tertype)).c_str(),"H3sprite.lod");
  1728. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  1729. defs.push_back(sdh);
  1730. }
  1731. }
  1732. }
  1733. }
  1734. EDefType CAmbarCendamo::getDefType(DefInfo &a)
  1735. {
  1736. switch(a.bytes[16])
  1737. {
  1738. case 5: case 65: case 66: case 67: case 68: case 69:
  1739. return EDefType::ARTIFACT_DEF; //handled
  1740. case 6:
  1741. return EDefType::PANDORA_DEF; //hanled
  1742. case 26:
  1743. return EDefType::EVENTOBJ_DEF; //handled
  1744. case 33:
  1745. return EDefType::GARRISON_DEF; //handled
  1746. case 34: case 70: //70 - random hero
  1747. return EDefType::HERO_DEF; //handled
  1748. case 36:
  1749. return EDefType::GRAIL_DEF; //hanled
  1750. case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
  1751. return EDefType::PLAYERONLY_DEF; //handled
  1752. case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
  1753. return EDefType::CREATURES_DEF; //handled
  1754. case 59:
  1755. return EDefType::SIGN_DEF; //handled
  1756. case 77:
  1757. return EDefType::TOWN_DEF; //can be problematic, but handled
  1758. case 79: case 76:
  1759. return EDefType::RESOURCE_DEF; //handled
  1760. case 81:
  1761. return EDefType::SCHOLAR_DEF; //handled
  1762. case 83:
  1763. return EDefType::SEERHUT_DEF; //handled
  1764. case 91:
  1765. return EDefType::SIGN_DEF; //handled
  1766. case 88: case 89: case 90:
  1767. return SHRINE_DEF; //handled
  1768. case 93:
  1769. return SPELLSCROLL_DEF; //handled
  1770. case 98:
  1771. return EDefType::TOWN_DEF; //handled
  1772. case 113:
  1773. return EDefType::WITCHHUT_DEF; //handled
  1774. case 215:
  1775. return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;]
  1776. case 216:
  1777. return EDefType::CREGEN2_DEF; //handled
  1778. case 217:
  1779. return EDefType::CREGEN_DEF; //handled
  1780. case 218:
  1781. return EDefType::CREGEN3_DEF; //handled
  1782. case 219:
  1783. return EDefType::GARRISON_DEF; //handled
  1784. default:
  1785. return EDefType::TERRAINOBJ_DEF; // nothing to be handled
  1786. }
  1787. }
  1788. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  1789. {
  1790. CCreatureSet ret;
  1791. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  1792. {
  1793. ret.slot1 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos, 2)]);
  1794. ret.s1 = readNormalNr(pos+2, 2);
  1795. }
  1796. else
  1797. {
  1798. ret.slot1 = NULL;
  1799. ret.s1 = 0;
  1800. }
  1801. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  1802. {
  1803. ret.slot2 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+4, 2)]);
  1804. ret.s2 = readNormalNr(pos+6, 2);
  1805. }
  1806. else
  1807. {
  1808. ret.slot2 = NULL;
  1809. ret.s2 = 0;
  1810. }
  1811. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  1812. {
  1813. ret.slot3 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+8, 2)]);
  1814. ret.s3 = readNormalNr(pos+10, 2);
  1815. }
  1816. else
  1817. {
  1818. ret.slot3 = NULL;
  1819. ret.s3 = 0;
  1820. }
  1821. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  1822. {
  1823. ret.slot4 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+12, 2)]);
  1824. ret.s4 = readNormalNr(pos+14, 2);
  1825. }
  1826. else
  1827. {
  1828. ret.slot4 = NULL;
  1829. ret.s4 = 0;
  1830. }
  1831. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  1832. {
  1833. ret.slot5 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+16, 2)]);
  1834. ret.s5 = readNormalNr(pos+18, 2);
  1835. }
  1836. else
  1837. {
  1838. ret.slot5 = NULL;
  1839. ret.s5 = 0;
  1840. }
  1841. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  1842. {
  1843. ret.slot6 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+20, 2)]);
  1844. ret.s6 = readNormalNr(pos+22, 2);
  1845. }
  1846. else
  1847. {
  1848. ret.slot6 = NULL;
  1849. ret.s6 = 0;
  1850. }
  1851. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  1852. {
  1853. ret.slot7 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+24, 2)]);
  1854. ret.s7 = readNormalNr(pos+26, 2);
  1855. }
  1856. else
  1857. {
  1858. ret.slot7 = NULL;
  1859. ret.s7 = 0;
  1860. }
  1861. return ret;
  1862. }