1
0
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:
MichalZr6 2024-09-19 08:34:53 +02:00
parent 6b4220c510
commit e13e72d093
3 changed files with 609 additions and 661 deletions

File diff suppressed because it is too large Load Diff

View File

@ -150,7 +150,9 @@ public:
void battleFinished(const BattleID & battleID); void battleFinished(const BattleID & battleID);
void startPlayerBattleAction(const BattleID & battleID, PlayerColor color); 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); std::shared_ptr<const CPathsInfo> getPathsInfo(const CGHeroInstance * h);
friend class CCallback; //handling players actions friend class CCallback; //handling players actions

View File

@ -25,7 +25,6 @@
#include "CMT.h" #include "CMT.h"
#include "GameChatHandler.h" #include "GameChatHandler.h"
#include "CServerHandler.h" #include "CServerHandler.h"
#include "PlayerLocalState.h"
#include "../CCallback.h" #include "../CCallback.h"
#include "../lib/filesystem/Filesystem.h" #include "../lib/filesystem/Filesystem.h"
@ -169,7 +168,7 @@ void ApplyClientNetPackVisitor::visitSetMana(SetMana & pack)
void ApplyClientNetPackVisitor::visitSetMovePoints(SetMovePoints & pack) void ApplyClientNetPackVisitor::visitSetMovePoints(SetMovePoints & pack)
{ {
const CGHeroInstance *h = cl.getHero(pack.hid); const CGHeroInstance *h = cl.getHero(pack.hid);
cl.invalidatePaths(); cl.updatePath(h);
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroMovePointsChanged, h); callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroMovePointsChanged, h);
} }
@ -230,16 +229,7 @@ void ApplyClientNetPackVisitor::visitSetStackType(SetStackType & pack)
void ApplyClientNetPackVisitor::visitEraseStack(EraseStack & pack) void ApplyClientNetPackVisitor::visitEraseStack(EraseStack & pack)
{ {
dispatchGarrisonChange(cl, pack.army, ObjectInstanceID()); dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
cl.invalidatePaths(); //it is possible to remove last non-native unit for current terrain and lose movement penalty cl.updatePath(pack.army); //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);
}
}
} }
void ApplyClientNetPackVisitor::visitSwapStacks(SwapStacks & pack) void ApplyClientNetPackVisitor::visitSwapStacks(SwapStacks & pack)
@ -247,32 +237,14 @@ void ApplyClientNetPackVisitor::visitSwapStacks(SwapStacks & pack)
dispatchGarrisonChange(cl, pack.srcArmy, pack.dstArmy); dispatchGarrisonChange(cl, pack.srcArmy, pack.dstArmy);
if(pack.srcArmy != pack.dstArmy) if(pack.srcArmy != pack.dstArmy)
{ cl.updatePath(pack.dstArmy); // adding/removing units may change terrain type penalty based on creature native terrains
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);
}
}
}
} }
void ApplyClientNetPackVisitor::visitInsertNewStack(InsertNewStack & pack) void ApplyClientNetPackVisitor::visitInsertNewStack(InsertNewStack & pack)
{ {
dispatchGarrisonChange(cl, pack.army, ObjectInstanceID()); dispatchGarrisonChange(cl, pack.army, ObjectInstanceID());
auto hero = gs.getHero(pack.army); cl.updatePath(pack.army); // adding/removing units may change terrain type penalty based on creature native terrains
if(hero)
{
cl.invalidatePaths(); // adding/removing units may change terrain type penalty based on creature native terrains
if(LOCPLINT)
{
LOCPLINT->localState->verifyPath(hero);
}
}
} }
void ApplyClientNetPackVisitor::visitRebalanceStacks(RebalanceStacks & pack) void ApplyClientNetPackVisitor::visitRebalanceStacks(RebalanceStacks & pack)
@ -281,15 +253,8 @@ void ApplyClientNetPackVisitor::visitRebalanceStacks(RebalanceStacks & pack)
if(pack.srcArmy != pack.dstArmy) if(pack.srcArmy != pack.dstArmy)
{ {
cl.invalidatePaths(); // adding/removing units may change terrain type penalty based on creature native terrains cl.updatePath(pack.srcArmy); // adding/removing units may change terrain type penalty based on creature native terrains
if(LOCPLINT) cl.updatePath(pack.dstArmy);
{
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
{
if(hero->id == pack.dstArmy || hero->id == pack.srcArmy)
LOCPLINT->localState->verifyPath(hero);
}
}
} }
} }
@ -304,16 +269,8 @@ void ApplyClientNetPackVisitor::visitBulkRebalanceStacks(BulkRebalanceStacks & p
if(pack.moves[0].srcArmy != destArmy) if(pack.moves[0].srcArmy != destArmy)
{ {
cl.invalidatePaths(); // adding/removing units may change terrain type penalty based on creature native terrains cl.updatePath(destArmy); // adding/removing units may change terrain type penalty based on creature native terrains
if(LOCPLINT) cl.updatePath(pack.moves[0].srcArmy);
{
// update all paths
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
{
if(hero->id == destArmy || hero->id == pack.moves[0].srcArmy)
LOCPLINT->localState->verifyPath(hero);
}
}
} }
} }
} }
@ -360,16 +317,8 @@ void ApplyClientNetPackVisitor::visitBulkMoveArtifacts(BulkMoveArtifacts & pack)
if(pack.interfaceOwner != dstOwner) if(pack.interfaceOwner != dstOwner)
callInterfaceIfPresent(cl, dstOwner, &IGameEventsReceiver::artifactMoved, srcLoc, dstLoc); callInterfaceIfPresent(cl, dstOwner, &IGameEventsReceiver::artifactMoved, srcLoc, dstLoc);
cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings cl.updatePath(pack.srcArtHolder); // hero might have equipped/unequipped Angel Wings
cl.updatePath(pack.dstArtHolder);
if(LOCPLINT)
{
for(const auto hero : LOCPLINT->localState->getWanderingHeroes())
{
if(hero->id == pack.srcArtHolder || hero->id == pack.dstArtHolder)
LOCPLINT->localState->verifyPath(hero);
}
}
} }
}; };
@ -399,31 +348,14 @@ void ApplyClientNetPackVisitor::visitAssembledArtifact(AssembledArtifact & pack)
{ {
callInterfaceIfPresent(cl, cl.getOwner(pack.al.artHolder), &IGameEventsReceiver::artifactAssembled, pack.al); callInterfaceIfPresent(cl, cl.getOwner(pack.al.artHolder), &IGameEventsReceiver::artifactAssembled, pack.al);
cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings cl.updatePath(pack.al.artHolder); // 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);
}
}
} }
void ApplyClientNetPackVisitor::visitDisassembledArtifact(DisassembledArtifact & pack) void ApplyClientNetPackVisitor::visitDisassembledArtifact(DisassembledArtifact & pack)
{ {
callInterfaceIfPresent(cl, cl.getOwner(pack.al.artHolder), &IGameEventsReceiver::artifactDisassembled, pack.al); callInterfaceIfPresent(cl, cl.getOwner(pack.al.artHolder), &IGameEventsReceiver::artifactDisassembled, pack.al);
cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings cl.updatePath(pack.al.artHolder); // 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);
}
}
} }
void ApplyClientNetPackVisitor::visitHeroVisit(HeroVisit & pack) void ApplyClientNetPackVisitor::visitHeroVisit(HeroVisit & pack)