CAmbarCendamo.cpp 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420
  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 "CTownHandler.h"
  8. #include "CDefObjInfoHandler.h"
  9. #include "../SDL_Extensions.h"
  10. #include "boost\filesystem.hpp"
  11. #include "../CGameState.h"
  12. #include "CLodHandler.h"
  13. #include <set>
  14. #include <iomanip>
  15. #include <sstream>
  16. #include "../CLua.h"
  17. unsigned int intPow(unsigned int a, unsigned int b)
  18. {
  19. unsigned int ret=1;
  20. for(int i=0; i<b; ++i)
  21. ret*=a;
  22. return ret;
  23. }
  24. unsigned char reverse(unsigned char arg)
  25. {
  26. unsigned char ret = 0;
  27. for (int i=0; i<8;i++)
  28. {
  29. if(((arg)&(1<<i))>>i)
  30. {
  31. ret |= (128>>i);
  32. }
  33. }
  34. return ret;
  35. }
  36. CAmbarCendamo::CAmbarCendamo (unsigned char * map)
  37. {
  38. bufor=map;
  39. }
  40. CAmbarCendamo::CAmbarCendamo (const char * tie)
  41. {
  42. is = new std::ifstream();
  43. is -> open(tie,std::ios::binary);
  44. is->seekg(0,std::ios::end); // na koniec
  45. andame = is->tellg(); // read length
  46. is->seekg(0,std::ios::beg); // wracamy na poczatek
  47. bufor = new unsigned char[andame]; // allocate memory
  48. is->read((char*)bufor, andame); // read map file to buffer
  49. is->close();
  50. delete is;
  51. }
  52. CAmbarCendamo::~CAmbarCendamo ()
  53. {// free memory
  54. for (int ii=0;ii<map.width;ii++)
  55. delete map.terrain[ii] ;
  56. delete map.terrain;
  57. delete bufor;
  58. }
  59. void CAmbarCendamo::teceDef()
  60. {
  61. //for (int i=0; i<map.defy.size(); i++)
  62. //{
  63. // std::ofstream * of = new std::ofstream(map.defy[i].name.c_str());
  64. // for (int j=0;j<46;j++)
  65. // {
  66. // (*of) << map.defy[i].bytes[j]<<std::endl;
  67. // }
  68. // of->close();
  69. // delete of;
  70. //}
  71. }
  72. void CAmbarCendamo::deh3m()
  73. {
  74. THC timeHandler th;
  75. map.version = (Eformat)bufor[0]; //wersja mapy
  76. map.areAnyPLayers = bufor[4]; //invalid on some maps
  77. map.height = map.width = bufor[5]; // wymiary mapy
  78. map.twoLevel = bufor[9]; //czy sa lochy
  79. map.terrain = new TerrainTile*[map.width]; // allocate memory
  80. for (int ii=0;ii<map.width;ii++)
  81. map.terrain[ii] = new TerrainTile[map.height]; // allocate memory
  82. if (map.twoLevel)
  83. {
  84. map.undergroungTerrain = new TerrainTile*[map.width]; // allocate memory
  85. for (int ii=0;ii<map.width;ii++)
  86. map.undergroungTerrain[ii] = new TerrainTile[map.height]; // allocate memory
  87. }
  88. int length = bufor[10]; //name length
  89. int i=14, pom;
  90. while (i-14<length) //read name
  91. map.name+=bufor[i++];
  92. length = bufor[i] + bufor[i+1]*256; //description length
  93. i+=4;
  94. for (pom=0;pom<length;pom++)
  95. map.description+=bufor[i++];
  96. map.difficulty = bufor[i++]; // reading map difficulty
  97. if(map.version != Eformat::RoE)
  98. {
  99. map.levelLimit = bufor[i++]; // hero level limit
  100. }
  101. else
  102. {
  103. map.levelLimit = 0;
  104. }
  105. for (pom=0;pom<8;pom++)
  106. {
  107. map.players[pom].canHumanPlay = bufor[i++];
  108. map.players[pom].canComputerPlay = bufor[i++];
  109. if ((!(map.players[pom].canHumanPlay || map.players[pom].canComputerPlay)))
  110. {
  111. switch(map.version)
  112. {
  113. case Eformat::SoD: case Eformat::WoG:
  114. i+=13;
  115. break;
  116. case Eformat::AB:
  117. i+=12;
  118. break;
  119. case Eformat::RoE:
  120. i+=6;
  121. break;
  122. }
  123. continue;
  124. }
  125. map.players[pom].AITactic = bufor[i++];
  126. if(map.version == Eformat::SoD || map.version == Eformat::WoG)
  127. i++;
  128. map.players[pom].allowedFactions = 0;
  129. map.players[pom].allowedFactions += bufor[i++];
  130. if(map.version != Eformat::RoE)
  131. map.players[pom].allowedFactions += (bufor[i++])*256;
  132. map.players[pom].isFactionRandom = bufor[i++];
  133. map.players[pom].hasMainTown = bufor[i++];
  134. if (map.players[pom].hasMainTown)
  135. {
  136. if(map.version != Eformat::RoE)
  137. {
  138. map.players[pom].generateHeroAtMainTown = bufor[i++];
  139. map.players[pom].generateHero = bufor[i++];
  140. }
  141. map.players[pom].posOfMainTown.x = bufor[i++];
  142. map.players[pom].posOfMainTown.y = bufor[i++];
  143. map.players[pom].posOfMainTown.z = bufor[i++];
  144. }
  145. map.players[pom].p8= bufor[i++];
  146. map.players[pom].p9= bufor[i++];
  147. if(map.players[pom].p9!=0xff)
  148. {
  149. map.players[pom].mainHeroPortrait = bufor[i++];
  150. int nameLength = bufor[i++];
  151. i+=3;
  152. for (int pp=0;pp<nameLength;pp++)
  153. map.players[pom].mainHeroName+=bufor[i++];
  154. }
  155. if(map.version != Eformat::RoE)
  156. {
  157. i++; ////unknown byte
  158. int heroCount = bufor[i++];
  159. i+=3;
  160. for (int pp=0;pp<heroCount;pp++)
  161. {
  162. SheroName vv;
  163. vv.heroID=bufor[i++];
  164. int hnl = bufor[i++];
  165. i+=3;
  166. for (int zz=0;zz<hnl;zz++)
  167. {
  168. vv.heroName+=bufor[i++];
  169. }
  170. map.players[pom].heroesNames.push_back(vv);
  171. }
  172. }
  173. }
  174. map.victoryCondition = (EvictoryConditions)bufor[i++];
  175. if (map.victoryCondition != winStandard) //specific victory conditions
  176. {
  177. int nr;
  178. switch (map.victoryCondition) //read victory conditions
  179. {
  180. case artifact:
  181. {
  182. map.vicConDetails = new VicCon0();
  183. ((VicCon0*)map.vicConDetails)->ArtifactID = bufor[i+2];
  184. nr=(map.version==RoE ? 1 : 2);
  185. break;
  186. }
  187. case gatherTroop:
  188. {
  189. map.vicConDetails = new VicCon1();
  190. int temp1 = bufor[i+2];
  191. int temp2 = bufor[i+3];
  192. ((VicCon1*)map.vicConDetails)->monsterID = bufor[i+2];
  193. ((VicCon1*)map.vicConDetails)->neededQuantity=readNormalNr(i+(map.version==RoE ? 3 : 4));
  194. nr=(map.version==RoE ? 5 : 6);
  195. break;
  196. }
  197. case gatherResource:
  198. {
  199. map.vicConDetails = new VicCon2();
  200. ((VicCon2*)map.vicConDetails)->resourceID = bufor[i+2];
  201. ((VicCon2*)map.vicConDetails)->neededQuantity=readNormalNr(i+3);
  202. nr=5;
  203. break;
  204. }
  205. case buildCity:
  206. {
  207. map.vicConDetails = new VicCon3();
  208. ((VicCon3*)map.vicConDetails)->posOfCity.x = bufor[i+2];
  209. ((VicCon3*)map.vicConDetails)->posOfCity.y = bufor[i+3];
  210. ((VicCon3*)map.vicConDetails)->posOfCity.z = bufor[i+4];
  211. ((VicCon3*)map.vicConDetails)->councilNeededLevel = bufor[i+5];
  212. ((VicCon3*)map.vicConDetails)->fortNeededLevel = bufor[i+6];
  213. nr=5;
  214. break;
  215. }
  216. case buildGrail:
  217. {
  218. map.vicConDetails = new VicCon4();
  219. if (bufor[i+4]>2)
  220. ((VicCon4*)map.vicConDetails)->anyLocation = true;
  221. else
  222. {
  223. ((VicCon4*)map.vicConDetails)->whereBuildGrail.x = bufor[i+2];
  224. ((VicCon4*)map.vicConDetails)->whereBuildGrail.y = bufor[i+3];
  225. ((VicCon4*)map.vicConDetails)->whereBuildGrail.z = bufor[i+4];
  226. }
  227. nr=3;
  228. break;
  229. }
  230. case beatHero:
  231. {
  232. map.vicConDetails = new VicCon5();
  233. ((VicCon5*)map.vicConDetails)->locationOfHero.x = bufor[i+2];
  234. ((VicCon5*)map.vicConDetails)->locationOfHero.y = bufor[i+3];
  235. ((VicCon5*)map.vicConDetails)->locationOfHero.z = bufor[i+4];
  236. nr=3;
  237. break;
  238. }
  239. case captureCity:
  240. {
  241. map.vicConDetails = new VicCon6();
  242. ((VicCon6*)map.vicConDetails)->locationOfTown.x = bufor[i+2];
  243. ((VicCon6*)map.vicConDetails)->locationOfTown.y = bufor[i+3];
  244. ((VicCon6*)map.vicConDetails)->locationOfTown.z = bufor[i+4];
  245. nr=3;
  246. break;
  247. }
  248. case beatMonster:
  249. {
  250. map.vicConDetails = new VicCon7();
  251. ((VicCon7*)map.vicConDetails)->locationOfMonster.x = bufor[i+2];
  252. ((VicCon7*)map.vicConDetails)->locationOfMonster.y = bufor[i+3];
  253. ((VicCon7*)map.vicConDetails)->locationOfMonster.z = bufor[i+4];
  254. nr=3;
  255. break;
  256. }
  257. case takeDwellings:
  258. {
  259. map.vicConDetails = new CspecificVictoryConidtions();
  260. nr=0;
  261. break;
  262. }
  263. case takeMines:
  264. {
  265. map.vicConDetails = new CspecificVictoryConidtions();
  266. nr=0;
  267. break;
  268. }
  269. case transportItem:
  270. {
  271. map.vicConDetails = new VicCona();
  272. ((VicCona*)map.vicConDetails)->artifactID = bufor[i+2];
  273. ((VicCona*)map.vicConDetails)->destinationPlace.x = bufor[i+3];
  274. ((VicCona*)map.vicConDetails)->destinationPlace.y = bufor[i+4];
  275. ((VicCona*)map.vicConDetails)->destinationPlace.z = bufor[i+5];
  276. nr=3;
  277. break;
  278. }
  279. }
  280. map.vicConDetails->allowNormalVictory = bufor[i++];
  281. map.vicConDetails->appliesToAI = bufor[i++];
  282. i+=nr;
  283. }
  284. map.lossCondition.typeOfLossCon = (ElossCon)bufor[i++];
  285. switch (map.lossCondition.typeOfLossCon) //read loss conditions
  286. {
  287. case lossCastle:
  288. {
  289. map.lossCondition.castlePos.x=bufor[i++];
  290. map.lossCondition.castlePos.y=bufor[i++];
  291. map.lossCondition.castlePos.z=bufor[i++];
  292. break;
  293. }
  294. case lossHero:
  295. {
  296. map.lossCondition.heroPos.x=bufor[i++];
  297. map.lossCondition.heroPos.y=bufor[i++];
  298. map.lossCondition.heroPos.z=bufor[i++];
  299. break;
  300. }
  301. case timeExpires:
  302. {
  303. map.lossCondition.timeLimit = readNormalNr(i++,2);
  304. i++;
  305. break;
  306. }
  307. }
  308. map.howManyTeams=bufor[i++]; //read number of teams
  309. if(map.howManyTeams>0) //read team numbers
  310. {
  311. for(int rr=0; rr<8; ++rr)
  312. {
  313. map.players[rr].team=bufor[i++];
  314. }
  315. }
  316. //reading allowed heroes (20 bytes)
  317. int ist;
  318. ist=i; //starting i for loop
  319. for(i; i<ist+ (map.version == Eformat::RoE ? 16 : 20) ; ++i)
  320. {
  321. unsigned char c = bufor[i];
  322. for(int yy=0; yy<8; ++yy)
  323. {
  324. if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size())
  325. {
  326. if(c == (c|((unsigned char)intPow(2, yy))))
  327. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = true;
  328. else
  329. CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = false;
  330. }
  331. }
  332. }
  333. if(map.version>RoE)
  334. i+=4;
  335. unsigned char disp = 0;
  336. if(map.version>=SoD)
  337. {
  338. disp = bufor[i++];
  339. for(int g=0; g<disp; ++g)
  340. {
  341. i+=2;
  342. int lenbuf = readNormalNr(i); i+=4;
  343. i+=lenbuf+1;
  344. }
  345. }
  346. //allowed heroes have been read
  347. unsigned char aaa1=bufor[i], aaa2=bufor[i+1], aaa3=bufor[i+2];
  348. i+=31; //omitting 0s
  349. //reading allowed artifacts //18 bytes
  350. if(map.version!=RoE)
  351. {
  352. ist=i; //starting i for loop
  353. for(i; i<ist+(map.version==AB ? 17 : 18); ++i)
  354. {
  355. unsigned char c = bufor[i];
  356. for(int yy=0; yy<8; ++yy)
  357. {
  358. if((i-ist)*8+yy < CGameInfo::mainObj->arth->artifacts.size())
  359. {
  360. if(c != (c|((unsigned char)intPow(2, yy))))
  361. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true;
  362. else
  363. CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false;
  364. }
  365. }
  366. }//allowed artifacts have been read
  367. }
  368. //reading allowed spells (9 bytes)
  369. if(map.version>=SoD)
  370. {
  371. ist=i; //starting i for loop
  372. for(i; i<ist+9; ++i)
  373. {
  374. unsigned char c = bufor[i];
  375. for(int yy=0; yy<8; ++yy)
  376. {
  377. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  378. {
  379. if(c != (c|((unsigned char)intPow(2, yy))))
  380. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true;
  381. else
  382. CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false;
  383. }
  384. }
  385. }
  386. //allowed spells have been read
  387. //allowed hero's abilities (4 bytes)
  388. ist=i; //starting i for loop
  389. for(i; i<ist+4; ++i)
  390. {
  391. unsigned char c = bufor[i];
  392. for(int yy=0; yy<8; ++yy)
  393. {
  394. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  395. {
  396. if(c != (c|((unsigned char)intPow(2, yy))))
  397. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = true;
  398. else
  399. CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = false;
  400. }
  401. }
  402. }
  403. }
  404. //allowed hero's abilities have been read
  405. THC std::cout<<"Reading header: "<<th.getDif()<<std::endl;
  406. int rumNr = readNormalNr(i,4);i+=4;
  407. for (int it=0;it<rumNr;it++)
  408. {
  409. Rumor ourRumor;
  410. int nameL = readNormalNr(i,4);i+=4; //read length of name of rumor
  411. for (int zz=0; zz<nameL; zz++)
  412. ourRumor.name+=bufor[i++];
  413. nameL = readNormalNr(i,4);i+=4; //read length of rumor
  414. for (int zz=0; zz<nameL; zz++)
  415. ourRumor.text+=bufor[i++];
  416. map.rumors.push_back(ourRumor); //add to our list
  417. }
  418. THC std::cout<<"Reading rumors: "<<th.getDif()<<std::endl;
  419. switch(map.version)
  420. {
  421. case WoG: case SoD: case AB:
  422. if(bufor[i]=='\0') //omit 156 bytes of rubbish
  423. {
  424. if(map.version>AB)
  425. i+=156;
  426. break;
  427. }
  428. else if(map.version!=AB || map.rumors.size()==0) //omit a lot of rubbish in a strage way
  429. {
  430. int lastFFpos=i;
  431. while(i-lastFFpos<200) //i far in terrain bytes
  432. {
  433. ++i;
  434. if(bufor[i]==0xff)
  435. {
  436. lastFFpos=i;
  437. }
  438. }
  439. i=lastFFpos;
  440. while(bufor[i-1]!=0 || bufor[i]>8 || bufor[i+2]>4 || bufor[i+1]==0) //back to terrain bytes
  441. {
  442. i++;
  443. }
  444. }
  445. break;
  446. case RoE:
  447. i+=0;
  448. break;
  449. }
  450. for (int c=0; c<map.width; c++) // reading terrain
  451. {
  452. for (int z=0; z<map.height; z++)
  453. {
  454. map.terrain[z][c].tertype = (EterrainType)(bufor[i++]);
  455. map.terrain[z][c].terview = bufor[i++];
  456. map.terrain[z][c].nuine = (Eriver)bufor[i++];
  457. map.terrain[z][c].rivDir = bufor[i++];
  458. map.terrain[z][c].malle = (Eroad)bufor[i++];
  459. map.terrain[z][c].roadDir = bufor[i++];
  460. map.terrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  461. }
  462. }
  463. if (map.twoLevel) // read underground terrain
  464. {
  465. for (int c=0; c<map.width; c++) // reading terrain
  466. {
  467. for (int z=0; z<map.height; z++)
  468. {
  469. map.undergroungTerrain[z][c].tertype = (EterrainType)(bufor[i++]);
  470. map.undergroungTerrain[z][c].terview = bufor[i++];
  471. map.undergroungTerrain[z][c].nuine = (Eriver)bufor[i++];
  472. map.undergroungTerrain[z][c].rivDir = bufor[i++];
  473. map.undergroungTerrain[z][c].malle = (Eroad)bufor[i++];
  474. map.undergroungTerrain[z][c].roadDir = bufor[i++];
  475. map.undergroungTerrain[z][c].siodmyTajemniczyBajt = bufor[i++];
  476. }
  477. }
  478. }
  479. THC std::cout<<"Reading terrain: "<<th.getDif()<<std::endl;
  480. int defAmount = bufor[i]; // liczba defow
  481. defAmount = readNormalNr(i);
  482. i+=4;
  483. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  484. int srmask = 0xff000000;
  485. int sgmask = 0x00ff0000;
  486. int sbmask = 0x0000ff00;
  487. int samask = 0x000000ff;
  488. #else
  489. int srmask = 0x000000ff;
  490. int sgmask = 0x0000ff00;
  491. int sbmask = 0x00ff0000;
  492. int samask = 0xff000000;
  493. #endif
  494. SDL_Surface * alphaTransSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 12, 12, 32, srmask, sgmask, sbmask, samask);
  495. std::vector<std::string> defsToUnpack;
  496. for (int idd = 0 ; idd<defAmount; idd++) // reading defs
  497. {
  498. int nameLength = readNormalNr(i,4);i+=4;
  499. CGDefInfo * vinya = new CGDefInfo(); // info about new def
  500. for (int cd=0;cd<nameLength;cd++)
  501. {
  502. vinya->name += bufor[i++];
  503. }
  504. //for (int v=0; v<42; v++) // read info
  505. //{
  506. // vinya->bytes[v] = bufor[i++];
  507. //}
  508. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  509. vinya->name);
  510. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  511. {
  512. vinya->isOnDefList = false;
  513. }
  514. else
  515. {
  516. //vinya->printPriority = pit->priority;
  517. vinya->isOnDefList = true;
  518. }
  519. unsigned char bytes[12];
  520. for (int v=0; v<12; v++) // read info
  521. {
  522. bytes[v] = bufor[i++];
  523. }
  524. vinya->terrainAllowed = readNormalNr(i,2);i+=2;
  525. vinya->terrainMenu = readNormalNr(i,2);i+=2;
  526. vinya->id = readNormalNr(i,4);i+=4;
  527. vinya->subid = readNormalNr(i,4);i+=4;
  528. vinya->type = bufor[i++];
  529. vinya->printPriority = bufor[i++];
  530. for (int zi=0; zi<6; zi++)
  531. {
  532. vinya->blockMap[zi] = reverse(bytes[zi]);
  533. }
  534. for (int zi=0; zi<6; zi++)
  535. {
  536. vinya->visitMap[zi] = reverse(bytes[6+zi]);
  537. }
  538. i+=16;
  539. map.defy.push_back(vinya); // add this def to the vector
  540. defsToUnpack.push_back(vinya->name);
  541. }
  542. THC std::cout<<"Reading defs: "<<th.getDif()<<std::endl;
  543. ////loading objects
  544. int howManyObjs = readNormalNr(i, 4); i+=4;
  545. for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
  546. {
  547. //std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
  548. CGObjectInstance * nobj = new CGObjectInstance(); //we will read this object
  549. nobj->id = CGameInfo::mainObj->objh->objInstances.size();
  550. nobj->pos.x = bufor[i++];
  551. nobj->pos.y = bufor[i++];
  552. nobj->pos.z = bufor[i++];
  553. int tempd = readNormalNr(i, 4); i+=4;
  554. nobj->defInfo = map.defy[tempd];
  555. nobj->ID = nobj->defInfo->id;
  556. nobj->subID = nobj->defInfo->subid;
  557. //nobj->defInfo = readNormalNr(i, 4); i+=4;
  558. //nobj->defObjInfoNumber = -1;
  559. //nobj->isHero = false;
  560. //nobj->moveDir = 0;
  561. //nobj->isStanding = true;
  562. //nobj->state->owner = 254; //a lot of objs will never have an owner
  563. //if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
  564. // std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
  565. i+=5;
  566. unsigned char buff [30];
  567. for(int ccc=0; ccc<30; ++ccc)
  568. {
  569. buff[ccc] = bufor[i+ccc];
  570. }
  571. EDefType uu = getDefType(nobj->defInfo);
  572. int j = nobj->defInfo->id;
  573. int p = 99;
  574. switch(uu)
  575. {
  576. case EDefType::EVENTOBJ_DEF: //for event - objects
  577. {
  578. CEventObjInfo * spec = new CEventObjInfo;
  579. bool guardMess;
  580. guardMess = bufor[i]; ++i;
  581. if(guardMess)
  582. {
  583. int messLong = readNormalNr(i, 4); i+=4;
  584. if(messLong>0)
  585. {
  586. spec->isMessage = true;
  587. for(int yy=0; yy<messLong; ++yy)
  588. {
  589. spec->message +=bufor[i+yy];
  590. }
  591. i+=messLong;
  592. }
  593. spec->areGuarders = bufor[i]; ++i;
  594. if(spec->areGuarders)
  595. {
  596. spec->guarders = readCreatureSet(i); i+=( map.version == RoE ? 21 : 28);
  597. }
  598. i+=4;
  599. }
  600. else
  601. {
  602. spec->isMessage = false;
  603. spec->areGuarders = false;
  604. spec->message = std::string("");
  605. }
  606. spec->gainedExp = readNormalNr(i, 4); i+=4;
  607. spec->manaDiff = readNormalNr(i, 4); i+=4;
  608. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  609. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  610. spec->wood = readNormalNr(i); i+=4;
  611. spec->mercury = readNormalNr(i); i+=4;
  612. spec->ore = readNormalNr(i); i+=4;
  613. spec->sulfur = readNormalNr(i); i+=4;
  614. spec->crystal = readNormalNr(i); i+=4;
  615. spec->gems = readNormalNr(i); i+=4;
  616. spec->gold = readNormalNr(i); i+=4;
  617. spec->attack = readNormalNr(i, 1); ++i;
  618. spec->defence = readNormalNr(i, 1); ++i;
  619. spec->power = readNormalNr(i, 1); ++i;
  620. spec->knowledge = readNormalNr(i, 1); ++i;
  621. int gabn; //number of gained abilities
  622. gabn = readNormalNr(i, 1); ++i;
  623. for(int oo = 0; oo<gabn; ++oo)
  624. {
  625. spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
  626. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  627. }
  628. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  629. for(int oo = 0; oo<gart; ++oo)
  630. {
  631. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, (map.version == RoE ? 1 : 2))])); i+=(map.version == RoE ? 1 : 2);
  632. }
  633. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  634. for(int oo = 0; oo<gspel; ++oo)
  635. {
  636. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  637. }
  638. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  639. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  640. i+=8;
  641. spec->availableFor = readNormalNr(i, 1); ++i;
  642. spec->computerActivate = readNormalNr(i, 1); ++i;
  643. spec->humanActivate = readNormalNr(i, 1); ++i;
  644. i+=4;
  645. nobj->info = spec;
  646. break;
  647. }
  648. case EDefType::HERO_DEF:
  649. {
  650. CHeroObjInfo * spec = new CHeroObjInfo;
  651. if(map.version>RoE)
  652. {
  653. spec->bytes[0] = bufor[i]; ++i;
  654. spec->bytes[1] = bufor[i]; ++i;
  655. spec->bytes[2] = bufor[i]; ++i;
  656. spec->bytes[3] = bufor[i]; ++i;
  657. }
  658. spec->player = bufor[i]; ++i;
  659. int typeBuf = readNormalNr(i, 1); ++i;
  660. if(typeBuf==0xff)
  661. spec->type = NULL;
  662. else
  663. spec->type = CGameInfo::mainObj->heroh->heroes[typeBuf];
  664. bool isName = bufor[i]; ++i; //true if hero has nonstandard name
  665. if(isName)
  666. {
  667. int length = readNormalNr(i, 4); i+=4;
  668. for(int gg=0; gg<length; ++gg)
  669. {
  670. spec->name+=bufor[i]; ++i;
  671. }
  672. }
  673. else
  674. spec->name = std::string("");
  675. if(map.version>AB)
  676. {
  677. bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0
  678. if(isExp)
  679. {
  680. spec->experience = readNormalNr(i); i+=4;
  681. }
  682. else
  683. spec->experience = 0;
  684. }
  685. else
  686. {
  687. spec->experience = readNormalNr(i); i+=4;
  688. }
  689. bool portrait=bufor[i]; ++i;
  690. if (portrait)
  691. i++; //TODO read portrait nr, save, open
  692. bool nonstandardAbilities = bufor[i]; ++i; //true if hero has specified abilities
  693. if(nonstandardAbilities)
  694. {
  695. int howMany = readNormalNr(i); i+=4;
  696. for(int yy=0; yy<howMany; ++yy)
  697. {
  698. spec->abilities.push_back(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)]); ++i;
  699. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  700. }
  701. }
  702. bool standGarrison = bufor[i]; ++i; //true if hero has nonstandard garrison
  703. spec->standardGarrison = standGarrison;
  704. if(standGarrison)
  705. {
  706. spec->garrison = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28); //4 bytes per slot
  707. }
  708. bool form = bufor[i]; ++i; //formation
  709. spec->garrison.formation = form;
  710. bool artSet = bufor[i]; ++i; //true if artifact set is not default (hero has some artifacts)
  711. int artmask = map.version == RoE ? 0xff : 0xffff;
  712. int artidlen = map.version == RoE ? 1 : 2;
  713. if(artSet)
  714. {
  715. //head art //1
  716. int id = readNormalNr(i, artidlen); i+=artidlen;
  717. if(id!=artmask)
  718. spec->artHead = &(CGameInfo::mainObj->arth->artifacts[id]);
  719. else
  720. spec->artHead = NULL;
  721. //shoulders art //2
  722. id = readNormalNr(i, artidlen); i+=artidlen;
  723. if(id!=artmask)
  724. spec->artShoulders = &(CGameInfo::mainObj->arth->artifacts[id]);
  725. else
  726. spec->artShoulders = NULL;
  727. //neck art //3
  728. id = readNormalNr(i, artidlen); i+=artidlen;
  729. if(id!=artmask)
  730. spec->artNeck = &(CGameInfo::mainObj->arth->artifacts[id]);
  731. else
  732. spec->artNeck = NULL;
  733. //right hand art //4
  734. id = readNormalNr(i, artidlen); i+=artidlen;
  735. if(id!=artmask)
  736. spec->artRhand = &(CGameInfo::mainObj->arth->artifacts[id]);
  737. else
  738. spec->artRhand = NULL;
  739. //left hand art //5
  740. id = readNormalNr(i, artidlen); i+=artidlen;
  741. if(id!=artmask)
  742. spec->artLHand = &(CGameInfo::mainObj->arth->artifacts[id]);
  743. else
  744. spec->artLHand = NULL;
  745. //torso art //6
  746. id = readNormalNr(i, artidlen); i+=artidlen;
  747. if(id!=artmask)
  748. spec->artTorso = &(CGameInfo::mainObj->arth->artifacts[id]);
  749. else
  750. spec->artTorso = NULL;
  751. //right hand ring //7
  752. id = readNormalNr(i, artidlen); i+=artidlen;
  753. if(id!=artmask)
  754. spec->artRRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  755. else
  756. spec->artRRing = NULL;
  757. //left hand ring //8
  758. id = readNormalNr(i, artidlen); i+=artidlen;
  759. if(id!=artmask)
  760. spec->artLRing = &(CGameInfo::mainObj->arth->artifacts[id]);
  761. else
  762. spec->artLRing = NULL;
  763. //feet art //9
  764. id = readNormalNr(i, artidlen); i+=artidlen;
  765. if(id!=artmask)
  766. spec->artFeet = &(CGameInfo::mainObj->arth->artifacts[id]);
  767. else
  768. spec->artFeet = NULL;
  769. //misc1 art //10
  770. id = readNormalNr(i, artidlen); i+=artidlen;
  771. if(id!=artmask)
  772. spec->artMisc1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  773. else
  774. spec->artMisc1 = NULL;
  775. //misc2 art //11
  776. id = readNormalNr(i, artidlen); i+=artidlen;
  777. if(id!=artmask)
  778. spec->artMisc2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  779. else
  780. spec->artMisc2 = NULL;
  781. //misc3 art //12
  782. id = readNormalNr(i, artidlen); i+=artidlen;
  783. if(id!=artmask)
  784. spec->artMisc3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  785. else
  786. spec->artMisc3 = NULL;
  787. //misc4 art //13
  788. id = readNormalNr(i, artidlen); i+=artidlen;
  789. if(id!=artmask)
  790. spec->artMisc4 = &(CGameInfo::mainObj->arth->artifacts[id]);
  791. else
  792. spec->artMisc4 = NULL;
  793. //machine1 art //14
  794. id = readNormalNr(i, artidlen); i+=artidlen;
  795. if(id!=artmask)
  796. spec->artMach1 = &(CGameInfo::mainObj->arth->artifacts[id]);
  797. else
  798. spec->artMach1 = NULL;
  799. //machine2 art //15
  800. id = readNormalNr(i, artidlen); i+=artidlen;
  801. if(id!=artmask)
  802. spec->artMach2 = &(CGameInfo::mainObj->arth->artifacts[id]);
  803. else
  804. spec->artMach2 = NULL;
  805. //machine3 art //16
  806. id = readNormalNr(i, artidlen); i+=artidlen;
  807. if(id!=artmask)
  808. spec->artMach3 = &(CGameInfo::mainObj->arth->artifacts[id]);
  809. else
  810. spec->artMach3 = NULL;
  811. //misc5 art //17
  812. if(map.version>=SoD)
  813. {
  814. id = readNormalNr(i, artidlen); i+=artidlen;
  815. if(id!=artmask)
  816. spec->artMisc5 = &(CGameInfo::mainObj->arth->artifacts[id]);
  817. else
  818. spec->artMisc5 = NULL;
  819. }
  820. //spellbook
  821. id = readNormalNr(i, artidlen); i+=artidlen;
  822. if(id!=artmask)
  823. spec->artSpellBook = &(CGameInfo::mainObj->arth->artifacts[id]);
  824. else
  825. spec->artSpellBook = NULL;
  826. //19 //???what is that? gap in file or what?
  827. if(map.version>RoE)
  828. i+=2;
  829. else
  830. i+=1;
  831. //bag artifacts //20
  832. int amount = readNormalNr(i, 2); i+=2; //number of artifacts in hero's bag
  833. if(amount>0)
  834. {
  835. for(int ss=0; ss<amount; ++ss)
  836. {
  837. id = readNormalNr(i, artidlen); i+=2;
  838. if(id!=artmask)
  839. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[id]));
  840. else
  841. spec->artifacts.push_back(NULL);
  842. }
  843. }
  844. } //artifacts
  845. spec->guardRange = readNormalNr(i, 1); ++i;
  846. if(spec->guardRange == 0xff)
  847. spec->isGuarding = false;
  848. else
  849. spec->isGuarding = true;
  850. if(map.version>RoE)
  851. {
  852. bool hasBiography = bufor[i]; ++i; //true if hero has nonstandard (mapmaker defined) biography
  853. if(hasBiography)
  854. {
  855. int length = readNormalNr(i); i+=4;
  856. int iStart = i;
  857. i+=length;
  858. for(int bb=0; bb<length; ++bb)
  859. {
  860. spec->biography+=bufor[iStart+bb];
  861. }
  862. }
  863. spec->sex = !(bufor[i]); ++i;
  864. }
  865. //spells
  866. if(map.version>AB)
  867. {
  868. bool areSpells = bufor[i]; ++i;
  869. if(areSpells) //TODO: sprawdziæ //seems to be ok - tow
  870. {
  871. int ist = i;
  872. for(i; i<ist+9; ++i)
  873. {
  874. unsigned char c = bufor[i];
  875. for(int yy=0; yy<8; ++yy)
  876. {
  877. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  878. {
  879. if(c == (c|((unsigned char)intPow(2, yy))))
  880. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  881. }
  882. }
  883. }
  884. }
  885. }
  886. else if(map.version==AB) //we can read one spell
  887. {
  888. unsigned char buff = bufor[i]; ++i;
  889. if(buff!=254)
  890. {
  891. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[buff]));
  892. }
  893. }
  894. //spells loaded
  895. if(map.version>AB)
  896. {
  897. spec->defaultMainStats = bufor[i]; ++i;
  898. if(spec->defaultMainStats)
  899. {
  900. spec->attack = bufor[i]; ++i;
  901. spec->defence = bufor[i]; ++i;
  902. spec->power = bufor[i]; ++i;
  903. spec->knowledge = bufor[i]; ++i;
  904. }
  905. else
  906. {
  907. spec->attack = -1;
  908. spec->defence = -1;
  909. spec->power = -1;
  910. spec->knowledge = -1;
  911. }
  912. }
  913. i+=16;
  914. nobj->info = spec;
  915. //////creating CHeroInstance
  916. CGHeroInstance * nhi = new CGHeroInstance;
  917. (*(static_cast<CGObjectInstance*>(nhi))) = *nobj;
  918. delete nobj;
  919. nobj=nhi;
  920. spec->myInstance = nhi;
  921. //nobj->isHero = true;
  922. (static_cast<CGHeroInstance*>(nobj))->moveDir = 4;
  923. nhi->isStanding = true;
  924. nhi->exp = spec->experience;
  925. nhi->level = CGI->heroh->level(nhi->exp);
  926. nhi->primSkills.resize(PRIMARY_SKILLS);
  927. nhi->primSkills[0] = spec->attack;
  928. nhi->primSkills[1] = spec->defence;
  929. nhi->primSkills[2] = spec->power;
  930. nhi->primSkills[3] = spec->knowledge;
  931. nhi->mana = spec->knowledge * 10;
  932. nhi->movement = -1;
  933. nhi->name = spec->name;
  934. nhi->setOwner(spec->player);
  935. nhi->pos = nobj->pos;
  936. nhi->type = spec->type;
  937. nhi->army = spec->garrison;
  938. nhi->portrait = -1; // TODO: przypisywac portret
  939. CGI->heroh->heroInstances.push_back(nhi);
  940. break;
  941. }
  942. case CREATURES_DEF:
  943. {
  944. CCreatureObjInfo * spec = new CCreatureObjInfo;
  945. if(map.version>RoE)
  946. {
  947. spec->bytes[0] = bufor[i]; ++i;
  948. spec->bytes[1] = bufor[i]; ++i;
  949. spec->bytes[2] = bufor[i]; ++i;
  950. spec->bytes[3] = bufor[i]; ++i;
  951. }
  952. spec->number = readNormalNr(i, 2); i+=2;
  953. spec->character = bufor[i]; ++i;
  954. bool isMesTre = bufor[i]; ++i; //true if there is message or treasury
  955. if(isMesTre)
  956. {
  957. int messLength = readNormalNr(i); i+=4;
  958. if(messLength>0)
  959. {
  960. for(int tt=0; tt<messLength; ++tt)
  961. {
  962. spec->message += bufor[i]; ++i;
  963. }
  964. }
  965. spec->wood = readNormalNr(i); i+=4;
  966. spec->mercury = readNormalNr(i); i+=4;
  967. spec->ore = readNormalNr(i); i+=4;
  968. spec->sulfur = readNormalNr(i); i+=4;
  969. spec->crytal = readNormalNr(i); i+=4;
  970. spec->gems = readNormalNr(i); i+=4;
  971. spec->gold = readNormalNr(i); i+=4;
  972. int artID = readNormalNr(i, (map.version == RoE ? 1 : 2)); i+=(map.version == RoE ? 1 : 2);
  973. if(map.version==RoE)
  974. {
  975. if(artID!=0xff)
  976. spec->gainedArtifact = &(CGameInfo::mainObj->arth->artifacts[artID]);
  977. else
  978. spec->gainedArtifact = NULL;
  979. }
  980. else
  981. {
  982. if(artID!=0xffff)
  983. spec->gainedArtifact = &(CGameInfo::mainObj->arth->artifacts[artID]);
  984. else
  985. spec->gainedArtifact = NULL;
  986. }
  987. }
  988. spec->neverFlees = bufor[i]; ++i;
  989. spec->notGrowingTeam = bufor[i]; ++i;
  990. i+=2;
  991. nobj->info = spec;
  992. break;
  993. }
  994. case EDefType::SIGN_DEF:
  995. {
  996. CSignObjInfo * spec = new CSignObjInfo;
  997. int length = readNormalNr(i); i+=4;
  998. for(int rr=0; rr<length; ++rr)
  999. {
  1000. spec->message += bufor[i]; ++i;
  1001. }
  1002. i+=4;
  1003. nobj->info = spec;
  1004. break;
  1005. }
  1006. case EDefType::SEERHUT_DEF:
  1007. {
  1008. CSeerHutObjInfo * spec = new CSeerHutObjInfo;
  1009. if(map.version>RoE)
  1010. {
  1011. spec->missionType = bufor[i]; ++i;
  1012. switch(spec->missionType)
  1013. {
  1014. case 0:
  1015. i+=3;
  1016. continue;
  1017. case 1:
  1018. {
  1019. spec->m1level = readNormalNr(i); i+=4;
  1020. int limit = readNormalNr(i); i+=4;
  1021. if(limit == ((int)0xffffffff))
  1022. {
  1023. spec->isDayLimit = false;
  1024. spec->lastDay = -1;
  1025. }
  1026. else
  1027. {
  1028. spec->isDayLimit = true;
  1029. spec->lastDay = limit;
  1030. }
  1031. break;
  1032. }
  1033. case 2:
  1034. {
  1035. spec->m2attack = bufor[i]; ++i;
  1036. spec->m2defence = bufor[i]; ++i;
  1037. spec->m2power = bufor[i]; ++i;
  1038. spec->m2knowledge = bufor[i]; ++i;
  1039. int limit = readNormalNr(i); i+=4;
  1040. if(limit == ((int)0xffffffff))
  1041. {
  1042. spec->isDayLimit = false;
  1043. spec->lastDay = -1;
  1044. }
  1045. else
  1046. {
  1047. spec->isDayLimit = true;
  1048. spec->lastDay = limit;
  1049. }
  1050. break;
  1051. }
  1052. case 3:
  1053. {
  1054. spec->m3bytes[0] = bufor[i]; ++i;
  1055. spec->m3bytes[1] = bufor[i]; ++i;
  1056. spec->m3bytes[2] = bufor[i]; ++i;
  1057. spec->m3bytes[3] = bufor[i]; ++i;
  1058. int limit = readNormalNr(i); i+=4;
  1059. if(limit == ((int)0xffffffff))
  1060. {
  1061. spec->isDayLimit = false;
  1062. spec->lastDay = -1;
  1063. }
  1064. else
  1065. {
  1066. spec->isDayLimit = true;
  1067. spec->lastDay = limit;
  1068. }
  1069. break;
  1070. }
  1071. case 4:
  1072. {
  1073. spec->m4bytes[0] = bufor[i]; ++i;
  1074. spec->m4bytes[1] = bufor[i]; ++i;
  1075. spec->m4bytes[2] = bufor[i]; ++i;
  1076. spec->m4bytes[3] = bufor[i]; ++i;
  1077. int limit = readNormalNr(i); i+=4;
  1078. if(limit == ((int)0xffffffff))
  1079. {
  1080. spec->isDayLimit = false;
  1081. spec->lastDay = -1;
  1082. }
  1083. else
  1084. {
  1085. spec->isDayLimit = true;
  1086. spec->lastDay = limit;
  1087. }
  1088. break;
  1089. }
  1090. case 5:
  1091. {
  1092. int artNumber = bufor[i]; ++i;
  1093. for(int yy=0; yy<artNumber; ++yy)
  1094. {
  1095. int artid = readNormalNr(i, 2); i+=2;
  1096. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  1097. }
  1098. int limit = readNormalNr(i); i+=4;
  1099. if(limit == ((int)0xffffffff))
  1100. {
  1101. spec->isDayLimit = false;
  1102. spec->lastDay = -1;
  1103. }
  1104. else
  1105. {
  1106. spec->isDayLimit = true;
  1107. spec->lastDay = limit;
  1108. }
  1109. break;
  1110. }
  1111. case 6:
  1112. {
  1113. int typeNumber = bufor[i]; ++i;
  1114. for(int hh=0; hh<typeNumber; ++hh)
  1115. {
  1116. int creType = readNormalNr(i, 2); i+=2;
  1117. int creNumb = readNormalNr(i, 2); i+=2;
  1118. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  1119. spec->m6number.push_back(creNumb);
  1120. }
  1121. int limit = readNormalNr(i); i+=4;
  1122. if(limit == ((int)0xffffffff))
  1123. {
  1124. spec->isDayLimit = false;
  1125. spec->lastDay = -1;
  1126. }
  1127. else
  1128. {
  1129. spec->isDayLimit = true;
  1130. spec->lastDay = limit;
  1131. }
  1132. break;
  1133. }
  1134. case 7:
  1135. {
  1136. spec->m7wood = readNormalNr(i); i+=4;
  1137. spec->m7mercury = readNormalNr(i); i+=4;
  1138. spec->m7ore = readNormalNr(i); i+=4;
  1139. spec->m7sulfur = readNormalNr(i); i+=4;
  1140. spec->m7crystal = readNormalNr(i); i+=4;
  1141. spec->m7gems = readNormalNr(i); i+=4;
  1142. spec->m7gold = readNormalNr(i); i+=4;
  1143. int limit = readNormalNr(i); i+=4;
  1144. if(limit == ((int)0xffffffff))
  1145. {
  1146. spec->isDayLimit = false;
  1147. spec->lastDay = -1;
  1148. }
  1149. else
  1150. {
  1151. spec->isDayLimit = true;
  1152. spec->lastDay = limit;
  1153. }
  1154. break;
  1155. }
  1156. case 8:
  1157. {
  1158. int heroType = bufor[i]; ++i;
  1159. spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
  1160. int limit = readNormalNr(i); i+=4;
  1161. if(limit == ((int)0xffffffff))
  1162. {
  1163. spec->isDayLimit = false;
  1164. spec->lastDay = -1;
  1165. }
  1166. else
  1167. {
  1168. spec->isDayLimit = true;
  1169. spec->lastDay = limit;
  1170. }
  1171. break;
  1172. }
  1173. case 9:
  1174. {
  1175. spec->m9player = bufor[i]; ++i;
  1176. int limit = readNormalNr(i); i+=4;
  1177. if(limit == ((int)0xffffffff))
  1178. {
  1179. spec->isDayLimit = false;
  1180. spec->lastDay = -1;
  1181. }
  1182. else
  1183. {
  1184. spec->isDayLimit = true;
  1185. spec->lastDay = limit;
  1186. }
  1187. break;
  1188. }
  1189. }//internal switch end (seer huts)
  1190. int len1 = readNormalNr(i); i+=4;
  1191. for(int ee=0; ee<len1; ++ee)
  1192. {
  1193. spec->firstVisitText += bufor[i]; ++i;
  1194. }
  1195. int len2 = readNormalNr(i); i+=4;
  1196. for(int ee=0; ee<len2; ++ee)
  1197. {
  1198. spec->nextVisitText += bufor[i]; ++i;
  1199. }
  1200. int len3 = readNormalNr(i); i+=4;
  1201. for(int ee=0; ee<len3; ++ee)
  1202. {
  1203. spec->completedText += bufor[i]; ++i;
  1204. }
  1205. }
  1206. else //RoE
  1207. {
  1208. int artID = bufor[i]; ++i;
  1209. if(artID!=255) //not none quest
  1210. {
  1211. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artID]));
  1212. spec->missionType = 5;
  1213. }
  1214. else
  1215. {
  1216. spec->missionType = 255;
  1217. }
  1218. }
  1219. if(spec->missionType!=255)
  1220. {
  1221. unsigned char rewardType = bufor[i]; ++i;
  1222. spec->rewardType = rewardType;
  1223. switch(rewardType)
  1224. {
  1225. case 1:
  1226. {
  1227. spec->r1exp = readNormalNr(i); i+=4;
  1228. break;
  1229. }
  1230. case 2:
  1231. {
  1232. spec->r2mana = readNormalNr(i); i+=4;
  1233. break;
  1234. }
  1235. case 3:
  1236. {
  1237. spec->r3morale = bufor[i]; ++i;
  1238. break;
  1239. }
  1240. case 4:
  1241. {
  1242. spec->r4luck = bufor[i]; ++i;
  1243. break;
  1244. }
  1245. case 5:
  1246. {
  1247. spec->r5type = bufor[i]; ++i;
  1248. spec->r5amount = readNormalNr(i, 3); i+=3;
  1249. i+=1;
  1250. break;
  1251. }
  1252. case 6:
  1253. {
  1254. spec->r6type = bufor[i]; ++i;
  1255. spec->r6amount = bufor[i]; ++i;
  1256. break;
  1257. }
  1258. case 7:
  1259. {
  1260. int abid = bufor[i]; ++i;
  1261. spec->r7ability = CGameInfo::mainObj->abilh->abilities[abid];
  1262. spec->r7level = bufor[i]; ++i;
  1263. break;
  1264. }
  1265. case 8:
  1266. {
  1267. int artid = readNormalNr(i, (map.version == RoE ? 1 : 2)); i+=(map.version == RoE ? 1 : 2);
  1268. spec->r8art = &(CGameInfo::mainObj->arth->artifacts[artid]);
  1269. break;
  1270. }
  1271. case 9:
  1272. {
  1273. int spellid = bufor[i]; ++i;
  1274. spec->r9spell = &(CGameInfo::mainObj->spellh->spells[spellid]);
  1275. break;
  1276. }
  1277. case 10:
  1278. {
  1279. int creid = readNormalNr(i, 2); i+=2;
  1280. spec->r10creature = &(CGameInfo::mainObj->creh->creatures[creid]);
  1281. spec->r10amount = readNormalNr(i, 2); i+=2;
  1282. break;
  1283. }
  1284. }// end of internal switch
  1285. i+=2;
  1286. }
  1287. else //missionType==255
  1288. {
  1289. i+=3;
  1290. }
  1291. nobj->info = spec;
  1292. break;
  1293. }
  1294. case EDefType::WITCHHUT_DEF:
  1295. {
  1296. CWitchHutObjInfo * spec = new CWitchHutObjInfo;
  1297. if(map.version>RoE) //in reo we cannot specify it - all are allowed (I hope)
  1298. {
  1299. ist=i; //starting i for loop
  1300. for(i; i<ist+4; ++i)
  1301. {
  1302. unsigned char c = bufor[i];
  1303. for(int yy=0; yy<8; ++yy)
  1304. {
  1305. if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
  1306. {
  1307. if(c == (c|((unsigned char)intPow(2, yy))))
  1308. spec->allowedAbilities.push_back(CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]);
  1309. }
  1310. }
  1311. }
  1312. }
  1313. else //(RoE map)
  1314. {
  1315. for(int gg=0; gg<CGameInfo::mainObj->abilh->abilities.size(); ++gg)
  1316. {
  1317. spec->allowedAbilities.push_back(CGameInfo::mainObj->abilh->abilities[gg]);
  1318. }
  1319. }
  1320. nobj->info = spec;
  1321. break;
  1322. }
  1323. case EDefType::SCHOLAR_DEF:
  1324. {
  1325. CScholarObjInfo * spec = new CScholarObjInfo;
  1326. spec->bonusType = bufor[i]; ++i;
  1327. switch(spec->bonusType)
  1328. {
  1329. case 0xff:
  1330. ++i;
  1331. break;
  1332. case 0:
  1333. spec->r0type = bufor[i]; ++i;
  1334. break;
  1335. case 1:
  1336. spec->r1 = CGameInfo::mainObj->abilh->abilities[bufor[i]]; ++i;
  1337. break;
  1338. case 2:
  1339. spec->r2 = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1340. break;
  1341. }
  1342. i+=6;
  1343. nobj->info = spec;
  1344. break;
  1345. }
  1346. case EDefType::GARRISON_DEF:
  1347. {
  1348. CGarrisonObjInfo * spec = new CGarrisonObjInfo;
  1349. spec->player = bufor[i]; ++i;
  1350. i+=3;
  1351. spec->units = readCreatureSet(i); i+= (map.version==RoE ? 21 : 28);
  1352. if(map.version > RoE)
  1353. {
  1354. spec->movableUnits = bufor[i]; ++i;
  1355. }
  1356. else
  1357. spec->movableUnits = true;
  1358. i+=8;
  1359. nobj->setOwner(spec->player);
  1360. nobj->info = spec;
  1361. break;
  1362. }
  1363. case EDefType::ARTIFACT_DEF:
  1364. {
  1365. CArtifactObjInfo * spec = new CArtifactObjInfo;
  1366. bool areSettings = bufor[i]; ++i;
  1367. if(areSettings)
  1368. {
  1369. int messLength = readNormalNr(i, 4); i+=4;
  1370. for(int hh=0; hh<messLength; ++hh)
  1371. {
  1372. spec->message += bufor[i]; ++i;
  1373. }
  1374. bool areGuards = bufor[i]; ++i;
  1375. if(areGuards)
  1376. {
  1377. spec->areGuards = true;
  1378. spec->guards = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28) ;
  1379. }
  1380. else
  1381. spec->areGuards = false;
  1382. i+=4;
  1383. }
  1384. nobj->info = spec;
  1385. break;
  1386. }
  1387. case EDefType::RESOURCE_DEF:
  1388. {
  1389. CResourceObjInfo * spec = new CResourceObjInfo;
  1390. bool isMessGuard = bufor[i]; ++i;
  1391. if(isMessGuard)
  1392. {
  1393. int messLength = readNormalNr(i); i+=4;
  1394. for(int mm=0; mm<messLength; ++mm)
  1395. {
  1396. spec->message+=bufor[i]; ++i;
  1397. }
  1398. spec->areGuards = bufor[i]; ++i;
  1399. if(spec->areGuards)
  1400. {
  1401. spec->guards = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28);
  1402. }
  1403. i+=4;
  1404. }
  1405. else
  1406. {
  1407. spec->areGuards = false;
  1408. }
  1409. spec->amount = readNormalNr(i); i+=4;
  1410. i+=4;
  1411. nobj->info = spec;
  1412. break;
  1413. }
  1414. case EDefType::TOWN_DEF:
  1415. {
  1416. CCastleObjInfo * spec = new CCastleObjInfo;
  1417. if(map.version!=RoE)
  1418. {
  1419. spec->bytes[0] = bufor[i]; ++i;
  1420. spec->bytes[1] = bufor[i]; ++i;
  1421. spec->bytes[2] = bufor[i]; ++i;
  1422. spec->bytes[3] = bufor[i]; ++i;
  1423. }
  1424. else
  1425. {
  1426. spec->bytes[0] = 0;
  1427. spec->bytes[1] = 0;
  1428. spec->bytes[2] = 0;
  1429. spec->bytes[3] = 0;
  1430. }
  1431. spec->player = bufor[i]; ++i;
  1432. bool hasName = bufor[i]; ++i;
  1433. if(hasName)
  1434. {
  1435. int len = readNormalNr(i); i+=4;
  1436. for(int gg=0; gg<len; ++gg)
  1437. {
  1438. spec->name += bufor[i]; ++i;
  1439. }
  1440. }
  1441. bool stGarr = bufor[i]; ++i; //true if garrison isn't empty
  1442. if(stGarr)
  1443. {
  1444. spec->garrison = readCreatureSet(i); i+=( map.version > RoE ? 28 : 21 );
  1445. }
  1446. spec->garrison.formation = bufor[i]; ++i;
  1447. spec->unusualBuildins = bufor[i]; ++i;
  1448. if(spec->unusualBuildins)
  1449. {
  1450. for(int ff=0; ff<12; ++ff)
  1451. {
  1452. spec->buildingSettings[ff] = bufor[i]; ++i;
  1453. }
  1454. }
  1455. else
  1456. {
  1457. spec->hasFort = bufor[i]; ++i;
  1458. }
  1459. int ist = i;
  1460. if(map.version>RoE)
  1461. {
  1462. for(i; i<ist+9; ++i)
  1463. {
  1464. unsigned char c = bufor[i];
  1465. for(int yy=0; yy<8; ++yy)
  1466. {
  1467. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  1468. {
  1469. if(c == (c|((unsigned char)intPow(2, yy))))
  1470. spec->obligatorySpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  1471. }
  1472. }
  1473. }
  1474. }
  1475. ist = i;
  1476. for(i; i<ist+9; ++i)
  1477. {
  1478. unsigned char c = bufor[i];
  1479. for(int yy=0; yy<8; ++yy)
  1480. {
  1481. if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
  1482. {
  1483. if(c != (c|((unsigned char)intPow(2, yy))))
  1484. spec->possibleSpells.push_back(&(CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy]));
  1485. }
  1486. }
  1487. }
  1488. /////// reading castle events //////////////////////////////////
  1489. int numberOfEvent = readNormalNr(i); i+=4;
  1490. for(int gh = 0; gh<numberOfEvent; ++gh)
  1491. {
  1492. CCastleEvent nce;
  1493. int nameLen = readNormalNr(i); i+=4;
  1494. for(int ll=0; ll<nameLen; ++ll)
  1495. {
  1496. nce.name += bufor[i]; ++i;
  1497. }
  1498. int messLen = readNormalNr(i); i+=4;
  1499. for(int ll=0; ll<messLen; ++ll)
  1500. {
  1501. nce.message += bufor[i]; ++i;
  1502. }
  1503. nce.wood = readNormalNr(i); i+=4;
  1504. nce.mercury = readNormalNr(i); i+=4;
  1505. nce.ore = readNormalNr(i); i+=4;
  1506. nce.sulfur = readNormalNr(i); i+=4;
  1507. nce.crystal = readNormalNr(i); i+=4;
  1508. nce.gems = readNormalNr(i); i+=4;
  1509. nce.gold = readNormalNr(i); i+=4;
  1510. nce.players = bufor[i]; ++i;
  1511. if(map.version > AB)
  1512. {
  1513. nce.forHuman = bufor[i]; ++i;
  1514. }
  1515. else
  1516. nce.forHuman = true;
  1517. nce.forComputer = bufor[i]; ++i;
  1518. nce.firstShow = readNormalNr(i, 2); i+=2;
  1519. nce.forEvery = bufor[i]; ++i;
  1520. i+=17;
  1521. for(int kk=0; kk<6; ++kk)
  1522. {
  1523. nce.bytes[kk] = bufor[i]; ++i;
  1524. }
  1525. for(int vv=0; vv<7; ++vv)
  1526. {
  1527. nce.gen[vv] = readNormalNr(i, 2); i+=2;
  1528. }
  1529. i+=4;
  1530. spec->events.push_back(nce);
  1531. }
  1532. spec->x = nobj->pos.x;
  1533. spec->y = nobj->pos.y;
  1534. spec->z = nobj->pos.z;
  1535. /////// castle events have been read ///////////////////////////
  1536. if(map.version > AB)
  1537. {
  1538. spec->alignment = bufor[i]; ++i;
  1539. }
  1540. else
  1541. spec->alignment = 0xff;
  1542. i+=3;
  1543. nobj->info = spec;
  1544. //////////// rewriting info to CTownInstance class /////////////////////
  1545. CGTownInstance * nt = new CGTownInstance();
  1546. (*(static_cast<CGObjectInstance*>(nt))) = *nobj;
  1547. delete nobj;
  1548. nobj = nt;
  1549. if(spec->unusualBuildins)
  1550. {
  1551. nt->builtBuildings.insert(10);
  1552. for(int ir = 0; ir < 6; ir++)
  1553. {
  1554. for(int bs=0;bs<8;bs++)
  1555. {
  1556. if(ir==0)
  1557. {
  1558. if (bs<3)
  1559. {
  1560. if(spec->buildingSettings[ir] & (1<<bs))
  1561. {
  1562. nt->builtBuildings.insert(11+bs);
  1563. }
  1564. }
  1565. else if (bs<6)
  1566. {
  1567. if(spec->buildingSettings[ir] & (1<<bs))
  1568. {
  1569. nt->builtBuildings.insert(7+bs-3);
  1570. }
  1571. }
  1572. else if(bs==6)
  1573. {
  1574. if(spec->buildingSettings[ir] & (1<<bs))
  1575. {
  1576. nt->builtBuildings.insert(5);
  1577. }
  1578. }
  1579. else// if(bs==7)
  1580. {
  1581. if(spec->buildingSettings[ir] & (1<<bs))
  1582. {
  1583. nt->builtBuildings.insert(16);
  1584. }
  1585. }
  1586. } //if(ir==0)
  1587. else if(ir==1)
  1588. {
  1589. if(bs<2)
  1590. {
  1591. if(spec->buildingSettings[ir] & (1<<bs))
  1592. {
  1593. nt->builtBuildings.insert(14+bs);
  1594. }
  1595. }
  1596. else if (bs==2)
  1597. {
  1598. if(spec->buildingSettings[ir] & (1<<bs))
  1599. {
  1600. std::cout<<"Hej, sprawdz co to za budynek w miescie " <<nt<<std::endl;
  1601. }
  1602. }//bs==3 - not known what it is, 4 in 2. byte
  1603. else
  1604. {
  1605. if(spec->buildingSettings[ir] & (1<<bs))
  1606. {
  1607. nt->builtBuildings.insert(0+bs-3);
  1608. }
  1609. }
  1610. }//else if(ir==1)
  1611. else if(ir==2)
  1612. {
  1613. if(bs==0)
  1614. {
  1615. if(spec->buildingSettings[ir] & (1<<bs))
  1616. {
  1617. nt->builtBuildings.insert(6); //stocznia
  1618. }
  1619. }
  1620. else if(bs==1)
  1621. {
  1622. if(spec->buildingSettings[ir] & (1<<bs))
  1623. {
  1624. nt->builtBuildings.insert(26); //grail
  1625. }
  1626. }
  1627. else if(bs==2)
  1628. {
  1629. if(spec->buildingSettings[ir] & (1<<bs))
  1630. {
  1631. nt->builtBuildings.insert(17); //latarnia
  1632. }
  1633. }
  1634. else if(bs==3)
  1635. {
  1636. if(spec->buildingSettings[ir] & (1<<bs))
  1637. {
  1638. nt->builtBuildings.insert(22); //bractwo miecza
  1639. }
  1640. }
  1641. else if(bs==4)
  1642. {
  1643. if(spec->buildingSettings[ir] & (1<<bs))
  1644. {
  1645. nt->builtBuildings.insert(21); //stables
  1646. }
  1647. }
  1648. else if(bs==5)
  1649. {
  1650. if(spec->buildingSettings[ir] & (1<<bs))
  1651. {
  1652. std::cout<<"Hej, sprawdz co to za budynek2 w miescie " <<nt<<std::endl;
  1653. }
  1654. }
  1655. else if(bs==6)
  1656. {
  1657. if(spec->buildingSettings[ir] & (1<<bs))
  1658. {
  1659. nt->builtBuildings.insert(30); //gen1
  1660. }
  1661. }
  1662. else if(bs==7)
  1663. {
  1664. if(spec->buildingSettings[ir] & (1<<bs))
  1665. {
  1666. nt->builtBuildings.insert(37); //gen1+
  1667. }
  1668. }
  1669. }//else if(ir==2)
  1670. else if (ir==3)
  1671. {
  1672. if(bs==0)
  1673. {
  1674. if(spec->buildingSettings[ir] & (1<<bs))
  1675. {
  1676. std::cout<<"Hej, sprawdz co to za budynek3 w miescie " <<nt<<std::endl;
  1677. }
  1678. continue;
  1679. }
  1680. else if(bs<3)
  1681. {
  1682. if(bs==1)
  1683. {
  1684. if(spec->buildingSettings[ir] & (1<<bs))
  1685. {
  1686. nt->builtBuildings.insert(31); //gen2
  1687. }
  1688. }
  1689. else
  1690. {
  1691. if(spec->buildingSettings[ir] & (1<<bs))
  1692. {
  1693. nt->builtBuildings.insert(38); //gen2+
  1694. }
  1695. }
  1696. }
  1697. else if (bs==3)
  1698. {
  1699. if(spec->buildingSettings[ir] & (1<<bs))
  1700. {
  1701. std::cout<<"Hej, sprawdz co to za budynek4 w miescie " <<nt<<std::endl;
  1702. }
  1703. continue;
  1704. }
  1705. else
  1706. {
  1707. if(bs%2) //nieulepszone
  1708. {
  1709. if(spec->buildingSettings[ir] & (1<<bs))
  1710. {
  1711. nt->builtBuildings.insert((int)(39+(bs/2)-2));
  1712. }
  1713. }
  1714. else
  1715. {
  1716. if(spec->buildingSettings[ir] & (1<<bs))
  1717. {
  1718. nt->builtBuildings.insert(32+(bs/2)-2);
  1719. }
  1720. }
  1721. }
  1722. }//else if (ir==3)
  1723. else if (ir==4)
  1724. {
  1725. if(bs%2) //ulepszone
  1726. {
  1727. if(spec->buildingSettings[ir] & (1<<bs))
  1728. {
  1729. nt->builtBuildings.insert(40+(bs/2));
  1730. }
  1731. }
  1732. else
  1733. {
  1734. if(spec->buildingSettings[ir] & (1<<bs))
  1735. {
  1736. nt->builtBuildings.insert((int)(34+(bs/2)));
  1737. }
  1738. }
  1739. }//else if (ir==4)
  1740. else if (ir==5)
  1741. {
  1742. if(bs==0)
  1743. {
  1744. if(spec->buildingSettings[ir] & (1<<bs))
  1745. {
  1746. nt->builtBuildings.insert(43); //gen7+
  1747. }
  1748. }
  1749. }//else if (ir==5)
  1750. }
  1751. }
  1752. }
  1753. else
  1754. {
  1755. if(spec->hasFort)
  1756. {
  1757. nt->builtBuildings.insert(7);
  1758. }
  1759. }
  1760. nt->setOwner(spec->player);
  1761. nt->town = &CGI->townh->towns[nt->defInfo->subid];
  1762. nt->builded = 0;
  1763. nt->destroyed = 0;
  1764. nt->name = spec->name;
  1765. nt->garrison = spec->garrison;
  1766. nt->garrisonHero = NULL;// spec->garnisonHero is not readed - TODO: readit
  1767. nt->pos = int3(spec->x, spec->y, spec->z);
  1768. nt->possibleSpells = spec->possibleSpells;
  1769. nt->obligatorySpells = spec->obligatorySpells;
  1770. nt->availableSpells = std::vector<CSpell*>();
  1771. nt->creatureIncome = std::vector<int>();
  1772. nt->creaturesLeft = std::vector<int>();
  1773. CGI->townh->townInstances.push_back(nt);
  1774. break;
  1775. }
  1776. case EDefType::PLAYERONLY_DEF:
  1777. {
  1778. CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
  1779. spec->player = bufor[i]; ++i;
  1780. i+=3;
  1781. nobj->setOwner(spec->player);
  1782. nobj->info = spec;
  1783. break;
  1784. }
  1785. case EDefType::SHRINE_DEF:
  1786. {
  1787. CShrineObjInfo * spec = new CShrineObjInfo;
  1788. spec->spell = bufor[i]; i+=4;
  1789. nobj->info = spec;
  1790. break;
  1791. }
  1792. case EDefType::SPELLSCROLL_DEF:
  1793. {
  1794. CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
  1795. bool messg = bufor[i]; ++i;
  1796. if(messg)
  1797. {
  1798. int mLength = readNormalNr(i); i+=4;
  1799. for(int vv=0; vv<mLength; ++vv)
  1800. {
  1801. spec->message += bufor[i]; ++i;
  1802. }
  1803. spec->areGuarders = bufor[i]; ++i;
  1804. if(spec->areGuarders)
  1805. {
  1806. spec->guarders = readCreatureSet(i); i+=( map.version == RoE ? 21 : 28 );
  1807. }
  1808. i+=4;
  1809. }
  1810. spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1811. i+=3;
  1812. nobj->info = spec;
  1813. break;
  1814. }
  1815. case EDefType::PANDORA_DEF:
  1816. {
  1817. CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
  1818. bool messg = bufor[i]; ++i;
  1819. if(messg)
  1820. {
  1821. int mLength = readNormalNr(i); i+=4;
  1822. for(int vv=0; vv<mLength; ++vv)
  1823. {
  1824. spec->message += bufor[i]; ++i;
  1825. }
  1826. spec->areGuarders = bufor[i]; ++i;
  1827. if(spec->areGuarders)
  1828. {
  1829. spec->guarders = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28);
  1830. }
  1831. i+=4;
  1832. }
  1833. ////// copied form event handling (seems to be similar)
  1834. spec->gainedExp = readNormalNr(i, 4); i+=4;
  1835. spec->manaDiff = readNormalNr(i, 4); i+=4;
  1836. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  1837. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  1838. spec->wood = readNormalNr(i); i+=4;
  1839. spec->mercury = readNormalNr(i); i+=4;
  1840. spec->ore = readNormalNr(i); i+=4;
  1841. spec->sulfur = readNormalNr(i); i+=4;
  1842. spec->crystal = readNormalNr(i); i+=4;
  1843. spec->gems = readNormalNr(i); i+=4;
  1844. spec->gold = readNormalNr(i); i+=4;
  1845. spec->attack = readNormalNr(i, 1); ++i;
  1846. spec->defence = readNormalNr(i, 1); ++i;
  1847. spec->power = readNormalNr(i, 1); ++i;
  1848. spec->knowledge = readNormalNr(i, 1); ++i;
  1849. int gabn; //number of gained abilities
  1850. gabn = readNormalNr(i, 1); ++i;
  1851. for(int oo = 0; oo<gabn; ++oo)
  1852. {
  1853. spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
  1854. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  1855. }
  1856. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  1857. for(int oo = 0; oo<gart; ++oo)
  1858. {
  1859. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  1860. }
  1861. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  1862. for(int oo = 0; oo<gspel; ++oo)
  1863. {
  1864. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  1865. }
  1866. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  1867. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  1868. i+=8;
  1869. nobj->info = spec;
  1870. ///////end of copied fragment
  1871. break;
  1872. }
  1873. case EDefType::GRAIL_DEF:
  1874. {
  1875. CGrailObjInfo * spec = new CGrailObjInfo;
  1876. spec->radius = readNormalNr(i); i+=4;
  1877. nobj->info = spec;
  1878. break;
  1879. }
  1880. case EDefType::CREGEN_DEF:
  1881. {
  1882. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1883. spec->player = bufor[i]; ++i;
  1884. i+=3;
  1885. for(int ggg=0; ggg<4; ++ggg)
  1886. {
  1887. spec->bytes[ggg] = bufor[i]; ++i;
  1888. }
  1889. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1890. {
  1891. spec->asCastle = false;
  1892. spec->castles[0] = bufor[i]; ++i;
  1893. spec->castles[1] = bufor[i]; ++i;
  1894. }
  1895. else
  1896. {
  1897. spec->asCastle = true;
  1898. }
  1899. nobj->setOwner(spec->player);
  1900. nobj->info = spec;
  1901. break;
  1902. }
  1903. case EDefType::CREGEN2_DEF:
  1904. {
  1905. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1906. spec->player = bufor[i]; ++i;
  1907. i+=3;
  1908. for(int ggg=0; ggg<4; ++ggg)
  1909. {
  1910. spec->bytes[ggg] = bufor[i]; ++i;
  1911. }
  1912. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1913. {
  1914. spec->asCastle = false;
  1915. spec->castles[0] = bufor[i]; ++i;
  1916. spec->castles[1] = bufor[i]; ++i;
  1917. }
  1918. else
  1919. {
  1920. spec->asCastle = true;
  1921. }
  1922. spec->minLevel = bufor[i]; ++i;
  1923. spec->maxLevel = bufor[i]; ++i;
  1924. if(spec->maxLevel>7)
  1925. spec->maxLevel = 7;
  1926. if(spec->minLevel<1)
  1927. spec->minLevel = 1;
  1928. nobj->setOwner(spec->player);
  1929. nobj->info = spec;
  1930. break;
  1931. }
  1932. case EDefType::CREGEN3_DEF:
  1933. {
  1934. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1935. spec->player = bufor[i]; ++i;
  1936. i+=3;
  1937. spec->minLevel = bufor[i]; ++i;
  1938. spec->maxLevel = bufor[i]; ++i;
  1939. if(spec->maxLevel>7)
  1940. spec->maxLevel = 7;
  1941. if(spec->minLevel<1)
  1942. spec->minLevel = 1;
  1943. nobj->setOwner(spec->player);
  1944. nobj->info = spec;
  1945. break;
  1946. }
  1947. case EDefType::BORDERGUARD_DEF:
  1948. {
  1949. CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
  1950. spec->missionType = bufor[i]; ++i;
  1951. switch(spec->missionType)
  1952. {
  1953. case 1:
  1954. {
  1955. spec->m1level = readNormalNr(i); i+=4;
  1956. int limit = readNormalNr(i); i+=4;
  1957. if(limit == ((int)0xffffffff))
  1958. {
  1959. spec->isDayLimit = false;
  1960. spec->lastDay = -1;
  1961. }
  1962. else
  1963. {
  1964. spec->isDayLimit = true;
  1965. spec->lastDay = limit;
  1966. }
  1967. break;
  1968. }
  1969. case 2:
  1970. {
  1971. spec->m2attack = bufor[i]; ++i;
  1972. spec->m2defence = bufor[i]; ++i;
  1973. spec->m2power = bufor[i]; ++i;
  1974. spec->m2knowledge = bufor[i]; ++i;
  1975. int limit = readNormalNr(i); i+=4;
  1976. if(limit == ((int)0xffffffff))
  1977. {
  1978. spec->isDayLimit = false;
  1979. spec->lastDay = -1;
  1980. }
  1981. else
  1982. {
  1983. spec->isDayLimit = true;
  1984. spec->lastDay = limit;
  1985. }
  1986. break;
  1987. }
  1988. case 3:
  1989. {
  1990. spec->m3bytes[0] = bufor[i]; ++i;
  1991. spec->m3bytes[1] = bufor[i]; ++i;
  1992. spec->m3bytes[2] = bufor[i]; ++i;
  1993. spec->m3bytes[3] = bufor[i]; ++i;
  1994. int limit = readNormalNr(i); i+=4;
  1995. if(limit == ((int)0xffffffff))
  1996. {
  1997. spec->isDayLimit = false;
  1998. spec->lastDay = -1;
  1999. }
  2000. else
  2001. {
  2002. spec->isDayLimit = true;
  2003. spec->lastDay = limit;
  2004. }
  2005. break;
  2006. }
  2007. case 4:
  2008. {
  2009. spec->m4bytes[0] = bufor[i]; ++i;
  2010. spec->m4bytes[1] = bufor[i]; ++i;
  2011. spec->m4bytes[2] = bufor[i]; ++i;
  2012. spec->m4bytes[3] = bufor[i]; ++i;
  2013. int limit = readNormalNr(i); i+=4;
  2014. if(limit == ((int)0xffffffff))
  2015. {
  2016. spec->isDayLimit = false;
  2017. spec->lastDay = -1;
  2018. }
  2019. else
  2020. {
  2021. spec->isDayLimit = true;
  2022. spec->lastDay = limit;
  2023. }
  2024. break;
  2025. }
  2026. case 5:
  2027. {
  2028. int artNumber = bufor[i]; ++i;
  2029. for(int yy=0; yy<artNumber; ++yy)
  2030. {
  2031. int artid = readNormalNr(i, 2); i+=2;
  2032. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  2033. }
  2034. int limit = readNormalNr(i); i+=4;
  2035. if(limit == ((int)0xffffffff))
  2036. {
  2037. spec->isDayLimit = false;
  2038. spec->lastDay = -1;
  2039. }
  2040. else
  2041. {
  2042. spec->isDayLimit = true;
  2043. spec->lastDay = limit;
  2044. }
  2045. break;
  2046. }
  2047. case 6:
  2048. {
  2049. int typeNumber = bufor[i]; ++i;
  2050. for(int hh=0; hh<typeNumber; ++hh)
  2051. {
  2052. int creType = readNormalNr(i, 2); i+=2;
  2053. int creNumb = readNormalNr(i, 2); i+=2;
  2054. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  2055. spec->m6number.push_back(creNumb);
  2056. }
  2057. int limit = readNormalNr(i); i+=4;
  2058. if(limit == ((int)0xffffffff))
  2059. {
  2060. spec->isDayLimit = false;
  2061. spec->lastDay = -1;
  2062. }
  2063. else
  2064. {
  2065. spec->isDayLimit = true;
  2066. spec->lastDay = limit;
  2067. }
  2068. break;
  2069. }
  2070. case 7:
  2071. {
  2072. spec->m7wood = readNormalNr(i); i+=4;
  2073. spec->m7mercury = readNormalNr(i); i+=4;
  2074. spec->m7ore = readNormalNr(i); i+=4;
  2075. spec->m7sulfur = readNormalNr(i); i+=4;
  2076. spec->m7crystal = readNormalNr(i); i+=4;
  2077. spec->m7gems = readNormalNr(i); i+=4;
  2078. spec->m7gold = readNormalNr(i); i+=4;
  2079. int limit = readNormalNr(i); i+=4;
  2080. if(limit == ((int)0xffffffff))
  2081. {
  2082. spec->isDayLimit = false;
  2083. spec->lastDay = -1;
  2084. }
  2085. else
  2086. {
  2087. spec->isDayLimit = true;
  2088. spec->lastDay = limit;
  2089. }
  2090. break;
  2091. }
  2092. case 8:
  2093. {
  2094. int heroType = bufor[i]; ++i;
  2095. spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
  2096. int limit = readNormalNr(i); i+=4;
  2097. if(limit == ((int)0xffffffff))
  2098. {
  2099. spec->isDayLimit = false;
  2100. spec->lastDay = -1;
  2101. }
  2102. else
  2103. {
  2104. spec->isDayLimit = true;
  2105. spec->lastDay = limit;
  2106. }
  2107. break;
  2108. }
  2109. case 9:
  2110. {
  2111. spec->m9player = bufor[i]; ++i;
  2112. int limit = readNormalNr(i); i+=4;
  2113. if(limit == ((int)0xffffffff))
  2114. {
  2115. spec->isDayLimit = false;
  2116. spec->lastDay = -1;
  2117. }
  2118. else
  2119. {
  2120. spec->isDayLimit = true;
  2121. spec->lastDay = limit;
  2122. }
  2123. break;
  2124. }
  2125. }//internal switch end (seer huts)
  2126. int len1 = readNormalNr(i); i+=4;
  2127. for(int ee=0; ee<len1; ++ee)
  2128. {
  2129. spec->firstVisitText += bufor[i]; ++i;
  2130. }
  2131. int len2 = readNormalNr(i); i+=4;
  2132. for(int ee=0; ee<len2; ++ee)
  2133. {
  2134. spec->nextVisitText += bufor[i]; ++i;
  2135. }
  2136. int len3 = readNormalNr(i); i+=4;
  2137. for(int ee=0; ee<len3; ++ee)
  2138. {
  2139. spec->completedText += bufor[i]; ++i;
  2140. }
  2141. nobj->info = spec;
  2142. break;
  2143. }
  2144. } //end of main switch
  2145. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  2146. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  2147. }//*/ //end of loading objects; commented to make application work until it will be finished
  2148. ////objects loaded
  2149. //processMap(defsToUnpack);
  2150. std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack);
  2151. for (int i=0;i<dhandlers.size();i++)
  2152. map.defy[i]->handler=dhandlers[i];
  2153. for(int vv=0; vv<map.defy.size(); ++vv)
  2154. {
  2155. if(map.defy[vv]->handler->alphaTransformed)
  2156. continue;
  2157. for(int yy=0; yy<map.defy[vv]->handler->ourImages.size(); ++yy)
  2158. {
  2159. map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap);
  2160. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap, alphaTransSurf);
  2161. SDL_FreeSurface(map.defy[vv]->handler->ourImages[yy].bitmap);
  2162. map.defy[vv]->handler->ourImages[yy].bitmap = bufs;
  2163. map.defy[vv]->handler->alphaTransformed = true;
  2164. }
  2165. }
  2166. SDL_FreeSurface(alphaTransSurf);
  2167. //assigning defobjinfos
  2168. for(int ww=0; ww<CGI->objh->objInstances.size(); ++ww)
  2169. {
  2170. for(int h=0; h<CGI->dobjinfo->objs.size(); ++h)
  2171. {
  2172. if(CGI->dobjinfo->objs[h].defName==CGI->objh->objInstances[ww]->defInfo->name)
  2173. {
  2174. CGI->objh->objInstances[ww]->defObjInfoNumber = h;
  2175. break;
  2176. }
  2177. }
  2178. }
  2179. //assigned
  2180. //loading events
  2181. int numberOfEvents = readNormalNr(i); i+=4;
  2182. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  2183. {
  2184. CMapEvent ne;
  2185. ne.name = std::string();
  2186. ne.message = std::string();
  2187. int nameLen = readNormalNr(i); i+=4;
  2188. for(int qq=0; qq<nameLen; ++qq)
  2189. {
  2190. ne.name += bufor[i]; ++i;
  2191. }
  2192. int messLen = readNormalNr(i); i+=4;
  2193. for(int qq=0; qq<messLen; ++qq)
  2194. {
  2195. ne.message +=bufor[i]; ++i;
  2196. }
  2197. ne.wood = readNormalNr(i); i+=4;
  2198. ne.mercury = readNormalNr(i); i+=4;
  2199. ne.ore = readNormalNr(i); i+=4;
  2200. ne.sulfur = readNormalNr(i); i+=4;
  2201. ne.crystal = readNormalNr(i); i+=4;
  2202. ne.gems = readNormalNr(i); i+=4;
  2203. ne.gold = readNormalNr(i); i+=4;
  2204. ne.players = bufor[i]; ++i;
  2205. if(map.version>AB)
  2206. {
  2207. ne.humanAffected = bufor[i]; ++i;
  2208. }
  2209. else
  2210. ne.humanAffected = true;
  2211. ne.computerAffected = bufor[i]; ++i;
  2212. ne.firstOccurence = bufor[i]; ++i;
  2213. ne.nextOccurence = bufor[i]; ++i;
  2214. i+=18;
  2215. map.events.push_back(ne);
  2216. }
  2217. }
  2218. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  2219. {
  2220. int ret=0;
  2221. int amp=1;
  2222. for (int i=0; i<bytCon; i++)
  2223. {
  2224. ret+=bufor[pos+i]*amp;
  2225. amp*=256;
  2226. }
  2227. if(cyclic && bytCon<4 && ret>=amp/2)
  2228. {
  2229. ret = ret-amp;
  2230. }
  2231. return ret;
  2232. }
  2233. void CAmbarCendamo::loadDefs()
  2234. {
  2235. std::set<int> loadedTypes;
  2236. for (int i=0; i<map.width; i++)
  2237. {
  2238. for (int j=0; j<map.width; j++)
  2239. {
  2240. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  2241. {
  2242. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str());
  2243. loadedTypes.insert(map.terrain[i][j].tertype);
  2244. defs.push_back(sdh);
  2245. }
  2246. if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  2247. {
  2248. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str());
  2249. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  2250. defs.push_back(sdh);
  2251. }
  2252. }
  2253. }
  2254. }
  2255. EDefType CAmbarCendamo::getDefType(CGDefInfo * a)
  2256. {
  2257. switch(a->id)
  2258. {
  2259. case 5: case 65: case 66: case 67: case 68: case 69:
  2260. return EDefType::ARTIFACT_DEF; //handled
  2261. case 6:
  2262. return EDefType::PANDORA_DEF; //hanled
  2263. case 26:
  2264. return EDefType::EVENTOBJ_DEF; //handled
  2265. case 33:
  2266. return EDefType::GARRISON_DEF; //handled
  2267. case 34: case 70: case 62: //70 - random hero //62 - prison
  2268. return EDefType::HERO_DEF; //handled
  2269. case 36:
  2270. return EDefType::GRAIL_DEF; //hanled
  2271. case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
  2272. return EDefType::PLAYERONLY_DEF; //handled
  2273. case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
  2274. return EDefType::CREATURES_DEF; //handled
  2275. case 59:
  2276. return EDefType::SIGN_DEF; //handled
  2277. case 77:
  2278. return EDefType::TOWN_DEF; //can be problematic, but handled
  2279. case 79: case 76:
  2280. return EDefType::RESOURCE_DEF; //handled
  2281. case 81:
  2282. return EDefType::SCHOLAR_DEF; //handled
  2283. case 83:
  2284. return EDefType::SEERHUT_DEF; //handled
  2285. case 91:
  2286. return EDefType::SIGN_DEF; //handled
  2287. case 88: case 89: case 90:
  2288. return SHRINE_DEF; //handled
  2289. case 93:
  2290. return SPELLSCROLL_DEF; //handled
  2291. case 98:
  2292. return EDefType::TOWN_DEF; //handled
  2293. case 113:
  2294. return EDefType::WITCHHUT_DEF; //handled
  2295. case 215:
  2296. return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;]
  2297. case 216:
  2298. return EDefType::CREGEN2_DEF; //handled
  2299. case 217:
  2300. return EDefType::CREGEN_DEF; //handled
  2301. case 218:
  2302. return EDefType::CREGEN3_DEF; //handled
  2303. case 219:
  2304. return EDefType::GARRISON_DEF; //handled
  2305. default:
  2306. return EDefType::TERRAINOBJ_DEF; // nothing to be handled
  2307. }
  2308. }
  2309. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  2310. {
  2311. if(map.version>RoE)
  2312. {
  2313. CCreatureSet ret;
  2314. std::pair<CCreature *, int> ins;
  2315. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  2316. {
  2317. int rettt = readNormalNr(pos, 2);
  2318. if(rettt>32768)
  2319. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2320. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2321. ins.second = readNormalNr(pos+2, 2);
  2322. std::pair<int,std::pair<CCreature *, int> > tt(0,ins);
  2323. ret.slots.insert(tt);
  2324. }
  2325. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  2326. {
  2327. int rettt = readNormalNr(pos+4, 2);
  2328. if(rettt>32768)
  2329. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2330. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2331. ins.second = readNormalNr(pos+6, 2);
  2332. std::pair<int,std::pair<CCreature *, int> > tt(1,ins);
  2333. ret.slots.insert(tt);
  2334. }
  2335. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  2336. {
  2337. int rettt = readNormalNr(pos+8, 2);
  2338. if(rettt>32768)
  2339. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2340. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2341. ins.second = readNormalNr(pos+10, 2);
  2342. std::pair<int,std::pair<CCreature *, int> > tt(2,ins);
  2343. ret.slots.insert(tt);
  2344. }
  2345. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  2346. {
  2347. int rettt = readNormalNr(pos+12, 2);
  2348. if(rettt>32768)
  2349. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2350. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2351. ins.second = readNormalNr(pos+14, 2);
  2352. std::pair<int,std::pair<CCreature *, int> > tt(3,ins);
  2353. ret.slots.insert(tt);
  2354. }
  2355. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  2356. {
  2357. int rettt = readNormalNr(pos+16, 2);
  2358. if(rettt>32768)
  2359. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2360. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2361. ins.second = readNormalNr(pos+18, 2);
  2362. std::pair<int,std::pair<CCreature *, int> > tt(4,ins);
  2363. ret.slots.insert(tt);
  2364. }
  2365. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  2366. {
  2367. int rettt = readNormalNr(pos+20, 2);
  2368. if(rettt>32768)
  2369. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2370. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2371. ins.second = readNormalNr(pos+22, 2);
  2372. std::pair<int,std::pair<CCreature *, int> > tt(5,ins);
  2373. ret.slots.insert(tt);
  2374. }
  2375. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  2376. {
  2377. int rettt = readNormalNr(pos+24, 2);
  2378. if(rettt>32768)
  2379. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2380. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2381. ins.second = readNormalNr(pos+26, 2);
  2382. std::pair<int,std::pair<CCreature *, int> > tt(6,ins);
  2383. ret.slots.insert(tt);
  2384. }
  2385. return ret;
  2386. }
  2387. else
  2388. {
  2389. CCreatureSet ret;
  2390. std::pair<CCreature *, int> ins;
  2391. if(number>0 && readNormalNr(pos, 1)!=0xff)
  2392. {
  2393. int rettt = readNormalNr(pos, 1);
  2394. if(rettt>220)
  2395. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2396. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2397. ins.second = readNormalNr(pos+1, 2);
  2398. std::pair<int,std::pair<CCreature *, int> > tt(0,ins);
  2399. ret.slots.insert(tt);
  2400. }
  2401. if(number>1 && readNormalNr(pos+3, 1)!=0xff)
  2402. {
  2403. int rettt = readNormalNr(pos+3, 1);
  2404. if(rettt>220)
  2405. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2406. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2407. ins.second = readNormalNr(pos+4, 2);
  2408. std::pair<int,std::pair<CCreature *, int> > tt(1,ins);
  2409. ret.slots.insert(tt);
  2410. }
  2411. if(number>2 && readNormalNr(pos+6, 1)!=0xff)
  2412. {
  2413. int rettt = readNormalNr(pos+6, 1);
  2414. if(rettt>220)
  2415. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2416. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2417. ins.second = readNormalNr(pos+7, 2);
  2418. std::pair<int,std::pair<CCreature *, int> > tt(2,ins);
  2419. ret.slots.insert(tt);
  2420. }
  2421. if(number>3 && readNormalNr(pos+9, 1)!=0xff)
  2422. {
  2423. int rettt = readNormalNr(pos+9, 1);
  2424. if(rettt>220)
  2425. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2426. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2427. ins.second = readNormalNr(pos+10, 2);
  2428. std::pair<int,std::pair<CCreature *, int> > tt(3,ins);
  2429. ret.slots.insert(tt);
  2430. }
  2431. if(number>4 && readNormalNr(pos+12, 1)!=0xff)
  2432. {
  2433. int rettt = readNormalNr(pos+12, 1);
  2434. if(rettt>220)
  2435. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2436. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2437. ins.second = readNormalNr(pos+13, 2);
  2438. std::pair<int,std::pair<CCreature *, int> > tt(4,ins);
  2439. ret.slots.insert(tt);
  2440. }
  2441. if(number>5 && readNormalNr(pos+15, 1)!=0xff)
  2442. {
  2443. int rettt = readNormalNr(pos+15, 1);
  2444. if(rettt>220)
  2445. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2446. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2447. ins.second = readNormalNr(pos+16, 2);
  2448. std::pair<int,std::pair<CCreature *, int> > tt(5,ins);
  2449. ret.slots.insert(tt);
  2450. }
  2451. if(number>6 && readNormalNr(pos+18, 1)!=0xff)
  2452. {
  2453. int rettt = readNormalNr(pos+18, 1);
  2454. if(rettt>220)
  2455. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2456. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2457. ins.second = readNormalNr(pos+19, 2);
  2458. std::pair<int,std::pair<CCreature *, int> > tt(6,ins);
  2459. ret.slots.insert(tt);
  2460. }
  2461. return ret;
  2462. }
  2463. }
  2464. void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
  2465. {
  2466. resDefNames.push_back("AVTRNDM0.DEF");
  2467. resDefNames.push_back("AVTWOOD0.DEF");
  2468. resDefNames.push_back("AVTMERC0.DEF");
  2469. resDefNames.push_back("AVTORE0.DEF");
  2470. resDefNames.push_back("AVTSULF0.DEF");
  2471. resDefNames.push_back("AVTCRYS0.DEF");
  2472. resDefNames.push_back("AVTGEMS0.DEF");
  2473. resDefNames.push_back("AVTGOLD0.DEF");
  2474. resDefNames.push_back("ZMITHR.DEF");
  2475. std::vector<CGDefInfo*> resDefNumbers;
  2476. for(int hh=0; hh<resDefNames.size(); ++hh)
  2477. {
  2478. resDefNumbers.push_back(NULL);
  2479. for(int k=0; k<map.defy.size(); ++k)
  2480. {
  2481. std::string buf = map.defy[k]->name;
  2482. std::transform(buf.begin(), buf.end(), buf.begin(), (int(*)(int))toupper);
  2483. if(resDefNames[hh] == buf)
  2484. {
  2485. resDefNumbers[resDefNumbers.size()-1] = map.defy[k];
  2486. break;
  2487. }
  2488. }
  2489. }
  2490. std::vector<std::string> creDefNames;
  2491. for(int dd=0; dd<140; ++dd) //we do not use here WoG units
  2492. {
  2493. creDefNames.push_back(CGI->dobjinfo->objs[dd+1184].defName);
  2494. }
  2495. std::vector<CGDefInfo*> creDefNumbers;
  2496. for(int ee=0; ee<creDefNames.size(); ++ee)
  2497. {
  2498. creDefNumbers.push_back(NULL);
  2499. }
  2500. std::vector<std::string> artDefNames;
  2501. std::vector<CGDefInfo* > artDefNumbers;
  2502. for(int bb=0; bb<162; ++bb)
  2503. {
  2504. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass!=EartClass::SartClass)
  2505. artDefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2506. }
  2507. for(int ee=0; ee<artDefNames.size(); ++ee)
  2508. {
  2509. artDefNumbers.push_back(NULL);
  2510. }
  2511. std::vector<std::string> art1DefNames;
  2512. std::vector<CGDefInfo*> art1DefNumbers;
  2513. for(int bb=0; bb<162; ++bb)
  2514. {
  2515. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::TartClass)
  2516. art1DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2517. }
  2518. for(int ee=0; ee<art1DefNames.size(); ++ee)
  2519. {
  2520. art1DefNumbers.push_back(NULL);
  2521. }
  2522. std::vector<std::string> art2DefNames;
  2523. std::vector<CGDefInfo*> art2DefNumbers;
  2524. for(int bb=0; bb<162; ++bb)
  2525. {
  2526. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::NartClass)
  2527. art2DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2528. }
  2529. for(int ee=0; ee<art2DefNames.size(); ++ee)
  2530. {
  2531. art2DefNumbers.push_back(NULL);
  2532. }
  2533. std::vector<std::string> art3DefNames;
  2534. std::vector<CGDefInfo*> art3DefNumbers;
  2535. for(int bb=0; bb<162; ++bb)
  2536. {
  2537. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::JartClass)
  2538. art3DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2539. }
  2540. for(int ee=0; ee<art3DefNames.size(); ++ee)
  2541. {
  2542. art3DefNumbers.push_back(NULL);
  2543. }
  2544. std::vector<std::string> art4DefNames;
  2545. std::vector<CGDefInfo*> art4DefNumbers;
  2546. for(int bb=0; bb<162; ++bb)
  2547. {
  2548. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::RartClass)
  2549. art4DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2550. }
  2551. for(int ee=0; ee<art4DefNames.size(); ++ee)
  2552. {
  2553. art4DefNumbers.push_back(NULL);
  2554. }
  2555. std::vector<std::string> town0DefNames; //without fort
  2556. std::vector<CGDefInfo*> town0DefNumbers;
  2557. std::vector<std::string> town1DefNames; //with fort
  2558. std::vector<CGDefInfo*> town1DefNumbers;
  2559. for(int dd=0; dd<F_NUMBER; ++dd)
  2560. {
  2561. town1DefNames.push_back(CGI->dobjinfo->objs[dd+385].defName);
  2562. town1DefNumbers.push_back(NULL);
  2563. }
  2564. std::vector< std::vector<std::string> > creGenNames;
  2565. std::vector< std::vector<CGDefInfo*> > creGenNumbers;
  2566. creGenNames.resize(F_NUMBER);
  2567. creGenNumbers.resize(F_NUMBER);
  2568. for(int ff=0; ff<F_NUMBER-1; ++ff)
  2569. {
  2570. for(int dd=0; dd<7; ++dd)
  2571. {
  2572. creGenNames[ff].push_back(CGI->dobjinfo->objs[395+7*ff+dd].defName);
  2573. creGenNumbers[ff].push_back(NULL);
  2574. }
  2575. }
  2576. for(int dd=0; dd<7; ++dd)
  2577. {
  2578. creGenNumbers[8].push_back(NULL);
  2579. }
  2580. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName);
  2581. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName);
  2582. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[455].defName);
  2583. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName);
  2584. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName);
  2585. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
  2586. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[459].defName);
  2587. for(int b=0; b<CGI->scenarioOps.playerInfos.size(); ++b) // choosing random player alignment
  2588. {
  2589. if(CGI->scenarioOps.playerInfos[b].castle==-1)
  2590. CGI->scenarioOps.playerInfos[b].castle = rand()%F_NUMBER;
  2591. }
  2592. //variables initialized
  2593. for(int j=0; j<CGI->objh->objInstances.size(); ++j)
  2594. {
  2595. CGDefInfo * curDef = CGI->objh->objInstances[j]->defInfo;
  2596. switch(getDefType(curDef))
  2597. {
  2598. case EDefType::RESOURCE_DEF:
  2599. {
  2600. if(curDef->id==76) //resource to specify
  2601. {
  2602. CGDefInfo * nxt = curDef;
  2603. nxt->id = 79;
  2604. nxt->subid = rand()%7;
  2605. if(resDefNumbers[nxt->subid+1]!=NULL)
  2606. {
  2607. CGI->objh->objInstances[j]->defInfo = resDefNumbers[nxt->subid+1];
  2608. continue;
  2609. }
  2610. nxt->name = resDefNames[nxt->subid+1];
  2611. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2612. nxt->name);
  2613. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2614. {
  2615. nxt->isOnDefList = false;
  2616. }
  2617. else
  2618. {
  2619. nxt->printPriority = pit->priority;
  2620. nxt->isOnDefList = true;
  2621. }
  2622. map.defy.push_back(nxt); // add this def to the vector
  2623. defsToUnpack.push_back(nxt->name);
  2624. CGI->objh->objInstances[j]->defInfo = nxt;
  2625. if(resDefNumbers[nxt->subid+1]==NULL)
  2626. {
  2627. resDefNumbers[nxt->subid+1] = nxt;
  2628. }
  2629. }
  2630. break;
  2631. }
  2632. case EDefType::CREATURES_DEF:
  2633. {
  2634. if(curDef->id==72) //random monster lvl 1
  2635. {
  2636. CGDefInfo * nxt = curDef;
  2637. nxt->id = 54;
  2638. nxt->subid = 14*(rand()%9)+rand()%2;
  2639. if(creDefNumbers[nxt->subid]!=NULL)
  2640. {
  2641. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2642. continue;
  2643. }
  2644. nxt->name = creDefNames[nxt->subid];
  2645. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2646. nxt->name);
  2647. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2648. {
  2649. nxt->isOnDefList = false;
  2650. }
  2651. else
  2652. {
  2653. nxt->printPriority = pit->priority;
  2654. nxt->isOnDefList = true;
  2655. }
  2656. map.defy.push_back(nxt); // add this def to the vector
  2657. defsToUnpack.push_back(nxt->name);
  2658. CGI->objh->objInstances[j]->defInfo = nxt;
  2659. if(creDefNumbers[nxt->subid]==NULL)
  2660. {
  2661. creDefNumbers[nxt->subid] = nxt;
  2662. }
  2663. }
  2664. if(curDef->id==73) //random monster lvl 2
  2665. {
  2666. CGDefInfo * nxt = curDef;
  2667. nxt->id = 54;
  2668. nxt->subid = 14*(rand()%9)+rand()%2+2;
  2669. if(creDefNumbers[nxt->subid]!=NULL)
  2670. {
  2671. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2672. continue;
  2673. }
  2674. nxt->name = creDefNames[nxt->subid];
  2675. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2676. nxt->name);
  2677. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2678. {
  2679. nxt->isOnDefList = false;
  2680. }
  2681. else
  2682. {
  2683. nxt->printPriority = pit->priority;
  2684. nxt->isOnDefList = true;
  2685. }
  2686. map.defy.push_back(nxt); // add this def to the vector
  2687. defsToUnpack.push_back(nxt->name);
  2688. CGI->objh->objInstances[j]->defInfo = nxt;
  2689. if(creDefNumbers[nxt->subid]==NULL)
  2690. {
  2691. creDefNumbers[nxt->subid] = nxt;
  2692. }
  2693. }
  2694. if(curDef->id==74) //random monster lvl 3
  2695. {
  2696. CGDefInfo *nxt = curDef;
  2697. nxt->id = 54;
  2698. nxt->subid = 14*(rand()%9)+rand()%2+4;
  2699. if(creDefNumbers[nxt->subid]!=NULL)
  2700. {
  2701. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2702. continue;
  2703. }
  2704. nxt->name = creDefNames[nxt->subid];
  2705. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2706. nxt->name);
  2707. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2708. {
  2709. nxt->isOnDefList = false;
  2710. }
  2711. else
  2712. {
  2713. nxt->printPriority = pit->priority;
  2714. nxt->isOnDefList = true;
  2715. }
  2716. map.defy.push_back(nxt); // add this def to the vector
  2717. defsToUnpack.push_back(nxt->name);
  2718. CGI->objh->objInstances[j]->defInfo = nxt;
  2719. if(creDefNumbers[nxt->subid]==NULL)
  2720. {
  2721. creDefNumbers[nxt->subid] = nxt;
  2722. }
  2723. }
  2724. if(curDef->id==75) //random monster lvl 4
  2725. {
  2726. CGDefInfo * nxt = curDef;
  2727. nxt->id = 54;
  2728. nxt->subid = 14*(rand()%9)+rand()%2+6;
  2729. if(creDefNumbers[nxt->subid]!=NULL)
  2730. {
  2731. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2732. continue;
  2733. }
  2734. nxt->name = creDefNames[nxt->subid];
  2735. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2736. nxt->name);
  2737. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2738. {
  2739. nxt->isOnDefList = false;
  2740. }
  2741. else
  2742. {
  2743. nxt->printPriority = pit->priority;
  2744. nxt->isOnDefList = true;
  2745. }
  2746. map.defy.push_back(nxt); // add this def to the vector
  2747. defsToUnpack.push_back(nxt->name);
  2748. CGI->objh->objInstances[j]->defInfo = nxt;
  2749. if(creDefNumbers[nxt->subid]==NULL)
  2750. {
  2751. creDefNumbers[nxt->subid] = nxt;
  2752. }
  2753. }
  2754. if(curDef->id==162) //random monster lvl 5
  2755. {
  2756. CGDefInfo * nxt = curDef;
  2757. nxt->id = 54;
  2758. nxt->subid = 14*(rand()%9)+rand()%2+8;
  2759. if(creDefNumbers[nxt->subid]!=NULL)
  2760. {
  2761. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2762. continue;
  2763. }
  2764. nxt->name = creDefNames[nxt->subid];
  2765. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2766. nxt->name);
  2767. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2768. {
  2769. nxt->isOnDefList = false;
  2770. }
  2771. else
  2772. {
  2773. nxt->printPriority = pit->priority;
  2774. nxt->isOnDefList = true;
  2775. }
  2776. map.defy.push_back(nxt); // add this def to the vector
  2777. defsToUnpack.push_back(nxt->name);
  2778. CGI->objh->objInstances[j]->defInfo = nxt;
  2779. if(creDefNumbers[nxt->subid]==NULL)
  2780. {
  2781. creDefNumbers[nxt->subid] = nxt;
  2782. }
  2783. }
  2784. if(curDef->id==163) //random monster lvl 6
  2785. {
  2786. CGDefInfo* nxt = curDef;
  2787. nxt->id = 54;
  2788. nxt->subid = 14*(rand()%9)+rand()%2+10;
  2789. if(creDefNumbers[nxt->subid]!=NULL)
  2790. {
  2791. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2792. continue;
  2793. }
  2794. nxt->name = creDefNames[nxt->subid];
  2795. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2796. nxt->name);
  2797. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2798. {
  2799. nxt->isOnDefList = false;
  2800. }
  2801. else
  2802. {
  2803. nxt->printPriority = pit->priority;
  2804. nxt->isOnDefList = true;
  2805. }
  2806. map.defy.push_back(nxt); // add this def to the vector
  2807. defsToUnpack.push_back(nxt->name);
  2808. CGI->objh->objInstances[j]->defInfo = nxt;
  2809. if(creDefNumbers[nxt->subid]==NULL)
  2810. {
  2811. creDefNumbers[nxt->subid] = nxt;
  2812. }
  2813. }
  2814. if(curDef->id==164) //random monster lvl 7
  2815. {
  2816. CGDefInfo * nxt = curDef;
  2817. nxt->id = 54;
  2818. nxt->subid = 14*(rand()%9)+rand()%2+12;
  2819. if(creDefNumbers[nxt->subid]!=NULL)
  2820. {
  2821. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2822. continue;
  2823. }
  2824. nxt->name = creDefNames[nxt->subid];
  2825. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2826. nxt->name);
  2827. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2828. {
  2829. nxt->isOnDefList = false;
  2830. }
  2831. else
  2832. {
  2833. nxt->printPriority = pit->priority;
  2834. nxt->isOnDefList = true;
  2835. }
  2836. map.defy.push_back(nxt); // add this def to the vector
  2837. defsToUnpack.push_back(nxt->name);
  2838. CGI->objh->objInstances[j]->defInfo = nxt;
  2839. if(creDefNumbers[nxt->subid]==NULL)
  2840. {
  2841. creDefNumbers[nxt->subid] = nxt;
  2842. }
  2843. }
  2844. if(curDef->id==71) //random monster (any level)
  2845. {
  2846. CGDefInfo * nxt = curDef;
  2847. nxt->id = 54;
  2848. nxt->subid = rand()%126;
  2849. if(creDefNumbers[nxt->subid]!=NULL)
  2850. {
  2851. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2852. continue;
  2853. }
  2854. nxt->name = creDefNames[nxt->subid];
  2855. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2856. nxt->name);
  2857. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2858. {
  2859. nxt->isOnDefList = false;
  2860. }
  2861. else
  2862. {
  2863. nxt->printPriority = pit->priority;
  2864. nxt->isOnDefList = true;
  2865. }
  2866. map.defy.push_back(nxt); // add this def to the vector
  2867. defsToUnpack.push_back(nxt->name);
  2868. CGI->objh->objInstances[j]->defInfo = nxt;
  2869. if(creDefNumbers[nxt->subid]==NULL)
  2870. {
  2871. creDefNumbers[nxt->subid] = nxt;
  2872. }
  2873. }
  2874. break;
  2875. } //end of case
  2876. case EDefType::ARTIFACT_DEF:
  2877. {
  2878. if(curDef->id==65) //random atrifact (any class)
  2879. {
  2880. CGDefInfo *nxt = curDef;
  2881. nxt->id = 5;
  2882. nxt->subid = rand()%artDefNames.size();
  2883. if(artDefNumbers[nxt->subid]!=NULL)
  2884. {
  2885. CGI->objh->objInstances[j]->defInfo = artDefNumbers[nxt->subid];
  2886. continue;
  2887. }
  2888. nxt->name = artDefNames[nxt->subid];
  2889. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2890. nxt->name);
  2891. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2892. {
  2893. nxt->isOnDefList = false;
  2894. }
  2895. else
  2896. {
  2897. nxt->printPriority = pit->priority;
  2898. nxt->isOnDefList = true;
  2899. }
  2900. map.defy.push_back(nxt); // add this def to the vector
  2901. defsToUnpack.push_back(nxt->name);
  2902. CGI->objh->objInstances[j]->defInfo = nxt;
  2903. if(artDefNumbers[nxt->subid]==NULL)
  2904. {
  2905. artDefNumbers[nxt->subid] = nxt;
  2906. }
  2907. }
  2908. if(curDef->id==66) //random atrifact (treasure)
  2909. {
  2910. CGDefInfo* nxt = curDef;
  2911. nxt->id = 5;
  2912. nxt->subid = rand()%art1DefNames.size();
  2913. if(art1DefNumbers[nxt->subid]!=NULL)
  2914. {
  2915. CGI->objh->objInstances[j]->defInfo = art1DefNumbers[nxt->subid];
  2916. continue;
  2917. }
  2918. nxt->name = art1DefNames[nxt->subid];
  2919. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2920. nxt->name);
  2921. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2922. {
  2923. nxt->isOnDefList = false;
  2924. }
  2925. else
  2926. {
  2927. nxt->printPriority = pit->priority;
  2928. nxt->isOnDefList = true;
  2929. }
  2930. map.defy.push_back(nxt); // add this def to the vector
  2931. defsToUnpack.push_back(nxt->name);
  2932. CGI->objh->objInstances[j]->defInfo = nxt;
  2933. if(art1DefNumbers[nxt->subid]==NULL)
  2934. {
  2935. art1DefNumbers[nxt->subid] = nxt;
  2936. }
  2937. }
  2938. if(curDef->id==67) //random atrifact (minor)
  2939. {
  2940. CGDefInfo *nxt = curDef;
  2941. nxt->id = 5;
  2942. nxt->subid = rand()%art2DefNames.size();
  2943. if(art2DefNumbers[nxt->subid]!=NULL)
  2944. {
  2945. CGI->objh->objInstances[j]->defInfo = art2DefNumbers[nxt->subid];
  2946. continue;
  2947. }
  2948. nxt->name = art2DefNames[nxt->subid];
  2949. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2950. nxt->name);
  2951. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2952. {
  2953. nxt->isOnDefList = false;
  2954. }
  2955. else
  2956. {
  2957. nxt->printPriority = pit->priority;
  2958. nxt->isOnDefList = true;
  2959. }
  2960. map.defy.push_back(nxt); // add this def to the vector
  2961. defsToUnpack.push_back(nxt->name);
  2962. CGI->objh->objInstances[j]->defInfo = nxt;
  2963. if(art2DefNumbers[nxt->subid]==NULL)
  2964. {
  2965. art2DefNumbers[nxt->subid] = nxt;
  2966. }
  2967. }
  2968. if(curDef->id==68) //random atrifact (major)
  2969. {
  2970. CGDefInfo* nxt = curDef;
  2971. nxt->id = 5;
  2972. nxt->subid = rand()%art3DefNames.size();
  2973. if(art3DefNumbers[nxt->subid]!=NULL)
  2974. {
  2975. CGI->objh->objInstances[j]->defInfo = art3DefNumbers[nxt->subid];
  2976. continue;
  2977. }
  2978. nxt->name = art3DefNames[nxt->subid];
  2979. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2980. nxt->name);
  2981. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2982. {
  2983. nxt->isOnDefList = false;
  2984. }
  2985. else
  2986. {
  2987. nxt->printPriority = pit->priority;
  2988. nxt->isOnDefList = true;
  2989. }
  2990. map.defy.push_back(nxt); // add this def to the vector
  2991. defsToUnpack.push_back(nxt->name);
  2992. CGI->objh->objInstances[j]->defInfo = nxt;
  2993. if(art3DefNumbers[nxt->subid]==NULL)
  2994. {
  2995. art3DefNumbers[nxt->subid] =nxt;
  2996. }
  2997. }
  2998. if(curDef->id==69) //random atrifact (relic)
  2999. {
  3000. CGDefInfo *nxt = curDef;
  3001. nxt->id = 5;
  3002. nxt->subid = rand()%art4DefNames.size();
  3003. if(art4DefNumbers[nxt->subid]!=NULL)
  3004. {
  3005. CGI->objh->objInstances[j]->defInfo = art4DefNumbers[nxt->subid];
  3006. continue;
  3007. }
  3008. nxt->name = art4DefNames[nxt->subid];
  3009. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3010. nxt->name);
  3011. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3012. {
  3013. nxt->isOnDefList = false;
  3014. }
  3015. else
  3016. {
  3017. nxt->printPriority = pit->priority;
  3018. nxt->isOnDefList = true;
  3019. }
  3020. map.defy.push_back(nxt); // add this def to the vector
  3021. defsToUnpack.push_back(nxt->name);
  3022. CGI->objh->objInstances[j]->defInfo = nxt;
  3023. if(art4DefNumbers[nxt->subid]==NULL)
  3024. {
  3025. art4DefNumbers[nxt->subid] = nxt;
  3026. }
  3027. }
  3028. break;
  3029. }
  3030. case EDefType::TOWN_DEF:
  3031. {
  3032. if(curDef->id==77) //random town
  3033. {
  3034. CGDefInfo* nxt = curDef;
  3035. nxt->id = 98;
  3036. if(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player==0xff)
  3037. {
  3038. nxt->subid = rand()%town1DefNames.size();
  3039. }
  3040. else
  3041. {
  3042. if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle>-1)
  3043. {
  3044. nxt->subid = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle;
  3045. }
  3046. else
  3047. {
  3048. nxt->subid = rand()%town1DefNames.size();
  3049. }
  3050. }
  3051. if(town1DefNumbers[nxt->subid]!=NULL)
  3052. {
  3053. CGI->objh->objInstances[j]->defInfo = town1DefNumbers[nxt->subid];
  3054. continue;
  3055. }
  3056. nxt->name = town1DefNames[nxt->subid];
  3057. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3058. nxt->name);
  3059. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3060. {
  3061. nxt->isOnDefList = false;
  3062. }
  3063. else
  3064. {
  3065. nxt->printPriority = pit->priority;
  3066. nxt->isOnDefList = true;
  3067. }
  3068. map.defy.push_back(nxt); // add this def to the vector
  3069. defsToUnpack.push_back(nxt->name);
  3070. CGI->objh->objInstances[j]->defInfo = nxt;
  3071. if(town1DefNumbers[nxt->subid]==NULL)
  3072. {
  3073. town1DefNumbers[nxt->subid] = nxt;
  3074. }
  3075. for (int ij=0;ij<CGI->townh->townInstances.size();ij++) // wyharatac gdy bedzie dziedziczenie
  3076. {
  3077. if (CGI->townh->townInstances[ij]->pos==CGI->objh->objInstances[j]->pos)
  3078. {
  3079. CGI->townh->townInstances[ij]->town = &CGI->townh->towns[nxt->subid];
  3080. break;
  3081. }
  3082. }
  3083. }
  3084. //((CCastleObjInfo*)CGI->objh->objInstances[j].info)
  3085. break;
  3086. }
  3087. case EDefType::HERO_DEF:
  3088. {
  3089. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3090. CGI->objh->objInstances[j]->defInfo->name);
  3091. CGI->objh->objInstances[j]->defInfo->printPriority = 0;
  3092. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3093. {
  3094. CGI->objh->objInstances[j]->defInfo->isOnDefList = false;
  3095. }
  3096. else
  3097. {
  3098. CGI->objh->objInstances[j]->defInfo->isOnDefList = true;
  3099. }
  3100. break;
  3101. }
  3102. } //end of main switch
  3103. } //end of main loop
  3104. for(int j=0; j<CGI->objh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent)
  3105. {
  3106. CGDefInfo * curDef = CGI->objh->objInstances[j]->defInfo;
  3107. switch(getDefType(curDef))
  3108. {
  3109. case EDefType::CREGEN_DEF:
  3110. {
  3111. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
  3112. {
  3113. CGDefInfo *nxt = curDef;
  3114. nxt->id = 17;
  3115. for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
  3116. {
  3117. if(getDefType(CGI->objh->objInstances[vv]->defInfo)==EDefType::TOWN_DEF)
  3118. {
  3119. if(
  3120. ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
  3121. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
  3122. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
  3123. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
  3124. {
  3125. for(int mm=0; mm<town1DefNames.size(); ++mm)
  3126. {
  3127. std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
  3128. std::string hlp = CGI->objh->objInstances[vv]->defInfo->name;
  3129. std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
  3130. if(town1DefNames[mm]==hlp)
  3131. {
  3132. nxt->subid = mm;
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. int lvl = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str())-1;
  3139. nxt->name = creGenNames[nxt->subid][lvl];
  3140. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3141. {
  3142. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3143. continue;
  3144. }
  3145. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3146. nxt->name);
  3147. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3148. {
  3149. nxt->isOnDefList = false;
  3150. }
  3151. else
  3152. {
  3153. nxt->printPriority = pit->priority;
  3154. nxt->isOnDefList = true;
  3155. }
  3156. map.defy.push_back(nxt); // add this def to the vector
  3157. defsToUnpack.push_back(nxt->name);
  3158. CGI->objh->objInstances[j]->defInfo = nxt;
  3159. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3160. {
  3161. creGenNumbers[nxt->subid][lvl] = nxt;
  3162. }
  3163. }
  3164. else //if not as castle
  3165. {
  3166. CGDefInfo * nxt = curDef;
  3167. nxt->id = 17;
  3168. std::vector<int> possibleTowns;
  3169. for(int bb=0; bb<8; ++bb)
  3170. {
  3171. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
  3172. {
  3173. possibleTowns.push_back(bb);
  3174. }
  3175. }
  3176. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
  3177. possibleTowns.push_back(8);
  3178. nxt->subid = possibleTowns[rand()%possibleTowns.size()];
  3179. int lvl = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str())-1;
  3180. nxt->name = creGenNames[nxt->subid][lvl];
  3181. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3182. {
  3183. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3184. continue;
  3185. }
  3186. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3187. nxt->name);
  3188. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3189. {
  3190. nxt->isOnDefList = false;
  3191. }
  3192. else
  3193. {
  3194. nxt->printPriority = pit->priority;
  3195. nxt->isOnDefList = true;
  3196. }
  3197. map.defy.push_back(nxt); // add this def to the vector
  3198. defsToUnpack.push_back(nxt->name);
  3199. CGI->objh->objInstances[j]->defInfo = nxt;
  3200. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3201. {
  3202. creGenNumbers[nxt->subid][lvl] = nxt;
  3203. }
  3204. }
  3205. break;
  3206. }
  3207. case EDefType::CREGEN2_DEF:
  3208. {
  3209. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
  3210. {
  3211. CGDefInfo * nxt = curDef;
  3212. nxt->id = 17;
  3213. for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
  3214. {
  3215. if(getDefType(CGI->objh->objInstances[vv]->defInfo)==EDefType::TOWN_DEF)
  3216. {
  3217. if(
  3218. ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
  3219. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
  3220. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
  3221. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
  3222. {
  3223. for(int mm=0; mm<town1DefNames.size(); ++mm)
  3224. {
  3225. std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
  3226. std::string hlp = CGI->objh->objInstances[vv]->defInfo->name;
  3227. std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
  3228. if(town1DefNames[mm]==hlp)
  3229. {
  3230. nxt->subid = mm;
  3231. }
  3232. }
  3233. }
  3234. }
  3235. }
  3236. int lvl;
  3237. if((((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel)!=0)
  3238. lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
  3239. else lvl = 0;
  3240. nxt->name = creGenNames[nxt->subid][lvl];
  3241. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3242. {
  3243. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3244. continue;
  3245. }
  3246. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3247. nxt->name);
  3248. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3249. {
  3250. nxt->isOnDefList = false;
  3251. }
  3252. else
  3253. {
  3254. nxt->printPriority = pit->priority;
  3255. nxt->isOnDefList = true;
  3256. }
  3257. map.defy.push_back(nxt); // add this def to the vector
  3258. defsToUnpack.push_back(nxt->name);
  3259. CGI->objh->objInstances[j]->defInfo = nxt;
  3260. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3261. {
  3262. creGenNumbers[nxt->subid][lvl] = nxt;
  3263. }
  3264. }
  3265. else //if not as castle
  3266. {
  3267. CGDefInfo * nxt = curDef;
  3268. nxt->id = 17;
  3269. std::vector<int> possibleTowns;
  3270. for(int bb=0; bb<8; ++bb)
  3271. {
  3272. if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
  3273. {
  3274. possibleTowns.push_back(bb);
  3275. }
  3276. }
  3277. if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
  3278. possibleTowns.push_back(8);
  3279. nxt->subid = possibleTowns[rand()%possibleTowns.size()];
  3280. int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
  3281. nxt->name = creGenNames[nxt->subid][lvl];
  3282. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3283. {
  3284. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3285. continue;
  3286. }
  3287. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3288. nxt->name);
  3289. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3290. {
  3291. nxt->isOnDefList = false;
  3292. }
  3293. else
  3294. {
  3295. nxt->printPriority = pit->priority;
  3296. nxt->isOnDefList = true;
  3297. }
  3298. map.defy.push_back(nxt); // add this def to the vector
  3299. defsToUnpack.push_back(nxt->name);
  3300. CGI->objh->objInstances[j]->defInfo = nxt;
  3301. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3302. {
  3303. creGenNumbers[nxt->subid][lvl] = nxt;
  3304. }
  3305. }
  3306. }
  3307. case EDefType::CREGEN3_DEF:
  3308. {
  3309. CGDefInfo * nxt = curDef;
  3310. nxt->id = 17;
  3311. nxt->subid = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str());
  3312. int lvl = -1;
  3313. CCreGen3ObjInfo * ct = (CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info;
  3314. if(ct->maxLevel>7)
  3315. ct->maxLevel = 7;
  3316. if(ct->minLevel<1)
  3317. ct->minLevel = 1;
  3318. if((((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel)!=0)
  3319. lvl = rand()%(((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
  3320. else
  3321. lvl = ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel;
  3322. nxt->name = creGenNames[nxt->subid][lvl];
  3323. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3324. {
  3325. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3326. continue;
  3327. }
  3328. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3329. nxt->name);
  3330. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3331. {
  3332. nxt->isOnDefList = false;
  3333. }
  3334. else
  3335. {
  3336. nxt->printPriority = pit->priority;
  3337. nxt->isOnDefList = true;
  3338. }
  3339. map.defy.push_back(nxt); // add this def to the vector
  3340. defsToUnpack.push_back(nxt->name);
  3341. CGI->objh->objInstances[j]->defInfo = nxt;
  3342. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3343. {
  3344. creGenNumbers[nxt->subid][lvl] = nxt;
  3345. }
  3346. break;
  3347. }
  3348. }//end of main switch
  3349. } //end of sencond for loop
  3350. }