mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-06 23:26:26 +02:00
Various fixes for quick combat.
Replaced several boost::bind usages with lambdas.
This commit is contained in:
parent
06f0a29b31
commit
17403b544c
@ -376,27 +376,24 @@ int CCallback::mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance
|
|||||||
return swapCreatures(s1, s2, p1, p2);
|
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);
|
cl->additionalPlayerInts[*player].push_back(gameEvents);
|
||||||
registerBattleInterface(cgi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
cl->additionalPlayerInts[*player] -= gameEvents;
|
||||||
unregisterBattleInterface(cgi);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 )
|
CBattleCallback::CBattleCallback(CGameState *GS, boost::optional<PlayerColor> Player, CClient *C )
|
||||||
|
12
CCallback.h
12
CCallback.h
@ -27,8 +27,8 @@ struct CGPathNode;
|
|||||||
struct CGPath;
|
struct CGPath;
|
||||||
struct CPathsInfo;
|
struct CPathsInfo;
|
||||||
struct CPack;
|
struct CPack;
|
||||||
class CBattleGameInterface;
|
class IBattleEventsReceiver;
|
||||||
class CGameInterface;
|
class IGameEventsReceiver;
|
||||||
|
|
||||||
class IBattleCallback
|
class IBattleCallback
|
||||||
{
|
{
|
||||||
@ -114,10 +114,10 @@ public:
|
|||||||
virtual void recalculatePaths(); //updates main, client pathfinder info (should be called when moving hero is over)
|
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.
|
//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 registerGameInterface(shared_ptr<IGameEventsReceiver> gameEvents);
|
||||||
void registerBattleInterface(shared_ptr<CBattleGameInterface> cbga);
|
void registerBattleInterface(shared_ptr<IBattleEventsReceiver> battleEvents);
|
||||||
void unregisterGameInterface(shared_ptr<CGameInterface> cgi);
|
void unregisterGameInterface(shared_ptr<IGameEventsReceiver> gameEvents);
|
||||||
void unregisterBattleInterface(shared_ptr<CBattleGameInterface> cbga);
|
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
|
void unregisterMyInterface(); //stops delivering information about game events to that player's interface -> can be called ONLY after victory/loss
|
||||||
|
|
||||||
|
@ -767,7 +767,8 @@ void CCastleBuildings::enterCastleGate()
|
|||||||
void CCastleBuildings::enterDwelling(int level)
|
void CCastleBuildings::enterDwelling(int level)
|
||||||
{
|
{
|
||||||
assert(level >= 0 && level < town->creatures.size());
|
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)
|
void CCastleBuildings::enterFountain(BuildingID building)
|
||||||
@ -803,9 +804,9 @@ void CCastleBuildings::enterMagesGuild()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CFunctionList<void()> onYes = boost::bind(&CCastleBuildings::openMagesGuild,this);
|
CFunctionList<void()> onYes = [this]{ openMagesGuild(); };
|
||||||
CFunctionList<void()> onNo = onYes;
|
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));
|
std::vector<CComponent*> components(1, new CComponent(CComponent::artifact,0,0));
|
||||||
|
|
||||||
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214], onYes, onNo, true, components);
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214], onYes, onNo, true, components);
|
||||||
@ -1051,9 +1052,8 @@ void CCreaInfo::clickLeft(tribool down, bool previousState)
|
|||||||
if(previousState && (!down))
|
if(previousState && (!down))
|
||||||
{
|
{
|
||||||
int offset = LOCPLINT->castleInt? (-87) : 0;
|
int offset = LOCPLINT->castleInt? (-87) : 0;
|
||||||
|
auto recruitCb = [=](CreatureID id, int count) { LOCPLINT->cb->recruitCreatures(town, id, count, level); };
|
||||||
GH.pushInt(new CRecruitmentWindow(town, level, town,
|
GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, offset));
|
||||||
boost::bind(&CCallback::recruitCreatures, LOCPLINT->cb, town, _1, _2, level), 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);
|
cancel = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 224, 312,"ICANCEL.DEF",SDLK_ESCAPE);
|
||||||
|
|
||||||
if(possible)
|
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
|
else
|
||||||
buy->block(true);
|
buy->block(true);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
#define THREAD_CREATED_BY_CLIENT
|
#define THREAD_CREATED_BY_CLIENT
|
||||||
|
|
||||||
#define RETURN_IF_QUICK_COMBAT \
|
#define RETURN_IF_QUICK_COMBAT \
|
||||||
if(isAutoFightOn) \
|
if(isAutoFightOn && !battleInt) \
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#define BATTLE_EVENT_POSSIBLE_RETURN\
|
#define BATTLE_EVENT_POSSIBLE_RETURN\
|
||||||
@ -124,6 +124,7 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player)
|
|||||||
terminate_cond.set(false);
|
terminate_cond.set(false);
|
||||||
firstCall = 1; //if loading will be overwritten in serialize
|
firstCall = 1; //if loading will be overwritten in serialize
|
||||||
autosaveCount = 0;
|
autosaveCount = 0;
|
||||||
|
isAutoFightOn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPlayerInterface::~CPlayerInterface()
|
CPlayerInterface::~CPlayerInterface()
|
||||||
@ -805,11 +806,14 @@ void CPlayerInterface::battleEnd(const BattleResult *br)
|
|||||||
cb->unregisterBattleInterface(autofightingAI);
|
cb->unregisterBattleInterface(autofightingAI);
|
||||||
autofightingAI = nullptr;
|
autofightingAI = nullptr;
|
||||||
|
|
||||||
|
if(!battleInt)
|
||||||
|
{
|
||||||
SDL_Rect temp_rect = genRect(561, 470, (screen->w - 800)/2 + 165, (screen->h - 600)/2 + 19);
|
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);
|
auto resWindow = new CBattleResultWindow(*br, temp_rect, *this);
|
||||||
GH.pushInt(resWindow);
|
GH.pushInt(resWindow);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BATTLE_EVENT_POSSIBLE_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++)
|
for(int i=0;i<components.size();i++)
|
||||||
intComps.push_back(new CComponent(components[i])); //will be deleted by close in window
|
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)
|
else if(selection)
|
||||||
{
|
{
|
||||||
@ -1469,7 +1473,8 @@ void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const C
|
|||||||
{
|
{
|
||||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||||
waitWhileDialog();
|
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);
|
GH.pushInt(cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1493,7 +1498,7 @@ void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
|
|||||||
auto state = obj->state();
|
auto state = obj->state();
|
||||||
std::vector<si32> cost;
|
std::vector<si32> cost;
|
||||||
obj->getBoatCost(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);
|
GH.pushInt(csw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +119,8 @@ public:
|
|||||||
std::map<PlayerColor, shared_ptr<CGameInterface>> playerint;
|
std::map<PlayerColor, shared_ptr<CGameInterface>> playerint;
|
||||||
std::map<PlayerColor, shared_ptr<CBattleGameInterface>> battleints;
|
std::map<PlayerColor, shared_ptr<CBattleGameInterface>> battleints;
|
||||||
|
|
||||||
std::map<PlayerColor,std::vector<shared_ptr<CGameInterface>>> additionalPlayerInts;
|
std::map<PlayerColor,std::vector<shared_ptr<IGameEventsReceiver>>> additionalPlayerInts;
|
||||||
std::map<PlayerColor,std::vector<shared_ptr<CBattleGameInterface>>> additionalBattleInts;
|
std::map<PlayerColor,std::vector<shared_ptr<IBattleEventsReceiver>>> additionalBattleInts;
|
||||||
|
|
||||||
bool hotSeat;
|
bool hotSeat;
|
||||||
CConnection *serv;
|
CConnection *serv;
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
CALL_IN_PRIVILAGED_INTS(function, __VA_ARGS__); \
|
CALL_IN_PRIVILAGED_INTS(function, __VA_ARGS__); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define CALL_ONLY_THT_BATTLE_INTERFACE(player,function, ...) \
|
#define CALL_ONLY_THAT_BATTLE_INTERFACE(player,function, ...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
if(vstd::contains(cl->battleints,player)) \
|
if(vstd::contains(cl->battleints,player)) \
|
||||||
@ -88,8 +88,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#define BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(function,...) \
|
#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_THAT_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[1], function, __VA_ARGS__) \
|
||||||
BATTLE_INTERFACE_CALL_RECEIVERS(function, __VA_ARGS__)
|
BATTLE_INTERFACE_CALL_RECEIVERS(function, __VA_ARGS__)
|
||||||
/*
|
/*
|
||||||
* NetPacksClient.cpp, part of VCMI engine
|
* NetPacksClient.cpp, part of VCMI engine
|
||||||
|
Loading…
x
Reference in New Issue
Block a user