CAmbarCendamo.cpp 97 KB

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