diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index 3d2c18960..b6121bb26 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -249,12 +249,12 @@ void CMapHandler::initObjectRects() || obj->ID==HEROI_TYPE && static_cast(obj)->inTownGarrison //garrisoned hero || obj->ID==8 && static_cast(obj)->hero //boat wih hero (hero graphics is used) || !obj->defInfo - || !graphics->getDef(obj)) //no graphic... + || !obj->defInfo->handler) //no graphic... { 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; fxw>>5; ++fx) //bitmap->w/32 { for(int fy=0; fyh>>5; ++fy) //bitmap->h/32 @@ -298,57 +298,63 @@ static void processDef (const CGDefInfo* def) { if(def->id == EVENTI_TYPE) { - graphics->advmapobjGraphics[def->id][def->subid] = NULL; return; } - CDefEssential * ourDef = graphics->getDef(def); - - if(!ourDef) //if object has already set handler (eg. heroes) it should not be overwritten + if(!def->handler) //if object has already set handler (eg. heroes) it should not be overwritten { if(def->name.size()) { if(vstd::contains(graphics->mapObjectDefs, def->name)) { - graphics->advmapobjGraphics[def->id][def->subid] = graphics->mapObjectDefs[def->name]; + const_cast(def)->handler = graphics->mapObjectDefs[def->name]; } else { - graphics->mapObjectDefs[def->name] = graphics->advmapobjGraphics[def->id][def->subid] = CDefHandler::giveDefEss(def->name); + graphics->mapObjectDefs[def->name] = const_cast(def)->handler = CDefHandler::giveDefEss(def->name); } } else { tlog2 << "No def name for " << def->id << " " << def->subid << std::endl; + const_cast(def)->handler = NULL; return; } -// def->width = def->handler->ourImages[0].bitmap->w/32; -// def->height = def->handler->ourImages[0].bitmap->h/32; + const_cast(def)->width = def->handler->ourImages[0].bitmap->w/32; + const_cast(def)->height = def->handler->ourImages[0].bitmap->h/32; } - - ourDef = graphics->getDef(def); + + CGDefInfo* pom = const_cast(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 - 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) { - graphics->advmapobjGraphics[h->defInfo->id][h->defInfo->subid] = graphics->flags1[0]; -// h->defInfo->width =graphics->getDef(h)->ourImages[0].bitmap->w/32; -// h->defInfo->height = graphics->getDef(h)->ourImages[0].bitmap->h/32; + 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; } void CMapHandler::init() { timeHandler th; th.getDif(); - graphics->advmapobjGraphics[8][0] = graphics->boatAnims[0]; - graphics->advmapobjGraphics[8][1] = graphics->boatAnims[1]; - graphics->advmapobjGraphics[8][2] = graphics->boatAnims[2]; + const_cast(CGI)->dobjinfo->gobjs[8][0]->handler = graphics->boatAnims[0]; + const_cast(CGI)->dobjinfo->gobjs[8][1]->handler = graphics->boatAnims[1]; + const_cast(CGI)->dobjinfo->gobjs[8][2]->handler = graphics->boatAnims[2]; // Size of visible terrain. int mapW = conf.go()->ac.advmapW; @@ -381,7 +387,7 @@ void CMapHandler::init() for(int i=0;iheroes.size();i++) { - if( !graphics->getDef(map->heroes[i]) ) + if( !map->heroes[i]->defInfo->handler ) { initHeroDef(map->heroes[i]); } @@ -633,7 +639,7 @@ void CMapHandler::terrainRect(int3 top_tile, unsigned char anim, } else //blit normal object { - const std::vector &ourImages = graphics->getDef(obj)->ourImages; + const std::vector &ourImages = obj->defInfo->handler->ourImages; SDL_Surface *bitmap = ourImages[(anim+obj->animPhaseShift)%ourImages.size()].bitmap; //setting appropriate flag color @@ -820,10 +826,10 @@ std::pair CMapHandler::getVisBitmap( const int3 & pos, cons bool CMapHandler::printObject(const CGObjectInstance *obj) { - if(!graphics->getDef(obj)) + if(!obj->defInfo->handler) 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 tilesH = bitmap->h/32; @@ -864,7 +870,7 @@ bool CMapHandler::printObject(const CGObjectInstance *obj) bool CMapHandler::hideObject(const CGObjectInstance *obj) { - CDefEssential * curd = graphics->getDef(obj); + CDefEssential * curd = obj->defInfo->handler; if(!curd) return false; const SDL_Surface *bitmap = curd->ourImages[0].bitmap; for(int fx=0; fxw/32; ++fx) diff --git a/lib/CDefObjInfoHandler.cpp b/lib/CDefObjInfoHandler.cpp index a9af113b2..40e5f4801 100644 --- a/lib/CDefObjInfoHandler.cpp +++ b/lib/CDefObjInfoHandler.cpp @@ -30,6 +30,7 @@ bool CGDefInfo::isVisitable() const } CGDefInfo::CGDefInfo() { + handler = NULL; visitDir = (8|16|32|64|128); //4,5,6,7,8 - any not-from-up direction width = height = -1; @@ -58,6 +59,7 @@ void CDefObjInfoHandler::load() for(int hh=0; hhhandler = NULL; std::string dump; inp>>nobj->name; diff --git a/lib/CDefObjInfoHandler.h b/lib/CDefObjInfoHandler.h index f4d9a038d..a3d15c3ec 100644 --- a/lib/CDefObjInfoHandler.h +++ b/lib/CDefObjInfoHandler.h @@ -29,6 +29,7 @@ public: si32 id, subid; //of object described by this defInfo si32 terrainAllowed, //on which terrain it is possible to place object terrainMenu; //in which menus in map editor object will be showed + CDefEssential * handler; si32 width, height; //tiles si32 type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources) si32 printPriority;