mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
* minor improvements
This commit is contained in:
@ -48,26 +48,8 @@ CDefEssential::~CDefEssential()
|
||||
for(size_t i=0; i < ourImages.size(); ++i)
|
||||
SDL_FreeSurface(ourImages[i].bitmap);
|
||||
}
|
||||
// Note: this function is unused
|
||||
void CDefHandler::openDef(std::string name)
|
||||
{
|
||||
int andame;
|
||||
std::ifstream * is = new std::ifstream();
|
||||
is -> open(name.c_str(),std::ios::binary);
|
||||
is->seekg(0,std::ios::end); // na koniec
|
||||
andame = is->tellg(); // read length
|
||||
is->seekg(0,std::ios::beg); // wracamy na poczatek
|
||||
unsigned char * FDef = new unsigned char[andame]; // allocate memory
|
||||
is->read((char*)FDef, andame); // read map file to buffer
|
||||
is->close();
|
||||
delete is;
|
||||
|
||||
openFromMemory(FDef, name);
|
||||
|
||||
delete [] FDef;
|
||||
}
|
||||
|
||||
void CDefHandler::openFromMemory(unsigned char *table, std::string name)
|
||||
void CDefHandler::openFromMemory(unsigned char *table, const std::string & name)
|
||||
{
|
||||
BMPPalette palette[256];
|
||||
SDefEntry &de = * reinterpret_cast<SDefEntry *>(table);
|
||||
@ -150,8 +132,8 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const unsigned char * FDef, co
|
||||
SDL_Surface * ret=NULL;
|
||||
|
||||
unsigned int BaseOffset,
|
||||
SpriteWidth, SpriteHeight, //format sprite'a
|
||||
TotalRowLength, // dlugosc przeczytanego segmentu
|
||||
SpriteWidth, SpriteHeight, //format of sprite
|
||||
TotalRowLength, // length of read segment
|
||||
add, FullHeight,FullWidth,
|
||||
RowAdd, //, NextSpriteOffset; //TODO use me
|
||||
prSize,
|
||||
@ -393,7 +375,7 @@ CDefEssential * CDefHandler::essentialize()
|
||||
return ret;
|
||||
}
|
||||
|
||||
CDefHandler * CDefHandler::giveDef(std::string defName)
|
||||
CDefHandler * CDefHandler::giveDef(const std::string & defName)
|
||||
{
|
||||
unsigned char * data = spriteh->giveFile(defName);
|
||||
if(!data)
|
||||
@ -404,7 +386,7 @@ CDefHandler * CDefHandler::giveDef(std::string defName)
|
||||
delete [] data;
|
||||
return nh;
|
||||
}
|
||||
CDefEssential * CDefHandler::giveDefEss(std::string defName)
|
||||
CDefEssential * CDefHandler::giveDefEss(const std::string & defName)
|
||||
{
|
||||
CDefEssential * ret;
|
||||
CDefHandler * temp = giveDef(defName);
|
||||
|
@ -88,14 +88,13 @@ public:
|
||||
|
||||
CDefHandler(); //c-tor
|
||||
~CDefHandler(); //d-tor
|
||||
SDL_Surface * getSprite (int SIndex, const unsigned char * FDef, const BMPPalette * palette) const; //zapisuje klatke o zadanym numerze do "testtt.bmp"
|
||||
void openDef(std::string name);
|
||||
SDL_Surface * getSprite (int SIndex, const unsigned char * FDef, const BMPPalette * palette) const; //saves picture with given number to "testtt.bmp"
|
||||
static void expand(unsigned char N,unsigned char & BL, unsigned char & BR);
|
||||
void openFromMemory(unsigned char * table, std::string name);
|
||||
void openFromMemory(unsigned char * table, const std::string & name);
|
||||
CDefEssential * essentialize();
|
||||
|
||||
static CDefHandler * giveDef(std::string defName);
|
||||
static CDefEssential * giveDefEss(std::string defName);
|
||||
static CDefHandler * giveDef(const std::string & defName);
|
||||
static CDefEssential * giveDefEss(const std::string & defName);
|
||||
};
|
||||
|
||||
class CDefEssential //DefHandler with images only
|
||||
|
@ -234,7 +234,6 @@ CGObjectInstance::CGObjectInstance(): animPhaseShift(rand()%0xff)
|
||||
//state = new CLuaObjectScript();
|
||||
ID = subID = id = -1;
|
||||
defInfo = NULL;
|
||||
info = NULL;
|
||||
tempOwner = 254;
|
||||
blockVisit = false;
|
||||
}
|
||||
@ -448,6 +447,13 @@ ui8 CGObjectInstance::getPassableness() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CGObjectInstance::hasShadowAt( int x, int y ) const
|
||||
{
|
||||
if( (defInfo->shadowCoverage[y] >> (7-(x) )) & 1 )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int lowestSpeed(const CGHeroInstance * chi)
|
||||
{
|
||||
if(!chi->army.slots.size())
|
||||
|
@ -143,7 +143,6 @@ public:
|
||||
si32 ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
|
||||
si32 id;//number of object in CObjectHandler's vector
|
||||
CGDefInfo * defInfo;
|
||||
CSpecObjInfo * info;
|
||||
ui8 animPhaseShift;
|
||||
|
||||
ui8 tempOwner;
|
||||
@ -161,6 +160,7 @@ public:
|
||||
int3 getVisitableOffset() const; //returns (x,y,0) offset to first visitable tile from bottom right obj tile (0,0,0) (h3m pos)
|
||||
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 hasShadowAt(int x, int y) const;//returns true if object covers with shadow location (x, y) form left top tile of maximal possible image (8 x 6 tiles) (x, y in tiles)
|
||||
std::set<int3> getBlockedPos() const; //returns set of positions blocked by this object
|
||||
bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
|
||||
CGObjectInstance();
|
||||
@ -357,6 +357,7 @@ public:
|
||||
class DLL_EXPORT CGDwelling : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
CSpecObjInfo * info; //h3m info about dewlling
|
||||
std::vector<std::pair<ui32, std::vector<ui32> > > creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
|
@ -347,7 +347,6 @@ static CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
|
||||
nobj->pos = pos;
|
||||
//nobj->state = NULL;//new CLuaObjectScript();
|
||||
nobj->tempOwner = owner;
|
||||
nobj->info = NULL;
|
||||
nobj->defInfo->id = id;
|
||||
nobj->defInfo->subid = subid;
|
||||
|
||||
@ -1061,7 +1060,8 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
case 216: //random dwelling
|
||||
{
|
||||
int faction = ran()%F_NUMBER;
|
||||
CCreGen2ObjInfo* info = static_cast<CCreGen2ObjInfo*>(obj->info);
|
||||
CGDwelling * dwl = static_cast<CGDwelling*>(obj);
|
||||
CCreGen2ObjInfo* info = static_cast<CCreGen2ObjInfo*>(dwl->info);
|
||||
if (info->asCastle)
|
||||
{
|
||||
for(unsigned int i=0;i<map->objects.size();i++)
|
||||
@ -1095,11 +1095,14 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
return std::pair<int,int>(17,i);
|
||||
tlog3 << "Cannot find a dwelling for creature "<< cid << std::endl;
|
||||
return std::pair<int,int>(17,0);
|
||||
delete dwl->info;
|
||||
dwl->info = NULL;
|
||||
}
|
||||
case 217:
|
||||
{
|
||||
int faction = ran()%F_NUMBER;
|
||||
CCreGenObjInfo* info = static_cast<CCreGenObjInfo*>(obj->info);
|
||||
CGDwelling * dwl = static_cast<CGDwelling*>(obj);
|
||||
CCreGenObjInfo* info = static_cast<CCreGenObjInfo*>(dwl->info);
|
||||
if (info->asCastle)
|
||||
{
|
||||
for(unsigned int i=0;i<map->objects.size();i++)
|
||||
@ -1132,10 +1135,13 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
return std::pair<int,int>(17,i);
|
||||
tlog3 << "Cannot find a dwelling for creature "<<cid <<std::endl;
|
||||
return std::pair<int,int>(17,0);
|
||||
delete dwl->info;
|
||||
dwl->info = NULL;
|
||||
}
|
||||
case 218:
|
||||
{
|
||||
CCreGen3ObjInfo* info = static_cast<CCreGen3ObjInfo*>(obj->info);
|
||||
CGDwelling * dwl = static_cast<CGDwelling*>(obj);
|
||||
CCreGen3ObjInfo* info = static_cast<CCreGen3ObjInfo*>(dwl->info);
|
||||
int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel));
|
||||
int cid = VLC->townh->towns[obj->subID].basicCreatures[level];
|
||||
for(unsigned int i=0;i<VLC->objh->cregens.size();i++)
|
||||
@ -1143,6 +1149,8 @@ std::pair<int,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
return std::pair<int,int>(17,i);
|
||||
tlog3 << "Cannot find a dwelling for creature "<<cid <<std::endl;
|
||||
return std::pair<int,int>(17,0);
|
||||
delete dwl->info;
|
||||
dwl->info = NULL;
|
||||
}
|
||||
}
|
||||
return std::pair<int,int>(-1,-1);
|
||||
|
@ -1756,7 +1756,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i)
|
||||
spec->asCastle = true;
|
||||
}
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
static_cast<CGDwelling*>(nobj)->info = spec;
|
||||
break;
|
||||
}
|
||||
case 216:
|
||||
@ -1778,7 +1778,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i)
|
||||
spec->minLevel = bufor[i]; ++i;
|
||||
spec->maxLevel = bufor[i]; ++i;
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
static_cast<CGDwelling*>(nobj)->info = spec;
|
||||
break;
|
||||
}
|
||||
case 218:
|
||||
@ -1794,7 +1794,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i)
|
||||
if(spec->minLevel<1)
|
||||
spec->minLevel = 1;
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
static_cast<CGDwelling*>(nobj)->info = spec;
|
||||
break;
|
||||
}
|
||||
case 215:
|
||||
|
@ -438,7 +438,7 @@ void CMapHandler::init()
|
||||
for (int i = 0; i < 8 ; i++)
|
||||
{
|
||||
TerrainTile2 &t = ttiles[24+i][0][0];
|
||||
tlog0 << t.objects.front().first->defInfo->name << ' ';
|
||||
//tlog0 << t.objects.front().first->defInfo->name << ' ';
|
||||
|
||||
}
|
||||
}
|
||||
@ -665,7 +665,10 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, const std::vect
|
||||
if(color < 8 || color==255)
|
||||
CSDL_Ext::setPlayerColor(bitmap, color);
|
||||
|
||||
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
|
||||
SDL_BlitSurface(bitmap,&pp,extSurf,&sr2);
|
||||
}
|
||||
}
|
||||
//objects blitted
|
||||
@ -1150,7 +1153,9 @@ unsigned char CMapHandler::getHeroFrameNum(unsigned char dir, bool isMoving) con
|
||||
{
|
||||
if(isMoving)
|
||||
{
|
||||
switch(dir)
|
||||
static const unsigned char frame [] = {-1, 10, 5, 6, 7, 8, 9, 12, 11};
|
||||
return frame[dir];
|
||||
/*switch(dir)
|
||||
{
|
||||
case 1:
|
||||
return 10;
|
||||
@ -1170,11 +1175,13 @@ unsigned char CMapHandler::getHeroFrameNum(unsigned char dir, bool isMoving) con
|
||||
return 11;
|
||||
default:
|
||||
throw std::string("Something very wrong1.");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else //if(isMoving)
|
||||
{
|
||||
switch(dir)
|
||||
static const unsigned char frame [] = {-1, 13, 0, 1, 2, 3, 4, 15, 14};
|
||||
return frame[dir];
|
||||
/*switch(dir)
|
||||
{
|
||||
case 1:
|
||||
return 13;
|
||||
@ -1194,7 +1201,7 @@ unsigned char CMapHandler::getHeroFrameNum(unsigned char dir, bool isMoving) con
|
||||
return 14;
|
||||
default:
|
||||
throw std::string("Something very wrong2.");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user