CAmbarCendamo.cpp 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775
  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.pos.x = bufor[i++];
  463. nobj.pos.y = bufor[i++];
  464. nobj.pos.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. int typeBuf = readNormalNr(i, 1); ++i;
  560. if(typeBuf==0xff)
  561. spec->type = NULL;
  562. else
  563. spec->type = CGameInfo::mainObj->heroh->heroes[typeBuf];
  564. bool isName = bufor[i]; ++i; //true if hero has nonstandard name
  565. if(isName)
  566. {
  567. int length = readNormalNr(i, 4); i+=4;
  568. for(int gg=0; gg<length; ++gg)
  569. {
  570. spec->name+=bufor[i]; ++i;
  571. }
  572. }
  573. else
  574. spec->name = std::string("");
  575. bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0
  576. if(isExp)
  577. {
  578. spec->experience = readNormalNr(i); i+=4;
  579. }
  580. else spec->experience = 0;
  581. bool portrait=bufor[i]; ++i;
  582. if (portrait)
  583. i++; //TODO read portrait nr, save, open
  584. bool nonstandardAbilities = bufor[i]; ++i; //true if hero has specified abilities
  585. if(nonstandardAbilities)
  586. {
  587. int howMany = readNormalNr(i); i+=4;
  588. for(int yy=0; yy<howMany; ++yy)
  589. {
  590. spec->abilities.push_back(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)]); ++i;
  591. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  592. }
  593. }
  594. bool standGarrison = bufor[i]; ++i; //true if hero has nonstandard garrison
  595. spec->standardGarrison = standGarrison;
  596. if(standGarrison)
  597. {
  598. spec->garrison = readCreatureSet(i); i+=28; //4 bytes per slot
  599. }
  600. bool form = bufor[i]; ++i; //formation
  601. spec->garrison.formation = form;
  602. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  603. if(artSet)
  604. {
  605. //head art //1
  606. int id = readNormalNr(i, 2); i+=2;
  607. if(id!=0xffff)
  608. spec->artHead = &(CGameInfo::mainObj->arth->artifacts[id]);
  609. else
  610. spec->artHead = NULL;
  611. //shoulders art //2
  612. id = readNormalNr(i, 2); i+=2;
  613. if(id!=0xffff)
  614. spec->artShoulders = &(CGameInfo::mainObj->arth->artifacts[id]);
  615. else
  616. spec->artShoulders = NULL;
  617. //neck art //3
  618. id = readNormalNr(i, 2); i+=2;
  619. if(id!=0xffff)
  620. spec->artNeck = &(CGameInfo::mainObj->arth->artifacts[id]);
  621. else
  622. spec->artNeck = NULL;
  623. //right hand art //4
  624. id = readNormalNr(i, 2); i+=2;
  625. if(id!=0xffff)
  626. spec->artRhand = &(CGameInfo::mainObj->arth->artifacts[id]);
  627. else
  628. spec->artRhand = NULL;
  629. //left hand art //5
  630. id = readNormalNr(i, 2); i+=2;
  631. if(id!=0xffff)
  632. spec->artLHand = &(CGameInfo::mainObj->arth->artifacts[id]);
  633. else
  634. spec->artLHand = NULL;
  635. //torso art //6
  636. id = readNormalNr(i, 2); i+=2;
  637. if(id!=0xffff)
  638. spec->artTorso = &(CGameInfo::mainObj->arth->artifacts[id]);
  639. else
  640. spec->artTorso = NULL;
  641. //right hand ring //7
  642. id = readNormalNr(i, 2); i+=2;
  643. if(id!=0xffff)
  644. spec->artRRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  645. else
  646. spec->artRRing = NULL;
  647. //left hand ring //8
  648. id = readNormalNr(i, 2); i+=2;
  649. if(id!=0xffff)
  650. spec->artLRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  651. else
  652. spec->artLRing = NULL;
  653. //feet art //9
  654. id = readNormalNr(i, 2); i+=2;
  655. if(id!=0xffff)
  656. spec->artFeet = &(CGameInfo::mainObj->arth->artifacts[id]);
  657. else
  658. spec->artFeet = NULL;
  659. //misc1 art //10
  660. id = readNormalNr(i, 2); i+=2;
  661. if(id!=0xffff)
  662. spec->artMisc1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  663. else
  664. spec->artMisc1 = NULL;
  665. //misc2 art //11
  666. id = readNormalNr(i, 2); i+=2;
  667. if(id!=0xffff)
  668. spec->artMisc2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  669. else
  670. spec->artMisc2 = NULL;
  671. //misc3 art //12
  672. id = readNormalNr(i, 2); i+=2;
  673. if(id!=0xffff)
  674. spec->artMisc3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  675. else
  676. spec->artMisc3 = NULL;
  677. //misc4 art //13
  678. id = readNormalNr(i, 2); i+=2;
  679. if(id!=0xffff)
  680. spec->artMisc4 = &(CGameInfo::mainObj->arth->artifacts[id]);
  681. else
  682. spec->artMisc4 = NULL;
  683. //machine1 art //14
  684. id = readNormalNr(i, 2); i+=2;
  685. if(id!=0xffff)
  686. spec->artMach1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  687. else
  688. spec->artMach1 = NULL;
  689. //machine2 art //15
  690. id = readNormalNr(i, 2); i+=2;
  691. if(id!=0xffff)
  692. spec->artMach2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  693. else
  694. spec->artMach2 = NULL;
  695. //machine3 art //16
  696. id = readNormalNr(i, 2); i+=2;
  697. if(id!=0xffff)
  698. spec->artMach3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  699. else
  700. spec->artMach3 = NULL;
  701. //misc5 art //17
  702. id = readNormalNr(i, 2); i+=2;
  703. if(id!=0xffff)
  704. spec->artMisc5 = &(CGameInfo::mainObj->arth->artifacts[id]);
  705. else
  706. spec->artMisc5 = NULL;
  707. //spellbook
  708. id = readNormalNr(i, 2); i+=2;
  709. if(id!=0xffff)
  710. spec->artSpellBook = &(CGameInfo::mainObj->arth->artifacts[id]);
  711. else
  712. spec->artSpellBook = NULL;
  713. //19 //???what is that? gap in file or what?
  714. i+=2;
  715. //bag artifacts //20
  716. int amount = readNormalNr(i, 2); i+=2; //number of artifacts in hero's bag
  717. if(amount>0)
  718. {
  719. for(int ss=0; ss<amount; ++ss)
  720. {
  721. id = readNormalNr(i, 2); i+=2;
  722. if(id!=0xffff)
  723. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[id]));
  724. else
  725. spec->artifacts.push_back(NULL);
  726. }
  727. }
  728. } //artifacts
  729. spec->guardRange = readNormalNr(i, 1); ++i;
  730. if(spec->guardRange == 0xff)
  731. spec->isGuarding = false;
  732. else
  733. spec->isGuarding = true;
  734. bool hasBiography = bufor[i]; ++i; //true if hero has nonstandard (mapmaker defined) biography
  735. if(hasBiography)
  736. {
  737. int length = readNormalNr(i); i+=4;
  738. int iStart = i;
  739. i+=length;
  740. for(int bb=0; bb<length; ++bb)
  741. {
  742. spec->biography+=bufor[iStart+bb];
  743. }
  744. }
  745. spec->sex = !(bufor[i]); ++i;
  746. //spells
  747. bool areSpells = bufor[i]; ++i;
  748. if(areSpells) //TODO: sprawdziæ //seems to be ok - tow
  749. {
  750. int ist = i;
  751. for(i; i<ist+9; ++i)
  752. {
  753. unsigned char c = bufor[i];
  754. for(int yy=0; yy<8; ++yy)
  755. {
  756. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  757. {
  758. if(c == (c|((unsigned char)intPow(2, yy))))
  759. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  760. }
  761. }
  762. }
  763. }
  764. //spells loaded
  765. spec->defaultMianStats = bufor[i]; ++i;
  766. if(spec->defaultMianStats)
  767. {
  768. spec->attack = bufor[i]; ++i;
  769. spec->defence = bufor[i]; ++i;
  770. spec->power = bufor[i]; ++i;
  771. spec->knowledge = bufor[i]; ++i;
  772. }
  773. i+=16;
  774. nobj.info = spec;
  775. break;
  776. }
  777. case CREATURES_DEF:
  778. {
  779. CCreatureObjInfo * spec = new CCreatureObjInfo;
  780. spec->bytes[0] = bufor[i]; ++i;
  781. spec->bytes[1] = bufor[i]; ++i;
  782. spec->bytes[2] = bufor[i]; ++i;
  783. spec->bytes[3] = bufor[i]; ++i;
  784. spec->number = readNormalNr(i, 2); i+=2;
  785. spec->character = bufor[i]; ++i;
  786. bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
  787. if(isMesTre)
  788. {
  789. int messLength = readNormalNr(i); i+=4;
  790. if(messLength>0)
  791. {
  792. for(int tt=0; tt<messLength; ++tt)
  793. {
  794. spec->message += bufor[i]; ++i;
  795. }
  796. }
  797. spec->wood = readNormalNr(i); i+=4;
  798. spec->mercury = readNormalNr(i); i+=4;
  799. spec->ore = readNormalNr(i); i+=4;
  800. spec->sulfur = readNormalNr(i); i+=4;
  801. spec->crytal = readNormalNr(i); i+=4;
  802. spec->gems = readNormalNr(i); i+=4;
  803. spec->gold = readNormalNr(i); i+=4;
  804. int artID = readNormalNr(i, 2); i+=2;
  805. if(artID!=0xffff)
  806. spec->gainedArtifact = &(CGameInfo::mainObj->arth->artifacts[artID]);
  807. else
  808. spec->gainedArtifact = NULL;
  809. }
  810. spec->neverFlees = bufor[i]; ++i;
  811. spec->notGrowingTeam = bufor[i]; ++i;
  812. i+=2;
  813. nobj.info = spec;
  814. break;
  815. }
  816. case EDefType::SIGN_DEF:
  817. {
  818. CSignObjInfo * spec = new CSignObjInfo;
  819. int length = readNormalNr(i); i+=4;
  820. for(int rr=0; rr<length; ++rr)
  821. {
  822. spec->message += bufor[i]; ++i;
  823. }
  824. i+=4;
  825. nobj.info = spec;
  826. break;
  827. }
  828. case EDefType::SEERHUT_DEF:
  829. {
  830. CSeerHutObjInfo * spec = new CSeerHutObjInfo;
  831. spec->missionType = bufor[i]; ++i;
  832. switch(spec->missionType)
  833. {
  834. case 1:
  835. {
  836. spec->m1level = readNormalNr(i); i+=4;
  837. int limit = readNormalNr(i); i+=4;
  838. if(limit == ((int)0xffffffff))
  839. {
  840. spec->isDayLimit = false;
  841. spec->lastDay = -1;
  842. }
  843. else
  844. {
  845. spec->isDayLimit = true;
  846. spec->lastDay = limit;
  847. }
  848. break;
  849. }
  850. case 2:
  851. {
  852. spec->m2attack = bufor[i]; ++i;
  853. spec->m2defence = bufor[i]; ++i;
  854. spec->m2power = bufor[i]; ++i;
  855. spec->m2knowledge = bufor[i]; ++i;
  856. int limit = readNormalNr(i); i+=4;
  857. if(limit == ((int)0xffffffff))
  858. {
  859. spec->isDayLimit = false;
  860. spec->lastDay = -1;
  861. }
  862. else
  863. {
  864. spec->isDayLimit = true;
  865. spec->lastDay = limit;
  866. }
  867. break;
  868. }
  869. case 3:
  870. {
  871. spec->m3bytes[0] = bufor[i]; ++i;
  872. spec->m3bytes[1] = bufor[i]; ++i;
  873. spec->m3bytes[2] = bufor[i]; ++i;
  874. spec->m3bytes[3] = bufor[i]; ++i;
  875. int limit = readNormalNr(i); i+=4;
  876. if(limit == ((int)0xffffffff))
  877. {
  878. spec->isDayLimit = false;
  879. spec->lastDay = -1;
  880. }
  881. else
  882. {
  883. spec->isDayLimit = true;
  884. spec->lastDay = limit;
  885. }
  886. break;
  887. }
  888. case 4:
  889. {
  890. spec->m4bytes[0] = bufor[i]; ++i;
  891. spec->m4bytes[1] = bufor[i]; ++i;
  892. spec->m4bytes[2] = bufor[i]; ++i;
  893. spec->m4bytes[3] = bufor[i]; ++i;
  894. int limit = readNormalNr(i); i+=4;
  895. if(limit == ((int)0xffffffff))
  896. {
  897. spec->isDayLimit = false;
  898. spec->lastDay = -1;
  899. }
  900. else
  901. {
  902. spec->isDayLimit = true;
  903. spec->lastDay = limit;
  904. }
  905. break;
  906. }
  907. case 5:
  908. {
  909. int artNumber = bufor[i]; ++i;
  910. for(int yy=0; yy<artNumber; ++yy)
  911. {
  912. int artid = readNormalNr(i, 2); i+=2;
  913. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  914. }
  915. int limit = readNormalNr(i); i+=4;
  916. if(limit == ((int)0xffffffff))
  917. {
  918. spec->isDayLimit = false;
  919. spec->lastDay = -1;
  920. }
  921. else
  922. {
  923. spec->isDayLimit = true;
  924. spec->lastDay = limit;
  925. }
  926. break;
  927. }
  928. case 6:
  929. {
  930. int typeNumber = bufor[i]; ++i;
  931. for(int hh=0; hh<typeNumber; ++hh)
  932. {
  933. int creType = readNormalNr(i, 2); i+=2;
  934. int creNumb = readNormalNr(i, 2); i+=2;
  935. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  936. spec->m6number.push_back(creNumb);
  937. }
  938. int limit = readNormalNr(i); i+=4;
  939. if(limit == ((int)0xffffffff))
  940. {
  941. spec->isDayLimit = false;
  942. spec->lastDay = -1;
  943. }
  944. else
  945. {
  946. spec->isDayLimit = true;
  947. spec->lastDay = limit;
  948. }
  949. break;
  950. }
  951. case 7:
  952. {
  953. spec->m7wood = readNormalNr(i); i+=4;
  954. spec->m7mercury = readNormalNr(i); i+=4;
  955. spec->m7ore = readNormalNr(i); i+=4;
  956. spec->m7sulfur = readNormalNr(i); i+=4;
  957. spec->m7crystal = readNormalNr(i); i+=4;
  958. spec->m7gems = readNormalNr(i); i+=4;
  959. spec->m7gold = readNormalNr(i); i+=4;
  960. int limit = readNormalNr(i); i+=4;
  961. if(limit == ((int)0xffffffff))
  962. {
  963. spec->isDayLimit = false;
  964. spec->lastDay = -1;
  965. }
  966. else
  967. {
  968. spec->isDayLimit = true;
  969. spec->lastDay = limit;
  970. }
  971. break;
  972. }
  973. case 8:
  974. {
  975. int heroType = bufor[i]; ++i;
  976. spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
  977. int limit = readNormalNr(i); i+=4;
  978. if(limit == ((int)0xffffffff))
  979. {
  980. spec->isDayLimit = false;
  981. spec->lastDay = -1;
  982. }
  983. else
  984. {
  985. spec->isDayLimit = true;
  986. spec->lastDay = limit;
  987. }
  988. break;
  989. }
  990. case 9:
  991. {
  992. spec->m9player = bufor[i]; ++i;
  993. int limit = readNormalNr(i); i+=4;
  994. if(limit == ((int)0xffffffff))
  995. {
  996. spec->isDayLimit = false;
  997. spec->lastDay = -1;
  998. }
  999. else
  1000. {
  1001. spec->isDayLimit = true;
  1002. spec->lastDay = limit;
  1003. }
  1004. break;
  1005. }
  1006. }//internal switch end (seer huts)
  1007. int len1 = readNormalNr(i); i+=4;
  1008. for(int ee=0; ee<len1; ++ee)
  1009. {
  1010. spec->firstVisitText += bufor[i]; ++i;
  1011. }
  1012. int len2 = readNormalNr(i); i+=4;
  1013. for(int ee=0; ee<len2; ++ee)
  1014. {
  1015. spec->nextVisitText += bufor[i]; ++i;
  1016. }
  1017. int len3 = readNormalNr(i); i+=4;
  1018. for(int ee=0; ee<len3; ++ee)
  1019. {
  1020. spec->completedText += bufor[i]; ++i;
  1021. }
  1022. unsigned char rewardType = bufor[i]; ++i;
  1023. spec->rewardType = rewardType;
  1024. switch(rewardType)
  1025. {
  1026. case 1:
  1027. {
  1028. spec->r1exp = readNormalNr(i); i+=4;
  1029. break;
  1030. }
  1031. case 2:
  1032. {
  1033. spec->r2mana = readNormalNr(i); i+=4;
  1034. break;
  1035. }
  1036. case 3:
  1037. {
  1038. spec->r3morale = bufor[i]; ++i;
  1039. break;
  1040. }
  1041. case 4:
  1042. {
  1043. spec->r4luck = bufor[i]; ++i;
  1044. break;
  1045. }
  1046. case 5:
  1047. {
  1048. spec->r5type = bufor[i]; ++i;
  1049. spec->r5amount = readNormalNr(i, 3); i+=3;
  1050. i+=1;
  1051. break;
  1052. }
  1053. case 6:
  1054. {
  1055. spec->r6type = bufor[i]; ++i;
  1056. spec->r6amount = bufor[i]; ++i;
  1057. break;
  1058. }
  1059. case 7:
  1060. {
  1061. int abid = bufor[i]; ++i;
  1062. spec->r7ability = CGameInfo::mainObj->abilh->abilities[abid];
  1063. spec->r7level = bufor[i]; ++i;
  1064. break;
  1065. }
  1066. case 8:
  1067. {
  1068. int artid = readNormalNr(i, 2); i+=2;
  1069. spec->r8art = &(CGameInfo::mainObj->arth->artifacts[artid]);
  1070. break;
  1071. }
  1072. case 9:
  1073. {
  1074. int spellid = bufor[i]; ++i;
  1075. spec->r9spell = &(CGameInfo::mainObj->spellh->spells[spellid]);
  1076. break;
  1077. }
  1078. case 10:
  1079. {
  1080. int creid = readNormalNr(i, 2); i+=2;
  1081. spec->r10creature = &(CGameInfo::mainObj->creh->creatures[creid]);
  1082. spec->r10amount = readNormalNr(i, 2); i+=2;
  1083. break;
  1084. }
  1085. }// end of internal switch
  1086. i+=2;
  1087. nobj.info = spec;
  1088. break;
  1089. }
  1090. case EDefType::WITCHHUT_DEF:
  1091. {
  1092. CWitchHutObjInfo * spec = new CWitchHutObjInfo;
  1093. ist=i; //starting i for loop
  1094. for(i; i<ist+4; ++i)
  1095. {
  1096. unsigned char c = bufor[i];
  1097. for(int yy=0; yy<8; ++yy)
  1098. {
  1099. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  1100. {
  1101. if(c == (c|((unsigned char)intPow(2, yy))))
  1102. spec->allowedAbilities.push_back(CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]);
  1103. }
  1104. }
  1105. }
  1106. nobj.info = spec;
  1107. break;
  1108. }
  1109. case EDefType::SCHOLAR_DEF:
  1110. {
  1111. CScholarObjInfo * spec = new CScholarObjInfo;
  1112. spec->bonusType = bufor[i]; ++i;
  1113. switch(spec->bonusType)
  1114. {
  1115. case 0xff:
  1116. ++i;
  1117. break;
  1118. case 0:
  1119. spec->r0type = bufor[i]; ++i;
  1120. break;
  1121. case 1:
  1122. spec->r1 = CGameInfo::mainObj->abilh->abilities[bufor[i]]; ++i;
  1123. break;
  1124. case 2:
  1125. spec->r2 = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1126. break;
  1127. }
  1128. i+=6;
  1129. nobj.info = spec;
  1130. break;
  1131. }
  1132. case EDefType::GARRISON_DEF:
  1133. {
  1134. CGarrisonObjInfo * spec = new CGarrisonObjInfo;
  1135. spec->player = bufor[i]; ++i;
  1136. i+=3;
  1137. spec->units = readCreatureSet(i); i+=28;
  1138. spec->movableUnits = bufor[i]; ++i;
  1139. i+=8;
  1140. nobj.info = spec;
  1141. break;
  1142. }
  1143. case EDefType::ARTIFACT_DEF:
  1144. {
  1145. CArtifactObjInfo * spec = new CArtifactObjInfo;
  1146. bool areSettings = bufor[i]; ++i;
  1147. if(areSettings)
  1148. {
  1149. int messLength = readNormalNr(i, 4); i+=4;
  1150. for(int hh=0; hh<messLength; ++hh)
  1151. {
  1152. spec->message += bufor[i]; ++i;
  1153. }
  1154. bool areGuards = bufor[i]; ++i;
  1155. if(areGuards)
  1156. {
  1157. spec->areGuards = true;
  1158. spec->guards = readCreatureSet(i); i+=28;
  1159. }
  1160. else
  1161. spec->areGuards = false;
  1162. i+=4;
  1163. }
  1164. nobj.info = spec;
  1165. break;
  1166. }
  1167. case EDefType::RESOURCE_DEF:
  1168. {
  1169. CResourceObjInfo * spec = new CResourceObjInfo;
  1170. bool isMessGuard = bufor[i]; ++i;
  1171. if(isMessGuard)
  1172. {
  1173. int messLength = readNormalNr(i); i+=4;
  1174. for(int mm=0; mm<messLength; ++mm)
  1175. {
  1176. spec->message+=bufor[i]; ++i;
  1177. }
  1178. spec->areGuards = bufor[i]; ++i;
  1179. if(spec->areGuards)
  1180. {
  1181. spec->guards = readCreatureSet(i); i+=28;
  1182. }
  1183. i+=4;
  1184. }
  1185. else
  1186. {
  1187. spec->areGuards = false;
  1188. }
  1189. spec->amount = readNormalNr(i); i+=4;
  1190. i+=4;
  1191. nobj.info = spec;
  1192. break;
  1193. }
  1194. case EDefType::TOWN_DEF:
  1195. {
  1196. CCastleObjInfo * spec = new CCastleObjInfo;
  1197. spec->bytes[0] = bufor[i]; ++i;
  1198. spec->bytes[1] = bufor[i]; ++i;
  1199. spec->bytes[2] = bufor[i]; ++i;
  1200. spec->bytes[3] = bufor[i]; ++i;
  1201. spec->player = bufor[i]; ++i;
  1202. bool hasName = bufor[i]; ++i;
  1203. if(hasName)
  1204. {
  1205. int len = readNormalNr(i); i+=4;
  1206. for(int gg=0; gg<len; ++gg)
  1207. {
  1208. spec->name += bufor[i]; ++i;
  1209. }
  1210. }
  1211. bool stGarr = bufor[i]; ++i; //true if garrison isn't empty
  1212. if(stGarr)
  1213. {
  1214. spec->garrison = readCreatureSet(i); i+=28;
  1215. }
  1216. spec->garrison.formation = bufor[i]; ++i;
  1217. spec->unusualBuildins = bufor[i]; ++i;
  1218. if(spec->unusualBuildins)
  1219. {
  1220. for(int ff=0; ff<12; ++ff)
  1221. {
  1222. spec->buildingSettings[ff] = bufor[i]; ++i;
  1223. }
  1224. }
  1225. else
  1226. {
  1227. spec->hasFort = bufor[i]; ++i;
  1228. }
  1229. int ist = i;
  1230. for(i; i<ist+9; ++i)
  1231. {
  1232. unsigned char c = bufor[i];
  1233. for(int yy=0; yy<8; ++yy)
  1234. {
  1235. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  1236. {
  1237. if(c == (c|((unsigned char)intPow(2, yy))))
  1238. spec->obligatorySpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  1239. }
  1240. }
  1241. }
  1242. ist = i;
  1243. for(i; i<ist+9; ++i)
  1244. {
  1245. unsigned char c = bufor[i];
  1246. for(int yy=0; yy<8; ++yy)
  1247. {
  1248. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  1249. {
  1250. if(c != (c|((unsigned char)intPow(2, yy))))
  1251. spec->possibleSpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  1252. }
  1253. }
  1254. }
  1255. /////// reading castle events //////////////////////////////////
  1256. int numberOfEvent = readNormalNr(i); i+=4;
  1257. for(int gh = 0; gh<numberOfEvent; ++gh)
  1258. {
  1259. CCastleEvent nce;
  1260. int nameLen = readNormalNr(i); i+=4;
  1261. for(int ll=0; ll<nameLen; ++ll)
  1262. {
  1263. nce.name += bufor[i]; ++i;
  1264. }
  1265. int messLen = readNormalNr(i); i+=4;
  1266. for(int ll=0; ll<messLen; ++ll)
  1267. {
  1268. nce.message += bufor[i]; ++i;
  1269. }
  1270. nce.wood = readNormalNr(i); i+=4;
  1271. nce.mercury = readNormalNr(i); i+=4;
  1272. nce.ore = readNormalNr(i); i+=4;
  1273. nce.sulfur = readNormalNr(i); i+=4;
  1274. nce.crystal = readNormalNr(i); i+=4;
  1275. nce.gems = readNormalNr(i); i+=4;
  1276. nce.gold = readNormalNr(i); i+=4;
  1277. nce.players = bufor[i]; ++i;
  1278. nce.forHuman = bufor[i]; ++i;
  1279. nce.forComputer = bufor[i]; ++i;
  1280. nce.firstShow = readNormalNr(i, 2); i+=2;
  1281. nce.forEvery = bufor[i]; ++i;
  1282. i+=17;
  1283. for(int kk=0; kk<6; ++kk)
  1284. {
  1285. nce.bytes[kk] = bufor[i]; ++i;
  1286. }
  1287. for(int vv=0; vv<7; ++vv)
  1288. {
  1289. nce.gen[vv] = readNormalNr(i, 2); i+=2;
  1290. }
  1291. i+=4;
  1292. spec->events.push_back(nce);
  1293. }
  1294. /////// castle events have been read ///////////////////////////
  1295. spec->alignment = bufor[i]; ++i;
  1296. i+=3;
  1297. nobj.info = spec;
  1298. break;
  1299. }
  1300. case EDefType::PLAYERONLY_DEF:
  1301. {
  1302. CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
  1303. spec->player = bufor[i]; ++i;
  1304. i+=3;
  1305. nobj.info = spec;
  1306. break;
  1307. }
  1308. case EDefType::SHRINE_DEF:
  1309. {
  1310. CShrineObjInfo * spec = new CShrineObjInfo;
  1311. spec->spell = bufor[i]; i+=4;
  1312. nobj.info = spec;
  1313. break;
  1314. }
  1315. case EDefType::SPELLSCROLL_DEF:
  1316. {
  1317. CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
  1318. bool messg = bufor[i]; ++i;
  1319. if(messg)
  1320. {
  1321. int mLength = readNormalNr(i); i+=4;
  1322. for(int vv=0; vv<mLength; ++vv)
  1323. {
  1324. spec->message += bufor[i]; ++i;
  1325. }
  1326. spec->areGuarders = bufor[i]; ++i;
  1327. if(spec->areGuarders)
  1328. {
  1329. spec->guarders = readCreatureSet(i); i+=28;
  1330. }
  1331. i+=4;
  1332. }
  1333. spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1334. i+=3;
  1335. nobj.info = spec;
  1336. break;
  1337. }
  1338. case EDefType::PANDORA_DEF:
  1339. {
  1340. CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
  1341. bool messg = bufor[i]; ++i;
  1342. if(messg)
  1343. {
  1344. int mLength = readNormalNr(i); i+=4;
  1345. for(int vv=0; vv<mLength; ++vv)
  1346. {
  1347. spec->message += bufor[i]; ++i;
  1348. }
  1349. spec->areGuarders = bufor[i]; ++i;
  1350. if(spec->areGuarders)
  1351. {
  1352. spec->guarders = readCreatureSet(i); i+=28;
  1353. }
  1354. i+=4;
  1355. }
  1356. ////// copied form event handling (seems to be similar)
  1357. spec->gainedExp = readNormalNr(i, 4); i+=4;
  1358. spec->manaDiff = readNormalNr(i, 4); i+=4;
  1359. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  1360. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  1361. spec->wood = readNormalNr(i); i+=4;
  1362. spec->mercury = readNormalNr(i); i+=4;
  1363. spec->ore = readNormalNr(i); i+=4;
  1364. spec->sulfur = readNormalNr(i); i+=4;
  1365. spec->crystal = readNormalNr(i); i+=4;
  1366. spec->gems = readNormalNr(i); i+=4;
  1367. spec->gold = readNormalNr(i); i+=4;
  1368. spec->attack = readNormalNr(i, 1); ++i;
  1369. spec->defence = readNormalNr(i, 1); ++i;
  1370. spec->power = readNormalNr(i, 1); ++i;
  1371. spec->knowledge = readNormalNr(i, 1); ++i;
  1372. int gabn; //number of gained abilities
  1373. gabn = readNormalNr(i, 1); ++i;
  1374. for(int oo = 0; oo<gabn; ++oo)
  1375. {
  1376. spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
  1377. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  1378. }
  1379. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  1380. for(int oo = 0; oo<gart; ++oo)
  1381. {
  1382. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  1383. }
  1384. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  1385. for(int oo = 0; oo<gspel; ++oo)
  1386. {
  1387. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  1388. }
  1389. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  1390. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  1391. i+=8;
  1392. nobj.info = spec;
  1393. ///////end of copied fragment
  1394. break;
  1395. }
  1396. case EDefType::GRAIL_DEF:
  1397. {
  1398. CGrailObjInfo * spec = new CGrailObjInfo;
  1399. spec->radius = readNormalNr(i); i+=4;
  1400. nobj.info = spec;
  1401. break;
  1402. }
  1403. case EDefType::CREGEN_DEF:
  1404. {
  1405. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1406. spec->player = bufor[i]; ++i;
  1407. i+=3;
  1408. for(int ggg=0; ggg<4; ++ggg)
  1409. {
  1410. spec->bytes[ggg] = bufor[i]; ++i;
  1411. }
  1412. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1413. {
  1414. spec->asCastle = false;
  1415. spec->castles[0] = bufor[i]; ++i;
  1416. spec->castles[1] = bufor[i]; ++i;
  1417. }
  1418. else
  1419. {
  1420. spec->asCastle = true;
  1421. }
  1422. nobj.info = spec;
  1423. break;
  1424. }
  1425. case EDefType::CREGEN2_DEF:
  1426. {
  1427. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1428. spec->player = bufor[i]; ++i;
  1429. i+=3;
  1430. for(int ggg=0; ggg<4; ++ggg)
  1431. {
  1432. spec->bytes[ggg] = bufor[i]; ++i;
  1433. }
  1434. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1435. {
  1436. spec->asCastle = false;
  1437. spec->castles[0] = bufor[i]; ++i;
  1438. spec->castles[1] = bufor[i]; ++i;
  1439. }
  1440. else
  1441. {
  1442. spec->asCastle = true;
  1443. }
  1444. spec->minLevel = bufor[i]; ++i;
  1445. spec->maxLevel = bufor[i]; ++i;
  1446. nobj.info = spec;
  1447. break;
  1448. }
  1449. case EDefType::CREGEN3_DEF:
  1450. {
  1451. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1452. spec->player = bufor[i]; ++i;
  1453. i+=3;
  1454. spec->minLevel = bufor[i]; ++i;
  1455. spec->maxLevel = bufor[i]; ++i;
  1456. nobj.info = spec;
  1457. break;
  1458. }
  1459. case EDefType::BORDERGUARD_DEF:
  1460. {
  1461. CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
  1462. spec->missionType = bufor[i]; ++i;
  1463. switch(spec->missionType)
  1464. {
  1465. case 1:
  1466. {
  1467. spec->m1level = readNormalNr(i); i+=4;
  1468. int limit = readNormalNr(i); i+=4;
  1469. if(limit == ((int)0xffffffff))
  1470. {
  1471. spec->isDayLimit = false;
  1472. spec->lastDay = -1;
  1473. }
  1474. else
  1475. {
  1476. spec->isDayLimit = true;
  1477. spec->lastDay = limit;
  1478. }
  1479. break;
  1480. }
  1481. case 2:
  1482. {
  1483. spec->m2attack = bufor[i]; ++i;
  1484. spec->m2defence = bufor[i]; ++i;
  1485. spec->m2power = bufor[i]; ++i;
  1486. spec->m2knowledge = bufor[i]; ++i;
  1487. int limit = readNormalNr(i); i+=4;
  1488. if(limit == ((int)0xffffffff))
  1489. {
  1490. spec->isDayLimit = false;
  1491. spec->lastDay = -1;
  1492. }
  1493. else
  1494. {
  1495. spec->isDayLimit = true;
  1496. spec->lastDay = limit;
  1497. }
  1498. break;
  1499. }
  1500. case 3:
  1501. {
  1502. spec->m3bytes[0] = bufor[i]; ++i;
  1503. spec->m3bytes[1] = bufor[i]; ++i;
  1504. spec->m3bytes[2] = bufor[i]; ++i;
  1505. spec->m3bytes[3] = bufor[i]; ++i;
  1506. int limit = readNormalNr(i); i+=4;
  1507. if(limit == ((int)0xffffffff))
  1508. {
  1509. spec->isDayLimit = false;
  1510. spec->lastDay = -1;
  1511. }
  1512. else
  1513. {
  1514. spec->isDayLimit = true;
  1515. spec->lastDay = limit;
  1516. }
  1517. break;
  1518. }
  1519. case 4:
  1520. {
  1521. spec->m4bytes[0] = bufor[i]; ++i;
  1522. spec->m4bytes[1] = bufor[i]; ++i;
  1523. spec->m4bytes[2] = bufor[i]; ++i;
  1524. spec->m4bytes[3] = bufor[i]; ++i;
  1525. int limit = readNormalNr(i); i+=4;
  1526. if(limit == ((int)0xffffffff))
  1527. {
  1528. spec->isDayLimit = false;
  1529. spec->lastDay = -1;
  1530. }
  1531. else
  1532. {
  1533. spec->isDayLimit = true;
  1534. spec->lastDay = limit;
  1535. }
  1536. break;
  1537. }
  1538. case 5:
  1539. {
  1540. int artNumber = bufor[i]; ++i;
  1541. for(int yy=0; yy<artNumber; ++yy)
  1542. {
  1543. int artid = readNormalNr(i, 2); i+=2;
  1544. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  1545. }
  1546. int limit = readNormalNr(i); i+=4;
  1547. if(limit == ((int)0xffffffff))
  1548. {
  1549. spec->isDayLimit = false;
  1550. spec->lastDay = -1;
  1551. }
  1552. else
  1553. {
  1554. spec->isDayLimit = true;
  1555. spec->lastDay = limit;
  1556. }
  1557. break;
  1558. }
  1559. case 6:
  1560. {
  1561. int typeNumber = bufor[i]; ++i;
  1562. for(int hh=0; hh<typeNumber; ++hh)
  1563. {
  1564. int creType = readNormalNr(i, 2); i+=2;
  1565. int creNumb = readNormalNr(i, 2); i+=2;
  1566. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  1567. spec->m6number.push_back(creNumb);
  1568. }
  1569. int limit = readNormalNr(i); i+=4;
  1570. if(limit == ((int)0xffffffff))
  1571. {
  1572. spec->isDayLimit = false;
  1573. spec->lastDay = -1;
  1574. }
  1575. else
  1576. {
  1577. spec->isDayLimit = true;
  1578. spec->lastDay = limit;
  1579. }
  1580. break;
  1581. }
  1582. case 7:
  1583. {
  1584. spec->m7wood = readNormalNr(i); i+=4;
  1585. spec->m7mercury = readNormalNr(i); i+=4;
  1586. spec->m7ore = readNormalNr(i); i+=4;
  1587. spec->m7sulfur = readNormalNr(i); i+=4;
  1588. spec->m7crystal = readNormalNr(i); i+=4;
  1589. spec->m7gems = readNormalNr(i); i+=4;
  1590. spec->m7gold = readNormalNr(i); i+=4;
  1591. int limit = readNormalNr(i); i+=4;
  1592. if(limit == ((int)0xffffffff))
  1593. {
  1594. spec->isDayLimit = false;
  1595. spec->lastDay = -1;
  1596. }
  1597. else
  1598. {
  1599. spec->isDayLimit = true;
  1600. spec->lastDay = limit;
  1601. }
  1602. break;
  1603. }
  1604. case 8:
  1605. {
  1606. int heroType = bufor[i]; ++i;
  1607. spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
  1608. int limit = readNormalNr(i); i+=4;
  1609. if(limit == ((int)0xffffffff))
  1610. {
  1611. spec->isDayLimit = false;
  1612. spec->lastDay = -1;
  1613. }
  1614. else
  1615. {
  1616. spec->isDayLimit = true;
  1617. spec->lastDay = limit;
  1618. }
  1619. break;
  1620. }
  1621. case 9:
  1622. {
  1623. spec->m9player = bufor[i]; ++i;
  1624. int limit = readNormalNr(i); i+=4;
  1625. if(limit == ((int)0xffffffff))
  1626. {
  1627. spec->isDayLimit = false;
  1628. spec->lastDay = -1;
  1629. }
  1630. else
  1631. {
  1632. spec->isDayLimit = true;
  1633. spec->lastDay = limit;
  1634. }
  1635. break;
  1636. }
  1637. }//internal switch end (seer huts)
  1638. int len1 = readNormalNr(i); i+=4;
  1639. for(int ee=0; ee<len1; ++ee)
  1640. {
  1641. spec->firstVisitText += bufor[i]; ++i;
  1642. }
  1643. int len2 = readNormalNr(i); i+=4;
  1644. for(int ee=0; ee<len2; ++ee)
  1645. {
  1646. spec->nextVisitText += bufor[i]; ++i;
  1647. }
  1648. int len3 = readNormalNr(i); i+=4;
  1649. for(int ee=0; ee<len3; ++ee)
  1650. {
  1651. spec->completedText += bufor[i]; ++i;
  1652. }
  1653. nobj.info = spec;
  1654. break;
  1655. }
  1656. } //end of main switch
  1657. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  1658. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  1659. }//*/ //end of loading objects; commented to make application work until it will be finished
  1660. ////objects loaded
  1661. processMap(defsToUnpack);
  1662. std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack);
  1663. for (int i=0;i<dhandlers.size();i++)
  1664. map.defy[i].handler=dhandlers[i];
  1665. for(int vv=0; vv<map.defy.size(); ++vv)
  1666. {
  1667. if(map.defy[vv].handler->alphaTransformed)
  1668. continue;
  1669. for(int yy=0; yy<map.defy[vv].handler->ourImages.size(); ++yy)
  1670. {
  1671. map.defy[vv].handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv].handler->ourImages[yy].bitmap);
  1672. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv].handler->ourImages[yy].bitmap, alphaTransSurf);
  1673. SDL_FreeSurface(map.defy[vv].handler->ourImages[yy].bitmap);
  1674. map.defy[vv].handler->ourImages[yy].bitmap = bufs;
  1675. map.defy[vv].handler->alphaTransformed = true;
  1676. }
  1677. }
  1678. SDL_FreeSurface(alphaTransSurf);
  1679. //loading events
  1680. int numberOfEvents = readNormalNr(i); i+=4;
  1681. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  1682. {
  1683. CMapEvent ne;
  1684. ne.name = std::string();
  1685. ne.message = std::string();
  1686. int nameLen = readNormalNr(i); i+=4;
  1687. for(int qq=0; qq<nameLen; ++qq)
  1688. {
  1689. ne.name += bufor[i]; ++i;
  1690. }
  1691. int messLen = readNormalNr(i); i+=4;
  1692. for(int qq=0; qq<messLen; ++qq)
  1693. {
  1694. ne.message +=bufor[i]; ++i;
  1695. }
  1696. ne.wood = readNormalNr(i); i+=4;
  1697. ne.mercury = readNormalNr(i); i+=4;
  1698. ne.ore = readNormalNr(i); i+=4;
  1699. ne.sulfur = readNormalNr(i); i+=4;
  1700. ne.crystal = readNormalNr(i); i+=4;
  1701. ne.gems = readNormalNr(i); i+=4;
  1702. ne.gold = readNormalNr(i); i+=4;
  1703. ne.players = bufor[i]; ++i;
  1704. ne.humanAffected = bufor[i]; ++i;
  1705. ne.computerAffected = bufor[i]; ++i;
  1706. ne.firstOccurence = bufor[i]; ++i;
  1707. ne.nextOccurence = bufor[i]; ++i;
  1708. i+=18;
  1709. map.events.push_back(ne);
  1710. }
  1711. }
  1712. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  1713. {
  1714. int ret=0;
  1715. int amp=1;
  1716. for (int i=0; i<bytCon; i++)
  1717. {
  1718. ret+=bufor[pos+i]*amp;
  1719. amp*=256;
  1720. }
  1721. if(cyclic && bytCon<4 && ret>=amp/2)
  1722. {
  1723. ret = ret-amp;
  1724. }
  1725. return ret;
  1726. }
  1727. void CAmbarCendamo::loadDefs()
  1728. {
  1729. std::set<int> loadedTypes;
  1730. for (int i=0; i<map.width; i++)
  1731. {
  1732. for (int j=0; j<map.width; j++)
  1733. {
  1734. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  1735. {
  1736. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str());
  1737. loadedTypes.insert(map.terrain[i][j].tertype);
  1738. defs.push_back(sdh);
  1739. }
  1740. if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  1741. {
  1742. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str());
  1743. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  1744. defs.push_back(sdh);
  1745. }
  1746. }
  1747. }
  1748. }
  1749. EDefType CAmbarCendamo::getDefType(DefInfo &a)
  1750. {
  1751. switch(a.bytes[16])
  1752. {
  1753. case 5: case 65: case 66: case 67: case 68: case 69:
  1754. return EDefType::ARTIFACT_DEF; //handled
  1755. case 6:
  1756. return EDefType::PANDORA_DEF; //hanled
  1757. case 26:
  1758. return EDefType::EVENTOBJ_DEF; //handled
  1759. case 33:
  1760. return EDefType::GARRISON_DEF; //handled
  1761. case 34: case 70: case 62: //70 - random hero //62 - prison
  1762. return EDefType::HERO_DEF; //handled
  1763. case 36:
  1764. return EDefType::GRAIL_DEF; //hanled
  1765. case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
  1766. return EDefType::PLAYERONLY_DEF; //handled
  1767. case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
  1768. return EDefType::CREATURES_DEF; //handled
  1769. case 59:
  1770. return EDefType::SIGN_DEF; //handled
  1771. case 77:
  1772. return EDefType::TOWN_DEF; //can be problematic, but handled
  1773. case 79: case 76:
  1774. return EDefType::RESOURCE_DEF; //handled
  1775. case 81:
  1776. return EDefType::SCHOLAR_DEF; //handled
  1777. case 83:
  1778. return EDefType::SEERHUT_DEF; //handled
  1779. case 91:
  1780. return EDefType::SIGN_DEF; //handled
  1781. case 88: case 89: case 90:
  1782. return SHRINE_DEF; //handled
  1783. case 93:
  1784. return SPELLSCROLL_DEF; //handled
  1785. case 98:
  1786. return EDefType::TOWN_DEF; //handled
  1787. case 113:
  1788. return EDefType::WITCHHUT_DEF; //handled
  1789. case 215:
  1790. return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;]
  1791. case 216:
  1792. return EDefType::CREGEN2_DEF; //handled
  1793. case 217:
  1794. return EDefType::CREGEN_DEF; //handled
  1795. case 218:
  1796. return EDefType::CREGEN3_DEF; //handled
  1797. case 219:
  1798. return EDefType::GARRISON_DEF; //handled
  1799. default:
  1800. return EDefType::TERRAINOBJ_DEF; // nothing to be handled
  1801. }
  1802. }
  1803. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  1804. {
  1805. CCreatureSet ret;
  1806. std::pair<CCreature *, int> ins;
  1807. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  1808. {
  1809. int rettt = readNormalNr(pos, 2);
  1810. if(rettt>32768)
  1811. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1812. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1813. ins.second = readNormalNr(pos+2, 2);
  1814. std::pair<int,std::pair<CCreature *, int> > tt(0,ins);
  1815. ret.slots.insert(tt);
  1816. }
  1817. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  1818. {
  1819. int rettt = readNormalNr(pos+4, 2);
  1820. if(rettt>32768)
  1821. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1822. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1823. ins.second = readNormalNr(pos+6, 2);
  1824. std::pair<int,std::pair<CCreature *, int> > tt(1,ins);
  1825. ret.slots.insert(tt);
  1826. }
  1827. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  1828. {
  1829. int rettt = readNormalNr(pos+8, 2);
  1830. if(rettt>32768)
  1831. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1832. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1833. ins.second = readNormalNr(pos+10, 2);
  1834. std::pair<int,std::pair<CCreature *, int> > tt(2,ins);
  1835. ret.slots.insert(tt);
  1836. }
  1837. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  1838. {
  1839. int rettt = readNormalNr(pos+12, 2);
  1840. if(rettt>32768)
  1841. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1842. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1843. ins.second = readNormalNr(pos+14, 2);
  1844. std::pair<int,std::pair<CCreature *, int> > tt(3,ins);
  1845. ret.slots.insert(tt);
  1846. }
  1847. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  1848. {
  1849. int rettt = readNormalNr(pos+16, 2);
  1850. if(rettt>32768)
  1851. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1852. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1853. ins.second = readNormalNr(pos+18, 2);
  1854. std::pair<int,std::pair<CCreature *, int> > tt(4,ins);
  1855. ret.slots.insert(tt);
  1856. }
  1857. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  1858. {
  1859. int rettt = readNormalNr(pos+20, 2);
  1860. if(rettt>32768)
  1861. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1862. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1863. ins.second = readNormalNr(pos+22, 2);
  1864. std::pair<int,std::pair<CCreature *, int> > tt(5,ins);
  1865. ret.slots.insert(tt);
  1866. }
  1867. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  1868. {
  1869. int rettt = readNormalNr(pos+24, 2);
  1870. if(rettt>32768)
  1871. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  1872. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  1873. ins.second = readNormalNr(pos+26, 2);
  1874. std::pair<int,std::pair<CCreature *, int> > tt(6,ins);
  1875. ret.slots.insert(tt);
  1876. }
  1877. return ret;
  1878. }
  1879. void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
  1880. {
  1881. resDefNames.push_back("AVTRNDM0.DEF");
  1882. resDefNames.push_back("AVTWOOD0.DEF");
  1883. resDefNames.push_back("AVTMERC0.DEF");
  1884. resDefNames.push_back("AVTORE0.DEF");
  1885. resDefNames.push_back("AVTSULF0.DEF");
  1886. resDefNames.push_back("AVTCRYS0.DEF");
  1887. resDefNames.push_back("AVTGEMS0.DEF");
  1888. resDefNames.push_back("AVTGOLD0.DEF");
  1889. resDefNames.push_back("ZMITHR.DEF");
  1890. std::vector<int> resDefNumbers;
  1891. for(int hh=0; hh<resDefNames.size(); ++hh)
  1892. {
  1893. resDefNumbers.push_back(-1);
  1894. for(int k=0; k<map.defy.size(); ++k)
  1895. {
  1896. std::string buf = map.defy[k].name;
  1897. std::transform(buf.begin(), buf.end(), buf.begin(), (int(*)(int))toupper);
  1898. if(resDefNames[hh] == buf)
  1899. {
  1900. resDefNumbers[resDefNumbers.size()-1] = k;
  1901. break;
  1902. }
  1903. }
  1904. }
  1905. std::vector<std::string> creDefNames;
  1906. for(int dd=0; dd<140; ++dd) //we do not use here WoG units
  1907. {
  1908. creDefNames.push_back(CGI->dobjinfo->objs[dd+1184].defName);
  1909. }
  1910. std::vector<int> creDefNumbers;
  1911. for(int ee=0; ee<creDefNames.size(); ++ee)
  1912. {
  1913. creDefNumbers.push_back(-1);
  1914. }
  1915. std::vector<std::string> artDefNames;
  1916. std::vector<int> artDefNumbers;
  1917. for(int bb=0; bb<162; ++bb)
  1918. {
  1919. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass!=EartClass::SartClass)
  1920. artDefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1921. }
  1922. for(int ee=0; ee<artDefNames.size(); ++ee)
  1923. {
  1924. artDefNumbers.push_back(-1);
  1925. }
  1926. std::vector<std::string> art1DefNames;
  1927. std::vector<int> art1DefNumbers;
  1928. for(int bb=0; bb<162; ++bb)
  1929. {
  1930. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::TartClass)
  1931. art1DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1932. }
  1933. for(int ee=0; ee<art1DefNames.size(); ++ee)
  1934. {
  1935. art1DefNumbers.push_back(-1);
  1936. }
  1937. std::vector<std::string> art2DefNames;
  1938. std::vector<int> art2DefNumbers;
  1939. for(int bb=0; bb<162; ++bb)
  1940. {
  1941. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::NartClass)
  1942. art2DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1943. }
  1944. for(int ee=0; ee<art2DefNames.size(); ++ee)
  1945. {
  1946. art2DefNumbers.push_back(-1);
  1947. }
  1948. std::vector<std::string> art3DefNames;
  1949. std::vector<int> art3DefNumbers;
  1950. for(int bb=0; bb<162; ++bb)
  1951. {
  1952. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::JartClass)
  1953. art3DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1954. }
  1955. for(int ee=0; ee<art3DefNames.size(); ++ee)
  1956. {
  1957. art3DefNumbers.push_back(-1);
  1958. }
  1959. std::vector<std::string> art4DefNames;
  1960. std::vector<int> art4DefNumbers;
  1961. for(int bb=0; bb<162; ++bb)
  1962. {
  1963. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::RartClass)
  1964. art4DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  1965. }
  1966. for(int ee=0; ee<art4DefNames.size(); ++ee)
  1967. {
  1968. art4DefNumbers.push_back(-1);
  1969. }
  1970. std::vector<std::string> town0DefNames; //without fort
  1971. std::vector<int> town0DefNumbers;
  1972. std::vector<std::string> town1DefNames; //with fort
  1973. std::vector<int> town1DefNumbers;
  1974. for(int dd=0; dd<F_NUMBER; ++dd)
  1975. {
  1976. town1DefNames.push_back(CGI->dobjinfo->objs[dd+385].defName);
  1977. town1DefNumbers.push_back(-1);
  1978. }
  1979. std::vector< std::vector<std::string> > creGenNames;
  1980. std::vector< std::vector<int> > creGenNumbers;
  1981. creGenNames.resize(F_NUMBER);
  1982. creGenNumbers.resize(F_NUMBER);
  1983. for(int ff=0; ff<F_NUMBER-1; ++ff)
  1984. {
  1985. for(int dd=0; dd<7; ++dd)
  1986. {
  1987. creGenNames[ff].push_back(CGI->dobjinfo->objs[395+7*ff+dd].defName);
  1988. creGenNumbers[ff].push_back(-1);
  1989. }
  1990. }
  1991. for(int dd=0; dd<7; ++dd)
  1992. {
  1993. creGenNumbers[8].push_back(-1);
  1994. }
  1995. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName);
  1996. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName);
  1997. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[455].defName);
  1998. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName);
  1999. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName);
  2000. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
  2001. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[459].defName);
  2002. //variables initialized
  2003. for(int j=0; j<CGI->objh->objInstances.size(); ++j)
  2004. {
  2005. DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber];
  2006. switch(getDefType(curDef))
  2007. {
  2008. case EDefType::RESOURCE_DEF:
  2009. {
  2010. if(curDef.bytes[16]==76) //resource to specify
  2011. {
  2012. DefInfo nxt = curDef;
  2013. nxt.bytes[16] = 79;
  2014. nxt.bytes[20] = rand()%7;
  2015. if(resDefNumbers[nxt.bytes[20]+1]!=-1)
  2016. {
  2017. CGI->objh->objInstances[j].defNumber = resDefNumbers[nxt.bytes[20]+1];
  2018. continue;
  2019. }
  2020. nxt.name = resDefNames[nxt.bytes[20]+1];
  2021. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2022. nxt.name);
  2023. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2024. {
  2025. nxt.isOnDefList = false;
  2026. }
  2027. else
  2028. {
  2029. nxt.printPriority = pit->priority;
  2030. nxt.isOnDefList = true;
  2031. }
  2032. map.defy.push_back(nxt); // add this def to the vector
  2033. defsToUnpack.push_back(nxt.name);
  2034. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2035. if(resDefNumbers[nxt.bytes[20]+1]==-1)
  2036. {
  2037. resDefNumbers[nxt.bytes[20]+1] = map.defy.size()-1;
  2038. }
  2039. }
  2040. break;
  2041. }
  2042. case EDefType::CREATURES_DEF:
  2043. {
  2044. if(curDef.bytes[16]==72) //random monster lvl 1
  2045. {
  2046. DefInfo nxt = curDef;
  2047. nxt.bytes[16] = 54;
  2048. nxt.bytes[20] = 14*(rand()%9)+rand()%2;
  2049. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2050. {
  2051. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2052. continue;
  2053. }
  2054. nxt.name = creDefNames[nxt.bytes[20]];
  2055. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2056. nxt.name);
  2057. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2058. {
  2059. nxt.isOnDefList = false;
  2060. }
  2061. else
  2062. {
  2063. nxt.printPriority = pit->priority;
  2064. nxt.isOnDefList = true;
  2065. }
  2066. map.defy.push_back(nxt); // add this def to the vector
  2067. defsToUnpack.push_back(nxt.name);
  2068. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2069. if(creDefNumbers[nxt.bytes[20]]==-1)
  2070. {
  2071. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2072. }
  2073. }
  2074. if(curDef.bytes[16]==73) //random monster lvl 2
  2075. {
  2076. DefInfo nxt = curDef;
  2077. nxt.bytes[16] = 54;
  2078. nxt.bytes[20] = 14*(rand()%9)+rand()%2+2;
  2079. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2080. {
  2081. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2082. continue;
  2083. }
  2084. nxt.name = creDefNames[nxt.bytes[20]];
  2085. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2086. nxt.name);
  2087. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2088. {
  2089. nxt.isOnDefList = false;
  2090. }
  2091. else
  2092. {
  2093. nxt.printPriority = pit->priority;
  2094. nxt.isOnDefList = true;
  2095. }
  2096. map.defy.push_back(nxt); // add this def to the vector
  2097. defsToUnpack.push_back(nxt.name);
  2098. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2099. if(creDefNumbers[nxt.bytes[20]]==-1)
  2100. {
  2101. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2102. }
  2103. }
  2104. if(curDef.bytes[16]==74) //random monster lvl 3
  2105. {
  2106. DefInfo nxt = curDef;
  2107. nxt.bytes[16] = 54;
  2108. nxt.bytes[20] = 14*(rand()%9)+rand()%2+4;
  2109. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2110. {
  2111. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2112. continue;
  2113. }
  2114. nxt.name = creDefNames[nxt.bytes[20]];
  2115. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2116. nxt.name);
  2117. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2118. {
  2119. nxt.isOnDefList = false;
  2120. }
  2121. else
  2122. {
  2123. nxt.printPriority = pit->priority;
  2124. nxt.isOnDefList = true;
  2125. }
  2126. map.defy.push_back(nxt); // add this def to the vector
  2127. defsToUnpack.push_back(nxt.name);
  2128. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2129. if(creDefNumbers[nxt.bytes[20]]==-1)
  2130. {
  2131. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2132. }
  2133. }
  2134. if(curDef.bytes[16]==75) //random monster lvl 4
  2135. {
  2136. DefInfo nxt = curDef;
  2137. nxt.bytes[16] = 54;
  2138. nxt.bytes[20] = 14*(rand()%9)+rand()%2+6;
  2139. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2140. {
  2141. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2142. continue;
  2143. }
  2144. nxt.name = creDefNames[nxt.bytes[20]];
  2145. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2146. nxt.name);
  2147. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2148. {
  2149. nxt.isOnDefList = false;
  2150. }
  2151. else
  2152. {
  2153. nxt.printPriority = pit->priority;
  2154. nxt.isOnDefList = true;
  2155. }
  2156. map.defy.push_back(nxt); // add this def to the vector
  2157. defsToUnpack.push_back(nxt.name);
  2158. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2159. if(creDefNumbers[nxt.bytes[20]]==-1)
  2160. {
  2161. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2162. }
  2163. }
  2164. if(curDef.bytes[16]==162) //random monster lvl 5
  2165. {
  2166. DefInfo nxt = curDef;
  2167. nxt.bytes[16] = 54;
  2168. nxt.bytes[20] = 14*(rand()%9)+rand()%2+8;
  2169. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2170. {
  2171. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2172. continue;
  2173. }
  2174. nxt.name = creDefNames[nxt.bytes[20]];
  2175. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2176. nxt.name);
  2177. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2178. {
  2179. nxt.isOnDefList = false;
  2180. }
  2181. else
  2182. {
  2183. nxt.printPriority = pit->priority;
  2184. nxt.isOnDefList = true;
  2185. }
  2186. map.defy.push_back(nxt); // add this def to the vector
  2187. defsToUnpack.push_back(nxt.name);
  2188. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2189. if(creDefNumbers[nxt.bytes[20]]==-1)
  2190. {
  2191. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2192. }
  2193. }
  2194. if(curDef.bytes[16]==163) //random monster lvl 6
  2195. {
  2196. DefInfo nxt = curDef;
  2197. nxt.bytes[16] = 54;
  2198. nxt.bytes[20] = 14*(rand()%9)+rand()%2+10;
  2199. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2200. {
  2201. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2202. continue;
  2203. }
  2204. nxt.name = creDefNames[nxt.bytes[20]];
  2205. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2206. nxt.name);
  2207. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2208. {
  2209. nxt.isOnDefList = false;
  2210. }
  2211. else
  2212. {
  2213. nxt.printPriority = pit->priority;
  2214. nxt.isOnDefList = true;
  2215. }
  2216. map.defy.push_back(nxt); // add this def to the vector
  2217. defsToUnpack.push_back(nxt.name);
  2218. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2219. if(creDefNumbers[nxt.bytes[20]]==-1)
  2220. {
  2221. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2222. }
  2223. }
  2224. if(curDef.bytes[16]==164) //random monster lvl 7
  2225. {
  2226. DefInfo nxt = curDef;
  2227. nxt.bytes[16] = 54;
  2228. nxt.bytes[20] = 14*(rand()%9)+rand()%2+12;
  2229. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2230. {
  2231. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2232. continue;
  2233. }
  2234. nxt.name = creDefNames[nxt.bytes[20]];
  2235. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2236. nxt.name);
  2237. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2238. {
  2239. nxt.isOnDefList = false;
  2240. }
  2241. else
  2242. {
  2243. nxt.printPriority = pit->priority;
  2244. nxt.isOnDefList = true;
  2245. }
  2246. map.defy.push_back(nxt); // add this def to the vector
  2247. defsToUnpack.push_back(nxt.name);
  2248. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2249. if(creDefNumbers[nxt.bytes[20]]==-1)
  2250. {
  2251. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2252. }
  2253. }
  2254. if(curDef.bytes[16]==71) //random monster (any level)
  2255. {
  2256. DefInfo nxt = curDef;
  2257. nxt.bytes[16] = 54;
  2258. nxt.bytes[20] = rand()%126;
  2259. if(creDefNumbers[nxt.bytes[20]]!=-1)
  2260. {
  2261. CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
  2262. continue;
  2263. }
  2264. nxt.name = creDefNames[nxt.bytes[20]];
  2265. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2266. nxt.name);
  2267. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2268. {
  2269. nxt.isOnDefList = false;
  2270. }
  2271. else
  2272. {
  2273. nxt.printPriority = pit->priority;
  2274. nxt.isOnDefList = true;
  2275. }
  2276. map.defy.push_back(nxt); // add this def to the vector
  2277. defsToUnpack.push_back(nxt.name);
  2278. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2279. if(creDefNumbers[nxt.bytes[20]]==-1)
  2280. {
  2281. creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2282. }
  2283. }
  2284. break;
  2285. } //end of case
  2286. case EDefType::ARTIFACT_DEF:
  2287. {
  2288. if(curDef.bytes[16]==65) //random atrifact (any class)
  2289. {
  2290. DefInfo nxt = curDef;
  2291. nxt.bytes[16] = 5;
  2292. nxt.bytes[20] = rand()%artDefNames.size();
  2293. if(artDefNumbers[nxt.bytes[20]]!=-1)
  2294. {
  2295. CGI->objh->objInstances[j].defNumber = artDefNumbers[nxt.bytes[20]];
  2296. continue;
  2297. }
  2298. nxt.name = artDefNames[nxt.bytes[20]];
  2299. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2300. nxt.name);
  2301. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2302. {
  2303. nxt.isOnDefList = false;
  2304. }
  2305. else
  2306. {
  2307. nxt.printPriority = pit->priority;
  2308. nxt.isOnDefList = true;
  2309. }
  2310. map.defy.push_back(nxt); // add this def to the vector
  2311. defsToUnpack.push_back(nxt.name);
  2312. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2313. if(artDefNumbers[nxt.bytes[20]]==-1)
  2314. {
  2315. artDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2316. }
  2317. }
  2318. if(curDef.bytes[16]==66) //random atrifact (treasure)
  2319. {
  2320. DefInfo nxt = curDef;
  2321. nxt.bytes[16] = 5;
  2322. nxt.bytes[20] = rand()%art1DefNames.size();
  2323. if(art1DefNumbers[nxt.bytes[20]]!=-1)
  2324. {
  2325. CGI->objh->objInstances[j].defNumber = art1DefNumbers[nxt.bytes[20]];
  2326. continue;
  2327. }
  2328. nxt.name = art1DefNames[nxt.bytes[20]];
  2329. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2330. nxt.name);
  2331. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2332. {
  2333. nxt.isOnDefList = false;
  2334. }
  2335. else
  2336. {
  2337. nxt.printPriority = pit->priority;
  2338. nxt.isOnDefList = true;
  2339. }
  2340. map.defy.push_back(nxt); // add this def to the vector
  2341. defsToUnpack.push_back(nxt.name);
  2342. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2343. if(art1DefNumbers[nxt.bytes[20]]==-1)
  2344. {
  2345. art1DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2346. }
  2347. }
  2348. if(curDef.bytes[16]==67) //random atrifact (minor)
  2349. {
  2350. DefInfo nxt = curDef;
  2351. nxt.bytes[16] = 5;
  2352. nxt.bytes[20] = rand()%art2DefNames.size();
  2353. if(art2DefNumbers[nxt.bytes[20]]!=-1)
  2354. {
  2355. CGI->objh->objInstances[j].defNumber = art2DefNumbers[nxt.bytes[20]];
  2356. continue;
  2357. }
  2358. nxt.name = art2DefNames[nxt.bytes[20]];
  2359. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2360. nxt.name);
  2361. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2362. {
  2363. nxt.isOnDefList = false;
  2364. }
  2365. else
  2366. {
  2367. nxt.printPriority = pit->priority;
  2368. nxt.isOnDefList = true;
  2369. }
  2370. map.defy.push_back(nxt); // add this def to the vector
  2371. defsToUnpack.push_back(nxt.name);
  2372. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2373. if(art2DefNumbers[nxt.bytes[20]]==-1)
  2374. {
  2375. art2DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2376. }
  2377. }
  2378. if(curDef.bytes[16]==68) //random atrifact (major)
  2379. {
  2380. DefInfo nxt = curDef;
  2381. nxt.bytes[16] = 5;
  2382. nxt.bytes[20] = rand()%art3DefNames.size();
  2383. if(art3DefNumbers[nxt.bytes[20]]!=-1)
  2384. {
  2385. CGI->objh->objInstances[j].defNumber = art3DefNumbers[nxt.bytes[20]];
  2386. continue;
  2387. }
  2388. nxt.name = art3DefNames[nxt.bytes[20]];
  2389. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2390. nxt.name);
  2391. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2392. {
  2393. nxt.isOnDefList = false;
  2394. }
  2395. else
  2396. {
  2397. nxt.printPriority = pit->priority;
  2398. nxt.isOnDefList = true;
  2399. }
  2400. map.defy.push_back(nxt); // add this def to the vector
  2401. defsToUnpack.push_back(nxt.name);
  2402. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2403. if(art3DefNumbers[nxt.bytes[20]]==-1)
  2404. {
  2405. art3DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2406. }
  2407. }
  2408. if(curDef.bytes[16]==69) //random atrifact (relic)
  2409. {
  2410. DefInfo nxt = curDef;
  2411. nxt.bytes[16] = 5;
  2412. nxt.bytes[20] = rand()%art4DefNames.size();
  2413. if(art4DefNumbers[nxt.bytes[20]]!=-1)
  2414. {
  2415. CGI->objh->objInstances[j].defNumber = art4DefNumbers[nxt.bytes[20]];
  2416. continue;
  2417. }
  2418. nxt.name = art4DefNames[nxt.bytes[20]];
  2419. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2420. nxt.name);
  2421. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2422. {
  2423. nxt.isOnDefList = false;
  2424. }
  2425. else
  2426. {
  2427. nxt.printPriority = pit->priority;
  2428. nxt.isOnDefList = true;
  2429. }
  2430. map.defy.push_back(nxt); // add this def to the vector
  2431. defsToUnpack.push_back(nxt.name);
  2432. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2433. if(art4DefNumbers[nxt.bytes[20]]==-1)
  2434. {
  2435. art4DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2436. }
  2437. }
  2438. break;
  2439. }
  2440. case EDefType::TOWN_DEF:
  2441. {
  2442. if(curDef.bytes[16]==77) //random town
  2443. {
  2444. DefInfo nxt = curDef;
  2445. nxt.bytes[16] = 98;
  2446. if(((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player==0xff)
  2447. {
  2448. nxt.bytes[20] = rand()%town1DefNames.size();
  2449. }
  2450. else
  2451. {
  2452. if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player).castle>-1)
  2453. {
  2454. nxt.bytes[20] = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player).castle;
  2455. }
  2456. else
  2457. {
  2458. nxt.bytes[20] = rand()%town1DefNames.size();
  2459. }
  2460. }
  2461. if(town1DefNumbers[nxt.bytes[20]]!=-1)
  2462. {
  2463. CGI->objh->objInstances[j].defNumber = town1DefNumbers[nxt.bytes[20]];
  2464. continue;
  2465. }
  2466. nxt.name = town1DefNames[nxt.bytes[20]];
  2467. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2468. nxt.name);
  2469. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2470. {
  2471. nxt.isOnDefList = false;
  2472. }
  2473. else
  2474. {
  2475. nxt.printPriority = pit->priority;
  2476. nxt.isOnDefList = true;
  2477. }
  2478. map.defy.push_back(nxt); // add this def to the vector
  2479. defsToUnpack.push_back(nxt.name);
  2480. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2481. if(town1DefNumbers[nxt.bytes[20]]==-1)
  2482. {
  2483. town1DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
  2484. }
  2485. }
  2486. //((CCastleObjInfo*)CGI->objh->objInstances[j].info)
  2487. break;
  2488. }
  2489. } //end of main switch
  2490. } //end of main loop
  2491. for(int j=0; j<CGI->objh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent)
  2492. {
  2493. DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber];
  2494. switch(getDefType(curDef))
  2495. {
  2496. case EDefType::CREGEN_DEF:
  2497. {
  2498. if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->asCastle)
  2499. {
  2500. DefInfo nxt = curDef;
  2501. nxt.bytes[16] = 17;
  2502. for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
  2503. {
  2504. if(getDefType(map.defy[CGI->objh->objInstances[vv].defNumber])==EDefType::TOWN_DEF)
  2505. {
  2506. if(
  2507. ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[0]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[0]
  2508. && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[1]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[1]
  2509. && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[2]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[2]
  2510. && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[3]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[3])
  2511. {
  2512. for(int mm=0; mm<town1DefNames.size(); ++mm)
  2513. {
  2514. std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
  2515. std::string hlp = map.defy[CGI->objh->objInstances[vv].defNumber].name;
  2516. std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
  2517. if(town1DefNames[mm]==hlp)
  2518. {
  2519. nxt.bytes[20] = mm;
  2520. }
  2521. }
  2522. }
  2523. }
  2524. }
  2525. int lvl = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str())-1;
  2526. nxt.name = creGenNames[nxt.bytes[20]][lvl];
  2527. if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
  2528. {
  2529. CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
  2530. continue;
  2531. }
  2532. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2533. nxt.name);
  2534. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2535. {
  2536. nxt.isOnDefList = false;
  2537. }
  2538. else
  2539. {
  2540. nxt.printPriority = pit->priority;
  2541. nxt.isOnDefList = true;
  2542. }
  2543. map.defy.push_back(nxt); // add this def to the vector
  2544. defsToUnpack.push_back(nxt.name);
  2545. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2546. if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
  2547. {
  2548. creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
  2549. }
  2550. }
  2551. else //if not as castle
  2552. {
  2553. DefInfo nxt = curDef;
  2554. nxt.bytes[16] = 17;
  2555. std::vector<int> possibleTowns;
  2556. for(int bb=0; bb<8; ++bb)
  2557. {
  2558. if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->castles[0] & (1<<bb))
  2559. {
  2560. possibleTowns.push_back(bb);
  2561. }
  2562. }
  2563. if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->castles[1])
  2564. possibleTowns.push_back(8);
  2565. nxt.bytes[20] = possibleTowns[rand()%possibleTowns.size()];
  2566. int lvl = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str())-1;
  2567. nxt.name = creGenNames[nxt.bytes[20]][lvl];
  2568. if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
  2569. {
  2570. CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
  2571. continue;
  2572. }
  2573. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2574. nxt.name);
  2575. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2576. {
  2577. nxt.isOnDefList = false;
  2578. }
  2579. else
  2580. {
  2581. nxt.printPriority = pit->priority;
  2582. nxt.isOnDefList = true;
  2583. }
  2584. map.defy.push_back(nxt); // add this def to the vector
  2585. defsToUnpack.push_back(nxt.name);
  2586. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2587. if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
  2588. {
  2589. creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
  2590. }
  2591. }
  2592. break;
  2593. }
  2594. case EDefType::CREGEN2_DEF:
  2595. {
  2596. if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->asCastle)
  2597. {
  2598. DefInfo nxt = curDef;
  2599. nxt.bytes[16] = 17;
  2600. for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
  2601. {
  2602. if(getDefType(map.defy[CGI->objh->objInstances[vv].defNumber])==EDefType::TOWN_DEF)
  2603. {
  2604. if(
  2605. ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[0]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[0]
  2606. && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[1]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[1]
  2607. && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[2]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[2]
  2608. && ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[3]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[3])
  2609. {
  2610. for(int mm=0; mm<town1DefNames.size(); ++mm)
  2611. {
  2612. std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
  2613. std::string hlp = map.defy[CGI->objh->objInstances[vv].defNumber].name;
  2614. std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
  2615. if(town1DefNames[mm]==hlp)
  2616. {
  2617. nxt.bytes[20] = mm;
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel;
  2624. nxt.name = creGenNames[nxt.bytes[20]][lvl];
  2625. if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
  2626. {
  2627. CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
  2628. continue;
  2629. }
  2630. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2631. nxt.name);
  2632. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2633. {
  2634. nxt.isOnDefList = false;
  2635. }
  2636. else
  2637. {
  2638. nxt.printPriority = pit->priority;
  2639. nxt.isOnDefList = true;
  2640. }
  2641. map.defy.push_back(nxt); // add this def to the vector
  2642. defsToUnpack.push_back(nxt.name);
  2643. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2644. if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
  2645. {
  2646. creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
  2647. }
  2648. }
  2649. else //if not as castle
  2650. {
  2651. DefInfo nxt = curDef;
  2652. nxt.bytes[16] = 17;
  2653. std::vector<int> possibleTowns;
  2654. for(int bb=0; bb<8; ++bb)
  2655. {
  2656. if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->castles[0] & (1<<bb))
  2657. {
  2658. possibleTowns.push_back(bb);
  2659. }
  2660. }
  2661. if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->castles[1])
  2662. possibleTowns.push_back(8);
  2663. nxt.bytes[20] = possibleTowns[rand()%possibleTowns.size()];
  2664. int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel;
  2665. nxt.name = creGenNames[nxt.bytes[20]][lvl];
  2666. if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
  2667. {
  2668. CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
  2669. continue;
  2670. }
  2671. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2672. nxt.name);
  2673. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2674. {
  2675. nxt.isOnDefList = false;
  2676. }
  2677. else
  2678. {
  2679. nxt.printPriority = pit->priority;
  2680. nxt.isOnDefList = true;
  2681. }
  2682. map.defy.push_back(nxt); // add this def to the vector
  2683. defsToUnpack.push_back(nxt.name);
  2684. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2685. if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
  2686. {
  2687. creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
  2688. }
  2689. }
  2690. }
  2691. case EDefType::CREGEN3_DEF:
  2692. {
  2693. DefInfo nxt = curDef;
  2694. nxt.bytes[16] = 17;
  2695. nxt.bytes[20] = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str());
  2696. int lvl = rand()%(((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->minLevel;
  2697. nxt.name = creGenNames[nxt.bytes[20]][lvl];
  2698. if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
  2699. {
  2700. CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
  2701. continue;
  2702. }
  2703. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2704. nxt.name);
  2705. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2706. {
  2707. nxt.isOnDefList = false;
  2708. }
  2709. else
  2710. {
  2711. nxt.printPriority = pit->priority;
  2712. nxt.isOnDefList = true;
  2713. }
  2714. map.defy.push_back(nxt); // add this def to the vector
  2715. defsToUnpack.push_back(nxt.name);
  2716. CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
  2717. if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
  2718. {
  2719. creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
  2720. }
  2721. break;
  2722. }
  2723. }//end of main switch
  2724. } //end of sencond for loop
  2725. }