mapHandler.cpp 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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. extern SDL_Surface * ekran;
  12. class OCM_HLP
  13. {
  14. public:
  15. bool operator ()(const std::pair<CObjectInstance *, SDL_Rect> & a, const std::pair<CObjectInstance *, SDL_Rect> & b)
  16. {
  17. return (*a.first)<(*b.first);
  18. }
  19. } ocmptwo ;
  20. void CMapHandler::init()
  21. {
  22. fullHide = CGameInfo::mainObj->spriteh->giveDef("TSHRC.DEF");
  23. partialHide = CGameInfo::mainObj->spriteh->giveDef("TSHRE.DEF");
  24. for(int i=0; i<partialHide->ourImages.size(); ++i)
  25. {
  26. CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
  27. }
  28. visibility.resize(reader->map.width+2*Woff);
  29. for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
  30. {
  31. visibility[gg].resize(reader->map.height+2*Hoff);
  32. for(int jj=0; jj<reader->map.height+2*Hoff; ++jj)
  33. visibility[gg][jj] = true;
  34. }
  35. undVisibility.resize(reader->map.width+2*Woff);
  36. for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
  37. {
  38. undVisibility[gg].resize(reader->map.height+2*Woff);
  39. for(int jj=0; jj<reader->map.height+2*Woff; ++jj)
  40. undVisibility[gg][jj] = true;
  41. }
  42. visibility[6][7] = false;
  43. undVisibility[5][7] = false;
  44. visibility[7][7] = false;
  45. visibility[6][8] = false;
  46. visibility[6][6] = false;
  47. //visibility[5][6] = false;
  48. //visibility[7][8] = false;
  49. visibility[5][8] = false;
  50. visibility[7][6] = false;
  51. visibility[6][9] = false;
  52. //initializing road's and river's DefHandlers
  53. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  54. int rmask = 0xff000000;
  55. int gmask = 0x00ff0000;
  56. int bmask = 0x0000ff00;
  57. int amask = 0x000000ff;
  58. #else
  59. int rmask = 0x000000ff;
  60. int gmask = 0x0000ff00;
  61. int bmask = 0x00ff0000;
  62. int amask = 0xff000000;
  63. #endif
  64. SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32,
  65. rmask, gmask, bmask, amask);
  66. roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("dirtrd.def"));
  67. roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("gravrd.def"));
  68. roadDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("cobbrd.def"));
  69. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("clrrvr.def"));
  70. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("icyrvr.def"));
  71. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("mudrvr.def"));
  72. staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("lavrvr.def"));
  73. //roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff];
  74. //for (int ii=0;ii<reader->map.width+2*Woff;ii++)
  75. // roadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
  76. sizes.x = CGI->ac->map.width;
  77. sizes.y = CGI->ac->map.height;
  78. sizes.z = CGI->ac->map.twoLevel+1;
  79. ttiles.resize(CGI->ac->map.width,Woff);
  80. for (int i=0-Woff;i<ttiles.size()-Woff;i++)
  81. {
  82. ttiles[i].resize(CGI->ac->map.height,Hoff);
  83. }
  84. for (int i=0-Woff;i<ttiles.size()-Woff;i++)
  85. {
  86. for (int j=0-Hoff;j<CGI->ac->map.height+Hoff;j++)
  87. ttiles[i][j].resize(CGI->ac->map.twoLevel+1,0);
  88. }
  89. for (int i=0; i<reader->map.width; i++) //jest po szerokoœci
  90. {
  91. for (int j=0; j<reader->map.height;j++) //po wysokoœci
  92. {
  93. for (int k=0; k<=reader->map.twoLevel; ++k)
  94. {
  95. TerrainTile** pomm = reader->map.terrain; ;
  96. if (k==0)
  97. pomm = reader->map.terrain;
  98. else
  99. pomm = reader->map.undergroungTerrain;
  100. if(pomm[i][j].malle)
  101. {
  102. int cDir;
  103. bool rotV, rotH;
  104. if(k==0)
  105. {
  106. int roadpom = reader->map.terrain[i][j].malle-1,
  107. impom = reader->map.terrain[i][j].roadDir;
  108. SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap;
  109. ttiles[i][j][k].roadbitmap.push_back(pom1);
  110. cDir = reader->map.terrain[i][j].roadDir;
  111. rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
  112. rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
  113. }
  114. else
  115. {
  116. int pom111 = reader->map.undergroungTerrain[i][j].malle-1,
  117. pom777 = reader->map.undergroungTerrain[i][j].roadDir;
  118. SDL_Surface *pom1 = roadDefs[pom111]->ourImages[pom777].bitmap;
  119. ttiles[i][j][k].roadbitmap.push_back(pom1);
  120. cDir = reader->map.undergroungTerrain[i][j].roadDir;
  121. rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
  122. rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
  123. }
  124. if(rotH)
  125. {
  126. ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].roadbitmap[0]);
  127. }
  128. if(rotV)
  129. {
  130. ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].roadbitmap[0]);
  131. }
  132. if(rotH || rotV)
  133. {
  134. ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].roadbitmap[0]);
  135. SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].roadbitmap[0], su);
  136. SDL_FreeSurface(ttiles[i][j][k].roadbitmap[0]);
  137. ttiles[i][j][k].roadbitmap[0] = buf;
  138. }
  139. }
  140. }
  141. }
  142. }
  143. //initializing simple values
  144. for (int i=0; i<CGI->ac->map.width; i++) //jest po szerokoœci
  145. {
  146. for (int j=0; j<CGI->ac->map.height;j++) //po wysokoœci
  147. {
  148. for(int k=0; k<ttiles[0][0].size(); ++k)
  149. {
  150. ttiles[i][j][k].pos = int3(i, j, k);
  151. ttiles[i][j][k].blocked = false;
  152. ttiles[i][j][k].visitable = false;
  153. if(i<0 || j<0 || i>=CGI->ac->map.width || j>=CGI->ac->map.height)
  154. {
  155. ttiles[i][j][k].blocked = true;
  156. continue;
  157. }
  158. ttiles[i][j][k].terType = (k==0 ? CGI->ac->map.terrain[i][j].tertype : CGI->ac->map.undergroungTerrain[i][j].tertype);
  159. ttiles[i][j][k].malle = (k==0 ? CGI->ac->map.terrain[i][j].malle : CGI->ac->map.undergroungTerrain[i][j].malle);
  160. ttiles[i][j][k].nuine = (k==0 ? CGI->ac->map.terrain[i][j].nuine : CGI->ac->map.undergroungTerrain[i][j].nuine);
  161. ttiles[i][j][k].rivdir = (k==0 ? CGI->ac->map.terrain[i][j].rivDir : CGI->ac->map.undergroungTerrain[i][j].rivDir);
  162. ttiles[i][j][k].roaddir = (k==0 ? CGI->ac->map.terrain[i][j].roadDir : CGI->ac->map.undergroungTerrain[i][j].roadDir);
  163. }
  164. }
  165. }
  166. //simple values initialized
  167. for (int i=0; i<reader->map.width; i++) //jest po szerokoœci
  168. {
  169. for (int j=0; j<reader->map.height;j++) //po wysokoœci
  170. {
  171. for(int k=0; k<=reader->map.twoLevel; ++k)
  172. {
  173. TerrainTile** pomm = reader->map.terrain;
  174. if(k==0)
  175. {
  176. pomm = reader->map.terrain;
  177. }
  178. else
  179. {
  180. pomm = reader->map.undergroungTerrain;
  181. }
  182. if(pomm[i][j].nuine)
  183. {
  184. int cDir;
  185. bool rotH, rotV;
  186. if(k==0)
  187. {
  188. ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.terrain[i][j].nuine-1]->ourImages[reader->map.terrain[i][j].rivDir].bitmap);
  189. cDir = reader->map.terrain[i][j].rivDir;
  190. rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
  191. rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
  192. }
  193. else
  194. {
  195. ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.undergroungTerrain[i][j].nuine-1]->ourImages[reader->map.undergroungTerrain[i][j].rivDir].bitmap);
  196. cDir = reader->map.undergroungTerrain[i][j].rivDir;
  197. rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
  198. rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
  199. }
  200. if(rotH)
  201. {
  202. ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].rivbitmap[0]);
  203. }
  204. if(rotV)
  205. {
  206. ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].rivbitmap[0]);
  207. }
  208. if(rotH || rotV)
  209. {
  210. ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].rivbitmap[0]);
  211. SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].rivbitmap[0], su);
  212. SDL_FreeSurface(ttiles[i][j][k].rivbitmap[0]);
  213. ttiles[i][j][k].rivbitmap[0] = buf;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. SDL_FreeSurface(su);
  220. //road's and river's DefHandlers initialized
  221. //terrainBitmap = new SDL_Surface **[reader->map.width+2*Woff];
  222. //for (int ii=0;ii<reader->map.width+2*Woff;ii++)
  223. // terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
  224. CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF");
  225. for (int i=0-Woff; i<reader->map.width+Woff; i++) //jest po szerokoœci
  226. {
  227. for (int j=0-Hoff; j<reader->map.height+Hoff;j++) //po wysokoœci
  228. {
  229. for(int k=0; k<=reader->map.twoLevel; ++k)
  230. {
  231. if(i < 0 || i > (reader->map.width-1) || j < 0 || j > (reader->map.height-1))
  232. {
  233. if(i==-1 && j==-1)
  234. {
  235. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[16].bitmap);
  236. continue;
  237. }
  238. else if(i==-1 && j==(reader->map.height))
  239. {
  240. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[19].bitmap);
  241. continue;
  242. }
  243. else if(i==(reader->map.width) && j==-1)
  244. {
  245. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[17].bitmap);
  246. continue;
  247. }
  248. else if(i==(reader->map.width) && j==(reader->map.height))
  249. {
  250. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[18].bitmap);
  251. continue;
  252. }
  253. else if(j == -1 && i > -1 && i < reader->map.height)
  254. {
  255. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[22+rand()%2].bitmap);
  256. continue;
  257. }
  258. else if(i == -1 && j > -1 && j < reader->map.height)
  259. {
  260. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[33+rand()%2].bitmap);
  261. continue;
  262. }
  263. else if(j == reader->map.height && i >-1 && i < reader->map.width)
  264. {
  265. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[29+rand()%2].bitmap);
  266. continue;
  267. }
  268. else if(i == reader->map.width && j > -1 && j < reader->map.height)
  269. {
  270. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[25+rand()%2].bitmap);
  271. continue;
  272. }
  273. else
  274. {
  275. ttiles[i][j][k].terbitmap.push_back(bord->ourImages[rand()%16].bitmap);
  276. continue;
  277. }
  278. }
  279. //TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
  280. std::string name;
  281. if (k>0)
  282. name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i][j].tertype);
  283. else
  284. name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
  285. for (unsigned int m=0; m<reader->defs.size(); m++)
  286. {
  287. try
  288. {
  289. if (reader->defs[m]->defName != name)
  290. continue;
  291. else
  292. {
  293. int ktora;
  294. if (k==0)
  295. ktora = reader->map.terrain[i][j].terview;
  296. else
  297. ktora = reader->map.undergroungTerrain[i][j].terview;
  298. ttiles[i][j][k].terbitmap.push_back(reader->defs[m]->ourImages[ktora].bitmap);
  299. int zz;
  300. if (k==0)
  301. zz = (reader->map.terrain[i][j].siodmyTajemniczyBajt)%4;
  302. else
  303. zz = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt)%4;
  304. switch (zz)
  305. {
  306. case 1:
  307. {
  308. ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].terbitmap[0]);
  309. break;
  310. }
  311. case 2:
  312. {
  313. ttiles[i][j][k].terbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].terbitmap[0]);
  314. break;
  315. }
  316. case 3:
  317. {
  318. ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate03(ttiles[i][j][k].terbitmap[0]);
  319. break;
  320. }
  321. }
  322. break;
  323. }
  324. }
  325. catch (...)
  326. {
  327. continue;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. //initializing objects / rects
  334. for(int f=0; f<CGI->objh->objInstances.size(); ++f)
  335. {
  336. /*CGI->objh->objInstances[f]->pos.x+=1;
  337. CGI->objh->objInstances[f]->pos.y+=1;*/
  338. CDefHandler * curd = CGI->ac->map.defy[CGI->objh->objInstances[f]->defNumber].handler;
  339. for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
  340. {
  341. for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
  342. {
  343. SDL_Rect cr;
  344. cr.w = 32;
  345. cr.h = 32;
  346. cr.x = fx*32;
  347. cr.y = fy*32;
  348. std::pair<CObjectInstance *, SDL_Rect> toAdd = std::make_pair(CGI->objh->objInstances[f], cr);
  349. 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)
  350. {
  351. TerrainTile2 & curt =
  352. ttiles
  353. [CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32]
  354. [CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32]
  355. [CGI->objh->objInstances[f]->pos.z];
  356. 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);
  357. }
  358. } // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
  359. } //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
  360. } // for(int f=0; f<CGI->objh->objInstances.size(); ++f)
  361. for(int f=0; f<CGI->objh->objInstances.size(); ++f) //calculationg blocked / visitable positions
  362. {
  363. if(CGI->objh->objInstances[f]->defObjInfoNumber == -1)
  364. continue;
  365. CDefHandler * curd = CGI->ac->map.defy[CGI->objh->objInstances[f]->defNumber].handler;
  366. for(int fx=0; fx<8; ++fx)
  367. {
  368. for(int fy=0; fy<6; ++fy)
  369. {
  370. int xVal = CGI->objh->objInstances[f]->pos.x + fx - 7;
  371. int yVal = CGI->objh->objInstances[f]->pos.y + fy - 5;
  372. int zVal = CGI->objh->objInstances[f]->pos.z;
  373. if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
  374. {
  375. TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
  376. if(((CGI->dobjinfo->objs[CGI->objh->objInstances[f]->defObjInfoNumber].visitMap[fy] >> (7 - fx)) & 1))
  377. curt.visitable = true;
  378. if(!((CGI->dobjinfo->objs[CGI->objh->objInstances[f]->defObjInfoNumber].blockMap[fy] >> (7 - fx)) & 1))
  379. curt.blocked = true;
  380. }
  381. }
  382. }
  383. }
  384. for(int ix=0; ix<ttiles.size()-Woff; ++ix)
  385. {
  386. for(int iy=0; iy<ttiles[0].size()-Hoff; ++iy)
  387. {
  388. for(int iz=0; iz<ttiles[0][0].size(); ++iz)
  389. {
  390. stable_sort(ttiles[ix][iy][iz].objects.begin(), ttiles[ix][iy][iz].objects.end(), ocmptwo);
  391. }
  392. }
  393. }
  394. }
  395. SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim)
  396. {
  397. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  398. int rmask = 0xff000000;
  399. int gmask = 0x00ff0000;
  400. int bmask = 0x0000ff00;
  401. int amask = 0x000000ff;
  402. #else
  403. int rmask = 0x000000ff;
  404. int gmask = 0x0000ff00;
  405. int bmask = 0x00ff0000;
  406. int amask = 0xff000000;
  407. #endif
  408. SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
  409. rmask, gmask, bmask, amask);
  410. if (((dx+x)>((reader->map.width+Woff)) || (dy+y)>((reader->map.height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) )
  411. throw new std::string("terrainRect: out of range");
  412. ////printing terrain
  413. for (int bx=0; bx<dx; bx++)
  414. {
  415. for (int by=0; by<dy; by++)
  416. {
  417. SDL_Rect sr;
  418. sr.y=by*32;
  419. sr.x=bx*32;
  420. sr.h=sr.w=32;
  421. SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,&sr);
  422. }
  423. }
  424. ////terrain printed
  425. ////printing rivers
  426. for (int bx=0; bx<dx; bx++)
  427. {
  428. for (int by=0; by<dy; by++)
  429. {
  430. SDL_Rect sr;
  431. sr.y=by*32;
  432. sr.x=bx*32;
  433. sr.h=sr.w=32;
  434. if(ttiles[x+bx][y+by][level].rivbitmap.size())
  435. SDL_BlitSurface(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,&sr);
  436. }
  437. }
  438. ////rivers printed
  439. ////printing roads
  440. for (int bx=0; bx<dx; bx++)
  441. {
  442. for (int by=-1; by<dy; by++)
  443. {
  444. if(y+by<=-4)
  445. continue;
  446. SDL_Rect sr;
  447. sr.y=by*32+16;
  448. sr.x=bx*32;
  449. sr.h=sr.w=32;
  450. if(ttiles[x+bx][y+by][level].roadbitmap.size())
  451. SDL_BlitSurface(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()],NULL,su,&sr);
  452. }
  453. }
  454. ////roads printed
  455. ////printing objects
  456. for (int bx=0; bx<dx; bx++)
  457. {
  458. for (int by=0; by<dy; by++)
  459. {
  460. for(int h=0; h<ttiles[x+bx][y+by][level].objects.size(); ++h)
  461. {
  462. SDL_Rect sr;
  463. sr.w = 32;
  464. sr.h = 32;
  465. sr.x = (bx)*32;
  466. sr.y = (by)*32;
  467. SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second;
  468. if(ttiles[x+bx][y+by][level].objects[h].first->isHero && ttiles[x+bx][y+by][level].objects[h].first->moveDir && !ttiles[x+bx][y+by][level].objects[h].first->isStanding)
  469. {
  470. int imgVal = 8;
  471. SDL_Surface * tb;
  472. switch(ttiles[x+bx][y+by][level].objects[h].first->moveDir)
  473. {
  474. case 1:
  475. {
  476. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  477. continue;
  478. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  479. int gg;
  480. for(gg=0; gg<iv.size(); ++gg)
  481. {
  482. if(iv[gg].groupNumber==10)
  483. {
  484. tb = iv[gg+anim%imgVal].bitmap;
  485. break;
  486. }
  487. }
  488. SDL_BlitSurface(tb,&pp,su,&sr);
  489. if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
  490. {
  491. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
  492. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  493. }
  494. break;
  495. }
  496. case 2:
  497. {
  498. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  499. continue;
  500. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  501. int gg;
  502. for(gg=0; gg<iv.size(); ++gg)
  503. {
  504. if(iv[gg].groupNumber==5)
  505. {
  506. tb = iv[gg+anim%imgVal].bitmap;
  507. break;
  508. }
  509. }
  510. SDL_BlitSurface(tb,&pp,su,&sr);
  511. if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
  512. {
  513. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
  514. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  515. }
  516. break;
  517. }
  518. case 3:
  519. {
  520. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  521. continue;
  522. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  523. int gg;
  524. for(gg=0; gg<iv.size(); ++gg)
  525. {
  526. if(iv[gg].groupNumber==6)
  527. {
  528. tb = iv[gg+anim%imgVal].bitmap;
  529. break;
  530. }
  531. }
  532. SDL_BlitSurface(tb,&pp,su,&sr);
  533. if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
  534. {
  535. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
  536. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  537. }
  538. break;
  539. }
  540. case 4:
  541. {
  542. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  543. continue;
  544. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  545. int gg;
  546. for(gg=0; gg<iv.size(); ++gg)
  547. {
  548. if(iv[gg].groupNumber==7)
  549. {
  550. tb = iv[gg+anim%imgVal].bitmap;
  551. break;
  552. }
  553. }
  554. SDL_BlitSurface(tb,&pp,su,&sr);
  555. if(ttiles[x+bx][y+by][level].objects[h].first->flagPrinted++==2 )
  556. {
  557. SDL_Rect bufr = pp;
  558. bufr.w = 3*32;
  559. bufr.h = 2*32;
  560. bufr.x = 32 - bufr.x + 3*32 + bx + y + 6*32-10;
  561. bufr.y = 32 - bufr.y + 2*32 + by + x + 5*32-12;
  562. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &bufr);
  563. //ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  564. }
  565. break;
  566. }
  567. case 5:
  568. {
  569. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  570. continue;
  571. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  572. int gg;
  573. for(gg=0; gg<iv.size(); ++gg)
  574. {
  575. if(iv[gg].groupNumber==8)
  576. {
  577. tb = iv[gg+anim%imgVal].bitmap;
  578. break;
  579. }
  580. }
  581. SDL_BlitSurface(tb,&pp,su,&sr);
  582. if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
  583. {
  584. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
  585. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  586. }
  587. break;
  588. }
  589. case 6:
  590. {
  591. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  592. continue;
  593. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  594. int gg;
  595. for(gg=0; gg<iv.size(); ++gg)
  596. {
  597. if(iv[gg].groupNumber==9)
  598. {
  599. tb = iv[gg+anim%imgVal].bitmap;
  600. break;
  601. }
  602. }
  603. SDL_BlitSurface(tb,&pp,su,&sr);
  604. if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
  605. {
  606. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
  607. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  608. }
  609. break;
  610. }
  611. case 7:
  612. {
  613. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  614. continue;
  615. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  616. int gg;
  617. for(gg=0; gg<iv.size(); ++gg)
  618. {
  619. if(iv[gg].groupNumber==12)
  620. {
  621. tb = iv[gg+anim%imgVal].bitmap;
  622. break;
  623. }
  624. }
  625. SDL_BlitSurface(tb,&pp,su,&sr);
  626. if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
  627. {
  628. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
  629. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  630. }
  631. break;
  632. }
  633. case 8:
  634. {
  635. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  636. continue;
  637. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  638. int gg;
  639. for(gg=0; gg<iv.size(); ++gg)
  640. {
  641. if(iv[gg].groupNumber==11)
  642. {
  643. tb = iv[gg+anim%imgVal].bitmap;
  644. break;
  645. }
  646. }
  647. SDL_BlitSurface(tb,&pp,su,&sr);
  648. if(!ttiles[x+bx][y+by][level].objects[h].first->flagPrinted)
  649. {
  650. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[gg+anim%imgVal+35].bitmap, NULL, su, &sr);
  651. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  652. }
  653. break;
  654. }
  655. }
  656. }
  657. else if(ttiles[x+bx][y+by][level].objects[h].first->isHero && ttiles[x+bx][y+by][level].objects[h].first->moveDir && ttiles[x+bx][y+by][level].objects[h].first->isStanding)
  658. {
  659. int imgVal = 8;
  660. SDL_Surface * tb;
  661. switch(ttiles[x+bx][y+by][level].objects[h].first->moveDir)
  662. {
  663. case 1:
  664. {
  665. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  666. continue;
  667. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  668. int gg;
  669. for(gg=0; gg<iv.size(); ++gg)
  670. {
  671. if(iv[gg].groupNumber==13)
  672. {
  673. tb = iv[gg].bitmap;
  674. break;
  675. }
  676. }
  677. SDL_BlitSurface(tb,&pp,su,&sr);
  678. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  679. {
  680. SDL_Rect bufr = sr;
  681. bufr.x-=2*32;
  682. bufr.y-=1*32;
  683. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[13*8+anim%imgVal].bitmap, NULL, su, &bufr);
  684. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  685. }
  686. break;
  687. }
  688. case 2:
  689. {
  690. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  691. continue;
  692. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  693. int gg;
  694. for(gg=0; gg<iv.size(); ++gg)
  695. {
  696. if(iv[gg].groupNumber==0)
  697. {
  698. tb = iv[gg].bitmap;
  699. break;
  700. }
  701. }
  702. SDL_BlitSurface(tb,&pp,su,&sr);
  703. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  704. {
  705. SDL_Rect bufr = sr;
  706. bufr.x-=2*32;
  707. bufr.y-=1*32;
  708. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[anim%imgVal].bitmap, NULL, su, &bufr);
  709. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  710. }
  711. break;
  712. }
  713. case 3:
  714. {
  715. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  716. continue;
  717. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  718. int gg;
  719. for(gg=0; gg<iv.size(); ++gg)
  720. {
  721. if(iv[gg].groupNumber==1)
  722. {
  723. tb = iv[gg].bitmap;
  724. break;
  725. }
  726. }
  727. SDL_BlitSurface(tb,&pp,su,&sr);
  728. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  729. {
  730. SDL_Rect bufr = sr;
  731. bufr.x-=2*32;
  732. bufr.y-=1*32;
  733. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[8+anim%imgVal].bitmap, NULL, su, &bufr);
  734. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  735. }
  736. break;
  737. }
  738. case 4:
  739. {
  740. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  741. continue;
  742. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  743. int gg;
  744. for(gg=0; gg<iv.size(); ++gg)
  745. {
  746. if(iv[gg].groupNumber==2)
  747. {
  748. tb = iv[gg].bitmap;
  749. break;
  750. }
  751. }
  752. SDL_BlitSurface(tb,&pp,su,&sr);
  753. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  754. {
  755. SDL_Rect bufr = sr;
  756. bufr.x-=2*32;
  757. bufr.y-=1*32;
  758. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[2*8+anim%imgVal].bitmap, NULL, su, &bufr);
  759. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  760. }
  761. break;
  762. }
  763. case 5:
  764. {
  765. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  766. continue;
  767. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  768. int gg;
  769. for(gg=0; gg<iv.size(); ++gg)
  770. {
  771. if(iv[gg].groupNumber==3)
  772. {
  773. tb = iv[gg].bitmap;
  774. break;
  775. }
  776. }
  777. SDL_BlitSurface(tb,&pp,su,&sr);
  778. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  779. {
  780. SDL_Rect bufr = sr;
  781. bufr.x-=2*32;
  782. bufr.y-=1*32;
  783. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[3*8+anim%imgVal].bitmap, NULL, su, &bufr);
  784. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  785. }
  786. break;
  787. }
  788. case 6:
  789. {
  790. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  791. continue;
  792. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  793. int gg;
  794. for(gg=0; gg<iv.size(); ++gg)
  795. {
  796. if(iv[gg].groupNumber==4)
  797. {
  798. tb = iv[gg].bitmap;
  799. break;
  800. }
  801. }
  802. SDL_BlitSurface(tb,&pp,su,&sr);
  803. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  804. {
  805. SDL_Rect bufr = sr;
  806. bufr.x-=2*32;
  807. bufr.y-=1*32;
  808. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[4*8+anim%imgVal].bitmap, NULL, su, &bufr);
  809. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  810. }
  811. break;
  812. }
  813. case 7:
  814. {
  815. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  816. continue;
  817. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  818. int gg;
  819. for(gg=0; gg<iv.size(); ++gg)
  820. {
  821. if(iv[gg].groupNumber==15)
  822. {
  823. tb = iv[gg].bitmap;
  824. break;
  825. }
  826. }
  827. SDL_BlitSurface(tb,&pp,su,&sr);
  828. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  829. {
  830. SDL_Rect bufr = sr;
  831. bufr.x-=2*32;
  832. bufr.y-=1*32;
  833. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[15*8+anim%imgVal].bitmap, NULL, su, &bufr);
  834. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  835. }
  836. break;
  837. }
  838. case 8:
  839. {
  840. if(((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type==NULL)
  841. continue;
  842. std::vector<Cimage> & iv = ((CHeroObjInfo*)ttiles[x+bx][y+by][level].objects[h].first->info)->myInstance->type->heroClass->moveAnim->ourImages;
  843. int gg;
  844. for(gg=0; gg<iv.size(); ++gg)
  845. {
  846. if(iv[gg].groupNumber==14)
  847. {
  848. tb = iv[gg].bitmap;
  849. break;
  850. }
  851. }
  852. SDL_BlitSurface(tb,&pp,su,&sr);
  853. if(ttiles[x+bx][y+by][level].objects[h].first->pos.x==x+bx && ttiles[x+bx][y+by][level].objects[h].first->pos.y==y+by)
  854. {
  855. SDL_Rect bufr = sr;
  856. bufr.x-=2*32;
  857. bufr.y-=1*32;
  858. SDL_BlitSurface(CGI->heroh->flags4[ttiles[x+bx][y+by][level].objects[h].first->owner]->ourImages[14*8+anim%imgVal].bitmap, NULL, su, &bufr);
  859. ttiles[x+bx][y+by][level].objects[h].first->flagPrinted = true;
  860. }
  861. break;
  862. }
  863. }
  864. }
  865. else
  866. {
  867. int imgVal = CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages.size();
  868. SDL_BlitSurface(CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap,&pp,su,&sr);
  869. }
  870. }
  871. }
  872. }
  873. ///enabling flags
  874. for(int qq=0; qq<CGI->heroh->heroInstances.size(); ++qq)
  875. {
  876. CGI->heroh->heroInstances[qq]->ourObject->flagPrinted = false;
  877. }
  878. ///flags enabled
  879. ////objects printed, printing shadow
  880. for (int bx=0; bx<dx; bx++)
  881. {
  882. for (int by=0; by<dy; by++)
  883. {
  884. SDL_Rect sr;
  885. sr.y=by*32;
  886. sr.x=bx*32;
  887. sr.h=sr.w=32;
  888. if (!level)
  889. {
  890. if( bx+x>-1 && by+y>-1 && bx+x<visibility.size()-(-1) && by+y<visibility[0].size()-(-1) && !visibility[bx+x][by+y])
  891. {
  892. SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibility);
  893. SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
  894. SDL_BlitSurface(hide2, NULL, su, &sr);
  895. SDL_FreeSurface(hide2);
  896. }
  897. }
  898. else
  899. {
  900. if( bx+x>-1 && by+y>-1 && bx+x<undVisibility.size()-(-1) && by+y<undVisibility[0].size()-(-1) && !undVisibility[bx+x][by+y])
  901. {
  902. SDL_Surface * hide = getVisBitmap(bx+x, by+y, undVisibility);
  903. SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
  904. SDL_BlitSurface(hide2, NULL, su, &sr);
  905. SDL_FreeSurface(hide2);
  906. }
  907. }
  908. }
  909. }
  910. ////shadow printed
  911. //printing borders
  912. for (int bx=0; bx<dx; bx++)
  913. {
  914. for (int by=0; by<dy; by++)
  915. {
  916. if(bx+x<0 || by+y<0 || bx+x>reader->map.width+(-1) || by+y>reader->map.height+(-1))
  917. {
  918. SDL_Rect sr;
  919. sr.y=by*32;
  920. sr.x=bx*32;
  921. sr.h=sr.w=32;
  922. SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,&sr);
  923. }
  924. else
  925. {
  926. if(MARK_BLOCKED_POSITIONS && ttiles[x+bx][y+by][level].blocked) //temporary hiding blocked positions
  927. {
  928. SDL_Rect sr;
  929. sr.y=by*32;
  930. sr.x=bx*32;
  931. sr.h=sr.w=32;
  932. SDL_Surface * ns = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32,
  933. rmask, gmask, bmask, amask);
  934. for(int f=0; f<ns->w*ns->h*4; ++f)
  935. {
  936. *((unsigned char*)(ns->pixels) + f) = 128;
  937. }
  938. SDL_BlitSurface(ns,NULL,su,&sr);
  939. SDL_FreeSurface(ns);
  940. }
  941. if(MARK_VISITABLE_POSITIONS && ttiles[x+bx][y+by][level].visitable) //temporary hiding visitable positions
  942. {
  943. SDL_Rect sr;
  944. sr.y=by*32;
  945. sr.x=bx*32;
  946. sr.h=sr.w=32;
  947. SDL_Surface * ns = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32,
  948. rmask, gmask, bmask, amask);
  949. for(int f=0; f<ns->w*ns->h*4; ++f)
  950. {
  951. *((unsigned char*)(ns->pixels) + f) = 128;
  952. }
  953. SDL_BlitSurface(ns,NULL,su,&sr);
  954. SDL_FreeSurface(ns);
  955. }
  956. }
  957. }
  958. }
  959. CSDL_Ext::update(su);
  960. //borders printed
  961. return su;
  962. }
  963. SDL_Surface * CMapHandler::terrBitmap(int x, int y)
  964. {
  965. return ttiles[x+Woff][y+Hoff][0].terbitmap[0];
  966. }
  967. SDL_Surface * CMapHandler::undTerrBitmap(int x, int y)
  968. {
  969. return ttiles[x+Woff][y+Hoff][0].terbitmap[1];
  970. }
  971. SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector<char> > & visibility)
  972. {
  973. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
  974. {
  975. return fullHide->ourImages[rand()%fullHide->ourImages.size()].bitmap; //fully hidden
  976. }
  977. else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
  978. {
  979. return partialHide->ourImages[22].bitmap; //visible right bottom corner
  980. }
  981. else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
  982. {
  983. return partialHide->ourImages[15].bitmap; //visible right top corner
  984. }
  985. else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
  986. {
  987. return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner
  988. }
  989. else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
  990. {
  991. return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner
  992. }
  993. else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
  994. {
  995. //return partialHide->ourImages[rand()%2].bitmap; //visible top
  996. return partialHide->ourImages[0].bitmap; //visible top
  997. }
  998. else if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
  999. {
  1000. //return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom
  1001. return partialHide->ourImages[4].bitmap; //visble bottom
  1002. }
  1003. else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
  1004. {
  1005. //return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left
  1006. return CSDL_Ext::rotate01(partialHide->ourImages[2].bitmap); //visible left
  1007. }
  1008. else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
  1009. {
  1010. //return partialHide->ourImages[2+rand()%2].bitmap; //visible right
  1011. return partialHide->ourImages[2].bitmap; //visible right
  1012. }
  1013. else if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1])
  1014. {
  1015. //return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden
  1016. return partialHide->ourImages[12].bitmap; //visible bottom, right - bottom, right; left top corner hidden
  1017. }
  1018. else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && !visibility[x-1][y+1])
  1019. {
  1020. return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden
  1021. }
  1022. else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && !visibility[x+1][y+1])
  1023. {
  1024. return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden
  1025. }
  1026. else if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && !visibility[x+1][y-1])
  1027. {
  1028. //return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden
  1029. return CSDL_Ext::rotate01(partialHide->ourImages[12].bitmap); //visible left, left - bottom, bottom; right top corner hidden
  1030. }
  1031. else if(visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
  1032. {
  1033. return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top
  1034. }
  1035. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
  1036. {
  1037. return partialHide->ourImages[16].bitmap; //visible right corners
  1038. }
  1039. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
  1040. {
  1041. return partialHide->ourImages[18].bitmap; //visible top corners
  1042. }
  1043. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
  1044. {
  1045. return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners
  1046. }
  1047. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
  1048. {
  1049. return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners
  1050. }
  1051. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
  1052. {
  1053. return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners
  1054. }
  1055. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
  1056. {
  1057. return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners
  1058. }
  1059. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
  1060. {
  1061. return partialHide->ourImages[19].bitmap; //visible corners without left top
  1062. }
  1063. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
  1064. {
  1065. return partialHide->ourImages[20].bitmap; //visible corners without left bottom
  1066. }
  1067. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
  1068. {
  1069. return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom
  1070. }
  1071. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
  1072. {
  1073. return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top
  1074. }
  1075. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
  1076. {
  1077. return partialHide->ourImages[21].bitmap; //visible all corners only
  1078. }
  1079. if(visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1])
  1080. {
  1081. return partialHide->ourImages[6].bitmap; //hidden top
  1082. }
  1083. if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
  1084. {
  1085. return partialHide->ourImages[7].bitmap; //hidden right
  1086. }
  1087. if(!visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
  1088. {
  1089. return partialHide->ourImages[8].bitmap; //hidden bottom
  1090. }
  1091. if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1])
  1092. {
  1093. return CSDL_Ext::rotate01(partialHide->ourImages[6].bitmap); //hidden left
  1094. }
  1095. if(!visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
  1096. {
  1097. return partialHide->ourImages[9].bitmap; //hidden top and bottom
  1098. }
  1099. if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1])
  1100. {
  1101. return partialHide->ourImages[29].bitmap; //hidden left and right
  1102. }
  1103. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x+1][y+1] && !visibility[x-1][y+1])
  1104. {
  1105. return partialHide->ourImages[24].bitmap; //visible top and right bottom corner
  1106. }
  1107. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && !visibility[x+1][y+1] && visibility[x-1][y+1])
  1108. {
  1109. return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner
  1110. }
  1111. if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x+1][y+1] && visibility[x-1][y+1])
  1112. {
  1113. return partialHide->ourImages[33].bitmap; //visible top and bottom corners
  1114. }
  1115. if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1])
  1116. {
  1117. return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner
  1118. }
  1119. if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1])
  1120. {
  1121. return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner
  1122. }
  1123. if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1])
  1124. {
  1125. return partialHide->ourImages[32].bitmap; //visible left and right corners
  1126. }
  1127. if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y-1])
  1128. {
  1129. return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner
  1130. }
  1131. if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y-1])
  1132. {
  1133. return partialHide->ourImages[30].bitmap; //visible bottom and right top corner
  1134. }
  1135. if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y-1])
  1136. {
  1137. return partialHide->ourImages[31].bitmap; //visible bottom and top corners
  1138. }
  1139. if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x-1][y+1])
  1140. {
  1141. return partialHide->ourImages[25].bitmap; //visible right and left bottom corner
  1142. }
  1143. if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x-1][y+1])
  1144. {
  1145. return partialHide->ourImages[26].bitmap; //visible right and left top corner
  1146. }
  1147. if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x-1][y+1])
  1148. {
  1149. return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres
  1150. }
  1151. if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1])
  1152. {
  1153. return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible
  1154. }
  1155. else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x-1][y+1])
  1156. {
  1157. return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible
  1158. }
  1159. else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && visibility[x+1][y+1])
  1160. {
  1161. return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible
  1162. }
  1163. else if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x+1][y-1])
  1164. {
  1165. return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible
  1166. }
  1167. return fullHide->ourImages[0].bitmap; //this case should never happen, but it is better to hide too much than reveal it....
  1168. }
  1169. char & CMapHandler::visAccess(int x, int y)
  1170. {
  1171. return visibility[x+Woff][y+Hoff];
  1172. }
  1173. char & CMapHandler::undVisAccess(int x, int y)
  1174. {
  1175. return undVisibility[x+Woff][y+Hoff];
  1176. }
  1177. int CMapHandler::getCost(int3 &a, int3 &b, const CHeroInstance *hero)
  1178. {
  1179. int ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle];
  1180. if(!(a.x==b.x || a.y==b.y))
  1181. ret*=1.41421;
  1182. //TODO: use hero's pathfinding skill during calculating cost
  1183. return ret;
  1184. }
  1185. std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos)
  1186. {
  1187. std::vector < std::pair<CObjectInstance*,SDL_Rect> > objs = ttiles[pos.x][pos.y][pos.z].objects;
  1188. std::vector<std::string> ret;
  1189. for(int g=0; g<objs.size(); ++g)
  1190. {
  1191. if( (5-(objs[g].first->pos.y-pos.y-1)) >= 0 && (5-(objs[g].first->pos.y-pos.y-1)) < 6 && (objs[g].first->pos.x-pos.x-1) >= 0 && (objs[g].first->pos.x-pos.x-1)<7 && objs[g].first->defObjInfoNumber!=-1 &&
  1192. (((CGI->dobjinfo->objs[objs[g].first->defObjInfoNumber].blockMap[5-(objs[g].first->pos.y-pos.y-1)])>>((objs[g].first->pos.x-pos.x-1)))&1)==0
  1193. ) //checking position blocking
  1194. {
  1195. unsigned char * blm = CGI->dobjinfo->objs[objs[g].first->defObjInfoNumber].blockMap;
  1196. ret.push_back(CGI->objh->objects[CGI->ac->map.defy[objs[g].first->defNumber].bytes[16]].name);
  1197. }
  1198. }
  1199. return ret;
  1200. }