2010-04-06 11:59:24 +03:00
|
|
|
#include "../stdafx.h"
|
2009-02-02 15:05:19 +02:00
|
|
|
#include "mapHandler.h"
|
2010-04-06 11:59:24 +03:00
|
|
|
#include "SDL_Extensions.h"
|
|
|
|
#include "CGameInfo.h"
|
2009-02-02 15:05:19 +02:00
|
|
|
#include <cstdlib>
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CLodHandler.h"
|
|
|
|
#include "../lib/CDefObjInfoHandler.h"
|
2009-02-02 15:05:19 +02:00
|
|
|
#include <algorithm>
|
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"
|
2009-02-02 15:05:19 +02:00
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CObjectHandler.h"
|
2010-04-06 11:59:24 +03:00
|
|
|
#include "../lib/map.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CDefHandler.h"
|
2010-04-06 11:59:24 +03:00
|
|
|
#include "CConfigHandler.h"
|
2009-08-17 16:08:05 +03:00
|
|
|
#include <boost/assign/list_of.hpp>
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
2009-04-15 17:03:31 +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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
extern SDL_Surface * screen;
|
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
|
|
|
{
|
2009-05-07 20:20:41 +03:00
|
|
|
switch(static_cast<TerrainTile::EterrainType>(typ))
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::dirt:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("DIRTTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::sand:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("SANDTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::grass:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("GRASTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::snow:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("SNOWTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::swamp:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("SWMPTL.DEF");
|
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::rough:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("ROUGTL.DEF");
|
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::subterranean:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("SUBBTL.DEF");
|
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::lava:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("LAVATL.DEF");
|
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::water:
|
2009-02-02 15:05:19 +02:00
|
|
|
return std::string("WATRTL.DEF");
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
case TerrainTile::rock:
|
2009-07-25 19:35:47 +03:00
|
|
|
return std::string("ROCKTL.DEF");
|
|
|
|
|
|
|
|
case TerrainTile::border:
|
|
|
|
//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
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
struct OCM_HLP
|
|
|
|
{
|
|
|
|
bool operator ()(const std::pair<const CGObjectInstance*, SDL_Rect> & a, const std::pair<const CGObjectInstance*, SDL_Rect> & b)
|
|
|
|
{
|
|
|
|
return (*a.first)<(*b.first);
|
|
|
|
}
|
|
|
|
} ocmptwo ;
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
// void alphaTransformDef(CGDefInfo * defInfo)
|
|
|
|
// {
|
|
|
|
// for(int yy=0; yy<defInfo->handler->ourImages.size(); ++yy)
|
|
|
|
// {
|
|
|
|
// CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap);
|
|
|
|
// }
|
|
|
|
// }
|
2009-07-25 19:35:47 +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
|
2010-08-16 16:51:31 +03:00
|
|
|
static const int missRot [] = {22, 15, 2, 13, 12, 16, 18, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27, 28};
|
2009-07-25 19:35:47 +03:00
|
|
|
|
|
|
|
Cimage nw;
|
|
|
|
for(int g=0; g<ARRAY_COUNT(missRot); ++g)
|
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
nw = graphics->FoWpartialHide->ourImages[missRot[g]];
|
2009-07-25 19:35:47 +03:00
|
|
|
nw.bitmap = CSDL_Ext::rotate01(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
|
2010-08-16 16:51:31 +03:00
|
|
|
for(size_t i=0; i<graphics->FoWpartialHide->ourImages.size(); ++i)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
CSDL_Ext::alphaTransform(graphics->FoWpartialHide->ourImages[i].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);
|
2009-02-02 15:05:19 +02:00
|
|
|
for (size_t i=0;i<hideBitmap.size();i++)
|
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
hideBitmap[i].resize(sizes.y);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
for (size_t i=0; i<hideBitmap.size(); ++i)
|
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
for (int j=0; j < sizes.y; ++j)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
hideBitmap[i][j].resize(sizes.z);
|
|
|
|
for(int k=0; k<sizes.z; ++k)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
hideBitmap[i][j][k] = rand()%graphics->FoWfullHide->ourImages.size();
|
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"));
|
2009-02-02 15:05:19 +02:00
|
|
|
for(size_t g=0; g<staticRiverDefs.size(); ++g)
|
|
|
|
{
|
|
|
|
for(size_t h=0; h < staticRiverDefs[g]->ourImages.size(); ++h)
|
|
|
|
{
|
|
|
|
CSDL_Ext::alphaTransform(staticRiverDefs[g]->ourImages[h].bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(size_t g=0; g<roadDefs.size(); ++g)
|
|
|
|
{
|
|
|
|
for(size_t h=0; h < roadDefs[g]->ourImages.size(); ++h)
|
|
|
|
{
|
|
|
|
CSDL_Ext::alphaTransform(roadDefs[g]->ourImages[h].bitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-12 06:26:41 +03:00
|
|
|
// Create enough room for the whole map and its frame
|
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
|
|
|
}
|
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
// prepare the map
|
2010-08-16 16:51:31 +03:00
|
|
|
for (int i=0; i<sizes.x; i++) //by width
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
for (int j=0; j<sizes.y;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 levels
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
TerrainTile2 &pom(ttiles[i][j][k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
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;
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(j == -1 && i > -1 && i < sizes.y)
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 22+rand()%2;
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(i == -1 && j > -1 && j < sizes.y)
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 33+rand()%2;
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(j == sizes.y && i >-1 && i < sizes.x)
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 29+rand()%2;
|
2010-08-16 16:51:31 +03:00
|
|
|
else if(i == sizes.x && j > -1 && j < sizes.y)
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = 25+rand()%2;
|
2009-02-02 15:05:19 +02:00
|
|
|
else
|
2009-08-17 16:08:05 +03:00
|
|
|
terBitmapNum = rand()%16;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
void CMapHandler::initObjectRects()
|
|
|
|
{
|
|
|
|
//initializing objects / rects
|
|
|
|
for(size_t f=0; f < map->objects.size(); ++f)
|
|
|
|
{
|
2009-08-01 13:08:16 +03:00
|
|
|
const CGObjectInstance *obj = map->objects[f];
|
|
|
|
if( !obj
|
|
|
|
|| obj->ID==HEROI_TYPE && static_cast<const CGHeroInstance*>(obj)->inTownGarrison //garrisoned hero
|
|
|
|
|| obj->ID==8 && static_cast<const CGBoat*>(obj)->hero //boat wih hero (hero graphics is used)
|
|
|
|
|| !obj->defInfo
|
2010-12-27 12:48:28 +02:00
|
|
|
|| !obj->defInfo->handler) //no graphic...
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2009-06-11 06:57:21 +03:00
|
|
|
|
2010-12-27 12:48:28 +02:00
|
|
|
const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap;
|
2009-08-01 13:08:16 +03:00
|
|
|
for(int fx=0; fx<bitmap->w>>5; ++fx) //bitmap->w/32
|
|
|
|
{
|
|
|
|
for(int fy=0; fy<bitmap->h>>5; ++fy) //bitmap->h/32
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-08-01 13:08:16 +03:00
|
|
|
SDL_Rect cr;
|
|
|
|
cr.w = 32;
|
|
|
|
cr.h = 32;
|
|
|
|
cr.x = fx<<5; //fx*32
|
|
|
|
cr.y = fy<<5; //fy*32
|
|
|
|
std::pair<const CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj,cr);
|
|
|
|
|
|
|
|
if( (obj->pos.x + fx - bitmap->w/32+1) >= 0
|
|
|
|
&& (obj->pos.x + fx - bitmap->w/32+1) < ttiles.size() - frameW
|
|
|
|
&& (obj->pos.y + fy - bitmap->h/32+1) >= 0
|
|
|
|
&& (obj->pos.y + fy - bitmap->h/32+1) < ttiles[0].size() - frameH
|
|
|
|
)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-08-01 13:08:16 +03:00
|
|
|
//TerrainTile2 & curt =
|
|
|
|
// ttiles
|
|
|
|
// [obj->pos.x + fx - bitmap->w/32]
|
|
|
|
//[obj->pos.y + fy - bitmap->h/32]
|
|
|
|
//[obj->pos.z];
|
|
|
|
ttiles[obj->pos.x + fx - bitmap->w/32+1][obj->pos.y + fy - bitmap->h/32+1][obj->pos.z].objects.push_back(toAdd);
|
|
|
|
}
|
|
|
|
} // for(int fy=0; fy<bitmap->h/32; ++fy)
|
|
|
|
} //for(int fx=0; fx<bitmap->w/32; ++fx)
|
2009-02-02 15:05:19 +02:00
|
|
|
} // for(int f=0; f<map->objects.size(); ++f)
|
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)
|
|
|
|
{
|
|
|
|
stable_sort(ttiles[ix][iy][iz].objects.begin(), ttiles[ix][iy][iz].objects.end(), ocmptwo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 15:04:24 +02:00
|
|
|
static void processDef (const CGDefInfo* def)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-02-10 04:56:00 +02:00
|
|
|
if(def->id == EVENTI_TYPE)
|
2010-12-19 16:39:56 +02:00
|
|
|
{
|
2009-02-02 15:05:19 +02:00
|
|
|
return;
|
2010-12-19 16:39:56 +02:00
|
|
|
}
|
2009-07-25 19:35:47 +03:00
|
|
|
|
2010-12-27 12:48:28 +02:00
|
|
|
if(!def->handler) //if object has already set handler (eg. heroes) it should not be overwritten
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
if(def->name.size())
|
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
if(vstd::contains(graphics->mapObjectDefs, def->name))
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
const_cast<CGDefInfo*>(def)->handler = graphics->mapObjectDefs[def->name];
|
2010-02-21 17:03:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
graphics->mapObjectDefs[def->name] = const_cast<CGDefInfo*>(def)->handler = CDefHandler::giveDefEss(def->name);
|
2010-02-21 17:03:30 +02:00
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tlog2 << "No def name for " << def->id << " " << def->subid << std::endl;
|
2010-12-27 12:48:28 +02:00
|
|
|
const_cast<CGDefInfo*>(def)->handler = NULL;
|
2009-02-02 15:05:19 +02:00
|
|
|
return;
|
|
|
|
}
|
2010-02-21 17:03:30 +02:00
|
|
|
|
2010-12-27 12:48:28 +02:00
|
|
|
const_cast<CGDefInfo*>(def)->width = def->handler->ourImages[0].bitmap->w/32;
|
|
|
|
const_cast<CGDefInfo*>(def)->height = def->handler->ourImages[0].bitmap->h/32;
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2010-12-27 12:48:28 +02:00
|
|
|
|
|
|
|
CGDefInfo* pom = const_cast<CGameInfo*>(CGI)->dobjinfo->gobjs[def->id][def->subid];
|
|
|
|
if(pom && def->id!=TOWNI_TYPE)
|
|
|
|
{
|
|
|
|
pom->handler = def->handler;
|
|
|
|
pom->width = pom->handler->ourImages[0].bitmap->w/32;
|
|
|
|
pom->height = pom->handler->ourImages[0].bitmap->h/32;
|
|
|
|
}
|
|
|
|
else if(def->id != HEROI_TYPE && def->id != TOWNI_TYPE)
|
|
|
|
tlog3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl;
|
2010-12-19 16:39:56 +02:00
|
|
|
|
2009-07-25 19:35:47 +03:00
|
|
|
//alpha transformation
|
2010-12-27 12:48:28 +02:00
|
|
|
for(size_t yy=0; yy < def->handler->ourImages.size(); ++yy)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
2010-12-20 15:04:24 +02:00
|
|
|
void CMapHandler::initHeroDef(const CGHeroInstance * h)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
h->defInfo->handler = graphics->flags1[0];
|
|
|
|
h->defInfo->width = h->defInfo->handler->ourImages[0].bitmap->w/32;
|
|
|
|
h->defInfo->height = h->defInfo->handler->ourImages[0].bitmap->h/32;
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
void CMapHandler::init()
|
|
|
|
{
|
|
|
|
timeHandler th;
|
|
|
|
th.getDif();
|
|
|
|
|
2010-12-27 12:48:28 +02:00
|
|
|
const_cast<CGameInfo*>(CGI)->dobjinfo->gobjs[8][0]->handler = graphics->boatAnims[0];
|
|
|
|
const_cast<CGameInfo*>(CGI)->dobjinfo->gobjs[8][1]->handler = graphics->boatAnims[1];
|
|
|
|
const_cast<CGameInfo*>(CGI)->dobjinfo->gobjs[8][2]->handler = graphics->boatAnims[2];
|
2009-07-31 23:10:22 +03:00
|
|
|
|
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;
|
|
|
|
sizes.z = map->twoLevel+1;
|
2009-06-14 10:02:06 +03:00
|
|
|
|
|
|
|
// Total number of visible tiles. Substract the center tile, then
|
|
|
|
// 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
|
|
|
for(int i=0;i<map->heroes.size();i++)
|
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
if( !map->heroes[i]->defInfo->handler )
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
initHeroDef(map->heroes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs
|
|
|
|
tlog0<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
|
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
//it seems to be completely unnecessary and useless
|
|
|
|
// for(int i=0;i<PLAYER_LIMIT;i++)
|
|
|
|
// {
|
|
|
|
// for(size_t j=0; j < map->players[i].heroesNames.size(); ++j)
|
|
|
|
// {
|
|
|
|
// usedHeroes.insert(map->players[i].heroesNames[j].heroID);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// tlog0<<"\tChecking used heroes: "<<th.getDif()<<std::endl;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareFOWDefs();
|
|
|
|
roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
|
|
|
|
borderAndTerrainBitmapInit();
|
|
|
|
tlog0<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
|
|
|
|
initObjectRects();
|
|
|
|
tlog0<<"\tMaking object rects: "<<th.getDif()<<std::endl;
|
2010-02-21 17:03:30 +02:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
// Update map window screen
|
|
|
|
// top_tile top left tile to draw. Not necessarily visible.
|
|
|
|
// extRect, extRect = map window on screen
|
|
|
|
// moveX, moveY: when a hero is in movement indicates how to shift the map. Range is -31 to + 31.
|
2010-12-17 20:47:07 +02:00
|
|
|
void CMapHandler::terrainRect(int3 top_tile, unsigned char anim,
|
|
|
|
const std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap,
|
|
|
|
bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect,
|
|
|
|
int moveX, int moveY, bool puzzleMode) const
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
// Width and height of the portion of the map to process. Units in tiles.
|
|
|
|
unsigned int dx = tilesW;
|
|
|
|
unsigned int dy = tilesH;
|
|
|
|
|
|
|
|
// Basic rectangle for a tile. Should be a const but conflicts with SDL headers
|
|
|
|
SDL_Rect rtile = { 0, 0, 32, 32 };
|
|
|
|
|
|
|
|
// Absolute coords of the first pixel in the top left corner
|
|
|
|
int srx_init = offsetX + extRect->x;
|
|
|
|
int sry_init = offsetY + extRect->y;
|
|
|
|
|
|
|
|
int srx, sry; // absolute screen coordinates in pixels
|
|
|
|
|
|
|
|
// If moving, we need to add an extra column/line
|
2009-12-22 23:53:50 +02:00
|
|
|
if (moveX != 0)
|
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
dx++;
|
|
|
|
srx_init += moveX;
|
2009-12-22 23:53:50 +02:00
|
|
|
if (moveX > 0)
|
|
|
|
{
|
2009-06-20 18:57:53 +03:00
|
|
|
// Moving right. We still need to draw the old tile on the
|
|
|
|
// left, so adjust our referential
|
2009-06-14 10:02:06 +03:00
|
|
|
top_tile.x --;
|
|
|
|
srx_init -= 32;
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 06:26:41 +03:00
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
if (moveY != 0)
|
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
dy++;
|
|
|
|
sry_init += moveY;
|
2009-12-22 23:53:50 +02:00
|
|
|
if (moveY > 0)
|
|
|
|
{
|
2009-06-20 18:57:53 +03:00
|
|
|
// Moving down. We still need to draw the tile on the top,
|
|
|
|
// so adjust our referential.
|
2009-06-14 10:02:06 +03:00
|
|
|
top_tile.y --;
|
|
|
|
sry_init -= 32;
|
|
|
|
}
|
|
|
|
}
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
// Reduce sizes if we go out of the full map.
|
|
|
|
if (top_tile.x < -frameW)
|
|
|
|
top_tile.x = -frameW;
|
|
|
|
if (top_tile.y < -frameH)
|
|
|
|
top_tile.y = -frameH;
|
2010-08-16 16:51:31 +03:00
|
|
|
if (top_tile.x + dx > sizes.x + frameW)
|
|
|
|
dx = sizes.x + frameW - top_tile.x;
|
|
|
|
if (top_tile.y + dy > sizes.y + frameH)
|
|
|
|
dy = sizes.y + frameH - top_tile.y;
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
if(!otherHeroAnim)
|
|
|
|
heroAnim = anim; //the same, as it should be
|
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
SDL_Rect prevClip;
|
|
|
|
SDL_GetClipRect(extSurf, &prevClip);
|
|
|
|
SDL_SetClipRect(extSurf, extRect); //preventing blitting outside of that rect
|
2009-06-06 20:43:36 +03:00
|
|
|
|
2010-08-05 14:02:18 +03:00
|
|
|
const BlitterWithRotationVal blitterWithRotation = CSDL_Ext::getBlitterWithRotation(extSurf);
|
2010-08-05 14:47:57 +03:00
|
|
|
const BlitterWithRotationVal blitterWithRotationAndAlpha = CSDL_Ext::getBlitterWithRotationAndAlpha(extSurf);
|
2010-08-05 14:02:18 +03:00
|
|
|
//const BlitterWithRotationAndAlphaVal blitterWithRotation = CSDL_Ext::getBlitterWithRotation(extSurf);
|
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
// printing terrain
|
|
|
|
srx = srx_init;
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
for (int bx = 0; bx < dx; bx++, srx+=32)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
// Skip column if not in map
|
2010-08-16 16:51:31 +03:00
|
|
|
if (top_tile.x+bx < 0 || top_tile.x+bx >= sizes.x)
|
2009-06-14 10:02:06 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
sry = sry_init;
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
for (int by=0; by < dy; by++, sry+=32)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-12-22 23:53:50 +02:00
|
|
|
int3 pos(top_tile.x+bx, top_tile.y+by, top_tile.z); //blitted tile position
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
// Skip tile if not in map
|
2010-08-16 16:51:31 +03:00
|
|
|
if (pos.y < 0 || pos.y >= sizes.y)
|
2009-06-14 10:02:06 +03:00
|
|
|
continue;
|
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
const TerrainTile2 & tile = ttiles[pos.x][pos.y][pos.z];
|
2010-08-16 16:51:31 +03:00
|
|
|
const TerrainTile &tinfo = map->terrain[pos.x][pos.y][pos.z];
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
SDL_Rect sr;
|
2009-06-06 22:07:51 +03:00
|
|
|
sr.x=srx;
|
|
|
|
sr.y=sry;
|
|
|
|
sr.h=sr.w=32;
|
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
//blit terrain with river/road
|
|
|
|
if(tile.terbitmap) //if custom terrain graphic - use it
|
2010-08-26 15:06:36 +03:00
|
|
|
CSDL_Ext::blitSurface(tile.terbitmap, &genRect(sr.h, sr.w, 0, 0), extSurf, &sr);
|
2009-12-22 23:53:50 +02:00
|
|
|
else //use default terrain graphic
|
2010-08-05 14:02:18 +03:00
|
|
|
blitterWithRotation(terrainGraphics[tinfo.tertype][tinfo.terview],rtile, extSurf, sr, tinfo.siodmyTajemniczyBajt%4);
|
2009-12-22 23:53:50 +02:00
|
|
|
if(tinfo.nuine) //print river if present
|
2010-08-05 14:47:57 +03:00
|
|
|
blitterWithRotationAndAlpha(staticRiverDefs[tinfo.nuine-1]->ourImages[tinfo.rivDir].bitmap,rtile, extSurf, sr, (tinfo.siodmyTajemniczyBajt>>2)%4);
|
2009-12-22 23:53:50 +02:00
|
|
|
if(tinfo.malle) //print road if present
|
2010-08-05 14:47:57 +03:00
|
|
|
blitterWithRotationAndAlpha(roadDefs[tinfo.malle-1]->ourImages[tinfo.roadDir].bitmap,rtile, extSurf, sr, (tinfo.siodmyTajemniczyBajt>>4)%4);
|
2009-12-22 23:53:50 +02:00
|
|
|
|
|
|
|
//blit objects
|
|
|
|
const std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > &objects = tile.objects;
|
2009-06-14 10:02:06 +03:00
|
|
|
for(int h=0; h < objects.size(); ++h)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
const CGObjectInstance *obj = objects[h].first;
|
|
|
|
ui8 color = obj->tempOwner;
|
2009-12-22 23:53:50 +02:00
|
|
|
|
2009-07-25 15:49:45 +03:00
|
|
|
//checking if object has non-empty graphic on this tile
|
2009-07-27 15:29:10 +03:00
|
|
|
if(obj->ID != HEROI_TYPE && !obj->coveringAt(obj->pos.x - (top_tile.x + bx), top_tile.y + by - obj->pos.y + 5))
|
2009-07-01 18:58:20 +03:00
|
|
|
continue;
|
2009-07-25 15:49:45 +03:00
|
|
|
|
2009-08-31 18:57:15 +03:00
|
|
|
//don't print flaggable objects in puzzle mode
|
|
|
|
if(puzzleMode && obj->tempOwner != 254)
|
|
|
|
continue;
|
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
SDL_Rect sr2(sr);
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
SDL_Rect pp = objects[h].second;
|
2009-02-02 15:05:19 +02:00
|
|
|
pp.h = sr.h;
|
|
|
|
pp.w = sr.w;
|
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
const CGHeroInstance * themp = (obj->ID != HEROI_TYPE
|
2009-07-06 22:41:27 +03:00
|
|
|
? NULL
|
2009-07-26 06:33:13 +03:00
|
|
|
: static_cast<const CGHeroInstance*>(obj));
|
2009-07-06 22:41:27 +03:00
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
//print hero / boat and flag
|
|
|
|
if(themp && themp->moveDir && themp->type || obj->ID == 8) //it's hero or boat
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
const int IMGVAL = 8; //frames per group of movement animation
|
|
|
|
ui8 dir;
|
|
|
|
std::vector<Cimage> * iv = NULL;
|
2009-07-19 06:10:24 +03:00
|
|
|
std::vector<CDefEssential *> Graphics::*flg = NULL;
|
2009-07-26 06:33:13 +03:00
|
|
|
SDL_Surface * tb; //surface to blitted
|
2009-12-22 23:53:50 +02:00
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
if(themp) //hero
|
2009-07-19 06:10:24 +03:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
dir = themp->moveDir;
|
|
|
|
|
|
|
|
//pick graphics of hero (or boat if hero is sailing)
|
|
|
|
iv = (themp->boat)
|
|
|
|
? &graphics->boatAnims[themp->boat->subID]->ourImages
|
|
|
|
: &graphics->heroAnims[themp->type->heroType]->ourImages;
|
|
|
|
|
|
|
|
//pick appropriate flag set
|
|
|
|
if(themp->boat)
|
2009-07-19 06:10:24 +03:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
switch (themp->boat->subID)
|
|
|
|
{
|
|
|
|
case 0: flg = &Graphics::flags1; break;
|
|
|
|
case 1: flg = &Graphics::flags2; break;
|
|
|
|
case 2: flg = &Graphics::flags3; break;
|
|
|
|
default: tlog1 << "Not supported boat subtype: " << themp->boat->subID << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flg = &Graphics::flags4;
|
2009-07-19 06:10:24 +03:00
|
|
|
}
|
|
|
|
}
|
2009-07-26 06:33:13 +03:00
|
|
|
else //boat
|
2009-07-19 06:10:24 +03:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
const CGBoat *boat = static_cast<const CGBoat*>(obj);
|
|
|
|
dir = boat->direction;
|
|
|
|
iv = &graphics->boatAnims[boat->subID]->ourImages;
|
2009-07-19 06:10:24 +03:00
|
|
|
}
|
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
|
|
|
|
if(themp && !themp->isStanding) //hero is moving
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-07-06 22:41:27 +03:00
|
|
|
size_t gg;
|
2009-07-26 06:33:13 +03:00
|
|
|
for(gg=0; gg<iv->size(); ++gg)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
if((*iv)[gg].groupNumber==getHeroFrameNum(dir, true))
|
2009-07-06 22:41:27 +03:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
tb = (*iv)[gg+heroAnim%IMGVAL].bitmap;
|
2009-07-06 22:41:27 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2009-12-22 23:53:50 +02:00
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,extSurf,&sr2);
|
2009-07-25 19:35:47 +03:00
|
|
|
|
|
|
|
//printing flag
|
2009-07-26 06:33:13 +03:00
|
|
|
pp.y+=IMGVAL*2-32;
|
2009-12-22 23:53:50 +02:00
|
|
|
sr2.y-=16;
|
2010-08-26 15:06:36 +03:00
|
|
|
CSDL_Ext::blitSurface((graphics->*flg)[color]->ourImages[gg+heroAnim%IMGVAL+35].bitmap, &pp, extSurf, &sr2);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2009-07-26 06:33:13 +03:00
|
|
|
else //hero / boat stands still
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-07-06 22:41:27 +03:00
|
|
|
size_t gg;
|
2009-07-26 06:33:13 +03:00
|
|
|
for(gg=0; gg < iv->size(); ++gg)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
if((*iv)[gg].groupNumber==getHeroFrameNum(dir, false))
|
2009-07-06 22:41:27 +03:00
|
|
|
{
|
2009-07-26 06:33:13 +03:00
|
|
|
tb = (*iv)[gg].bitmap;
|
2009-07-06 22:41:27 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2009-12-22 23:53:50 +02:00
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,extSurf,&sr2);
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2009-07-25 19:35:47 +03:00
|
|
|
//printing flag
|
2009-07-26 06:33:13 +03:00
|
|
|
if(flg
|
|
|
|
&& obj->pos.x == top_tile.x + bx
|
|
|
|
&& obj->pos.y == top_tile.y + by)
|
2009-07-06 22:41:27 +03:00
|
|
|
{
|
2009-12-22 23:53:50 +02:00
|
|
|
SDL_Rect bufr = sr2;
|
2009-07-06 22:41:27 +03:00
|
|
|
bufr.x-=2*32;
|
|
|
|
bufr.y-=1*32;
|
|
|
|
bufr.h = 64;
|
|
|
|
bufr.w = 96;
|
|
|
|
if(bufr.x-extRect->x>-64)
|
2010-08-26 15:06:36 +03:00
|
|
|
CSDL_Ext::blitSurface((graphics->*flg)[color]->ourImages[getHeroFrameNum(dir, false) *8+(heroAnim/4)%IMGVAL].bitmap, NULL, extSurf, &bufr);
|
2009-07-06 22:41:27 +03:00
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-26 06:33:13 +03:00
|
|
|
else //blit normal object
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
const std::vector<Cimage> &ourImages = obj->defInfo->handler->ourImages;
|
2009-06-06 20:33:26 +03:00
|
|
|
SDL_Surface *bitmap = ourImages[(anim+obj->animPhaseShift)%ourImages.size()].bitmap;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
|
|
|
//setting appropriate flag color
|
2009-07-26 06:33:13 +03:00
|
|
|
if(color < 8 || color==255)
|
|
|
|
CSDL_Ext::setPlayerColor(bitmap, color);
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2010-02-21 20:07:24 +02:00
|
|
|
if( obj->hasShadowAt(obj->pos.x - (top_tile.x + bx), top_tile.y + by - obj->pos.y + 5) )
|
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(bitmap,&pp,extSurf,&sr2);
|
|
|
|
else
|
2010-08-26 15:06:36 +03:00
|
|
|
CSDL_Ext::blitSurface(bitmap,&pp,extSurf,&sr2);
|
2009-08-31 18:57:15 +03:00
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
2009-12-22 23:53:50 +02:00
|
|
|
//objects blitted
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
2009-12-22 23:53:50 +02:00
|
|
|
// terrain printed
|
|
|
|
|
2009-06-06 22:07:51 +03:00
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
// printing borders
|
|
|
|
srx = srx_init;
|
|
|
|
|
|
|
|
for (int bx = 0; bx < dx; bx++, srx+=32)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
sry = sry_init;
|
|
|
|
|
|
|
|
for (int by = 0; by<dy; by++, sry+=32)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-12-22 23:53:50 +02:00
|
|
|
int3 pos(top_tile.x+bx, top_tile.y+by, top_tile.z); //blitted tile position
|
|
|
|
|
|
|
|
SDL_Rect sr;
|
|
|
|
sr.x=srx;
|
|
|
|
sr.y=sry;
|
|
|
|
sr.h=sr.w=32;
|
2009-06-14 10:02:06 +03:00
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
if (pos.x < 0 || pos.x >= sizes.x ||
|
|
|
|
pos.y < 0 || pos.y >= sizes.y)
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
|
|
|
|
|
2010-08-26 15:06:36 +03:00
|
|
|
CSDL_Ext::blitSurface(ttiles[pos.x][pos.y][top_tile.z].terbitmap,
|
2009-06-14 10:02:06 +03:00
|
|
|
&genRect(sr.h, sr.w, 0, 0),extSurf,&sr);
|
2009-12-22 23:53:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//blitting Fog of War
|
2010-02-18 16:09:16 +02:00
|
|
|
if (!puzzleMode)
|
2009-12-22 23:53:50 +02:00
|
|
|
{
|
2010-02-18 16:09:16 +02:00
|
|
|
if (pos.x >= 0 &&
|
|
|
|
pos.y >= 0 &&
|
2010-08-16 16:51:31 +03:00
|
|
|
pos.x < sizes.x &&
|
|
|
|
pos.y < sizes.y &&
|
2010-02-18 16:09:16 +02:00
|
|
|
!(*visibilityMap)[pos.x][pos.y][top_tile.z])
|
|
|
|
{
|
2010-08-26 18:33:55 +03:00
|
|
|
std::pair<SDL_Surface *, bool> hide = getVisBitmap(pos, *visibilityMap);
|
|
|
|
if(hide.second)
|
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(hide.first, &rtile, extSurf, &sr);
|
|
|
|
else
|
|
|
|
CSDL_Ext::blitSurface(hide.first, &rtile, extSurf, &sr);
|
2010-02-18 16:09:16 +02:00
|
|
|
}
|
2009-12-22 23:53:50 +02:00
|
|
|
}
|
2010-02-18 16:09:16 +02:00
|
|
|
|
2009-12-22 23:53:50 +02:00
|
|
|
//FoW blitted
|
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
// TODO: these should be activable by the console
|
2009-02-02 15:05:19 +02:00
|
|
|
#ifdef MARK_BLOCKED_POSITIONS
|
2010-08-16 16:51:31 +03:00
|
|
|
if(map->terrain[pos.x][pos.y][top_tile.z].blocked) //temporary hiding blocked positions
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
SDL_Rect sr;
|
|
|
|
|
2009-06-14 18:53:40 +03:00
|
|
|
sr.x=srx;
|
|
|
|
sr.y=sry;
|
|
|
|
sr.h=sr.w=32;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2009-06-14 18:53:40 +03:00
|
|
|
memset(rSurf->pixels, 128, rSurf->pitch * rSurf->h);
|
2010-08-26 15:06:36 +03:00
|
|
|
CSDL_Ext::blitSurface(rSurf,&genRect(sr.h, sr.w, 0, 0),extSurf,&sr);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MARK_VISITABLE_POSITIONS
|
2010-08-16 16:51:31 +03:00
|
|
|
if(map->terrain[pos.x][pos.y][top_tile.z].visitable) //temporary hiding visitable positions
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
SDL_Rect sr;
|
|
|
|
|
2009-06-14 18:53:40 +03:00
|
|
|
sr.x=srx;
|
|
|
|
sr.y=sry;
|
|
|
|
sr.h=sr.w=32;
|
2009-02-02 15:05:19 +02:00
|
|
|
|
2009-06-14 18:53:40 +03:00
|
|
|
memset(rSurf->pixels, 128, rSurf->pitch * rSurf->h);
|
2010-08-26 15:06:36 +03:00
|
|
|
CSDL_Ext::blitSurface(rSurf,&genRect(sr.h, sr.w, 0, 0),extSurf,&sr);
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-14 10:02:06 +03:00
|
|
|
// borders printed
|
|
|
|
|
2009-06-14 18:53:40 +03:00
|
|
|
#ifdef MARK_GRID_POSITIONS
|
2009-06-14 10:02:06 +03:00
|
|
|
// print grid
|
|
|
|
// TODO: This option should be activated by the console.
|
|
|
|
srx = srx_init;
|
|
|
|
|
|
|
|
for (int bx = 0; bx < dx; bx++, srx+=32)
|
|
|
|
{
|
|
|
|
sry = sry_init;
|
|
|
|
|
|
|
|
for (int by = 0; by<dy; by++, sry+=32)
|
|
|
|
{
|
|
|
|
SDL_Rect sr;
|
|
|
|
|
|
|
|
sr.x=srx;
|
|
|
|
sr.y=sry;
|
|
|
|
sr.h=sr.w=32;
|
|
|
|
|
|
|
|
const int3 color(0x555555, 0x555555, 0x555555);
|
|
|
|
|
|
|
|
if (sr.y >= extRect->y &&
|
|
|
|
sr.y < extRect->y+extRect->h)
|
|
|
|
for(int i=0;i<sr.w;i++)
|
|
|
|
if (sr.x+i >= extRect->x &&
|
|
|
|
sr.x+i < extRect->x+extRect->w)
|
|
|
|
CSDL_Ext::SDL_PutPixelWithoutRefresh(extSurf,sr.x+i,sr.y,color.x,color.y,color.z);
|
|
|
|
|
|
|
|
if (sr.x >= extRect->x &&
|
|
|
|
sr.x < extRect->x+extRect->w)
|
|
|
|
for(int i=0; i<sr.h;i++)
|
|
|
|
if (sr.y+i >= extRect->y &&
|
|
|
|
sr.y+i < extRect->y+extRect->h)
|
|
|
|
CSDL_Ext::SDL_PutPixelWithoutRefresh(extSurf,sr.x,sr.y+i,color.x,color.y,color.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// grid
|
|
|
|
#endif
|
|
|
|
|
2009-08-31 18:57:15 +03:00
|
|
|
//applying sepia / gray effect
|
|
|
|
if(puzzleMode)
|
|
|
|
{
|
2010-08-17 15:48:34 +03:00
|
|
|
CSDL_Ext::applyEffect(extSurf, extRect, static_cast<int>(!ADVOPT.puzzleSepia));
|
2009-08-31 18:57:15 +03:00
|
|
|
}
|
|
|
|
//sepia / gray effect applied
|
|
|
|
|
2009-06-14 10:02:06 +03:00
|
|
|
SDL_SetClipRect(extSurf, &prevClip); //restoring clip_rect
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:47:07 +02:00
|
|
|
std::pair<SDL_Surface *, bool> CMapHandler::getVisBitmap( const int3 & pos, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap ) const
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
static const int visBitmaps[256] = {-1, 34, -1, 4, 22, 22, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, 3, 25, 12, 12, 3, 25, 12, 12,
|
|
|
|
9, 9, 6, 6, 9, 9, 6, 6, 35, 34, 4, 4, 22, 22, 4, 4, 36, 36, 38, 38, 47, 47, 38, 38, 26, 49, 28, 28, 26, 49, 28,
|
|
|
|
28, 9, 9, 6, 6, 9, 9, 6, 6, -3, 0, -3, 4, 0, 0, 4, 4, 37, 37, 7, 7, 50, 50, 7, 7, 13, 27, 44, 44, 13, 27, 44,
|
|
|
|
44, 8,8, 10, 10, 8, 8, 10, 10, 0, 0, 4, 4, 0, 0, 4, 4, 37, 37, 7, 7, 50, 50, 7, 7, 13, 27, 44, 44, 13, 27, 44,
|
|
|
|
44, 8, 8, 10, 10, 8, 8, 10, 10, 15, 15, 4, 4, 22, 22, 4, 4, 46, 46, 51, 51, 32, 32, 51, 51, 2, 25, 12, 12, 2,
|
|
|
|
25, 12, 12, 9, 9, 6, 6, 9, 9, 6, 6, 15, 15, 4, 4, 22, 22, 4, 4, 46, 46, 51, 51, 32, 32, 51, 51, 26, 49, 28, 28,
|
|
|
|
26, 49, 28, 28, 9, 9, 6, 6, 9, 9, 6, 6, 0, 0, 4, 4, 0, 0, 4, 4, 37, 37, 7, 7, 50, 50, 7, 7, 13, 27, 44, 44, 13,
|
|
|
|
27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10, 0, 0, 4, 4, 0, 0, 4, 4, 37, 37, 7, 7, 50, 50, 7, 7, 13, 27, 44, 44, 13,
|
|
|
|
27, 44, 44, 8, 8, 10, 10, 8, 8, 10, 10};
|
|
|
|
|
|
|
|
|
|
|
|
//is tile visible. arrangement: (like num keyboard)
|
|
|
|
bool d7 = (pos.x>0 && pos.y>0) ? visibilityMap[pos.x-1][pos.y-1][pos.z] : 0, //789
|
|
|
|
d8 = (pos.y>0) ? visibilityMap[pos.x][pos.y-1][pos.z] : 0, //456
|
2010-08-18 13:37:43 +03:00
|
|
|
d9 = (pos.y>0 && pos.x<sizes.x-1) ? visibilityMap[pos.x+1][pos.y-1][pos.z] : 0, //123
|
2010-08-16 16:51:31 +03:00
|
|
|
d4 = (pos.x>0) ? visibilityMap[pos.x-1][pos.y][pos.z] : 0,
|
|
|
|
//d5 = visibilityMap[pos.x][y][pos.z], //TODO use me - OMFG
|
2010-08-18 13:37:43 +03:00
|
|
|
d6 = (pos.x<sizes.x-1) ? visibilityMap[pos.x+1][pos.y][pos.z] : 0,
|
|
|
|
d1 = (pos.x>0 && pos.y<sizes.y-1) ? visibilityMap[pos.x-1][pos.y+1][pos.z] : 0,
|
|
|
|
d2 = (pos.y<sizes.y-1) ? visibilityMap[pos.x][pos.y+1][pos.z] : 0,
|
|
|
|
d3 = (pos.x<sizes.x-1 && pos.y<sizes.y-1) ? visibilityMap[pos.x+1][pos.y+1][pos.z] : 0;
|
2010-08-16 16:51:31 +03:00
|
|
|
|
|
|
|
int retBitmapID = visBitmaps[d1 + d2 * 2 + d3 * 4 + d4 * 8 + d6 * 16 + d7 * 32 + d8 * 64 + d9 * 128]; // >=0 -> partial hide, <0 - full hide
|
|
|
|
if (retBitmapID < 0)
|
2010-06-03 08:38:59 +03:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
retBitmapID = - hideBitmap[pos.x][pos.y][pos.z] - 1; //fully hidden
|
2009-02-02 15:05:19 +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)
|
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
if(!obj->defInfo->handler)
|
2010-03-02 22:12:32 +02:00
|
|
|
processDef(obj->defInfo);
|
|
|
|
|
2010-12-27 12:48:28 +02:00
|
|
|
const SDL_Surface *bitmap = obj->defInfo->handler->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
|
|
|
|
|
|
|
std::vector< std::pair<const CGObjectInstance*,SDL_Rect> >::iterator i = curt.objects.begin();
|
|
|
|
for(; i != curt.objects.end(); i++)
|
2010-02-24 15:03:36 +02:00
|
|
|
{
|
|
|
|
OCM_HLP cmp;
|
|
|
|
if(cmp(toAdd, *i))
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2010-12-27 12:48:28 +02:00
|
|
|
CDefEssential * curd = obj->defInfo->handler;
|
2009-04-15 02:29:26 +03:00
|
|
|
if(!curd) return false;
|
2009-06-11 06:57:21 +03:00
|
|
|
const SDL_Surface *bitmap = curd->ourImages[0].bitmap;
|
|
|
|
for(int fx=0; fx<bitmap->w/32; ++fx)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-06-11 06:57:21 +03:00
|
|
|
for(int fy=0; fy<bitmap->h/32; ++fy)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
if((obj->pos.x + fx - bitmap->w/32+1)>=0 && (obj->pos.x + fx - bitmap->w/32+1)<ttiles.size()-frameW && (obj->pos.y + fy - bitmap->h/32+1)>=0 && (obj->pos.y + fy - bitmap->h/32+1)<ttiles[0].size()-frameH)
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
2009-06-11 06:57:21 +03:00
|
|
|
std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & ctile = ttiles[obj->pos.x + fx - bitmap->w/32+1][obj->pos.y + fy - bitmap->h/32+1][obj->pos.z].objects;
|
2009-02-02 15:05:19 +02:00
|
|
|
for(size_t dd=0; dd < ctile.size(); ++dd)
|
|
|
|
{
|
|
|
|
if(ctile[dd].first->id==obj->id)
|
|
|
|
ctile.erase(ctile.begin() + dd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-11 06:57:21 +03:00
|
|
|
} // for(int fy=0; fy<bitmap->h/32; ++fy)
|
|
|
|
} //for(int fx=0; fx<bitmap->w/32; ++fx)
|
2009-02-02 15:05:19 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool CMapHandler::removeObject(CGObjectInstance *obj)
|
|
|
|
{
|
|
|
|
hideObject(obj);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-25 19:35:47 +03:00
|
|
|
unsigned char CMapHandler::getHeroFrameNum(unsigned char dir, bool isMoving) const
|
2009-02-02 15:05:19 +02:00
|
|
|
{
|
|
|
|
if(isMoving)
|
|
|
|
{
|
2010-02-21 20:07:24 +02:00
|
|
|
static const unsigned char frame [] = {-1, 10, 5, 6, 7, 8, 9, 12, 11};
|
|
|
|
return frame[dir];
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
else //if(isMoving)
|
|
|
|
{
|
2010-02-21 20:07:24 +02:00
|
|
|
static const unsigned char frame [] = {-1, 13, 0, 1, 2, 3, 4, 15, 14};
|
|
|
|
return frame[dir];
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char CMapHandler::getDir(const int3 &a, const int3 &b)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2009-12-22 23:53:50 +02:00
|
|
|
for(size_t j=0; j < terrainGraphics[7].size(); ++j)
|
|
|
|
{
|
|
|
|
shiftColors(terrainGraphics[7][j],246, 9);
|
|
|
|
}
|
2009-02-02 15:05:19 +02:00
|
|
|
for(size_t j=0; j < terrainGraphics[8].size(); ++j)
|
|
|
|
{
|
2009-12-22 23:53:50 +02:00
|
|
|
shiftColors(terrainGraphics[8][j],229, 12);
|
|
|
|
shiftColors(terrainGraphics[8][j],242, 14);
|
|
|
|
}
|
|
|
|
for(size_t j=0; j < staticRiverDefs[0]->ourImages.size(); ++j)
|
|
|
|
{
|
|
|
|
shiftColors(staticRiverDefs[0]->ourImages[j].bitmap,183, 12);
|
|
|
|
shiftColors(staticRiverDefs[0]->ourImages[j].bitmap,195, 6);
|
|
|
|
}
|
|
|
|
for(size_t j=0; j < staticRiverDefs[2]->ourImages.size(); ++j)
|
|
|
|
{
|
|
|
|
shiftColors(staticRiverDefs[2]->ourImages[j].bitmap,228, 12);
|
|
|
|
shiftColors(staticRiverDefs[2]->ourImages[j].bitmap,183, 6);
|
|
|
|
shiftColors(staticRiverDefs[2]->ourImages[j].bitmap,240, 6);
|
|
|
|
}
|
|
|
|
for(size_t j=0; j < staticRiverDefs[3]->ourImages.size(); ++j)
|
|
|
|
{
|
|
|
|
shiftColors(staticRiverDefs[3]->ourImages[j].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
|
|
|
|
|
|
|
for(int i=0; i < roadDefs.size(); i++)
|
|
|
|
delete roadDefs[i];
|
|
|
|
|
|
|
|
for(int i=0; i < staticRiverDefs.size(); i++)
|
|
|
|
delete staticRiverDefs[i];
|
|
|
|
|
2010-01-29 18:19:12 +02:00
|
|
|
//TODO: why this code makes VCMI crash?
|
|
|
|
/*for(int i=0; i < terrainGraphics.size(); ++i)
|
|
|
|
{
|
|
|
|
for(int j=0; j < terrainGraphics[i].size(); ++j)
|
|
|
|
SDL_FreeSurface(terrainGraphics[i][j]);
|
|
|
|
}
|
|
|
|
terrainGraphics.clear();*/
|
2009-02-02 15:05:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CMapHandler::CMapHandler()
|
|
|
|
{
|
2009-06-14 10:02:06 +03:00
|
|
|
frameW = frameH = 0;
|
2010-08-16 16:51:31 +03:00
|
|
|
graphics->FoWfullHide = NULL;
|
|
|
|
graphics->FoWpartialHide = NULL;
|
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];
|
|
|
|
const TerrainTile &t = map->terrain[pos.x][pos.y][pos.z];
|
|
|
|
for(std::vector < std::pair<const CGObjectInstance*,SDL_Rect> >::const_iterator i = tt.objects.begin(); i != tt.objects.end(); i++)
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
2010-07-09 07:29:11 +03:00
|
|
|
if(i->first->ID == 124) //Hole
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
|
|
|
out = i->first->hoverName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
if(t.siodmyTajemniczyBajt & 128)
|
2010-07-09 07:29:11 +03:00
|
|
|
out = CGI->generaltexth->names[225]; //Favourable Winds
|
|
|
|
else if(terName)
|
2010-08-16 16:51:31 +03:00
|
|
|
out = CGI->generaltexth->terrainNames[t.tertype];
|
2010-02-21 17:03:30 +02:00
|
|
|
}
|
|
|
|
|
2009-02-02 15:05:19 +02:00
|
|
|
TerrainTile2::TerrainTile2()
|
2010-08-16 16:51:31 +03:00
|
|
|
:terbitmap(0)
|
2009-02-02 15:05:19 +02:00
|
|
|
{}
|