CAmbarCendamo.cpp 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418
  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 && bs==0)
  1724. {
  1725. if(spec->buildingSettings[ir] & 1<<0)
  1726. nt->builtBuildings.insert(40);
  1727. if(spec->buildingSettings[ir] & 1<<2)
  1728. nt->builtBuildings.insert(34);
  1729. if(spec->buildingSettings[ir] & 1<<3)
  1730. nt->builtBuildings.insert(41);
  1731. if(spec->buildingSettings[ir] & 1<<5)
  1732. nt->builtBuildings.insert(35);
  1733. if(spec->buildingSettings[ir] & 1<<6)
  1734. nt->builtBuildings.insert(42);
  1735. if(spec->buildingSettings[ir] & 1<<7)
  1736. nt->builtBuildings.insert(36);
  1737. }//else if (ir==4)
  1738. else if (ir==5)
  1739. {
  1740. if(bs==0)
  1741. {
  1742. if(spec->buildingSettings[ir] & (1<<bs))
  1743. {
  1744. nt->builtBuildings.insert(43); //gen7+
  1745. }
  1746. }
  1747. }//else if (ir==5)
  1748. }
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if(spec->hasFort)
  1754. {
  1755. nt->builtBuildings.insert(7);
  1756. }
  1757. }
  1758. nt->setOwner(spec->player);
  1759. nt->town = &CGI->townh->towns[nt->defInfo->subid];
  1760. nt->builded = 0;
  1761. nt->destroyed = 0;
  1762. nt->name = spec->name;
  1763. nt->garrison = spec->garrison;
  1764. nt->garrisonHero = NULL;// spec->garnisonHero is not readed - TODO: readit
  1765. nt->pos = int3(spec->x, spec->y, spec->z);
  1766. nt->possibleSpells = spec->possibleSpells;
  1767. nt->obligatorySpells = spec->obligatorySpells;
  1768. nt->availableSpells = std::vector<CSpell*>();
  1769. nt->creatureIncome = std::vector<int>();
  1770. nt->creaturesLeft = std::vector<int>();
  1771. CGI->townh->townInstances.push_back(nt);
  1772. break;
  1773. }
  1774. case EDefType::PLAYERONLY_DEF:
  1775. {
  1776. CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
  1777. spec->player = bufor[i]; ++i;
  1778. i+=3;
  1779. nobj->setOwner(spec->player);
  1780. nobj->info = spec;
  1781. break;
  1782. }
  1783. case EDefType::SHRINE_DEF:
  1784. {
  1785. CShrineObjInfo * spec = new CShrineObjInfo;
  1786. spec->spell = bufor[i]; i+=4;
  1787. nobj->info = spec;
  1788. break;
  1789. }
  1790. case EDefType::SPELLSCROLL_DEF:
  1791. {
  1792. CSpellScrollObjinfo * spec = new CSpellScrollObjinfo;
  1793. bool messg = bufor[i]; ++i;
  1794. if(messg)
  1795. {
  1796. int mLength = readNormalNr(i); i+=4;
  1797. for(int vv=0; vv<mLength; ++vv)
  1798. {
  1799. spec->message += bufor[i]; ++i;
  1800. }
  1801. spec->areGuarders = bufor[i]; ++i;
  1802. if(spec->areGuarders)
  1803. {
  1804. spec->guarders = readCreatureSet(i); i+=( map.version == RoE ? 21 : 28 );
  1805. }
  1806. i+=4;
  1807. }
  1808. spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
  1809. i+=3;
  1810. nobj->info = spec;
  1811. break;
  1812. }
  1813. case EDefType::PANDORA_DEF:
  1814. {
  1815. CPandorasBoxObjInfo * spec = new CPandorasBoxObjInfo;
  1816. bool messg = bufor[i]; ++i;
  1817. if(messg)
  1818. {
  1819. int mLength = readNormalNr(i); i+=4;
  1820. for(int vv=0; vv<mLength; ++vv)
  1821. {
  1822. spec->message += bufor[i]; ++i;
  1823. }
  1824. spec->areGuarders = bufor[i]; ++i;
  1825. if(spec->areGuarders)
  1826. {
  1827. spec->guarders = readCreatureSet(i); i+= (map.version == RoE ? 21 : 28);
  1828. }
  1829. i+=4;
  1830. }
  1831. ////// copied form event handling (seems to be similar)
  1832. spec->gainedExp = readNormalNr(i, 4); i+=4;
  1833. spec->manaDiff = readNormalNr(i, 4); i+=4;
  1834. spec->moraleDiff = readNormalNr(i, 1, true); ++i;
  1835. spec->luckDiff = readNormalNr(i, 1, true); ++i;
  1836. spec->wood = readNormalNr(i); i+=4;
  1837. spec->mercury = readNormalNr(i); i+=4;
  1838. spec->ore = readNormalNr(i); i+=4;
  1839. spec->sulfur = readNormalNr(i); i+=4;
  1840. spec->crystal = readNormalNr(i); i+=4;
  1841. spec->gems = readNormalNr(i); i+=4;
  1842. spec->gold = readNormalNr(i); i+=4;
  1843. spec->attack = readNormalNr(i, 1); ++i;
  1844. spec->defence = readNormalNr(i, 1); ++i;
  1845. spec->power = readNormalNr(i, 1); ++i;
  1846. spec->knowledge = readNormalNr(i, 1); ++i;
  1847. int gabn; //number of gained abilities
  1848. gabn = readNormalNr(i, 1); ++i;
  1849. for(int oo = 0; oo<gabn; ++oo)
  1850. {
  1851. spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
  1852. spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
  1853. }
  1854. int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
  1855. for(int oo = 0; oo<gart; ++oo)
  1856. {
  1857. spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
  1858. }
  1859. int gspel = readNormalNr(i, 1); ++i; //number of gained spells
  1860. for(int oo = 0; oo<gspel; ++oo)
  1861. {
  1862. spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
  1863. }
  1864. int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
  1865. spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
  1866. i+=8;
  1867. nobj->info = spec;
  1868. ///////end of copied fragment
  1869. break;
  1870. }
  1871. case EDefType::GRAIL_DEF:
  1872. {
  1873. CGrailObjInfo * spec = new CGrailObjInfo;
  1874. spec->radius = readNormalNr(i); i+=4;
  1875. nobj->info = spec;
  1876. break;
  1877. }
  1878. case EDefType::CREGEN_DEF:
  1879. {
  1880. CCreGenObjInfo * spec = new CCreGenObjInfo;
  1881. spec->player = bufor[i]; ++i;
  1882. i+=3;
  1883. for(int ggg=0; ggg<4; ++ggg)
  1884. {
  1885. spec->bytes[ggg] = bufor[i]; ++i;
  1886. }
  1887. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1888. {
  1889. spec->asCastle = false;
  1890. spec->castles[0] = bufor[i]; ++i;
  1891. spec->castles[1] = bufor[i]; ++i;
  1892. }
  1893. else
  1894. {
  1895. spec->asCastle = true;
  1896. }
  1897. nobj->setOwner(spec->player);
  1898. nobj->info = spec;
  1899. break;
  1900. }
  1901. case EDefType::CREGEN2_DEF:
  1902. {
  1903. CCreGen2ObjInfo * spec = new CCreGen2ObjInfo;
  1904. spec->player = bufor[i]; ++i;
  1905. i+=3;
  1906. for(int ggg=0; ggg<4; ++ggg)
  1907. {
  1908. spec->bytes[ggg] = bufor[i]; ++i;
  1909. }
  1910. if((spec->bytes[0] == '\0') && (spec->bytes[1] == '\0') && (spec->bytes[2] == '\0') && (spec->bytes[3] == '\0'))
  1911. {
  1912. spec->asCastle = false;
  1913. spec->castles[0] = bufor[i]; ++i;
  1914. spec->castles[1] = bufor[i]; ++i;
  1915. }
  1916. else
  1917. {
  1918. spec->asCastle = true;
  1919. }
  1920. spec->minLevel = bufor[i]; ++i;
  1921. spec->maxLevel = bufor[i]; ++i;
  1922. if(spec->maxLevel>7)
  1923. spec->maxLevel = 7;
  1924. if(spec->minLevel<1)
  1925. spec->minLevel = 1;
  1926. nobj->setOwner(spec->player);
  1927. nobj->info = spec;
  1928. break;
  1929. }
  1930. case EDefType::CREGEN3_DEF:
  1931. {
  1932. CCreGen3ObjInfo * spec = new CCreGen3ObjInfo;
  1933. spec->player = bufor[i]; ++i;
  1934. i+=3;
  1935. spec->minLevel = bufor[i]; ++i;
  1936. spec->maxLevel = bufor[i]; ++i;
  1937. if(spec->maxLevel>7)
  1938. spec->maxLevel = 7;
  1939. if(spec->minLevel<1)
  1940. spec->minLevel = 1;
  1941. nobj->setOwner(spec->player);
  1942. nobj->info = spec;
  1943. break;
  1944. }
  1945. case EDefType::BORDERGUARD_DEF:
  1946. {
  1947. CBorderGuardObjInfo * spec = new CBorderGuardObjInfo;
  1948. spec->missionType = bufor[i]; ++i;
  1949. switch(spec->missionType)
  1950. {
  1951. case 1:
  1952. {
  1953. spec->m1level = readNormalNr(i); i+=4;
  1954. int limit = readNormalNr(i); i+=4;
  1955. if(limit == ((int)0xffffffff))
  1956. {
  1957. spec->isDayLimit = false;
  1958. spec->lastDay = -1;
  1959. }
  1960. else
  1961. {
  1962. spec->isDayLimit = true;
  1963. spec->lastDay = limit;
  1964. }
  1965. break;
  1966. }
  1967. case 2:
  1968. {
  1969. spec->m2attack = bufor[i]; ++i;
  1970. spec->m2defence = bufor[i]; ++i;
  1971. spec->m2power = bufor[i]; ++i;
  1972. spec->m2knowledge = bufor[i]; ++i;
  1973. int limit = readNormalNr(i); i+=4;
  1974. if(limit == ((int)0xffffffff))
  1975. {
  1976. spec->isDayLimit = false;
  1977. spec->lastDay = -1;
  1978. }
  1979. else
  1980. {
  1981. spec->isDayLimit = true;
  1982. spec->lastDay = limit;
  1983. }
  1984. break;
  1985. }
  1986. case 3:
  1987. {
  1988. spec->m3bytes[0] = bufor[i]; ++i;
  1989. spec->m3bytes[1] = bufor[i]; ++i;
  1990. spec->m3bytes[2] = bufor[i]; ++i;
  1991. spec->m3bytes[3] = bufor[i]; ++i;
  1992. int limit = readNormalNr(i); i+=4;
  1993. if(limit == ((int)0xffffffff))
  1994. {
  1995. spec->isDayLimit = false;
  1996. spec->lastDay = -1;
  1997. }
  1998. else
  1999. {
  2000. spec->isDayLimit = true;
  2001. spec->lastDay = limit;
  2002. }
  2003. break;
  2004. }
  2005. case 4:
  2006. {
  2007. spec->m4bytes[0] = bufor[i]; ++i;
  2008. spec->m4bytes[1] = bufor[i]; ++i;
  2009. spec->m4bytes[2] = bufor[i]; ++i;
  2010. spec->m4bytes[3] = bufor[i]; ++i;
  2011. int limit = readNormalNr(i); i+=4;
  2012. if(limit == ((int)0xffffffff))
  2013. {
  2014. spec->isDayLimit = false;
  2015. spec->lastDay = -1;
  2016. }
  2017. else
  2018. {
  2019. spec->isDayLimit = true;
  2020. spec->lastDay = limit;
  2021. }
  2022. break;
  2023. }
  2024. case 5:
  2025. {
  2026. int artNumber = bufor[i]; ++i;
  2027. for(int yy=0; yy<artNumber; ++yy)
  2028. {
  2029. int artid = readNormalNr(i, 2); i+=2;
  2030. spec->m5arts.push_back(&(CGameInfo::mainObj->arth->artifacts[artid]));
  2031. }
  2032. int limit = readNormalNr(i); i+=4;
  2033. if(limit == ((int)0xffffffff))
  2034. {
  2035. spec->isDayLimit = false;
  2036. spec->lastDay = -1;
  2037. }
  2038. else
  2039. {
  2040. spec->isDayLimit = true;
  2041. spec->lastDay = limit;
  2042. }
  2043. break;
  2044. }
  2045. case 6:
  2046. {
  2047. int typeNumber = bufor[i]; ++i;
  2048. for(int hh=0; hh<typeNumber; ++hh)
  2049. {
  2050. int creType = readNormalNr(i, 2); i+=2;
  2051. int creNumb = readNormalNr(i, 2); i+=2;
  2052. spec->m6cre.push_back(&(CGameInfo::mainObj->creh->creatures[creType]));
  2053. spec->m6number.push_back(creNumb);
  2054. }
  2055. int limit = readNormalNr(i); i+=4;
  2056. if(limit == ((int)0xffffffff))
  2057. {
  2058. spec->isDayLimit = false;
  2059. spec->lastDay = -1;
  2060. }
  2061. else
  2062. {
  2063. spec->isDayLimit = true;
  2064. spec->lastDay = limit;
  2065. }
  2066. break;
  2067. }
  2068. case 7:
  2069. {
  2070. spec->m7wood = readNormalNr(i); i+=4;
  2071. spec->m7mercury = readNormalNr(i); i+=4;
  2072. spec->m7ore = readNormalNr(i); i+=4;
  2073. spec->m7sulfur = readNormalNr(i); i+=4;
  2074. spec->m7crystal = readNormalNr(i); i+=4;
  2075. spec->m7gems = readNormalNr(i); i+=4;
  2076. spec->m7gold = readNormalNr(i); i+=4;
  2077. int limit = readNormalNr(i); i+=4;
  2078. if(limit == ((int)0xffffffff))
  2079. {
  2080. spec->isDayLimit = false;
  2081. spec->lastDay = -1;
  2082. }
  2083. else
  2084. {
  2085. spec->isDayLimit = true;
  2086. spec->lastDay = limit;
  2087. }
  2088. break;
  2089. }
  2090. case 8:
  2091. {
  2092. int heroType = bufor[i]; ++i;
  2093. spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
  2094. int limit = readNormalNr(i); i+=4;
  2095. if(limit == ((int)0xffffffff))
  2096. {
  2097. spec->isDayLimit = false;
  2098. spec->lastDay = -1;
  2099. }
  2100. else
  2101. {
  2102. spec->isDayLimit = true;
  2103. spec->lastDay = limit;
  2104. }
  2105. break;
  2106. }
  2107. case 9:
  2108. {
  2109. spec->m9player = bufor[i]; ++i;
  2110. int limit = readNormalNr(i); i+=4;
  2111. if(limit == ((int)0xffffffff))
  2112. {
  2113. spec->isDayLimit = false;
  2114. spec->lastDay = -1;
  2115. }
  2116. else
  2117. {
  2118. spec->isDayLimit = true;
  2119. spec->lastDay = limit;
  2120. }
  2121. break;
  2122. }
  2123. }//internal switch end (seer huts)
  2124. int len1 = readNormalNr(i); i+=4;
  2125. for(int ee=0; ee<len1; ++ee)
  2126. {
  2127. spec->firstVisitText += bufor[i]; ++i;
  2128. }
  2129. int len2 = readNormalNr(i); i+=4;
  2130. for(int ee=0; ee<len2; ++ee)
  2131. {
  2132. spec->nextVisitText += bufor[i]; ++i;
  2133. }
  2134. int len3 = readNormalNr(i); i+=4;
  2135. for(int ee=0; ee<len3; ++ee)
  2136. {
  2137. spec->completedText += bufor[i]; ++i;
  2138. }
  2139. nobj->info = spec;
  2140. break;
  2141. }
  2142. } //end of main switch
  2143. CGameInfo::mainObj->objh->objInstances.push_back(nobj);
  2144. //TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
  2145. }//*/ //end of loading objects; commented to make application work until it will be finished
  2146. ////objects loaded
  2147. //processMap(defsToUnpack);
  2148. std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack);
  2149. for (int i=0;i<dhandlers.size();i++)
  2150. map.defy[i]->handler=dhandlers[i];
  2151. for(int vv=0; vv<map.defy.size(); ++vv)
  2152. {
  2153. if(map.defy[vv]->handler->alphaTransformed)
  2154. continue;
  2155. for(int yy=0; yy<map.defy[vv]->handler->ourImages.size(); ++yy)
  2156. {
  2157. map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap);
  2158. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap, alphaTransSurf);
  2159. SDL_FreeSurface(map.defy[vv]->handler->ourImages[yy].bitmap);
  2160. map.defy[vv]->handler->ourImages[yy].bitmap = bufs;
  2161. map.defy[vv]->handler->alphaTransformed = true;
  2162. }
  2163. }
  2164. SDL_FreeSurface(alphaTransSurf);
  2165. //assigning defobjinfos
  2166. for(int ww=0; ww<CGI->objh->objInstances.size(); ++ww)
  2167. {
  2168. for(int h=0; h<CGI->dobjinfo->objs.size(); ++h)
  2169. {
  2170. if(CGI->dobjinfo->objs[h].defName==CGI->objh->objInstances[ww]->defInfo->name)
  2171. {
  2172. CGI->objh->objInstances[ww]->defObjInfoNumber = h;
  2173. break;
  2174. }
  2175. }
  2176. }
  2177. //assigned
  2178. //loading events
  2179. int numberOfEvents = readNormalNr(i); i+=4;
  2180. for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
  2181. {
  2182. CMapEvent ne;
  2183. ne.name = std::string();
  2184. ne.message = std::string();
  2185. int nameLen = readNormalNr(i); i+=4;
  2186. for(int qq=0; qq<nameLen; ++qq)
  2187. {
  2188. ne.name += bufor[i]; ++i;
  2189. }
  2190. int messLen = readNormalNr(i); i+=4;
  2191. for(int qq=0; qq<messLen; ++qq)
  2192. {
  2193. ne.message +=bufor[i]; ++i;
  2194. }
  2195. ne.wood = readNormalNr(i); i+=4;
  2196. ne.mercury = readNormalNr(i); i+=4;
  2197. ne.ore = readNormalNr(i); i+=4;
  2198. ne.sulfur = readNormalNr(i); i+=4;
  2199. ne.crystal = readNormalNr(i); i+=4;
  2200. ne.gems = readNormalNr(i); i+=4;
  2201. ne.gold = readNormalNr(i); i+=4;
  2202. ne.players = bufor[i]; ++i;
  2203. if(map.version>AB)
  2204. {
  2205. ne.humanAffected = bufor[i]; ++i;
  2206. }
  2207. else
  2208. ne.humanAffected = true;
  2209. ne.computerAffected = bufor[i]; ++i;
  2210. ne.firstOccurence = bufor[i]; ++i;
  2211. ne.nextOccurence = bufor[i]; ++i;
  2212. i+=18;
  2213. map.events.push_back(ne);
  2214. }
  2215. }
  2216. int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
  2217. {
  2218. int ret=0;
  2219. int amp=1;
  2220. for (int i=0; i<bytCon; i++)
  2221. {
  2222. ret+=bufor[pos+i]*amp;
  2223. amp*=256;
  2224. }
  2225. if(cyclic && bytCon<4 && ret>=amp/2)
  2226. {
  2227. ret = ret-amp;
  2228. }
  2229. return ret;
  2230. }
  2231. void CAmbarCendamo::loadDefs()
  2232. {
  2233. std::set<int> loadedTypes;
  2234. for (int i=0; i<map.width; i++)
  2235. {
  2236. for (int j=0; j<map.width; j++)
  2237. {
  2238. if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end())
  2239. {
  2240. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str());
  2241. loadedTypes.insert(map.terrain[i][j].tertype);
  2242. defs.push_back(sdh);
  2243. }
  2244. if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
  2245. {
  2246. CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str());
  2247. loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
  2248. defs.push_back(sdh);
  2249. }
  2250. }
  2251. }
  2252. }
  2253. EDefType CAmbarCendamo::getDefType(CGDefInfo * a)
  2254. {
  2255. switch(a->id)
  2256. {
  2257. case 5: case 65: case 66: case 67: case 68: case 69:
  2258. return EDefType::ARTIFACT_DEF; //handled
  2259. case 6:
  2260. return EDefType::PANDORA_DEF; //hanled
  2261. case 26:
  2262. return EDefType::EVENTOBJ_DEF; //handled
  2263. case 33:
  2264. return EDefType::GARRISON_DEF; //handled
  2265. case 34: case 70: case 62: //70 - random hero //62 - prison
  2266. return EDefType::HERO_DEF; //handled
  2267. case 36:
  2268. return EDefType::GRAIL_DEF; //hanled
  2269. case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
  2270. return EDefType::PLAYERONLY_DEF; //handled
  2271. case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
  2272. return EDefType::CREATURES_DEF; //handled
  2273. case 59:
  2274. return EDefType::SIGN_DEF; //handled
  2275. case 77:
  2276. return EDefType::TOWN_DEF; //can be problematic, but handled
  2277. case 79: case 76:
  2278. return EDefType::RESOURCE_DEF; //handled
  2279. case 81:
  2280. return EDefType::SCHOLAR_DEF; //handled
  2281. case 83:
  2282. return EDefType::SEERHUT_DEF; //handled
  2283. case 91:
  2284. return EDefType::SIGN_DEF; //handled
  2285. case 88: case 89: case 90:
  2286. return SHRINE_DEF; //handled
  2287. case 93:
  2288. return SPELLSCROLL_DEF; //handled
  2289. case 98:
  2290. return EDefType::TOWN_DEF; //handled
  2291. case 113:
  2292. return EDefType::WITCHHUT_DEF; //handled
  2293. case 215:
  2294. return EDefType::BORDERGUARD_DEF; //handled by analogy to seer huts ;]
  2295. case 216:
  2296. return EDefType::CREGEN2_DEF; //handled
  2297. case 217:
  2298. return EDefType::CREGEN_DEF; //handled
  2299. case 218:
  2300. return EDefType::CREGEN3_DEF; //handled
  2301. case 219:
  2302. return EDefType::GARRISON_DEF; //handled
  2303. default:
  2304. return EDefType::TERRAINOBJ_DEF; // nothing to be handled
  2305. }
  2306. }
  2307. CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
  2308. {
  2309. if(map.version>RoE)
  2310. {
  2311. CCreatureSet ret;
  2312. std::pair<CCreature *, int> ins;
  2313. if(number>0 && readNormalNr(pos, 2)!=0xffff)
  2314. {
  2315. int rettt = readNormalNr(pos, 2);
  2316. if(rettt>32768)
  2317. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2318. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2319. ins.second = readNormalNr(pos+2, 2);
  2320. std::pair<int,std::pair<CCreature *, int> > tt(0,ins);
  2321. ret.slots.insert(tt);
  2322. }
  2323. if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
  2324. {
  2325. int rettt = readNormalNr(pos+4, 2);
  2326. if(rettt>32768)
  2327. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2328. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2329. ins.second = readNormalNr(pos+6, 2);
  2330. std::pair<int,std::pair<CCreature *, int> > tt(1,ins);
  2331. ret.slots.insert(tt);
  2332. }
  2333. if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
  2334. {
  2335. int rettt = readNormalNr(pos+8, 2);
  2336. if(rettt>32768)
  2337. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2338. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2339. ins.second = readNormalNr(pos+10, 2);
  2340. std::pair<int,std::pair<CCreature *, int> > tt(2,ins);
  2341. ret.slots.insert(tt);
  2342. }
  2343. if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
  2344. {
  2345. int rettt = readNormalNr(pos+12, 2);
  2346. if(rettt>32768)
  2347. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2348. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2349. ins.second = readNormalNr(pos+14, 2);
  2350. std::pair<int,std::pair<CCreature *, int> > tt(3,ins);
  2351. ret.slots.insert(tt);
  2352. }
  2353. if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
  2354. {
  2355. int rettt = readNormalNr(pos+16, 2);
  2356. if(rettt>32768)
  2357. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2358. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2359. ins.second = readNormalNr(pos+18, 2);
  2360. std::pair<int,std::pair<CCreature *, int> > tt(4,ins);
  2361. ret.slots.insert(tt);
  2362. }
  2363. if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
  2364. {
  2365. int rettt = readNormalNr(pos+20, 2);
  2366. if(rettt>32768)
  2367. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2368. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2369. ins.second = readNormalNr(pos+22, 2);
  2370. std::pair<int,std::pair<CCreature *, int> > tt(5,ins);
  2371. ret.slots.insert(tt);
  2372. }
  2373. if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
  2374. {
  2375. int rettt = readNormalNr(pos+24, 2);
  2376. if(rettt>32768)
  2377. rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2378. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2379. ins.second = readNormalNr(pos+26, 2);
  2380. std::pair<int,std::pair<CCreature *, int> > tt(6,ins);
  2381. ret.slots.insert(tt);
  2382. }
  2383. return ret;
  2384. }
  2385. else
  2386. {
  2387. CCreatureSet ret;
  2388. std::pair<CCreature *, int> ins;
  2389. if(number>0 && readNormalNr(pos, 1)!=0xff)
  2390. {
  2391. int rettt = readNormalNr(pos, 1);
  2392. if(rettt>220)
  2393. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2394. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2395. ins.second = readNormalNr(pos+1, 2);
  2396. std::pair<int,std::pair<CCreature *, int> > tt(0,ins);
  2397. ret.slots.insert(tt);
  2398. }
  2399. if(number>1 && readNormalNr(pos+3, 1)!=0xff)
  2400. {
  2401. int rettt = readNormalNr(pos+3, 1);
  2402. if(rettt>220)
  2403. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2404. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2405. ins.second = readNormalNr(pos+4, 2);
  2406. std::pair<int,std::pair<CCreature *, int> > tt(1,ins);
  2407. ret.slots.insert(tt);
  2408. }
  2409. if(number>2 && readNormalNr(pos+6, 1)!=0xff)
  2410. {
  2411. int rettt = readNormalNr(pos+6, 1);
  2412. if(rettt>220)
  2413. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2414. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2415. ins.second = readNormalNr(pos+7, 2);
  2416. std::pair<int,std::pair<CCreature *, int> > tt(2,ins);
  2417. ret.slots.insert(tt);
  2418. }
  2419. if(number>3 && readNormalNr(pos+9, 1)!=0xff)
  2420. {
  2421. int rettt = readNormalNr(pos+9, 1);
  2422. if(rettt>220)
  2423. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2424. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2425. ins.second = readNormalNr(pos+10, 2);
  2426. std::pair<int,std::pair<CCreature *, int> > tt(3,ins);
  2427. ret.slots.insert(tt);
  2428. }
  2429. if(number>4 && readNormalNr(pos+12, 1)!=0xff)
  2430. {
  2431. int rettt = readNormalNr(pos+12, 1);
  2432. if(rettt>220)
  2433. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2434. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2435. ins.second = readNormalNr(pos+13, 2);
  2436. std::pair<int,std::pair<CCreature *, int> > tt(4,ins);
  2437. ret.slots.insert(tt);
  2438. }
  2439. if(number>5 && readNormalNr(pos+15, 1)!=0xff)
  2440. {
  2441. int rettt = readNormalNr(pos+15, 1);
  2442. if(rettt>220)
  2443. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2444. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2445. ins.second = readNormalNr(pos+16, 2);
  2446. std::pair<int,std::pair<CCreature *, int> > tt(5,ins);
  2447. ret.slots.insert(tt);
  2448. }
  2449. if(number>6 && readNormalNr(pos+18, 1)!=0xff)
  2450. {
  2451. int rettt = readNormalNr(pos+18, 1);
  2452. if(rettt>220)
  2453. rettt = 256-rettt+CGameInfo::mainObj->creh->creatures.size()-16;
  2454. ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]);
  2455. ins.second = readNormalNr(pos+19, 2);
  2456. std::pair<int,std::pair<CCreature *, int> > tt(6,ins);
  2457. ret.slots.insert(tt);
  2458. }
  2459. return ret;
  2460. }
  2461. }
  2462. void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
  2463. {
  2464. resDefNames.push_back("AVTRNDM0.DEF");
  2465. resDefNames.push_back("AVTWOOD0.DEF");
  2466. resDefNames.push_back("AVTMERC0.DEF");
  2467. resDefNames.push_back("AVTORE0.DEF");
  2468. resDefNames.push_back("AVTSULF0.DEF");
  2469. resDefNames.push_back("AVTCRYS0.DEF");
  2470. resDefNames.push_back("AVTGEMS0.DEF");
  2471. resDefNames.push_back("AVTGOLD0.DEF");
  2472. resDefNames.push_back("ZMITHR.DEF");
  2473. std::vector<CGDefInfo*> resDefNumbers;
  2474. for(int hh=0; hh<resDefNames.size(); ++hh)
  2475. {
  2476. resDefNumbers.push_back(NULL);
  2477. for(int k=0; k<map.defy.size(); ++k)
  2478. {
  2479. std::string buf = map.defy[k]->name;
  2480. std::transform(buf.begin(), buf.end(), buf.begin(), (int(*)(int))toupper);
  2481. if(resDefNames[hh] == buf)
  2482. {
  2483. resDefNumbers[resDefNumbers.size()-1] = map.defy[k];
  2484. break;
  2485. }
  2486. }
  2487. }
  2488. std::vector<std::string> creDefNames;
  2489. for(int dd=0; dd<140; ++dd) //we do not use here WoG units
  2490. {
  2491. creDefNames.push_back(CGI->dobjinfo->objs[dd+1184].defName);
  2492. }
  2493. std::vector<CGDefInfo*> creDefNumbers;
  2494. for(int ee=0; ee<creDefNames.size(); ++ee)
  2495. {
  2496. creDefNumbers.push_back(NULL);
  2497. }
  2498. std::vector<std::string> artDefNames;
  2499. std::vector<CGDefInfo* > artDefNumbers;
  2500. for(int bb=0; bb<162; ++bb)
  2501. {
  2502. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass!=EartClass::SartClass)
  2503. artDefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2504. }
  2505. for(int ee=0; ee<artDefNames.size(); ++ee)
  2506. {
  2507. artDefNumbers.push_back(NULL);
  2508. }
  2509. std::vector<std::string> art1DefNames;
  2510. std::vector<CGDefInfo*> art1DefNumbers;
  2511. for(int bb=0; bb<162; ++bb)
  2512. {
  2513. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::TartClass)
  2514. art1DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2515. }
  2516. for(int ee=0; ee<art1DefNames.size(); ++ee)
  2517. {
  2518. art1DefNumbers.push_back(NULL);
  2519. }
  2520. std::vector<std::string> art2DefNames;
  2521. std::vector<CGDefInfo*> art2DefNumbers;
  2522. for(int bb=0; bb<162; ++bb)
  2523. {
  2524. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::NartClass)
  2525. art2DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2526. }
  2527. for(int ee=0; ee<art2DefNames.size(); ++ee)
  2528. {
  2529. art2DefNumbers.push_back(NULL);
  2530. }
  2531. std::vector<std::string> art3DefNames;
  2532. std::vector<CGDefInfo*> art3DefNumbers;
  2533. for(int bb=0; bb<162; ++bb)
  2534. {
  2535. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::JartClass)
  2536. art3DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2537. }
  2538. for(int ee=0; ee<art3DefNames.size(); ++ee)
  2539. {
  2540. art3DefNumbers.push_back(NULL);
  2541. }
  2542. std::vector<std::string> art4DefNames;
  2543. std::vector<CGDefInfo*> art4DefNumbers;
  2544. for(int bb=0; bb<162; ++bb)
  2545. {
  2546. if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::RartClass)
  2547. art4DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName);
  2548. }
  2549. for(int ee=0; ee<art4DefNames.size(); ++ee)
  2550. {
  2551. art4DefNumbers.push_back(NULL);
  2552. }
  2553. std::vector<std::string> town0DefNames; //without fort
  2554. std::vector<CGDefInfo*> town0DefNumbers;
  2555. std::vector<std::string> town1DefNames; //with fort
  2556. std::vector<CGDefInfo*> town1DefNumbers;
  2557. for(int dd=0; dd<F_NUMBER; ++dd)
  2558. {
  2559. town1DefNames.push_back(CGI->dobjinfo->objs[dd+385].defName);
  2560. town1DefNumbers.push_back(NULL);
  2561. }
  2562. std::vector< std::vector<std::string> > creGenNames;
  2563. std::vector< std::vector<CGDefInfo*> > creGenNumbers;
  2564. creGenNames.resize(F_NUMBER);
  2565. creGenNumbers.resize(F_NUMBER);
  2566. for(int ff=0; ff<F_NUMBER-1; ++ff)
  2567. {
  2568. for(int dd=0; dd<7; ++dd)
  2569. {
  2570. creGenNames[ff].push_back(CGI->dobjinfo->objs[395+7*ff+dd].defName);
  2571. creGenNumbers[ff].push_back(NULL);
  2572. }
  2573. }
  2574. for(int dd=0; dd<7; ++dd)
  2575. {
  2576. creGenNumbers[8].push_back(NULL);
  2577. }
  2578. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[457].defName);
  2579. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[452].defName);
  2580. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[455].defName);
  2581. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[454].defName);
  2582. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName);
  2583. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
  2584. creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[459].defName);
  2585. for(int b=0; b<CGI->scenarioOps.playerInfos.size(); ++b) // choosing random player alignment
  2586. {
  2587. if(CGI->scenarioOps.playerInfos[b].castle==-1)
  2588. CGI->scenarioOps.playerInfos[b].castle = rand()%F_NUMBER;
  2589. }
  2590. //variables initialized
  2591. for(int j=0; j<CGI->objh->objInstances.size(); ++j)
  2592. {
  2593. CGDefInfo * curDef = CGI->objh->objInstances[j]->defInfo;
  2594. switch(getDefType(curDef))
  2595. {
  2596. case EDefType::RESOURCE_DEF:
  2597. {
  2598. if(curDef->id==76) //resource to specify
  2599. {
  2600. CGDefInfo * nxt = curDef;
  2601. nxt->id = 79;
  2602. nxt->subid = rand()%7;
  2603. if(resDefNumbers[nxt->subid+1]!=NULL)
  2604. {
  2605. CGI->objh->objInstances[j]->defInfo = resDefNumbers[nxt->subid+1];
  2606. continue;
  2607. }
  2608. nxt->name = resDefNames[nxt->subid+1];
  2609. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2610. nxt->name);
  2611. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2612. {
  2613. nxt->isOnDefList = false;
  2614. }
  2615. else
  2616. {
  2617. nxt->printPriority = pit->priority;
  2618. nxt->isOnDefList = true;
  2619. }
  2620. map.defy.push_back(nxt); // add this def to the vector
  2621. defsToUnpack.push_back(nxt->name);
  2622. CGI->objh->objInstances[j]->defInfo = nxt;
  2623. if(resDefNumbers[nxt->subid+1]==NULL)
  2624. {
  2625. resDefNumbers[nxt->subid+1] = nxt;
  2626. }
  2627. }
  2628. break;
  2629. }
  2630. case EDefType::CREATURES_DEF:
  2631. {
  2632. if(curDef->id==72) //random monster lvl 1
  2633. {
  2634. CGDefInfo * nxt = curDef;
  2635. nxt->id = 54;
  2636. nxt->subid = 14*(rand()%9)+rand()%2;
  2637. if(creDefNumbers[nxt->subid]!=NULL)
  2638. {
  2639. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2640. continue;
  2641. }
  2642. nxt->name = creDefNames[nxt->subid];
  2643. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2644. nxt->name);
  2645. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2646. {
  2647. nxt->isOnDefList = false;
  2648. }
  2649. else
  2650. {
  2651. nxt->printPriority = pit->priority;
  2652. nxt->isOnDefList = true;
  2653. }
  2654. map.defy.push_back(nxt); // add this def to the vector
  2655. defsToUnpack.push_back(nxt->name);
  2656. CGI->objh->objInstances[j]->defInfo = nxt;
  2657. if(creDefNumbers[nxt->subid]==NULL)
  2658. {
  2659. creDefNumbers[nxt->subid] = nxt;
  2660. }
  2661. }
  2662. if(curDef->id==73) //random monster lvl 2
  2663. {
  2664. CGDefInfo * nxt = curDef;
  2665. nxt->id = 54;
  2666. nxt->subid = 14*(rand()%9)+rand()%2+2;
  2667. if(creDefNumbers[nxt->subid]!=NULL)
  2668. {
  2669. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2670. continue;
  2671. }
  2672. nxt->name = creDefNames[nxt->subid];
  2673. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2674. nxt->name);
  2675. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2676. {
  2677. nxt->isOnDefList = false;
  2678. }
  2679. else
  2680. {
  2681. nxt->printPriority = pit->priority;
  2682. nxt->isOnDefList = true;
  2683. }
  2684. map.defy.push_back(nxt); // add this def to the vector
  2685. defsToUnpack.push_back(nxt->name);
  2686. CGI->objh->objInstances[j]->defInfo = nxt;
  2687. if(creDefNumbers[nxt->subid]==NULL)
  2688. {
  2689. creDefNumbers[nxt->subid] = nxt;
  2690. }
  2691. }
  2692. if(curDef->id==74) //random monster lvl 3
  2693. {
  2694. CGDefInfo *nxt = curDef;
  2695. nxt->id = 54;
  2696. nxt->subid = 14*(rand()%9)+rand()%2+4;
  2697. if(creDefNumbers[nxt->subid]!=NULL)
  2698. {
  2699. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2700. continue;
  2701. }
  2702. nxt->name = creDefNames[nxt->subid];
  2703. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2704. nxt->name);
  2705. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2706. {
  2707. nxt->isOnDefList = false;
  2708. }
  2709. else
  2710. {
  2711. nxt->printPriority = pit->priority;
  2712. nxt->isOnDefList = true;
  2713. }
  2714. map.defy.push_back(nxt); // add this def to the vector
  2715. defsToUnpack.push_back(nxt->name);
  2716. CGI->objh->objInstances[j]->defInfo = nxt;
  2717. if(creDefNumbers[nxt->subid]==NULL)
  2718. {
  2719. creDefNumbers[nxt->subid] = nxt;
  2720. }
  2721. }
  2722. if(curDef->id==75) //random monster lvl 4
  2723. {
  2724. CGDefInfo * nxt = curDef;
  2725. nxt->id = 54;
  2726. nxt->subid = 14*(rand()%9)+rand()%2+6;
  2727. if(creDefNumbers[nxt->subid]!=NULL)
  2728. {
  2729. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2730. continue;
  2731. }
  2732. nxt->name = creDefNames[nxt->subid];
  2733. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2734. nxt->name);
  2735. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2736. {
  2737. nxt->isOnDefList = false;
  2738. }
  2739. else
  2740. {
  2741. nxt->printPriority = pit->priority;
  2742. nxt->isOnDefList = true;
  2743. }
  2744. map.defy.push_back(nxt); // add this def to the vector
  2745. defsToUnpack.push_back(nxt->name);
  2746. CGI->objh->objInstances[j]->defInfo = nxt;
  2747. if(creDefNumbers[nxt->subid]==NULL)
  2748. {
  2749. creDefNumbers[nxt->subid] = nxt;
  2750. }
  2751. }
  2752. if(curDef->id==162) //random monster lvl 5
  2753. {
  2754. CGDefInfo * nxt = curDef;
  2755. nxt->id = 54;
  2756. nxt->subid = 14*(rand()%9)+rand()%2+8;
  2757. if(creDefNumbers[nxt->subid]!=NULL)
  2758. {
  2759. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2760. continue;
  2761. }
  2762. nxt->name = creDefNames[nxt->subid];
  2763. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2764. nxt->name);
  2765. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2766. {
  2767. nxt->isOnDefList = false;
  2768. }
  2769. else
  2770. {
  2771. nxt->printPriority = pit->priority;
  2772. nxt->isOnDefList = true;
  2773. }
  2774. map.defy.push_back(nxt); // add this def to the vector
  2775. defsToUnpack.push_back(nxt->name);
  2776. CGI->objh->objInstances[j]->defInfo = nxt;
  2777. if(creDefNumbers[nxt->subid]==NULL)
  2778. {
  2779. creDefNumbers[nxt->subid] = nxt;
  2780. }
  2781. }
  2782. if(curDef->id==163) //random monster lvl 6
  2783. {
  2784. CGDefInfo* nxt = curDef;
  2785. nxt->id = 54;
  2786. nxt->subid = 14*(rand()%9)+rand()%2+10;
  2787. if(creDefNumbers[nxt->subid]!=NULL)
  2788. {
  2789. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2790. continue;
  2791. }
  2792. nxt->name = creDefNames[nxt->subid];
  2793. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2794. nxt->name);
  2795. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2796. {
  2797. nxt->isOnDefList = false;
  2798. }
  2799. else
  2800. {
  2801. nxt->printPriority = pit->priority;
  2802. nxt->isOnDefList = true;
  2803. }
  2804. map.defy.push_back(nxt); // add this def to the vector
  2805. defsToUnpack.push_back(nxt->name);
  2806. CGI->objh->objInstances[j]->defInfo = nxt;
  2807. if(creDefNumbers[nxt->subid]==NULL)
  2808. {
  2809. creDefNumbers[nxt->subid] = nxt;
  2810. }
  2811. }
  2812. if(curDef->id==164) //random monster lvl 7
  2813. {
  2814. CGDefInfo * nxt = curDef;
  2815. nxt->id = 54;
  2816. nxt->subid = 14*(rand()%9)+rand()%2+12;
  2817. if(creDefNumbers[nxt->subid]!=NULL)
  2818. {
  2819. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2820. continue;
  2821. }
  2822. nxt->name = creDefNames[nxt->subid];
  2823. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2824. nxt->name);
  2825. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2826. {
  2827. nxt->isOnDefList = false;
  2828. }
  2829. else
  2830. {
  2831. nxt->printPriority = pit->priority;
  2832. nxt->isOnDefList = true;
  2833. }
  2834. map.defy.push_back(nxt); // add this def to the vector
  2835. defsToUnpack.push_back(nxt->name);
  2836. CGI->objh->objInstances[j]->defInfo = nxt;
  2837. if(creDefNumbers[nxt->subid]==NULL)
  2838. {
  2839. creDefNumbers[nxt->subid] = nxt;
  2840. }
  2841. }
  2842. if(curDef->id==71) //random monster (any level)
  2843. {
  2844. CGDefInfo * nxt = curDef;
  2845. nxt->id = 54;
  2846. nxt->subid = rand()%126;
  2847. if(creDefNumbers[nxt->subid]!=NULL)
  2848. {
  2849. CGI->objh->objInstances[j]->defInfo = creDefNumbers[nxt->subid];
  2850. continue;
  2851. }
  2852. nxt->name = creDefNames[nxt->subid];
  2853. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2854. nxt->name);
  2855. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2856. {
  2857. nxt->isOnDefList = false;
  2858. }
  2859. else
  2860. {
  2861. nxt->printPriority = pit->priority;
  2862. nxt->isOnDefList = true;
  2863. }
  2864. map.defy.push_back(nxt); // add this def to the vector
  2865. defsToUnpack.push_back(nxt->name);
  2866. CGI->objh->objInstances[j]->defInfo = nxt;
  2867. if(creDefNumbers[nxt->subid]==NULL)
  2868. {
  2869. creDefNumbers[nxt->subid] = nxt;
  2870. }
  2871. }
  2872. break;
  2873. } //end of case
  2874. case EDefType::ARTIFACT_DEF:
  2875. {
  2876. if(curDef->id==65) //random atrifact (any class)
  2877. {
  2878. CGDefInfo *nxt = curDef;
  2879. nxt->id = 5;
  2880. nxt->subid = rand()%artDefNames.size();
  2881. if(artDefNumbers[nxt->subid]!=NULL)
  2882. {
  2883. CGI->objh->objInstances[j]->defInfo = artDefNumbers[nxt->subid];
  2884. continue;
  2885. }
  2886. nxt->name = artDefNames[nxt->subid];
  2887. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2888. nxt->name);
  2889. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2890. {
  2891. nxt->isOnDefList = false;
  2892. }
  2893. else
  2894. {
  2895. nxt->printPriority = pit->priority;
  2896. nxt->isOnDefList = true;
  2897. }
  2898. map.defy.push_back(nxt); // add this def to the vector
  2899. defsToUnpack.push_back(nxt->name);
  2900. CGI->objh->objInstances[j]->defInfo = nxt;
  2901. if(artDefNumbers[nxt->subid]==NULL)
  2902. {
  2903. artDefNumbers[nxt->subid] = nxt;
  2904. }
  2905. }
  2906. if(curDef->id==66) //random atrifact (treasure)
  2907. {
  2908. CGDefInfo* nxt = curDef;
  2909. nxt->id = 5;
  2910. nxt->subid = rand()%art1DefNames.size();
  2911. if(art1DefNumbers[nxt->subid]!=NULL)
  2912. {
  2913. CGI->objh->objInstances[j]->defInfo = art1DefNumbers[nxt->subid];
  2914. continue;
  2915. }
  2916. nxt->name = art1DefNames[nxt->subid];
  2917. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2918. nxt->name);
  2919. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2920. {
  2921. nxt->isOnDefList = false;
  2922. }
  2923. else
  2924. {
  2925. nxt->printPriority = pit->priority;
  2926. nxt->isOnDefList = true;
  2927. }
  2928. map.defy.push_back(nxt); // add this def to the vector
  2929. defsToUnpack.push_back(nxt->name);
  2930. CGI->objh->objInstances[j]->defInfo = nxt;
  2931. if(art1DefNumbers[nxt->subid]==NULL)
  2932. {
  2933. art1DefNumbers[nxt->subid] = nxt;
  2934. }
  2935. }
  2936. if(curDef->id==67) //random atrifact (minor)
  2937. {
  2938. CGDefInfo *nxt = curDef;
  2939. nxt->id = 5;
  2940. nxt->subid = rand()%art2DefNames.size();
  2941. if(art2DefNumbers[nxt->subid]!=NULL)
  2942. {
  2943. CGI->objh->objInstances[j]->defInfo = art2DefNumbers[nxt->subid];
  2944. continue;
  2945. }
  2946. nxt->name = art2DefNames[nxt->subid];
  2947. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2948. nxt->name);
  2949. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2950. {
  2951. nxt->isOnDefList = false;
  2952. }
  2953. else
  2954. {
  2955. nxt->printPriority = pit->priority;
  2956. nxt->isOnDefList = true;
  2957. }
  2958. map.defy.push_back(nxt); // add this def to the vector
  2959. defsToUnpack.push_back(nxt->name);
  2960. CGI->objh->objInstances[j]->defInfo = nxt;
  2961. if(art2DefNumbers[nxt->subid]==NULL)
  2962. {
  2963. art2DefNumbers[nxt->subid] = nxt;
  2964. }
  2965. }
  2966. if(curDef->id==68) //random atrifact (major)
  2967. {
  2968. CGDefInfo* nxt = curDef;
  2969. nxt->id = 5;
  2970. nxt->subid = rand()%art3DefNames.size();
  2971. if(art3DefNumbers[nxt->subid]!=NULL)
  2972. {
  2973. CGI->objh->objInstances[j]->defInfo = art3DefNumbers[nxt->subid];
  2974. continue;
  2975. }
  2976. nxt->name = art3DefNames[nxt->subid];
  2977. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  2978. nxt->name);
  2979. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  2980. {
  2981. nxt->isOnDefList = false;
  2982. }
  2983. else
  2984. {
  2985. nxt->printPriority = pit->priority;
  2986. nxt->isOnDefList = true;
  2987. }
  2988. map.defy.push_back(nxt); // add this def to the vector
  2989. defsToUnpack.push_back(nxt->name);
  2990. CGI->objh->objInstances[j]->defInfo = nxt;
  2991. if(art3DefNumbers[nxt->subid]==NULL)
  2992. {
  2993. art3DefNumbers[nxt->subid] =nxt;
  2994. }
  2995. }
  2996. if(curDef->id==69) //random atrifact (relic)
  2997. {
  2998. CGDefInfo *nxt = curDef;
  2999. nxt->id = 5;
  3000. nxt->subid = rand()%art4DefNames.size();
  3001. if(art4DefNumbers[nxt->subid]!=NULL)
  3002. {
  3003. CGI->objh->objInstances[j]->defInfo = art4DefNumbers[nxt->subid];
  3004. continue;
  3005. }
  3006. nxt->name = art4DefNames[nxt->subid];
  3007. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3008. nxt->name);
  3009. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3010. {
  3011. nxt->isOnDefList = false;
  3012. }
  3013. else
  3014. {
  3015. nxt->printPriority = pit->priority;
  3016. nxt->isOnDefList = true;
  3017. }
  3018. map.defy.push_back(nxt); // add this def to the vector
  3019. defsToUnpack.push_back(nxt->name);
  3020. CGI->objh->objInstances[j]->defInfo = nxt;
  3021. if(art4DefNumbers[nxt->subid]==NULL)
  3022. {
  3023. art4DefNumbers[nxt->subid] = nxt;
  3024. }
  3025. }
  3026. break;
  3027. }
  3028. case EDefType::TOWN_DEF:
  3029. {
  3030. if(curDef->id==77) //random town
  3031. {
  3032. CGDefInfo* nxt = curDef;
  3033. nxt->id = 98;
  3034. if(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player==0xff)
  3035. {
  3036. nxt->subid = rand()%town1DefNames.size();
  3037. }
  3038. else
  3039. {
  3040. if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle>-1)
  3041. {
  3042. nxt->subid = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle;
  3043. }
  3044. else
  3045. {
  3046. nxt->subid = rand()%town1DefNames.size();
  3047. }
  3048. }
  3049. if(town1DefNumbers[nxt->subid]!=NULL)
  3050. {
  3051. CGI->objh->objInstances[j]->defInfo = town1DefNumbers[nxt->subid];
  3052. continue;
  3053. }
  3054. nxt->name = town1DefNames[nxt->subid];
  3055. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3056. nxt->name);
  3057. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3058. {
  3059. nxt->isOnDefList = false;
  3060. }
  3061. else
  3062. {
  3063. nxt->printPriority = pit->priority;
  3064. nxt->isOnDefList = true;
  3065. }
  3066. map.defy.push_back(nxt); // add this def to the vector
  3067. defsToUnpack.push_back(nxt->name);
  3068. CGI->objh->objInstances[j]->defInfo = nxt;
  3069. if(town1DefNumbers[nxt->subid]==NULL)
  3070. {
  3071. town1DefNumbers[nxt->subid] = nxt;
  3072. }
  3073. for (int ij=0;ij<CGI->townh->townInstances.size();ij++) // wyharatac gdy bedzie dziedziczenie
  3074. {
  3075. if (CGI->townh->townInstances[ij]->pos==CGI->objh->objInstances[j]->pos)
  3076. {
  3077. CGI->townh->townInstances[ij]->town = &CGI->townh->towns[nxt->subid];
  3078. break;
  3079. }
  3080. }
  3081. }
  3082. //((CCastleObjInfo*)CGI->objh->objInstances[j].info)
  3083. break;
  3084. }
  3085. case EDefType::HERO_DEF:
  3086. {
  3087. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3088. CGI->objh->objInstances[j]->defInfo->name);
  3089. CGI->objh->objInstances[j]->defInfo->printPriority = 0;
  3090. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3091. {
  3092. CGI->objh->objInstances[j]->defInfo->isOnDefList = false;
  3093. }
  3094. else
  3095. {
  3096. CGI->objh->objInstances[j]->defInfo->isOnDefList = true;
  3097. }
  3098. break;
  3099. }
  3100. } //end of main switch
  3101. } //end of main loop
  3102. for(int j=0; j<CGI->objh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent)
  3103. {
  3104. CGDefInfo * curDef = CGI->objh->objInstances[j]->defInfo;
  3105. switch(getDefType(curDef))
  3106. {
  3107. case EDefType::CREGEN_DEF:
  3108. {
  3109. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
  3110. {
  3111. CGDefInfo *nxt = curDef;
  3112. nxt->id = 17;
  3113. for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
  3114. {
  3115. if(getDefType(CGI->objh->objInstances[vv]->defInfo)==EDefType::TOWN_DEF)
  3116. {
  3117. if(
  3118. ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
  3119. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
  3120. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
  3121. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
  3122. {
  3123. for(int mm=0; mm<town1DefNames.size(); ++mm)
  3124. {
  3125. std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
  3126. std::string hlp = CGI->objh->objInstances[vv]->defInfo->name;
  3127. std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
  3128. if(town1DefNames[mm]==hlp)
  3129. {
  3130. nxt->subid = mm;
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. int lvl = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str())-1;
  3137. nxt->name = creGenNames[nxt->subid][lvl];
  3138. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3139. {
  3140. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3141. continue;
  3142. }
  3143. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3144. nxt->name);
  3145. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3146. {
  3147. nxt->isOnDefList = false;
  3148. }
  3149. else
  3150. {
  3151. nxt->printPriority = pit->priority;
  3152. nxt->isOnDefList = true;
  3153. }
  3154. map.defy.push_back(nxt); // add this def to the vector
  3155. defsToUnpack.push_back(nxt->name);
  3156. CGI->objh->objInstances[j]->defInfo = nxt;
  3157. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3158. {
  3159. creGenNumbers[nxt->subid][lvl] = nxt;
  3160. }
  3161. }
  3162. else //if not as castle
  3163. {
  3164. CGDefInfo * nxt = curDef;
  3165. nxt->id = 17;
  3166. std::vector<int> possibleTowns;
  3167. for(int bb=0; bb<8; ++bb)
  3168. {
  3169. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
  3170. {
  3171. possibleTowns.push_back(bb);
  3172. }
  3173. }
  3174. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
  3175. possibleTowns.push_back(8);
  3176. nxt->subid = possibleTowns[rand()%possibleTowns.size()];
  3177. int lvl = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str())-1;
  3178. nxt->name = creGenNames[nxt->subid][lvl];
  3179. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3180. {
  3181. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3182. continue;
  3183. }
  3184. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3185. nxt->name);
  3186. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3187. {
  3188. nxt->isOnDefList = false;
  3189. }
  3190. else
  3191. {
  3192. nxt->printPriority = pit->priority;
  3193. nxt->isOnDefList = true;
  3194. }
  3195. map.defy.push_back(nxt); // add this def to the vector
  3196. defsToUnpack.push_back(nxt->name);
  3197. CGI->objh->objInstances[j]->defInfo = nxt;
  3198. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3199. {
  3200. creGenNumbers[nxt->subid][lvl] = nxt;
  3201. }
  3202. }
  3203. break;
  3204. }
  3205. case EDefType::CREGEN2_DEF:
  3206. {
  3207. if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
  3208. {
  3209. CGDefInfo * nxt = curDef;
  3210. nxt->id = 17;
  3211. for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
  3212. {
  3213. if(getDefType(CGI->objh->objInstances[vv]->defInfo)==EDefType::TOWN_DEF)
  3214. {
  3215. if(
  3216. ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
  3217. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
  3218. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
  3219. && ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
  3220. {
  3221. for(int mm=0; mm<town1DefNames.size(); ++mm)
  3222. {
  3223. std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
  3224. std::string hlp = CGI->objh->objInstances[vv]->defInfo->name;
  3225. std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
  3226. if(town1DefNames[mm]==hlp)
  3227. {
  3228. nxt->subid = mm;
  3229. }
  3230. }
  3231. }
  3232. }
  3233. }
  3234. int lvl;
  3235. if((((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel)!=0)
  3236. lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
  3237. else lvl = 0;
  3238. nxt->name = creGenNames[nxt->subid][lvl];
  3239. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3240. {
  3241. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3242. continue;
  3243. }
  3244. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3245. nxt->name);
  3246. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3247. {
  3248. nxt->isOnDefList = false;
  3249. }
  3250. else
  3251. {
  3252. nxt->printPriority = pit->priority;
  3253. nxt->isOnDefList = true;
  3254. }
  3255. map.defy.push_back(nxt); // add this def to the vector
  3256. defsToUnpack.push_back(nxt->name);
  3257. CGI->objh->objInstances[j]->defInfo = nxt;
  3258. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3259. {
  3260. creGenNumbers[nxt->subid][lvl] = nxt;
  3261. }
  3262. }
  3263. else //if not as castle
  3264. {
  3265. CGDefInfo * nxt = curDef;
  3266. nxt->id = 17;
  3267. std::vector<int> possibleTowns;
  3268. for(int bb=0; bb<8; ++bb)
  3269. {
  3270. if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
  3271. {
  3272. possibleTowns.push_back(bb);
  3273. }
  3274. }
  3275. if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
  3276. possibleTowns.push_back(8);
  3277. nxt->subid = possibleTowns[rand()%possibleTowns.size()];
  3278. int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
  3279. nxt->name = creGenNames[nxt->subid][lvl];
  3280. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3281. {
  3282. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3283. continue;
  3284. }
  3285. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3286. nxt->name);
  3287. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3288. {
  3289. nxt->isOnDefList = false;
  3290. }
  3291. else
  3292. {
  3293. nxt->printPriority = pit->priority;
  3294. nxt->isOnDefList = true;
  3295. }
  3296. map.defy.push_back(nxt); // add this def to the vector
  3297. defsToUnpack.push_back(nxt->name);
  3298. CGI->objh->objInstances[j]->defInfo = nxt;
  3299. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3300. {
  3301. creGenNumbers[nxt->subid][lvl] = nxt;
  3302. }
  3303. }
  3304. }
  3305. case EDefType::CREGEN3_DEF:
  3306. {
  3307. CGDefInfo * nxt = curDef;
  3308. nxt->id = 17;
  3309. nxt->subid = atoi(CGI->objh->objInstances[j]->defInfo->name.substr(7, 8).c_str());
  3310. int lvl = -1;
  3311. CCreGen3ObjInfo * ct = (CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info;
  3312. if(ct->maxLevel>7)
  3313. ct->maxLevel = 7;
  3314. if(ct->minLevel<1)
  3315. ct->minLevel = 1;
  3316. if((((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel)!=0)
  3317. lvl = rand()%(((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
  3318. else
  3319. lvl = ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel;
  3320. nxt->name = creGenNames[nxt->subid][lvl];
  3321. if(creGenNumbers[nxt->subid][lvl]!=NULL)
  3322. {
  3323. CGI->objh->objInstances[j]->defInfo = creGenNumbers[nxt->subid][lvl];
  3324. continue;
  3325. }
  3326. std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
  3327. nxt->name);
  3328. if(pit == CGameInfo::mainObj->dobjinfo->objs.end())
  3329. {
  3330. nxt->isOnDefList = false;
  3331. }
  3332. else
  3333. {
  3334. nxt->printPriority = pit->priority;
  3335. nxt->isOnDefList = true;
  3336. }
  3337. map.defy.push_back(nxt); // add this def to the vector
  3338. defsToUnpack.push_back(nxt->name);
  3339. CGI->objh->objInstances[j]->defInfo = nxt;
  3340. if(creGenNumbers[nxt->subid][lvl]==NULL)
  3341. {
  3342. creGenNumbers[nxt->subid][lvl] = nxt;
  3343. }
  3344. break;
  3345. }
  3346. }//end of main switch
  3347. } //end of sencond for loop
  3348. }