CAmbarCendamo.cpp 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470
  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. #include <iomanip>
  11. #include <sstream>
  12. #define CGI (CGameInfo::mainObj)
  13. unsigned int intPow(unsigned int a, unsigned int b)
  14. {
  15. unsigned int ret=1;
  16. for(int i=0; i<b; ++i)
  17. ret*=a;
  18. return ret;
  19. }
  20. CAmbarCendamo::CAmbarCendamo (unsigned char * map)
  21. {
  22. bufor=map;
  23. }
  24. CAmbarCendamo::CAmbarCendamo (const char * tie)
  25. {
  26. is = new std::ifstream();
  27. is -> open(tie,std::ios::binary);
  28. is->seekg(0,std::ios::end); // na koniec
  29. andame = is->tellg(); // read length
  30. is->seekg(0,std::ios::beg); // wracamy na poczatek
  31. bufor = new unsigned char[andame]; // allocate memory
  32. is->read((char*)bufor, andame); // read map file to buffer
  33. is->close();
  34. delete is;
  35. }
  36. CAmbarCendamo::~CAmbarCendamo ()
  37. {// free memory
  38. for (int ii=0;ii<map.width;ii++)
  39. delete map.terrain[ii] ;
  40. delete map.terrain;
  41. delete bufor;
  42. }
  43. void CAmbarCendamo::teceDef()
  44. {
  45. for (int i=0; i<map.defy.size(); i++)
  46. {
  47. std::ofstream * of = new std::ofstream(map.defy[i].name.c_str());
  48. for (int j=0;j<46;j++)
  49. {
  50. (*of) << map.defy[i].bytes[j]<<std::endl;
  51. }
  52. of->close();
  53. delete of;
  54. }
  55. }
  56. void CAmbarCendamo::deh3m()
  57. {
  58. THC timeHandler th;
  59. map.version = (Eformat)bufor[0]; //wersja mapy
  60. map.areAnyPLayers = bufor[4]; //invalid on some maps
  61. map.height = map.width = bufor[5]; // wymiary mapy
  62. map.twoLevel = bufor[9]; //czy sa lochy
  63. map.terrain = new TerrainTile*[map.width]; // allocate memory
  64. for (int ii=0;ii<map.width;ii++)
  65. map.terrain[ii] = new TerrainTile[map.height]; // allocate memory
  66. if (map.twoLevel)
  67. {
  68. map.undergroungTerrain = new TerrainTile*[map.width]; // allocate memory
  69. for (int ii=0;ii<map.width;ii++)
  70. map.undergroungTerrain[ii] = new TerrainTile[map.height]; // allocate memory
  71. }
  72. int length = bufor[10]; //name length
  73. int i=14, pom;
  74. while (i-14<length) //read name
  75. map.name+=bufor[i++];
  76. length = bufor[i] + bufor[i+1]*256; //description length
  77. i+=4;
  78. for (pom=0;pom<length;pom++)
  79. map.description+=bufor[i++];
  80. map.difficulty = bufor[i++]; // reading map difficulty
  81. map.levelLimit = bufor[i++]; // hero level limit
  82. for (pom=0;pom<8;pom++)
  83. {
  84. map.players[pom].canHumanPlay = bufor[i++];
  85. map.players[pom].canComputerPlay = bufor[i++];
  86. if ((!(map.players[pom].canHumanPlay || map.players[pom].canComputerPlay)))
  87. {
  88. i+=13;
  89. continue;
  90. }
  91. map.players[pom].AITactic = bufor[i++];
  92. if (bufor[i++])
  93. {
  94. map.players[pom].allowedFactions = 0;
  95. map.players[pom].allowedFactions += bufor[i++];
  96. map.players[pom].allowedFactions += (bufor[i++])*256;
  97. }
  98. else
  99. {
  100. map.players[pom].allowedFactions = 511;
  101. i+=2;
  102. }
  103. map.players[pom].isFactionRandom = bufor[i++];
  104. map.players[pom].hasMainTown = bufor[i++];
  105. if (map.players[pom].hasMainTown)
  106. {
  107. map.players[pom].generateHeroAtMainTown = bufor[i++];
  108. map.players[pom].generateHero = bufor[i++];
  109. map.players[pom].posOfMainTown.x = bufor[i++];
  110. map.players[pom].posOfMainTown.y = bufor[i++];
  111. map.players[pom].posOfMainTown.z = bufor[i++];
  112. }
  113. i++; //unknown byte
  114. int unknown = bufor[i++];
  115. if (unknown == 255)
  116. {
  117. map.players[pom].mainHeroPortrait = 255;
  118. i+=5;
  119. continue;
  120. }
  121. map.players[pom].mainHeroPortrait = bufor[i++];
  122. int nameLength = bufor[i++];
  123. i+=3;
  124. for (int pp=0;pp<nameLength;pp++)
  125. map.players[pom].mainHeroName+=bufor[i++];
  126. i++; ////unknown byte
  127. int heroCount = bufor[i++];
  128. i+=3;
  129. for (int pp=0;pp<heroCount;pp++)
  130. {
  131. SheroName vv;
  132. vv.heroID=bufor[i++];
  133. int hnl = bufor[i++];
  134. i+=3;
  135. for (int zz=0;zz<hnl;zz++)
  136. {
  137. vv.heroName+=bufor[i++];
  138. }
  139. map.players[pom].heroesNames.push_back(vv);
  140. }
  141. }
  142. map.victoryCondition = (EvictoryConditions)bufor[i++];
  143. if (map.victoryCondition != winStandard) //specific victory conditions
  144. {
  145. int nr;
  146. switch (map.victoryCondition) //read victory conditions
  147. {
  148. case artifact:
  149. {
  150. map.vicConDetails = new VicCon0();
  151. ((VicCon0*)map.vicConDetails)->ArtifactID = bufor[i+2];
  152. nr=2;
  153. break;
  154. }
  155. case gatherTroop:
  156. {
  157. map.vicConDetails = new VicCon1();
  158. int temp1 = bufor[i+2];
  159. int temp2 = bufor[i+3];
  160. ((VicCon1*)map.vicConDetails)->monsterID = bufor[i+2];
  161. ((VicCon1*)map.vicConDetails)->neededQuantity=readNormalNr(i+4);
  162. nr=6;
  163. break;
  164. }
  165. case gatherResource:
  166. {
  167. map.vicConDetails = new VicCon2();
  168. ((VicCon2*)map.vicConDetails)->resourceID = bufor[i+2];
  169. ((VicCon2*)map.vicConDetails)->neededQuantity=readNormalNr(i+3);
  170. nr=5;
  171. break;
  172. }
  173. case buildCity:
  174. {
  175. map.vicConDetails = new VicCon3();
  176. ((VicCon3*)map.vicConDetails)->posOfCity.x = bufor[i+2];
  177. ((VicCon3*)map.vicConDetails)->posOfCity.y = bufor[i+3];
  178. ((VicCon3*)map.vicConDetails)->posOfCity.z = bufor[i+4];
  179. ((VicCon3*)map.vicConDetails)->councilNeededLevel = bufor[i+5];
  180. ((VicCon3*)map.vicConDetails)->fortNeededLevel = bufor[i+6];
  181. nr=5;
  182. break;
  183. }
  184. case buildGrail:
  185. {
  186. map.vicConDetails = new VicCon4();
  187. if (bufor[i+4]>2)
  188. ((VicCon4*)map.vicConDetails)->anyLocation = true;
  189. else
  190. {
  191. ((VicCon4*)map.vicConDetails)->whereBuildGrail.x = bufor[i+2];
  192. ((VicCon4*)map.vicConDetails)->whereBuildGrail.y = bufor[i+3];
  193. ((VicCon4*)map.vicConDetails)->whereBuildGrail.z = bufor[i+4];
  194. }
  195. nr=3;
  196. break;
  197. }
  198. case beatHero:
  199. {
  200. map.vicConDetails = new VicCon5();
  201. ((VicCon5*)map.vicConDetails)->locationOfHero.x = bufor[i+2];
  202. ((VicCon5*)map.vicConDetails)->locationOfHero.y = bufor[i+3];
  203. ((VicCon5*)map.vicConDetails)->locationOfHero.z = bufor[i+4];
  204. nr=3;
  205. break;
  206. }
  207. case captureCity:
  208. {
  209. map.vicConDetails = new VicCon6();
  210. ((VicCon6*)map.vicConDetails)->locationOfTown.x = bufor[i+2];
  211. ((VicCon6*)map.vicConDetails)->locationOfTown.y = bufor[i+3];
  212. ((VicCon6*)map.vicConDetails)->locationOfTown.z = bufor[i+4];
  213. nr=3;
  214. break;
  215. }
  216. case beatMonster:
  217. {
  218. map.vicConDetails = new VicCon7();
  219. ((VicCon7*)map.vicConDetails)->locationOfMonster.x = bufor[i+2];
  220. ((VicCon7*)map.vicConDetails)->locationOfMonster.y = bufor[i+3];
  221. ((VicCon7*)map.vicConDetails)->locationOfMonster.z = bufor[i+4];
  222. nr=3;
  223. break;
  224. }
  225. case takeDwellings:
  226. {
  227. map.vicConDetails = new CspecificVictoryConidtions();
  228. nr=3;
  229. break;
  230. }
  231. case takeMines:
  232. {
  233. map.vicConDetails = new CspecificVictoryConidtions();
  234. nr=3;
  235. break;
  236. }
  237. case transportItem:
  238. {
  239. map.vicConDetails = new VicCona();
  240. ((VicCona*)map.vicConDetails)->artifactID = bufor[i+2];
  241. ((VicCona*)map.vicConDetails)->destinationPlace.x = bufor[i+3];
  242. ((VicCona*)map.vicConDetails)->destinationPlace.y = bufor[i+4];
  243. ((VicCona*)map.vicConDetails)->destinationPlace.z = bufor[i+5];
  244. nr=3;
  245. break;
  246. }
  247. }
  248. map.vicConDetails->allowNormalVictory = bufor[i++];
  249. map.vicConDetails->appliesToAI = bufor[i++];
  250. i+=nr;
  251. }
  252. map.lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
  253. switch (map.lossCondition.typeOfLossCon) //read loss conditions
  254. {
  255. case lossCastle:
  256. {
  257. map.lossCondition.castlePos.x=bufor[i++];
  258. map.lossCondition.castlePos.y=bufor[i++];
  259. map.lossCondition.castlePos.z=bufor[i++];
  260. break;
  261. }
  262. case lossHero:
  263. {
  264. map.lossCondition.heroPos.x=bufor[i++];
  265. map.lossCondition.heroPos.y=bufor[i++];
  266. map.lossCondition.heroPos.z=bufor[i++];
  267. break;
  268. }
  269. case timeExpires:
  270. {
  271. map.lossCondition.timeLimit = readNormalNr(i++,2);
  272. i++;
  273. break;
  274. }
  275. }
  276. map.howManyTeams=bufor[i++]; //read number of teams
  277. if(map.howManyTeams>0) //read team numbers
  278. {
  279. for(int rr=0; rr<8; ++rr)
  280. {
  281. map.players[rr].team=bufor[i++];
  282. }
  283. }
  284. //reading allowed heroes (20 bytes)
  285. int ist=i; //starting i for loop
  286. for(i; i<ist+20; ++i)
  287. {
  288. unsigned char c = bufor[i];
  289. for(int yy=0; yy<8; ++yy)
  290. {
  291. if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size())
  292. {
  293. if(c == (c|((unsigned char)intPow(2, yy))))
  294. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = true;
  295. else
  296. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = false;
  297. }
  298. }
  299. }
  300. //allowed heroes have been read
  301. i+=36;
  302. //reading allowed artifacts //18 bytes
  303. ist=i; //starting i for loop
  304. for(i; i<ist+18; ++i)
  305. {
  306. unsigned char c = bufor[i];
  307. for(int yy=0; yy<8; ++yy)
  308. {
  309. if((i-ist)*8+yy < CGameInfo::mainObj->arth->artifacts.size())
  310. {
  311. if(c != (c|((unsigned char)intPow(2, yy))))
  312. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true;
  313. else
  314. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false;
  315. }
  316. }
  317. }//allowed artifacts have been read
  318. //reading allowed spells (9 bytes)
  319. ist=i; //starting i for loop
  320. for(i; i<ist+9; ++i)
  321. {
  322. unsigned char c = bufor[i];
  323. for(int yy=0; yy<8; ++yy)
  324. {
  325. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  326. {
  327. if(c != (c|((unsigned char)intPow(2, yy))))
  328. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true;
  329. else
  330. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false;
  331. }
  332. }
  333. }
  334. //allowed spells have been read
  335. //allowed hero's abilities (4 bytes)
  336. ist=i; //starting i for loop
  337. for(i; i<ist+4; ++i)
  338. {
  339. unsigned char c = bufor[i];
  340. for(int yy=0; yy<8; ++yy)
  341. {
  342. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  343. {
  344. if(c != (c|((unsigned char)intPow(2, yy))))
  345. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = true;
  346. else
  347. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = false;
  348. }
  349. }
  350. }
  351. //allowed hero's abilities have been read
  352. THC std::cout<<"Reading header: "<<th.getDif()<<std::endl;
  353. int rumNr = readNormalNr(i,4);i+=4;
  354. for (int it=0;it<rumNr;it++)
  355. {
  356. Rumor ourRumor;
  357. int nameL = readNormalNr(i,4);i+=4; //read length of name of rumor
  358. for (int zz=0; zz<nameL; zz++)
  359. ourRumor.name+=bufor[i++];
  360. nameL = readNormalNr(i,4);i+=4; //read length of rumor
  361. for (int zz=0; zz<nameL; zz++)
  362. ourRumor.text+=bufor[i++];
  363. map.rumors.push_back(ourRumor); //add to our list
  364. }
  365. THC std::cout<<"Reading rumors: "<<th.getDif()<<std::endl;
  366. i+=156;
  367. for (int c=0; c<map.width; c++) // reading terrain
  368. {
  369. for (int z=0; z<map.height; z++)
  370. {
  371. map.terrain[z][c].tertype = (EterrainType)(bufor[i++]);
  372. map.terrain[z][c].terview = bufor[i++];
  373. map.terrain[z][c].nuine = (Eriver)bufor[i++];
  374. map.terrain[z][c].rivDir = bufor[i++];
  375. map.terrain[z][c].malle = (Eroad)bufor[i++];
  376. map.terrain[z][c].roadDir = bufor[i++];
  377. map.terrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  378. }
  379. }
  380. if (map.twoLevel) // read underground terrain
  381. {
  382. for (int c=0; c<map.width; c++) // reading terrain
  383. {
  384. for (int z=0; z<map.height; z++)
  385. {
  386. map.undergroungTerrain[z][c].tertype = (EterrainType)(bufor[i++]);
  387. map.undergroungTerrain[z][c].terview = bufor[i++];
  388. map.undergroungTerrain[z][c].nuine = (Eriver)bufor[i++];
  389. map.undergroungTerrain[z][c].rivDir = bufor[i++];
  390. map.undergroungTerrain[z][c].malle = (Eroad)bufor[i++];
  391. map.undergroungTerrain[z][c].roadDir = bufor[i++];
  392. map.undergroungTerrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  393. }
  394. }
  395. }
  396. THC std::cout<<"Reading terrain: "<<th.getDif()<<std::endl;
  397. int defAmount = bufor[i]; // liczba defow
  398. defAmount = readNormalNr(i);
  399. i+=4;
  400. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  401. int srmask = 0xff000000;
  402. int sgmask = 0x00ff0000;
  403. int sbmask = 0x0000ff00;
  404. int samask = 0x000000ff;
  405. #else
  406. int srmask = 0x000000ff;
  407. int sgmask = 0x0000ff00;
  408. int sbmask = 0x00ff0000;
  409. int samask = 0xff000000;
  410. #endif
  411. SDL_Surface * alphaTransSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 12, 12, 32, srmask, sgmask, sbmask, samask);
  412. std::vector<std::string> defsToUnpack;
  413. for (int idd = 0 ; idd<defAmount; idd++) // reading defs
  414. {
  415. int nameLength = readNormalNr(i,4);i+=4;
  416. DefInfo vinya; // info about new def
  417. for (int cd=0;cd<nameLength;cd++)
  418. {
  419. vinya.name += bufor[i++];
  420. }
  421. for (int v=0; v<42; v++) // read info
  422. {
  423. vinya.bytes[v] = bufor[i++];
  424. }
  425. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  426. vinya.name);
  427. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  428. {
  429. vinya.isOnDefList = false;
  430. }
  431. else
  432. {
  433. vinya.printPriority = pit->priority;
  434. vinya.isOnDefList = true;
  435. }
  436. map.defy.push_back(vinya); // add this def to the vector
  437. defsToUnpack.push_back(vinya.name);
  438. //testing - only fragment//////////////////////////////////////////////////////////////
  439. /*map.defy[idd].handler = new CDefHandler();
  440. CGameInfo::mainObj->lodh->extractFile(std::string("newH3sprite.lod"), map.defy[idd].name);
  441. map.defy[idd].handler->openDef( std::string("newH3sprite\\")+map.defy[idd].name);
  442. for(int ff=0; ff<map.defy[idd].handler->ourImages.size(); ++ff) //adding shadows and transparency
  443. {
  444. map.defy[idd].handler->ourImages[ff].bitmap = CSDL_Ext::alphaTransform(map.defy[idd].handler->ourImages[ff].bitmap);
  445. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[idd].handler->ourImages[ff].bitmap, alphaTransSurf);
  446. SDL_FreeSurface(map.defy[idd].handler->ourImages[ff].bitmap);
  447. map.defy[idd].handler->ourImages[ff].bitmap = bufs;
  448. }
  449. boost::filesystem::remove(boost::filesystem::path(std::string("newH3sprite\\")+map.defy[idd].name));*/
  450. //system((std::string("DEL newH3sprite\\")+map.defy[idd].name).c_str());
  451. //end fo testing - only fragment///////////////////////////////////////////////////////
  452. //teceDef();
  453. }
  454. THC std::cout<<"Reading defs: "<<th.getDif()<<std::endl;
  455. ////loading objects
  456. int howManyObjs = readNormalNr(i, 4); i+=4;
  457. for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
  458. {
  459. //std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
  460. CObjectInstance nobj; //we will read this object
  461. nobj.id = CGameInfo::mainObj->objh->objInstances.size();
  462. nobj.x = bufor[i++];
  463. nobj.y = bufor[i++];
  464. nobj.z = bufor[i++];
  465. nobj.defNumber = readNormalNr(i, 4); i+=4;
  466. //if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
  467. // std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
  468. i+=5;
  469. unsigned char buff [30];
  470. for(int ccc=0; ccc<30; ++ccc)
  471. {
  472. buff[ccc] = bufor[i+ccc];
  473. }
  474. EDefType uu = getDefType(map.defy[nobj.defNumber]);
  475. int j = map.defy[nobj.defNumber].bytes[16];
  476. int p = 99;
  477. switch(getDefType(map.defy[nobj.defNumber]))
  478. {
  479. case EDefType::EVENTOBJ_DEF: //for event - objects
  480. {
  481. CEventObjInfo * spec = new CEventObjInfo;
  482. bool guardMess;
  483. guardMess = bufor[i]; ++i;
  484. if(guardMess)
  485. {
  486. int messLong = readNormalNr(i, 4); i+=4;
  487. if(messLong>0)
  488. {
  489. spec->isMessage = true;
  490. for(int yy=0; yy<messLong; ++yy)
  491. {
  492. spec->message +=bufor[i+yy];
  493. }
  494. i+=messLong;
  495. }
  496. spec->areGuarders = bufor[i]; ++i;
  497. if(spec->areGuarders)
  498. {
  499. spec->guarders = readCreatureSet(i); i+=28;
  500. }
  501. i+=4;
  502. }
  503. else
  504. {
  505. spec->isMessage = false;
  506. spec->areGuarders = false;
  507. spec->message = std::string("");
  508. }
  509. spec->gainedExp = readNormalNr(i, 4); i+=4;
  510. spec->manaDiff = readNormalNr(i, 4); i+=4;
  511. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  512. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  513. spec->wood = readNormalNr(i); i+=4;
  514. spec->mercury = readNormalNr(i); i+=4;
  515. spec->ore = readNormalNr(i); i+=4;
  516. spec->sulfur = readNormalNr(i); i+=4;
  517. spec->crystal = readNormalNr(i); i+=4;
  518. spec->gems = readNormalNr(i); i+=4;
  519. spec->gold = readNormalNr(i); i+=4;
  520. spec->attack = readNormalNr(i, 1); ++i;
  521. spec->defence = readNormalNr(i, 1); ++i;
  522. spec->power = readNormalNr(i, 1); ++i;
  523. spec->knowledge = readNormalNr(i, 1); ++i;
  524. int gabn; //number of gained abilities
  525. gabn = readNormalNr(i, 1); ++i;
  526. for(int oo = 0; oo<gabn; ++oo)
  527. {
  528. spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
  529. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  530. }
  531. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  532. for(int oo = 0; oo<gart; ++oo)
  533. {
  534. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  535. }
  536. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  537. for(int oo = 0; oo<gspel; ++oo)
  538. {
  539. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  540. }
  541. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  542. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  543. i+=8;
  544. spec->availableFor = readNormalNr(i, 1); ++i;
  545. spec->computerActivate = readNormalNr(i, 1); ++i;
  546. spec->humanActivate = readNormalNr(i, 1); ++i;
  547. i+=4;
  548. nobj.info = spec;
  549. break;
  550. }
  551. case EDefType::HERO_DEF:
  552. {
  553. CHeroObjInfo * spec = new CHeroObjInfo;
  554. spec->bytes[0] = bufor[i]; ++i;
  555. spec->bytes[1] = bufor[i]; ++i;
  556. spec->bytes[2] = bufor[i]; ++i;
  557. spec->bytes[3] = bufor[i]; ++i;
  558. spec->player = bufor[i]; ++i;
  559. spec->type = CGameInfo::mainObj->heroh->heroes[readNormalNr(i, 1)]; ++i;
  560. bool isName = bufor[i]; ++i; //true if hero has nonstandard name
  561. if(isName)
  562. {
  563. int length = readNormalNr(i, 4); i+=4;
  564. for(int gg=0; gg<length; ++gg)
  565. {
  566. spec->name+=bufor[i]; ++i;
  567. }
  568. }
  569. else
  570. spec->name = std::string("");
  571. bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0
  572. if(isExp)
  573. {
  574. spec->experience = readNormalNr(i); i+=4;
  575. }
  576. else spec->experience = 0;
  577. bool portrait=bufor[i]; ++i;
  578. if (portrait)
  579. i++; //TODO read portrait nr, save, open
  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+=28; //4 bytes per slot
  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æ //seems to be ok - tow
  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); i+=2;
  1286. }
  1287. i+=4;
  1288. spec->events.push_back(nce);
  1289. }
  1290. /////// castle events have been read ///////////////////////////
  1291. spec->alignment = bufor[i]; ++i;
  1292. i+=3;
  1293. nobj.info = spec;
  1294. break;
  1295. }
  1296. case EDefType::PLAYERONLY_DEF:
  1297. {
  1298. CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
  1299. spec->player = bufor[i]; ++i;
  1300. i+=3;
  1301. nobj.info = spec;
  1302. break;
  1303. }
  1304. case EDefType::SHRINE_DEF:
  1305. {
  1306. CShrineObjInfo * spec = new CShrineObjInfo;
  1307. spec->spell = bufor[i]; i+=4;
  1308. nobj.info = spec;
  1309. break;
  1310. }
  1311. case EDefType::SPELLSCROLL_DEF:
  1312. {
  1313. CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
  1314. bool messg = bufor[i]; ++i;
  1315. if(messg)
  1316. {
  1317. int mLength = readNormalNr(i); i+=4;
  1318. for(int vv=0; vv<mLength; ++vv)
  1319. {
  1320. spec->message += bufor[i]; ++i;
  1321. }
  1322. spec->areGuarders = bufor[i]; ++i;
  1323. if(spec->areGuarders)
  1324. {
  1325. spec->guarders = readCreatureSet(i); i+=28;
  1326. }
  1327. i+=4;
  1328. }
  1329. spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1330. i+=3;
  1331. nobj.info = spec;
  1332. break;
  1333. }
  1334. case EDefType::PANDORA_DEF:
  1335. {
  1336. CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
  1337. bool messg = bufor[i]; ++i;
  1338. if(messg)
  1339. {
  1340. int mLength = readNormalNr(i); i+=4;
  1341. for(int vv=0; vv<mLength; ++vv)
  1342. {
  1343. spec->message += bufor[i]; ++i;
  1344. }
  1345. spec->areGuarders = bufor[i]; ++i;
  1346. if(spec->areGuarders)
  1347. {
  1348. spec->guarders = readCreatureSet(i); i+=28;
  1349. }
  1350. i+=4;
  1351. }
  1352. ////// copied form event handling (seems to be similar)
  1353. spec->gainedExp = readNormalNr(i, 4); i+=4;
  1354. spec->manaDiff = readNormalNr(i, 4); i+=4;
  1355. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  1356. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  1357. spec->wood = readNormalNr(i); i+=4;
  1358. spec->mercury = readNormalNr(i); i+=4;
  1359. spec->ore = readNormalNr(i); i+=4;
  1360. spec->sulfur = readNormalNr(i); i+=4;
  1361. spec->crystal = readNormalNr(i); i+=4;
  1362. spec->gems = readNormalNr(i); i+=4;
  1363. spec->gold = readNormalNr(i); i+=4;
  1364. spec->attack = readNormalNr(i, 1); ++i;
  1365. spec->defence = readNormalNr(i, 1); ++i;
  1366. spec->power = readNormalNr(i, 1); ++i;
  1367. spec->knowledge = readNormalNr(i, 1); ++i;
  1368. int gabn; //number of gained abilities
  1369. gabn = readNormalNr(i, 1); ++i;
  1370. for(int oo = 0; oo<gabn; ++oo)
  1371. {
  1372. spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
  1373. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  1374. }
  1375. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  1376. for(int oo = 0; oo<gart; ++oo)
  1377. {
  1378. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  1379. }
  1380. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  1381. for(int oo = 0; oo<gspel; ++oo)
  1382. {
  1383. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  1384. }
  1385. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  1386. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  1387. i+=8;
  1388. nobj.info = spec;
  1389. ///////end of copied fragment
  1390. break;
  1391. }
  1392. case EDefType::GRAIL_DEF:
  1393. {
  1394. CGrailObjInfo * spec = new CGrailObjInfo;
  1395. spec->radius = readNormalNr(i); i+=4;
  1396. nobj.info = spec;
  1397. break;
  1398. }
  1399. case EDefType::CREGEN_DEF:
  1400. {
  1401. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1402. spec->player = bufor[i]; ++i;
  1403. i+=3;
  1404. for(int ggg=0; ggg<4; ++ggg)
  1405. {
  1406. spec->bytes[ggg] = bufor[i]; ++i;
  1407. }
  1408. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1409. {
  1410. spec->asCastle = false;
  1411. spec->castles[0] = bufor[i]; ++i;
  1412. spec->castles[1] = bufor[i]; ++i;
  1413. }
  1414. else
  1415. {
  1416. spec->asCastle = true;
  1417. }
  1418. nobj.info = spec;
  1419. break;
  1420. }
  1421. case EDefType::CREGEN2_DEF:
  1422. {
  1423. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1424. spec->player = bufor[i]; ++i;
  1425. i+=3;
  1426. for(int ggg=0; ggg<4; ++ggg)
  1427. {
  1428. spec->bytes[ggg] = bufor[i]; ++i;
  1429. }
  1430. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1431. {
  1432. spec->asCastle = false;
  1433. spec->castles[0] = bufor[i]; ++i;
  1434. spec->castles[1] = bufor[i]; ++i;
  1435. }
  1436. else
  1437. {
  1438. spec->asCastle = true;
  1439. }
  1440. spec->minLevel = bufor[i]; ++i;
  1441. spec->maxLevel = bufor[i]; ++i;
  1442. nobj.info = spec;
  1443. break;
  1444. }
  1445. case EDefType::CREGEN3_DEF:
  1446. {
  1447. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1448. spec->player = bufor[i]; ++i;
  1449. i+=3;
  1450. spec->minLevel = bufor[i]; ++i;
  1451. spec->maxLevel = bufor[i]; ++i;
  1452. nobj.info = spec;
  1453. break;
  1454. }
  1455. case EDefType::BORDERGUARD_DEF:
  1456. {
  1457. CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
  1458. spec->missionType = bufor[i]; ++i;
  1459. switch(spec->missionType)
  1460. {
  1461. case 1:
  1462. {
  1463. spec->m1level = readNormalNr(i); i+=4;
  1464. int limit = readNormalNr(i); i+=4;
  1465. if(limit == ((int)0xffffffff))
  1466. {
  1467. spec->isDayLimit = false;
  1468. spec->lastDay = -1;
  1469. }
  1470. else
  1471. {
  1472. spec->isDayLimit = true;
  1473. spec->lastDay = limit;
  1474. }
  1475. break;
  1476. }
  1477. case 2:
  1478. {
  1479. spec->m2attack = bufor[i]; ++i;
  1480. spec->m2defence = bufor[i]; ++i;
  1481. spec->m2power = bufor[i]; ++i;
  1482. spec->m2knowledge = bufor[i]; ++i;
  1483. int limit = readNormalNr(i); i+=4;
  1484. if(limit == ((int)0xffffffff))
  1485. {
  1486. spec->isDayLimit = false;
  1487. spec->lastDay = -1;
  1488. }
  1489. else
  1490. {
  1491. spec->isDayLimit = true;
  1492. spec->lastDay = limit;
  1493. }
  1494. break;
  1495. }
  1496. case 3:
  1497. {
  1498. spec->m3bytes[0] = bufor[i]; ++i;
  1499. spec->m3bytes[1] = bufor[i]; ++i;
  1500. spec->m3bytes[2] = bufor[i]; ++i;
  1501. spec->m3bytes[3] = bufor[i]; ++i;
  1502. int limit = readNormalNr(i); i+=4;
  1503. if(limit == ((int)0xffffffff))
  1504. {
  1505. spec->isDayLimit = false;
  1506. spec->lastDay = -1;
  1507. }
  1508. else
  1509. {
  1510. spec->isDayLimit = true;
  1511. spec->lastDay = limit;
  1512. }
  1513. break;
  1514. }
  1515. case 4:
  1516. {
  1517. spec->m4bytes[0] = bufor[i]; ++i;
  1518. spec->m4bytes[1] = bufor[i]; ++i;
  1519. spec->m4bytes[2] = bufor[i]; ++i;
  1520. spec->m4bytes[3] = bufor[i]; ++i;
  1521. int limit = readNormalNr(i); i+=4;
  1522. if(limit == ((int)0xffffffff))
  1523. {
  1524. spec->isDayLimit = false;
  1525. spec->lastDay = -1;
  1526. }
  1527. else
  1528. {
  1529. spec->isDayLimit = true;
  1530. spec->lastDay = limit;
  1531. }
  1532. break;
  1533. }
  1534. case 5:
  1535. {
  1536. int artNumber = bufor[i]; ++i;
  1537. for(int yy=0; yy<artNumber; ++yy)
  1538. {
  1539. int artid = readNormalNr(i, 2); i+=2;
  1540. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  1541. }
  1542. int limit = readNormalNr(i); i+=4;
  1543. if(limit == ((int)0xffffffff))
  1544. {
  1545. spec->isDayLimit = false;
  1546. spec->lastDay = -1;
  1547. }
  1548. else
  1549. {
  1550. spec->isDayLimit = true;
  1551. spec->lastDay = limit;
  1552. }
  1553. break;
  1554. }
  1555. case 6:
  1556. {
  1557. int typeNumber = bufor[i]; ++i;
  1558. for(int hh=0; hh<typeNumber; ++hh)
  1559. {
  1560. int creType = readNormalNr(i, 2); i+=2;
  1561. int creNumb = readNormalNr(i, 2); i+=2;
  1562. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  1563. spec->m6number.push_back(creNumb);
  1564. }
  1565. int limit = readNormalNr(i); i+=4;
  1566. if(limit == ((int)0xffffffff))
  1567. {
  1568. spec->isDayLimit = false;
  1569. spec->lastDay = -1;
  1570. }
  1571. else
  1572. {
  1573. spec->isDayLimit = true;
  1574. spec->lastDay = limit;
  1575. }
  1576. break;
  1577. }
  1578. case 7:
  1579. {
  1580. spec->m7wood = readNormalNr(i); i+=4;
  1581. spec->m7mercury = readNormalNr(i); i+=4;
  1582. spec->m7ore = readNormalNr(i); i+=4;
  1583. spec->m7sulfur = readNormalNr(i); i+=4;
  1584. spec->m7crystal = readNormalNr(i); i+=4;
  1585. spec->m7gems = readNormalNr(i); i+=4;
  1586. spec->m7gold = readNormalNr(i); i+=4;
  1587. int limit = readNormalNr(i); i+=4;
  1588. if(limit == ((int)0xffffffff))
  1589. {
  1590. spec->isDayLimit = false;
  1591. spec->lastDay = -1;
  1592. }
  1593. else
  1594. {
  1595. spec->isDayLimit = true;
  1596. spec->lastDay = limit;
  1597. }
  1598. break;
  1599. }
  1600. case 8:
  1601. {
  1602. int heroType = bufor[i]; ++i;
  1603. spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
  1604. int limit = readNormalNr(i); i+=4;
  1605. if(limit == ((int)0xffffffff))
  1606. {
  1607. spec->isDayLimit = false;
  1608. spec->lastDay = -1;
  1609. }
  1610. else
  1611. {
  1612. spec->isDayLimit = true;
  1613. spec->lastDay = limit;
  1614. }
  1615. break;
  1616. }
  1617. case 9:
  1618. {
  1619. spec->m9player = bufor[i]; ++i;
  1620. int limit = readNormalNr(i); i+=4;
  1621. if(limit == ((int)0xffffffff))
  1622. {
  1623. spec->isDayLimit = false;
  1624. spec->lastDay = -1;
  1625. }
  1626. else
  1627. {
  1628. spec->isDayLimit = true;
  1629. spec->lastDay = limit;
  1630. }
  1631. break;
  1632. }
  1633. }//internal switch end (seer huts)
  1634. int len1 = readNormalNr(i); i+=4;
  1635. for(int ee=0; ee<len1; ++ee)
  1636. {
  1637. spec->firstVisitText += bufor[i]; ++i;
  1638. }
  1639. int len2 = readNormalNr(i); i+=4;
  1640. for(int ee=0; ee<len2; ++ee)
  1641. {
  1642. spec->nextVisitText += bufor[i]; ++i;
  1643. }
  1644. int len3 = readNormalNr(i); i+=4;
  1645. for(int ee=0; ee<len3; ++ee)
  1646. {
  1647. spec->completedText += bufor[i]; ++i;
  1648. }
  1649. nobj.info = spec;
  1650. break;
  1651. }
  1652. } //end of main switch
  1653. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  1654. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  1655. }//*/ //end of loading objects; commented to make application work until it will be finished
  1656. ////objects loaded
  1657. processMap(defsToUnpack);
  1658. std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack);
  1659. for (int i=0;i<dhandlers.size();i++)
  1660. map.defy[i].handler=dhandlers[i];
  1661. for(int vv=0; vv<map.defy.size(); ++vv)
  1662. {
  1663. if(map.defy[vv].handler->alphaTransformed)
  1664. continue;
  1665. for(int yy=0; yy<map.defy[vv].handler->ourImages.size(); ++yy)
  1666. {
  1667. map.defy[vv].handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv].handler->ourImages[yy].bitmap);
  1668. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv].handler->ourImages[yy].bitmap, alphaTransSurf);
  1669. SDL_FreeSurface(map.defy[vv].handler->ourImages[yy].bitmap);
  1670. map.defy[vv].handler->ourImages[yy].bitmap = bufs;
  1671. map.defy[vv].handler->alphaTransformed = true;
  1672. }
  1673. }
  1674. SDL_FreeSurface(alphaTransSurf);
  1675. //loading events
  1676. int numberOfEvents = readNormalNr(i); i+=4;
  1677. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  1678. {
  1679. CMapEvent ne;
  1680. ne.name = std::string();
  1681. ne.message = std::string();
  1682. int nameLen = readNormalNr(i); i+=4;
  1683. for(int qq=0; qq<nameLen; ++qq)
  1684. {
  1685. ne.name += bufor[i]; ++i;
  1686. }
  1687. int messLen = readNormalNr(i); i+=4;
  1688. for(int qq=0; qq<messLen; ++qq)
  1689. {
  1690. ne.message +=bufor[i]; ++i;
  1691. }
  1692. ne.wood = readNormalNr(i); i+=4;
  1693. ne.mercury = readNormalNr(i); i+=4;
  1694. ne.ore = readNormalNr(i); i+=4;
  1695. ne.sulfur = readNormalNr(i); i+=4;
  1696. ne.crystal = readNormalNr(i); i+=4;
  1697. ne.gems = readNormalNr(i); i+=4;
  1698. ne.gold = readNormalNr(i); i+=4;
  1699. ne.players = bufor[i]; ++i;
  1700. ne.humanAffected = bufor[i]; ++i;
  1701. ne.computerAffected = bufor[i]; ++i;
  1702. ne.firstOccurence = bufor[i]; ++i;
  1703. ne.nextOccurence = bufor[i]; ++i;
  1704. i+=18;
  1705. map.events.push_back(ne);
  1706. }
  1707. }
  1708. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  1709. {
  1710. int ret=0;
  1711. int amp=1;
  1712. for (int i=0; i<bytCon; i++)
  1713. {
  1714. ret+=bufor[pos+i]*amp;
  1715. amp*=256;
  1716. }
  1717. if(cyclic && bytCon<4 && ret>=amp/2)
  1718. {
  1719. ret = ret-amp;
  1720. }
  1721. return ret;
  1722. }
  1723. void CAmbarCendamo::loadDefs()
  1724. {
  1725. std::set<int> loadedTypes;
  1726. for (int i=0; i<map.width; i++)
  1727. {
  1728. for (int j=0; j<map.width; j++)
  1729. {
  1730. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  1731. {
  1732. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str());
  1733. loadedTypes.insert(map.terrain[i][j].tertype);
  1734. defs.push_back(sdh);
  1735. }
  1736. if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  1737. {
  1738. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str());
  1739. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  1740. defs.push_back(sdh);
  1741. }
  1742. }
  1743. }
  1744. }
  1745. EDefType CAmbarCendamo::getDefType(DefInfo &a)
  1746. {
  1747. switch(a.bytes[16])
  1748. {
  1749. case 5: case 65: case 66: case 67: case 68: case 69:
  1750. return EDefType::ARTIFACT_DEF; //handled
  1751. case 6:
  1752. return EDefType::PANDORA_DEF; //hanled
  1753. case 26:
  1754. return EDefType::EVENTOBJ_DEF; //handled
  1755. case 33:
  1756. return EDefType::GARRISON_DEF; //handled
  1757. case 34: case 70: case 62: //70 - random hero //62 - prison
  1758. return EDefType::HERO_DEF; //handled
  1759. case 36:
  1760. return EDefType::GRAIL_DEF; //hanled
  1761. case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
  1762. return EDefType::PLAYERONLY_DEF; //handled
  1763. case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
  1764. return EDefType::CREATURES_DEF; //handled
  1765. case 59:
  1766. return EDefType::SIGN_DEF; //handled
  1767. case 77:
  1768. return EDefType::TOWN_DEF; //can be problematic, but handled
  1769. case 79: case 76:
  1770. return EDefType::RESOURCE_DEF; //handled
  1771. case 81:
  1772. return EDefType::SCHOLAR_DEF; //handled
  1773. case 83:
  1774. return EDefType::SEERHUT_DEF; //handled
  1775. case 91:
  1776. return EDefType::SIGN_DEF; //handled
  1777. case 88: case 89: case 90:
  1778. return SHRINE_DEF; //handled
  1779. case 93:
  1780. return SPELLSCROLL_DEF; //handled
  1781. case 98:
  1782. return EDefType::TOWN_DEF; //handled
  1783. case 113:
  1784. return EDefType::WITCHHUT_DEF; //handled
  1785. case 215:
  1786. return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;]
  1787. case 216:
  1788. return EDefType::CREGEN2_DEF; //handled
  1789. case 217:
  1790. return EDefType::CREGEN_DEF; //handled
  1791. case 218:
  1792. return EDefType::CREGEN3_DEF; //handled
  1793. case 219:
  1794. return EDefType::GARRISON_DEF; //handled
  1795. default:
  1796. return EDefType::TERRAINOBJ_DEF; // nothing to be handled
  1797. }
  1798. }
  1799. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  1800. {
  1801. CCreatureSet ret;
  1802. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  1803. {
  1804. int rettt = readNormalNr(pos, 2);
  1805. if(rettt>32768)
  1806. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1807. ret.slot1 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1808. ret.s1 = readNormalNr(pos+2, 2);
  1809. }
  1810. else
  1811. {
  1812. ret.slot1 = NULL;
  1813. ret.s1 = 0;
  1814. }
  1815. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  1816. {
  1817. int rettt = readNormalNr(pos+4, 2);
  1818. if(rettt>32768)
  1819. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1820. ret.slot2 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1821. ret.s2 = readNormalNr(pos+6, 2);
  1822. }
  1823. else
  1824. {
  1825. ret.slot2 = NULL;
  1826. ret.s2 = 0;
  1827. }
  1828. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  1829. {
  1830. int rettt = readNormalNr(pos+8, 2);
  1831. if(rettt>32768)
  1832. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1833. ret.slot3 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1834. ret.s3 = readNormalNr(pos+10, 2);
  1835. }
  1836. else
  1837. {
  1838. ret.slot3 = NULL;
  1839. ret.s3 = 0;
  1840. }
  1841. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  1842. {
  1843. int rettt = readNormalNr(pos+12, 2);
  1844. if(rettt>32768)
  1845. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1846. ret.slot4 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1847. ret.s4 = readNormalNr(pos+14, 2);
  1848. }
  1849. else
  1850. {
  1851. ret.slot4 = NULL;
  1852. ret.s4 = 0;
  1853. }
  1854. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  1855. {
  1856. int rettt = readNormalNr(pos+16, 2);
  1857. if(rettt>32768)
  1858. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1859. ret.slot5 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1860. ret.s5 = readNormalNr(pos+18, 2);
  1861. }
  1862. else
  1863. {
  1864. ret.slot5 = NULL;
  1865. ret.s5 = 0;
  1866. }
  1867. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  1868. {
  1869. int rettt = readNormalNr(pos+20, 2);
  1870. if(rettt>32768)
  1871. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1872. ret.slot6 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1873. ret.s6 = readNormalNr(pos+22, 2);
  1874. }
  1875. else
  1876. {
  1877. ret.slot6 = NULL;
  1878. ret.s6 = 0;
  1879. }
  1880. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  1881. {
  1882. int rettt = readNormalNr(pos+24, 2);
  1883. if(rettt>32768)
  1884. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1885. ret.slot7 = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1886. ret.s7 = readNormalNr(pos+26, 2);
  1887. }
  1888. else
  1889. {
  1890. ret.slot7 = NULL;
  1891. ret.s7 = 0;
  1892. }
  1893. return ret;
  1894. }
  1895. void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
  1896. {
  1897. resDefNames.push_back("AVTRNDM0.DEF");
  1898. resDefNames.push_back("AVTWOOD0.DEF");
  1899. resDefNames.push_back("AVTMERC0.DEF");
  1900. resDefNames.push_back("AVTORE0.DEF");
  1901. resDefNames.push_back("AVTSULF0.DEF");
  1902. resDefNames.push_back("AVTCRYS0.DEF");
  1903. resDefNames.push_back("AVTGEMS0.DEF");
  1904. resDefNames.push_back("AVTGOLD0.DEF");
  1905. resDefNames.push_back("ZMITHR.DEF");
  1906. std::vector<int> resDefNumbers;
  1907. for(int hh=0; hh<resDefNames.size(); ++hh)
  1908. {
  1909. resDefNumbers.push_back(-1);
  1910. for(int k=0; k<map.defy.size(); ++k)
  1911. {
  1912. std::string buf = map.defy[k].name;
  1913. std::transform(buf.begin(), buf.end(), buf.begin(), (int(*)(int))toupper);
  1914. if(resDefNames[hh] == buf)
  1915. {
  1916. resDefNumbers[resDefNumbers.size()-1] = k;
  1917. break;
  1918. }
  1919. }
  1920. }
  1921. std::vector<std::string> creDefNames;
  1922. for(int dd=0; dd<140; ++dd) //we do not use here WoG units
  1923. {
  1924. creDefNames.push_back(CGI->dobjinfo->objs[dd+1184].defName);
  1925. }
  1926. std::vector<int> creDefNumbers;
  1927. for(int ee=0; ee<creDefNames.size(); ++ee)
  1928. {
  1929. creDefNumbers.push_back(-1);
  1930. }
  1931. std::vector<std::string> artDefNames;
  1932. std::vector<int> artDefNumbers;
  1933. for(int bb=0; bb<162; ++bb)
  1934. {
  1935. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass!=EartClass::SartClass)
  1936. artDefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1937. }
  1938. for(int ee=0; ee<artDefNames.size(); ++ee)
  1939. {
  1940. artDefNumbers.push_back(-1);
  1941. }
  1942. std::vector<std::string> art1DefNames;
  1943. std::vector<int> art1DefNumbers;
  1944. for(int bb=0; bb<162; ++bb)
  1945. {
  1946. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::TartClass)
  1947. art1DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1948. }
  1949. for(int ee=0; ee<art1DefNames.size(); ++ee)
  1950. {
  1951. art1DefNumbers.push_back(-1);
  1952. }
  1953. std::vector<std::string> art2DefNames;
  1954. std::vector<int> art2DefNumbers;
  1955. for(int bb=0; bb<162; ++bb)
  1956. {
  1957. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::NartClass)
  1958. art2DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1959. }
  1960. for(int ee=0; ee<art2DefNames.size(); ++ee)
  1961. {
  1962. art2DefNumbers.push_back(-1);
  1963. }
  1964. std::vector<std::string> art3DefNames;
  1965. std::vector<int> art3DefNumbers;
  1966. for(int bb=0; bb<162; ++bb)
  1967. {
  1968. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::JartClass)
  1969. art3DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1970. }
  1971. for(int ee=0; ee<art3DefNames.size(); ++ee)
  1972. {
  1973. art3DefNumbers.push_back(-1);
  1974. }
  1975. std::vector<std::string> art4DefNames;
  1976. std::vector<int> art4DefNumbers;
  1977. for(int bb=0; bb<162; ++bb)
  1978. {
  1979. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::RartClass)
  1980. art4DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1981. }
  1982. for(int ee=0; ee<art4DefNames.size(); ++ee)
  1983. {
  1984. art4DefNumbers.push_back(-1);
  1985. }
  1986. //variables initialized
  1987. for(int j=0; j<CGI->objh->objInstances.size(); ++j)
  1988. {
  1989. DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber];
  1990. switch(getDefType(curDef))
  1991. {
  1992. case EDefType::RESOURCE_DEF:
  1993. {
  1994. if(curDef.bytes[16]==76) //resource to specify
  1995. {
  1996. DefInfo nxt = curDef;
  1997. nxt.bytes[16] = 79;
  1998. nxt.bytes[20] = rand()%7;
  1999. if(resDefNumbers[nxt.bytes[20]+1]!=-1)
  2000. {
  2001. CGI->objh->objInstances[j].defNumber = resDefNumbers[nxt.bytes[20]+1];
  2002. continue;
  2003. }
  2004. nxt.name = resDefNames[nxt.bytes[20]+1];
  2005. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2006. nxt.name);
  2007. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2008. {
  2009. nxt.isOnDefList = false;
  2010. }
  2011. else
  2012. {
  2013. nxt.printPriority = pit->priority;
  2014. nxt.isOnDefList = true;
  2015. }
  2016. map.defy.push_back(nxt); // add this def to the vector
  2017. defsToUnpack.push_back(nxt.name);
  2018. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2019. if(resDefNumbers[nxt.bytes[20]+1]==-1)
  2020. {
  2021. resDefNumbers[nxt.bytes[20]+1] = map.defy.size()-1;
  2022. }
  2023. }
  2024. break;
  2025. }
  2026. case EDefType::CREATURES_DEF:
  2027. {
  2028. if(curDef.bytes[16]==72) //random monster lvl 1
  2029. {
  2030. DefInfo nxt = curDef;
  2031. nxt.bytes[16] = 54;
  2032. nxt.bytes[20] = 14*(rand()%9)+rand()%2;
  2033. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2034. {
  2035. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2036. continue;
  2037. }
  2038. nxt.name = creDefNames[nxt.bytes[20]];
  2039. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2040. nxt.name);
  2041. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2042. {
  2043. nxt.isOnDefList = false;
  2044. }
  2045. else
  2046. {
  2047. nxt.printPriority = pit->priority;
  2048. nxt.isOnDefList = true;
  2049. }
  2050. map.defy.push_back(nxt); // add this def to the vector
  2051. defsToUnpack.push_back(nxt.name);
  2052. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2053. if(creDefNumbers[nxt.bytes[20]]==-1)
  2054. {
  2055. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2056. }
  2057. }
  2058. if(curDef.bytes[16]==73) //random monster lvl 2
  2059. {
  2060. DefInfo nxt = curDef;
  2061. nxt.bytes[16] = 54;
  2062. nxt.bytes[20] = 14*(rand()%9)+rand()%2+2;
  2063. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2064. {
  2065. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2066. continue;
  2067. }
  2068. nxt.name = creDefNames[nxt.bytes[20]];
  2069. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2070. nxt.name);
  2071. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2072. {
  2073. nxt.isOnDefList = false;
  2074. }
  2075. else
  2076. {
  2077. nxt.printPriority = pit->priority;
  2078. nxt.isOnDefList = true;
  2079. }
  2080. map.defy.push_back(nxt); // add this def to the vector
  2081. defsToUnpack.push_back(nxt.name);
  2082. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2083. if(creDefNumbers[nxt.bytes[20]]==-1)
  2084. {
  2085. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2086. }
  2087. }
  2088. if(curDef.bytes[16]==74) //random monster lvl 3
  2089. {
  2090. DefInfo nxt = curDef;
  2091. nxt.bytes[16] = 54;
  2092. nxt.bytes[20] = 14*(rand()%9)+rand()%2+4;
  2093. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2094. {
  2095. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2096. continue;
  2097. }
  2098. nxt.name = creDefNames[nxt.bytes[20]];
  2099. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2100. nxt.name);
  2101. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2102. {
  2103. nxt.isOnDefList = false;
  2104. }
  2105. else
  2106. {
  2107. nxt.printPriority = pit->priority;
  2108. nxt.isOnDefList = true;
  2109. }
  2110. map.defy.push_back(nxt); // add this def to the vector
  2111. defsToUnpack.push_back(nxt.name);
  2112. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2113. if(creDefNumbers[nxt.bytes[20]]==-1)
  2114. {
  2115. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2116. }
  2117. }
  2118. if(curDef.bytes[16]==75) //random monster lvl 4
  2119. {
  2120. DefInfo nxt = curDef;
  2121. nxt.bytes[16] = 54;
  2122. nxt.bytes[20] = 14*(rand()%9)+rand()%2+6;
  2123. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2124. {
  2125. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2126. continue;
  2127. }
  2128. nxt.name = creDefNames[nxt.bytes[20]];
  2129. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2130. nxt.name);
  2131. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2132. {
  2133. nxt.isOnDefList = false;
  2134. }
  2135. else
  2136. {
  2137. nxt.printPriority = pit->priority;
  2138. nxt.isOnDefList = true;
  2139. }
  2140. map.defy.push_back(nxt); // add this def to the vector
  2141. defsToUnpack.push_back(nxt.name);
  2142. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2143. if(creDefNumbers[nxt.bytes[20]]==-1)
  2144. {
  2145. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2146. }
  2147. }
  2148. if(curDef.bytes[16]==162) //random monster lvl 5
  2149. {
  2150. DefInfo nxt = curDef;
  2151. nxt.bytes[16] = 54;
  2152. nxt.bytes[20] = 14*(rand()%9)+rand()%2+8;
  2153. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2154. {
  2155. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2156. continue;
  2157. }
  2158. nxt.name = creDefNames[nxt.bytes[20]];
  2159. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2160. nxt.name);
  2161. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2162. {
  2163. nxt.isOnDefList = false;
  2164. }
  2165. else
  2166. {
  2167. nxt.printPriority = pit->priority;
  2168. nxt.isOnDefList = true;
  2169. }
  2170. map.defy.push_back(nxt); // add this def to the vector
  2171. defsToUnpack.push_back(nxt.name);
  2172. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2173. if(creDefNumbers[nxt.bytes[20]]==-1)
  2174. {
  2175. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2176. }
  2177. }
  2178. if(curDef.bytes[16]==163) //random monster lvl 6
  2179. {
  2180. DefInfo nxt = curDef;
  2181. nxt.bytes[16] = 54;
  2182. nxt.bytes[20] = 14*(rand()%9)+rand()%2+10;
  2183. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2184. {
  2185. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2186. continue;
  2187. }
  2188. nxt.name = creDefNames[nxt.bytes[20]];
  2189. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2190. nxt.name);
  2191. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2192. {
  2193. nxt.isOnDefList = false;
  2194. }
  2195. else
  2196. {
  2197. nxt.printPriority = pit->priority;
  2198. nxt.isOnDefList = true;
  2199. }
  2200. map.defy.push_back(nxt); // add this def to the vector
  2201. defsToUnpack.push_back(nxt.name);
  2202. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2203. if(creDefNumbers[nxt.bytes[20]]==-1)
  2204. {
  2205. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2206. }
  2207. }
  2208. if(curDef.bytes[16]==164) //random monster lvl 7
  2209. {
  2210. DefInfo nxt = curDef;
  2211. nxt.bytes[16] = 54;
  2212. nxt.bytes[20] = 14*(rand()%9)+rand()%2+12;
  2213. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2214. {
  2215. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2216. continue;
  2217. }
  2218. nxt.name = creDefNames[nxt.bytes[20]];
  2219. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2220. nxt.name);
  2221. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2222. {
  2223. nxt.isOnDefList = false;
  2224. }
  2225. else
  2226. {
  2227. nxt.printPriority = pit->priority;
  2228. nxt.isOnDefList = true;
  2229. }
  2230. map.defy.push_back(nxt); // add this def to the vector
  2231. defsToUnpack.push_back(nxt.name);
  2232. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2233. if(creDefNumbers[nxt.bytes[20]]==-1)
  2234. {
  2235. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2236. }
  2237. }
  2238. if(curDef.bytes[16]==71) //random monster (any level)
  2239. {
  2240. DefInfo nxt = curDef;
  2241. nxt.bytes[16] = 54;
  2242. nxt.bytes[20] = rand()%126;
  2243. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2244. {
  2245. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2246. continue;
  2247. }
  2248. nxt.name = creDefNames[nxt.bytes[20]];
  2249. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2250. nxt.name);
  2251. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2252. {
  2253. nxt.isOnDefList = false;
  2254. }
  2255. else
  2256. {
  2257. nxt.printPriority = pit->priority;
  2258. nxt.isOnDefList = true;
  2259. }
  2260. map.defy.push_back(nxt); // add this def to the vector
  2261. defsToUnpack.push_back(nxt.name);
  2262. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2263. if(creDefNumbers[nxt.bytes[20]]==-1)
  2264. {
  2265. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2266. }
  2267. }
  2268. break;
  2269. } //end of case
  2270. case EDefType::ARTIFACT_DEF:
  2271. {
  2272. if(curDef.bytes[16]==65) //random atrifact (any class)
  2273. {
  2274. DefInfo nxt = curDef;
  2275. nxt.bytes[16] = 5;
  2276. nxt.bytes[20] = rand()%artDefNames.size();
  2277. if(artDefNumbers[nxt.bytes[20]]!=-1)
  2278. {
  2279. CGI->objh->objInstances[j].defNumber = artDefNumbers[nxt.bytes[20]];
  2280. continue;
  2281. }
  2282. nxt.name = artDefNames[nxt.bytes[20]];
  2283. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2284. nxt.name);
  2285. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2286. {
  2287. nxt.isOnDefList = false;
  2288. }
  2289. else
  2290. {
  2291. nxt.printPriority = pit->priority;
  2292. nxt.isOnDefList = true;
  2293. }
  2294. map.defy.push_back(nxt); // add this def to the vector
  2295. defsToUnpack.push_back(nxt.name);
  2296. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2297. if(artDefNumbers[nxt.bytes[20]]==-1)
  2298. {
  2299. artDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2300. }
  2301. }
  2302. if(curDef.bytes[16]==66) //random atrifact (treasure)
  2303. {
  2304. DefInfo nxt = curDef;
  2305. nxt.bytes[16] = 5;
  2306. nxt.bytes[20] = rand()%art1DefNames.size();
  2307. if(art1DefNumbers[nxt.bytes[20]]!=-1)
  2308. {
  2309. CGI->objh->objInstances[j].defNumber = art1DefNumbers[nxt.bytes[20]];
  2310. continue;
  2311. }
  2312. nxt.name = art1DefNames[nxt.bytes[20]];
  2313. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2314. nxt.name);
  2315. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2316. {
  2317. nxt.isOnDefList = false;
  2318. }
  2319. else
  2320. {
  2321. nxt.printPriority = pit->priority;
  2322. nxt.isOnDefList = true;
  2323. }
  2324. map.defy.push_back(nxt); // add this def to the vector
  2325. defsToUnpack.push_back(nxt.name);
  2326. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2327. if(art1DefNumbers[nxt.bytes[20]]==-1)
  2328. {
  2329. art1DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2330. }
  2331. }
  2332. if(curDef.bytes[16]==67) //random atrifact (minor)
  2333. {
  2334. DefInfo nxt = curDef;
  2335. nxt.bytes[16] = 5;
  2336. nxt.bytes[20] = rand()%art2DefNames.size();
  2337. if(art2DefNumbers[nxt.bytes[20]]!=-1)
  2338. {
  2339. CGI->objh->objInstances[j].defNumber = art2DefNumbers[nxt.bytes[20]];
  2340. continue;
  2341. }
  2342. nxt.name = art2DefNames[nxt.bytes[20]];
  2343. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2344. nxt.name);
  2345. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2346. {
  2347. nxt.isOnDefList = false;
  2348. }
  2349. else
  2350. {
  2351. nxt.printPriority = pit->priority;
  2352. nxt.isOnDefList = true;
  2353. }
  2354. map.defy.push_back(nxt); // add this def to the vector
  2355. defsToUnpack.push_back(nxt.name);
  2356. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2357. if(art2DefNumbers[nxt.bytes[20]]==-1)
  2358. {
  2359. art2DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2360. }
  2361. }
  2362. if(curDef.bytes[16]==68) //random atrifact (major)
  2363. {
  2364. DefInfo nxt = curDef;
  2365. nxt.bytes[16] = 5;
  2366. nxt.bytes[20] = rand()%art3DefNames.size();
  2367. if(art3DefNumbers[nxt.bytes[20]]!=-1)
  2368. {
  2369. CGI->objh->objInstances[j].defNumber = art3DefNumbers[nxt.bytes[20]];
  2370. continue;
  2371. }
  2372. nxt.name = art3DefNames[nxt.bytes[20]];
  2373. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2374. nxt.name);
  2375. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2376. {
  2377. nxt.isOnDefList = false;
  2378. }
  2379. else
  2380. {
  2381. nxt.printPriority = pit->priority;
  2382. nxt.isOnDefList = true;
  2383. }
  2384. map.defy.push_back(nxt); // add this def to the vector
  2385. defsToUnpack.push_back(nxt.name);
  2386. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2387. if(art3DefNumbers[nxt.bytes[20]]==-1)
  2388. {
  2389. art3DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2390. }
  2391. }
  2392. if(curDef.bytes[16]==69) //random atrifact (relic)
  2393. {
  2394. DefInfo nxt = curDef;
  2395. nxt.bytes[16] = 5;
  2396. nxt.bytes[20] = rand()%art4DefNames.size();
  2397. if(art4DefNumbers[nxt.bytes[20]]!=-1)
  2398. {
  2399. CGI->objh->objInstances[j].defNumber = art4DefNumbers[nxt.bytes[20]];
  2400. continue;
  2401. }
  2402. nxt.name = art4DefNames[nxt.bytes[20]];
  2403. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2404. nxt.name);
  2405. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2406. {
  2407. nxt.isOnDefList = false;
  2408. }
  2409. else
  2410. {
  2411. nxt.printPriority = pit->priority;
  2412. nxt.isOnDefList = true;
  2413. }
  2414. map.defy.push_back(nxt); // add this def to the vector
  2415. defsToUnpack.push_back(nxt.name);
  2416. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2417. if(art4DefNumbers[nxt.bytes[20]]==-1)
  2418. {
  2419. art4DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2420. }
  2421. }
  2422. break;
  2423. }
  2424. } //end of main switch
  2425. } //end of main loop
  2426. }