From 4724ccbb45ea483471b485568810bb1b8ff3fac5 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 30 May 2013 18:43:45 +0000 Subject: [PATCH] - fixes #1276 - minor fix to json arrays merging - fixed update of growth icons on town screen --- client/CCastleInterface.cpp | 29 ++++++++++++++++++----------- client/CCastleInterface.h | 4 ++++ lib/JsonNode.cpp | 6 +++--- server/CGameHandler.cpp | 5 ++--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index fc0d14b24..1cca8cedc 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -37,6 +37,14 @@ using namespace boost::assign; * */ +const CBuilding * CBuildingRect::getBuilding() +{ + if (str->hiddenUpgrade) // hidden upgrades, e.g. hordes - return base (dwelling for hordes) + return town->town->buildings[str->building->getBase()]; + + return str->building; +} + CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str) :CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE | CShowableAnim::USE_RLE), parent(Par), @@ -94,18 +102,18 @@ void CBuildingRect::hover(bool on) void CBuildingRect::clickLeft(tribool down, bool previousState) { - if( previousState && !down && area && (parent->selectedBuilding==this) && str->building ) + if( previousState && !down && area && (parent->selectedBuilding==this) && getBuilding() ) if (!CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image - parent->buildingClicked(str->building->bid); + parent->buildingClicked(getBuilding()->bid); } void CBuildingRect::clickRight(tribool down, bool previousState) { - if((!area) || (!((bool)down)) || (this!=parent->selectedBuilding) || str->building == nullptr) + if((!area) || (!((bool)down)) || (this!=parent->selectedBuilding) || getBuilding() == nullptr) return; if( !CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image { - BuildingID bid = str->building->bid; + BuildingID bid = getBuilding()->bid; const CBuilding *bld = town->town->buildings[bid]; if (bid < BuildingID::DWELL_FIRST) { @@ -193,19 +201,18 @@ void CBuildingRect::showAll(SDL_Surface * to) blitAtLoc(border,0,0,to); } -std::string getBuildingSubtitle(const CStructure * structure)//hover text for building +std::string CBuildingRect::getSubtitle()//hover text for building { - const CGTownInstance * t = LOCPLINT->castleInt->town; - if (!structure->building) + if (!getBuilding()) return ""; - int bid = structure->building->bid; + int bid = getBuilding()->bid; if (bid<30)//non-dwellings - only buiding name - return t->town->buildings[structure->building->bid]->Name(); + return town->town->buildings[getBuilding()->bid]->Name(); else//dwellings - recruit %creature% { - auto & availableCreatures = t->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second; + auto & availableCreatures = town->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second; if(availableCreatures.size()) { int creaID = availableCreatures.back();//taking last of available creatures @@ -237,7 +244,7 @@ void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) || (*parent->selectedBuilding)<(*this)) //or we are on top { parent->selectedBuilding = this; - GH.statusbar->print(getBuildingSubtitle(str)); + GH.statusbar->print(getSubtitle()); } } } diff --git a/client/CCastleInterface.h b/client/CCastleInterface.h index 6a4e65515..365729ab7 100644 --- a/client/CCastleInterface.h +++ b/client/CCastleInterface.h @@ -36,7 +36,11 @@ class CCreature; /// Building "button" class CBuildingRect : public CShowableAnim { + std::string getSubtitle(); public: + /// returns building associated with this structure + const CBuilding * getBuilding(); + CCastleBuildings * parent; const CGTownInstance * town; const CStructure* str; diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index 6da3c2eba..9fd9c4a7a 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -1570,12 +1570,12 @@ void JsonUtils::merge(JsonNode & dest, JsonNode & source) for (size_t i=0; i< total; i++) merge(dest.Vector()[i], source.Vector()[i]); - if (source.Vector().size() < dest.Vector().size()) + if (dest.Vector().size() < source.Vector().size()) { - //reserve place and *move* data from source to dest + //reserve place and *move* remaining data from source to dest source.Vector().reserve(source.Vector().size() + dest.Vector().size()); - std::move(source.Vector().begin(), source.Vector().end(), + std::move(source.Vector().begin() + total, source.Vector().end(), std::back_inserter(dest.Vector())); } break; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index f498f7d0a..3a2cf01ba 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2482,9 +2482,6 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, } } - //We know what has been built, appluy changes - sendAndApply(&ns); - //reveal ground for lookout tower FoWChange fw; fw.player = t->tempOwner; @@ -2505,6 +2502,8 @@ bool CGameHandler::buildStructure( ObjectInstanceID tid, BuildingID requestedID, sendAndApply(&sr); } + //We know what has been built, appluy changes. Do this as final step to properly update town window + sendAndApply(&ns); if(t->visitingHero) vistiCastleObjects (t, t->visitingHero);