From 5b836f428a92d5b4b71986d45af9589f486965c3 Mon Sep 17 00:00:00 2001 From: "ori.bar" Date: Sun, 4 Sep 2011 00:04:48 +0000 Subject: [PATCH] Partial fix for 37. Full fix for 27, 64, 600. Fix for bug where code tried to reload non existent file. --- client/CAdvmapInterface.cpp | 132 ++++++++++++++++++++++++------------ client/CAdvmapInterface.h | 31 ++++++--- client/CBattleInterface.cpp | 35 +++++----- client/CBattleInterface.h | 4 +- client/Graphics.cpp | 4 +- client/Graphics.h | 2 +- client/mapHandler.cpp | 59 +++++++--------- lib/CDefObjInfoHandler.cpp | 2 - lib/CDefObjInfoHandler.h | 1 - lib/CGameState.cpp | 29 ++++---- lib/IGameCallback.cpp | 13 ++++ lib/IGameCallback.h | 1 + 12 files changed, 183 insertions(+), 130 deletions(-) diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index aabb24e87..410f86b29 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -56,7 +56,7 @@ using namespace CSDL_Ext; CAdvMapInt *adventureInt; -CMinimap::CMinimap(bool draw) +CMinimap::CMinimap() { OBJ_CONSTRUCTION_CAPTURING_ALL; used = LCLICK | RCLICK | HOVER; @@ -93,39 +93,29 @@ CMinimap::CMinimap(bool draw) vinya.second.unused = 255; colorsBlocked.insert(vinya); } - - if (draw) - redraw(); } CMinimap::~CMinimap() { SDL_FreeSurface(temps); - - for(int g=0; g::iterator it = surfs.begin(); it != surfs.end(); ++it) + { + it->second.free(); + } } void CMinimap::draw(SDL_Surface * to) { + int player = adventureInt->player; if(LOCPLINT->makingTurn) { int3 mapSizes = LOCPLINT->cb->getMapSize(); //draw terrain - blitAt(map[adventureInt->position.z],0,0,temps); + blitAt(surfs[player].map()[adventureInt->position.z],0,0,temps); //draw heroes std::vector hh = LOCPLINT->cb->getHeroesInfo(false); - int mw = map[0]->w, mh = map[0]->h, + int mw = surfs[player].map()[0]->w, mh = surfs[player].map()[0]->h, wo = mw/mapSizes.x, ho = mh/mapSizes.y; for (size_t i=0; i < hh.size(); ++i) @@ -145,9 +135,9 @@ void CMinimap::draw(SDL_Surface * to) } } - blitAt(flObjs[adventureInt->position.z],0,0,temps); + blitAt(surfs[player].flObjs()[adventureInt->position.z],0,0,temps); - blitAt(FoW[adventureInt->position.z],0,0,temps); + blitAt(surfs[player].FoW()[adventureInt->position.z],0,0,temps); //draw radar const int tilesw=(ADVOPT.advmapW+31)/32; @@ -167,8 +157,15 @@ void CMinimap::draw(SDL_Surface * to) aiShield->showAll(to); } } -void CMinimap::redraw(int level)// (level==-1) => redraw all levels + +CMinimapSurfacesRef::CMinimapSurfacesRef() : ready(false) { +} + + +void CMinimapSurfacesRef::redraw(int level) +{ + ready = true; initMap(level); //FoW @@ -181,29 +178,31 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels showVisibleTiles(); } -void CMinimap::initMap(int level) +void CMinimapSurfacesRef::initMap(int level) { /*for(int g=0; gminimap.pos; + std::map &colors = adventureInt->minimap.colors; + std::map &colorsBlocked = adventureInt->minimap.colorsBlocked; int3 mapSizes = LOCPLINT->cb->getMapSize(); for (size_t i=0; imh->sizes.z; i++) { - SDL_Surface * pom ; + SDL_Surface *pom; if ((level>=0) && (i!=level)) continue; - if (map.size()cb->getTile(int3(mx, my, i), false); if(tile) { @@ -213,12 +212,12 @@ void CMinimap::initMap(int level) } } } - map.push_back(pom); + map_.push_back(pom); } } -void CMinimap::initFoW(int level) +void CMinimapSurfacesRef::initFoW(int level) { /*for(int g=0; gminimap.pos; int3 mapSizes = LOCPLINT->cb->getMapSize(); - int mw = map[0]->w, mh = map[0]->h;//, + int mw = map_[0]->w, mh = map_[0]->h;//, //wo = mw/mapSizes.x, ho = mh/mapSizes.y; //TODO use me for(int d=0; dmh->map->twoLevel+1; ++d) { if(level>=0 && d!=level) continue; - SDL_Surface * pt = CSDL_Ext::newSurface(pos.w, pos.h, CSDL_Ext::std32bppSurface); + SDL_Surface * pt = CSDL_Ext::newSurface(minimap_pos.w, minimap_pos.h, CSDL_Ext::std32bppSurface); for (int i=0; iminimap.pos; int3 mapSizes = LOCPLINT->cb->getMapSize(); - int mw = map[0]->w, mh = map[0]->h; + int mw = map_[0]->w, mh = map_[0]->h; for(int d=0; dmh->map->twoLevel+1; ++d) { if(level>=0 && d!=level) continue; - SDL_Surface * pt = CSDL_Ext::newSurface(pos.w, pos.h, CSDL_Ext::std32bppSurface); + SDL_Surface * pt = CSDL_Ext::newSurface(minimap_pos.w, minimap_pos.h, CSDL_Ext::std32bppSurface); for (int i=0; i & CMinimapSurfacesRef::map() +{ + if (!ready) redraw(); + return map_; +} +std::vector & CMinimapSurfacesRef::FoW() +{ + if (!ready) redraw(); + return FoW_; +} +std::vector & CMinimapSurfacesRef::flObjs() +{ + if (!ready) redraw(); + return flObjs_; +} + +void CMinimapSurfacesRef::free() +{ + if (ready) + { + for (int g = 0; g < map_.size(); ++g) + SDL_FreeSurface(map_[g]); + map_.clear(); + + for (int g = 0; g < FoW_.size(); ++g) + SDL_FreeSurface(FoW_[g]); + FoW_.clear(); + + for (int g = 0; g < flObjs_.size(); ++g) + SDL_FreeSurface(flObjs_[g]); + flObjs_.clear(); + } +} + void CMinimap::showTile(const int3 &pos) { + const int player = adventureInt->player; + std::vector &map = surfs[player].map(); + std::vector &FoW = surfs[player].FoW(); + std::vector &flObjs = surfs[player].flObjs(); int3 mapSizes = LOCPLINT->cb->getMapSize(); //drawing terrain int mw = map[0]->w, mh = map[0]->h; @@ -347,8 +386,8 @@ void CMinimap::showTile(const int3 &pos) if(tile) { if (tile->blocked && (!tile->visitable)) - SDL_PutPixelWithoutRefresh(map[pos.z], pos.x*wo+ii, pos.y*ho+jj, colorsBlocked[tile->tertype].r, colorsBlocked[tile->tertype].g, colorsBlocked[tile->tertype].b); - else SDL_PutPixelWithoutRefresh(map[pos.z], pos.x*wo+ii, pos.y*ho+jj, colors[tile->tertype].r, colors[tile->tertype].g, colors[tile->tertype].b); + SDL_PutPixelWithoutRefresh(surfs[player].map()[pos.z], pos.x*wo+ii, pos.y*ho+jj, colorsBlocked[tile->tertype].r, colorsBlocked[tile->tertype].g, colorsBlocked[tile->tertype].b); + else SDL_PutPixelWithoutRefresh(surfs[player].map()[pos.z], pos.x*wo+ii, pos.y*ho+jj, colors[tile->tertype].r, colors[tile->tertype].g, colors[tile->tertype].b); } } } @@ -403,7 +442,7 @@ void CMinimap::showTile(const int3 &pos) //flaggable objects drawn } -void CMinimap::showVisibleTiles(int level) +void CMinimapSurfacesRef::showVisibleTiles(int level) { int3 mapSizes = LOCPLINT->cb->getMapSize(); for(int d=0; dmh->map->twoLevel+1; ++d) @@ -416,7 +455,7 @@ void CMinimap::showVisibleTiles(int level) { if(LOCPLINT->cb->isVisible(int3(x, y, d))) { - showTile(int3(x, y, d)); + adventureInt->minimap.showTile(int3(x, y, d)); } } } @@ -425,6 +464,9 @@ void CMinimap::showVisibleTiles(int level) void CMinimap::hideTile(const int3 &pos) { + const int player = adventureInt->player; + std::vector &map = surfs[player].map(); + std::vector &FoW = surfs[player].FoW(); int3 mapSizes = LOCPLINT->cb->getMapSize(); //drawing terrain int mw = map[0]->w, mh = map[0]->h; diff --git a/client/CAdvmapInterface.h b/client/CAdvmapInterface.h index 5d7e6f21b..b10100b65 100644 --- a/client/CAdvmapInterface.h +++ b/client/CAdvmapInterface.h @@ -39,7 +39,25 @@ public: ~CAdventureOptions(); static void showScenarioInfo(); }; - + +class CMinimapSurfacesRef { +public: + CMinimapSurfacesRef(); + std::vector< SDL_Surface* > &map(); + std::vector< SDL_Surface* > &FoW(); + std::vector< SDL_Surface* > &flObjs(); + void free(); +private: + void redraw(int level=-1);// (level==-1) => redraw all levels + void initMap(int level=-1);// (level==-1) => redraw all levels + void initFoW(int level=-1);// (level==-1) => redraw all levels + void initFlaggableObjs(int level=-1);// (level==-1) => redraw all levels + void showVisibleTiles(int level=-1);// (level==-1) => redraw all levels +private: + std::vector< SDL_Surface* > map_, FoW_, flObjs_; //one bitmap for each level (terrain, Fog of War, flaggable objects) (one for underworld, one for surface) + bool ready; +}; + /// Minimap which is displayed at the right upper corner of adventure map class CMinimap : public CIntObject { @@ -48,17 +66,13 @@ public: SDL_Surface * temps; std::map colors; std::map colorsBlocked; - std::vector map, FoW, flObjs; //one bitmap for each level (terrain, Fog of War, flaggable objects) + + std::map surfs; std::string statusbarTxt, rcText; - CMinimap(bool draw=true); + CMinimap(); ~CMinimap(); void draw(SDL_Surface * to); - void redraw(int level=-1);// (level==-1) => redraw all levels - void initMap(int level=-1);// (level==-1) => redraw all levels - void initFoW(int level=-1);// (level==-1) => redraw all levels - void initFlaggableObjs(int level=-1);// (level==-1) => redraw all levels - void updateRadar(); void clickRight(tribool down, bool previousState); @@ -69,7 +83,6 @@ public: void deactivate(); // makes button inactive (but don't deletes) void hideTile(const int3 &pos); //puts FoW void showTile(const int3 &pos); //removes FoW - void showVisibleTiles(int level=-1);// (level==-1) => redraw all levels }; /// Holds information about which tiles of the terrain are shown/not shown at the screen diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index 8d594fd36..10db5a019 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -40,6 +40,8 @@ const double M_PI = 3.14159265358979323846; #endif #include +const time_t CBattleInterface::HOVER_ANIM_DELTA = 1; + /* * CBattleInterface.cpp, part of VCMI engine * @@ -1182,10 +1184,11 @@ void CBattleInterface::addNewAnim(CBattleAnimation * anim) CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, CPlayerInterface * att, CPlayerInterface * defen) : queue(NULL), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), - activeStack(NULL), stackToActivate(NULL), mouseHoveredStack(-1), previouslyHoveredHex(-1), + activeStack(NULL), stackToActivate(NULL), mouseHoveredStack(-1), lastMouseHoveredStackAnimationTime(-1), previouslyHoveredHex(-1), currentlyHoveredHex(-1), tacticianInterface(NULL), spellDestSelectMode(false), spellToCast(NULL), siegeH(NULL), attackerInt(att), defenderInt(defen), curInt(att), animIDhelper(0), givenCommand(NULL), myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL) + { ObjectConstruction h__l__p(this); @@ -1453,7 +1456,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds); CCS->soundh->setCallback(channel, boost::bind(&CMusicHandler::playMusicFromSet, CCS->musich, CCS->musich->battleMusics, -1)); - + memset(stackCountOutsideHexes, 1, BFIELD_SIZE * sizeof(bool)); //initialize array with trues } CBattleInterface::~CBattleInterface() @@ -1990,6 +1993,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) { if(activeStack!= NULL && !spellDestSelectMode) { + int lastMouseHoveredStack = mouseHoveredStack; mouseHoveredStack = -1; int myNumber = -1; //number of hovered tile for(int g = 0; g < BFIELD_SIZE; ++g) @@ -2033,12 +2037,16 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent) sprintf(buf, CGI->generaltexth->allTexts[297].c_str(), shere->count == 1 ? shere->getCreature()->nameSing.c_str() : shere->getCreature()->namePl.c_str()); console->alterTxt = buf; console->whoSetAlter = 0; - mouseHoveredStack = shere->ID; - if(creAnims[shere->ID]->getType() == CCreatureAnim::HOLDING && creAnims[shere->ID]->framesInGroup(CCreatureAnim::MOUSEON) > 0) + const time_t curTime = time(NULL); + if(shere->ID != lastMouseHoveredStack && + curTime > lastMouseHoveredStackAnimationTime + HOVER_ANIM_DELTA && + creAnims[shere->ID]->getType() == CCreatureAnim::HOLDING && + creAnims[shere->ID]->framesInGroup(CCreatureAnim::MOUSEON) > 0) { creAnims[shere->ID]->playOnce(CCreatureAnim::MOUSEON); + lastMouseHoveredStackAnimationTime = curTime; } - + mouseHoveredStack = shere->ID; } else if(curInt->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy { @@ -3527,11 +3535,11 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to) { const THex nextPos = stack->position + (stack->attackerOwned ? 1 : -1); const bool edge = stack->position % BFIELD_WIDTH == (stack->attackerOwned ? BFIELD_WIDTH - 2 : 1); - const bool moveInside = !edge && !isHexAccessible(nextPos); + const bool moveInside = !edge && !stackCountOutsideHexes[nextPos]; int xAdd = (stack->attackerOwned ? 220 : 202) + (stack->doubleWide() ? 44 : 0) * (stack->attackerOwned ? +1 : -1) + (moveInside ? amountNormal->w + 10 : 0) * (stack->attackerOwned ? -1 : +1); - + int yAdd = 260 + ((stack->attackerOwned || moveInside) ? 0 : -15); //blitting amount background box SDL_Surface *amountBG = NULL; boost::shared_ptr spellEffects = stack->getSpellBonuses(); @@ -3560,13 +3568,13 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to) amountBG = amountEffNeutral; } } - SDL_Rect temp_rect = genRect(amountNormal->h, amountNormal->w, creAnims[ID]->pos.x + xAdd, creAnims[ID]->pos.y + 260); + SDL_Rect temp_rect = genRect(amountNormal->h, amountNormal->w, creAnims[ID]->pos.x + xAdd, creAnims[ID]->pos.y + yAdd); SDL_BlitSurface(amountBG, NULL, to, &temp_rect); //blitting amount CSDL_Ext::printAtMiddle( makeNumberShort(stack->count), creAnims[ID]->pos.x + xAdd + 15, - creAnims[ID]->pos.y + 260 + 5, + creAnims[ID]->pos.y + yAdd + 5, FONT_TINY, zwykly, to @@ -3654,7 +3662,7 @@ void CBattleInterface::redrawBackgroundWithHexes(const CStack * activeStack) attackableHexes.clear(); if (activeStack) occupyableHexes = curInt->cb->battleGetAvailableHexes(activeStack, true, &attackableHexes); - + curInt->cb->battleGetStackCountOutsideHexes(stackCountOutsideHexes); //preparating background graphic with hexes and shaded hexes blitAt(background, 0, 0, backgroundWithHexes); if(curInt->sysOpts.printCellBorders) @@ -3976,13 +3984,6 @@ void CBattleInterface::bTacticNextStack() stackActivated(stacksOfMine.front()); } -bool CBattleInterface::isHexAccessible(THex nextPos) -{ - //!vstd::contains(curInt->cb->battleGetAvailableHexes(stack, true), nextPos) - //TODO has to be fast - return true; -} - void CBattleHero::show(SDL_Surface *to) { //animation of flag diff --git a/client/CBattleInterface.h b/client/CBattleInterface.h index 93f12f860..7d781a790 100644 --- a/client/CBattleInterface.h +++ b/client/CBattleInterface.h @@ -435,8 +435,11 @@ private: const CStack * stackToActivate; //when animation is playing, we should wait till the end to make the next stack active; NULL of none void activateStack(); //sets activeStack to stackToActivate etc. int mouseHoveredStack; //stack hovered by mouse; if -1 -> none + time_t lastMouseHoveredStackAnimationTime; // time when last mouse hovered animation occured + static const time_t HOVER_ANIM_DELTA; std::vector occupyableHexes, //hexes available for active stack attackableHexes; //hexes attackable by active stack + bool stackCountOutsideHexes[BFIELD_SIZE]; // hexes that when in front of a unit cause it's amount box to move back int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon) float getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group @@ -462,7 +465,6 @@ private: void giveCommand(ui8 action, THex tile, ui32 stack, si32 additional=-1); bool isTileAttackable(const THex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles bool blockedByObstacle(THex hex) const; - bool isHexAccessible(THex nextPos); bool isCatapultAttackable(THex hex) const; //returns true if given tile can be attacked by catapult std::list battleEffects; //different animations to display on the screen like spell effects diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 8a785fd0a..d5969fd75 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -702,12 +702,12 @@ void Graphics::loadFonts() CDefEssential * Graphics::getDef( const CGObjectInstance * obj ) { - return advmapobjGraphics[obj->defInfo->id][obj->defInfo->subid]; + return advmapobjGraphics[obj->defInfo->id][obj->defInfo->subid][obj->defInfo->name]; } CDefEssential * Graphics::getDef( const CGDefInfo * info ) { - return advmapobjGraphics[info->id][info->subid]; + return advmapobjGraphics[info->id][info->subid][info->name]; } void Graphics::loadErmuToPicture() diff --git a/client/Graphics.h b/client/Graphics.h index 4c4c1494c..9f2a47829 100644 --- a/client/Graphics.h +++ b/client/Graphics.h @@ -68,7 +68,7 @@ public: CDefHandler * FoWfullHide; //for Fog of War CDefHandler * FoWpartialHide; //for For of War - std::map > advmapobjGraphics; + std::map > > advmapobjGraphics; CDefEssential * getDef(const CGObjectInstance * obj); CDefEssential * getDef(const CGDefInfo * info); //creatures diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index d335c9933..633343e2e 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -249,12 +249,11 @@ 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 - || !obj->defInfo->handler) //no graphic... + || !graphics->getDef(obj)) //no graphic... { continue; } - - const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap; + const SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap; for(int fx=0; fxw>>5; ++fx) //bitmap->w/32 { for(int fy=0; fyh>>5; ++fy) //bitmap->h/32 @@ -298,64 +297,49 @@ static void processDef (const CGDefInfo* def) { if(def->id == EVENTI_TYPE) { + graphics->advmapobjGraphics[def->id][def->subid][def->name] = NULL; return; } - - if(!def->handler) //if object has already set handler (eg. heroes) it should not be overwritten + CDefEssential * ourDef = graphics->getDef(def); + if(!ourDef) //if object has already set handler (eg. heroes) it should not be overwritten { if(def->name.size()) { if(vstd::contains(graphics->mapObjectDefs, def->name)) { - const_cast(def)->handler = graphics->mapObjectDefs[def->name]; + graphics->advmapobjGraphics[def->id][def->subid][def->name] = graphics->mapObjectDefs[def->name]; } else { - graphics->mapObjectDefs[def->name] = const_cast(def)->handler = CDefHandler::giveDefEss(def->name); + graphics->mapObjectDefs[def->name] = graphics->advmapobjGraphics[def->id][def->subid][def->name] = CDefHandler::giveDefEss(def->name); } } else { tlog2 << "No def name for " << def->id << " " << def->subid << std::endl; - const_cast(def)->handler = NULL; return; } - - 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 < def->handler->ourImages.size(); ++yy) + for(size_t yy=0; yy < ourDef->ourImages.size(); ++yy) { - CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap); + CSDL_Ext::alphaTransform(ourDef->ourImages[yy].bitmap); } } void CMapHandler::initHeroDef(const CGHeroInstance * h) { - 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; + graphics->advmapobjGraphics[h->defInfo->id][h->defInfo->subid][h->defInfo->name] = graphics->flags1[0]; } void CMapHandler::init() { timeHandler th; th.getDif(); - 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]; - + graphics->advmapobjGraphics[8][0]["AB01_.DEF"] = graphics->boatAnims[0]; + graphics->advmapobjGraphics[8][1]["AB02_.DEF"] = graphics->boatAnims[1]; + graphics->advmapobjGraphics[8][2]["AB03_.DEF"] = graphics->boatAnims[2]; // Size of visible terrain. int mapW = conf.go()->ac.advmapW; int mapH = conf.go()->ac.advmapH; @@ -387,7 +371,7 @@ void CMapHandler::init() for(int i=0;iheroes.size();i++) { - if( !map->heroes[i]->defInfo->handler ) + if( !graphics->getDef(map->heroes[i]) ) { initHeroDef(map->heroes[i]); } @@ -527,6 +511,9 @@ void CMapHandler::terrainRect( int3 top_tile, unsigned char anim, const std::vec for(int h=0; h < objects.size(); ++h) { const CGObjectInstance *obj = objects[h].first; + if (!graphics->getDef(obj)) + processDef(obj->defInfo); + ui8 color = obj->tempOwner; //checking if object has non-empty graphic on this tile @@ -639,7 +626,7 @@ void CMapHandler::terrainRect( int3 top_tile, unsigned char anim, const std::vec } else //blit normal object { - const std::vector &ourImages = obj->defInfo->handler->ourImages; + const std::vector &ourImages = graphics->getDef(obj)->ourImages; SDL_Surface *bitmap = ourImages[(anim+obj->animPhaseShift)%ourImages.size()].bitmap; //setting appropriate flag color @@ -835,10 +822,10 @@ std::pair CMapHandler::getVisBitmap( const int3 & pos, cons bool CMapHandler::printObject(const CGObjectInstance *obj) { - if(!obj->defInfo->handler) + if (!graphics->getDef(obj)) processDef(obj->defInfo); - const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap; + const SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap; const int tilesW = bitmap->w/32; const int tilesH = bitmap->h/32; @@ -879,7 +866,7 @@ bool CMapHandler::printObject(const CGObjectInstance *obj) bool CMapHandler::hideObject(const CGObjectInstance *obj) { - CDefEssential * curd = obj->defInfo->handler; + CDefEssential * curd = graphics->getDef(obj); 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 a95e20ba3..7a447a6bf 100644 --- a/lib/CDefObjInfoHandler.cpp +++ b/lib/CDefObjInfoHandler.cpp @@ -30,7 +30,6 @@ 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; @@ -59,7 +58,6 @@ 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 a3d15c3ec..f4d9a038d 100644 --- a/lib/CDefObjInfoHandler.h +++ b/lib/CDefObjInfoHandler.h @@ -29,7 +29,6 @@ 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; diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 1a816e94d..0ff08cbf0 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1737,28 +1737,25 @@ int CGameState::getPlayerRelations( ui8 color1, ui8 color2 ) void CGameState::loadTownDInfos() { - for(int i=0;idobjinfo->castles[i]); forts[i] = VLC->dobjinfo->castles[i]; map->defy.push_back(forts[i]); capitols[i] = new CGDefInfo(*VLC->dobjinfo->castles[i]); } - std::ifstream ifs(DATA_DIR "/config/townsDefs.txt"); - int ccc; - ifs>>ccc; - for(int i=0; i < ccc*2; i++) - { - CGDefInfo *n; - if(i> n->name; - map->defy.push_back(n); - } + i = 0; + BOOST_FOREACH(const JsonNode &t, vec) { + villages[i]->name = t["village"].String(); + capitols[i]->name = t["capitol"].String(); + ++i; + } + for (i = 0; i < vec.size(); ++i) map->defy.push_back(villages[i]); + for (i = 0; i < vec.size(); ++i) map->defy.push_back(capitols[i]); } void CGameState::getNeighbours(const TerrainTile &srct, int3 tile, std::vector &vec, const boost::logic::tribool &onLand, bool limitCoastSailing) diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index e7d6e7be4..d0e491995 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -220,6 +220,19 @@ void CBattleInfoCallback::getStackQueue( std::vector &out, int h gs->curB->getStackQueue(out, howMany); } +void CBattleInfoCallback::battleGetStackCountOutsideHexes(bool *ac) +{ + if(!gs->curB) + { + tlog2<<"battleGetAvailableHexes called when there is no battle!"< ignored; + gs->curB->getAccessibilityMap(ac, false /*ignored*/, false, false, ignored, false /*ignored*/, NULL); + } +} + std::vector CBattleInfoCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable) { //boost::shared_lock lock(*gs->mx); diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 33f205c73..dd21e340e 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -97,6 +97,7 @@ public: THex battleGetPos(int stack); //returns position (tile ID) of stack TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true); //returns stacks on battlefield void getStackQueue( std::vector &out, int howMany ); //returns vector of stack in order of their move sequence + void battleGetStackCountOutsideHexes(bool *ac); // returns hexes which when in front of a stack cause us to move the amount box back std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * attackable = NULL); //returns numbers of hexes reachable by creature with id ID std::vector battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL); //returns vector of distances to [dest hex number] bool battleCanShoot(const CStack * stack, THex dest); //returns true if unit with id ID can shoot to dest