mapHandler.cpp 67 KB

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