CAmbarCendamo.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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
  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. }
  638. break;
  639. }
  640. }
  641. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  642. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  643. }//*/ //end of loading objects; commented to making application work until it will be finished
  644. ////objects loaded
  645. //todo: read events
  646. }
  647. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  648. {
  649. int ret=0;
  650. int amp=1;
  651. for (int i=0; i<bytCon; i++)
  652. {
  653. ret+=bufor[pos+i]*amp;
  654. amp*=256;
  655. }
  656. if(cyclic && bytCon<4 && ret>=amp/2)
  657. {
  658. ret = ret-amp;
  659. }
  660. return ret;
  661. }
  662. void CAmbarCendamo::loadDefs()
  663. {
  664. std::set<int> loadedTypes;
  665. for (int i=0; i<map.width; i++)
  666. {
  667. for (int j=0; j<map.width; j++)
  668. {
  669. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  670. {
  671. CSemiDefHandler *sdh = new CSemiDefHandler();
  672. sdh->openDef((sdh->nameFromType(map.terrain[i][j].tertype)).c_str(),"H3sprite.lod");
  673. loadedTypes.insert(map.terrain[i][j].tertype);
  674. defs.push_back(sdh);
  675. }
  676. if (loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  677. {
  678. CSemiDefHandler *sdh = new CSemiDefHandler();
  679. sdh->openDef((sdh->nameFromType(map.undergroungTerrain[i][j].tertype)).c_str(),"H3sprite.lod");
  680. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  681. defs.push_back(sdh);
  682. }
  683. }
  684. }
  685. }
  686. EDefType CAmbarCendamo::getDefType(DefInfo &a)
  687. {
  688. switch(a.bytes[16])
  689. {
  690. case 26:
  691. return EDefType::EVENTOBJ_DEF;
  692. case 33:
  693. return EDefType::GARRISON_DEF;
  694. case 34:
  695. return EDefType::HERO_DEF;
  696. case 79:
  697. return EDefType::RESOURCE_DEF;
  698. case 83:
  699. return EDefType::SEERHUT_DEF;
  700. case 91:
  701. return EDefType::SIGN_DEF;
  702. case 98:
  703. return EDefType::TOWN_DEF;
  704. case 219:
  705. return EDefType::GARRISON_DEF;
  706. default:
  707. return EDefType::TERRAINOBJ_DEF;
  708. }
  709. }
  710. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  711. {
  712. CCreatureSet ret;
  713. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  714. {
  715. ret.slot1 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos, 2)]);
  716. ret.s1 = readNormalNr(pos+2, 2);
  717. }
  718. else
  719. {
  720. ret.slot1 = NULL;
  721. ret.s1 = 0;
  722. }
  723. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  724. {
  725. ret.slot2 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+4, 2)]);
  726. ret.s2 = readNormalNr(pos+6, 2);
  727. }
  728. else
  729. {
  730. ret.slot2 = NULL;
  731. ret.s2 = 0;
  732. }
  733. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  734. {
  735. ret.slot3 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+8, 2)]);
  736. ret.s3 = readNormalNr(pos+10, 2);
  737. }
  738. else
  739. {
  740. ret.slot3 = NULL;
  741. ret.s3 = 0;
  742. }
  743. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  744. {
  745. ret.slot4 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+12, 2)]);
  746. ret.s4 = readNormalNr(pos+14, 2);
  747. }
  748. else
  749. {
  750. ret.slot4 = NULL;
  751. ret.s4 = 0;
  752. }
  753. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  754. {
  755. ret.slot5 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+16, 2)]);
  756. ret.s5 = readNormalNr(pos+18, 2);
  757. }
  758. else
  759. {
  760. ret.slot5 = NULL;
  761. ret.s5 = 0;
  762. }
  763. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  764. {
  765. ret.slot6 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+20, 2)]);
  766. ret.s6 = readNormalNr(pos+22, 2);
  767. }
  768. else
  769. {
  770. ret.slot6 = NULL;
  771. ret.s6 = 0;
  772. }
  773. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  774. {
  775. ret.slot7 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+24, 2)]);
  776. ret.s7 = readNormalNr(pos+26, 2);
  777. }
  778. else
  779. {
  780. ret.slot7 = NULL;
  781. ret.s7 = 0;
  782. }
  783. return ret;
  784. }