mapHandler.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. #include "stdafx.h"
  2. #include "mapHandler.h"
  3. #include "CSemiDefHandler.h"
  4. #include "SDL_rotozoom.h"
  5. #include "SDL_Extensions.h"
  6. #include "CGameInfo.h"
  7. #include "stdlib.h"
  8. #include <algorithm>
  9. extern SDL_Surface * ekran;
  10. //
  11. //bool ObjSorter::operator <(const ObjSorter & por) const
  12. //{
  13. // if(this->xpos>=por.xpos)
  14. // return false;
  15. // if(this->ypos>=por.ypos)
  16. // return false;
  17. // return true;
  18. //};
  19. class poX
  20. {
  21. public:
  22. bool operator()(const ObjSorter & por2, const ObjSorter & por) const
  23. {
  24. if(por2.xpos<=por.xpos)
  25. return false;
  26. return true;
  27. };
  28. } pox;
  29. class poY
  30. {
  31. public:
  32. bool operator ()(const ObjSorter & por2, const ObjSorter & por) const
  33. {
  34. if(por2.ypos>=por.ypos)
  35. return false;
  36. return true;
  37. };
  38. } poy;
  39. void CMapHandler::init()
  40. {
  41. fullHide = CGameInfo::mainObj->spriteh->giveDef("TSHRC.DEF");
  42. partialHide = CGameInfo::mainObj->sspriteh->giveDef("TSHRE.DEF");
  43. for(int i=0; i<partialHide->ourImages.size(); ++i)
  44. {
  45. CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
  46. }
  47. visibility.resize(reader->map.width+2*Woff);
  48. for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
  49. {
  50. visibility[gg].resize(reader->map.height+2*Hoff);
  51. for(int jj=0; jj<reader->map.height+2*Hoff; ++jj)
  52. visibility[gg][jj] = true;
  53. }
  54. undVisibility.resize(reader->map.width+2*Woff);
  55. for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
  56. {
  57. undVisibility[gg].resize(reader->map.height+2*Woff);
  58. for(int jj=0; jj<reader->map.height+2*Woff; ++jj)
  59. undVisibility[gg][jj] = true;
  60. }
  61. visibility[6][7] = false;
  62. undVisibility[5][7] = false;
  63. visibility[7][7] = false;
  64. visibility[6][8] = false;
  65. visibility[6][6] = false;
  66. //visibility[5][6] = false;
  67. //visibility[7][8] = false;
  68. visibility[5][8] = false;
  69. visibility[7][6] = false;
  70. visibility[6][9] = false;
  71. terrainBitmap = new SDL_Surface **[reader->map.width+8];
  72. for (int ii=0;ii<reader->map.width+2*Woff;ii++)
  73. terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
  74. CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF");
  75. for (int i=0; i<reader->map.width+2*Woff; i++) //jest po szerokoœci
  76. {
  77. for (int j=0; j<reader->map.height+2*Hoff;j++) //po wysokoœci
  78. {
  79. if(i < Woff || i > (reader->map.width+Woff-1) || j < Hoff || j > (reader->map.height+Hoff-1))
  80. {
  81. if(i==Woff-1 && j==Hoff-1)
  82. {
  83. terrainBitmap[i][j] = bord->ourImages[16].bitmap;
  84. continue;
  85. }
  86. else if(i==Woff-1 && j==(reader->map.height+Hoff))
  87. {
  88. terrainBitmap[i][j] = bord->ourImages[19].bitmap;
  89. continue;
  90. }
  91. else if(i==(reader->map.width+Woff) && j==Hoff-1)
  92. {
  93. terrainBitmap[i][j] = bord->ourImages[17].bitmap;
  94. continue;
  95. }
  96. else if(i==(reader->map.width+Woff) && j==(reader->map.height+Hoff))
  97. {
  98. terrainBitmap[i][j] = bord->ourImages[18].bitmap;
  99. continue;
  100. }
  101. else if(j == Hoff-1 && i > Woff-1 && i < reader->map.height+Woff)
  102. {
  103. terrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
  104. continue;
  105. }
  106. else if(i == Woff-1 && j > Hoff-1 && j < reader->map.height+Hoff)
  107. {
  108. terrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
  109. continue;
  110. }
  111. else if(j == reader->map.height+Hoff && i > Woff-1 && i < reader->map.width+Woff)
  112. {
  113. terrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
  114. continue;
  115. }
  116. else if(i == reader->map.width+Woff && j > Hoff-1 && j < reader->map.height+Hoff)
  117. {
  118. terrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
  119. continue;
  120. }
  121. else
  122. {
  123. terrainBitmap[i][j] = bord->ourImages[rand()%16].bitmap;
  124. continue;
  125. }
  126. }
  127. TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
  128. std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i-Woff][j-Hoff].tertype);
  129. for (unsigned int k=0; k<reader->defs.size(); k++)
  130. {
  131. try
  132. {
  133. if (reader->defs[k]->defName != name)
  134. continue;
  135. else
  136. {
  137. int ktora = reader->map.terrain[i-Woff][j-Hoff].terview;
  138. terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
  139. //TODO: odwracanie
  140. switch ((reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4)
  141. {
  142. case 1:
  143. {
  144. terrainBitmap[i][j] = CSDL_Ext::rotate01(terrainBitmap[i][j]);
  145. break;
  146. }
  147. case 2:
  148. {
  149. terrainBitmap[i][j] = CSDL_Ext::hFlip(terrainBitmap[i][j]);
  150. break;
  151. }
  152. case 3:
  153. {
  154. terrainBitmap[i][j] = CSDL_Ext::rotate03(terrainBitmap[i][j]);
  155. break;
  156. }
  157. }
  158. //SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
  159. break;
  160. }
  161. }
  162. catch (...)
  163. { continue; }
  164. }
  165. }
  166. }
  167. if (reader->map.twoLevel)
  168. {
  169. undTerrainBitmap = new SDL_Surface **[reader->map.width+8];
  170. for (int ii=0;ii<reader->map.width+8;ii++)
  171. undTerrainBitmap[ii] = new SDL_Surface*[reader->map.height+8]; // allocate memory
  172. for (int i=0; i<reader->map.width+2*Woff; i++)
  173. {
  174. for (int j=0; j<reader->map.height+2*Hoff;j++)
  175. {
  176. if(i < Woff || i > (reader->map.width+Woff-1) || j < Hoff || j > (reader->map.height+Hoff-1))
  177. {
  178. if(i==Woff-1 && j==Hoff-1)
  179. {
  180. undTerrainBitmap[i][j] = bord->ourImages[16].bitmap;
  181. continue;
  182. }
  183. else if(i==Woff-1 && j==(reader->map.height+Hoff))
  184. {
  185. undTerrainBitmap[i][j] = bord->ourImages[19].bitmap;
  186. continue;
  187. }
  188. else if(i==(reader->map.width+Woff) && j==Hoff-1)
  189. {
  190. undTerrainBitmap[i][j] = bord->ourImages[17].bitmap;
  191. continue;
  192. }
  193. else if(i==(reader->map.width+Woff) && j==(reader->map.height+Hoff))
  194. {
  195. undTerrainBitmap[i][j] = bord->ourImages[18].bitmap;
  196. continue;
  197. }
  198. else if(j == Hoff-1 && i > Woff-1 && i < reader->map.width+Woff)
  199. {
  200. undTerrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
  201. continue;
  202. }
  203. else if(i == Woff-1 && j > Hoff-1 && j < reader->map.height+Hoff)
  204. {
  205. undTerrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
  206. continue;
  207. }
  208. else if(j == reader->map.height+Hoff && i > Woff-1 && i < reader->map.width+Woff)
  209. {
  210. undTerrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
  211. continue;
  212. }
  213. else if(i == reader->map.width+Woff && j > Hoff-1 && j < reader->map.height+Hoff)
  214. {
  215. undTerrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
  216. continue;
  217. }
  218. else
  219. {
  220. undTerrainBitmap[i][j] = bord->ourImages[rand()%16].bitmap;
  221. continue;
  222. }
  223. }
  224. TerrainTile zz = reader->map.undergroungTerrain[i-Woff][j-Hoff];
  225. std::string name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i-Woff][j-Hoff].tertype);
  226. for (unsigned int k=0; k<reader->defs.size(); k++)
  227. {
  228. try
  229. {
  230. if (reader->defs[k]->defName != name)
  231. continue;
  232. else
  233. {
  234. int ktora = reader->map.undergroungTerrain[i-Woff][j-Hoff].terview;
  235. undTerrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
  236. //TODO: odwracanie
  237. switch ((reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4)
  238. {
  239. case 1:
  240. {
  241. undTerrainBitmap[i][j] = CSDL_Ext::rotate01(undTerrainBitmap[i][j]);
  242. break;
  243. }
  244. case 2:
  245. {
  246. undTerrainBitmap[i][j] = CSDL_Ext::hFlip(undTerrainBitmap[i][j]);
  247. break;
  248. }
  249. case 3:
  250. {
  251. undTerrainBitmap[i][j] = CSDL_Ext::rotate03(undTerrainBitmap[i][j]);
  252. break;
  253. }
  254. }
  255. //SDL_BlitSurface(undTerrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
  256. break;
  257. }
  258. }
  259. catch (...)
  260. { continue; }
  261. }
  262. } //end of internal for
  263. } //end of external for
  264. } //end of if
  265. }
  266. SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim)
  267. {
  268. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  269. int rmask = 0xff000000;
  270. int gmask = 0x00ff0000;
  271. int bmask = 0x0000ff00;
  272. int amask = 0x000000ff;
  273. #else
  274. int rmask = 0x000000ff;
  275. int gmask = 0x0000ff00;
  276. int bmask = 0x00ff0000;
  277. int amask = 0xff000000;
  278. #endif
  279. SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
  280. rmask, gmask, bmask, amask);
  281. if (((dx+x)>((reader->map.width+8)) || (dy+y)>((reader->map.height+8))) || ((x<0)||(y<0) ) )
  282. throw new std::string("Poza zakresem");
  283. ////printing terrain
  284. for (int bx=0; bx<dx; bx++)
  285. {
  286. for (int by=0; by<dy; by++)
  287. {
  288. SDL_Rect * sr = new SDL_Rect;
  289. sr->y=by*32;
  290. sr->x=bx*32;
  291. sr->h=sr->w=32;
  292. if (!level)
  293. {
  294. SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
  295. }
  296. else
  297. {
  298. SDL_BlitSurface(undTerrainBitmap[bx+x][by+y],NULL,su,sr);
  299. }
  300. delete sr;
  301. }
  302. }
  303. ////terrain printed; printing objects
  304. std::vector<ObjSorter> lowPrObjs;
  305. std::vector<ObjSorter> highPrObjs;
  306. std::vector<ObjSorter> highPrObjsVis;
  307. for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
  308. {
  309. if(CGameInfo::mainObj->objh->objInstances[gg].x >= x-Woff-4 && CGameInfo::mainObj->objh->objInstances[gg].x < dx+x-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].y >= y-Hoff-4 && CGameInfo::mainObj->objh->objInstances[gg].y < dy+y-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
  310. {
  311. if(!CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isOnDefList)
  312. {
  313. ObjSorter os;
  314. os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
  315. os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
  316. os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
  317. highPrObjsVis.push_back(os);
  318. }
  319. else if(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].printPriority==0)
  320. {
  321. ObjSorter os;
  322. int defyod = CGameInfo::mainObj->objh->objInstances[gg].defNumber;
  323. int ourimagesod = anim%CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages.size();
  324. os.bitmap = CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages[ourimagesod].bitmap;
  325. os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
  326. os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
  327. if (CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isVisitable())
  328. highPrObjsVis.push_back(os);
  329. else
  330. highPrObjs.push_back(os);
  331. }
  332. else
  333. {
  334. ObjSorter os;
  335. os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
  336. os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
  337. os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
  338. lowPrObjs.push_back(os);
  339. }
  340. }
  341. }
  342. #ifndef _DEBUG
  343. std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), pox);
  344. std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), poy);
  345. std::stable_sort(highPrObjs.begin(), highPrObjs.end(),pox);
  346. std::stable_sort(highPrObjs.begin(), highPrObjs.end(),poy);
  347. std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox);
  348. std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy);
  349. #else
  350. std::sort(lowPrObjs.begin(), lowPrObjs.end(), pox);
  351. std::sort(lowPrObjs.begin(), lowPrObjs.end(), poy);
  352. std::sort(highPrObjs.begin(), highPrObjs.end(),pox);
  353. std::sort(highPrObjs.begin(), highPrObjs.end(),poy);
  354. std::sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox);
  355. std::sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy);
  356. #endif
  357. for(int yy=0; yy<lowPrObjs.size(); ++yy)
  358. {
  359. SDL_Rect * sr = new SDL_Rect;
  360. sr->w = lowPrObjs[yy].bitmap->w;
  361. sr->h = lowPrObjs[yy].bitmap->h;
  362. sr->x = lowPrObjs[yy].xpos - lowPrObjs[yy].bitmap->w + 32;
  363. sr->y = lowPrObjs[yy].ypos - lowPrObjs[yy].bitmap->h + 32;
  364. SDL_BlitSurface(lowPrObjs[yy].bitmap, NULL, su, sr);
  365. delete sr;
  366. }
  367. for(int yy=0; yy<highPrObjs.size(); ++yy)
  368. {
  369. SDL_Rect * sr = new SDL_Rect;
  370. sr->w = highPrObjs[yy].bitmap->w;
  371. sr->h = highPrObjs[yy].bitmap->h;
  372. sr->x = highPrObjs[yy].xpos - highPrObjs[yy].bitmap->w + 32;
  373. sr->y = highPrObjs[yy].ypos - highPrObjs[yy].bitmap->h + 32;
  374. SDL_BlitSurface(highPrObjs[yy].bitmap, NULL, su, sr);
  375. delete sr;
  376. }
  377. for(int yy=0; yy<highPrObjsVis.size(); ++yy)
  378. {
  379. SDL_Rect * sr = new SDL_Rect;
  380. sr->w = highPrObjsVis[yy].bitmap->w;
  381. sr->h = highPrObjsVis[yy].bitmap->h;
  382. sr->x = highPrObjsVis[yy].xpos - highPrObjsVis[yy].bitmap->w + 32;
  383. sr->y = highPrObjsVis[yy].ypos - highPrObjsVis[yy].bitmap->h + 32;
  384. SDL_BlitSurface(highPrObjsVis[yy].bitmap, NULL, su, sr);
  385. delete sr;
  386. }
  387. /*for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
  388. {
  389. if(CGameInfo::mainObj->objh->objInstances[gg].x >= x-3 && CGameInfo::mainObj->objh->objInstances[gg].x < dx+x-3 && CGameInfo::mainObj->objh->objInstances[gg].y >= y-3 && CGameInfo::mainObj->objh->objInstances[gg].y < dy+y-3 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
  390. {
  391. SDL_Rect * sr = new SDL_Rect;
  392. sr->w = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w;
  393. sr->h = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h;
  394. sr->x = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w + 32;
  395. sr->y = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h + 32;
  396. SDL_BlitSurface(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap, NULL, su, sr);
  397. delete sr;
  398. }
  399. }*/
  400. ////objects printed, printing shadow
  401. for (int bx=0; bx<dx; bx++)
  402. {
  403. for (int by=0; by<dy; by++)
  404. {
  405. SDL_Rect * sr = new SDL_Rect;
  406. sr->y=by*32;
  407. sr->x=bx*32;
  408. sr->h=sr->w=32;
  409. if (!level)
  410. {
  411. if( bx+x>Woff-1 && by+y>Hoff-1 && bx+x<visibility.size()-(Woff-1) && by+y<visibility[0].size()-(Hoff-1) && !visibility[bx+x][by+y])
  412. {
  413. SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibility);
  414. SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
  415. SDL_BlitSurface(hide2, NULL, su, sr);
  416. SDL_FreeSurface(hide2);
  417. }
  418. }
  419. else
  420. {
  421. if( bx+x>Woff-1 && by+y>Hoff-1 && bx+x<undVisibility.size()-(Woff-1) && by+y<undVisibility[0].size()-(Hoff-1) && !undVisibility[bx+x][by+y])
  422. {
  423. SDL_Surface * hide = getVisBitmap(bx+x, by+y, undVisibility);
  424. SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
  425. SDL_BlitSurface(hide2, NULL, su, sr);
  426. SDL_FreeSurface(hide2);
  427. }
  428. }
  429. delete sr;
  430. }
  431. }
  432. ////shadow printed
  433. //printing borders
  434. for (int bx=0; bx<dx; bx++)
  435. {
  436. for (int by=0; by<dy; by++)
  437. {
  438. if(bx+x<Woff || by+y<Hoff || bx+x>reader->map.width+(Woff-1) || by+y>reader->map.height+(Hoff-1))
  439. {
  440. SDL_Rect * sr = new SDL_Rect;
  441. sr->y=by*32;
  442. sr->x=bx*32;
  443. sr->h=sr->w=32;
  444. if (!level)
  445. {
  446. SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
  447. }
  448. else
  449. {
  450. SDL_BlitSurface(undTerrainBitmap[bx+x][by+y],NULL,su,sr);
  451. }
  452. delete sr;
  453. }
  454. }
  455. }
  456. //borders printed
  457. return su;
  458. }
  459. SDL_Surface * CMapHandler::terrBitmap(int x, int y)
  460. {
  461. return terrainBitmap[x+4][y+4];
  462. }
  463. SDL_Surface * CMapHandler::undTerrBitmap(int x, int y)
  464. {
  465. return undTerrainBitmap[x+4][y+4];
  466. }
  467. SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector<char> > & visibility)
  468. {
  469. 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])
  470. {
  471. return fullHide->ourImages[rand()%fullHide->ourImages.size()].bitmap; //fully hidden
  472. }
  473. 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])
  474. {
  475. return partialHide->ourImages[22].bitmap; //visible right bottom corner
  476. }
  477. 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])
  478. {
  479. return partialHide->ourImages[15].bitmap; //visible right top corner
  480. }
  481. 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])
  482. {
  483. return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner
  484. }
  485. 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])
  486. {
  487. return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner
  488. }
  489. 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])
  490. {
  491. //return partialHide->ourImages[rand()%2].bitmap; //visible top
  492. return partialHide->ourImages[0].bitmap; //visible top
  493. }
  494. 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])
  495. {
  496. //return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom
  497. return partialHide->ourImages[4].bitmap; //visble bottom
  498. }
  499. 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])
  500. {
  501. //return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left
  502. return CSDL_Ext::rotate01(partialHide->ourImages[2].bitmap); //visible left
  503. }
  504. 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])
  505. {
  506. //return partialHide->ourImages[2+rand()%2].bitmap; //visible right
  507. return partialHide->ourImages[2].bitmap; //visible right
  508. }
  509. else if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1])
  510. {
  511. //return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden
  512. return partialHide->ourImages[12].bitmap; //visible bottom, right - bottom, right; left top corner hidden
  513. }
  514. else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && !visibility[x-1][y+1])
  515. {
  516. return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden
  517. }
  518. else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && !visibility[x+1][y+1])
  519. {
  520. return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden
  521. }
  522. else if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && !visibility[x+1][y-1])
  523. {
  524. //return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden
  525. return CSDL_Ext::rotate01(partialHide->ourImages[12].bitmap); //visible left, left - bottom, bottom; right top corner hidden
  526. }
  527. 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])
  528. {
  529. return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top
  530. }
  531. 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])
  532. {
  533. return partialHide->ourImages[16].bitmap; //visible right corners
  534. }
  535. 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])
  536. {
  537. return partialHide->ourImages[18].bitmap; //visible top corners
  538. }
  539. 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])
  540. {
  541. return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners
  542. }
  543. 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])
  544. {
  545. return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners
  546. }
  547. 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])
  548. {
  549. return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners
  550. }
  551. 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])
  552. {
  553. return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners
  554. }
  555. 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])
  556. {
  557. return partialHide->ourImages[19].bitmap; //visible corners without left top
  558. }
  559. 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])
  560. {
  561. return partialHide->ourImages[20].bitmap; //visible corners without left bottom
  562. }
  563. 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])
  564. {
  565. return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom
  566. }
  567. 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])
  568. {
  569. return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top
  570. }
  571. 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])
  572. {
  573. return partialHide->ourImages[21].bitmap; //visible all corners only
  574. }
  575. if(visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1])
  576. {
  577. return partialHide->ourImages[6].bitmap; //hidden top
  578. }
  579. if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
  580. {
  581. return partialHide->ourImages[7].bitmap; //hidden right
  582. }
  583. if(!visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
  584. {
  585. return partialHide->ourImages[8].bitmap; //hidden bottom
  586. }
  587. if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1])
  588. {
  589. return CSDL_Ext::rotate01(partialHide->ourImages[6].bitmap); //hidden left
  590. }
  591. if(!visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
  592. {
  593. return partialHide->ourImages[9].bitmap; //hidden top and bottom
  594. }
  595. if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1])
  596. {
  597. return partialHide->ourImages[29].bitmap; //hidden left and right
  598. }
  599. 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])
  600. {
  601. return partialHide->ourImages[24].bitmap; //visible top and right bottom corner
  602. }
  603. 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])
  604. {
  605. return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner
  606. }
  607. 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])
  608. {
  609. return partialHide->ourImages[33].bitmap; //visible top and bottom corners
  610. }
  611. 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])
  612. {
  613. return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner
  614. }
  615. 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])
  616. {
  617. return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner
  618. }
  619. 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])
  620. {
  621. return partialHide->ourImages[32].bitmap; //visible left and right corners
  622. }
  623. 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])
  624. {
  625. return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner
  626. }
  627. 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])
  628. {
  629. return partialHide->ourImages[30].bitmap; //visible bottom and right top corner
  630. }
  631. 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])
  632. {
  633. return partialHide->ourImages[31].bitmap; //visible bottom and top corners
  634. }
  635. 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])
  636. {
  637. return partialHide->ourImages[25].bitmap; //visible right and left bottom corner
  638. }
  639. 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])
  640. {
  641. return partialHide->ourImages[26].bitmap; //visible right and left top corner
  642. }
  643. 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])
  644. {
  645. return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres
  646. }
  647. if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1])
  648. {
  649. return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible
  650. }
  651. else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x-1][y+1])
  652. {
  653. return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible
  654. }
  655. else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && visibility[x+1][y+1])
  656. {
  657. return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible
  658. }
  659. else if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x+1][y-1])
  660. {
  661. return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible
  662. }
  663. return fullHide->ourImages[0].bitmap; //this case should never happen, but it is better to hide too much than reveal it....
  664. }
  665. char & CMapHandler::visAccess(int x, int y)
  666. {
  667. return visibility[x+Woff][y+Hoff];
  668. }
  669. char & CMapHandler::undVisAccess(int x, int y)
  670. {
  671. return undVisibility[x+Woff][y+Hoff];
  672. }