CAmbarCendamo.cpp 96 KB

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