CAmbarCendamo.cpp 52 KB

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