1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* partial handling of advmap objects changing battle background (like clover field) (their existence should change the background but nothing else)

* map should be drawn faster because empty tiles are no more blitted (according to info from .msk files) - I hope it will work correctly, if not please report or turn it off if too hard to make it work
This commit is contained in:
mateuszb 2009-07-01 15:58:20 +00:00
parent 824061e185
commit 50a49460bf
7 changed files with 64 additions and 28 deletions

View File

@ -55,6 +55,7 @@ void CDefObjInfoHandler::load()
{
nobj->blockMap[o] = 0xff;
nobj->visitMap[o] = 0x00;
nobj->coverageMap[0] = 0x00;
}
inp>>mapStr;
std::reverse(mapStr.begin(), mapStr.end());
@ -100,6 +101,16 @@ void CDefObjInfoHandler::load()
}
}
inp >> nobj->printPriority;
//coverageMap calculating
std::string nameCopy = nobj->name;
std::string msk = spriteh->getTextFile(nameCopy.replace( nameCopy.size()-4, 4, ".MSK" ));
for(int i=0; i<6; ++i)
{
nobj->coverageMap[i] = msk[i+2];
}
gobjs[nobj->id][nobj->subid] = nobj;
if(nobj->id==TOWNI_TYPE)
castles[nobj->subid]=nobj;

View File

@ -23,6 +23,7 @@ public:
ui8 visitMap[6];
ui8 blockMap[6];
ui8 coverageMap[6]; //to determine which tiles are covered by picture of this object
ui8 visitDir; //directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
si32 id, subid; //of object described by this defInfo
si32 serial;
@ -43,7 +44,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & name & serial & visitMap & blockMap & visitDir & id & subid &terrainAllowed
& terrainMenu & width & height & type & printPriority;
& terrainMenu & width & height & type & printPriority & coverageMap;
}
CGDefInfo();
};

View File

@ -186,6 +186,14 @@ bool CGObjectInstance::blockingAt(int x, int y) const
return true;
return false;
}
bool CGObjectInstance::coveringAt(int x, int y) const
{
if((defInfo->coverageMap[y] >> (7-(x) )) & 1)
return true;
return false;
}
bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen printing priority comparing
{
if(defInfo->printPriority==1 && cmp.defInfo->printPriority==0)

View File

@ -126,6 +126,7 @@ public:
int getHeight() const; //returns height of object graphic in tiles
bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles)
bool blockingAt(int x, int y) const; //returns true if object is blocking location (x, y) form left top tile of image (x, y in tiles)
bool coveringAt(int x, int y) const; //returns true if object covers with picture location (x, y) form left top tile of maximal possible image (8 x 6 tiles) (x, y in tiles)
bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
CGObjectInstance();
virtual ~CGObjectInstance();

View File

@ -1343,33 +1343,37 @@ int CGameState::battleGetBattlefieldType(int3 tile)
else if(tile==int3() && !curB)
return -1;
//std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[tile.x][tile.y][tile.z].objects;
//for(int g=0; g<objs.size(); ++g)
//{
// switch(objs[g].first->ID)
// {
// case 222: //clover field
// return 19;
// case 223: //cursed ground
// return 22;
// case 224: //evil fog
// return 20;
// case 225: //favourable winds
// return 21;
// case 226: //fiery fields
// return 14;
// case 227: //holy ground
// return 18;
// case 228: //lucid pools
// return 17;
// case 229: //magic clouds
// return 16;
// case 230: //magic plains
// return 9;
// case 231: //rocklands
// return 15;
// }
//}
std::vector <CGObjectInstance*> & objs = map->objects;
for(int g=0; g<objs.size(); ++g)
{
if( objs[g]->pos.x - tile.x < 0 || objs[g]->pos.x - tile.x >= 8 || tile.y - objs[g]->pos.y + 5 < 0 || tile.y - objs[g]->pos.y + 5 >=6 ||
!objs[g]->coveringAt(objs[g]->pos.x - tile.x, tile.y - objs[g]->pos.y + 5)
) //look only for objects covering given tile
continue;
switch(objs[g]->ID)
{
case 222: //clover field
return 19;
case 223: //cursed ground
return 22;
case 224: //evil fog
return 20;
case 225: //favourable winds
return 21;
case 226: //fiery fields
return 14;
case 227: //holy ground
return 18;
case 228: //lucid pools
return 17;
case 229: //magic clouds
return 16;
case 230: //magic plains
return 9;
case 231: //rocklands
return 15;
}
}
switch(map->terrain[tile.x][tile.y][tile.z].tertype)
{

View File

@ -6,6 +6,7 @@
#include "VCMI_Lib.h"
#include <zlib.h>
#include <boost/crc.hpp>
#include "../hch/CLodHandler.h"
/*
* map.cpp, part of VCMI engine
@ -1358,6 +1359,14 @@ void Mapa::readDefInfo( unsigned char * bufor, int &i)
if(vinya->id == 26)
std::memset(vinya->blockMap,255,6);
//calculating coverageMap
std::string nameCopy = vinya->name;
std::string msk = spriteh->getTextFile(nameCopy.replace( nameCopy.size()-4, 4, ".MSK" ));
for(int i=0; i<6; ++i)
{
vinya->coverageMap[i] = msk[i+2];
}
defy.push_back(vinya); // add this def to the vector
}
}

View File

@ -762,6 +762,8 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, std::vector< st
for(int h=0; h < objects.size(); ++h)
{
if(!objects[h].first->coveringAt(objects[h].first->pos.x - (top_tile.x + bx), top_tile.y + by - objects[h].first->pos.y + 5))
continue;
SDL_Rect sr;
sr.x = srx;