浏览代码

Various fixes for quick combat.
Replaced several boost::bind usages with lambdas.

Michał W. Urbańczyk 12 年之前
父节点
当前提交
17403b544c
共有 6 个文件被更改,包括 39 次插入37 次删除
  1. 8 11
      CCallback.cpp
  2. 6 6
      CCallback.h
  3. 7 7
      client/CCastleInterface.cpp
  4. 13 8
      client/CPlayerInterface.cpp
  5. 2 2
      client/Client.h
  6. 3 3
      client/NetPacksClient.cpp

+ 8 - 11
CCallback.cpp

@@ -376,27 +376,24 @@ int CCallback::mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance
 		return swapCreatures(s1, s2, p1, p2);
 }
 
-void CCallback::registerGameInterface(shared_ptr<CGameInterface> cgi)
+void CCallback::registerGameInterface(shared_ptr<IGameEventsReceiver> gameEvents)
 {
-	cl->additionalPlayerInts[*player].push_back(cgi);
-	registerBattleInterface(cgi);
+	cl->additionalPlayerInts[*player].push_back(gameEvents);
 }
 
-void CCallback::registerBattleInterface(shared_ptr<CBattleGameInterface> cbga)
+void CCallback::registerBattleInterface(shared_ptr<IBattleEventsReceiver> battleEvents)
 {
-	cl->additionalBattleInts[*player].push_back(cbga);
+	cl->additionalBattleInts[*player].push_back(battleEvents);
 }
 
-void CCallback::unregisterGameInterface(shared_ptr<CGameInterface> cgi)
+void CCallback::unregisterGameInterface(shared_ptr<IGameEventsReceiver> gameEvents)
 {
-	cl->additionalPlayerInts[*player] -= cgi;
-	unregisterBattleInterface(cgi);
-
+	cl->additionalPlayerInts[*player] -= gameEvents;
 }
 
-void CCallback::unregisterBattleInterface(shared_ptr<CBattleGameInterface> cbga)
+void CCallback::unregisterBattleInterface(shared_ptr<IBattleEventsReceiver> battleEvents)
 {
-	cl->additionalBattleInts[*player] -= cbga;
+	cl->additionalBattleInts[*player] -= battleEvents;
 }
 
 CBattleCallback::CBattleCallback(CGameState *GS, boost::optional<PlayerColor> Player, CClient *C )

+ 6 - 6
CCallback.h

@@ -27,8 +27,8 @@ struct CGPathNode;
 struct CGPath;
 struct CPathsInfo;
 struct CPack;
-class CBattleGameInterface;
-class CGameInterface;
+class IBattleEventsReceiver;
+class IGameEventsReceiver;
 
 class IBattleCallback
 {
@@ -114,10 +114,10 @@ public:
 	virtual void recalculatePaths(); //updates main, client pathfinder info (should be called when moving hero is over)
 
 	//Set of metrhods that allows adding more interfaces for this player that'll receive game event call-ins.
-	void registerGameInterface(shared_ptr<CGameInterface> cgi);
-	void registerBattleInterface(shared_ptr<CBattleGameInterface> cbga);
-	void unregisterGameInterface(shared_ptr<CGameInterface> cgi);
-	void unregisterBattleInterface(shared_ptr<CBattleGameInterface> cbga);
+	void registerGameInterface(shared_ptr<IGameEventsReceiver> gameEvents);
+	void registerBattleInterface(shared_ptr<IBattleEventsReceiver> battleEvents);
+	void unregisterGameInterface(shared_ptr<IGameEventsReceiver> gameEvents);
+	void unregisterBattleInterface(shared_ptr<IBattleEventsReceiver> battleEvents);
 
 	void unregisterMyInterface(); //stops delivering information about game events to that player's interface -> can be called ONLY after victory/loss
 

+ 7 - 7
client/CCastleInterface.cpp

@@ -767,7 +767,8 @@ void CCastleBuildings::enterCastleGate()
 void CCastleBuildings::enterDwelling(int level)
 {
 	assert(level >= 0 && level < town->creatures.size());
-	GH.pushInt(new CRecruitmentWindow(town, level, town, boost::bind(&CCallback::recruitCreatures,LOCPLINT->cb,town,_1,_2,level), -87));
+	auto recruitCb = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, id, count, level); };
+	GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, -87));
 }
 
 void CCastleBuildings::enterFountain(BuildingID building)
@@ -803,9 +804,9 @@ void CCastleBuildings::enterMagesGuild()
 		}
 		else
 		{
-			CFunctionList<void()> onYes = boost::bind(&CCastleBuildings::openMagesGuild,this);
+			CFunctionList<void()> onYes = [this]{ openMagesGuild(); };
 			CFunctionList<void()> onNo = onYes;
-			onYes += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb, hero,ArtifactID::SPELLBOOK);
+			onYes += [hero]{ LOCPLINT->cb->buyArtifact(hero, ArtifactID::SPELLBOOK); };
 			std::vector<CComponent*> components(1, new CComponent(CComponent::artifact,0,0));
 
 			LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214], onYes, onNo, true, components);
@@ -1051,9 +1052,8 @@ void CCreaInfo::clickLeft(tribool down, bool previousState)
 	if(previousState && (!down))
 	{
 		int offset = LOCPLINT->castleInt? (-87) : 0;
-
-		GH.pushInt(new CRecruitmentWindow(town, level, town, 
-		           boost::bind(&CCallback::recruitCreatures, LOCPLINT->cb, town, _1, _2, level), offset));
+		auto recruitCb = [=](CreatureID id, int count) { LOCPLINT->cb->recruitCreatures(town, id, count, level); };
+		GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, offset));
 	}
 }
 
