1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

* a voodoo fix of a mysterious bug

This commit is contained in:
mateuszb
2010-12-27 10:48:28 +00:00
parent 471c23ba71
commit 8104a43809
3 changed files with 34 additions and 25 deletions

View File

@ -249,12 +249,12 @@ void CMapHandler::initObjectRects()
|| obj->ID==HEROI_TYPE && static_cast<const CGHeroInstance*>(obj)->inTownGarrison //garrisoned hero || 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->ID==8 && static_cast<const CGBoat*>(obj)->hero //boat wih hero (hero graphics is used)
|| !obj->defInfo || !obj->defInfo
|| !graphics->getDef(obj)) //no graphic... || !obj->defInfo->handler) //no graphic...
{ {
continue; continue;
} }
const SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap; const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap;
for(int fx=0; fx<bitmap->w>>5; ++fx) //bitmap->w/32 for(int fx=0; fx<bitmap->w>>5; ++fx) //bitmap->w/32
{ {
for(int fy=0; fy<bitmap->h>>5; ++fy) //bitmap->h/32 for(int fy=0; fy<bitmap->h>>5; ++fy) //bitmap->h/32
@ -298,57 +298,63 @@ static void processDef (const CGDefInfo* def)
{ {
if(def->id == EVENTI_TYPE) if(def->id == EVENTI_TYPE)
{ {
graphics->advmapobjGraphics[def->id][def->subid] = NULL;
return; return;
} }
CDefEssential * ourDef = graphics->getDef(def); if(!def->handler) //if object has already set handler (eg. heroes) it should not be overwritten
if(!ourDef) //if object has already set handler (eg. heroes) it should not be overwritten
{ {
if(def->name.size()) if(def->name.size())
{ {
if(vstd::contains(graphics->mapObjectDefs, def->name)) if(vstd::contains(graphics->mapObjectDefs, def->name))
{ {
graphics->advmapobjGraphics[def->id][def->subid] = graphics->mapObjectDefs[def->name]; const_cast<CGDefInfo*>(def)->handler = graphics->mapObjectDefs[def->name];
} }
else else
{ {
graphics->mapObjectDefs[def->name] = graphics->advmapobjGraphics[def->id][def->subid] = CDefHandler::giveDefEss(def->name); graphics->mapObjectDefs[def->name] = const_cast<CGDefInfo*>(def)->handler = CDefHandler::giveDefEss(def->name);
} }
} }
else else
{ {
tlog2 << "No def name for " << def->id << " " << def->subid << std::endl; tlog2 << "No def name for " << def->id << " " << def->subid << std::endl;
const_cast<CGDefInfo*>(def)->handler = NULL;
return; return;
} }
// def->width = def->handler->ourImages[0].bitmap->w/32; const_cast<CGDefInfo*>(def)->width = def->handler->ourImages[0].bitmap->w/32;
// def->height = def->handler->ourImages[0].bitmap->h/32; const_cast<CGDefInfo*>(def)->height = def->handler->ourImages[0].bitmap->h/32;
} }
ourDef = graphics->getDef(def); 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;
//alpha transformation //alpha transformation
for(size_t yy=0; yy < ourDef->ourImages.size(); ++yy) for(size_t yy=0; yy < def->handler->ourImages.size(); ++yy)
{ {
CSDL_Ext::alphaTransform(ourDef->ourImages[yy].bitmap); CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap);
} }
} }
void CMapHandler::initHeroDef(const CGHeroInstance * h) void CMapHandler::initHeroDef(const CGHeroInstance * h)
{ {
graphics->advmapobjGraphics[h->defInfo->id][h->defInfo->subid] = graphics->flags1[0]; h->defInfo->handler = graphics->flags1[0];
// h->defInfo->width =graphics->getDef(h)->ourImages[0].bitmap->w/32; h->defInfo->width = h->defInfo->handler->ourImages[0].bitmap->w/32;
// h->defInfo->height = graphics->getDef(h)->ourImages[0].bitmap->h/32; h->defInfo->height = h->defInfo->handler->ourImages[0].bitmap->h/32;
} }
void CMapHandler::init() void CMapHandler::init()
{ {
timeHandler th; timeHandler th;
th.getDif(); th.getDif();
graphics->advmapobjGraphics[8][0] = graphics->boatAnims[0]; const_cast<CGameInfo*>(CGI)->dobjinfo->gobjs[8][0]->handler = graphics->boatAnims[0];
graphics->advmapobjGraphics[8][1] = graphics->boatAnims[1]; const_cast<CGameInfo*>(CGI)->dobjinfo->gobjs[8][1]->handler = graphics->boatAnims[1];
graphics->advmapobjGraphics[8][2] = graphics->boatAnims[2]; const_cast<CGameInfo*>(CGI)->dobjinfo->gobjs[8][2]->handler = graphics->boatAnims[2];
// Size of visible terrain. // Size of visible terrain.
int mapW = conf.go()->ac.advmapW; int mapW = conf.go()->ac.advmapW;
@ -381,7 +387,7 @@ void CMapHandler::init()
for(int i=0;i<map->heroes.size();i++) for(int i=0;i<map->heroes.size();i++)
{ {
if( !graphics->getDef(map->heroes[i]) ) if( !map->heroes[i]->defInfo->handler )
{ {
initHeroDef(map->heroes[i]); initHeroDef(map->heroes[i]);
} }
@ -633,7 +639,7 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim,
} }
else //blit normal object else //blit normal object
{ {
const std::vector<Cimage> &ourImages = graphics->getDef(obj)->ourImages; const std::vector<Cimage> &ourImages = obj->defInfo->handler->ourImages;
SDL_Surface *bitmap = ourImages[(anim+obj->animPhaseShift)%ourImages.size()].bitmap; SDL_Surface *bitmap = ourImages[(anim+obj->animPhaseShift)%ourImages.size()].bitmap;
//setting appropriate flag color //setting appropriate flag color
@ -820,10 +826,10 @@ std::pair<SDL_Surface *, bool> CMapHandler::getVisBitmap( const int3 & pos, cons
bool CMapHandler::printObject(const CGObjectInstance *obj) bool CMapHandler::printObject(const CGObjectInstance *obj)
{ {
if(!graphics->getDef(obj)) if(!obj->defInfo->handler)
processDef(obj->defInfo); processDef(obj->defInfo);
const SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap; const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap;
const int tilesW = bitmap->w/32; const int tilesW = bitmap->w/32;
const int tilesH = bitmap->h/32; const int tilesH = bitmap->h/32;
@ -864,7 +870,7 @@ bool CMapHandler::printObject(const CGObjectInstance *obj)
bool CMapHandler::hideObject(const CGObjectInstance *obj) bool CMapHandler::hideObject(const CGObjectInstance *obj)
{ {
CDefEssential * curd = graphics->getDef(obj); CDefEssential * curd = obj->defInfo->handler;
if(!curd) return false; if(!curd) return false;
const SDL_Surface *bitmap = curd->ourImages[0].bitmap; const SDL_Surface *bitmap = curd->ourImages[0].bitmap;
for(int fx=0; fx<bitmap->w/32; ++fx) for(int fx=0; fx<bitmap->w/32; ++fx)

View File

@ -30,6 +30,7 @@ bool CGDefInfo::isVisitable() const
} }
CGDefInfo::CGDefInfo() CGDefInfo::CGDefInfo()
{ {
handler = NULL;
visitDir = (8|16|32|64|128); //4,5,6,7,8 - any not-from-up direction visitDir = (8|16|32|64|128); //4,5,6,7,8 - any not-from-up direction
width = height = -1; width = height = -1;
@ -58,6 +59,7 @@ void CDefObjInfoHandler::load()
for(int hh=0; hh<objNumber; ++hh) for(int hh=0; hh<objNumber; ++hh)
{ {
CGDefInfo* nobj = new CGDefInfo(); CGDefInfo* nobj = new CGDefInfo();
nobj->handler = NULL;
std::string dump; std::string dump;
inp>>nobj->name; inp>>nobj->name;

View File

@ -29,6 +29,7 @@ public:
si32 id, subid; //of object described by this defInfo si32 id, subid; //of object described by this defInfo
si32 terrainAllowed, //on which terrain it is possible to place object si32 terrainAllowed, //on which terrain it is possible to place object
terrainMenu; //in which menus in map editor object will be showed terrainMenu; //in which menus in map editor object will be showed
CDefEssential * handler;
si32 width, height; //tiles si32 width, height; //tiles
si32 type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources) si32 type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources)
si32 printPriority; si32 printPriority;