mapHandler.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  1. /*
  2. * mapHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "mapHandler.h"
  12. #include "CBitmapHandler.h"
  13. #include "gui/CAnimation.h"
  14. #include "gui/SDL_Extensions.h"
  15. #include "CGameInfo.h"
  16. #include "../lib/mapObjects/CGHeroInstance.h"
  17. #include "../lib/mapObjects/CObjectClassesHandler.h"
  18. #include "../lib/CGameState.h"
  19. #include "../lib/CHeroHandler.h"
  20. #include "../lib/CTownHandler.h"
  21. #include "Graphics.h"
  22. #include "../lib/mapping/CMap.h"
  23. #include "CDefHandler.h"
  24. #include "../lib/CConfigHandler.h"
  25. #include "../lib/CGeneralTextHandler.h"
  26. #include "../lib/GameConstants.h"
  27. #include "../lib/CStopWatch.h"
  28. #include "CMT.h"
  29. #include "../lib/CRandomGenerator.h"
  30. #define ADVOPT (conf.go()->ac)
  31. std::string nameFromType (int typ)
  32. {
  33. switch(ETerrainType(typ))
  34. {
  35. case ETerrainType::DIRT:
  36. return std::string("DIRTTL.DEF");
  37. case ETerrainType::SAND:
  38. return std::string("SANDTL.DEF");
  39. case ETerrainType::GRASS:
  40. return std::string("GRASTL.DEF");
  41. case ETerrainType::SNOW:
  42. return std::string("SNOWTL.DEF");
  43. case ETerrainType::SWAMP:
  44. return std::string("SWMPTL.DEF");
  45. case ETerrainType::ROUGH:
  46. return std::string("ROUGTL.DEF");
  47. case ETerrainType::SUBTERRANEAN:
  48. return std::string("SUBBTL.DEF");
  49. case ETerrainType::LAVA:
  50. return std::string("LAVATL.DEF");
  51. case ETerrainType::WATER:
  52. return std::string("WATRTL.DEF");
  53. case ETerrainType::ROCK:
  54. return std::string("ROCKTL.DEF");
  55. case ETerrainType::BORDER:
  56. //TODO use me
  57. break;
  58. default:
  59. //TODO do something here
  60. break;
  61. }
  62. return std::string();
  63. }
  64. static bool objectBlitOrderSorter(const TerrainTileObject & a, const TerrainTileObject & b)
  65. {
  66. return CMapHandler::compareObjectBlitOrder(a.obj, b.obj);
  67. }
  68. struct NeighborTilesInfo
  69. {
  70. bool d7, //789
  71. d8, //456
  72. d9, //123
  73. d4,
  74. d5,
  75. d6,
  76. d1,
  77. d2,
  78. d3;
  79. NeighborTilesInfo(const int3 & pos, const int3 & sizes, const std::vector< std::vector< std::vector<ui8> > > & visibilityMap)
  80. {
  81. auto getTile = [&](int dx, int dy)->bool
  82. {
  83. if ( dx + pos.x < 0 || dx + pos.x >= sizes.x
  84. || dy + pos.y < 0 || dy + pos.y >= sizes.y)
  85. return false;
  86. return visibilityMap[dx+pos.x][dy+pos.y][pos.z];
  87. };
  88. d7 = getTile(-1, -1); //789
  89. d8 = getTile( 0, -1); //456
  90. d9 = getTile(+1, -1); //123
  91. d4 = getTile(-1, 0);
  92. d5 = visibilityMap[pos.x][pos.y][pos.z];
  93. d6 = getTile(+1, 0);
  94. d1 = getTile(-1, +1);
  95. d2 = getTile( 0, +1);
  96. d3 = getTile(+1, +1);
  97. }
  98. bool areAllHidden() const
  99. {
  100. return !(d1 || d2 || d3 || d4 || d5 || d6 || d7 || d8 || d8 );
  101. }
  102. int getBitmapID() const
  103. {
  104. //NOTE: some images have unused in VCMI pair (same blockmap but a bit different look)
  105. // 0-1, 2-3, 4-5, 11-13, 12-14
  106. static const int visBitmaps[256] = {
  107. -1, 34, 4, 4, 22, 23, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, //16
  108. 3, 25, 12, 12, 3, 25, 12, 12, 9, 9, 6, 6, 9, 9, 6, 6, //32
  109. 35, 39, 48, 48, 41, 43, 48, 48, 36, 36, 38, 38, 47, 47, 38, 38, //48
  110. 26, 49, 28, 28, 26, 49, 28, 28, 9, 9, 6, 6, 9, 9, 6, 6, //64
  111. 0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //80
  112. 13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10, //96
  113. 0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //112
  114. 13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10, //128
  115. 15, 17, 30, 30, 16, 19, 30, 30, 46, 46, 40, 40, 32, 32, 40, 40, //144
  116. 2, 25, 12, 12, 2, 25, 12, 12, 9, 9, 6, 6, 9, 9, 6, 6, //160
  117. 18, 42, 31, 31, 20, 21, 31, 31, 46, 46, 40, 40, 32, 32, 40, 40, //176
  118. 26, 49, 28, 28, 26, 49, 28, 28, 9, 9, 6, 6, 9, 9, 6, 6, //192
  119. 0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //208
  120. 13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10, //224
  121. 0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //240
  122. 13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10 //256
  123. };
  124. return visBitmaps[d1 + d2 * 2 + d3 * 4 + d4 * 8 + d6 * 16 + d7 * 32 + d8 * 64 + d9 * 128]; // >=0 -> partial hide, <0 - full hide
  125. }
  126. };
  127. void CMapHandler::prepareFOWDefs()
  128. {
  129. graphics->FoWfullHide = CDefHandler::giveDef("TSHRC.DEF");
  130. graphics->FoWpartialHide = CDefHandler::giveDef("TSHRE.DEF");
  131. //adding necessary rotations
  132. static const int missRot [] = {22, 15, 2, 13, 12, 16, 28, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27};
  133. Cimage nw;
  134. for(auto & elem : missRot)
  135. {
  136. nw = graphics->FoWpartialHide->ourImages[elem];
  137. nw.bitmap = CSDL_Ext::verticalFlip(nw.bitmap);
  138. graphics->FoWpartialHide->ourImages.push_back(nw);
  139. }
  140. //necessaary rotations added
  141. //alpha - transformation
  142. for(auto & elem : graphics->FoWpartialHide->ourImages)
  143. {
  144. CSDL_Ext::alphaTransform(elem.bitmap);
  145. }
  146. //initialization of type of full-hide image
  147. hideBitmap.resize(sizes.x);
  148. for (auto & elem : hideBitmap)
  149. {
  150. elem.resize(sizes.y);
  151. }
  152. for (auto & elem : hideBitmap)
  153. {
  154. for (int j = 0; j < sizes.y; ++j)
  155. {
  156. elem[j].resize(sizes.z);
  157. for(int k = 0; k < sizes.z; ++k)
  158. {
  159. elem[j][k] = CRandomGenerator::getDefault().nextInt(graphics->FoWfullHide->ourImages.size() - 1);
  160. }
  161. }
  162. }
  163. }
  164. EMapAnimRedrawStatus CMapHandler::drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim /* = false */)
  165. {
  166. assert(info);
  167. bool hasActiveFade = updateObjectsFade();
  168. resolveBlitter(info)->blit(targetSurface, info);
  169. return hasActiveFade ? EMapAnimRedrawStatus::REDRAW_REQUESTED : EMapAnimRedrawStatus::OK;
  170. }
  171. void CMapHandler::roadsRiverTerrainInit()
  172. {
  173. //initializing road's and river's DefHandlers
  174. roadDefs.push_back(CDefHandler::giveDefEss("dirtrd.def"));
  175. roadDefs.push_back(CDefHandler::giveDefEss("gravrd.def"));
  176. roadDefs.push_back(CDefHandler::giveDefEss("cobbrd.def"));
  177. staticRiverDefs.push_back(CDefHandler::giveDefEss("clrrvr.def"));
  178. staticRiverDefs.push_back(CDefHandler::giveDefEss("icyrvr.def"));
  179. staticRiverDefs.push_back(CDefHandler::giveDefEss("mudrvr.def"));
  180. staticRiverDefs.push_back(CDefHandler::giveDefEss("lavrvr.def"));
  181. for(auto & elem : staticRiverDefs)
  182. {
  183. for(size_t h=0; h < elem->ourImages.size(); ++h)
  184. {
  185. CSDL_Ext::alphaTransform(elem->ourImages[h].bitmap);
  186. }
  187. }
  188. for(auto & elem : roadDefs)
  189. {
  190. for(size_t h=0; h < elem->ourImages.size(); ++h)
  191. {
  192. CSDL_Ext::alphaTransform(elem->ourImages[h].bitmap);
  193. }
  194. }
  195. // Create enough room for the whole map and its frame
  196. ttiles.resize(sizes.x, frameW, frameW);
  197. for (int i=0-frameW;i<ttiles.size()-frameW;i++)
  198. {
  199. ttiles[i].resize(sizes.y, frameH, frameH);
  200. }
  201. for (int i=0-frameW;i<ttiles.size()-frameW;i++)
  202. {
  203. for (int j=0-frameH;j<(int)sizes.y+frameH;j++)
  204. ttiles[i][j].resize(sizes.z, 0, 0);
  205. }
  206. }
  207. void CMapHandler::borderAndTerrainBitmapInit()
  208. {
  209. CDefHandler * bord = CDefHandler::giveDef("EDG.DEF");
  210. bord->notFreeImgs = true;
  211. terrainGraphics.resize(10);
  212. for (int i = 0; i < 10 ; i++)
  213. {
  214. CDefHandler *hlp = CDefHandler::giveDef(nameFromType(i));
  215. terrainGraphics[i].resize(hlp->ourImages.size());
  216. hlp->notFreeImgs = true;
  217. for(size_t j=0; j < hlp->ourImages.size(); ++j)
  218. terrainGraphics[i][j] = hlp->ourImages[j].bitmap;
  219. delete hlp;
  220. }
  221. for (int i=0-frameW; i<sizes.x+frameW; i++) //by width
  222. {
  223. for (int j=0-frameH; j<sizes.y+frameH;j++) //by height
  224. {
  225. for(int k=0; k<sizes.z; ++k) //by levles
  226. {
  227. if(i < 0 || i > (sizes.x-1) || j < 0 || j > (sizes.y-1))
  228. {
  229. int terBitmapNum = -1;
  230. auto & rand = CRandomGenerator::getDefault();
  231. if(i==-1 && j==-1)
  232. terBitmapNum = 16;
  233. else if(i==-1 && j==(sizes.y))
  234. terBitmapNum = 19;
  235. else if(i==(sizes.x) && j==-1)
  236. terBitmapNum = 17;
  237. else if(i==(sizes.x) && j==(sizes.y))
  238. terBitmapNum = 18;
  239. else if(j == -1 && i > -1 && i < sizes.x)
  240. terBitmapNum = rand.nextInt(22, 23);
  241. else if(i == -1 && j > -1 && j < sizes.y)
  242. terBitmapNum = rand.nextInt(33, 34);
  243. else if(j == sizes.y && i >-1 && i < sizes.x)
  244. terBitmapNum = rand.nextInt(29, 30);
  245. else if(i == sizes.x && j > -1 && j < sizes.y)
  246. terBitmapNum = rand.nextInt(25, 26);
  247. else
  248. terBitmapNum = rand.nextInt(15);
  249. if(terBitmapNum != -1)
  250. {
  251. ttiles[i][j][k].terbitmap = bord->ourImages[terBitmapNum].bitmap;
  252. continue;
  253. }
  254. }
  255. }
  256. }
  257. }
  258. delete bord;
  259. }
  260. static void processDef (const ObjectTemplate & objTempl)
  261. {
  262. if(objTempl.id == Obj::EVENT)
  263. {
  264. graphics->advmapobjGraphics[objTempl.animationFile] = nullptr;
  265. return;
  266. }
  267. CDefEssential * ourDef = graphics->getDef(objTempl);
  268. if(!ourDef) //if object has already set handler (eg. heroes) it should not be overwritten
  269. {
  270. if(objTempl.animationFile.size())
  271. {
  272. graphics->advmapobjGraphics[objTempl.animationFile] = CDefHandler::giveDefEss(objTempl.animationFile);
  273. }
  274. else
  275. {
  276. logGlobal->warnStream() << "No def name for " << objTempl.id << " " << objTempl.subid;
  277. return;
  278. }
  279. ourDef = graphics->getDef(objTempl);
  280. }
  281. //alpha transformation
  282. for(auto & elem : ourDef->ourImages)
  283. {
  284. CSDL_Ext::alphaTransform(elem.bitmap);
  285. }
  286. }
  287. void CMapHandler::initObjectRects()
  288. {
  289. //initializing objects / rects
  290. for(auto & elem : map->objects)
  291. {
  292. const CGObjectInstance *obj = elem;
  293. if( !obj
  294. || (obj->ID==Obj::HERO && static_cast<const CGHeroInstance*>(obj)->inTownGarrison) //garrisoned hero
  295. || (obj->ID==Obj::BOAT && static_cast<const CGBoat*>(obj)->hero)) //boat with hero (hero graphics is used)
  296. {
  297. continue;
  298. }
  299. if (!graphics->getDef(obj)) //try to load it
  300. processDef(obj->appearance);
  301. if (!graphics->getDef(obj)) // stil no graphics? exit
  302. continue;
  303. const SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap;
  304. for(int fx=0; fx < obj->getWidth(); ++fx)
  305. {
  306. for(int fy=0; fy < obj->getHeight(); ++fy)
  307. {
  308. int3 currTile(obj->pos.x - fx, obj->pos.y - fy, obj->pos.z);
  309. SDL_Rect cr;
  310. cr.w = 32;
  311. cr.h = 32;
  312. cr.x = bitmap->w - fx * 32 - 32;
  313. cr.y = bitmap->h - fy * 32 - 32;
  314. TerrainTileObject toAdd(obj,cr);
  315. if( map->isInTheMap(currTile) && // within map
  316. cr.x + cr.w > 0 && // image has data on this tile
  317. cr.y + cr.h > 0 &&
  318. obj->coveringAt(currTile.x, currTile.y) // object is visible here
  319. )
  320. {
  321. ttiles[currTile.x][currTile.y][currTile.z].objects.push_back(toAdd);
  322. }
  323. }
  324. }
  325. }
  326. for(int ix=0; ix<ttiles.size()-frameW; ++ix)
  327. {
  328. for(int iy=0; iy<ttiles[0].size()-frameH; ++iy)
  329. {
  330. for(int iz=0; iz<ttiles[0][0].size(); ++iz)
  331. {
  332. stable_sort(ttiles[ix][iy][iz].objects.begin(), ttiles[ix][iy][iz].objects.end(), objectBlitOrderSorter);
  333. }
  334. }
  335. }
  336. }
  337. void CMapHandler::init()
  338. {
  339. CStopWatch th;
  340. th.getDiff();
  341. graphics->advmapobjGraphics["AB01_.DEF"] = graphics->boatAnims[0];
  342. graphics->advmapobjGraphics["AB02_.DEF"] = graphics->boatAnims[1];
  343. graphics->advmapobjGraphics["AB03_.DEF"] = graphics->boatAnims[2];
  344. // Size of visible terrain.
  345. int mapW = conf.go()->ac.advmapW;
  346. int mapH = conf.go()->ac.advmapH;
  347. //sizes of terrain
  348. sizes.x = map->width;
  349. sizes.y = map->height;
  350. sizes.z = map->twoLevel ? 2 : 1;
  351. // Total number of visible tiles. Subtract the center tile, then
  352. // compute the number of tiles on each side, and reassemble.
  353. int t1, t2;
  354. t1 = (mapW-32)/2;
  355. t2 = mapW - 32 - t1;
  356. tilesW = 1 + (t1+31)/32 + (t2+31)/32;
  357. t1 = (mapH-32)/2;
  358. t2 = mapH - 32 - t1;
  359. tilesH = 1 + (t1+31)/32 + (t2+31)/32;
  360. // Size of the frame around the map. In extremes positions, the
  361. // frame must not be on the center of the map, but right on the
  362. // edge of the center tile.
  363. frameW = (mapW+31) /32 / 2;
  364. frameH = (mapH+31) /32 / 2;
  365. offsetX = (mapW - (2*frameW+1)*32)/2;
  366. offsetY = (mapH - (2*frameH+1)*32)/2;
  367. prepareFOWDefs();
  368. roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
  369. borderAndTerrainBitmapInit();
  370. logGlobal->infoStream()<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDiff();
  371. initObjectRects();
  372. logGlobal->infoStream()<<"\tMaking object rects: "<<th.getDiff();
  373. }
  374. CMapHandler::CMapBlitter *CMapHandler::resolveBlitter(const MapDrawingInfo * info) const
  375. {
  376. if (info->scaled)
  377. return worldViewBlitter;
  378. if (info->puzzleMode)
  379. return puzzleViewBlitter;
  380. return normalBlitter;
  381. }
  382. void CMapHandler::CMapNormalBlitter::drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit, ui8 rotationInfo) const
  383. {
  384. if (rotationInfo != 0)
  385. {
  386. if (!sourceRect)
  387. {
  388. Rect sourceRect2(0, 0, sourceSurf->w, sourceSurf->h);
  389. if (alphaBlit)
  390. CSDL_Ext::getBlitterWithRotationAndAlpha(targetSurf)(sourceSurf, sourceRect2, targetSurf, *destRect, rotationInfo);
  391. else
  392. CSDL_Ext::getBlitterWithRotation(targetSurf)(sourceSurf, sourceRect2, targetSurf, *destRect, rotationInfo);
  393. }
  394. else
  395. {
  396. if (alphaBlit)
  397. CSDL_Ext::getBlitterWithRotationAndAlpha(targetSurf)(sourceSurf, *sourceRect, targetSurf, *destRect, rotationInfo);
  398. else
  399. CSDL_Ext::getBlitterWithRotation(targetSurf)(sourceSurf, *sourceRect, targetSurf, *destRect, rotationInfo);
  400. }
  401. }
  402. else
  403. {
  404. if (alphaBlit)
  405. CSDL_Ext::blit8bppAlphaTo24bpp(sourceSurf, sourceRect, targetSurf, destRect);
  406. else
  407. CSDL_Ext::blitSurface(sourceSurf, sourceRect, targetSurf, destRect);
  408. }
  409. }
  410. void CMapHandler::CMapNormalBlitter::init(const MapDrawingInfo * drawingInfo)
  411. {
  412. info = drawingInfo;
  413. // Width and height of the portion of the map to process. Units in tiles.
  414. tileCount.x = parent->tilesW;
  415. tileCount.y = parent->tilesH;
  416. topTile = info->topTile;
  417. initPos.x = parent->offsetX + info->drawBounds->x;
  418. initPos.y = parent->offsetY + info->drawBounds->y;
  419. realTileRect = Rect(initPos.x, initPos.y, tileSize, tileSize);
  420. // If moving, we need to add an extra column/line
  421. if (info->movement.x != 0)
  422. {
  423. tileCount.x++;
  424. initPos.x += info->movement.x;
  425. if (info->movement.x > 0)
  426. {
  427. // Moving right. We still need to draw the old tile on the
  428. // left, so adjust our referential
  429. topTile.x--;
  430. initPos.x -= tileSize;
  431. }
  432. }
  433. if (info->movement.y != 0)
  434. {
  435. tileCount.y++;
  436. initPos.y += info->movement.y;
  437. if (info->movement.y > 0)
  438. {
  439. // Moving down. We still need to draw the tile on the top,
  440. // so adjust our referential.
  441. topTile.y--;
  442. initPos.y -= tileSize;
  443. }
  444. }
  445. // Reduce sizes if we go out of the full map.
  446. if (topTile.x < -parent->frameW)
  447. topTile.x = -parent->frameW;
  448. if (topTile.y < -parent->frameH)
  449. topTile.y = -parent->frameH;
  450. if (topTile.x + tileCount.x > parent->sizes.x + parent->frameW)
  451. tileCount.x = parent->sizes.x + parent->frameW - topTile.x;
  452. if (topTile.y + tileCount.y > parent->sizes.y + parent->frameH)
  453. tileCount.y = parent->sizes.y + parent->frameH - topTile.y;
  454. }
  455. SDL_Rect CMapHandler::CMapNormalBlitter::clip(SDL_Surface * targetSurf) const
  456. {
  457. SDL_Rect prevClip;
  458. SDL_GetClipRect(targetSurf, &prevClip);
  459. SDL_SetClipRect(targetSurf, info->drawBounds);
  460. return prevClip;
  461. }
  462. CMapHandler::CMapNormalBlitter::CMapNormalBlitter(CMapHandler * parent)
  463. : CMapBlitter(parent)
  464. {
  465. tileSize = 32;
  466. halfTileSizeCeil = 16;
  467. defaultTileRect = Rect(0, 0, tileSize, tileSize);
  468. }
  469. void CMapHandler::CMapWorldViewBlitter::calculateWorldViewCameraPos()
  470. {
  471. bool outsideLeft = topTile.x < 0;
  472. bool outsideTop = topTile.y < 0;
  473. bool outsideRight = std::max(0, topTile.x) + tileCount.x > parent->sizes.x;
  474. bool outsideBottom = std::max(0, topTile.y) + tileCount.y > parent->sizes.y;
  475. if (tileCount.x > parent->sizes.x)
  476. topTile.x = parent->sizes.x / 2 - tileCount.x / 2; // center viewport if the whole map can fit into the screen at once
  477. else if (outsideLeft)
  478. {
  479. if (outsideRight)
  480. topTile.x = parent->sizes.x / 2 - tileCount.x / 2;
  481. else
  482. topTile.x = 0;
  483. }
  484. else if (outsideRight)
  485. topTile.x = parent->sizes.x - tileCount.x;
  486. if (tileCount.y > parent->sizes.y)
  487. topTile.y = parent->sizes.y / 2 - tileCount.y / 2;
  488. else if (outsideTop)
  489. {
  490. if (outsideBottom)
  491. topTile.y = parent->sizes.y / 2 - tileCount.y / 2;
  492. else
  493. topTile.y = 0;
  494. }
  495. else if (outsideBottom)
  496. topTile.y = parent->sizes.y - tileCount.y;
  497. }
  498. void CMapHandler::CMapWorldViewBlitter::drawScaledRotatedElement(EMapCacheType type, SDL_Surface * baseSurf, SDL_Surface * targetSurf, ui8 rotation,
  499. float scale, SDL_Rect * dstRect, SDL_Rect * srcRect /*= nullptr*/) const
  500. {
  501. auto key = parent->cache.genKey((intptr_t)baseSurf, rotation);
  502. auto scaledSurf = parent->cache.requestWorldViewCache(type, key);
  503. if (scaledSurf) // blitting from cache
  504. {
  505. if (srcRect)
  506. {
  507. dstRect->w = srcRect->w;
  508. dstRect->h = srcRect->h;
  509. }
  510. CSDL_Ext::blitSurface(scaledSurf, srcRect, targetSurf, dstRect);
  511. }
  512. else // creating new
  513. {
  514. auto baseSurfRotated = CSDL_Ext::newSurface(baseSurf->w, baseSurf->h);
  515. if (!baseSurfRotated)
  516. return;
  517. Rect baseRect(0, 0, baseSurf->w, baseSurf->h);
  518. CSDL_Ext::getBlitterWithRotationAndAlpha(targetSurf)(baseSurf, baseRect, baseSurfRotated, baseRect, rotation);
  519. SDL_Surface * scaledSurf2 = CSDL_Ext::scaleSurfaceFast(baseSurfRotated, baseSurf->w * scale, baseSurf->h * scale);
  520. CSDL_Ext::blitSurface(scaledSurf2, srcRect, targetSurf, dstRect);
  521. parent->cache.cacheWorldViewEntry(type, key, scaledSurf2);
  522. }
  523. }
  524. void CMapHandler::CMapWorldViewBlitter::drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit, ui8 rotationInfo) const
  525. {
  526. if (rotationInfo != 0)
  527. {
  528. drawScaledRotatedElement(cacheType, sourceSurf, targetSurf, rotationInfo, info->scale, destRect, sourceRect);
  529. }
  530. else
  531. {
  532. auto scaledSurf = parent->cache.requestWorldViewCacheOrCreate(cacheType, (intptr_t) sourceSurf, sourceSurf, info->scale);
  533. if (alphaBlit)
  534. CSDL_Ext::blit8bppAlphaTo24bpp(scaledSurf, sourceRect, targetSurf, destRect);
  535. else
  536. CSDL_Ext::blitSurface(scaledSurf, sourceRect, targetSurf, destRect);
  537. }
  538. }
  539. void CMapHandler::CMapWorldViewBlitter::drawTileOverlay(SDL_Surface * targetSurf, const TerrainTile2 & tile) const
  540. {
  541. auto & objects = tile.objects;
  542. for(auto & object : objects)
  543. {
  544. const CGObjectInstance * obj = object.obj;
  545. if (obj->pos.z != pos.z)
  546. continue;
  547. if (!(*info->visibilityMap)[pos.x][pos.y][pos.z])
  548. continue; // TODO needs to skip this check if we have view-air-like spell cast
  549. if (!obj->visitableAt(pos.x, pos.y))
  550. continue;
  551. auto &ownerRaw = obj->tempOwner;
  552. int ownerIndex = 0;
  553. if (ownerRaw < PlayerColor::PLAYER_LIMIT)
  554. {
  555. ownerIndex = ownerRaw.getNum() * 19;
  556. }
  557. else if (ownerRaw == PlayerColor::NEUTRAL)
  558. {
  559. ownerIndex = PlayerColor::PLAYER_LIMIT.getNum() * 19;
  560. }
  561. SDL_Surface * wvIcon = nullptr;
  562. switch (obj->ID)
  563. {
  564. default:
  565. continue;
  566. case Obj::MONOLITH_ONE_WAY_ENTRANCE:
  567. case Obj::MONOLITH_ONE_WAY_EXIT:
  568. case Obj::MONOLITH_TWO_WAY:
  569. wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TELEPORT].bitmap;
  570. break;
  571. case Obj::SUBTERRANEAN_GATE:
  572. wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::GATE].bitmap;
  573. break;
  574. case Obj::ARTIFACT:
  575. wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::ARTIFACT].bitmap;
  576. break;
  577. case Obj::TOWN:
  578. wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TOWN + ownerIndex].bitmap;
  579. break;
  580. case Obj::HERO:
  581. wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::HERO + ownerIndex].bitmap;
  582. break;
  583. case Obj::MINE:
  584. wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::MINE_WOOD + obj->subID + ownerIndex].bitmap;
  585. break;
  586. case Obj::RESOURCE:
  587. wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::RES_WOOD + obj->subID + ownerIndex].bitmap;
  588. break;
  589. }
  590. if (wvIcon)
  591. {
  592. // centering icon on the object
  593. Rect destRect(realPos.x + tileSize / 2 - wvIcon->w / 2, realPos.y + tileSize / 2 - wvIcon->h / 2, wvIcon->w, wvIcon->h);
  594. CSDL_Ext::blitSurface(wvIcon, nullptr, targetSurf, &destRect);
  595. }
  596. }
  597. }
  598. void CMapHandler::CMapWorldViewBlitter::drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const
  599. {
  600. if (moving)
  601. return;
  602. CMapBlitter::drawHeroFlag(targetSurf, sourceSurf, sourceRect, destRect, false);
  603. }
  604. void CMapHandler::CMapWorldViewBlitter::drawObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const
  605. {
  606. if (moving)
  607. return;
  608. Rect scaledSourceRect(sourceRect->x * info->scale, sourceRect->y * info->scale, sourceRect->w, sourceRect->h);
  609. CMapBlitter::drawObject(targetSurf, sourceSurf, &scaledSourceRect, false);
  610. }
  611. void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile2 & tile) const
  612. {
  613. Rect destRect(realTileRect);
  614. if(tile.terbitmap) //if custom terrain graphic - use it
  615. drawElement(EMapCacheType::TERRAIN_CUSTOM, tile.terbitmap, nullptr, targetSurf, &destRect);
  616. else //use default terrain graphic
  617. drawElement(EMapCacheType::TERRAIN, parent->terrainGraphics[tinfo.terType][tinfo.terView],
  618. nullptr, targetSurf, &destRect, false, tinfo.extTileFlags % 4);
  619. }
  620. void CMapHandler::CMapWorldViewBlitter::init(const MapDrawingInfo * drawingInfo)
  621. {
  622. info = drawingInfo;
  623. parent->cache.updateWorldViewScale(info->scale);
  624. topTile = info->topTile;
  625. tileSize = (int) floorf(32.0f * info->scale);
  626. halfTileSizeCeil = (int)ceilf(tileSize / 2.0f);
  627. tileCount.x = (int) ceilf((float)info->drawBounds->w / tileSize);
  628. tileCount.y = (int) ceilf((float)info->drawBounds->h / tileSize);
  629. initPos.x = info->drawBounds->x;
  630. initPos.y = info->drawBounds->y;
  631. realTileRect = Rect(initPos.x, initPos.y, tileSize, tileSize);
  632. defaultTileRect = Rect(0, 0, tileSize, tileSize);
  633. calculateWorldViewCameraPos();
  634. }
  635. SDL_Rect CMapHandler::CMapWorldViewBlitter::clip(SDL_Surface * targetSurf) const
  636. {
  637. SDL_Rect prevClip;
  638. SDL_FillRect(targetSurf, info->drawBounds, SDL_MapRGB(targetSurf->format, 0, 0, 0));
  639. // makes the clip area smaller if the map is smaller than the screen frame
  640. // (actually, it could be made 1 tile bigger so that overlay icons on edge tiles could be drawn partly outside)
  641. Rect clipRect(std::max<int>(info->drawBounds->x, info->drawBounds->x - topTile.x * tileSize),
  642. std::max<int>(info->drawBounds->y, info->drawBounds->y - topTile.y * tileSize),
  643. std::min<int>(info->drawBounds->w, parent->sizes.x * tileSize),
  644. std::min<int>(info->drawBounds->h, parent->sizes.y * tileSize));
  645. SDL_GetClipRect(targetSurf, &prevClip);
  646. SDL_SetClipRect(targetSurf, &clipRect); //preventing blitting outside of that rect
  647. return prevClip;
  648. }
  649. CMapHandler::CMapWorldViewBlitter::CMapWorldViewBlitter(CMapHandler * parent)
  650. : CMapBlitter(parent)
  651. {
  652. }
  653. void CMapHandler::CMapPuzzleViewBlitter::drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const
  654. {
  655. CMapBlitter::drawObjects(targetSurf, tile);
  656. // grail X mark
  657. if(pos.x == info->grailPos.x && pos.y == info->grailPos.y)
  658. {
  659. Rect destRect(realTileRect);
  660. CSDL_Ext::blit8bppAlphaTo24bpp(graphics->heroMoveArrows->ourImages[0].bitmap, nullptr, targetSurf, &destRect);
  661. }
  662. }
  663. void CMapHandler::CMapPuzzleViewBlitter::postProcessing(SDL_Surface * targetSurf) const
  664. {
  665. CSDL_Ext::applyEffect(targetSurf, info->drawBounds, static_cast<int>(!ADVOPT.puzzleSepia));
  666. }
  667. bool CMapHandler::CMapPuzzleViewBlitter::canDrawObject(const CGObjectInstance * obj) const
  668. {
  669. if (!CMapBlitter::canDrawObject(obj))
  670. return false;
  671. //don't print flaggable objects in puzzle mode
  672. if (obj->isVisitable())
  673. return false;
  674. if(std::find(unblittableObjects.begin(), unblittableObjects.end(), obj->ID) != unblittableObjects.end())
  675. return false;
  676. return true;
  677. }
  678. CMapHandler::CMapPuzzleViewBlitter::CMapPuzzleViewBlitter(CMapHandler * parent)
  679. : CMapNormalBlitter(parent)
  680. {
  681. unblittableObjects.push_back(Obj::HOLE);
  682. }
  683. void CMapHandler::CMapBlitter::drawFrame(SDL_Surface * targetSurf) const
  684. {
  685. Rect destRect(realTileRect);
  686. drawElement(EMapCacheType::FRAME, parent->ttiles[pos.x][pos.y][topTile.z].terbitmap, nullptr, targetSurf, &destRect);
  687. }
  688. void CMapHandler::CMapBlitter::drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const
  689. {
  690. drawElement(EMapCacheType::HERO_FLAGS, sourceSurf, sourceRect, targetSurf, destRect, false);
  691. }
  692. void CMapHandler::CMapBlitter::drawObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const
  693. {
  694. Rect dstRect(realTileRect);
  695. drawElement(EMapCacheType::OBJECTS, sourceSurf, sourceRect, targetSurf, &dstRect, true);
  696. }
  697. void CMapHandler::CMapBlitter::drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const
  698. {
  699. auto & objects = tile.objects;
  700. for(auto & object : objects)
  701. {
  702. if (object.fadeAnimKey >= 0)
  703. {
  704. auto fadeIter = parent->fadeAnims.find(object.fadeAnimKey);
  705. if (fadeIter != parent->fadeAnims.end())
  706. {
  707. // this object is currently fading, so skip normal drawing
  708. Rect r2(realTileRect);
  709. CFadeAnimation * fade = (*fadeIter).second.second;
  710. fade->draw(targetSurf, nullptr, &r2);
  711. continue;
  712. }
  713. logGlobal->errorStream() << "Fading map object with missing fade anim : " << object.fadeAnimKey;
  714. continue;
  715. }
  716. const CGObjectInstance * obj = object.obj;
  717. if (!obj)
  718. {
  719. logGlobal->errorStream() << "Stray map object that isn't fading";
  720. continue;
  721. }
  722. if (!graphics->getDef(obj))
  723. processDef(obj->appearance);
  724. if (!graphics->getDef(obj) && !obj->appearance.animationFile.empty())
  725. logGlobal->errorStream() << "Failed to load image " << obj->appearance.animationFile;
  726. if (!canDrawObject(obj))
  727. continue;
  728. auto objData = findObjectBitmap(obj, info->anim);
  729. if (objData.objBitmap)
  730. {
  731. Rect srcRect(object.rect.x, object.rect.y, tileSize, tileSize);
  732. drawObject(targetSurf, objData.objBitmap, &srcRect, objData.isMoving);
  733. if (objData.flagBitmap)
  734. {
  735. if (objData.isMoving)
  736. {
  737. srcRect.y += FRAMES_PER_MOVE_ANIM_GROUP * 2 - tileSize;
  738. Rect dstRect(realPos.x, realPos.y - tileSize / 2, tileSize, tileSize);
  739. drawHeroFlag(targetSurf, objData.flagBitmap, &srcRect, &dstRect, true);
  740. }
  741. else if (obj->pos.x == pos.x && obj->pos.y == pos.y)
  742. {
  743. Rect dstRect(realPos.x - 2 * tileSize, realPos.y - tileSize, 3 * tileSize, 2 * tileSize);
  744. drawHeroFlag(targetSurf, objData.flagBitmap, nullptr, &dstRect, false);
  745. }
  746. }
  747. }
  748. }
  749. }
  750. void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const
  751. {
  752. if (tinfoUpper && tinfoUpper->roadType != ERoadType::NO_ROAD)
  753. {
  754. Rect source(0, tileSize / 2, tileSize, tileSize / 2);
  755. Rect dest(realPos.x, realPos.y, tileSize, tileSize / 2);
  756. drawElement(EMapCacheType::ROADS, parent->roadDefs[tinfoUpper->roadType - 1]->ourImages[tinfoUpper->roadDir].bitmap,
  757. &source, targetSurf, &dest, true, (tinfoUpper->extTileFlags >> 4) % 4);
  758. }
  759. if(tinfo.roadType != ERoadType::NO_ROAD) //print road from this tile
  760. {
  761. Rect source(0, 0, tileSize, halfTileSizeCeil);
  762. Rect dest(realPos.x, realPos.y + tileSize / 2, tileSize, tileSize / 2);
  763. drawElement(EMapCacheType::ROADS, parent->roadDefs[tinfo.roadType - 1]->ourImages[tinfo.roadDir].bitmap,
  764. &source, targetSurf, &dest, true, (tinfo.extTileFlags >> 4) % 4);
  765. }
  766. }
  767. void CMapHandler::CMapBlitter::drawRiver(SDL_Surface * targetSurf, const TerrainTile & tinfo) const
  768. {
  769. Rect destRect(realTileRect);
  770. drawElement(EMapCacheType::RIVERS, parent->staticRiverDefs[tinfo.riverType-1]->ourImages[tinfo.riverDir].bitmap,
  771. nullptr, targetSurf, &destRect, true, (tinfo.extTileFlags >> 2) % 4);
  772. }
  773. void CMapHandler::CMapBlitter::drawFow(SDL_Surface * targetSurf) const
  774. {
  775. Rect destRect(realTileRect);
  776. std::pair<SDL_Surface *, bool> hide = getVisBitmap();
  777. drawElement(EMapCacheType::FOW, hide.first, nullptr, targetSurf, &destRect, hide.second);
  778. }
  779. void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingInfo * info)
  780. {
  781. init(info);
  782. auto prevClip = clip(targetSurf);
  783. pos = int3(0, 0, topTile.z);
  784. for (realPos.x = initPos.x, pos.x = topTile.x; pos.x < topTile.x + tileCount.x; pos.x++, realPos.x += tileSize)
  785. {
  786. if (pos.x < 0 || pos.x >= parent->sizes.x)
  787. continue;
  788. for (realPos.y = initPos.y, pos.y = topTile.y; pos.y < topTile.y + tileCount.y; pos.y++, realPos.y += tileSize)
  789. {
  790. if (pos.y < 0 || pos.y >= parent->sizes.y)
  791. continue;
  792. if (!canDrawCurrentTile())
  793. continue;
  794. realTileRect.x = realPos.x;
  795. realTileRect.y = realPos.y;
  796. const TerrainTile2 & tile = parent->ttiles[pos.x][pos.y][pos.z];
  797. const TerrainTile & tinfo = parent->map->getTile(pos);
  798. const TerrainTile * tinfoUpper = pos.y > 0 ? &parent->map->getTile(int3(pos.x, pos.y - 1, pos.z)) : nullptr;
  799. drawTileTerrain(targetSurf, tinfo, tile);
  800. if (tinfo.riverType)
  801. drawRiver(targetSurf, tinfo);
  802. drawRoad(targetSurf, tinfo, tinfoUpper);
  803. drawObjects(targetSurf, tile);
  804. }
  805. }
  806. for (realPos.x = initPos.x, pos.x = topTile.x; pos.x < topTile.x + tileCount.x; pos.x++, realPos.x += tileSize)
  807. {
  808. for (realPos.y = initPos.y, pos.y = topTile.y; pos.y < topTile.y + tileCount.y; pos.y++, realPos.y += tileSize)
  809. {
  810. realTileRect.x = realPos.x;
  811. realTileRect.y = realPos.y;
  812. if (pos.x < 0 || pos.x >= parent->sizes.x ||
  813. pos.y < 0 || pos.y >= parent->sizes.y)
  814. {
  815. drawFrame(targetSurf);
  816. }
  817. else
  818. {
  819. const TerrainTile2 & tile = parent->ttiles[pos.x][pos.y][pos.z];
  820. if (!(*info->visibilityMap)[pos.x][pos.y][topTile.z])
  821. drawFow(targetSurf);
  822. // overlay needs to be drawn over fow, because of artifacts-aura-like spells
  823. drawTileOverlay(targetSurf, tile);
  824. // drawDebugVisitables()
  825. if (settings["session"]["showBlock"].Bool())
  826. {
  827. if(parent->map->getTile(int3(pos.x, pos.y, pos.z)).blocked) //temporary hiding blocked positions
  828. {
  829. static SDL_Surface * block = nullptr;
  830. if (!block)
  831. block = BitmapHandler::loadBitmap("blocked");
  832. CSDL_Ext::blitSurface(block, nullptr, targetSurf, &realTileRect);
  833. }
  834. }
  835. if (settings["session"]["showVisit"].Bool())
  836. {
  837. if(parent->map->getTile(int3(pos.x, pos.y, pos.z)).visitable) //temporary hiding visitable positions
  838. {
  839. static SDL_Surface * visit = nullptr;
  840. if (!visit)
  841. visit = BitmapHandler::loadBitmap("visitable");
  842. CSDL_Ext::blitSurface(visit, nullptr, targetSurf, &realTileRect);
  843. }
  844. }
  845. }
  846. }
  847. }
  848. // drawDebugGrid()
  849. if (settings["session"]["showGrid"].Bool())
  850. {
  851. for (realPos.x = initPos.x, pos.x = topTile.x; pos.x < topTile.x + tileCount.x; pos.x++, realPos.x += tileSize)
  852. {
  853. for (realPos.y = initPos.y, pos.y = topTile.y; pos.y < topTile.y + tileCount.y; pos.y++, realPos.y += tileSize)
  854. {
  855. const int3 color(0x555555, 0x555555, 0x555555);
  856. if (realPos.y >= info->drawBounds->y &&
  857. realPos.y < info->drawBounds->y + info->drawBounds->h)
  858. for(int i = 0; i < tileSize; i++)
  859. if (realPos.x + i >= info->drawBounds->x &&
  860. realPos.x + i < info->drawBounds->x + info->drawBounds->w)
  861. CSDL_Ext::SDL_PutPixelWithoutRefresh(targetSurf, realPos.x + i, realPos.y, color.x, color.y, color.z);
  862. if (realPos.x >= info->drawBounds->x &&
  863. realPos.x < info->drawBounds->x + info->drawBounds->w)
  864. for(int i = 0; i < tileSize; i++)
  865. if (realPos.y + i >= info->drawBounds->y &&
  866. realPos.y + i < info->drawBounds->y + info->drawBounds->h)
  867. CSDL_Ext::SDL_PutPixelWithoutRefresh(targetSurf, realPos.x, realPos.y + i, color.x, color.y, color.z);
  868. }
  869. }
  870. }
  871. postProcessing(targetSurf);
  872. SDL_SetClipRect(targetSurf, &prevClip);
  873. }
  874. CMapHandler::AnimBitmapHolder CMapHandler::CMapBlitter::findHeroBitmap(const CGHeroInstance * hero, int anim) const
  875. {
  876. if(hero && hero->moveDir && hero->type) //it's hero or boat
  877. {
  878. if(hero->tempOwner >= PlayerColor::PLAYER_LIMIT) //Neutral hero?
  879. {
  880. logGlobal->errorStream() << "A neutral hero (" << hero->name << ") at " << hero->pos << ". Should not happen!";
  881. return CMapHandler::AnimBitmapHolder();
  882. }
  883. //pick graphics of hero (or boat if hero is sailing)
  884. CDefEssential * def = nullptr;
  885. if (hero->boat)
  886. def = graphics->boatAnims[hero->boat->subID];
  887. else
  888. def = graphics->heroAnims[hero->appearance.animationFile];
  889. bool moving = !hero->isStanding;
  890. int framesOffset = moving ? anim % FRAMES_PER_MOVE_ANIM_GROUP : 0;
  891. int index = findAnimIndexByGroup(def, getHeroFrameNum(hero->moveDir, moving));
  892. if (index >= 0)
  893. {
  894. auto heroBitmap = def->ourImages[index + framesOffset].bitmap;
  895. auto flagBitmap = findFlagBitmap(hero, anim, &hero->tempOwner, index + 35);
  896. return CMapHandler::AnimBitmapHolder(heroBitmap, flagBitmap, moving);
  897. }
  898. }
  899. return CMapHandler::AnimBitmapHolder();
  900. }
  901. CMapHandler::AnimBitmapHolder CMapHandler::CMapBlitter::findBoatBitmap(const CGBoat * boat, int anim) const
  902. {
  903. auto def = graphics->boatAnims[boat->subID];
  904. int index = findAnimIndexByGroup(def, getHeroFrameNum(boat->direction, false));
  905. if (index < 0)
  906. return CMapHandler::AnimBitmapHolder();
  907. return CMapHandler::AnimBitmapHolder(def->ourImages[index].bitmap);
  908. }
  909. SDL_Surface * CMapHandler::CMapBlitter::findFlagBitmap(const CGHeroInstance * hero, int anim, const PlayerColor * color, int indexOffset) const
  910. {
  911. if (!hero)
  912. return nullptr;
  913. if (hero->boat)
  914. return findBoatFlagBitmap(hero->boat, anim, color, indexOffset, hero->moveDir);
  915. return findHeroFlagBitmap(hero, anim, color, indexOffset);
  916. }
  917. SDL_Surface * CMapHandler::CMapBlitter::findHeroFlagBitmap(const CGHeroInstance * hero, int anim, const PlayerColor * color, int indexOffset) const
  918. {
  919. return findFlagBitmapInternal(graphics->flags4[color->getNum()], anim, indexOffset, hero->moveDir, !hero->isStanding);
  920. }
  921. SDL_Surface * CMapHandler::CMapBlitter::findBoatFlagBitmap(const CGBoat * boat, int anim, const PlayerColor * color, int indexOffset, ui8 dir) const
  922. {
  923. std::vector<CDefEssential *> Graphics::*flg = nullptr;
  924. switch (boat->subID)
  925. {
  926. case 0: flg = &Graphics::flags1; break;
  927. case 1: flg = &Graphics::flags2; break;
  928. case 2: flg = &Graphics::flags3; break;
  929. default: logGlobal->errorStream() << "Not supported boat subtype: " << boat->subID; return nullptr;
  930. }
  931. return findFlagBitmapInternal((graphics->*flg)[color->getNum()], anim, indexOffset, dir, false);
  932. }
  933. SDL_Surface * CMapHandler::CMapBlitter::findFlagBitmapInternal(const CDefEssential * def, int anim, int indexOffset, ui8 dir, bool moving) const
  934. {
  935. if (moving)
  936. return def->ourImages[indexOffset + anim % FRAMES_PER_MOVE_ANIM_GROUP].bitmap;
  937. return def->ourImages[getHeroFrameNum(dir, false) * FRAMES_PER_MOVE_ANIM_GROUP + (anim / 4) % FRAMES_PER_MOVE_ANIM_GROUP].bitmap;
  938. }
  939. int CMapHandler::CMapBlitter::findAnimIndexByGroup(const CDefEssential * def, int groupNum) const
  940. {
  941. auto iter = std::find_if(def->ourImages.begin(), def->ourImages.end(), [&](const Cimage &img){ return img.groupNumber == groupNum; });
  942. if (iter == def->ourImages.end())
  943. return -1;
  944. return static_cast<int>(iter - def->ourImages.begin());
  945. }
  946. CMapHandler::AnimBitmapHolder CMapHandler::CMapBlitter::findObjectBitmap(const CGObjectInstance * obj, int anim) const
  947. {
  948. if (!obj)
  949. return CMapHandler::AnimBitmapHolder();
  950. if (obj->ID == Obj::HERO)
  951. return findHeroBitmap(static_cast<const CGHeroInstance*>(obj), anim);
  952. if (obj->ID == Obj::BOAT)
  953. return findBoatBitmap(static_cast<const CGBoat*>(obj), anim);
  954. // normal object
  955. const std::vector<Cimage> &ourImages = graphics->getDef(obj)->ourImages;
  956. SDL_Surface *bitmap = ourImages[(anim + getPhaseShift(obj)) % ourImages.size()].bitmap;
  957. //setting appropriate flag color
  958. const PlayerColor &color = obj->tempOwner;
  959. if(color < PlayerColor::PLAYER_LIMIT || color==PlayerColor::NEUTRAL)
  960. CSDL_Ext::setPlayerColor(bitmap, color);
  961. return CMapHandler::AnimBitmapHolder(bitmap);
  962. }
  963. ui8 CMapHandler::CMapBlitter::getPhaseShift(const CGObjectInstance *object) const
  964. {
  965. auto i = parent->animationPhase.find(object);
  966. if(i == parent->animationPhase.end())
  967. {
  968. ui8 ret = CRandomGenerator::getDefault().nextInt(254);
  969. parent->animationPhase[object] = ret;
  970. return ret;
  971. }
  972. return i->second;
  973. }
  974. bool CMapHandler::CMapBlitter::canDrawObject(const CGObjectInstance * obj) const
  975. {
  976. //checking if object has non-empty graphic on this tile
  977. return obj->ID == Obj::HERO || obj->coveringAt(pos.x, pos.y);
  978. }
  979. bool CMapHandler::CMapBlitter::canDrawCurrentTile() const
  980. {
  981. const NeighborTilesInfo neighbors(pos, parent->sizes, *info->visibilityMap);
  982. return !neighbors.areAllHidden();
  983. }
  984. ui8 CMapHandler::CMapBlitter::getHeroFrameNum(ui8 dir, bool isMoving) const
  985. {
  986. if(isMoving)
  987. {
  988. static const ui8 frame [] = {0xff, 10, 5, 6, 7, 8, 9, 12, 11};
  989. return frame[dir];
  990. }
  991. else //if(isMoving)
  992. {
  993. static const ui8 frame [] = {0xff, 13, 0, 1, 2, 3, 4, 15, 14};
  994. return frame[dir];
  995. }
  996. }
  997. std::pair<SDL_Surface *, bool> CMapHandler::CMapBlitter::getVisBitmap() const
  998. {
  999. const NeighborTilesInfo neighborInfo(pos, parent->sizes, *info->visibilityMap);
  1000. int retBitmapID = neighborInfo.getBitmapID();// >=0 -> partial hide, <0 - full hide
  1001. if (retBitmapID < 0)
  1002. {
  1003. retBitmapID = - parent->hideBitmap[pos.x][pos.y][pos.z] - 1; //fully hidden
  1004. }
  1005. if (retBitmapID >= 0)
  1006. {
  1007. return std::make_pair(graphics->FoWpartialHide->ourImages[retBitmapID].bitmap, true);
  1008. }
  1009. else
  1010. {
  1011. return std::make_pair(graphics->FoWfullHide->ourImages[-retBitmapID - 1].bitmap, false);
  1012. }
  1013. }
  1014. bool CMapHandler::updateObjectsFade()
  1015. {
  1016. for (auto iter = fadeAnims.begin(); iter != fadeAnims.end(); )
  1017. {
  1018. int3 pos = (*iter).second.first;
  1019. CFadeAnimation * anim = (*iter).second.second;
  1020. anim->update();
  1021. if (anim->isFading())
  1022. ++iter;
  1023. else // fade finished
  1024. {
  1025. auto &objs = ttiles[pos.x][pos.y][pos.z].objects;
  1026. for (auto objIter = objs.begin(); objIter != objs.end(); ++objIter)
  1027. {
  1028. if ((*objIter).fadeAnimKey == (*iter).first)
  1029. {
  1030. logAnim->traceStream() << "Fade anim finished for obj at " << pos << "; remaining: " << (fadeAnims.size() - 1);
  1031. if (anim->fadingMode == CFadeAnimation::EMode::OUT)
  1032. objs.erase(objIter); // if this was fadeout, remove the object from the map
  1033. else
  1034. (*objIter).fadeAnimKey = -1; // for fadein, just remove its connection to the finished fade
  1035. break;
  1036. }
  1037. }
  1038. iter = fadeAnims.erase(iter);
  1039. }
  1040. }
  1041. return !fadeAnims.empty();
  1042. }
  1043. bool CMapHandler::startObjectFade(TerrainTileObject & obj, bool in, int3 pos)
  1044. {
  1045. SDL_Surface * fadeBitmap;
  1046. assert(obj.obj);
  1047. auto objData = normalBlitter->findObjectBitmap(obj.obj, 0);
  1048. if (objData.objBitmap)
  1049. {
  1050. if (objData.isMoving) // ignore fading of moving objects (for now?)
  1051. {
  1052. logAnim->debugStream() << "Ignoring fade of moving object";
  1053. return false;
  1054. }
  1055. fadeBitmap = CSDL_Ext::newSurface(32, 32); // TODO cache these bitmaps instead of creating new ones?
  1056. Rect objSrcRect(obj.rect.x, obj.rect.y, 32, 32);
  1057. CSDL_Ext::blit8bppAlphaTo24bpp(objData.objBitmap, &objSrcRect, fadeBitmap, nullptr);
  1058. if (objData.flagBitmap)
  1059. {
  1060. if (obj.obj->pos.x - 1 == pos.x && obj.obj->pos.y - 1 == pos.y) // -1 to draw flag in top-center instead of right-bottom; kind of a hack
  1061. {
  1062. Rect flagSrcRect(32, 0, 32, 32);
  1063. CSDL_Ext::blitSurface(objData.flagBitmap, &flagSrcRect, fadeBitmap, nullptr);
  1064. }
  1065. }
  1066. auto anim = new CFadeAnimation();
  1067. anim->init(in ? CFadeAnimation::EMode::IN : CFadeAnimation::EMode::OUT, fadeBitmap, true);
  1068. fadeAnims[++fadeAnimCounter] = std::pair<int3, CFadeAnimation*>(pos, anim);
  1069. obj.fadeAnimKey = fadeAnimCounter;
  1070. logAnim->traceStream() << "Fade anim started for obj " << obj.obj->ID
  1071. << " at " << pos << "; anim count: " << fadeAnims.size();
  1072. return true;
  1073. }
  1074. return false;
  1075. }
  1076. bool CMapHandler::printObject(const CGObjectInstance *obj, bool fadein /* = false */)
  1077. {
  1078. if (!graphics->getDef(obj))
  1079. processDef(obj->appearance);
  1080. SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap;
  1081. const int tilesW = bitmap->w/32;
  1082. const int tilesH = bitmap->h/32;
  1083. for(int fx=0; fx<tilesW; ++fx)
  1084. {
  1085. for(int fy=0; fy<tilesH; ++fy)
  1086. {
  1087. SDL_Rect cr;
  1088. cr.w = 32;
  1089. cr.h = 32;
  1090. cr.x = fx*32;
  1091. cr.y = fy*32;
  1092. TerrainTileObject toAdd(obj, cr);
  1093. if((obj->pos.x + fx - tilesW+1)>=0 && (obj->pos.x + fx - tilesW+1)<ttiles.size()-frameW && (obj->pos.y + fy - tilesH+1)>=0 && (obj->pos.y + fy - tilesH+1)<ttiles[0].size()-frameH)
  1094. {
  1095. int3 pos(obj->pos.x + fx - tilesW + 1, obj->pos.y + fy - tilesH + 1, obj->pos.z);
  1096. TerrainTile2 & curt = ttiles[pos.x][pos.y][pos.z];
  1097. if (fadein && ADVOPT.objectFading)
  1098. {
  1099. startObjectFade(toAdd, true, pos);
  1100. }
  1101. auto i = curt.objects.begin();
  1102. for(; i != curt.objects.end(); i++)
  1103. {
  1104. if(objectBlitOrderSorter(toAdd, *i))
  1105. {
  1106. curt.objects.insert(i, toAdd);
  1107. i = curt.objects.begin(); //to validate and avoid adding it second time
  1108. break;
  1109. }
  1110. }
  1111. if(i == curt.objects.end())
  1112. curt.objects.insert(i, toAdd);
  1113. }
  1114. } // for(int fy=0; fy<tilesH; ++fy)
  1115. } //for(int fx=0; fx<tilesW; ++fx)
  1116. return true;
  1117. }
  1118. bool CMapHandler::hideObject(const CGObjectInstance *obj, bool fadeout /* = false */)
  1119. {
  1120. // do we actually need to search through the whole map for this?
  1121. for (size_t i=0; i<map->width; i++)
  1122. {
  1123. for (size_t j=0; j<map->height; j++)
  1124. {
  1125. for (size_t k=0; k<(map->twoLevel ? 2 : 1); k++)
  1126. {
  1127. auto &objs = ttiles[i][j][k].objects;
  1128. for(size_t x=0; x < objs.size(); x++)
  1129. {
  1130. if (objs[x].obj && objs[x].obj->id == obj->id)
  1131. {
  1132. if (fadeout && ADVOPT.objectFading) // object should be faded == erase is delayed until the end of fadeout
  1133. {
  1134. if (startObjectFade(objs[x], false, int3(i, j, k)))
  1135. objs[x].obj = nullptr;
  1136. else
  1137. objs.erase(objs.begin() + x);
  1138. }
  1139. else
  1140. objs.erase(objs.begin() + x);
  1141. break;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. return true;
  1148. }
  1149. bool CMapHandler::removeObject(CGObjectInstance *obj, bool fadeout /* = false */)
  1150. {
  1151. hideObject(obj, fadeout);
  1152. return true;
  1153. }
  1154. void CMapHandler::validateRectTerr(SDL_Rect * val, const SDL_Rect * ext)
  1155. {
  1156. if(ext)
  1157. {
  1158. if(val->x<0)
  1159. {
  1160. val->w += val->x;
  1161. val->x = ext->x;
  1162. }
  1163. else
  1164. {
  1165. val->x += ext->x;
  1166. }
  1167. if(val->y<0)
  1168. {
  1169. val->h += val->y;
  1170. val->y = ext->y;
  1171. }
  1172. else
  1173. {
  1174. val->y += ext->y;
  1175. }
  1176. if(val->x+val->w > ext->x+ext->w)
  1177. {
  1178. val->w = ext->x+ext->w-val->x;
  1179. }
  1180. if(val->y+val->h > ext->y+ext->h)
  1181. {
  1182. val->h = ext->y+ext->h-val->y;
  1183. }
  1184. //for sign problems
  1185. if(val->h > 20000 || val->w > 20000)
  1186. {
  1187. val->h = val->w = 0;
  1188. }
  1189. }
  1190. }
  1191. ui8 CMapHandler::getDir(const int3 &a, const int3 &b)
  1192. {
  1193. if(a.z!=b.z)
  1194. return -1; //error!
  1195. if(a.x==b.x+1 && a.y==b.y+1) //lt
  1196. return 0;
  1197. else if(a.x==b.x && a.y==b.y+1) //t
  1198. return 1;
  1199. else if(a.x==b.x-1 && a.y==b.y+1) //rt
  1200. return 2;
  1201. else if(a.x==b.x-1 && a.y==b.y) //r
  1202. return 3;
  1203. else if(a.x==b.x-1 && a.y==b.y-1) //rb
  1204. return 4;
  1205. else if(a.x==b.x && a.y==b.y-1) //b
  1206. return 5;
  1207. else if(a.x==b.x+1 && a.y==b.y-1) //lb
  1208. return 6;
  1209. else if(a.x==b.x+1 && a.y==b.y) //l
  1210. return 7;
  1211. return -2; //shouldn't happen
  1212. }
  1213. bool CMapHandler::canStartHeroMovement()
  1214. {
  1215. return fadeAnims.empty(); // don't allow movement during fade animation
  1216. }
  1217. void shiftColors(SDL_Surface *img, int from, int howMany) //shifts colors in palette
  1218. {
  1219. //works with at most 16 colors, if needed more -> increase values
  1220. assert(howMany < 16);
  1221. SDL_Color palette[16];
  1222. for(int i=0; i<howMany; ++i)
  1223. {
  1224. palette[(i+1)%howMany] =img->format->palette->colors[from + i];
  1225. }
  1226. SDL_SetColors(img,palette,from,howMany);
  1227. }
  1228. void CMapHandler::updateWater() //shift colors in palettes of water tiles
  1229. {
  1230. for(auto & elem : terrainGraphics[7])
  1231. {
  1232. shiftColors(elem,246, 9);
  1233. }
  1234. for(auto & elem : terrainGraphics[8])
  1235. {
  1236. shiftColors(elem,229, 12);
  1237. shiftColors(elem,242, 14);
  1238. }
  1239. for(auto & elem : staticRiverDefs[0]->ourImages)
  1240. {
  1241. shiftColors(elem.bitmap,183, 12);
  1242. shiftColors(elem.bitmap,195, 6);
  1243. }
  1244. for(auto & elem : staticRiverDefs[2]->ourImages)
  1245. {
  1246. shiftColors(elem.bitmap,228, 12);
  1247. shiftColors(elem.bitmap,183, 6);
  1248. shiftColors(elem.bitmap,240, 6);
  1249. }
  1250. for(auto & elem : staticRiverDefs[3]->ourImages)
  1251. {
  1252. shiftColors(elem.bitmap,240, 9);
  1253. }
  1254. }
  1255. CMapHandler::~CMapHandler()
  1256. {
  1257. delete graphics->FoWfullHide;
  1258. delete graphics->FoWpartialHide;
  1259. // if (fadingOffscreenBitmapSurface)
  1260. // delete fadingOffscreenBitmapSurface;
  1261. delete normalBlitter;
  1262. delete worldViewBlitter;
  1263. delete puzzleViewBlitter;
  1264. for(auto & elem : roadDefs)
  1265. delete elem;
  1266. for(auto & elem : staticRiverDefs)
  1267. delete elem;
  1268. for(auto & elem : terrainGraphics)
  1269. {
  1270. for(int j=0; j < elem.size(); ++j)
  1271. SDL_FreeSurface(elem[j]);
  1272. }
  1273. for (auto & elem : fadeAnims)
  1274. {
  1275. delete elem.second.second;
  1276. }
  1277. terrainGraphics.clear();
  1278. }
  1279. CMapHandler::CMapHandler()
  1280. {
  1281. frameW = frameH = 0;
  1282. graphics->FoWfullHide = nullptr;
  1283. graphics->FoWpartialHide = nullptr;
  1284. normalBlitter = new CMapNormalBlitter(this);
  1285. worldViewBlitter = new CMapWorldViewBlitter(this);
  1286. puzzleViewBlitter = new CMapPuzzleViewBlitter(this);
  1287. fadeAnimCounter = 0;
  1288. }
  1289. void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terName )
  1290. {
  1291. out.clear();
  1292. TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
  1293. const TerrainTile &t = map->getTile(pos);
  1294. for(auto & elem : tt.objects)
  1295. {
  1296. if(elem.obj && elem.obj->ID == Obj::HOLE) //Hole
  1297. {
  1298. out = elem.obj->getObjectName();
  1299. return;
  1300. }
  1301. }
  1302. if(t.hasFavourableWinds())
  1303. out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS);
  1304. else if(terName)
  1305. out = CGI->generaltexth->terrainNames[t.terType];
  1306. }
  1307. void CMapHandler::discardWorldViewCache()
  1308. {
  1309. cache.discardWorldViewCache();
  1310. }
  1311. void CMapHandler::CMapCache::discardWorldViewCache()
  1312. {
  1313. for (auto &cacheDataPair : data)
  1314. {
  1315. for (auto &cacheEntryPair : cacheDataPair.second)
  1316. {
  1317. if (cacheEntryPair.second)
  1318. {
  1319. SDL_FreeSurface(cacheEntryPair.second);
  1320. }
  1321. }
  1322. data[cacheDataPair.first].clear();
  1323. }
  1324. logGlobal->debugStream() << "Discarded world view cache";
  1325. }
  1326. void CMapHandler::CMapCache::updateWorldViewScale(float scale)
  1327. {
  1328. if (fabs(scale - worldViewCachedScale) > 0.001f)
  1329. discardWorldViewCache();
  1330. worldViewCachedScale = scale;
  1331. }
  1332. void CMapHandler::CMapCache::removeFromWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key)
  1333. {
  1334. auto iter = data[type].find(key);
  1335. if (iter != data[type].end())
  1336. {
  1337. SDL_FreeSurface((*iter).second);
  1338. data[type].erase(iter);
  1339. }
  1340. }
  1341. SDL_Surface * CMapHandler::CMapCache::requestWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key)
  1342. {
  1343. auto iter = data[type].find(key);
  1344. if (iter == data[type].end())
  1345. return nullptr;
  1346. return (*iter).second;
  1347. }
  1348. SDL_Surface * CMapHandler::CMapCache::requestWorldViewCacheOrCreate(CMapHandler::EMapCacheType type, intptr_t key, SDL_Surface * fullSurface, float scale)
  1349. {
  1350. auto cached = requestWorldViewCache(type, key);
  1351. if (cached)
  1352. return cached;
  1353. auto scaled = CSDL_Ext::scaleSurfaceFast(fullSurface, fullSurface->w * scale, fullSurface->h * scale);
  1354. if (scaled->format && scaled->format->palette) // fix color keying, because SDL loses it at this point
  1355. CSDL_Ext::setColorKey(scaled, scaled->format->palette->colors[0]);
  1356. return cacheWorldViewEntry(type, key, scaled);
  1357. }
  1358. SDL_Surface *CMapHandler::CMapCache::cacheWorldViewEntry(CMapHandler::EMapCacheType type, intptr_t key, SDL_Surface * entry)
  1359. {
  1360. if (!entry)
  1361. return nullptr;
  1362. if (requestWorldViewCache(type, key)) // valid cache already present, no need to do it again
  1363. return requestWorldViewCache(type, key);
  1364. data[type][key] = entry;
  1365. return entry;
  1366. }
  1367. intptr_t CMapHandler::CMapCache::genKey(intptr_t realPtr, ui8 mod)
  1368. {
  1369. return (intptr_t)(realPtr ^ (mod << (sizeof(intptr_t) - 2))); // maybe some cleaner method to pack rotation into cache key?
  1370. }
  1371. TerrainTile2::TerrainTile2()
  1372. :terbitmap(nullptr)
  1373. {}
  1374. bool CMapHandler::compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b)
  1375. {
  1376. if (!a)
  1377. return true;
  1378. if (!b)
  1379. return false;
  1380. if (a->appearance.printPriority != b->appearance.printPriority)
  1381. return a->appearance.printPriority > b->appearance.printPriority;
  1382. if(a->pos.y != b->pos.y)
  1383. return a->pos.y < b->pos.y;
  1384. if(b->ID==Obj::HERO && a->ID!=Obj::HERO)
  1385. return true;
  1386. if(b->ID!=Obj::HERO && a->ID==Obj::HERO)
  1387. return false;
  1388. if(!a->isVisitable() && b->isVisitable())
  1389. return true;
  1390. if(!b->isVisitable() && a->isVisitable())
  1391. return false;
  1392. if(a->pos.x < b->pos.x)
  1393. return true;
  1394. return false;
  1395. }
  1396. TerrainTileObject::TerrainTileObject(const CGObjectInstance * obj_, SDL_Rect rect_)
  1397. : obj(obj_),
  1398. rect(rect_),
  1399. fadeAnimKey(-1)
  1400. {
  1401. }
  1402. TerrainTileObject::~TerrainTileObject()
  1403. {
  1404. }