@@ -1691,7 +1691,7 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, CreatureID creMachineID, Art
 	cancel = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 224, 312,"ICANCEL.DEF",SDLK_ESCAPE);
 
 	if(possible)
-		buy->callback += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,LOCPLINT->cb->getHero(hid),aid);
+		buy->callback += [=]{ LOCPLINT->cb->buyArtifact(LOCPLINT->cb->getHero(hid),aid); };
 	else
 		buy->block(true);
 

+ 13 - 8
client/CPlayerInterface.cpp

@@ -67,7 +67,7 @@
 #define THREAD_CREATED_BY_CLIENT
 
 #define RETURN_IF_QUICK_COMBAT		\
-	if(isAutoFightOn)				\
+	if(isAutoFightOn && !battleInt)	\
 		return;
 
 #define BATTLE_EVENT_POSSIBLE_RETURN\
@@ -124,6 +124,7 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player)
 	terminate_cond.set(false);
 	firstCall = 1; //if loading will be overwritten in serialize
 	autosaveCount = 0;
+	isAutoFightOn = false;
 }
 
 CPlayerInterface::~CPlayerInterface()
@@ -805,10 +806,13 @@ void CPlayerInterface::battleEnd(const BattleResult *br)
 		cb->unregisterBattleInterface(autofightingAI);
 		autofightingAI = nullptr;
 
-		SDL_Rect temp_rect = genRect(561, 470, (screen->w - 800)/2 + 165, (screen->h - 600)/2 + 19);
-		auto resWindow = new CBattleResultWindow(*br, temp_rect, *this);
-		GH.pushInt(resWindow);
-		return;
+		if(!battleInt)
+		{
+			SDL_Rect temp_rect = genRect(561, 470, (screen->w - 800)/2 + 165, (screen->h - 600)/2 + 19);
+			auto resWindow = new CBattleResultWindow(*br, temp_rect, *this);
+			GH.pushInt(resWindow);
+			return;
+		}
 	}
 
 	BATTLE_EVENT_POSSIBLE_RETURN;
@@ -1033,7 +1037,7 @@ void CPlayerInterface::showBlockingDialog( const std::string &text, const std::v
 		for(int i=0;i<components.size();i++)
 			intComps.push_back(new CComponent(components[i])); //will be deleted by close in window
 
-		showYesNoDialog(text, boost::bind(&CCallback::selectionMade,cb,1,askID),boost::bind(&CCallback::selectionMade,cb,0,askID),true, intComps);
+		showYesNoDialog(text, [=]{ cb->selectionMade(1, askID); }, [=]{ cb->selectionMade(0, askID); }, true, intComps);
 	}
 	else if(selection)
 	{
@@ -1469,7 +1473,8 @@ void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const C
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	waitWhileDialog();
-	CRecruitmentWindow *cr = new CRecruitmentWindow(dwelling, level, dst, boost::bind(&CCallback::recruitCreatures, cb, dwelling, _1, _2, -1));
+	auto recruitCb = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(dwelling, id, count, -1); };
+	CRecruitmentWindow *cr = new CRecruitmentWindow(dwelling, level, dst, recruitCb);
 	GH.pushInt(cr);
 }
 
@@ -1493,7 +1498,7 @@ void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
 	auto state = obj->state();
 	std::vector<si32> cost;
 	obj->getBoatCost(cost);
-	CShipyardWindow *csw = new CShipyardWindow(cost, state, obj->getBoatType(), boost::bind(&CCallback::buildBoat, cb, obj));
+	CShipyardWindow *csw = new CShipyardWindow(cost, state, obj->getBoatType(), [=]{ cb->buildBoat(obj); });
 	GH.pushInt(csw);
 }
 

+ 2 - 2
client/Client.h

@@ -119,8 +119,8 @@ public:
 	std::map<PlayerColor, shared_ptr<CGameInterface>> playerint;
 	std::map<PlayerColor, shared_ptr<CBattleGameInterface>> battleints;
 
-	std::map<PlayerColor,std::vector<shared_ptr<CGameInterface>>> additionalPlayerInts;
-	std::map<PlayerColor,std::vector<shared_ptr<CBattleGameInterface>>> additionalBattleInts;
+	std::map<PlayerColor,std::vector<shared_ptr<IGameEventsReceiver>>> additionalPlayerInts;
+	std::map<PlayerColor,std::vector<shared_ptr<IBattleEventsReceiver>>> additionalBattleInts;
 
 	bool hotSeat;
 	CConnection *serv;

+ 3 - 3
client/NetPacksClient.cpp

@@ -52,7 +52,7 @@
 			CALL_IN_PRIVILAGED_INTS(function, __VA_ARGS__);			\
 		} while(0)
 
-#define CALL_ONLY_THT_BATTLE_INTERFACE(player,function, ...) 	\
+#define CALL_ONLY_THAT_BATTLE_INTERFACE(player,function, ...) 	\
 	do															\
 	{															\
 		if(vstd::contains(cl->battleints,player))				\
@@ -88,8 +88,8 @@
 
 
 #define BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(function,...) 				\
-	CALL_ONLY_THT_BATTLE_INTERFACE(GS(cl)->curB->sides[0], function, __VA_ARGS__)	\
-	CALL_ONLY_THT_BATTLE_INTERFACE(GS(cl)->curB->sides[1], function, __VA_ARGS__)	\
+	CALL_ONLY_THAT_BATTLE_INTERFACE(GS(cl)->curB->sides[0], function, __VA_ARGS__)	\
+	CALL_ONLY_THAT_BATTLE_INTERFACE(GS(cl)->curB->sides[1], function, __VA_ARGS__)	\
 	BATTLE_INTERFACE_CALL_RECEIVERS(function, __VA_ARGS__)
 /*
  * NetPacksClient.cpp, part of VCMI engine