mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
Moved code from NetpacksClient.cpp to Client.cpp
Created new function CClient::updatePath that will invalidate paths and update given hero displayed path
This commit is contained in:
parent
6b4220c510
commit
e13e72d093
@ -13,6 +13,7 @@
|
||||
|
||||
#include "CGameInfo.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "PlayerLocalState.h"
|
||||
#include "CServerHandler.h"
|
||||
#include "ClientNetPackVisitors.h"
|
||||
#include "adventureMap/AdventureMapInterface.h"
|
||||
@ -495,6 +496,19 @@ void CClient::startPlayerBattleAction(const BattleID & battleID, PlayerColor col
|
||||
}
|
||||
}
|
||||
|
||||
void CClient::updatePath(const ObjectInstanceID & id)
|
||||
{
|
||||
invalidatePaths();
|
||||
auto hero = getHero(id);
|
||||
updatePath(hero);
|
||||
}
|
||||
|
||||
void CClient::updatePath(const CGHeroInstance * hero)
|
||||
{
|
||||
if(LOCPLINT && hero)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
|
||||
void CClient::invalidatePaths()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> pathLock(pathCacheMutex);
|
||||
|
@ -150,7 +150,9 @@ public:
|
||||
void battleFinished(const BattleID & battleID);
|
||||
void startPlayerBattleAction(const BattleID & battleID, PlayerColor color);
|
||||
|
||||
void invalidatePaths();
|
||||
void invalidatePaths(); // clears this->pathCache()
|
||||
void updatePath(const ObjectInstanceID & heroID); // invalidatePaths and update displayed hero path
|
||||
void updatePath(const CGHeroInstance * hero);
|
||||
std::shared_ptr<const CPathsInfo> getPathsInfo(const CGHeroInstance * h);
|
||||
|
||||
friend class CCallback; //handling players actions
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "CMT.h"
|
||||
#include "GameChatHandler.h"
|
||||
#include "CServerHandler.h"
|
||||
#include "PlayerLocalState.h"
|
||||
|
||||
#include "../CCallback.h"
|
||||
#include "../lib/filesystem/Filesystem.h"
|
||||
@ -169,7 +168,7 @@ void ApplyClientNetPackVisitor::visitSetMana(SetMana & pack)
|
||||
void ApplyClientNetPackVisitor::visitSetMovePoints(SetMovePoints & pack)
|
||||
{
|
||||
const CGHeroInstance *h = cl.getHero(pack.hid);
|
||||
cl.invalidatePaths();
|
||||
cl.updatePath(h);
|
||||
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroMovePointsChanged, h);
|
||||
}
|
||||
|
||||
@ -230,16 +229,7 @@ void ApplyClientNetPackVisitor::visitSetStackType(SetStackType & pack)
|
||||
void ApplyClientNetPackVisitor::visitEraseStack(EraseStack & pack)
|
||||
{
|
||||
dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
|
||||
cl.invalidatePaths(); //it is possible to remove last non-native unit for current terrain and lose movement penalty
|
||||
|
||||
if(LOCPLINT)
|
||||
{
|
||||
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
|
||||
{
|
||||
if(hero->id == pack.army)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
cl.updatePath(pack.army); //it is possible to remove last non-native unit for current terrain and lose movement penalty
|
||||
}
|
||||
|
||||
void ApplyClientNetPackVisitor::visitSwapStacks(SwapStacks & pack)
|
||||
@ -247,32 +237,14 @@ void ApplyClientNetPackVisitor::visitSwapStacks(SwapStacks & pack)
|
||||
dispatchGarrisonChange(cl, pack.srcArmy, pack.dstArmy);
|
||||
|
||||
if(pack.srcArmy != pack.dstArmy)
|
||||
{
|
||||
cl.invalidatePaths(); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
if(LOCPLINT)
|
||||
{
|
||||
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
|
||||
{
|
||||
if(hero->id == pack.dstArmy)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
}
|
||||
cl.updatePath(pack.dstArmy); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
}
|
||||
|
||||
void ApplyClientNetPackVisitor::visitInsertNewStack(InsertNewStack & pack)
|
||||
{
|
||||
dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
|
||||
|
||||
auto hero = gs.getHero(pack.army);
|
||||
if(hero)
|
||||
{
|
||||
cl.invalidatePaths(); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
if(LOCPLINT)
|
||||
{
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
cl.updatePath(pack.army); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
}
|
||||
|
||||
void ApplyClientNetPackVisitor::visitRebalanceStacks(RebalanceStacks & pack)
|
||||
@ -281,15 +253,8 @@ void ApplyClientNetPackVisitor::visitRebalanceStacks(RebalanceStacks & pack)
|
||||
|
||||
if(pack.srcArmy != pack.dstArmy)
|
||||
{
|
||||
cl.invalidatePaths(); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
if(LOCPLINT)
|
||||
{
|
||||
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
|
||||
{
|
||||
if(hero->id == pack.dstArmy || hero->id == pack.srcArmy)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
cl.updatePath(pack.srcArmy); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
cl.updatePath(pack.dstArmy);
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,16 +269,8 @@ void ApplyClientNetPackVisitor::visitBulkRebalanceStacks(BulkRebalanceStacks & p
|
||||
|
||||
if(pack.moves[0].srcArmy != destArmy)
|
||||
{
|
||||
cl.invalidatePaths(); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
if(LOCPLINT)
|
||||
{
|
||||
// update all paths
|
||||
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
|
||||
{
|
||||
if(hero->id == destArmy || hero->id == pack.moves[0].srcArmy)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
cl.updatePath(destArmy); // adding/removing units may change terrain type penalty based on creature native terrains
|
||||
cl.updatePath(pack.moves[0].srcArmy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -360,16 +317,8 @@ void ApplyClientNetPackVisitor::visitBulkMoveArtifacts(BulkMoveArtifacts & pack)
|
||||
if(pack.interfaceOwner != dstOwner)
|
||||
callInterfaceIfPresent(cl, dstOwner, &IGameEventsReceiver::artifactMoved, srcLoc, dstLoc);
|
||||
|
||||
cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings
|
||||
|
||||
if(LOCPLINT)
|
||||
{
|
||||
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
|
||||
{
|
||||
if(hero->id == pack.srcArtHolder || hero->id == pack.dstArtHolder)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
cl.updatePath(pack.srcArtHolder); // hero might have equipped/unequipped Angel Wings
|
||||
cl.updatePath(pack.dstArtHolder);
|
||||
}
|
||||
};
|
||||
|
||||
@ -399,31 +348,14 @@ void ApplyClientNetPackVisitor::visitAssembledArtifact(AssembledArtifact & pack)
|
||||
{
|
||||
callInterfaceIfPresent(cl, cl.getOwner(pack.al.artHolder), &IGameEventsReceiver::artifactAssembled, pack.al);
|
||||
|
||||
cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings
|
||||
if(LOCPLINT)
|
||||
{
|
||||
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
|
||||
{
|
||||
if(hero->id == pack.al.artHolder)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
|
||||
cl.updatePath(pack.al.artHolder); // hero might have equipped/unequipped Angel Wings
|
||||
}
|
||||
|
||||
void ApplyClientNetPackVisitor::visitDisassembledArtifact(DisassembledArtifact & pack)
|
||||
{
|
||||
callInterfaceIfPresent(cl, cl.getOwner(pack.al.artHolder), &IGameEventsReceiver::artifactDisassembled, pack.al);
|
||||
|
||||
cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings
|
||||
if(LOCPLINT)
|
||||
{
|
||||
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
|
||||
{
|
||||
if(hero->id == pack.al.artHolder)
|
||||
LOCPLINT->localState->verifyPath(hero);
|
||||
}
|
||||
}
|
||||
cl.updatePath(pack.al.artHolder); // hero might have equipped/unequipped Angel Wings
|
||||
}
|
||||
|
||||
void ApplyClientNetPackVisitor::visitHeroVisit(HeroVisit & pack)
|
||||
|
Loading…
x
Reference in New Issue
Block a user