Quellcode durchsuchen

- fixes #1276
- minor fix to json arrays merging
- fixed update of growth icons on town screen

Ivan Savenko vor 12 Jahren
Ursprung
Commit
4724ccbb45
4 geänderte Dateien mit 27 neuen und 17 gelöschten Zeilen
  1. 18 11
      client/CCastleInterface.cpp
  2. 4 0
      client/CCastleInterface.h
  3. 3 3
      lib/JsonNode.cpp
  4. 2 3
      server/CGameHandler.cpp

+ 18 - 11
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());
 			}
 		}
 	}

+ 4 - 0
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;

+ 3 - 3
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;

+ 2 - 3
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);