2014-05-16 20:22:21 +03:00
|
|
|
/*
|
|
|
|
* mapHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2009-02-02 15:05:19 +02:00
|
|
|
#include "mapHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2014-01-03 02:48:38 +03:00
|
|
|
#include "CBitmapHandler.h"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "gui/SDL_Extensions.h"
|
2010-04-06 11:59:24 +03:00
|
|
|
#include "CGameInfo.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
#include "../lib/mapObjects/CGHeroInstance.h"
|
2014-06-05 14:19:47 +03:00
|
|
|
#include "../lib/mapObjects/CObjectClassesHandler.h"
|
2010-04-06 11:59:24 +03:00
|
|
|
#include "../lib/CGameState.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CHeroHandler.h"
|
|
|
|
#include "../lib/CTownHandler.h"
|
2010-04-06 11:59:24 +03:00
|
|
|
#include "Graphics.h"
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "../lib/mapping/CMap.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CDefHandler.h"
|
2012-09-29 13:59:43 +03:00
|
|
|
#include "../lib/CConfigHandler.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "../lib/GameConstants.h"
|
2011-12-17 21:59:59 +03:00
|
|
|
#include "../lib/CStopWatch.h"
|
2013-04-04 17:58:54 +03:00
|
|
|
#include "CMT.h"
|
2014-04-10 20:11:09 +03:00
|
|
|
#include "../lib/CRandomGenerator.h"
|
2009-04-15 17:03:31 +03:00
|
|
|
|
2009-08-31 18:57:15 +03:00
|
|
|
#define ADVOPT (conf.go()->ac)
|
2009-04-15 17:03:31 +03:00
|
|
|
|
2009-07-25 19:35:47 +03:00
|
|
|
std::string nameFromType (int typ)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
switch(ETerrainType(typ))
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::DIRT:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("DIRTTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::SAND:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("SANDTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::GRASS:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("GRASTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::SNOW:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("SNOWTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::SWAMP:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("SWMPTL.DEF");
|
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::ROUGH:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("ROUGTL.DEF");
|
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::SUBTERRANEAN:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("SUBBTL.DEF");
|
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::LAVA:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("LAVATL.DEF");
|
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::WATER:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("WATRTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::ROCK:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("ROCKTL.DEF");
|
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
case ETerrainType::BORDER:
|
2009-07-25 19:35:47 +03:00
|
|
|
//TODO use me
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//TODO do something here
|
|
|
|
break;
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
return std::string();
|
|
|
|
}
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2014-06-24 02:26:36 +03:00
|
|
|
static bool objectBlitOrderSorter(const std::pair<const CGObjectInstance*,SDL_Rect> & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-06-24 02:26:36 +03:00
|
|
|
return CMapHandler::compareObjectBlitOrder(a.first, b.first);
|
|
|
|
}
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2014-07-03 19:41:42 +03:00
|
|
|
struct NeighborTilesInfo
|
|
|
|
{
|
|
|
|
bool d7, //789
|
|
|
|
d8, //456
|
|
|
|
d9, //123
|
|
|
|
d4,
|
|
|
|
d5,
|
|
|
|
d6,
|
|
|
|
d1,
|
|
|
|
d2,
|
|
|
|
d3;
|
|
|
|
NeighborTilesInfo(const int3 & pos, const int3 & sizes, const std::vector< std::vector< std::vector<ui8> > > & visibilityMap)
|
|
|
|
{
|
|
|
|
auto getTile = [&](int dx, int dy)->bool
|
|
|
|
{
|
|
|
|
if ( dx + pos.x < 0 || dx + pos.x >= sizes.x
|
|
|
|
|| dy + pos.y < 0 || dy + pos.y >= sizes.y)
|
|
|
|
return false;
|
|
|
|
return visibilityMap[dx+pos.x][dy+pos.y][pos.z];
|
|
|
|
};
|
|
|
|
d7 = getTile(-1, -1); //789
|
|
|
|
d8 = getTile( 0, -1); //456
|
|
|
|
d9 = getTile(+1, -1); //123
|
|
|
|
d4 = getTile(-1, 0);
|
|
|
|
d5 = visibilityMap[pos.x][pos.y][pos.z];
|
|
|
|
d6 = getTile(+1, 0);
|
|
|
|
d1 = getTile(-1, +1);
|
|
|
|
d2 = getTile( 0, +1);
|
|
|
|
d3 = getTile(+1, +1);
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
|
|
|
bool areAllHidden() const
|
2014-07-03 19:41:42 +03:00
|
|
|
{
|
|
|
|
return !(d1 || d2 || d3 || d4 || d5 || d6 || d7 || d8 || d8 );
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2014-07-03 19:41:42 +03:00
|
|
|
int getBitmapID() const
|
|
|
|
{
|
|
|
|
//NOTE: some images have unused in VCMI pair (same blockmap but a bit different look)
|
|
|
|
// 0-1, 2-3, 4-5, 11-13, 12-14
|
|
|
|
static const int visBitmaps[256] = {
|
|
|
|
-1, 34, 4, 4, 22, 23, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, //16
|
|
|
|
3, 25, 12, 12, 3, 25, 12, 12, 9, 9, 6, 6, 9, 9, 6, 6, //32
|
|
|
|
35, 39, 48, 48, 41, 43, 48, 48, 36, 36, 38, 38, 47, 47, 38, 38, //48
|
|
|
|
26, 49, 28, 28, 26, 49, 28, 28, 9, 9, 6, 6, 9, 9, 6, 6, //64
|
|
|
|
0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //80
|
|
|
|
13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10, //96
|
|
|
|
0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //112
|
|
|
|
13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10, //128
|
|
|
|
15, 17, 30, 30, 16, 19, 30, 30, 46, 46, 40, 40, 32, 32, 40, 40, //144
|
|
|
|
2, 25, 12, 12, 2, 25, 12, 12, 9, 9, 6, 6, 9, 9, 6, 6, //160
|
|
|
|
18, 42, 31, 31, 20, 21, 31, 31, 46, 46, 40, 40, 32, 32, 40, 40, //176
|
|
|
|
26, 49, 28, 28, 26, 49, 28, 28, 9, 9, 6, 6, 9, 9, 6, 6, //192
|
|
|
|
0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //208
|
|
|
|
13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10, //224
|
|
|
|
0, 45, 29, 29, 24, 33, 29, 29, 37, 37, 7, 7, 50, 50, 7, 7, //240
|
|
|
|
13, 27, 44, 44, 13, 27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10 //256
|
2015-01-13 21:57:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return visBitmaps[d1 + d2 * 2 + d3 * 4 + d4 * 8 + d6 * 16 + d7 * 32 + d8 * 64 + d9 * 128]; // >=0 -> partial hide, <0 - full hide
|
2014-07-03 19:41:42 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
void CMapHandler::prepareFOWDefs()
|
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
graphics->FoWfullHide = CDefHandler::giveDef("TSHRC.DEF");
|
|
|
|
graphics->FoWpartialHide = CDefHandler::giveDef("TSHRE.DEF");
|
2009-02-02 15:05:19 +02:00
|
|
|
|
|
|
|
//adding necessary rotations
|
2012-05-14 19:29:06 +03:00
|
|
|
static const int missRot [] = {22, 15, 2, 13, 12, 16, 28, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27};
|
2009-07-25 19:35:47 +03:00
|
|
|
|
|
|
|
Cimage nw;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : missRot)
|
2009-07-25 19:35:47 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
nw = graphics->FoWpartialHide->ourImages[elem];
|
2013-11-06 16:42:58 +03:00
|
|
|
nw.bitmap = CSDL_Ext::verticalFlip(nw.bitmap);
|
2010-08-16 16:51:31 +03:00
|
|
|
graphics->FoWpartialHide->ourImages.push_back(nw);
|
2009-07-25 19:35:47 +03:00
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
//necessaary rotations added
|
|
|
|
|
2009-07-25 19:35:47 +03:00
|
|
|
//alpha - transformation
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : graphics->FoWpartialHide->ourImages)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
CSDL_Ext::alphaTransform(elem.bitmap);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2009-07-25 19:35:47 +03:00
|
|
|
//initialization of type of full-hide image
|
2010-08-16 16:51:31 +03:00
|
|
|
hideBitmap.resize(sizes.x);
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : hideBitmap)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
elem.resize(sizes.y);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : hideBitmap)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
for (int j = 0; j < sizes.y; ++j)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
elem[j].resize(sizes.z);
|
2011-12-14 00:23:17 +03:00
|
|
|
for(int k = 0; k < sizes.z; ++k)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-04-10 20:11:09 +03:00
|
|
|
elem[j][k] = CRandomGenerator::getDefault().nextInt(graphics->FoWfullHide->ourImages.size() - 1);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
void CMapHandler::drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info)
|
|
|
|
{
|
|
|
|
assert(info);
|
2015-01-19 21:08:19 +02:00
|
|
|
resolveBlitter(info)->blit(targetSurface, info);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
void CMapHandler::roadsRiverTerrainInit()
|
|
|
|
{
|
|
|
|
//initializing road's and river's DefHandlers
|
|
|
|
|
2009-06-17 19:46:16 +03:00
|
|
|
roadDefs.push_back(CDefHandler::giveDefEss("dirtrd.def"));
|
|
|
|
roadDefs.push_back(CDefHandler::giveDefEss("gravrd.def"));
|
|
|
|
roadDefs.push_back(CDefHandler::giveDefEss("cobbrd.def"));
|
|
|
|
staticRiverDefs.push_back(CDefHandler::giveDefEss("clrrvr.def"));
|
|
|
|
staticRiverDefs.push_back(CDefHandler::giveDefEss("icyrvr.def"));
|
|
|
|
staticRiverDefs.push_back(CDefHandler::giveDefEss("mudrvr.def"));
|
|
|
|
staticRiverDefs.push_back(CDefHandler::giveDefEss("lavrvr.def"));
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : staticRiverDefs)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(size_t h=0; h < elem->ourImages.size(); ++h)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
CSDL_Ext::alphaTransform(elem->ourImages[h].bitmap);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : roadDefs)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(size_t h=0; h < elem->ourImages.size(); ++h)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
CSDL_Ext::alphaTransform(elem->ourImages[h].bitmap);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-12 06:26:41 +03:00
|
|
|
// Create enough room for the whole map and its frame
|
2014-09-18 15:29:57 +03:00
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
ttiles.resize(sizes.x, frameW, frameW);
|
2009-06-14 10:02:06 +03:00
|
|
|
for (int i=0-frameW;i<ttiles.size()-frameW;i++)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
ttiles[i].resize(sizes.y, frameH, frameH);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
for (int i=0-frameW;i<ttiles.size()-frameW;i++)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
for (int j=0-frameH;j<(int)sizes.y+frameH;j++)
|
|
|
|
ttiles[i][j].resize(sizes.z, 0, 0);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 16:07:58 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
void CMapHandler::borderAndTerrainBitmapInit()
|
|
|
|
{
|
|
|
|
CDefHandler * bord = CDefHandler::giveDef("EDG.DEF");
|
|
|
|
bord->notFreeImgs = true;
|
|
|
|
terrainGraphics.resize(10);
|
|
|
|
for (int i = 0; i < 10 ; i++)
|
|
|
|
{
|
|
|
|
CDefHandler *hlp = CDefHandler::giveDef(nameFromType(i));
|
|
|
|
terrainGraphics[i].resize(hlp->ourImages.size());
|
|
|
|
hlp->notFreeImgs = true;
|
|
|
|
for(size_t j=0; j < hlp->ourImages.size(); ++j)
|
|
|
|
terrainGraphics[i][j] = hlp->ourImages[j].bitmap;
|
|
|
|
delete hlp;
|
|
|
|
}
|
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
for (int i=0-frameW; i<sizes.x+frameW; i++) //by width
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
for (int j=0-frameH; j<sizes.y+frameH;j++) //by height
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
for(int k=0; k<sizes.z; ++k) //by levles
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
if(i < 0 || i > (sizes.x-1) || j < 0 || j > (sizes.y-1))
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-08-17 16:08:05 +03:00
|
|
|
int terBitmapNum = -1;
|
|
|
|
|
2014-04-10 20:11:09 +03:00
|
|
|
auto & rand = CRandomGenerator::getDefault();
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
if(i==-1 && j==-1)
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 16;
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(i==-1 && j==(sizes.y))
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 19;
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(i==(sizes.x) && j==-1)
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 17;
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(i==(sizes.x) && j==(sizes.y))
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 18;
|
2014-06-23 19:31:17 +03:00
|
|
|
else if(j == -1 && i > -1 && i < sizes.x)
|
2014-04-10 20:11:09 +03:00
|
|
|
terBitmapNum = rand.nextInt(22, 23);
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(i == -1 && j > -1 && j < sizes.y)
|
2014-04-10 20:11:09 +03:00
|
|
|
terBitmapNum = rand.nextInt(33, 34);
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(j == sizes.y && i >-1 && i < sizes.x)
|
2014-04-10 20:11:09 +03:00
|
|
|
terBitmapNum = rand.nextInt(29, 30);
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(i == sizes.x && j > -1 && j < sizes.y)
|
2014-04-10 20:11:09 +03:00
|
|
|
terBitmapNum = rand.nextInt(25, 26);
|
2009-02-02 15:05:19 +02:00
|
|
|
else
|
2014-04-10 20:11:09 +03:00
|
|
|
terBitmapNum = rand.nextInt(15);
|
2009-08-17 16:08:05 +03:00
|
|
|
|
|
|
|
if(terBitmapNum != -1)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-08-17 16:08:05 +03:00
|
|
|
ttiles[i][j][k].terbitmap = bord->ourImages[terBitmapNum].bitmap;
|
2009-02-02 15:05:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete bord;
|
|
|
|
}
|
2012-11-13 14:52:23 +03:00
|
|
|
|
2014-01-03 02:48:38 +03:00
|
|
|
static void processDef (const ObjectTemplate & objTempl)
|
2012-11-13 14:52:23 +03:00
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
if(objTempl.id == Obj::EVENT)
|
2012-11-13 14:52:23 +03:00
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
graphics->advmapobjGraphics[objTempl.animationFile] = nullptr;
|
2012-11-13 14:52:23 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-01-03 02:48:38 +03:00
|
|
|
CDefEssential * ourDef = graphics->getDef(objTempl);
|
2012-11-13 14:52:23 +03:00
|
|
|
if(!ourDef) //if object has already set handler (eg. heroes) it should not be overwritten
|
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
if(objTempl.animationFile.size())
|
2012-11-13 14:52:23 +03:00
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
graphics->advmapobjGraphics[objTempl.animationFile] = CDefHandler::giveDefEss(objTempl.animationFile);
|
2012-11-13 14:52:23 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
logGlobal->warnStream() << "No def name for " << objTempl.id << " " << objTempl.subid;
|
2012-11-13 14:52:23 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-01-03 02:48:38 +03:00
|
|
|
ourDef = graphics->getDef(objTempl);
|
2012-11-13 14:52:23 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
//alpha transformation
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : ourDef->ourImages)
|
2012-11-13 14:52:23 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
CSDL_Ext::alphaTransform(elem.bitmap);
|
2012-11-13 14:52:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
void CMapHandler::initObjectRects()
|
|
|
|
{
|
|
|
|
//initializing objects / rects
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : map->objects)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
const CGObjectInstance *obj = elem;
|
2009-08-01 13:08:16 +03:00
|
|
|
if( !obj
|
2012-09-23 21:01:04 +03:00
|
|
|
|| (obj->ID==Obj::HERO && static_cast<const CGHeroInstance*>(obj)->inTownGarrison) //garrisoned hero
|
2014-01-03 02:48:38 +03:00
|
|
|
|| (obj->ID==Obj::BOAT && static_cast<const CGBoat*>(obj)->hero)) //boat with hero (hero graphics is used)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-13 14:52:23 +03:00
|
|
|
if (!graphics->getDef(obj)) //try to load it
|
2014-01-03 02:48:38 +03:00
|
|
|
processDef(obj->appearance);
|
2012-11-13 14:52:23 +03:00
|
|
|
if (!graphics->getDef(obj)) // stil no graphics? exit
|
|
|
|
continue;
|
|
|
|
|
2011-09-04 03:04:48 +03:00
|
|
|
const SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap;
|
2014-01-03 02:48:38 +03:00
|
|
|
for(int fx=0; fx < obj->getWidth(); ++fx)
|
2009-08-01 13:08:16 +03:00
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
for(int fy=0; fy < obj->getHeight(); ++fy)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
int3 currTile(obj->pos.x - fx, obj->pos.y - fy, obj->pos.z);
|
2009-08-01 13:08:16 +03:00
|
|
|
SDL_Rect cr;
|
|
|
|
cr.w = 32;
|
|
|
|
cr.h = 32;
|
2014-01-03 02:48:38 +03:00
|
|
|
cr.x = bitmap->w - fx * 32 - 32;
|
|
|
|
cr.y = bitmap->h - fy * 32 - 32;
|
2009-08-01 13:08:16 +03:00
|
|
|
std::pair<const CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj,cr);
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2014-01-03 02:48:38 +03:00
|
|
|
|
|
|
|
if( map->isInTheMap(currTile) && // within map
|
|
|
|
cr.x + cr.w > 0 && // image has data on this tile
|
|
|
|
cr.y + cr.h > 0 &&
|
|
|
|
obj->coveringAt(currTile.x, currTile.y) // object is visible here
|
2009-08-01 13:08:16 +03:00
|
|
|
)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-01-03 02:48:38 +03:00
|
|
|
ttiles[currTile.x][currTile.y][currTile.z].objects.push_back(toAdd);
|
2009-08-01 13:08:16 +03:00
|
|
|
}
|
2014-01-03 02:48:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-01 13:08:16 +03:00
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
for(int ix=0; ix<ttiles.size()-frameW; ++ix)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
for(int iy=0; iy<ttiles[0].size()-frameH; ++iy)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
for(int iz=0; iz<ttiles[0][0].size(); ++iz)
|
|
|
|
{
|
2014-06-24 02:26:36 +03:00
|
|
|
stable_sort(ttiles[ix][iy][iz].objects.begin(), ttiles[ix][iy][iz].objects.end(), objectBlitOrderSorter);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 14:52:23 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
void CMapHandler::init()
|
|
|
|
{
|
2011-12-17 21:59:59 +03:00
|
|
|
CStopWatch th;
|
2011-12-14 00:23:17 +03:00
|
|
|
th.getDiff();
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2012-11-13 14:52:23 +03:00
|
|
|
graphics->advmapobjGraphics["AB01_.DEF"] = graphics->boatAnims[0];
|
|
|
|
graphics->advmapobjGraphics["AB02_.DEF"] = graphics->boatAnims[1];
|
|
|
|
graphics->advmapobjGraphics["AB03_.DEF"] = graphics->boatAnims[2];
|
2009-06-14 18:14:03 +03:00
|
|
|
// Size of visible terrain.
|
2010-08-16 16:51:31 +03:00
|
|
|
int mapW = conf.go()->ac.advmapW;
|
|
|
|
int mapH = conf.go()->ac.advmapH;
|
|
|
|
|
|
|
|
//sizes of terrain
|
|
|
|
sizes.x = map->width;
|
|
|
|
sizes.y = map->height;
|
2012-11-20 20:53:45 +03:00
|
|
|
sizes.z = map->twoLevel ? 2 : 1;
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2011-09-24 04:15:36 +03:00
|
|
|
// Total number of visible tiles. Subtract the center tile, then
|
2009-06-14 10:02:06 +03:00
|
|
|
// compute the number of tiles on each side, and reassemble.
|
|
|
|
int t1, t2;
|
|
|
|
t1 = (mapW-32)/2;
|
|
|
|
t2 = mapW - 32 - t1;
|
|
|
|
tilesW = 1 + (t1+31)/32 + (t2+31)/32;
|
|
|
|
|
|
|
|
t1 = (mapH-32)/2;
|
|
|
|
t2 = mapH - 32 - t1;
|
|
|
|
tilesH = 1 + (t1+31)/32 + (t2+31)/32;
|
|
|
|
|
2009-06-12 06:26:41 +03:00
|
|
|
// Size of the frame around the map. In extremes positions, the
|
|
|
|
// frame must not be on the center of the map, but right on the
|
2009-06-14 10:02:06 +03:00
|
|
|
// edge of the center tile.
|
|
|
|
frameW = (mapW+31) /32 / 2;
|
|
|
|
frameH = (mapH+31) /32 / 2;
|
|
|
|
|
|
|
|
offsetX = (mapW - (2*frameW+1)*32)/2;
|
|
|
|
offsetY = (mapH - (2*frameH+1)*32)/2;
|
2009-06-12 06:26:41 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
prepareFOWDefs();
|
|
|
|
roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
|
|
|
|
borderAndTerrainBitmapInit();
|
2015-01-13 21:57:41 +02:00
|
|
|
logGlobal->infoStream()<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDiff();
|
2009-02-02 15:05:19 +02:00
|
|
|
initObjectRects();
|
2015-01-13 21:57:41 +02:00
|
|
|
logGlobal->infoStream()<<"\tMaking object rects: "<<th.getDiff();
|
2010-02-21 17:03:30 +02:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
CMapHandler::CMapBlitter *CMapHandler::resolveBlitter(const MapDrawingInfo * info) const
|
2015-01-13 21:57:41 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
if (info->scaled)
|
|
|
|
return worldViewBlitter;
|
|
|
|
if (info->puzzleMode)
|
|
|
|
return puzzleViewBlitter;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
return normalBlitter;
|
2015-01-13 21:57:41 +02:00
|
|
|
}
|
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapNormalBlitter::drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit, ui8 rotationInfo) const
|
2015-01-17 00:44:40 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
if (rotationInfo != 0)
|
2015-01-17 00:44:40 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
if (!sourceRect)
|
2015-01-17 00:44:40 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
Rect sourceRect2(0, 0, sourceSurf->w, sourceSurf->h);
|
|
|
|
if (alphaBlit)
|
|
|
|
CSDL_Ext::getBlitterWithRotationAndAlpha(targetSurf)(sourceSurf, sourceRect2, targetSurf, *destRect, rotationInfo);
|
|
|
|
else
|
|
|
|
CSDL_Ext::getBlitterWithRotation(targetSurf)(sourceSurf, sourceRect2, targetSurf, *destRect, rotationInfo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (alphaBlit)
|
|
|
|
CSDL_Ext::getBlitterWithRotationAndAlpha(targetSurf)(sourceSurf, *sourceRect, targetSurf, *destRect, rotationInfo);
|
|
|
|
else
|
|
|
|
CSDL_Ext::getBlitterWithRotation(targetSurf)(sourceSurf, *sourceRect, targetSurf, *destRect, rotationInfo);
|
2015-01-17 00:44:40 +02:00
|
|
|
}
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
|
|
|
else
|
2015-01-13 21:57:41 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
if (alphaBlit)
|
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(sourceSurf, sourceRect, targetSurf, destRect);
|
|
|
|
else
|
|
|
|
CSDL_Ext::blitSurface(sourceSurf, sourceRect, targetSurf, destRect);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapNormalBlitter::init(const MapDrawingInfo * drawingInfo)
|
|
|
|
{
|
|
|
|
info = drawingInfo;
|
|
|
|
// Width and height of the portion of the map to process. Units in tiles.
|
2015-01-18 19:53:40 +02:00
|
|
|
tileCount.x = parent->tilesW;
|
|
|
|
tileCount.y = parent->tilesH;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
topTile = info->topTile;
|
|
|
|
initPos.x = parent->offsetX + info->drawBounds->x;
|
|
|
|
initPos.y = parent->offsetY + info->drawBounds->y;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
realTileRect = Rect(initPos.x, initPos.y, tileSize, tileSize);
|
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
// If moving, we need to add an extra column/line
|
|
|
|
if (info->movement.x != 0)
|
|
|
|
{
|
|
|
|
tileCount.x++;
|
|
|
|
initPos.x += info->movement.x;
|
|
|
|
if (info->movement.x > 0)
|
|
|
|
{
|
|
|
|
// Moving right. We still need to draw the old tile on the
|
|
|
|
// left, so adjust our referential
|
|
|
|
topTile.x--;
|
|
|
|
initPos.x -= tileSize;
|
|
|
|
}
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
if (info->movement.y != 0)
|
|
|
|
{
|
|
|
|
tileCount.y++;
|
|
|
|
initPos.y += info->movement.y;
|
|
|
|
if (info->movement.y > 0)
|
|
|
|
{
|
|
|
|
// Moving down. We still need to draw the tile on the top,
|
|
|
|
// so adjust our referential.
|
|
|
|
topTile.y--;
|
|
|
|
initPos.y -= tileSize;
|
|
|
|
}
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
// Reduce sizes if we go out of the full map.
|
|
|
|
if (topTile.x < -parent->frameW)
|
|
|
|
topTile.x = -parent->frameW;
|
|
|
|
if (topTile.y < -parent->frameH)
|
|
|
|
topTile.y = -parent->frameH;
|
|
|
|
if (topTile.x + tileCount.x > parent->sizes.x + parent->frameW)
|
|
|
|
tileCount.x = parent->sizes.x + parent->frameW - topTile.x;
|
|
|
|
if (topTile.y + tileCount.y > parent->sizes.y + parent->frameH)
|
|
|
|
tileCount.y = parent->sizes.y + parent->frameH - topTile.y;
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
SDL_Rect CMapHandler::CMapNormalBlitter::clip(SDL_Surface * targetSurf) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
SDL_Rect prevClip;
|
|
|
|
SDL_GetClipRect(targetSurf, &prevClip);
|
|
|
|
SDL_SetClipRect(targetSurf, info->drawBounds);
|
|
|
|
return prevClip;
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
CMapHandler::CMapNormalBlitter::CMapNormalBlitter(CMapHandler * parent)
|
|
|
|
: CMapBlitter(parent)
|
|
|
|
{
|
|
|
|
tileSize = 32;
|
2015-01-19 21:08:19 +02:00
|
|
|
halfTileSizeCeil = 16;
|
|
|
|
defaultTileRect = Rect(0, 0, tileSize, tileSize);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapWorldViewBlitter::calculateWorldViewCameraPos()
|
|
|
|
{
|
|
|
|
bool outsideLeft = topTile.x < 0;
|
|
|
|
bool outsideTop = topTile.y < 0;
|
|
|
|
bool outsideRight = std::max(0, topTile.x) + tileCount.x > parent->sizes.x;
|
|
|
|
bool outsideBottom = std::max(0, topTile.y) + tileCount.y > parent->sizes.y;
|
|
|
|
|
|
|
|
if (tileCount.x > parent->sizes.x)
|
|
|
|
topTile.x = parent->sizes.x / 2 - tileCount.x / 2; // center viewport if the whole map can fit into the screen at once
|
|
|
|
else if (outsideLeft)
|
|
|
|
{
|
|
|
|
if (outsideRight)
|
|
|
|
topTile.x = parent->sizes.x / 2 - tileCount.x / 2;
|
|
|
|
else
|
|
|
|
topTile.x = 0;
|
|
|
|
}
|
|
|
|
else if (outsideRight)
|
|
|
|
topTile.x = parent->sizes.x - tileCount.x;
|
|
|
|
|
|
|
|
if (tileCount.y > parent->sizes.y)
|
|
|
|
topTile.y = parent->sizes.y / 2 - tileCount.y / 2;
|
|
|
|
else if (outsideTop)
|
|
|
|
{
|
|
|
|
if (outsideBottom)
|
|
|
|
topTile.y = parent->sizes.y / 2 - tileCount.y / 2;
|
|
|
|
else
|
|
|
|
topTile.y = 0;
|
|
|
|
}
|
|
|
|
else if (outsideBottom)
|
|
|
|
topTile.y = parent->sizes.y - tileCount.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapWorldViewBlitter::drawScaledRotatedElement(EMapCacheType type, SDL_Surface * baseSurf, SDL_Surface * targetSurf, ui8 rotation,
|
|
|
|
float scale, SDL_Rect * dstRect, SDL_Rect * srcRect /*= nullptr*/) const
|
|
|
|
{
|
|
|
|
auto key = parent->cache.genKey((intptr_t)baseSurf, rotation);
|
|
|
|
auto scaledSurf = parent->cache.requestWorldViewCache(type, key);
|
|
|
|
if (scaledSurf) // blitting from cache
|
|
|
|
{
|
|
|
|
if (srcRect)
|
|
|
|
{
|
|
|
|
dstRect->w = srcRect->w;
|
|
|
|
dstRect->h = srcRect->h;
|
|
|
|
}
|
|
|
|
CSDL_Ext::blitSurface(scaledSurf, srcRect, targetSurf, dstRect);
|
|
|
|
}
|
|
|
|
else // creating new
|
|
|
|
{
|
|
|
|
auto baseSurfRotated = CSDL_Ext::newSurface(baseSurf->w, baseSurf->h);
|
|
|
|
if (!baseSurfRotated)
|
|
|
|
return;
|
|
|
|
Rect baseRect(0, 0, baseSurf->w, baseSurf->h);
|
|
|
|
|
|
|
|
CSDL_Ext::getBlitterWithRotationAndAlpha(targetSurf)(baseSurf, baseRect, baseSurfRotated, baseRect, rotation);
|
|
|
|
|
|
|
|
SDL_Surface * scaledSurf2 = CSDL_Ext::scaleSurfaceFast(baseSurfRotated, baseSurf->w * scale, baseSurf->h * scale);
|
|
|
|
|
|
|
|
CSDL_Ext::blitSurface(scaledSurf2, srcRect, targetSurf, dstRect);
|
|
|
|
parent->cache.cacheWorldViewEntry(type, key, scaledSurf2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapWorldViewBlitter::drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit, ui8 rotationInfo) const
|
|
|
|
{
|
|
|
|
if (rotationInfo != 0)
|
|
|
|
{
|
|
|
|
drawScaledRotatedElement(cacheType, sourceSurf, targetSurf, rotationInfo, info->scale, destRect, sourceRect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto scaledSurf = parent->cache.requestWorldViewCacheOrCreate(cacheType, (intptr_t) sourceSurf, sourceSurf, info->scale);
|
|
|
|
|
|
|
|
if (alphaBlit)
|
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(scaledSurf, sourceRect, targetSurf, destRect);
|
|
|
|
else
|
|
|
|
CSDL_Ext::blitSurface(scaledSurf, sourceRect, targetSurf, destRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapWorldViewBlitter::drawTileOverlay(SDL_Surface * targetSurf, const TerrainTile2 & tile) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
auto & objects = tile.objects;
|
|
|
|
for(auto & object : objects)
|
|
|
|
{
|
|
|
|
const CGObjectInstance * obj = object.first;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
if (obj->pos.z != pos.z)
|
|
|
|
continue;
|
|
|
|
if (!(*info->visibilityMap)[pos.x][pos.y][pos.z])
|
|
|
|
continue; // TODO needs to skip this check if we have artifacts-aura-like spell cast
|
|
|
|
if (!obj->visitableAt(pos.x, pos.y))
|
|
|
|
continue;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
auto &ownerRaw = obj->tempOwner;
|
|
|
|
int ownerIndex = 0;
|
|
|
|
if (ownerRaw < PlayerColor::PLAYER_LIMIT)
|
|
|
|
{
|
|
|
|
ownerIndex = ownerRaw.getNum() * 19;
|
|
|
|
}
|
|
|
|
else if (ownerRaw == PlayerColor::NEUTRAL)
|
|
|
|
{
|
|
|
|
ownerIndex = PlayerColor::PLAYER_LIMIT.getNum() * 19;
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
SDL_Surface * wvIcon = nullptr;
|
|
|
|
switch (obj->ID)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
case Obj::MONOLITH_ONE_WAY_ENTRANCE:
|
|
|
|
case Obj::MONOLITH_ONE_WAY_EXIT:
|
|
|
|
case Obj::MONOLITH_TWO_WAY:
|
|
|
|
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TELEPORT].bitmap;
|
|
|
|
break;
|
|
|
|
case Obj::SUBTERRANEAN_GATE:
|
|
|
|
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::GATE].bitmap;
|
|
|
|
break;
|
|
|
|
case Obj::ARTIFACT:
|
|
|
|
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::ARTIFACT].bitmap;
|
|
|
|
break;
|
|
|
|
case Obj::TOWN:
|
|
|
|
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::TOWN + ownerIndex].bitmap;
|
|
|
|
break;
|
|
|
|
case Obj::HERO:
|
|
|
|
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::HERO + ownerIndex].bitmap;
|
|
|
|
break;
|
|
|
|
case Obj::MINE:
|
|
|
|
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::MINE_WOOD + obj->subID + ownerIndex].bitmap;
|
|
|
|
break;
|
|
|
|
case Obj::RESOURCE:
|
|
|
|
wvIcon = info->iconsDef->ourImages[(int)EWorldViewIcon::RES_WOOD + obj->subID + ownerIndex].bitmap;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
if (wvIcon)
|
|
|
|
{
|
|
|
|
// centering icon on the object
|
|
|
|
Rect destRect(realPos.x + tileSize / 2 - wvIcon->w / 2, realPos.y + tileSize / 2 - wvIcon->h / 2, wvIcon->w, wvIcon->h);
|
|
|
|
CSDL_Ext::blitSurface(wvIcon, nullptr, targetSurf, &destRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapWorldViewBlitter::drawNormalObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
Rect scaledSourceRect(sourceRect->x * info->scale, sourceRect->y * info->scale, tileSize, tileSize);
|
|
|
|
CMapBlitter::drawNormalObject(targetSurf, sourceSurf, &scaledSourceRect);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapWorldViewBlitter::drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
if (moving)
|
|
|
|
return;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
CMapBlitter::drawHeroFlag(targetSurf, sourceSurf, sourceRect, destRect, false);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapWorldViewBlitter::drawHero(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
if (moving)
|
|
|
|
return;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
Rect scaledSourceRect(sourceRect->x * info->scale, sourceRect->y * info->scale, sourceRect->w, sourceRect->h);
|
|
|
|
CMapBlitter::drawHero(targetSurf, sourceSurf, &scaledSourceRect, false);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile2 & tile) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
Rect destRect(realTileRect);
|
2015-01-18 19:53:40 +02:00
|
|
|
if(tile.terbitmap) //if custom terrain graphic - use it
|
2015-01-19 21:08:19 +02:00
|
|
|
drawElement(EMapCacheType::TERRAIN_CUSTOM, tile.terbitmap, nullptr, targetSurf, &destRect);
|
2015-01-18 19:53:40 +02:00
|
|
|
else //use default terrain graphic
|
2015-01-19 21:08:19 +02:00
|
|
|
drawElement(EMapCacheType::TERRAIN, parent->terrainGraphics[tinfo.terType][tinfo.terView],
|
|
|
|
nullptr, targetSurf, &destRect, false, tinfo.extTileFlags % 4);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapWorldViewBlitter::init(const MapDrawingInfo * drawingInfo)
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
info = drawingInfo;
|
2015-01-18 19:53:40 +02:00
|
|
|
parent->cache.updateWorldViewScale(info->scale);
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
topTile = info->topTile;
|
|
|
|
tileSize = (int) floorf(32.0f * info->scale);
|
2015-01-19 21:08:19 +02:00
|
|
|
halfTileSizeCeil = (int)ceilf(tileSize / 2.0f);
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
tileCount.x = (int) ceilf((float)info->drawBounds->w / tileSize) + 1;
|
|
|
|
tileCount.y = (int) ceilf((float)info->drawBounds->h / tileSize) + 1;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
initPos.x = parent->offsetX + info->drawBounds->x;
|
|
|
|
initPos.y = parent->offsetY + info->drawBounds->y;
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
realTileRect = Rect(initPos.x, initPos.y, tileSize, tileSize);
|
|
|
|
defaultTileRect = Rect(0, 0, tileSize, tileSize);
|
|
|
|
|
|
|
|
calculateWorldViewCameraPos();
|
2015-01-13 21:57:41 +02:00
|
|
|
|
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
SDL_Rect CMapHandler::CMapWorldViewBlitter::clip(SDL_Surface * targetSurf) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
SDL_Rect prevClip;
|
2012-11-13 14:52:23 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
SDL_FillRect(targetSurf, info->drawBounds, SDL_MapRGB(targetSurf->format, 0, 0, 0));
|
|
|
|
// makes the clip area smaller if the map is smaller than the screen frame
|
|
|
|
Rect clipRect(std::max(info->drawBounds->x, -topTile.x * tileSize),
|
|
|
|
std::max(info->drawBounds->y, -topTile.y * tileSize),
|
|
|
|
std::min(info->drawBounds->w, parent->sizes.x * tileSize),
|
|
|
|
std::min(info->drawBounds->h, parent->sizes.y * tileSize));
|
|
|
|
SDL_GetClipRect(targetSurf, &prevClip);
|
|
|
|
SDL_SetClipRect(targetSurf, &clipRect); //preventing blitting outside of that rect
|
|
|
|
return prevClip;
|
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
CMapHandler::CMapWorldViewBlitter::CMapWorldViewBlitter(CMapHandler * parent)
|
|
|
|
: CMapBlitter(parent)
|
|
|
|
{
|
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapPuzzleViewBlitter::drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const
|
|
|
|
{
|
|
|
|
CMapBlitter::drawObjects(targetSurf, tile);
|
|
|
|
|
|
|
|
// grail X mark
|
|
|
|
if(pos.x == info->grailPos.x && pos.y == info->grailPos.y)
|
|
|
|
{
|
|
|
|
Rect destRect(realTileRect);
|
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(graphics->heroMoveArrows->ourImages[0].bitmap, nullptr, targetSurf, &destRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapPuzzleViewBlitter::postProcessing(SDL_Surface * targetSurf) const
|
|
|
|
{
|
|
|
|
CSDL_Ext::applyEffect(targetSurf, info->drawBounds, static_cast<int>(!ADVOPT.puzzleSepia));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapHandler::CMapPuzzleViewBlitter::canDrawObject(const CGObjectInstance * obj) const
|
|
|
|
{
|
|
|
|
if (!CMapBlitter::canDrawObject(obj))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//don't print flaggable objects in puzzle mode
|
|
|
|
if (obj->isVisitable())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(std::find(unblittableObjects.begin(), unblittableObjects.end(), obj->ID) != unblittableObjects.end())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMapHandler::CMapPuzzleViewBlitter::CMapPuzzleViewBlitter(CMapHandler * parent)
|
|
|
|
: CMapNormalBlitter(parent)
|
|
|
|
{
|
|
|
|
unblittableObjects.push_back(Obj::HOLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::drawFrame(SDL_Surface * targetSurf) const
|
|
|
|
{
|
|
|
|
Rect destRect(realTileRect);
|
|
|
|
drawElement(EMapCacheType::FRAME, parent->ttiles[pos.x][pos.y][topTile.z].terbitmap, nullptr, targetSurf, &destRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::drawNormalObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect) const
|
|
|
|
{
|
|
|
|
Rect destRect(realTileRect);
|
|
|
|
drawElement(EMapCacheType::OBJECTS, sourceSurf, sourceRect, targetSurf, &destRect, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const
|
|
|
|
{
|
|
|
|
drawElement(EMapCacheType::HERO_FLAGS, sourceSurf, sourceRect, targetSurf, destRect, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::drawHero(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const
|
|
|
|
{
|
|
|
|
Rect dstRect(realTileRect);
|
|
|
|
drawElement(EMapCacheType::HEROES, sourceSurf, sourceRect, targetSurf, &dstRect, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
auto & objects = tile.objects;
|
|
|
|
for(auto & object : objects)
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
const CGObjectInstance * obj = object.first;
|
|
|
|
if (!graphics->getDef(obj))
|
|
|
|
processDef(obj->appearance);
|
|
|
|
if (!graphics->getDef(obj) && !obj->appearance.animationFile.empty())
|
|
|
|
logGlobal->errorStream() << "Failed to load image " << obj->appearance.animationFile;
|
2009-06-12 06:26:41 +03:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
if (!canDrawObject(obj))
|
2015-01-18 19:53:40 +02:00
|
|
|
continue;
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
PlayerColor color = obj->tempOwner;
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
SDL_Rect pp = object.second;
|
|
|
|
pp.h = tileSize;
|
|
|
|
pp.w = tileSize;
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
const CGHeroInstance * hero = (obj->ID != Obj::HERO
|
|
|
|
? nullptr
|
|
|
|
: static_cast<const CGHeroInstance*>(obj));
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
//print hero / boat and flag
|
|
|
|
if((hero && hero->moveDir && hero->type) || (obj->ID == Obj::BOAT)) //it's hero or boat
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
const int IMGVAL = 8; //frames per group of movement animation
|
|
|
|
ui8 dir;
|
|
|
|
std::vector<Cimage> * iv = nullptr;
|
|
|
|
std::vector<CDefEssential *> Graphics::*flg = nullptr;
|
|
|
|
SDL_Surface * tb = nullptr; //surface to blitted
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
if(hero) //hero
|
2014-07-03 19:41:42 +03:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
if(hero->tempOwner >= PlayerColor::PLAYER_LIMIT) //Neutral hero?
|
|
|
|
{
|
|
|
|
logGlobal->errorStream() << "A neutral hero (" << hero->name << ") at " << hero->pos << ". Should not happen!";
|
2014-07-03 19:41:42 +03:00
|
|
|
continue;
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
dir = hero->moveDir;
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
//pick graphics of hero (or boat if hero is sailing)
|
|
|
|
if (hero->boat)
|
|
|
|
iv = &graphics->boatAnims[hero->boat->subID]->ourImages;
|
|
|
|
else
|
|
|
|
iv = &graphics->heroAnims[hero->appearance.animationFile]->ourImages;
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
//pick appropriate flag set
|
|
|
|
if(hero->boat)
|
|
|
|
{
|
|
|
|
switch (hero->boat->subID)
|
|
|
|
{
|
|
|
|
case 0: flg = &Graphics::flags1; break;
|
|
|
|
case 1: flg = &Graphics::flags2; break;
|
|
|
|
case 2: flg = &Graphics::flags3; break;
|
|
|
|
default: logGlobal->errorStream() << "Not supported boat subtype: " << hero->boat->subID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flg = &Graphics::flags4;
|
|
|
|
}
|
2012-05-11 22:03:40 +03:00
|
|
|
}
|
2015-01-18 19:53:40 +02:00
|
|
|
else //boat
|
2012-05-11 22:03:40 +03:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
const CGBoat *boat = static_cast<const CGBoat*>(obj);
|
|
|
|
dir = boat->direction;
|
|
|
|
iv = &graphics->boatAnims[boat->subID]->ourImages;
|
2012-05-11 22:03:40 +03:00
|
|
|
}
|
2015-01-18 19:53:40 +02:00
|
|
|
|
|
|
|
if(hero && !hero->isStanding) //hero is moving
|
2012-05-11 22:03:40 +03:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
size_t gg;
|
|
|
|
for(gg=0; gg<iv->size(); ++gg)
|
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
if((*iv)[gg].groupNumber == getHeroFrameNum(dir, true))
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
tb = (*iv)[gg+info->getHeroAnim()%IMGVAL].bitmap;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-19 21:08:19 +02:00
|
|
|
drawHero(targetSurf, tb, &pp, true);
|
2012-05-11 22:03:40 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
pp.y += IMGVAL * 2 - tileSize;
|
|
|
|
Rect destRect(realPos.x, realPos.y - tileSize / 2, tileSize, tileSize);
|
2015-01-19 21:08:19 +02:00
|
|
|
drawHeroFlag(targetSurf, (graphics->*flg)[color.getNum()]->ourImages[gg + info->getHeroAnim() % IMGVAL + 35].bitmap, &pp, &destRect, true);
|
2012-05-11 22:03:40 +03:00
|
|
|
|
|
|
|
}
|
2015-01-18 19:53:40 +02:00
|
|
|
else //hero / boat stands still
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
size_t gg;
|
|
|
|
for(gg=0; gg < iv->size(); ++gg)
|
2014-01-03 02:48:38 +03:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
if((*iv)[gg].groupNumber == getHeroFrameNum(dir, false))
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
tb = (*iv)[gg].bitmap;
|
|
|
|
break;
|
|
|
|
}
|
2014-01-03 02:48:38 +03:00
|
|
|
}
|
2015-01-19 21:08:19 +02:00
|
|
|
drawHero(targetSurf, tb, &pp, false);
|
2011-09-04 03:04:48 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
//printing flag
|
|
|
|
if(flg
|
|
|
|
&& obj->pos.x == pos.x
|
|
|
|
&& obj->pos.y == pos.y)
|
|
|
|
{
|
|
|
|
Rect dstRect(realPos.x - 2 * tileSize, realPos.y - tileSize, 3 * tileSize, 2 * tileSize);
|
|
|
|
if (dstRect.x - info->drawBounds->x > -tileSize * 2)
|
|
|
|
{
|
|
|
|
auto surf = (graphics->*flg)[color.getNum()]->ourImages
|
2015-01-19 21:08:19 +02:00
|
|
|
[getHeroFrameNum(dir, false) * 8 + (info->getHeroAnim() / 4) % IMGVAL].bitmap;
|
|
|
|
drawHeroFlag(targetSurf, surf, nullptr, &dstRect, false);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //blit normal object
|
|
|
|
{
|
|
|
|
const std::vector<Cimage> &ourImages = graphics->getDef(obj)->ourImages;
|
2015-01-19 21:08:19 +02:00
|
|
|
SDL_Surface *bitmap = ourImages[(info->anim + getPhaseShift(obj)) % ourImages.size()].bitmap;
|
2009-07-25 15:49:45 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
//setting appropriate flag color
|
|
|
|
if(color < PlayerColor::PLAYER_LIMIT || color==PlayerColor::NEUTRAL)
|
|
|
|
CSDL_Ext::setPlayerColor(bitmap, color);
|
2011-02-24 17:05:21 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
drawNormalObject(targetSurf, bitmap, &pp);
|
2015-01-18 19:53:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-31 18:57:15 +03:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
void CMapHandler::CMapBlitter::drawRoad(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const
|
|
|
|
{
|
|
|
|
if (tinfoUpper && tinfoUpper->roadType != ERoadType::NO_ROAD)
|
|
|
|
{
|
|
|
|
Rect source(0, tileSize / 2, tileSize, tileSize / 2);
|
|
|
|
Rect dest(realPos.x, realPos.y, tileSize, tileSize / 2);
|
|
|
|
drawElement(EMapCacheType::ROADS, parent->roadDefs[tinfoUpper->roadType - 1]->ourImages[tinfoUpper->roadDir].bitmap,
|
|
|
|
&source, targetSurf, &dest, true, (tinfoUpper->extTileFlags >> 4) % 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tinfo.roadType != ERoadType::NO_ROAD) //print road from this tile
|
|
|
|
{
|
|
|
|
Rect source(0, 0, tileSize, halfTileSizeCeil);
|
|
|
|
Rect dest(realPos.x, realPos.y + tileSize / 2, tileSize, tileSize / 2);
|
|
|
|
drawElement(EMapCacheType::ROADS, parent->roadDefs[tinfo.roadType - 1]->ourImages[tinfo.roadDir].bitmap,
|
|
|
|
&source, targetSurf, &dest, true, (tinfo.extTileFlags >> 4) % 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::drawRiver(SDL_Surface * targetSurf, const TerrainTile & tinfo) const
|
|
|
|
{
|
|
|
|
Rect destRect(realTileRect);
|
|
|
|
drawElement(EMapCacheType::RIVERS, parent->staticRiverDefs[tinfo.riverType-1]->ourImages[tinfo.riverDir].bitmap,
|
|
|
|
nullptr, targetSurf, &destRect, true, (tinfo.extTileFlags >> 2) % 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::drawFow(SDL_Surface * targetSurf) const
|
|
|
|
{
|
|
|
|
Rect destRect(realTileRect);
|
|
|
|
std::pair<SDL_Surface *, bool> hide = getVisBitmap();
|
|
|
|
drawElement(EMapCacheType::FOW, hide.first, nullptr, targetSurf, &destRect, hide.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingInfo * info)
|
2015-01-18 19:53:40 +02:00
|
|
|
{
|
|
|
|
init(info);
|
2015-01-19 21:08:19 +02:00
|
|
|
auto prevClip = clip(targetSurf);
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
pos = int3(0, 0, topTile.z);
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
for (realPos.x = initPos.x, pos.x = topTile.x; pos.x < topTile.x + tileCount.x; pos.x++, realPos.x += tileSize)
|
|
|
|
{
|
|
|
|
if (pos.x < 0 || pos.x >= parent->sizes.x)
|
|
|
|
continue;
|
2009-07-06 22:41:27 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
for (realPos.y = initPos.y, pos.y = topTile.y; pos.y < topTile.y + tileCount.y; pos.y++, realPos.y += tileSize)
|
|
|
|
{
|
|
|
|
if (pos.y < 0 || pos.y >= parent->sizes.y)
|
|
|
|
continue;
|
2009-12-22 23:53:50 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
if (!canDrawCurrentTile())
|
|
|
|
continue;
|
2009-07-19 06:10:24 +03:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
realTileRect.x = realPos.x;
|
|
|
|
realTileRect.y = realPos.y;
|
2009-07-26 06:33:13 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
const TerrainTile2 & tile = parent->ttiles[pos.x][pos.y][pos.z];
|
|
|
|
const TerrainTile & tinfo = parent->map->getTile(pos);
|
|
|
|
const TerrainTile * tinfoUpper = pos.y > 0 ? &parent->map->getTile(int3(pos.x, pos.y - 1, pos.z)) : nullptr;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
drawTileTerrain(targetSurf, tinfo, tile);
|
2015-01-18 19:53:40 +02:00
|
|
|
if (tinfo.riverType)
|
2015-01-19 21:08:19 +02:00
|
|
|
drawRiver(targetSurf, tinfo);
|
|
|
|
drawRoad(targetSurf, tinfo, tinfoUpper);
|
2011-02-23 20:21:51 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
drawObjects(targetSurf, tile);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
for (realPos.x = initPos.x, pos.x = topTile.x; pos.x < topTile.x + tileCount.x; pos.x++, realPos.x += tileSize)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
for (realPos.y = initPos.y, pos.y = topTile.y; pos.y < topTile.y + tileCount.y; pos.y++, realPos.y += tileSize)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
realTileRect.x = realPos.x;
|
|
|
|
realTileRect.y = realPos.y;
|
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
if (pos.x < 0 || pos.x >= parent->sizes.x ||
|
|
|
|
pos.y < 0 || pos.y >= parent->sizes.y)
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
drawFrame(targetSurf);
|
2009-12-22 23:53:50 +02:00
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
else
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
const TerrainTile2 & tile = parent->ttiles[pos.x][pos.y][pos.z];
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
if (!(*info->visibilityMap)[pos.x][pos.y][topTile.z])
|
|
|
|
drawFow(targetSurf);
|
2009-12-22 23:53:50 +02:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
// overlay needs to be drawn over fow, because of artifacts-aura-like spells
|
2015-01-19 21:08:19 +02:00
|
|
|
drawTileOverlay(targetSurf, tile);
|
2014-01-03 02:48:38 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
// drawDebugVisitables()
|
2014-01-03 02:48:38 +03:00
|
|
|
if (settings["session"]["showBlock"].Bool())
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
if(parent->map->getTile(int3(pos.x, pos.y, pos.z)).blocked) //temporary hiding blocked positions
|
2014-01-03 02:48:38 +03:00
|
|
|
{
|
|
|
|
static SDL_Surface * block = nullptr;
|
|
|
|
if (!block)
|
|
|
|
block = BitmapHandler::loadBitmap("blocked");
|
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
CSDL_Ext::blitSurface(block, nullptr, targetSurf, &realTileRect);
|
2014-01-03 02:48:38 +03:00
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2014-01-03 02:48:38 +03:00
|
|
|
if (settings["session"]["showVisit"].Bool())
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
if(parent->map->getTile(int3(pos.x, pos.y, pos.z)).visitable) //temporary hiding visitable positions
|
2014-01-03 02:48:38 +03:00
|
|
|
{
|
|
|
|
static SDL_Surface * visit = nullptr;
|
|
|
|
if (!visit)
|
|
|
|
visit = BitmapHandler::loadBitmap("visitable");
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
CSDL_Ext::blitSurface(visit, nullptr, targetSurf, &realTileRect);
|
2014-01-03 02:48:38 +03:00
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
// drawDebugGrid()
|
2012-05-14 19:29:06 +03:00
|
|
|
if (settings["session"]["showGrid"].Bool())
|
2009-06-14 10:02:06 +03:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
for (realPos.x = initPos.x, pos.x = topTile.x; pos.x < topTile.x + tileCount.x; pos.x++, realPos.x += tileSize)
|
2009-06-14 10:02:06 +03:00
|
|
|
{
|
2015-01-18 19:53:40 +02:00
|
|
|
for (realPos.y = initPos.y, pos.y = topTile.y; pos.y < topTile.y + tileCount.y; pos.y++, realPos.y += tileSize)
|
2012-05-14 19:29:06 +03:00
|
|
|
{
|
|
|
|
const int3 color(0x555555, 0x555555, 0x555555);
|
|
|
|
|
2015-01-18 19:53:40 +02:00
|
|
|
if (realPos.y >= info->drawBounds->y &&
|
|
|
|
realPos.y < info->drawBounds->y + info->drawBounds->h)
|
|
|
|
for(int i = 0; i < tileSize; i++)
|
|
|
|
if (realPos.x + i >= info->drawBounds->x &&
|
|
|
|
realPos.x + i < info->drawBounds->x + info->drawBounds->w)
|
|
|
|
CSDL_Ext::SDL_PutPixelWithoutRefresh(targetSurf, realPos.x + i, realPos.y, color.x, color.y, color.z);
|
|
|
|
|
|
|
|
if (realPos.x >= info->drawBounds->x &&
|
|
|
|
realPos.x < info->drawBounds->x + info->drawBounds->w)
|
|
|
|
for(int i = 0; i < tileSize; i++)
|
|
|
|
if (realPos.y + i >= info->drawBounds->y &&
|
|
|
|
realPos.y + i < info->drawBounds->y + info->drawBounds->h)
|
|
|
|
CSDL_Ext::SDL_PutPixelWithoutRefresh(targetSurf, realPos.x, realPos.y + i, color.x, color.y, color.z);
|
2012-05-14 19:29:06 +03:00
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
postProcessing(targetSurf);
|
|
|
|
|
|
|
|
SDL_SetClipRect(targetSurf, &prevClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui8 CMapHandler::CMapBlitter::getPhaseShift(const CGObjectInstance *object) const
|
|
|
|
{
|
|
|
|
auto i = parent->animationPhase.find(object);
|
|
|
|
if(i == parent->animationPhase.end())
|
2009-08-31 18:57:15 +03:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
ui8 ret = CRandomGenerator::getDefault().nextInt(254);
|
|
|
|
parent->animationPhase[object] = ret;
|
|
|
|
return ret;
|
2009-08-31 18:57:15 +03:00
|
|
|
}
|
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
return i->second;
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
bool CMapHandler::CMapBlitter::canDrawObject(const CGObjectInstance * obj) const
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
//checking if object has non-empty graphic on this tile
|
|
|
|
return obj->ID == Obj::HERO || obj->coveringAt(pos.x, pos.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapHandler::CMapBlitter::canDrawCurrentTile() const
|
|
|
|
{
|
|
|
|
const NeighborTilesInfo neighbors(pos, parent->sizes, *info->visibilityMap);
|
|
|
|
return !neighbors.areAllHidden();
|
|
|
|
}
|
2014-07-03 19:41:42 +03:00
|
|
|
|
2015-01-19 21:08:19 +02:00
|
|
|
ui8 CMapHandler::CMapBlitter::getHeroFrameNum(ui8 dir, bool isMoving) const
|
|
|
|
{
|
|
|
|
if(isMoving)
|
|
|
|
{
|
|
|
|
static const ui8 frame [] = {0xff, 10, 5, 6, 7, 8, 9, 12, 11};
|
|
|
|
return frame[dir];
|
|
|
|
}
|
|
|
|
else //if(isMoving)
|
|
|
|
{
|
|
|
|
static const ui8 frame [] = {0xff, 13, 0, 1, 2, 3, 4, 15, 14};
|
|
|
|
return frame[dir];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<SDL_Surface *, bool> CMapHandler::CMapBlitter::getVisBitmap() const
|
|
|
|
{
|
|
|
|
const NeighborTilesInfo neighborInfo(pos, parent->sizes, *info->visibilityMap);
|
|
|
|
|
|
|
|
int retBitmapID = neighborInfo.getBitmapID();// >=0 -> partial hide, <0 - full hide
|
2010-08-16 16:51:31 +03:00
|
|
|
if (retBitmapID < 0)
|
2010-06-03 08:38:59 +03:00
|
|
|
{
|
2015-01-19 21:08:19 +02:00
|
|
|
retBitmapID = - parent->hideBitmap[pos.x][pos.y][pos.z] - 1; //fully hidden
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2015-01-13 21:57:41 +02:00
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
if (retBitmapID >= 0)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-26 18:33:55 +03:00
|
|
|
return std::make_pair(graphics->FoWpartialHide->ourImages[retBitmapID].bitmap, true);
|
2010-08-16 16:51:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-26 18:33:55 +03:00
|
|
|
return std::make_pair(graphics->FoWfullHide->ourImages[-retBitmapID - 1].bitmap, false);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapHandler::printObject(const CGObjectInstance *obj)
|
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
if (!graphics->getDef(obj))
|
2014-01-03 02:48:38 +03:00
|
|
|
processDef(obj->appearance);
|
2010-03-02 22:12:32 +02:00
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
const SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap;
|
2010-10-31 00:53:41 +03:00
|
|
|
const int tilesW = bitmap->w/32;
|
|
|
|
const int tilesH = bitmap->h/32;
|
|
|
|
|
|
|
|
for(int fx=0; fx<tilesW; ++fx)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-10-31 00:53:41 +03:00
|
|
|
for(int fy=0; fy<tilesH; ++fy)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
SDL_Rect cr;
|
|
|
|
cr.w = 32;
|
|
|
|
cr.h = 32;
|
|
|
|
cr.x = fx*32;
|
|
|
|
cr.y = fy*32;
|
|
|
|
std::pair<const CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj, cr);
|
2010-10-31 00:53:41 +03:00
|
|
|
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)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-10-31 00:53:41 +03:00
|
|
|
TerrainTile2 & curt = ttiles[obj->pos.x + fx - tilesW+1][obj->pos.y + fy - tilesH+1][obj->pos.z];
|
2010-02-28 14:39:38 +02:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
auto i = curt.objects.begin();
|
2010-02-28 14:39:38 +02:00
|
|
|
for(; i != curt.objects.end(); i++)
|
2010-02-24 15:03:36 +02:00
|
|
|
{
|
2014-06-24 02:26:36 +03:00
|
|
|
if(objectBlitOrderSorter(toAdd, *i))
|
2010-02-24 15:03:36 +02:00
|
|
|
{
|
|
|
|
curt.objects.insert(i, toAdd);
|
2010-02-28 14:39:38 +02:00
|
|
|
i = curt.objects.begin(); //to validate and avoid adding it second time
|
2010-02-24 15:03:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-28 14:39:38 +02:00
|
|
|
|
|
|
|
if(i == curt.objects.end())
|
|
|
|
curt.objects.insert(i, toAdd);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2010-10-31 00:53:41 +03:00
|
|
|
} // for(int fy=0; fy<tilesH; ++fy)
|
|
|
|
} //for(int fx=0; fx<tilesW; ++fx)
|
2009-02-02 15:05:19 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMapHandler::hideObject(const CGObjectInstance *obj)
|
|
|
|
{
|
2014-01-05 16:45:44 +03:00
|
|
|
for (size_t i=0; i<map->width; i++)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-01-05 16:45:44 +03:00
|
|
|
for (size_t j=0; j<map->height; j++)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-01-05 16:45:44 +03:00
|
|
|
for (size_t k=0; k<(map->twoLevel ? 2 : 1); k++)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-01-05 16:45:44 +03:00
|
|
|
for(size_t x=0; x < ttiles[i][j][k].objects.size(); x++)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2014-01-05 16:45:44 +03:00
|
|
|
if (ttiles[i][j][k].objects[x].first->id == obj->id)
|
|
|
|
{
|
|
|
|
ttiles[i][j][k].objects.erase(ttiles[i][j][k].objects.begin() + x);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
2014-01-05 16:45:44 +03:00
|
|
|
}
|
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool CMapHandler::removeObject(CGObjectInstance *obj)
|
|
|
|
{
|
|
|
|
hideObject(obj);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::validateRectTerr(SDL_Rect * val, const SDL_Rect * ext)
|
|
|
|
{
|
|
|
|
if(ext)
|
|
|
|
{
|
|
|
|
if(val->x<0)
|
|
|
|
{
|
|
|
|
val->w += val->x;
|
|
|
|
val->x = ext->x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val->x += ext->x;
|
|
|
|
}
|
|
|
|
if(val->y<0)
|
|
|
|
{
|
|
|
|
val->h += val->y;
|
|
|
|
val->y = ext->y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val->y += ext->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(val->x+val->w > ext->x+ext->w)
|
|
|
|
{
|
|
|
|
val->w = ext->x+ext->w-val->x;
|
|
|
|
}
|
|
|
|
if(val->y+val->h > ext->y+ext->h)
|
|
|
|
{
|
|
|
|
val->h = ext->y+ext->h-val->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//for sign problems
|
|
|
|
if(val->h > 20000 || val->w > 20000)
|
|
|
|
{
|
|
|
|
val->h = val->w = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
ui8 CMapHandler::getDir(const int3 &a, const int3 &b)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
if(a.z!=b.z)
|
|
|
|
return -1; //error!
|
|
|
|
if(a.x==b.x+1 && a.y==b.y+1) //lt
|
|
|
|
return 0;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
else if(a.x==b.x && a.y==b.y+1) //t
|
|
|
|
return 1;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
else if(a.x==b.x-1 && a.y==b.y+1) //rt
|
|
|
|
return 2;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
else if(a.x==b.x-1 && a.y==b.y) //r
|
|
|
|
return 3;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
else if(a.x==b.x-1 && a.y==b.y-1) //rb
|
|
|
|
return 4;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
else if(a.x==b.x && a.y==b.y-1) //b
|
|
|
|
return 5;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
else if(a.x==b.x+1 && a.y==b.y-1) //lb
|
|
|
|
return 6;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
else if(a.x==b.x+1 && a.y==b.y) //l
|
|
|
|
return 7;
|
2009-08-17 16:08:05 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
return -2; //shouldn't happen
|
|
|
|
}
|
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
void shiftColors(SDL_Surface *img, int from, int howMany) //shifts colors in palette
|
|
|
|
{
|
|
|
|
//works with at most 16 colors, if needed more -> increase values
|
|
|
|
assert(howMany < 16);
|
|
|
|
SDL_Color palette[16];
|
|
|
|
|
|
|
|
for(int i=0; i<howMany; ++i)
|
|
|
|
{
|
|
|
|
palette[(i+1)%howMany] =img->format->palette->colors[from + i];
|
|
|
|
}
|
|
|
|
SDL_SetColors(img,palette,from,howMany);
|
|
|
|
}
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
void CMapHandler::updateWater() //shift colors in palettes of water tiles
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : terrainGraphics[7])
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
shiftColors(elem,246, 9);
|
2009-12-22 23:53:50 +02:00
|
|
|
}
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : terrainGraphics[8])
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
shiftColors(elem,229, 12);
|
|
|
|
shiftColors(elem,242, 14);
|
2009-12-22 23:53:50 +02:00
|
|
|
}
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : staticRiverDefs[0]->ourImages)
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
shiftColors(elem.bitmap,183, 12);
|
|
|
|
shiftColors(elem.bitmap,195, 6);
|
2009-12-22 23:53:50 +02:00
|
|
|
}
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : staticRiverDefs[2]->ourImages)
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
shiftColors(elem.bitmap,228, 12);
|
|
|
|
shiftColors(elem.bitmap,183, 6);
|
|
|
|
shiftColors(elem.bitmap,240, 6);
|
2009-12-22 23:53:50 +02:00
|
|
|
}
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : staticRiverDefs[3]->ourImages)
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2015-01-13 21:57:41 +02:00
|
|
|
shiftColors(elem.bitmap,240, 9);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CMapHandler::~CMapHandler()
|
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
delete graphics->FoWfullHide;
|
|
|
|
delete graphics->FoWpartialHide;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2015-01-20 21:51:09 +02:00
|
|
|
delete normalBlitter;
|
|
|
|
delete worldViewBlitter;
|
|
|
|
delete puzzleViewBlitter;
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : roadDefs)
|
|
|
|
delete elem;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : staticRiverDefs)
|
|
|
|
delete elem;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : terrainGraphics)
|
2010-01-29 18:19:12 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(int j=0; j < elem.size(); ++j)
|
|
|
|
SDL_FreeSurface(elem[j]);
|
2010-01-29 18:19:12 +02:00
|
|
|
}
|
2011-04-23 13:27:44 +03:00
|
|
|
terrainGraphics.clear();
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CMapHandler::CMapHandler()
|
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
frameW = frameH = 0;
|
2013-06-26 14:18:27 +03:00
|
|
|
graphics->FoWfullHide = nullptr;
|
|
|
|
graphics->FoWpartialHide = nullptr;
|
2015-01-18 19:53:40 +02:00
|
|
|
normalBlitter = new CMapNormalBlitter(this);
|
|
|
|
worldViewBlitter = new CMapWorldViewBlitter(this);
|
2015-01-19 21:08:19 +02:00
|
|
|
puzzleViewBlitter = new CMapPuzzleViewBlitter(this);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2010-02-21 17:03:30 +02:00
|
|
|
void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terName )
|
|
|
|
{
|
|
|
|
out.clear();
|
2010-08-16 16:51:31 +03:00
|
|
|
TerrainTile2 & tt = ttiles[pos.x][pos.y][pos.z];
|
2013-04-19 14:43:11 +03:00
|
|
|
const TerrainTile &t = map->getTile(pos);
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : tt.objects)
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
if(elem.first->ID == Obj::HOLE) //Hole
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
2014-06-24 20:39:36 +03:00
|
|
|
out = elem.first->getObjectName();
|
2010-02-21 17:03:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 23:50:25 +03:00
|
|
|
if(t.hasFavourableWinds())
|
2014-05-24 01:56:51 +03:00
|
|
|
out = CGI->objtypeh->getObjectName(Obj::FAVORABLE_WINDS);
|
2010-07-09 07:29:11 +03:00
|
|
|
else if(terName)
|
2015-01-13 21:57:41 +02:00
|
|
|
out = CGI->generaltexth->terrainNames[t.terType];
|
2010-02-21 17:03:30 +02:00
|
|
|
}
|
|
|
|
|
2015-01-13 21:57:41 +02:00
|
|
|
void CMapHandler::discardWorldViewCache()
|
|
|
|
{
|
|
|
|
cache.discardWorldViewCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapCache::discardWorldViewCache()
|
|
|
|
{
|
|
|
|
for (auto &cacheDataPair : data)
|
|
|
|
{
|
|
|
|
for (auto &cacheEntryPair : cacheDataPair.second)
|
|
|
|
{
|
|
|
|
if (cacheEntryPair.second)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(cacheEntryPair.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data[cacheDataPair.first].clear();
|
|
|
|
}
|
|
|
|
logGlobal->debugStream() << "Discarded world view cache";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapHandler::CMapCache::updateWorldViewScale(float scale)
|
|
|
|
{
|
|
|
|
if (fabs(scale - worldViewCachedScale) > 0.001f)
|
|
|
|
discardWorldViewCache();
|
|
|
|
worldViewCachedScale = scale;
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:17:26 +02:00
|
|
|
void CMapHandler::CMapCache::removeFromWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key)
|
2015-01-13 21:57:41 +02:00
|
|
|
{
|
|
|
|
auto iter = data[type].find(key);
|
|
|
|
if (iter != data[type].end())
|
|
|
|
{
|
|
|
|
SDL_FreeSurface((*iter).second);
|
|
|
|
data[type].erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:17:26 +02:00
|
|
|
SDL_Surface * CMapHandler::CMapCache::requestWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key)
|
2015-01-13 21:57:41 +02:00
|
|
|
{
|
|
|
|
auto iter = data[type].find(key);
|
|
|
|
if (iter == data[type].end())
|
|
|
|
return nullptr;
|
|
|
|
return (*iter).second;
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:17:26 +02:00
|
|
|
SDL_Surface * CMapHandler::CMapCache::requestWorldViewCacheOrCreate(CMapHandler::EMapCacheType type, intptr_t key, SDL_Surface * fullSurface, float scale)
|
2015-01-13 21:57:41 +02:00
|
|
|
{
|
|
|
|
auto cached = requestWorldViewCache(type, key);
|
|
|
|
if (cached)
|
|
|
|
return cached;
|
|
|
|
|
|
|
|
auto scaled = CSDL_Ext::scaleSurfaceFast(fullSurface, fullSurface->w * scale, fullSurface->h * scale);
|
|
|
|
return cacheWorldViewEntry(type, key, scaled);
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:17:26 +02:00
|
|
|
SDL_Surface *CMapHandler::CMapCache::cacheWorldViewEntry(CMapHandler::EMapCacheType type, intptr_t key, SDL_Surface * entry)
|
2015-01-13 21:57:41 +02:00
|
|
|
{
|
|
|
|
if (!entry)
|
|
|
|
return nullptr;
|
|
|
|
if (requestWorldViewCache(type, key)) // valid cache already present, no need to do it again
|
|
|
|
return requestWorldViewCache(type, key);
|
|
|
|
|
|
|
|
data[type][key] = entry;
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2015-01-17 00:44:40 +02:00
|
|
|
intptr_t CMapHandler::CMapCache::genKey(intptr_t realPtr, ui8 mod)
|
|
|
|
{
|
|
|
|
return (intptr_t)(realPtr ^ (mod << (sizeof(intptr_t) - 2))); // maybe some cleaner method to pack rotation into cache key?
|
|
|
|
}
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
TerrainTile2::TerrainTile2()
|
2013-06-29 16:05:48 +03:00
|
|
|
:terbitmap(nullptr)
|
2009-02-02 15:05:19 +02:00
|
|
|
{}
|
2014-06-24 02:26:36 +03:00
|
|
|
|
|
|
|
bool CMapHandler::compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b)
|
|
|
|
{
|
|
|
|
if (a->appearance.printPriority != b->appearance.printPriority)
|
|
|
|
return a->appearance.printPriority > b->appearance.printPriority;
|
|
|
|
|
|
|
|
if(a->pos.y != b->pos.y)
|
|
|
|
return a->pos.y < b->pos.y;
|
|
|
|
|
|
|
|
if(b->ID==Obj::HERO && a->ID!=Obj::HERO)
|
|
|
|
return true;
|
|
|
|
if(b->ID!=Obj::HERO && a->ID==Obj::HERO)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!a->isVisitable() && b->isVisitable())
|
|
|
|
return true;
|
|
|
|
if(!b->isVisitable() && a->isVisitable())
|
|
|
|
return false;
|
|
|
|
if(a->pos.x < b->pos.x)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-19 21:08:19 +02:00
|
|
|
|