Browse Source

Update for previous rev. Support for synchronous building demolition.

DjWarmonger 16 years ago
parent
commit
7c2b54844f

+ 13 - 0
client/NetPacksClient.cpp

@@ -208,6 +208,19 @@ void NewStructures::applyCl( CClient *cl )
 			cl->playerint[town->tempOwner]->buildChanged(town,id,1);
 	}
 }
+void RazeStructures::applyCl (CClient *cl)
+{
+	CGTownInstance *town = GS(cl)->getTown(tid);
+	BOOST_FOREACH(si32 id, bid)
+	{
+		if (id == 13) //fort or capitol
+		{
+			town->defInfo = GS(cl)->forts[town->subID];
+		}
+		if(vstd::contains (cl->playerint,town->tempOwner))
+			cl->playerint[town->tempOwner]->buildChanged (town,id,2);
+	}
+}
 
 void SetAvailableCreatures::applyCl( CClient *cl )
 {

+ 8 - 2
hch/CObjectHandler.cpp

@@ -1553,6 +1553,7 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
 		else
 		{
 			cb->setOwner(id, h->tempOwner);
+			removeCapitols (h->getOwner(), true);
 		}
 	}
 	cb->heroVisitCastle(id, h->id);
@@ -1618,11 +1619,16 @@ void CGTownInstance::removeCapitols (ui8 owner, bool me) const
 				{
 					if (me)
 					{
-						cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol
+						RazeStructures rs;
+						rs.tid = id;
+						rs.bid.insert(13);
+						si16 builded = destroyed; 
+						cb->sendAndApply(&rs);
+						//cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol
 						return;
 					}
 					else
-						(*i)->builtBuildings.erase(13); //destroy all other capitols
+						(*i)->builtBuildings.erase(13); //destroy all other capitols at the beginning of game
 				}
 			}
 		}

+ 19 - 2
lib/NetPacks.h

@@ -442,7 +442,7 @@ struct NewStructures : public CPackForClient //504
 {
 	NewStructures(){type = 504;};
 	void applyCl(CClient *cl);
-	DLL_EXPORT void applyGs(CGameState *gs);
+	DLL_EXPORT virtual void applyGs(CGameState *gs);
 
 	si32 tid;
 	std::set<si32> bid;
@@ -452,7 +452,18 @@ struct NewStructures : public CPackForClient //504
 	{
 		h & tid & bid & builded;
 	}
-}; 
+};
+struct RazeStructures : public NewStructures //505
+{
+	RazeStructures() {type = 505;};
+	void applyCl (CClient *cl);
+	DLL_EXPORT void applyGs(CGameState *gs);
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & tid & bid & builded;
+	}
+};
 struct SetAvailableCreatures : public CPackForClient //506
 {
 	SetAvailableCreatures(){type = 506;};
@@ -1145,7 +1156,13 @@ struct BuildStructure : public CPackForServer
 		h & tid & bid;
 	}
 };
+struct RazeStructure : public BuildStructure
+{
+	RazeStructure(){};
+	//RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
 
+	bool applyGh(CGameHandler *gh);
+};
 struct RecruitCreatures : public CPackForServer
 {
 	RecruitCreatures(){};

+ 9 - 1
lib/NetPacksLib.cpp

@@ -352,7 +352,15 @@ DLL_EXPORT void NewStructures::applyGs( CGameState *gs )
 	}
 	t->builded = builded;
 }
-
+DLL_EXPORT void RazeStructures::applyGs( CGameState *gs )
+{
+	CGTownInstance *t = gs->getTown(tid);
+	BOOST_FOREACH(si32 id,bid)
+	{
+		t->builtBuildings.erase(id);
+	}
+	t->destroyed = builded; //yeaha
+}
 DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs )
 {
 	CGDwelling *dw = dynamic_cast<CGDwelling*>(gs->map->objects[tid]);

+ 1 - 0
lib/RegisterTypes.cpp

@@ -80,6 +80,7 @@ void registerTypes2(Serializer &s)
 	s.template registerType<TryMoveHero>();
 	s.template registerType<SetGarrisons>();
 	s.template registerType<NewStructures>();
+	s.template registerType<RazeStructures>();
 	s.template registerType<SetAvailableCreatures>();
 	s.template registerType<SetHeroesInTown>();
 	s.template registerType<SetHeroArtifacts>();

+ 14 - 1
server/CGameHandler.cpp

@@ -1984,7 +1984,7 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid )
 
 	if(gs->canBuildStructure(t,bid) != 7)
 	{
-		complain("Cannot build that building!");
+		complain("Cannot raze that building!");
 		return false;
 	}
 
@@ -2035,6 +2035,19 @@ bool CGameHandler::buildStructure( si32 tid, si32 bid )
 
 	return true;
 }
+bool CGameHandler::razeStructure (si32 tid, si32 bid)
+{
+///incomplete, simply erases target building
+	CGTownInstance * t = static_cast<CGTownInstance*>(gs->map->objects[tid]);
+	if (t->builtBuildings.find(bid) == t->builtBuildings.end())
+		return false;
+	RazeStructures rs;
+	rs.tid = tid;
+	rs.bid.insert(bid);
+	rs.builded = t->destroyed + 1; //define TRUE FALSE?
+	sendAndApply(&rs);
+	return true;
+}
 
 void CGameHandler::sendMessageToAll( const std::string &message )
 {

+ 1 - 0
server/CGameHandler.h

@@ -153,6 +153,7 @@ public:
 	bool upgradeCreature( ui32 objid, ui8 pos, ui32 upgID );
 	bool recruitCreatures(si32 objid, ui32 crid, ui32 cram);
 	bool buildStructure(si32 tid, si32 bid);
+	bool razeStructure(si32 tid, si32 bid);
 	bool disbandCreature( si32 id, ui8 pos );
 	bool arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2, si32 val );
 	void save(const std::string &fname);