CAmbarCendamo.cpp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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 <set>
  8. unsigned int intPow(unsigned int a, unsigned int b)
  9. {
  10. unsigned int ret=1;
  11. for(int i=0; i<b; ++i)
  12. ret*=a;
  13. return ret;
  14. }
  15. CAmbarCendamo::CAmbarCendamo (const char * tie)
  16. {
  17. is = new std::ifstream();
  18. is -> open(tie,std::ios::binary);
  19. is->seekg(0,std::ios::end); // na koniec
  20. andame = is->tellg(); // read length
  21. is->seekg(0,std::ios::beg); // wracamy na poczatek
  22. bufor = new unsigned char[andame]; // allocate memory
  23. is->read((char*)bufor, andame); // read map file to buffer
  24. delete is;
  25. }
  26. CAmbarCendamo::~CAmbarCendamo ()
  27. {// free memory
  28. for (int ii=0;ii<map.width;ii++)
  29. delete map.terrain[ii] ;
  30. delete map.terrain;
  31. delete bufor;
  32. }
  33. void CAmbarCendamo::teceDef()
  34. {
  35. for (int i=0; i<map.defy.size(); i++)
  36. {
  37. std::ofstream * of = new std::ofstream(map.defy[i].name.c_str());
  38. for (int j=0;j<46;j++)
  39. {
  40. (*of) << map.defy[i].bytes[j]<<std::endl;
  41. }
  42. delete of;
  43. }
  44. }
  45. void CAmbarCendamo::deh3m()
  46. {
  47. THC timeHandler th;
  48. map.version = (Eformat)bufor[0]; //wersja mapy
  49. map.areAnyPLayers = bufor[4];
  50. map.height = map.width = bufor[5]; // wymiary mapy
  51. map.twoLevel = bufor[9]; //czy sa lochy
  52. map.terrain = new TerrainTile*[map.width]; // allocate memory
  53. for (int ii=0;ii<map.width;ii++)
  54. map.terrain[ii] = new TerrainTile[map.height]; // allocate memory
  55. if (map.twoLevel)
  56. {
  57. map.undergroungTerrain = new TerrainTile*[map.width]; // allocate memory
  58. for (int ii=0;ii<map.width;ii++)
  59. map.undergroungTerrain[ii] = new TerrainTile[map.height]; // allocate memory
  60. }
  61. int length = bufor[10]; //name length
  62. int i=14, pom;
  63. while (i-14<length) //read name
  64. map.name+=bufor[i++];
  65. length = bufor[i] + bufor[i+1]*256; //description length
  66. i+=4;
  67. for (pom=0;pom<length;pom++)
  68. map.description+=bufor[i++];
  69. map.difficulty = bufor[i++]; // reading map difficulty
  70. map.levelLimit = bufor[i++]; // hero level limit
  71. for (pom=0;pom<8;pom++)
  72. {
  73. map.players[pom].canHumanPlay = bufor[i++];
  74. map.players[pom].canComputerPlay = bufor[i++];
  75. if ((!(map.players[pom].canHumanPlay || map.players[pom].canComputerPlay)) || (!map.areAnyPLayers))
  76. {
  77. i+=13;
  78. continue;
  79. }
  80. map.players[pom].AITactic = bufor[i++];
  81. if (bufor[i++])
  82. {
  83. map.players[pom].allowedFactions = 0;
  84. map.players[pom].allowedFactions += bufor[i++];
  85. map.players[pom].allowedFactions += (bufor[i++])*256;
  86. }
  87. else
  88. {
  89. map.players[pom].allowedFactions = 511;
  90. i+=2;
  91. }
  92. map.players[pom].isFactionRandom = bufor[i++];
  93. map.players[pom].hasMainTown = bufor[i++];
  94. if (map.players[pom].hasMainTown)
  95. {
  96. map.players[pom].generateHeroAtMainTown = bufor[i++];
  97. i++; //unknown byte
  98. map.players[pom].posOfMainTown.x = bufor[i++];
  99. map.players[pom].posOfMainTown.y = bufor[i++];
  100. map.players[pom].posOfMainTown.z = bufor[i++];
  101. }
  102. i++; //unknown byte
  103. int unknown = bufor[i++];
  104. if (unknown == 255)
  105. {
  106. map.players[pom].mainHeroPortrait = 255;
  107. i+=5;
  108. continue;
  109. }
  110. map.players[pom].mainHeroPortrait = bufor[i++];
  111. int nameLength = bufor[i++];
  112. i+=3;
  113. for (int pp=0;pp<nameLength;pp++)
  114. map.players[pom].mainHeroName+=bufor[i++];
  115. i++; ////unknown byte
  116. int heroCount = bufor[i++];
  117. i+=3;
  118. for (int pp=0;pp<heroCount;pp++)
  119. {
  120. SheroName vv;
  121. vv.heroID=bufor[i++];
  122. int hnl = bufor[i++];
  123. i+=3;
  124. for (int zz=0;zz<hnl;zz++)
  125. {
  126. vv.heroName+=bufor[i++];
  127. }
  128. map.players[pom].heroesNames.push_back(vv);
  129. }
  130. }
  131. map.victoryCondition = (EvictoryConditions)bufor[i++];
  132. if (map.victoryCondition != winStandard) //specific victory conditions
  133. {
  134. int nr;
  135. switch (map.victoryCondition) //read victory conditions
  136. {
  137. case artifact:
  138. {
  139. map.vicConDetails = new VicCon0();
  140. ((VicCon0*)map.vicConDetails)->ArtifactID = bufor[i+2];
  141. nr=2;
  142. break;
  143. }
  144. case gatherTroop:
  145. {
  146. map.vicConDetails = new VicCon1();
  147. int temp1 = bufor[i+2];
  148. int temp2 = bufor[i+3];
  149. ((VicCon1*)map.vicConDetails)->monsterID = bufor[i+2];
  150. ((VicCon1*)map.vicConDetails)->neededQuantity=readNormalNr(i+4);
  151. nr=6;
  152. break;
  153. }
  154. case gatherResource:
  155. {
  156. map.vicConDetails = new VicCon2();
  157. ((VicCon2*)map.vicConDetails)->resourceID = bufor[i+2];
  158. ((VicCon2*)map.vicConDetails)->neededQuantity=readNormalNr(i+3);
  159. nr=5;
  160. break;
  161. }
  162. case buildCity:
  163. {
  164. map.vicConDetails = new VicCon3();
  165. ((VicCon3*)map.vicConDetails)->posOfCity.x = bufor[i+2];
  166. ((VicCon3*)map.vicConDetails)->posOfCity.y = bufor[i+3];
  167. ((VicCon3*)map.vicConDetails)->posOfCity.z = bufor[i+4];
  168. ((VicCon3*)map.vicConDetails)->councilNeededLevel = bufor[i+5];
  169. ((VicCon3*)map.vicConDetails)->fortNeededLevel = bufor[i+6];
  170. nr=5;
  171. break;
  172. }
  173. case buildGrail:
  174. {
  175. map.vicConDetails = new VicCon4();
  176. if (bufor[i+4]>2)
  177. ((VicCon4*)map.vicConDetails)->anyLocation = true;
  178. else
  179. {
  180. ((VicCon4*)map.vicConDetails)->whereBuildGrail.x = bufor[i+2];
  181. ((VicCon4*)map.vicConDetails)->whereBuildGrail.y = bufor[i+3];
  182. ((VicCon4*)map.vicConDetails)->whereBuildGrail.z = bufor[i+4];
  183. }
  184. nr=3;
  185. break;
  186. }
  187. case beatHero:
  188. {
  189. map.vicConDetails = new VicCon5();
  190. ((VicCon5*)map.vicConDetails)->locationOfHero.x = bufor[i+2];
  191. ((VicCon5*)map.vicConDetails)->locationOfHero.y = bufor[i+3];
  192. ((VicCon5*)map.vicConDetails)->locationOfHero.z = bufor[i+4];
  193. nr=3;
  194. break;
  195. }
  196. case captureCity:
  197. {
  198. map.vicConDetails = new VicCon6();
  199. ((VicCon6*)map.vicConDetails)->locationOfTown.x = bufor[i+2];
  200. ((VicCon6*)map.vicConDetails)->locationOfTown.y = bufor[i+3];
  201. ((VicCon6*)map.vicConDetails)->locationOfTown.z = bufor[i+4];
  202. nr=3;
  203. break;
  204. }
  205. case beatMonster:
  206. {
  207. map.vicConDetails = new VicCon7();
  208. ((VicCon7*)map.vicConDetails)->locationOfMonster.x = bufor[i+2];
  209. ((VicCon7*)map.vicConDetails)->locationOfMonster.y = bufor[i+3];
  210. ((VicCon7*)map.vicConDetails)->locationOfMonster.z = bufor[i+4];
  211. nr=3;
  212. break;
  213. }
  214. case takeDwellings:
  215. {
  216. map.vicConDetails = new CspecificVictoryConidtions();
  217. nr=3;
  218. break;
  219. }
  220. case takeMines:
  221. {
  222. map.vicConDetails = new CspecificVictoryConidtions();
  223. nr=3;
  224. break;
  225. }
  226. case transportItem:
  227. {
  228. map.vicConDetails = new VicCona();
  229. ((VicCona*)map.vicConDetails)->artifactID = bufor[i+2];
  230. ((VicCona*)map.vicConDetails)->destinationPlace.x = bufor[i+3];
  231. ((VicCona*)map.vicConDetails)->destinationPlace.y = bufor[i+4];
  232. ((VicCona*)map.vicConDetails)->destinationPlace.z = bufor[i+5];
  233. nr=3;
  234. break;
  235. }
  236. }
  237. map.vicConDetails->allowNormalVictory = bufor[i++];
  238. map.vicConDetails->appliesToAI = bufor[i++];
  239. i+=nr;
  240. }
  241. map.lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
  242. switch (map.lossCondition.typeOfLossCon) //read loss conditions
  243. {
  244. case lossCastle:
  245. {
  246. map.lossCondition.castlePos.x=bufor[i++];
  247. map.lossCondition.castlePos.y=bufor[i++];
  248. map.lossCondition.castlePos.z=bufor[i++];
  249. }
  250. case lossHero:
  251. {
  252. map.lossCondition.heroPos.x=bufor[i++];
  253. map.lossCondition.heroPos.y=bufor[i++];
  254. map.lossCondition.heroPos.z=bufor[i++];
  255. }
  256. case timeExpires:
  257. {
  258. map.lossCondition.timeLimit = readNormalNr(i++,2);
  259. i++;
  260. }
  261. }
  262. map.howManyTeams=bufor[i++]; //read number of teams
  263. if(map.howManyTeams>0) //read team numbers
  264. {
  265. for(int rr=0; rr<8; ++rr)
  266. {
  267. map.players[rr].team=bufor[i++];
  268. }
  269. }
  270. //reading allowed heroes (20 bytes)
  271. int ist=i; //starting i for loop
  272. for(i; i<ist+20; ++i)
  273. {
  274. unsigned char c = bufor[i];
  275. for(int yy=0; yy<8; ++yy)
  276. {
  277. if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size())
  278. {
  279. if(c == (c|((unsigned char)intPow(2, yy))))
  280. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = true;
  281. else
  282. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = false;
  283. }
  284. }
  285. }
  286. //allowed heroes have been read
  287. i+=36;
  288. //reading allowed artifacts //18 bytes
  289. ist=i; //starting i for loop
  290. for(i; i<ist+18; ++i)
  291. {
  292. unsigned char c = bufor[i];
  293. for(int yy=0; yy<8; ++yy)
  294. {
  295. if((i-ist)*8+yy < CGameInfo::mainObj->arth->artifacts.size())
  296. {
  297. if(c != (c|((unsigned char)intPow(2, yy))))
  298. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true;
  299. else
  300. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false;
  301. }
  302. }
  303. }
  304. //allowed artifacts have been read
  305. //reading allowed spells (9 bytes)
  306. ist=i; //starting i for loop
  307. for(i; i<ist+9; ++i)
  308. {
  309. unsigned char c = bufor[i];
  310. for(int yy=0; yy<8; ++yy)
  311. {
  312. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  313. {
  314. if(c != (c|((unsigned char)intPow(2, yy))))
  315. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true;
  316. else
  317. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false;
  318. }
  319. }
  320. }
  321. //allowed spells have been read
  322. //allowed hero's abilities (4 bytes)
  323. ist=i; //starting i for loop
  324. for(i; i<ist+4; ++i)
  325. {
  326. unsigned char c = bufor[i];
  327. for(int yy=0; yy<8; ++yy)
  328. {
  329. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  330. {
  331. if(c != (c|((unsigned char)intPow(2, yy))))
  332. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = true;
  333. else
  334. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = false;
  335. }
  336. }
  337. }
  338. //allowed hero's abilities have been read
  339. THC std::cout<<"Wczytywanie naglowka: "<<th.getDif()<<std::endl;
  340. int rumNr = readNormalNr(i,4);i+=4;
  341. for (int it=0;it<rumNr;it++)
  342. {
  343. Rumor ourRumor;
  344. int nameL = readNormalNr(i,4);i+=4; //read length of name of rumor
  345. for (int zz=0; zz<nameL; zz++)
  346. ourRumor.name+=bufor[i++];
  347. nameL = readNormalNr(i,4);i+=4; //read length of rumor
  348. for (int zz=0; zz<nameL; zz++)
  349. ourRumor.text+=bufor[i++];
  350. map.rumors.push_back(ourRumor); //add to our list
  351. }
  352. THC std::cout<<"Wczytywanie plotek: "<<th.getDif()<<std::endl;
  353. i+=156;
  354. for (int c=0; c<map.width; c++) // reading terrain
  355. {
  356. for (int z=0; z<map.height; z++)
  357. {
  358. map.terrain[z][c].tertype = (EterrainType)(bufor[i++]);
  359. map.terrain[z][c].terview = bufor[i++];
  360. map.terrain[z][c].nuine = (Eriver)bufor[i++];
  361. map.terrain[z][c].rivDir = bufor[i++];
  362. map.terrain[z][c].malle = (Eroad)bufor[i++];
  363. map.terrain[z][c].roadDir = bufor[i++];
  364. map.terrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  365. }
  366. }
  367. if (map.twoLevel) // read underground terrain
  368. {
  369. for (int c=0; c<map.width; c++) // reading terrain
  370. {
  371. for (int z=0; z<map.height; z++)
  372. {
  373. map.undergroungTerrain[z][c].tertype = (EterrainType)(bufor[i++]);
  374. map.undergroungTerrain[z][c].terview = bufor[i++];
  375. map.undergroungTerrain[z][c].nuine = (Eriver)bufor[i++];
  376. map.undergroungTerrain[z][c].rivDir = bufor[i++];
  377. map.undergroungTerrain[z][c].malle = (Eroad)bufor[i++];
  378. map.undergroungTerrain[z][c].roadDir = bufor[i++];
  379. map.undergroungTerrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  380. }
  381. }
  382. }
  383. THC std::cout<<"Wczytywanie terenu: "<<th.getDif()<<std::endl;
  384. int defAmount = bufor[i]; // liczba defow
  385. defAmount = readNormalNr(i);
  386. i+=4;
  387. for (int idd = 0 ; idd<defAmount; idd++) // reading defs
  388. {
  389. int nameLength = readNormalNr(i,4);i+=4;
  390. DefInfo vinya; // info about new def
  391. for (int cd=0;cd<nameLength;cd++)
  392. {
  393. vinya.name += bufor[i++];
  394. }
  395. for (int v=0; v<42; v++) // read info
  396. {
  397. vinya.bytes[v] = bufor[i++];
  398. }
  399. map.defy.push_back(vinya); // add this def to the vector
  400. //teceDef();
  401. }
  402. THC std::cout<<"Wczytywanie defow: "<<th.getDif()<<std::endl;
  403. ////loading objects
  404. int howManyObjs = readNormalNr(i, 4); i+=4;
  405. /*for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
  406. {
  407. CObjectInstance nobj; //we will read this object
  408. nobj.id = CGameInfo::mainObj->objh->objInstances.size();
  409. nobj.x = bufor[i++];
  410. nobj.y = bufor[i++];
  411. nobj.z = bufor[i++];
  412. nobj.defNumber = readNormalNr(i, 4); i+=4;
  413. i+=5;
  414. switch(getDefType(map.defy[nobj.defNumber]))
  415. {
  416. case EDefType::EVENTOBJ_DEF: //for event - objects
  417. {
  418. CEventObjInfo * spec = new CEventObjInfo;
  419. bool guardMess;
  420. guardMess = bufor[i]; ++i;
  421. if(guardMess)
  422. {
  423. int messLong = readNormalNr(i, 4); i+=4;
  424. if(messLong>0)
  425. {
  426. spec->isMessage = true;
  427. for(int yy=0; yy<messLong; ++yy)
  428. {
  429. spec->message +=bufor[i+yy];
  430. }
  431. i+=messLong;
  432. }
  433. spec->areGuarders = bufor[i]; ++i;
  434. if(spec->areGuarders)
  435. {
  436. spec->guarders = readCreatureSet(i); i+=32;
  437. }
  438. }
  439. else
  440. {
  441. spec->isMessage = false;
  442. spec->areGuarders = false;
  443. spec->message = std::string("");
  444. }
  445. spec->gainedExp = readNormalNr(i, 4); i+=4;
  446. spec->manaDiff = readNormalNr(i, 4); i+=4;
  447. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  448. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  449. spec->wood = readNormalNr(i); i+=4;
  450. spec->mercury = readNormalNr(i); i+=4;
  451. spec->ore = readNormalNr(i); i+=4;
  452. spec->sulfur = readNormalNr(i); i+=4;
  453. spec->crystal = readNormalNr(i); i+=4;
  454. spec->gems = readNormalNr(i); i+=4;
  455. spec->gold = readNormalNr(i); i+=4;
  456. spec->attack = readNormalNr(i, 1); ++i;
  457. spec->defence = readNormalNr(i, 1); ++i;
  458. spec->power = readNormalNr(i, 1); ++i;
  459. spec->knowledge = readNormalNr(i, 1); ++i;
  460. int gabn; //number of gained abilities
  461. gabn = readNormalNr(i, 1); ++i;
  462. for(int oo = 0; oo<gabn; ++oo)
  463. {
  464. spec->abilities.push_back(&((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)])); ++i;
  465. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  466. }
  467. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  468. for(int oo = 0; oo<gart; ++oo)
  469. {
  470. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  471. }
  472. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  473. for(int oo = 0; oo<gspel; ++oo)
  474. {
  475. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  476. }
  477. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  478. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  479. i+=8;
  480. spec->availableFor = readNormalNr(i, 1); ++i;
  481. spec->computerActivate = readNormalNr(i, 1); ++i;
  482. spec->humanActivate = readNormalNr(i, 1); ++i;
  483. i+=4;
  484. nobj.info = spec;
  485. break;
  486. }
  487. case EDefType::HERO_DEF:
  488. {
  489. CHeroObjInfo * spec = new CHeroObjInfo;
  490. spec->bytes[0] = bufor[i]; ++i;
  491. spec->bytes[1] = bufor[i]; ++i;
  492. spec->bytes[2] = bufor[i]; ++i;
  493. spec->bytes[3] = bufor[i]; ++i;
  494. spec->player = bufor[i]; ++i;
  495. spec->type = &(CGameInfo::mainObj->heroh->heroes[readNormalNr(i, 1)]); ++i;
  496. bool isName = bufor[i]; ++i; //true if hero has nonstandard name
  497. if(isName)
  498. {
  499. int length = readNormalNr(i, 4); i+=4;
  500. for(int gg=0; gg<length; ++gg)
  501. {
  502. spec->name+=bufor[i]; ++i;
  503. }
  504. }
  505. else
  506. spec->name = std::string("");
  507. bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0
  508. if(isExp)
  509. {
  510. spec->experience = readNormalNr(i); i+=4;
  511. }
  512. else spec->experience = 0;
  513. ++i; //TODO - czy tu na pewno nie ma istotnej informacji?
  514. bool nonstandardAbilities = bufor[i]; ++i; //true if hero has specified abilities
  515. if(nonstandardAbilities)
  516. {
  517. int howMany = readNormalNr(i); i+=4;
  518. for(int yy=0; yy<howMany; ++yy)
  519. {
  520. spec->abilities.push_back(&(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)])); ++i;
  521. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  522. }
  523. }
  524. bool standGarrison = bufor[i]; ++i; //true if hero has nonstandard garrison
  525. spec->standardGarrison = standGarrison;
  526. if(standGarrison)
  527. {
  528. spec->garrison = readCreatureSet(i); i+=7;
  529. }
  530. bool form = bufor[i]; ++i; //formation
  531. spec->garrison.formation = form;
  532. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  533. if(artSet)
  534. {
  535. //head art //1
  536. int id = readNormalNr(i, 2); i+=2;
  537. if(id!=0xffff)
  538. spec->artHead = &(CGameInfo::mainObj->arth->artifacts[id]);
  539. else
  540. spec->artHead = NULL;
  541. //shoulders art //2
  542. id = readNormalNr(i, 2); i+=2;
  543. if(id!=0xffff)
  544. spec->artShoulders = &(CGameInfo::mainObj->arth->artifacts[id]);
  545. else
  546. spec->artShoulders = NULL;
  547. //neck art //3
  548. id = readNormalNr(i, 2); i+=2;
  549. if(id!=0xffff)
  550. spec->artNeck = &(CGameInfo::mainObj->arth->artifacts[id]);
  551. else
  552. spec->artNeck = NULL;
  553. //right hand art //4
  554. id = readNormalNr(i, 2); i+=2;
  555. if(id!=0xffff)
  556. spec->artRhand = &(CGameInfo::mainObj->arth->artifacts[id]);
  557. else
  558. spec->artRhand = NULL;
  559. //left hand art //5
  560. id = readNormalNr(i, 2); i+=2;
  561. if(id!=0xffff)
  562. spec->artLHand = &(CGameInfo::mainObj->arth->artifacts[id]);
  563. else
  564. spec->artLHand = NULL;
  565. //torso art //6
  566. id = readNormalNr(i, 2); i+=2;
  567. if(id!=0xffff)
  568. spec->artTorso = &(CGameInfo::mainObj->arth->artifacts[id]);
  569. else
  570. spec->artTorso = NULL;
  571. //right hand ring //7
  572. id = readNormalNr(i, 2); i+=2;
  573. if(id!=0xffff)
  574. spec->artRRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  575. else
  576. spec->artRRing = NULL;
  577. //left hand ring //8
  578. id = readNormalNr(i, 2); i+=2;
  579. if(id!=0xffff)
  580. spec->artLRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  581. else
  582. spec->artLRing = NULL;
  583. //feet art //9
  584. id = readNormalNr(i, 2); i+=2;
  585. if(id!=0xffff)
  586. spec->artFeet = &(CGameInfo::mainObj->arth->artifacts[id]);
  587. else
  588. spec->artFeet = NULL;
  589. //misc1 art //10
  590. id = readNormalNr(i, 2); i+=2;
  591. if(id!=0xffff)
  592. spec->artMisc1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  593. else
  594. spec->artMisc1 = NULL;
  595. //misc2 art //11
  596. id = readNormalNr(i, 2); i+=2;
  597. if(id!=0xffff)
  598. spec->artMisc2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  599. else
  600. spec->artMisc2 = NULL;
  601. //misc3 art //12
  602. id = readNormalNr(i, 2); i+=2;
  603. if(id!=0xffff)
  604. spec->artMisc3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  605. else
  606. spec->artMisc3 = NULL;
  607. //misc4 art //13
  608. id = readNormalNr(i, 2); i+=2;
  609. if(id!=0xffff)
  610. spec->artMisc4 = &(CGameInfo::mainObj->arth->artifacts[id]);
  611. else
  612. spec->artMisc4 = NULL;
  613. //machine1 art //14
  614. id = readNormalNr(i, 2); i+=2;
  615. if(id!=0xffff)
  616. spec->artMach1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  617. else
  618. spec->artMach1 = NULL;
  619. //machine2 art //15
  620. id = readNormalNr(i, 2); i+=2;
  621. if(id!=0xffff)
  622. spec->artMach2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  623. else
  624. spec->artMach2 = NULL;
  625. //machine3 art //16
  626. id = readNormalNr(i, 2); i+=2;
  627. if(id!=0xffff)
  628. spec->artMach3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  629. else
  630. spec->artMach3 = NULL;
  631. //misc5 art //17
  632. id = readNormalNr(i, 2); i+=2;
  633. if(id!=0xffff)
  634. spec->artMisc5 = &(CGameInfo::mainObj->arth->artifacts[id]);
  635. else
  636. spec->artMisc5 = NULL;
  637. //spellbook
  638. id = readNormalNr(i, 2); i+=2;
  639. if(id!=0xffff)
  640. spec->artSpellBook = &(CGameInfo::mainObj->arth->artifacts[id]);
  641. else
  642. spec->artSpellBook = NULL;
  643. //19 //???what is that? gap in file or what?
  644. i+=2;
  645. //bag artifacts //20
  646. int amount = readNormalNr(i, 2); i+=2; //number of artifacts in hero's bag
  647. if(amount>0)
  648. {
  649. for(int ss=0; ss<amount; ++ss)
  650. {
  651. id = readNormalNr(i, 2); i+=2;
  652. if(id!=0xffff)
  653. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[id]));
  654. else
  655. spec->artifacts.push_back(NULL);
  656. }
  657. }
  658. } //artifacts
  659. spec->guardRange = readNormalNr(i, 1); ++i;
  660. if(spec->guardRange == 0xff)
  661. spec->isGuarding = false;
  662. else
  663. spec->isGuarding = true;
  664. bool hasBiography = bufor[i]; ++i; //true if hero has nonstandard (mapmaker defined) biography
  665. if(hasBiography)
  666. {
  667. int length = readNormalNr(i); i+=4;
  668. int iStart = i;
  669. i+=length;
  670. for(int bb=0; bb<length; ++bb)
  671. {
  672. spec->biography+=bufor[iStart+bb];
  673. }
  674. }
  675. spec->sex = !(bufor[i]); ++i;
  676. //spells
  677. bool areSpells = bufor[i]; ++i;
  678. if(areSpells) //TODO: sprawdziæ
  679. {
  680. int ist = i;
  681. for(i; i<ist+9; ++i)
  682. {
  683. unsigned char c = bufor[i];
  684. for(int yy=0; yy<8; ++yy)
  685. {
  686. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  687. {
  688. if(c == (c|((unsigned char)intPow(2, yy))))
  689. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  690. }
  691. }
  692. }
  693. }
  694. //spells loaded
  695. spec->defaultMianStats = bufor[i]; ++i;
  696. if(spec->defaultMianStats)
  697. {
  698. spec->attack = bufor[i]; ++i;
  699. spec->defence = bufor[i]; ++i;
  700. spec->power = bufor[i]; ++i;
  701. spec->knowledge = bufor[i]; ++i;
  702. }
  703. i+=16;
  704. nobj.info = spec;
  705. break;
  706. }
  707. case CREATURES_DEF:
  708. {
  709. CCreatureObjInfo * spec = new CCreatureObjInfo;
  710. spec->bytes[0] = bufor[i]; ++i;
  711. spec->bytes[1] = bufor[i]; ++i;
  712. spec->bytes[2] = bufor[i]; ++i;
  713. spec->bytes[3] = bufor[i]; ++i;
  714. spec->number = readNormalNr(i, 2); i+=2;
  715. spec->character = bufor[i]; ++i;
  716. bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
  717. if(isMesTre)
  718. {
  719. int messLength = readNormalNr(i); i+=4;
  720. if(messLength>0)
  721. {
  722. for(int tt=0; tt<messLength; ++tt)
  723. {
  724. spec->message += bufor[i]; ++i;
  725. }
  726. }
  727. spec->wood = readNormalNr(i); i+=4;
  728. spec->mercury = readNormalNr(i); i+=4;
  729. spec->ore = readNormalNr(i); i+=4;
  730. spec->sulfur = readNormalNr(i); i+=4;
  731. spec->crytal = readNormalNr(i); i+=4;
  732. spec->gems = readNormalNr(i); i+=4;
  733. spec->gold = readNormalNr(i); i+=4;
  734. int artID = readNormalNr(i, 2); i+=2;
  735. if(artID!=0xffff)
  736. spec->gainedArtifact = &(CGameInfo::mainObj->arth->artifacts[artID]);
  737. else
  738. spec->gainedArtifact = NULL;
  739. }
  740. spec->neverFlees = bufor[i]; ++i;
  741. spec->notGrowingTeam = bufor[i]; ++i;
  742. i+=2;
  743. nobj.info = spec;
  744. break;
  745. }
  746. case EDefType::SIGN_DEF:
  747. {
  748. CSignObjInfo * spec = new CSignObjInfo;
  749. int length = readNormalNr(i); i+=4;
  750. for(int rr=0; rr<length; ++rr)
  751. {
  752. spec->message += bufor[i]; ++i;
  753. }
  754. i+=4;
  755. nobj.info = spec;
  756. break;
  757. }
  758. case EDefType::SEERHUT_DEF:
  759. {
  760. CSeerHutObjInfo * spec = new CSeerHutObjInfo;
  761. spec->missionType = bufor[i]; ++i;
  762. switch(spec->missionType)
  763. {
  764. case 1:
  765. {
  766. spec->m1level = readNormalNr(i); i+=4;
  767. int limit = readNormalNr(i); i+=4;
  768. if(limit == ((int)0xffffffff))
  769. {
  770. spec->isDayLimit = false;
  771. spec->lastDay = -1;
  772. }
  773. else
  774. {
  775. spec->isDayLimit = true;
  776. spec->lastDay = limit;
  777. }
  778. break;
  779. }
  780. case 2:
  781. {
  782. spec->m2attack = bufor[i]; ++i;
  783. spec->m2defence = bufor[i]; ++i;
  784. spec->m2power = bufor[i]; ++i;
  785. spec->m2knowledge = bufor[i]; ++i;
  786. int limit = readNormalNr(i); i+=4;
  787. if(limit == ((int)0xffffffff))
  788. {
  789. spec->isDayLimit = false;
  790. spec->lastDay = -1;
  791. }
  792. else
  793. {
  794. spec->isDayLimit = true;
  795. spec->lastDay = limit;
  796. }
  797. break;
  798. }
  799. case 3:
  800. {
  801. spec->m3bytes[0] = bufor[i]; ++i;
  802. spec->m3bytes[1] = bufor[i]; ++i;
  803. spec->m3bytes[2] = bufor[i]; ++i;
  804. spec->m3bytes[3] = bufor[i]; ++i;
  805. int limit = readNormalNr(i); i+=4;
  806. if(limit == ((int)0xffffffff))
  807. {
  808. spec->isDayLimit = false;
  809. spec->lastDay = -1;
  810. }
  811. else
  812. {
  813. spec->isDayLimit = true;
  814. spec->lastDay = limit;
  815. }
  816. break;
  817. }
  818. case 4:
  819. {
  820. spec->m4bytes[0] = bufor[i]; ++i;
  821. spec->m4bytes[1] = bufor[i]; ++i;
  822. spec->m4bytes[2] = bufor[i]; ++i;
  823. spec->m4bytes[3] = bufor[i]; ++i;
  824. int limit = readNormalNr(i); i+=4;
  825. if(limit == ((int)0xffffffff))
  826. {
  827. spec->isDayLimit = false;
  828. spec->lastDay = -1;
  829. }
  830. else
  831. {
  832. spec->isDayLimit = true;
  833. spec->lastDay = limit;
  834. }
  835. break;
  836. }
  837. case 5:
  838. {
  839. int artNumber = bufor[i]; ++i;
  840. for(int yy=0; yy<artNumber; ++yy)
  841. {
  842. int artid = readNormalNr(i, 2); i+=2;
  843. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  844. }
  845. int limit = readNormalNr(i); i+=4;
  846. if(limit == ((int)0xffffffff))
  847. {
  848. spec->isDayLimit = false;
  849. spec->lastDay = -1;
  850. }
  851. else
  852. {
  853. spec->isDayLimit = true;
  854. spec->lastDay = limit;
  855. }
  856. break;
  857. }
  858. case 6:
  859. {
  860. int typeNumber = bufor[i]; ++i;
  861. for(int hh=0; hh<typeNumber; ++hh)
  862. {
  863. int creType = readNormalNr(i, 2); i+=2;
  864. int creNumb = readNormalNr(i, 2); i+=2;
  865. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  866. spec->m6number.push_back(creNumb);
  867. }
  868. int limit = readNormalNr(i); i+=4;
  869. if(limit == ((int)0xffffffff))
  870. {
  871. spec->isDayLimit = false;
  872. spec->lastDay = -1;
  873. }
  874. else
  875. {
  876. spec->isDayLimit = true;
  877. spec->lastDay = limit;
  878. }
  879. break;
  880. }
  881. case 7:
  882. {
  883. spec->m7wood = readNormalNr(i); i+=4;
  884. spec->m7mercury = readNormalNr(i); i+=4;
  885. spec->m7ore = readNormalNr(i); i+=4;
  886. spec->m7sulfur = readNormalNr(i); i+=4;
  887. spec->m7crystal = readNormalNr(i); i+=4;
  888. spec->m7gems = readNormalNr(i); i+=4;
  889. spec->m7gold = readNormalNr(i); i+=4;
  890. int limit = readNormalNr(i); i+=4;
  891. if(limit == ((int)0xffffffff))
  892. {
  893. spec->isDayLimit = false;
  894. spec->lastDay = -1;
  895. }
  896. else
  897. {
  898. spec->isDayLimit = true;
  899. spec->lastDay = limit;
  900. }
  901. break;
  902. }
  903. case 8:
  904. {
  905. int heroType = bufor[i]; ++i;
  906. spec->m8hero = &(CGameInfo::mainObj->heroh->heroes[heroType]);
  907. int limit = readNormalNr(i); i+=4;
  908. if(limit == ((int)0xffffffff))
  909. {
  910. spec->isDayLimit = false;
  911. spec->lastDay = -1;
  912. }
  913. else
  914. {
  915. spec->isDayLimit = true;
  916. spec->lastDay = limit;
  917. }
  918. break;
  919. }
  920. case 9:
  921. {
  922. spec->m9player = bufor[i]; ++i;
  923. int limit = readNormalNr(i); i+=4;
  924. if(limit == ((int)0xffffffff))
  925. {
  926. spec->isDayLimit = false;
  927. spec->lastDay = -1;
  928. }
  929. else
  930. {
  931. spec->isDayLimit = true;
  932. spec->lastDay = limit;
  933. }
  934. break;
  935. }
  936. }//internal switch end (seer huts)
  937. int len1 = readNormalNr(i); i+=4;
  938. for(int ee=0; ee<len1; ++ee)
  939. {
  940. spec->firstVisitText += bufor[i]; ++i;
  941. }
  942. int len2 = readNormalNr(i); i+=4;
  943. for(int ee=0; ee<len2; ++ee)
  944. {
  945. spec->nextVisitText += bufor[i]; ++i;
  946. }
  947. int len3 = readNormalNr(i); i+=4;
  948. for(int ee=0; ee<len3; ++ee)
  949. {
  950. spec->completedText += bufor[i]; ++i;
  951. }
  952. unsigned char rewardType = bufor[i]; ++i;
  953. spec->rewardType = rewardType;
  954. switch(rewardType)
  955. {
  956. case 1:
  957. {
  958. spec->r1exp = readNormalNr(i); i+=4;
  959. break;
  960. }
  961. case 2:
  962. {
  963. spec->r2mana = readNormalNr(i); i+=4;
  964. break;
  965. }
  966. case 3:
  967. {
  968. spec->r3morale = bufor[i]; ++i;
  969. break;
  970. }
  971. case 4:
  972. {
  973. spec->r4luck = bufor[i]; ++i;
  974. break;
  975. }
  976. case 5:
  977. {
  978. spec->r5type = bufor[i]; ++i;
  979. spec->r5amount = readNormalNr(i, 3); i+=3;
  980. break;
  981. }
  982. case 6:
  983. {
  984. spec->r6type = bufor[i]; ++i;
  985. spec->r6amount = bufor[i]; ++i;
  986. break;
  987. }
  988. case 7:
  989. {
  990. int abid = bufor[i]; ++i;
  991. spec->r7ability = &(CGameInfo::mainObj->abilh->abilities[abid]);
  992. spec->r7level = bufor[i]; ++i;
  993. break;
  994. }
  995. case 8:
  996. {
  997. int artid = readNormalNr(i, 2); i+=2;
  998. spec->r8art = &(CGameInfo::mainObj->arth->artifacts[artid]);
  999. break;
  1000. }
  1001. case 9:
  1002. {
  1003. int spellid = bufor[i]; ++i;
  1004. spec->r9spell = &(CGameInfo::mainObj->spellh->spells[spellid]);
  1005. break;
  1006. }
  1007. case 10:
  1008. {
  1009. int creid = readNormalNr(i, 2); i+=2;
  1010. spec->r10creature = &(CGameInfo::mainObj->creh->creatures[creid]);
  1011. spec->r10amount = readNormalNr(i, 2); i+=2;
  1012. break;
  1013. }
  1014. }// end of internal switch
  1015. i+=2;
  1016. nobj.info = spec;
  1017. break;
  1018. }
  1019. case EDefType::WITCHHUT_DEF:
  1020. {
  1021. CWitchHutObjInfo * spec = new CWitchHutObjInfo;
  1022. ist=i; //starting i for loop
  1023. for(i; i<ist+4; ++i)
  1024. {
  1025. unsigned char c = bufor[i];
  1026. for(int yy=0; yy<8; ++yy)
  1027. {
  1028. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  1029. {
  1030. if(c == (c|((unsigned char)intPow(2, yy))))
  1031. spec->allowedAbilities.push_back(&(CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]));
  1032. }
  1033. }
  1034. }
  1035. nobj.info = spec;
  1036. break;
  1037. }
  1038. case EDefType::SCHOLAR_DEF:
  1039. {
  1040. CScholarObjInfo * spec = new CScholarObjInfo;
  1041. spec->bonusType = bufor[i]; ++i;
  1042. switch(spec->bonusType)
  1043. {
  1044. case 0xff:
  1045. ++i;
  1046. break;
  1047. case 0:
  1048. spec->r0type = bufor[i]; ++i;
  1049. break;
  1050. case 1:
  1051. spec->r1 = &(CGameInfo::mainObj->abilh->abilities[bufor[i]]); ++i;
  1052. break;
  1053. case 2:
  1054. spec->r2 = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1055. break;
  1056. }
  1057. i+=6;
  1058. nobj.info = spec;
  1059. break;
  1060. }
  1061. case EDefType::GARRISON_DEF:
  1062. {
  1063. CGarrisonObjInfo * spec = new CGarrisonObjInfo;
  1064. spec->player = bufor[i]; ++i;
  1065. i+=3;
  1066. spec->units = readCreatureSet(i); i+=28;
  1067. spec->movableUnits = bufor[i]; ++i;
  1068. i+=8;
  1069. nobj.info = spec;
  1070. break;
  1071. }
  1072. case EDefType::ARTIFACT_DEF:
  1073. {
  1074. CArtifactObjInfo * spec = new CArtifactObjInfo;
  1075. bool areSettings = bufor[i]; ++i;
  1076. if(areSettings)
  1077. {
  1078. int messLength = readNormalNr(i, 4); i+=4;
  1079. for(int hh=0; hh<messLength; ++hh)
  1080. {
  1081. spec->message += bufor[i]; ++i;
  1082. }
  1083. bool areGuards = bufor[i]; ++i;
  1084. if(areGuards)
  1085. {
  1086. spec->areGuards = true;
  1087. spec->guards = readCreatureSet(i);
  1088. }
  1089. else
  1090. spec->areGuards = false;
  1091. }
  1092. nobj.info = spec;
  1093. break;
  1094. }
  1095. case EDefType::RESOURCE_DEF:
  1096. {
  1097. CResourceObjInfo * spec = new CResourceObjInfo;
  1098. bool isMessGuard = bufor[i]; ++i;
  1099. if(isMessGuard)
  1100. {
  1101. int messLength = readNormalNr(i); i+=4;
  1102. for(int mm=0; mm<messLength; ++mm)
  1103. {
  1104. spec->message+=bufor[i]; ++i;
  1105. }
  1106. spec->areGuards = bufor[i]; ++i;
  1107. if(spec->areGuards)
  1108. {
  1109. spec->guards = readCreatureSet(i); i+=28;
  1110. }
  1111. i+=4;
  1112. }
  1113. else
  1114. {
  1115. spec->areGuards = false;
  1116. }
  1117. spec->amount = readNormalNr(i); i+=4;
  1118. i+=4;
  1119. nobj.info = spec;
  1120. break;
  1121. }
  1122. case EDefType::TOWN_DEF:
  1123. {
  1124. CCastleObjInfo * spec = new CCastleObjInfo;
  1125. spec->bytes[0] = bufor[i]; ++i;
  1126. spec->bytes[1] = bufor[i]; ++i;
  1127. spec->bytes[2] = bufor[i]; ++i;
  1128. spec->bytes[3] = bufor[i]; ++i;
  1129. spec->player = bufor[i]; ++i;
  1130. bool hasName = bufor[i]; ++i;
  1131. if(hasName)
  1132. {
  1133. int len = readNormalNr(i); i+=4;
  1134. for(iny gg=0; gg<len; ++gg)
  1135. {
  1136. spec->name += bufor[i]; ++i;
  1137. }
  1138. }
  1139. bool stGarr = bufor[i]; ++i; //true if garrison isn't empty
  1140. if(stGarr)
  1141. {
  1142. spec->garrison = readCreatureSet(i); i+=28;
  1143. }
  1144. spec->garrison.formation = bufor[i]; ++i;
  1145. break;
  1146. }
  1147. } //end of main switch
  1148. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  1149. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  1150. }//*/ //end of loading objects; commented to make application work until it will be finished
  1151. ////objects loaded
  1152. //todo: read events
  1153. }
  1154. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  1155. {
  1156. int ret=0;
  1157. int amp=1;
  1158. for (int i=0; i<bytCon; i++)
  1159. {
  1160. ret+=bufor[pos+i]*amp;
  1161. amp*=256;
  1162. }
  1163. if(cyclic && bytCon<4 && ret>=amp/2)
  1164. {
  1165. ret = ret-amp;
  1166. }
  1167. return ret;
  1168. }
  1169. void CAmbarCendamo::loadDefs()
  1170. {
  1171. std::set<int> loadedTypes;
  1172. for (int i=0; i<map.width; i++)
  1173. {
  1174. for (int j=0; j<map.width; j++)
  1175. {
  1176. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  1177. {
  1178. CSemiDefHandler *sdh = new CSemiDefHandler();
  1179. sdh->openDef((sdh->nameFromType(map.terrain[i][j].tertype)).c_str(),"H3sprite.lod");
  1180. loadedTypes.insert(map.terrain[i][j].tertype);
  1181. defs.push_back(sdh);
  1182. }
  1183. if (loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  1184. {
  1185. CSemiDefHandler *sdh = new CSemiDefHandler();
  1186. sdh->openDef((sdh->nameFromType(map.undergroungTerrain[i][j].tertype)).c_str(),"H3sprite.lod");
  1187. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  1188. defs.push_back(sdh);
  1189. }
  1190. }
  1191. }
  1192. }
  1193. EDefType CAmbarCendamo::getDefType(DefInfo &a)
  1194. {
  1195. switch(a.bytes[16])
  1196. {
  1197. case 5:
  1198. return EDefType::ARTIFACT_DEF; //handled
  1199. case 26:
  1200. return EDefType::EVENTOBJ_DEF; //handled
  1201. case 33:
  1202. return EDefType::GARRISON_DEF; //handled
  1203. case 34:
  1204. return EDefType::HERO_DEF; //handled
  1205. case 54:
  1206. return EDefType::CREATURES_DEF; //handled
  1207. case 59:
  1208. return EDefType::SIGN_DEF; //handled
  1209. case 79:
  1210. return EDefType::RESOURCE_DEF; //handled
  1211. case 81:
  1212. return EDefType::SCHOLAR_DEF; //handled
  1213. case 83:
  1214. return EDefType::SEERHUT_DEF; //handled
  1215. case 91:
  1216. return EDefType::SIGN_DEF; //handled
  1217. case 98:
  1218. return EDefType::TOWN_DEF;
  1219. case 113:
  1220. return EDefType::WITCHHUT_DEF; //handled
  1221. case 219:
  1222. return EDefType::GARRISON_DEF; //handled
  1223. default:
  1224. return EDefType::TERRAINOBJ_DEF;
  1225. }
  1226. }
  1227. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  1228. {
  1229. CCreatureSet ret;
  1230. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  1231. {
  1232. ret.slot1 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos, 2)]);
  1233. ret.s1 = readNormalNr(pos+2, 2);
  1234. }
  1235. else
  1236. {
  1237. ret.slot1 = NULL;
  1238. ret.s1 = 0;
  1239. }
  1240. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  1241. {
  1242. ret.slot2 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+4, 2)]);
  1243. ret.s2 = readNormalNr(pos+6, 2);
  1244. }
  1245. else
  1246. {
  1247. ret.slot2 = NULL;
  1248. ret.s2 = 0;
  1249. }
  1250. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  1251. {
  1252. ret.slot3 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+8, 2)]);
  1253. ret.s3 = readNormalNr(pos+10, 2);
  1254. }
  1255. else
  1256. {
  1257. ret.slot3 = NULL;
  1258. ret.s3 = 0;
  1259. }
  1260. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  1261. {
  1262. ret.slot4 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+12, 2)]);
  1263. ret.s4 = readNormalNr(pos+14, 2);
  1264. }
  1265. else
  1266. {
  1267. ret.slot4 = NULL;
  1268. ret.s4 = 0;
  1269. }
  1270. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  1271. {
  1272. ret.slot5 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+16, 2)]);
  1273. ret.s5 = readNormalNr(pos+18, 2);
  1274. }
  1275. else
  1276. {
  1277. ret.slot5 = NULL;
  1278. ret.s5 = 0;
  1279. }
  1280. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  1281. {
  1282. ret.slot6 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+20, 2)]);
  1283. ret.s6 = readNormalNr(pos+22, 2);
  1284. }
  1285. else
  1286. {
  1287. ret.slot6 = NULL;
  1288. ret.s6 = 0;
  1289. }
  1290. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  1291. {
  1292. ret.slot7 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+24, 2)]);
  1293. ret.s7 = readNormalNr(pos+26, 2);
  1294. }
  1295. else
  1296. {
  1297. ret.slot7 = NULL;
  1298. ret.s7 = 0;
  1299. }
  1300. return ret;
  1301. }