mapHandler.cpp 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. #include "stdafx.h"
  2. #include "mapHandler.h"
  3. #include "hch\CSemiDefHandler.h"
  4. #include "SDL_rotozoom.h"
  5. #include "SDL_Extensions.h"
  6. #include "CGameInfo.h"
  7. #include "stdlib.h"
  8. #include "hch\CLodHandler.h"
  9. #include "hch\CDefObjInfoHandler.h"
  10. #include <algorithm>
  11. #include "CGameState.h"
  12. #include "CLua.h"
  13. #include "hch\CCastleHandler.h"
  14. #include "hch\CHeroHandler.h"
  15. #include "hch\CTownHandler.h"
  16. #include <iomanip>
  17. #include <sstream>
  18. extern SDL_Surface * ekran;
  19. class OCM_HLP
  20. {
  21. public:
  22. bool operator ()(const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & a, const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & b)
  23. {
  24. return (*a.first)<(*b.first);
  25. }
  26. } ocmptwo ;
  27. void alphaTransformDef(CGDefInfo * defInfo)
  28. {
  29. SDL_Surface * alphaTransSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 12, 12, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
  30. for(int yy=0;yy<defInfo->handler->ourImages.size();yy++)
  31. {
  32. defInfo->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap);
  33. SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(defInfo->handler->ourImages[yy].bitmap, alphaTransSurf);
  34. SDL_FreeSurface(defInfo->handler->ourImages[yy].bitmap);
  35. defInfo->handler->ourImages[yy].bitmap = bufs;
  36. defInfo->handler->alphaTransformed = true;
  37. }
  38. SDL_FreeSurface(alphaTransSurf);
  39. }
  40. std::pair<int,int> CMapHandler::pickObject(CGObjectInstance *obj)
  41. {
  42. switch(obj->ID)
  43. {
  44. case 65: //random artifact
  45. return std::pair<int,int>(5,(rand()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki
  46. case 66: //random treasure artifact
  47. return std::pair<int,int>(5,CGI->arth->treasures[rand()%CGI->arth->treasures.size()]->id);
  48. case 67: //random minor artifact
  49. return std::pair<int,int>(5,CGI->arth->minors[rand()%CGI->arth->minors.size()]->id);
  50. case 68: //random major artifact
  51. return std::pair<int,int>(5,CGI->arth->majors[rand()%CGI->arth->majors.size()]->id);
  52. case 69: //random relic artifact
  53. return std::pair<int,int>(5,CGI->arth->relics[rand()%CGI->arth->relics.size()]->id);
  54. case 70: //random hero
  55. return std::pair<int,int>(34,rand()%CGI->heroh->heroes.size());
  56. case 71: //random monster
  57. return std::pair<int,int>(54,rand()%(CGI->creh->creatures.size()));
  58. case 72: //random monster lvl1
  59. return std::pair<int,int>(54,CGI->creh->levelCreatures[1][rand()%CGI->creh->levelCreatures[1].size()]->idNumber);
  60. case 73: //random monster lvl2
  61. return std::pair<int,int>(54,CGI->creh->levelCreatures[2][rand()%CGI->creh->levelCreatures[2].size()]->idNumber);
  62. case 74: //random monster lvl3
  63. return std::pair<int,int>(54,CGI->creh->levelCreatures[3][rand()%CGI->creh->levelCreatures[3].size()]->idNumber);
  64. case 75: //random monster lvl4
  65. return std::pair<int,int>(54,CGI->creh->levelCreatures[4][rand()%CGI->creh->levelCreatures[4].size()]->idNumber);
  66. case 76: //random resource
  67. return std::pair<int,int>(79,rand()%7); //now it's OH3 style, use %8 for mithril
  68. case 77: //random town
  69. return std::pair<int,int>(98,rand()%CGI->townh->towns.size());
  70. case 162: //random monster lvl5
  71. return std::pair<int,int>(54,CGI->creh->levelCreatures[5][rand()%CGI->creh->levelCreatures[5].size()]->idNumber);
  72. case 163: //random monster lvl6
  73. return std::pair<int,int>(54,CGI->creh->levelCreatures[6][rand()%CGI->creh->levelCreatures[6].size()]->idNumber);
  74. case 164: //random monster lvl7
  75. return std::pair<int,int>(54,CGI->creh->levelCreatures[7][rand()%CGI->creh->levelCreatures[7].size()]->idNumber);
  76. case 216: //random dwelling
  77. {
  78. int faction = rand()%F_NUMBER;
  79. CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info;
  80. if (info->asCastle)
  81. {
  82. for(int i=0;i<CGI->objh->objInstances.size();i++)
  83. {
  84. if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
  85. {
  86. randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first
  87. faction = CGI->objh->objInstances[i]->subID;
  88. break;
  89. }
  90. else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
  91. {
  92. faction = CGI->objh->objInstances[i]->subID;
  93. break;
  94. }
  95. }
  96. }
  97. else
  98. {
  99. while((!(info->castles[0]&(1<<faction))))
  100. {
  101. if((faction>7) && (info->castles[1]&(1<<(faction-8))))
  102. break;
  103. faction = rand()%F_NUMBER;
  104. }
  105. }
  106. int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
  107. int cid = CGI->townh->towns[faction].basicCreatures[level];
  108. for(int i=0;i<CGI->objh->cregens.size();i++)
  109. if(CGI->objh->cregens[i]==cid)
  110. return std::pair<int,int>(17,i);
  111. std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
  112. return std::pair<int,int>(17,0);
  113. }
  114. case 217:
  115. {
  116. int faction = rand()%F_NUMBER;
  117. CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info;
  118. if (info->asCastle)
  119. {
  120. for(int i=0;i<CGI->objh->objInstances.size();i++)
  121. {
  122. if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
  123. {
  124. randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first
  125. faction = CGI->objh->objInstances[i]->subID;
  126. break;
  127. }
  128. else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
  129. {
  130. faction = CGI->objh->objInstances[i]->subID;
  131. break;
  132. }
  133. }
  134. }
  135. else
  136. {
  137. while((!(info->castles[0]&(1<<faction))))
  138. {
  139. if((faction>7) && (info->castles[1]&(1<<(faction-8))))
  140. break;
  141. faction = rand()%F_NUMBER;
  142. }
  143. }
  144. int cid = CGI->townh->towns[faction].basicCreatures[obj->subID];
  145. for(int i=0;i<CGI->objh->cregens.size();i++)
  146. if(CGI->objh->cregens[i]==cid)
  147. return std::pair<int,int>(17,i);
  148. std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
  149. return std::pair<int,int>(17,0);
  150. }
  151. case 218:
  152. {
  153. CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info;
  154. int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
  155. int cid = CGI->townh->towns[obj->subID].basicCreatures[level];
  156. for(int i=0;i<CGI->objh->cregens.size();i++)
  157. if(CGI->objh->cregens[i]==cid)
  158. return std::pair<int,int>(17,i);
  159. std::cout << "Cannot find a dwelling for creature "<<cid <<std::endl;
  160. return std::pair<int,int>(17,0);
  161. }
  162. }
  163. return std::pair<int,int>(-1,-1);
  164. }
  165. void CMapHandler::randomizeObject(CGObjectInstance *cur)
  166. {
  167. std::pair<int,int> ran = pickObject(cur);
  168. if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything
  169. return;
  170. else if(ran.first==34)//special code for hero
  171. {
  172. CGHeroInstance *h = dynamic_cast<CGHeroInstance *>(cur);
  173. if(!h) {std::cout<<"Wrong random hero at "<<cur->pos<<std::endl; return;}
  174. cur->ID = ran.first;
  175. cur->subID = ran.second;
  176. h->type = CGI->heroh->heroes[ran.second];
  177. CGI->heroh->heroInstances.push_back(h);
  178. CGI->objh->objInstances.erase(std::find(CGI->objh->objInstances.begin(),CGI->objh->objInstances.end(),h));
  179. return; //TODO: maybe we should do something with definfo?
  180. }
  181. else if(ran.first==98)//special code for town
  182. {
  183. CGTownInstance *t = dynamic_cast<CGTownInstance*>(cur);
  184. if(!t) {std::cout<<"Wrong random town at "<<cur->pos<<std::endl; return;}
  185. cur->ID = ran.first;
  186. cur->subID = ran.second;
  187. t->town = &CGI->townh->towns[ran.second];
  188. if(t->hasCapitol())
  189. t->defInfo = capitols[t->subID];
  190. else if(t->hasFort())
  191. t->defInfo = CGI->dobjinfo->castles[t->subID];
  192. else
  193. t->defInfo = villages[t->subID];
  194. if(!t->defInfo->handler)
  195. {
  196. t->defInfo->handler = CGI->spriteh->giveDef(t->defInfo->name);
  197. alphaTransformDef(t->defInfo);
  198. }
  199. //CGI->townh->townInstances.push_back(t);
  200. return;
  201. }
  202. //we have to replace normal random object
  203. cur->ID = ran.first;
  204. cur->subID = ran.second;
  205. cur->defInfo = CGI->dobjinfo->gobjs[ran.first][ran.second];
  206. if(!cur->defInfo){std::cout<<"Missing def declaration for "<<cur->ID<<" "<<cur->subID<<std::endl;return;}
  207. if(!cur->defInfo->handler) //if we have to load def
  208. {
  209. cur->defInfo->handler = CGI->spriteh->giveDef(cur->defInfo->name);
  210. alphaTransformDef(cur->defInfo);
  211. }
  212. }
  213. void CMapHandler::randomizeObjects()
  214. {
  215. CGObjectInstance * cur;
  216. for(int no=0; no<CGI->objh->objInstances.size(); ++no)
  217. {
  218. randomizeObject(CGI->objh->objInstances[no]);
  219. if(CGI->objh->objInstances[no]->ID==26)
  220. CGI->objh->objInstances[no]->defInfo->handler=NULL;
  221. }
  222. }
  223. void CMapHandler::prepareFOWDefs()
  224. {
  225. fullHide = CGameInfo::mainObj->spriteh->giveDef("TSHRC.DEF");
  226. partialHide = CGameInfo::mainObj->spriteh->giveDef("TSHRE.DEF");
  227. //adding necessary rotations
  228. Cimage nw = partialHide->ourImages[22]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  229. partialHide->ourImages.push_back(nw);
  230. nw = partialHide->ourImages[15]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  231. partialHide->ourImages.push_back(nw);
  232. nw = partialHide->ourImages[2]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  233. partialHide->ourImages.push_back(nw);
  234. nw = partialHide->ourImages[13]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  235. partialHide->ourImages.push_back(nw);
  236. nw = partialHide->ourImages[12]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  237. partialHide->ourImages.push_back(nw);
  238. nw = partialHide->ourImages[16]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  239. partialHide->ourImages.push_back(nw);
  240. nw = partialHide->ourImages[18]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  241. partialHide->ourImages.push_back(nw);
  242. nw = partialHide->ourImages[17]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  243. partialHide->ourImages.push_back(nw);
  244. nw = partialHide->ourImages[20]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  245. partialHide->ourImages.push_back(nw);
  246. nw = partialHide->ourImages[19]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  247. partialHide->ourImages.push_back(nw);
  248. nw = partialHide->ourImages[7]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  249. partialHide->ourImages.push_back(nw);
  250. nw = partialHide->ourImages[24]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  251. partialHide->ourImages.push_back(nw);
  252. nw = partialHide->ourImages[26]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  253. partialHide->ourImages.push_back(nw);
  254. nw = partialHide->ourImages[25]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  255. partialHide->ourImages.push_back(nw);
  256. nw = partialHide->ourImages[30]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  257. partialHide->ourImages.push_back(nw);
  258. nw = partialHide->ourImages[32]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  259. partialHide->ourImages.push_back(nw);
  260. nw = partialHide->ourImages[27]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  261. partialHide->ourImages.push_back(nw);
  262. nw = partialHide->ourImages[28]; nw.bitmap = CSDL_Ext::rotate01(nw.bitmap);
  263. partialHide->ourImages.push_back(nw);
  264. //necessaary rotations added
  265. for(int i=0; i<partialHide->ourImages.size(); ++i)
  266. {
  267. CSDL_Ext::fullAlphaTransform(partialHide->ourImages[i].bitmap);
  268. }
  269. //visibility.resize(reader->map.width+2*Woff);
  270. //for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
  271. //{
  272. // visibility[gg].resize(reader->map.height+2*Hoff);
  273. // for(int jj=0; jj<reader->map.height+2*Hoff; ++jj)
  274. // visibility[gg][jj] = true;
  275. //}
  276. visibility.resize(CGI->ac->map.width, Woff);
  277. for (int i=0-Woff;i<visibility.size()-Woff;i++)
  278. {
  279. visibility[i].resize(CGI->ac->map.height,Hoff);
  280. }
  281. for (int i=0-Woff; i<visibility.size()-Woff; ++i)
  282. {
  283. for (int j=0-Hoff; j<CGI->ac->map.height+Hoff; ++j)
  284. {
  285. visibility[i][j].resize(CGI->ac->map.twoLevel+1,0);
  286. for(int k=0; k<CGI->ac->map.twoLevel+1; ++k)
  287. visibility[i][j][k]=true;
  288. }
  289. }
  290. hideBitmap.resize(CGI->ac->map.width, Woff);
  291. for (int i=0-Woff;i<visibility.size()-Woff;i++)
  292. {
  293. hideBitmap[i].resize(CGI->ac->map.height,Hoff);
  294. }
  295. for (int i=0-Woff; i<hideBitmap.size()-Woff; ++i)
  296. {
  297. for (int j=0-Hoff; j<CGI->ac->map.height+Hoff; ++j)
  298. {
  299. hideBitmap[i][j].resize(CGI->ac->map.twoLevel+1,0);
  300. for(int k=0; k<CGI->ac->map.twoLevel+1; ++k)
  301. hideBitmap[i][j][k] = rand()%fullHide->ourImages.size();
  302. }
  303. }
  304. //visibility[6][7][1] = false;
  305. //visibility[7][7][1] = false;
  306. //visibility[6][8][1] = false;
  307. //visibility[6][6][1] = false;
  308. //visibility[5][8][1] = false;
  309. //visibility[7][6][1] = false;
  310. //visibility[6][9][1] = false;
  311. }
  312. void CMapHandler::roadsRiverTerrainInit()
  313. {
  314. //initializing road's and river's DefHandlers
  315. roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("dirtrd.def"));
  316. roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("gravrd.def"));
  317. roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("cobbrd.def"));
  318. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("clrrvr.def"));
  319. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("icyrvr.def"));
  320. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("mudrvr.def"));
  321. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("lavrvr.def"));
  322. //roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff];
  323. //for (int ii=0;ii<reader->map.width+2*Woff;ii++)
  324. // roadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
  325. sizes.x = CGI->ac->map.width;
  326. sizes.y = CGI->ac->map.height;
  327. sizes.z = CGI->ac->map.twoLevel+1;
  328. ttiles.resize(CGI->ac->map.width,Woff);
  329. for (int i=0-Woff;i<ttiles.size()-Woff;i++)
  330. {
  331. ttiles[i].resize(CGI->ac->map.height,Hoff);
  332. }
  333. for (int i=0-Woff;i<ttiles.size()-Woff;i++)
  334. {
  335. for (int j=0-Hoff;j<CGI->ac->map.height+Hoff;j++)
  336. ttiles[i][j].resize(CGI->ac->map.twoLevel+1,0);
  337. }
  338. for (int i=0; i<reader->map.width; i++) //jest po szerokoœci
  339. {
  340. for (int j=0; j<reader->map.height;j++) //po wysokoœci
  341. {
  342. for (int k=0; k<=reader->map.twoLevel; ++k)
  343. {
  344. TerrainTile** pomm = reader->map.terrain; ;
  345. if (k==0)
  346. pomm = reader->map.terrain;
  347. else
  348. pomm = reader->map.undergroungTerrain;
  349. if(pomm[i][j].malle)
  350. {
  351. int cDir;
  352. bool rotV, rotH;
  353. if(k==0)
  354. {
  355. int roadpom = reader->map.terrain[i][j].malle-1,
  356. impom = reader->map.terrain[i][j].roadDir;
  357. SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap;
  358. ttiles[i][j][k].roadbitmap.push_back(pom1);
  359. cDir = reader->map.terrain[i][j].roadDir;
  360. rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
  361. rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
  362. }
  363. else
  364. {
  365. int pom111 = reader->map.undergroungTerrain[i][j].malle-1,
  366. pom777 = reader->map.undergroungTerrain[i][j].roadDir;
  367. SDL_Surface *pom1 = roadDefs[pom111]->ourImages[pom777].bitmap;
  368. ttiles[i][j][k].roadbitmap.push_back(pom1);
  369. cDir = reader->map.undergroungTerrain[i][j].roadDir;
  370. rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
  371. rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
  372. }
  373. if(rotH)
  374. {
  375. ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].roadbitmap[0]);
  376. }
  377. if(rotV)
  378. {
  379. ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].roadbitmap[0]);
  380. }
  381. if(rotH || rotV)
  382. {
  383. ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].roadbitmap[0]);
  384. SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].roadbitmap[0], CSDL_Ext::std32bppSurface);
  385. SDL_FreeSurface(ttiles[i][j][k].roadbitmap[0]);
  386. ttiles[i][j][k].roadbitmap[0] = buf;
  387. }
  388. }
  389. }
  390. }
  391. }
  392. //initializing simple values
  393. for (int i=0; i<CGI->ac->map.width; i++) //jest po szerokoœci
  394. {
  395. for (int j=0; j<CGI->ac->map.height;j++) //po wysokoœci
  396. {
  397. for(int k=0; k<ttiles[0][0].size(); ++k)
  398. {
  399. ttiles[i][j][k].pos = int3(i, j, k);
  400. ttiles[i][j][k].blocked = false;
  401. ttiles[i][j][k].visitable = false;
  402. if(i<0 || j<0 || i>=CGI->ac->map.width || j>=CGI->ac->map.height)
  403. {
  404. ttiles[i][j][k].blocked = true;
  405. continue;
  406. }
  407. ttiles[i][j][k].terType = (k==0 ? CGI->ac->map.terrain[i][j].tertype : CGI->ac->map.undergroungTerrain[i][j].tertype);
  408. ttiles[i][j][k].malle = (k==0 ? CGI->ac->map.terrain[i][j].malle : CGI->ac->map.undergroungTerrain[i][j].malle);
  409. ttiles[i][j][k].nuine = (k==0 ? CGI->ac->map.terrain[i][j].nuine : CGI->ac->map.undergroungTerrain[i][j].nuine);
  410. ttiles[i][j][k].rivdir = (k==0 ? CGI->ac->map.terrain[i][j].rivDir : CGI->ac->map.undergroungTerrain[i][j].rivDir);
  411. ttiles[i][j][k].roaddir = (k==0 ? CGI->ac->map.terrain[i][j].roadDir : CGI->ac->map.undergroungTerrain[i][j].roadDir);
  412. }
  413. }
  414. }
  415. //simple values initialized
  416. for (int i=0; i<reader->map.width; i++) //jest po szerokoœci
  417. {
  418. for (int j=0; j<reader->map.height;j++) //po wysokoœci
  419. {
  420. for(int k=0; k<=reader->map.twoLevel; ++k)
  421. {
  422. TerrainTile** pomm = reader->map.terrain;
  423. if(k==0)
  424. {
  425. pomm = reader->map.terrain;
  426. }
  427. else
  428. {
  429. pomm = reader->map.undergroungTerrain;
  430. }
  431. if(pomm[i][j].nuine)
  432. {
  433. int cDir;
  434. bool rotH, rotV;
  435. if(k==0)
  436. {
  437. ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.terrain[i][j].nuine-1]->ourImages[reader->map.terrain[i][j].rivDir].bitmap);
  438. cDir = reader->map.terrain[i][j].rivDir;
  439. rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
  440. rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
  441. }
  442. else
  443. {
  444. ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.undergroungTerrain[i][j].nuine-1]->ourImages[reader->map.undergroungTerrain[i][j].rivDir].bitmap);
  445. cDir = reader->map.undergroungTerrain[i][j].rivDir;
  446. rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
  447. rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
  448. }
  449. if(rotH)
  450. {
  451. ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].rivbitmap[0]);
  452. }
  453. if(rotV)
  454. {
  455. ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].rivbitmap[0]);
  456. }
  457. if(rotH || rotV)
  458. {
  459. ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].rivbitmap[0]);
  460. SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].rivbitmap[0], CSDL_Ext::std32bppSurface);
  461. SDL_FreeSurface(ttiles[i][j][k].rivbitmap[0]);
  462. ttiles[i][j][k].rivbitmap[0] = buf;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. void CMapHandler::borderAndTerrainBitmapInit()
  470. {
  471. //terrainBitmap = new SDL_Surface **[reader->map.width+2*Woff];
  472. //for (int ii=0;ii<reader->map.width+2*Woff;ii++)
  473. // terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
  474. CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF");
  475. for (int i=0-Woff; i<reader->map.width+Woff; i++) //jest po szerokoœci
  476. {
  477. for (int j=0-Hoff; j<reader->map.height+Hoff;j++) //po wysokoœci
  478. {
  479. for(int k=0; k<=reader->map.twoLevel; ++k)
  480. {
  481. if(i < 0 || i > (reader->map.width-1) || j < 0 || j > (reader->map.height-1))
  482. {
  483. if(i==-1 && j==-1)
  484. {
  485. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[16].bitmap);
  486. continue;
  487. }
  488. else if(i==-1 && j==(reader->map.height))
  489. {
  490. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[19].bitmap);
  491. continue;
  492. }
  493. else if(i==(reader->map.width) && j==-1)
  494. {
  495. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[17].bitmap);
  496. continue;
  497. }
  498. else if(i==(reader->map.width) && j==(reader->map.height))
  499. {
  500. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[18].bitmap);
  501. continue;
  502. }
  503. else if(j == -1 && i > -1 && i < reader->map.height)
  504. {
  505. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[22+rand()%2].bitmap);
  506. continue;
  507. }
  508. else if(i == -1 && j > -1 && j < reader->map.height)
  509. {
  510. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[33+rand()%2].bitmap);
  511. continue;
  512. }
  513. else if(j == reader->map.height && i >-1 && i < reader->map.width)
  514. {
  515. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[29+rand()%2].bitmap);
  516. continue;
  517. }
  518. else if(i == reader->map.width && j > -1 && j < reader->map.height)
  519. {
  520. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[25+rand()%2].bitmap);
  521. continue;
  522. }
  523. else
  524. {
  525. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[rand()%16].bitmap);
  526. continue;
  527. }
  528. }
  529. //TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
  530. std::string name;
  531. if (k>0)
  532. name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i][j].tertype);
  533. else
  534. name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
  535. for (unsigned int m=0; m<reader->defs.size(); m++)
  536. {
  537. try
  538. {
  539. if (reader->defs[m]->defName != name)
  540. continue;
  541. else
  542. {
  543. int ktora;
  544. if (k==0)
  545. ktora = reader->map.terrain[i][j].terview;
  546. else
  547. ktora = reader->map.undergroungTerrain[i][j].terview;
  548. ttiles[i][j][k].terbitmap.push_back(reader->defs[m]->ourImages[ktora].bitmap);
  549. int zz;
  550. if (k==0)
  551. zz = (reader->map.terrain[i][j].siodmyTajemniczyBajt)%4;
  552. else
  553. zz = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt)%4;
  554. switch (zz)
  555. {
  556. case 1:
  557. {
  558. ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].terbitmap[0]);
  559. break;
  560. }
  561. case 2:
  562. {
  563. ttiles[i][j][k].terbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].terbitmap[0]);
  564. break;
  565. }
  566. case 3:
  567. {
  568. ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate03(ttiles[i][j][k].terbitmap[0]);
  569. break;
  570. }
  571. }
  572. break;
  573. }
  574. }
  575. catch (...)
  576. {
  577. continue;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. }
  584. void CMapHandler::initObjectRects()
  585. {
  586. //initializing objects / rects
  587. for(int f=0; f<CGI->objh->objInstances.size(); ++f)
  588. {
  589. /*CGI->objh->objInstances[f]->pos.x+=1;
  590. CGI->objh->objInstances[f]->pos.y+=1;*/
  591. if(!CGI->objh->objInstances[f]->defInfo)
  592. {
  593. continue;
  594. }
  595. CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler;
  596. if(curd)
  597. {
  598. for(int fx=0; fx<curd->ourImages[0].bitmap->w>>5; ++fx) //curd->ourImages[0].bitmap->w/32
  599. {
  600. for(int fy=0; fy<curd->ourImages[0].bitmap->h>>5; ++fy) //curd->ourImages[0].bitmap->h/32
  601. {
  602. SDL_Rect cr;
  603. cr.w = 32;
  604. cr.h = 32;
  605. cr.x = fx<<5; //fx*32
  606. cr.y = fy<<5; //fy*32
  607. std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector<std::list<int3>>()));
  608. ///initializing places that will be coloured by blitting (flag colour / player colour positions)
  609. if(toAdd.first->defInfo->isVisitable())
  610. {
  611. SDL_Rect cr;
  612. cr.w = 32;
  613. cr.h = 32;
  614. cr.x = fx*32;
  615. cr.y = fy*32;
  616. std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3> > > > toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector<std::list<int3>>()));
  617. ///initializing places that will be coloured by blitting (flag colour / player colour positions)
  618. if(toAdd.first->defInfo->isVisitable() && toAdd.first->defInfo->handler->ourImages[0].bitmap->format->BitsPerPixel!=8)
  619. {
  620. toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
  621. for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)
  622. {
  623. bool breakNow = true;
  624. for(int dx=0; dx<32; ++dx)
  625. {
  626. for(int dy=0; dy<32; ++dy)
  627. {
  628. SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap;
  629. Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx));
  630. Uint8 r, g, b, a;
  631. SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a);
  632. if(r==255 && g==255 && b==0)
  633. {
  634. toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0));
  635. breakNow = false;
  636. }
  637. }
  638. }
  639. if(breakNow)
  640. break;
  641. }
  642. }
  643. }
  644. if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
  645. {
  646. //TerrainTile2 & curt =
  647. // ttiles
  648. // [CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32]
  649. //[CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32]
  650. //[CGI->objh->objInstances[f]->pos.z];
  651. ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd);
  652. }
  653. } // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
  654. } //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
  655. }//if curd
  656. } // for(int f=0; f<CGI->objh->objInstances.size(); ++f)
  657. for(int ix=0; ix<ttiles.size()-Woff; ++ix)
  658. {
  659. for(int iy=0; iy<ttiles[0].size()-Hoff; ++iy)
  660. {
  661. for(int iz=0; iz<ttiles[0][0].size(); ++iz)
  662. {
  663. stable_sort(ttiles[ix][iy][iz].objects.begin(), ttiles[ix][iy][iz].objects.end(), ocmptwo);
  664. }
  665. }
  666. }
  667. }
  668. void CMapHandler::calculateBlockedPos()
  669. {
  670. for(int f=0; f<CGI->objh->objInstances.size(); ++f) //calculationg blocked / visitable positions
  671. {
  672. if(!CGI->objh->objInstances[f]->defInfo)
  673. continue;
  674. CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler;
  675. for(int fx=0; fx<8; ++fx)
  676. {
  677. for(int fy=0; fy<6; ++fy)
  678. {
  679. int xVal = CGI->objh->objInstances[f]->pos.x + fx - 7;
  680. int yVal = CGI->objh->objInstances[f]->pos.y + fy - 5;
  681. int zVal = CGI->objh->objInstances[f]->pos.z;
  682. if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
  683. {
  684. TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
  685. if(((CGI->objh->objInstances[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1))
  686. curt.visitable = true;
  687. if(!((CGI->objh->objInstances[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1))
  688. curt.blocked = true;
  689. }
  690. }
  691. }
  692. }
  693. }
  694. void CMapHandler::init()
  695. {
  696. std::ifstream ifs("config/townsDefs.txt");
  697. int ccc;
  698. ifs>>ccc;
  699. for(int i=0;i<ccc*2;i++)
  700. {
  701. CGDefInfo * n = new CGDefInfo(*CGI->dobjinfo->castles[i%ccc]);
  702. ifs >> n->name;
  703. if (!(n->handler = CGI->spriteh->giveDef(n->name)))
  704. std::cout << "Cannot open "<<n->name<<std::endl;
  705. if(i<ccc)
  706. villages[i]=n;
  707. else
  708. capitols[i%ccc]=n;
  709. alphaTransformDef(n);
  710. }
  711. timeHandler th;
  712. th.getDif();
  713. randomizeObjects();//randomizing objects on map
  714. std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
  715. for(int h=0; h<reader->map.defy.size(); ++h) //initializing loaded def handler's info
  716. {
  717. //std::string hlp = reader->map.defy[h]->name;
  718. //std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
  719. CGI->mh->loadedDefs.insert(std::make_pair(reader->map.defy[h]->name, reader->map.defy[h]->handler));
  720. }
  721. std::cout<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
  722. prepareFOWDefs();
  723. roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
  724. borderAndTerrainBitmapInit();
  725. std::cout<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
  726. for(int i=0;i<PLAYER_LIMIT;i++)
  727. {
  728. if(reader->map.players[i].generateHeroAtMainTown && reader->map.players[i].hasMainTown)
  729. {
  730. int3 hpos = reader->map.players[i].posOfMainTown;
  731. hpos.x+=1; hpos.y+=1;
  732. int j;
  733. for(j=0;j<CGI->scenarioOps.playerInfos.size();j++)
  734. if(CGI->scenarioOps.playerInfos[j].color==i)
  735. break;
  736. if(j==CGI->scenarioOps.playerInfos.size())
  737. continue;
  738. CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,CGI->scenarioOps.playerInfos[j].hero,hpos,i);
  739. nnn->defInfo->handler = CGI->heroh->flags1[0];
  740. CGI->heroh->heroInstances.push_back(nnn);
  741. CGI->objh->objInstances.push_back(nnn);
  742. }
  743. }
  744. initObjectRects();
  745. std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
  746. calculateBlockedPos();
  747. std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl;
  748. }
  749. SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim)
  750. {
  751. if(!otherHeroAnim)
  752. heroAnim = anim; //the same, as it should be
  753. SDL_Surface * su = CSDL_Ext::newSurface(dx*32, dy*32, CSDL_Ext::std32bppSurface);
  754. if (((dx+x)>((reader->map.width+Woff)) || (dy+y)>((reader->map.height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) )
  755. throw new std::string("terrainRect: out of range");
  756. ////printing terrain
  757. for (int bx=0; bx<dx; bx++)
  758. {
  759. for (int by=0; by<dy; by++)
  760. {
  761. SDL_Rect sr;
  762. sr.y=by*32;
  763. sr.x=bx*32;
  764. sr.h=sr.w=32;
  765. SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,&sr);
  766. }
  767. }
  768. ////terrain printed
  769. ////printing rivers
  770. for (int bx=0; bx<dx; bx++)
  771. {
  772. for (int by=0; by<dy; by++)
  773. {
  774. SDL_Rect sr;
  775. sr.y=by*32;
  776. sr.x=bx*32;
  777. sr.h=sr.w=32;
  778. if(ttiles[x+bx][y+by][level].rivbitmap.size())
  779. SDL_BlitSurface(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,&sr);
  780. }
  781. }
  782. ////rivers printed
  783. ////printing roads
  784. for (int bx=0; bx<dx; bx++)
  785. {
  786. for (int by=-1; by<dy; by++)
  787. {
  788. if(y+by<=-4)
  789. continue;
  790. SDL_Rect sr;
  791. sr.y=by*32+16;
  792. sr.x=bx*32;
  793. sr.h=sr.w=32;
  794. if(ttiles[x+bx][y+by][level].roadbitmap.size())
  795. SDL_BlitSurface(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()],NULL,su,&sr);
  796. }
  797. }
  798. ////roads printed
  799. ////printing objects
  800. for (int bx=0; bx<dx; bx++)
  801. {
  802. for (int by=0; by<dy; by++)
  803. {
  804. for(int h=0; h<ttiles[x+bx][y+by][level].objects.size(); ++h)
  805. {
  806. SDL_Rect sr;
  807. sr.w = 32;
  808. sr.h = 32;
  809. sr.x = (bx)*32;
  810. sr.y = (by)*32;
  811. SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second.first;
  812. CGHeroInstance * themp = (dynamic_cast<CGHeroInstance*>(ttiles[x+bx][y+by][level].objects[h].first));
  813. if(themp && themp->moveDir && !themp->isStanding && themp->ID!=62) //last condition - this is not prison
  814. {
  815. int imgVal = 8;
  816. SDL_Surface * tb;
  817. if(themp->type==NULL)
  818. continue;
  819. std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
  820. switch(themp->moveDir)
  821. {
  822. case 1:
  823. {
  824. int gg;
  825. for(gg=0; gg<iv.size(); ++gg)
  826. {
  827. if(iv[gg].groupNumber==10)
  828. {
  829. tb = iv[gg+heroAnim%imgVal].bitmap;
  830. break;
  831. }
  832. }
  833. SDL_BlitSurface(tb,&pp,su,&sr);
  834. pp.y+=imgVal*2-32;
  835. sr.y-=16;
  836. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  837. break;
  838. }
  839. case 2:
  840. {
  841. int gg;
  842. for(gg=0; gg<iv.size(); ++gg)
  843. {
  844. if(iv[gg].groupNumber==5)
  845. {
  846. tb = iv[gg+heroAnim%imgVal].bitmap;
  847. break;
  848. }
  849. }
  850. SDL_BlitSurface(tb,&pp,su,&sr);
  851. pp.y+=imgVal*2-32;
  852. sr.y-=16;
  853. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  854. break;
  855. }
  856. case 3:
  857. {
  858. int gg;
  859. for(gg=0; gg<iv.size(); ++gg)
  860. {
  861. if(iv[gg].groupNumber==6)
  862. {
  863. tb = iv[gg+heroAnim%imgVal].bitmap;
  864. break;
  865. }
  866. }
  867. SDL_BlitSurface(tb,&pp,su,&sr);
  868. pp.y+=imgVal*2-32;
  869. sr.y-=16;
  870. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  871. break;
  872. }
  873. case 4:
  874. {
  875. int gg;
  876. for(gg=0; gg<iv.size(); ++gg)
  877. {
  878. if(iv[gg].groupNumber==7)
  879. {
  880. tb = iv[gg+heroAnim%imgVal].bitmap;
  881. break;
  882. }
  883. }
  884. SDL_BlitSurface(tb,&pp,su,&sr);
  885. pp.y+=imgVal*2-32;
  886. sr.y-=16;
  887. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  888. break;
  889. }
  890. case 5:
  891. {
  892. int gg;
  893. for(gg=0; gg<iv.size(); ++gg)
  894. {
  895. if(iv[gg].groupNumber==8)
  896. {
  897. tb = iv[gg+heroAnim%imgVal].bitmap;
  898. break;
  899. }
  900. }
  901. SDL_BlitSurface(tb,&pp,su,&sr);
  902. pp.y+=imgVal*2-32;
  903. sr.y-=16;
  904. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  905. break;
  906. }
  907. case 6: //ok
  908. {
  909. int gg;
  910. for(gg=0; gg<iv.size(); ++gg)
  911. {
  912. if(iv[gg].groupNumber==9)
  913. {
  914. tb = iv[gg+heroAnim%imgVal].bitmap;
  915. break;
  916. }
  917. }
  918. SDL_BlitSurface(tb,&pp,su,&sr);
  919. pp.y+=imgVal*2-32;
  920. sr.y-=16;
  921. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  922. break;
  923. }
  924. case 7:
  925. {
  926. int gg;
  927. for(gg=0; gg<iv.size(); ++gg)
  928. {
  929. if(iv[gg].groupNumber==12)
  930. {
  931. tb = iv[gg+heroAnim%imgVal].bitmap;
  932. break;
  933. }
  934. }
  935. SDL_BlitSurface(tb,&pp,su,&sr);
  936. pp.y+=imgVal*2-32;
  937. sr.y-=16;
  938. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  939. break;
  940. }
  941. case 8:
  942. {
  943. int gg;
  944. for(gg=0; gg<iv.size(); ++gg)
  945. {
  946. if(iv[gg].groupNumber==11)
  947. {
  948. tb = iv[gg+heroAnim%imgVal].bitmap;
  949. break;
  950. }
  951. }
  952. SDL_BlitSurface(tb,&pp,su,&sr);
  953. pp.y+=imgVal*2-32;
  954. sr.y-=16;
  955. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
  956. break;
  957. }
  958. }
  959. }
  960. else if(themp && themp->moveDir && themp->isStanding && themp->ID!=62) //last condition - this is not prison
  961. {
  962. int imgVal = 8;
  963. SDL_Surface * tb;
  964. if(themp->type==NULL)
  965. continue;
  966. std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages;
  967. switch(themp->moveDir)
  968. {
  969. case 1:
  970. {
  971. int gg;
  972. for(gg=0; gg<iv.size(); ++gg)
  973. {
  974. if(iv[gg].groupNumber==13)
  975. {
  976. tb = iv[gg].bitmap;
  977. break;
  978. }
  979. }
  980. SDL_BlitSurface(tb,&pp,su,&sr);
  981. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  982. {
  983. SDL_Rect bufr = sr;
  984. bufr.x-=2*32;
  985. bufr.y-=1*32;
  986. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[13*8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
  987. themp->flagPrinted = true;
  988. }
  989. break;
  990. }
  991. case 2:
  992. {
  993. int gg;
  994. for(gg=0; gg<iv.size(); ++gg)
  995. {
  996. if(iv[gg].groupNumber==0)
  997. {
  998. tb = iv[gg].bitmap;
  999. break;
  1000. }
  1001. }
  1002. SDL_BlitSurface(tb,&pp,su,&sr);
  1003. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  1004. {
  1005. SDL_Rect bufr = sr;
  1006. bufr.x-=2*32;
  1007. bufr.y-=1*32;
  1008. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[heroAnim%imgVal].bitmap, NULL, su, &bufr);
  1009. themp->flagPrinted = true;
  1010. }
  1011. break;
  1012. }
  1013. case 3:
  1014. {
  1015. int gg;
  1016. for(gg=0; gg<iv.size(); ++gg)
  1017. {
  1018. if(iv[gg].groupNumber==1)
  1019. {
  1020. tb = iv[gg].bitmap;
  1021. break;
  1022. }
  1023. }
  1024. SDL_BlitSurface(tb,&pp,su,&sr);
  1025. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  1026. {
  1027. SDL_Rect bufr = sr;
  1028. bufr.x-=2*32;
  1029. bufr.y-=1*32;
  1030. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
  1031. themp->flagPrinted = true;
  1032. }
  1033. break;
  1034. }
  1035. case 4:
  1036. {
  1037. int gg;
  1038. for(gg=0; gg<iv.size(); ++gg)
  1039. {
  1040. if(iv[gg].groupNumber==2)
  1041. {
  1042. tb = iv[gg].bitmap;
  1043. break;
  1044. }
  1045. }
  1046. SDL_BlitSurface(tb,&pp,su,&sr);
  1047. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  1048. {
  1049. SDL_Rect bufr = sr;
  1050. bufr.x-=2*32;
  1051. bufr.y-=1*32;
  1052. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[2*8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
  1053. themp->flagPrinted = true;
  1054. }
  1055. break;
  1056. }
  1057. case 5:
  1058. {
  1059. int gg;
  1060. for(gg=0; gg<iv.size(); ++gg)
  1061. {
  1062. if(iv[gg].groupNumber==3)
  1063. {
  1064. tb = iv[gg].bitmap;
  1065. break;
  1066. }
  1067. }
  1068. SDL_BlitSurface(tb,&pp,su,&sr);
  1069. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  1070. {
  1071. SDL_Rect bufr = sr;
  1072. bufr.x-=2*32;
  1073. bufr.y-=1*32;
  1074. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[3*8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
  1075. themp->flagPrinted = true;
  1076. }
  1077. break;
  1078. }
  1079. case 6:
  1080. {
  1081. int gg;
  1082. for(gg=0; gg<iv.size(); ++gg)
  1083. {
  1084. if(iv[gg].groupNumber==4)
  1085. {
  1086. tb = iv[gg].bitmap;
  1087. break;
  1088. }
  1089. }
  1090. SDL_BlitSurface(tb,&pp,su,&sr);
  1091. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  1092. {
  1093. SDL_Rect bufr = sr;
  1094. bufr.x-=2*32;
  1095. bufr.y-=1*32;
  1096. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[4*8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
  1097. themp->flagPrinted = true;
  1098. }
  1099. break;
  1100. }
  1101. case 7:
  1102. {
  1103. int gg;
  1104. for(gg=0; gg<iv.size(); ++gg)
  1105. {
  1106. if(iv[gg].groupNumber==15)
  1107. {
  1108. tb = iv[gg].bitmap;
  1109. break;
  1110. }
  1111. }
  1112. SDL_BlitSurface(tb,&pp,su,&sr);
  1113. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  1114. {
  1115. SDL_Rect bufr = sr;
  1116. bufr.x-=2*32;
  1117. bufr.y-=1*32;
  1118. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[15*8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
  1119. themp->flagPrinted = true;
  1120. }
  1121. break;
  1122. }
  1123. case 8:
  1124. {
  1125. int gg;
  1126. for(gg=0; gg<iv.size(); ++gg)
  1127. {
  1128. if(iv[gg].groupNumber==14)
  1129. {
  1130. tb = iv[gg].bitmap;
  1131. break;
  1132. }
  1133. }
  1134. SDL_BlitSurface(tb,&pp,su,&sr);
  1135. if(themp->pos.x==x+bx && themp->pos.y==y+by)
  1136. {
  1137. SDL_Rect bufr = sr;
  1138. bufr.x-=2*32;
  1139. bufr.y-=1*32;
  1140. SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[14*8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
  1141. themp->flagPrinted = true;
  1142. }
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. else
  1148. {
  1149. int imgVal = ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages.size();
  1150. SDL_BlitSurface(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[anim%imgVal].bitmap,&pp,su,&sr);
  1151. }
  1152. //printing appropriate flag colour
  1153. if(ttiles[x+bx][y+by][level].objects[h].second.second.size())
  1154. {
  1155. std::list<int3> & curl = ttiles[x+bx][y+by][level].objects[h].second.second[anim%ttiles[x+bx][y+by][level].objects[h].second.second.size()];
  1156. for(std::list<int3>::iterator g=curl.begin(); g!=curl.end(); ++g)
  1157. {
  1158. SDL_Color ourC;
  1159. int own = ttiles[x+bx][y+by][level].objects[h].first->getOwner();
  1160. if(ttiles[x+bx][y+by][level].objects[h].first->getOwner()!=255 && ttiles[x+bx][y+by][level].objects[h].first->getOwner()!=254)
  1161. ourC = CGI->playerColors[ttiles[x+bx][y+by][level].objects[h].first->getOwner()];
  1162. else if(ttiles[x+bx][y+by][level].objects[h].first->getOwner()==255)
  1163. ourC = CGI->neutralColor;
  1164. else continue;
  1165. CSDL_Ext::SDL_PutPixelWithoutRefresh(su, bx*32 + g->x%32 , by*32 + g->y%32, ourC.r , ourC.g, ourC.b, 0);
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }
  1171. ///enabling flags
  1172. //nie zauwazylem aby ustawianie tego cokolwiek zmienialo w wyswietlaniu, wiec komentuje (do dzialania wymaga jeszcze odkomentowania przyjazni w statcie)
  1173. /*for(std::map<int, PlayerState>::iterator k=CGI->state->players.begin(); k!=CGI->state->players.end(); ++k)
  1174. {
  1175. for (int l = 0; l<k->second.heroes.size(); l++)
  1176. k->second.heroes[l]->flagPrinted = false;
  1177. }
  1178. for(int qq=0; qq<CGI->heroh->heroInstances.size(); ++qq)
  1179. {
  1180. CGI->heroh->heroInstances[qq]->flagPrinted = false;
  1181. }*/
  1182. ///flags enabled
  1183. ////objects printed, printing shadow
  1184. for (int bx=0; bx<dx; bx++)
  1185. {
  1186. for (int by=0; by<dy; by++)
  1187. {
  1188. SDL_Rect sr;
  1189. sr.y=by*32;
  1190. sr.x=bx*32;
  1191. sr.h=sr.w=32;
  1192. if (!level)
  1193. {
  1194. //if( bx+x>-1 && by+y>-1 && bx+x<visibilityMap.size()-(-1) && by+y<visibilityMap[0].size()-(-1) && !visibilityMap[bx+x][by+y][0])
  1195. if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->reader->map.width && by+y<CGI->mh->reader->map.height && !visibilityMap[bx+x][by+y][0])
  1196. {
  1197. SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, 0);
  1198. //SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
  1199. SDL_BlitSurface(hide, NULL, su, &sr);
  1200. //SDL_FreeSurface(hide2);
  1201. }
  1202. }
  1203. else
  1204. {
  1205. //if( bx+x>-1 && by+y>-1 && bx+x<visibilityMap.size()-(-1) && by+y<visibilityMap[0].size()-(-1) && !visibilityMap[bx+x][by+y][1])
  1206. if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->reader->map.width && by+y<CGI->mh->reader->map.height && !visibilityMap[bx+x][by+y][1])
  1207. {
  1208. SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, 1);
  1209. //SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
  1210. SDL_BlitSurface(hide, NULL, su, &sr);
  1211. //SDL_FreeSurface(hide2);
  1212. }
  1213. }
  1214. }
  1215. }
  1216. ////shadow printed
  1217. //printing borders
  1218. for (int bx=0; bx<dx; bx++)
  1219. {
  1220. for (int by=0; by<dy; by++)
  1221. {
  1222. if(bx+x<0 || by+y<0 || bx+x>reader->map.width+(-1) || by+y>reader->map.height+(-1))
  1223. {
  1224. SDL_Rect sr;
  1225. sr.y=by*32;
  1226. sr.x=bx*32;
  1227. sr.h=sr.w=32;
  1228. SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,&sr);
  1229. }
  1230. else
  1231. {
  1232. if(MARK_BLOCKED_POSITIONS && ttiles[x+bx][y+by][level].blocked) //temporary hiding blocked positions
  1233. {
  1234. SDL_Rect sr;
  1235. sr.y=by*32;
  1236. sr.x=bx*32;
  1237. sr.h=sr.w=32;
  1238. SDL_Surface * ns = CSDL_Ext::newSurface(32, 32, CSDL_Ext::std32bppSurface);
  1239. for(int f=0; f<ns->w*ns->h*4; ++f)
  1240. {
  1241. *((unsigned char*)(ns->pixels) + f) = 128;
  1242. }
  1243. SDL_BlitSurface(ns,NULL,su,&sr);
  1244. SDL_FreeSurface(ns);
  1245. }
  1246. if(MARK_VISITABLE_POSITIONS && ttiles[x+bx][y+by][level].visitable) //temporary hiding visitable positions
  1247. {
  1248. SDL_Rect sr;
  1249. sr.y=by*32;
  1250. sr.x=bx*32;
  1251. sr.h=sr.w=32;
  1252. SDL_Surface * ns = CSDL_Ext::newSurface(32, 32, CSDL_Ext::std32bppSurface);
  1253. for(int f=0; f<ns->w*ns->h*4; ++f)
  1254. {
  1255. *((unsigned char*)(ns->pixels) + f) = 128;
  1256. }
  1257. SDL_BlitSurface(ns,NULL,su,&sr);
  1258. SDL_FreeSurface(ns);
  1259. }
  1260. }
  1261. }
  1262. }
  1263. CSDL_Ext::update(su);
  1264. //borders printed
  1265. return su;
  1266. }
  1267. SDL_Surface * CMapHandler::terrBitmap(int x, int y)
  1268. {
  1269. return ttiles[x+Woff][y+Hoff][0].terbitmap[0];
  1270. }
  1271. SDL_Surface * CMapHandler::undTerrBitmap(int x, int y)
  1272. {
  1273. return ttiles[x+Woff][y+Hoff][0].terbitmap[1];
  1274. }
  1275. SDL_Surface * CMapHandler::getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, int lvl)
  1276. {
  1277. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1278. {
  1279. return fullHide->ourImages[hideBitmap[x][y][lvl]].bitmap; //fully hidden
  1280. }
  1281. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1282. {
  1283. return partialHide->ourImages[22].bitmap; //visible right bottom corner
  1284. }
  1285. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1286. {
  1287. return partialHide->ourImages[15].bitmap; //visible right top corner
  1288. }
  1289. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1290. {
  1291. //return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner
  1292. return partialHide->ourImages[34].bitmap; //visible left bottom corner
  1293. }
  1294. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1295. {
  1296. //return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner
  1297. return partialHide->ourImages[35].bitmap;
  1298. }
  1299. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1300. {
  1301. //return partialHide->ourImages[rand()%2].bitmap; //visible top
  1302. return partialHide->ourImages[0].bitmap; //visible top
  1303. }
  1304. else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1305. {
  1306. //return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom
  1307. return partialHide->ourImages[4].bitmap; //visble bottom
  1308. }
  1309. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1310. {
  1311. //return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left
  1312. //return CSDL_Ext::rotate01(partialHide->ourImages[2].bitmap); //visible left
  1313. return partialHide->ourImages[36].bitmap;
  1314. }
  1315. else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1316. {
  1317. //return partialHide->ourImages[2+rand()%2].bitmap; //visible right
  1318. return partialHide->ourImages[2].bitmap; //visible right
  1319. }
  1320. else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl])
  1321. {
  1322. //return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden
  1323. return partialHide->ourImages[12].bitmap; //visible bottom, right - bottom, right; left top corner hidden
  1324. }
  1325. else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1326. {
  1327. return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden
  1328. }
  1329. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl])
  1330. {
  1331. //return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden
  1332. return partialHide->ourImages[37].bitmap;
  1333. }
  1334. else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y-1][lvl])
  1335. {
  1336. //return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden
  1337. //return CSDL_Ext::rotate01(partialHide->ourImages[12].bitmap); //visible left, left - bottom, bottom; right top corner hidden
  1338. return partialHide->ourImages[38].bitmap;
  1339. }
  1340. else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1341. {
  1342. return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top
  1343. }
  1344. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1345. {
  1346. return partialHide->ourImages[16].bitmap; //visible right corners
  1347. }
  1348. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1349. {
  1350. return partialHide->ourImages[18].bitmap; //visible top corners
  1351. }
  1352. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1353. {
  1354. //return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners
  1355. return partialHide->ourImages[39].bitmap;
  1356. }
  1357. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1358. {
  1359. //return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners
  1360. return partialHide->ourImages[40].bitmap;
  1361. }
  1362. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1363. {
  1364. return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners
  1365. }
  1366. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1367. {
  1368. //return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners
  1369. return partialHide->ourImages[41].bitmap;
  1370. }
  1371. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1372. {
  1373. return partialHide->ourImages[19].bitmap; //visible corners without left top
  1374. }
  1375. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1376. {
  1377. return partialHide->ourImages[20].bitmap; //visible corners without left bottom
  1378. }
  1379. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1380. {
  1381. //return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom
  1382. return partialHide->ourImages[42].bitmap;
  1383. }
  1384. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1385. {
  1386. //return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top
  1387. return partialHide->ourImages[43].bitmap;
  1388. }
  1389. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1390. {
  1391. return partialHide->ourImages[21].bitmap; //visible all corners only
  1392. }
  1393. if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl])
  1394. {
  1395. return partialHide->ourImages[6].bitmap; //hidden top
  1396. }
  1397. if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl])
  1398. {
  1399. return partialHide->ourImages[7].bitmap; //hidden right
  1400. }
  1401. if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl])
  1402. {
  1403. return partialHide->ourImages[8].bitmap; //hidden bottom
  1404. }
  1405. if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl])
  1406. {
  1407. //return CSDL_Ext::rotate01(partialHide->ourImages[7].bitmap); //hidden left
  1408. return partialHide->ourImages[44].bitmap;
  1409. }
  1410. if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl])
  1411. {
  1412. return partialHide->ourImages[9].bitmap; //hidden top and bottom
  1413. }
  1414. if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl])
  1415. {
  1416. return partialHide->ourImages[29].bitmap; //hidden left and right
  1417. }
  1418. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1419. {
  1420. return partialHide->ourImages[24].bitmap; //visible top and right bottom corner
  1421. }
  1422. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl])
  1423. {
  1424. //return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner
  1425. return partialHide->ourImages[45].bitmap;
  1426. }
  1427. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl])
  1428. {
  1429. return partialHide->ourImages[33].bitmap; //visible top and bottom corners
  1430. }
  1431. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl])
  1432. {
  1433. //return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner
  1434. return partialHide->ourImages[46].bitmap;
  1435. }
  1436. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl])
  1437. {
  1438. //return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner
  1439. return partialHide->ourImages[47].bitmap;
  1440. }
  1441. if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl])
  1442. {
  1443. return partialHide->ourImages[32].bitmap; //visible left and right corners
  1444. }
  1445. if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y-1][lvl])
  1446. {
  1447. //return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner
  1448. return partialHide->ourImages[48].bitmap;
  1449. }
  1450. if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl])
  1451. {
  1452. return partialHide->ourImages[30].bitmap; //visible bottom and right top corner
  1453. }
  1454. if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl])
  1455. {
  1456. return partialHide->ourImages[31].bitmap; //visible bottom and top corners
  1457. }
  1458. if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1459. {
  1460. return partialHide->ourImages[25].bitmap; //visible right and left bottom corner
  1461. }
  1462. if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl])
  1463. {
  1464. return partialHide->ourImages[26].bitmap; //visible right and left top corner
  1465. }
  1466. if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1467. {
  1468. //return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres
  1469. return partialHide->ourImages[49].bitmap;
  1470. }
  1471. if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl])
  1472. {
  1473. return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible
  1474. }
  1475. else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y+1][lvl])
  1476. {
  1477. return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible
  1478. }
  1479. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl])
  1480. {
  1481. //return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible
  1482. return partialHide->ourImages[50].bitmap;
  1483. }
  1484. else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y-1][lvl])
  1485. {
  1486. //return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible
  1487. return partialHide->ourImages[51].bitmap;
  1488. }
  1489. //newly added
  1490. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tr
  1491. {
  1492. return partialHide->ourImages[0].bitmap;
  1493. }
  1494. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tl
  1495. {
  1496. return partialHide->ourImages[1].bitmap;
  1497. }
  1498. else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible b and br
  1499. {
  1500. return partialHide->ourImages[4].bitmap;
  1501. }
  1502. else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible b and bl
  1503. {
  1504. return partialHide->ourImages[5].bitmap;
  1505. }
  1506. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible l and tl
  1507. {
  1508. return partialHide->ourImages[36].bitmap;
  1509. }
  1510. else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible l and bl
  1511. {
  1512. return partialHide->ourImages[36].bitmap;
  1513. }
  1514. else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and tr
  1515. {
  1516. return partialHide->ourImages[2].bitmap;
  1517. }
  1518. else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and br
  1519. {
  1520. return partialHide->ourImages[3].bitmap;
  1521. }
  1522. return fullHide->ourImages[0].bitmap; //this case should never happen, but it is better to hide too much than reveal it....
  1523. }
  1524. int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero)
  1525. {
  1526. int ret=-1;
  1527. if(a.x>=CGI->mh->reader->map.width && a.y>=CGI->mh->reader->map.height)
  1528. ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->reader->map.width-1][CGI->mh->reader->map.width-1][a.z].malle];
  1529. else if(a.x>=CGI->mh->reader->map.width && a.y<CGI->mh->reader->map.height)
  1530. ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->reader->map.width-1][a.y][a.z].malle];
  1531. else if(a.x<CGI->mh->reader->map.width && a.y>=CGI->mh->reader->map.height)
  1532. ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->reader->map.width-1][a.z].malle];
  1533. else
  1534. ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle];
  1535. if(!(a.x==b.x || a.y==b.y))
  1536. ret*=1.41421;
  1537. //TODO: use hero's pathfinding skill during calculating cost
  1538. return ret;
  1539. }
  1540. std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos)
  1541. {
  1542. std::vector < std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> > objs = ttiles[pos.x][pos.y][pos.z].objects;
  1543. std::vector<std::string> ret;
  1544. for(int g=0; g<objs.size(); ++g)
  1545. {
  1546. if( (5-(objs[g].first->pos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defInfo &&
  1547. (((objs[g].first->defInfo->blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0
  1548. ) //checking position blocking
  1549. {
  1550. //unsigned char * blm = objs[g].first->defInfo->blockMap;
  1551. if (objs[g].first->state)
  1552. ret.push_back(objs[g].first->state->hoverText(objs[g].first));
  1553. else
  1554. ret.push_back(CGI->objh->objects[objs[g].first->ID].name);
  1555. }
  1556. }
  1557. return ret;
  1558. }
  1559. std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos)
  1560. {
  1561. std::vector < CGObjectInstance * > ret;
  1562. for(int h=0; h<ttiles[pos.x][pos.y][pos.z].objects.size(); ++h)
  1563. {
  1564. CGObjectInstance * curi = ttiles[pos.x][pos.y][pos.z].objects[h].first;
  1565. if(curi->visitableAt(- curi->pos.x + pos.x + curi->getWidth() - 1, -curi->pos.y + pos.y + curi->getHeight() - 1))
  1566. ret.push_back(curi);
  1567. }
  1568. return ret;
  1569. }
  1570. CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos, int owner)
  1571. {
  1572. CGObjectInstance * nobj;
  1573. switch(id)
  1574. {
  1575. case 34: //hero
  1576. {
  1577. CGHeroInstance * nobj;
  1578. nobj = new CGHeroInstance();
  1579. nobj->pos = pos;
  1580. nobj->tempOwner = owner;
  1581. nobj->defInfo = new CGDefInfo();
  1582. nobj->defInfo->id = 34;
  1583. nobj->defInfo->subid = subid;
  1584. nobj->type = CGI->heroh->heroes[subid];
  1585. for(int i=0;i<6;i++)
  1586. {
  1587. nobj->defInfo->blockMap[i]=1;
  1588. nobj->defInfo->visitMap[i]=0;
  1589. }
  1590. nobj->ID = id;
  1591. nobj->subID = subid;
  1592. nobj->defInfo->handler=NULL;
  1593. nobj->defInfo->blockMap[5] = 0x7f;
  1594. nobj->defInfo->visitMap[5] = 0x80;
  1595. nobj->artifWorn.resize(20);
  1596. nobj->artifacts.resize(20);
  1597. nobj->artifWorn[16] = &CGI->arth->artifacts[3];
  1598. return nobj;
  1599. }
  1600. case 98: //town
  1601. nobj = new CGTownInstance;
  1602. break;
  1603. default: //rest of objects
  1604. nobj = new CGObjectInstance;
  1605. nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
  1606. break;
  1607. }
  1608. nobj->ID = id;
  1609. nobj->subID = subid;
  1610. if(!nobj->defInfo)
  1611. std::cout <<"No def declaration for " <<id <<" "<<subid<<std::endl;
  1612. nobj->pos = pos;
  1613. //nobj->state = NULL;//new CLuaObjectScript();
  1614. nobj->tempOwner = owner;
  1615. nobj->info = NULL;
  1616. nobj->defInfo->id = id;
  1617. nobj->defInfo->subid = subid;
  1618. //assigning defhandler
  1619. if(nobj->ID==34 || nobj->ID==98)
  1620. return nobj;
  1621. nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
  1622. if(!nobj->defInfo->handler)
  1623. nobj->defInfo->handler = CGI->spriteh->giveDef(nobj->defInfo->name);
  1624. return nobj;
  1625. }
  1626. std::string CMapHandler::getDefName(int id, int subid)
  1627. {
  1628. CGDefInfo* temp = CGI->dobjinfo->gobjs[id][subid];
  1629. if(temp)
  1630. return temp->name;
  1631. throw new std::exception("Def not found.");
  1632. }
  1633. bool CMapHandler::printObject(CGObjectInstance *obj)
  1634. {
  1635. CDefHandler * curd = obj->defInfo->handler;
  1636. for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
  1637. {
  1638. for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
  1639. {
  1640. SDL_Rect cr;
  1641. cr.w = 32;
  1642. cr.h = 32;
  1643. cr.x = fx*32;
  1644. cr.y = fy*32;
  1645. std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(obj, std::make_pair(cr, std::vector<std::list<int3>>()));
  1646. ///initializing places that will be coloured by blitting (flag colour / player colour positions)
  1647. if(CGI->dobjinfo->gobjs[toAdd.first->ID][toAdd.first->subID]->isVisitable())
  1648. {
  1649. toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
  1650. for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)
  1651. {
  1652. bool breakNow = true;
  1653. for(int dx=0; dx<32; ++dx)
  1654. {
  1655. for(int dy=0; dy<32; ++dy)
  1656. {
  1657. SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap;
  1658. Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx));
  1659. Uint8 r, g, b, a;
  1660. SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a);
  1661. if(r==255 && g==255 && b==0)
  1662. {
  1663. toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0));
  1664. breakNow = false;
  1665. }
  1666. }
  1667. }
  1668. if(breakNow)
  1669. break;
  1670. }
  1671. }
  1672. if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
  1673. {
  1674. TerrainTile2 & curt =
  1675. ttiles
  1676. [obj->pos.x + fx - curd->ourImages[0].bitmap->w/32]
  1677. [obj->pos.y + fy - curd->ourImages[0].bitmap->h/32]
  1678. [obj->pos.z];
  1679. ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects.push_back(toAdd);
  1680. }
  1681. } // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
  1682. } //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
  1683. return true;
  1684. }
  1685. bool CMapHandler::hideObject(CGObjectInstance *obj)
  1686. {
  1687. CDefHandler * curd = obj->defInfo->handler;
  1688. for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
  1689. {
  1690. for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
  1691. {
  1692. if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
  1693. {
  1694. std::vector < std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects;
  1695. for(int dd=0; dd<ctile.size(); ++dd)
  1696. {
  1697. if(ctile[dd].first->id==obj->id)
  1698. ctile.erase(ctile.begin() + dd);
  1699. }
  1700. }
  1701. } // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
  1702. } //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
  1703. return true;
  1704. }
  1705. std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance * obj)
  1706. {
  1707. return std::string();
  1708. }
  1709. bool CMapHandler::removeObject(CGObjectInstance *obj)
  1710. {
  1711. hideObject(obj);
  1712. std::vector<CGObjectInstance *>::iterator db = std::find(CGI->objh->objInstances.begin(), CGI->objh->objInstances.end(), obj);
  1713. recalculateHideVisPosUnderObj(*db);
  1714. delete *db;
  1715. CGI->objh->objInstances.erase(db);
  1716. return true;
  1717. }
  1718. bool CMapHandler::recalculateHideVisPos(int3 &pos)
  1719. {
  1720. ttiles[pos.x][pos.y][pos.z].visitable = false;
  1721. ttiles[pos.x][pos.y][pos.z].blocked = false;
  1722. for(int i=0; i<ttiles[pos.x][pos.y][pos.z].objects.size(); ++i)
  1723. {
  1724. CDefHandler * curd = ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->handler;
  1725. for(int fx=0; fx<8; ++fx)
  1726. {
  1727. for(int fy=0; fy<6; ++fy)
  1728. {
  1729. int xVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.x + fx - 7;
  1730. int yVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.y + fy - 5;
  1731. int zVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.z;
  1732. if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
  1733. {
  1734. TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
  1735. if(((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->visitMap[fy] >> (7 - fx)) & 1))
  1736. curt.visitable = true;
  1737. if(!((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->blockMap[fy] >> (7 - fx)) & 1))
  1738. curt.blocked = true;
  1739. }
  1740. }
  1741. }
  1742. }
  1743. return true;
  1744. }
  1745. bool CMapHandler::recalculateHideVisPosUnderObj(CGObjectInstance *obj, bool withBorder)
  1746. {
  1747. if(withBorder)
  1748. {
  1749. for(int fx=-1; fx<=obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx)
  1750. {
  1751. for(int fy=-1; fy<=obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy)
  1752. {
  1753. if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
  1754. {
  1755. recalculateHideVisPos(int3(obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z));
  1756. }
  1757. }
  1758. }
  1759. }
  1760. else
  1761. {
  1762. for(int fx=0; fx<obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx)
  1763. {
  1764. for(int fy=0; fy<obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy)
  1765. {
  1766. if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
  1767. {
  1768. recalculateHideVisPos(int3(obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z));
  1769. }
  1770. }
  1771. }
  1772. }
  1773. return true;
  1774. }