From 49caccda25b96289f5ee25952b113b260032e466 Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Wed, 13 Mar 2024 11:01:25 -0300 Subject: [PATCH 01/10] - renaming getPathSearchParams to buildFindPathParams also remove abbreviation --- src/creature.cpp | 22 +++++++++++----------- src/creature.h | 2 +- src/monster.cpp | 28 ++++++++++++++-------------- src/monster.h | 2 +- src/player.cpp | 6 +++--- src/player.h | 2 +- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index ae27b9ab68..06565a5425 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -939,23 +939,23 @@ bool Creature::setAttackedCreature(Creature* creature) return true; } -void Creature::getPathSearchParams(const Creature*, FindPathParams& fpp) const +void Creature::buildFindPathParams(const Creature*, FindPathParams& findPathParams) const { - fpp.fullPathSearch = !hasFollowPath; - fpp.clearSight = true; - fpp.maxSearchDist = 12; - fpp.minTargetDist = 1; - fpp.maxTargetDist = 1; + findPathParams.fullPathSearch = !hasFollowPath; + findPathParams.clearSight = true; + findPathParams.maxSearchDist = 12; + findPathParams.minTargetDist = 1; + findPathParams.maxTargetDist = 1; } void Creature::goToFollowCreature() { if (followCreature) { - FindPathParams fpp; - getPathSearchParams(followCreature, fpp); + FindPathParams findPathParams; + buildFindPathParams(followCreature, findPathParams); Monster* monster = getMonster(); - if (monster && !monster->getMaster() && (monster->isFleeing() || fpp.maxTargetDist > 1)) { + if (monster && !monster->getMaster() && (monster->isFleeing() || findPathParams.maxTargetDist > 1)) { Direction dir = DIRECTION_NONE; if (monster->isFleeing()) { @@ -964,7 +964,7 @@ void Creature::goToFollowCreature() if (!monster->getDistanceStep(followCreature->getPosition(), dir)) { // if we can't get anything then let the A* calculate listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) { + if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { hasFollowPath = true; startAutoWalk(); } else { @@ -983,7 +983,7 @@ void Creature::goToFollowCreature() } } else { listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, fpp)) { + if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { hasFollowPath = true; startAutoWalk(); } else { diff --git a/src/creature.h b/src/creature.h index 170a4b5abe..fbc5341a3f 100644 --- a/src/creature.h +++ b/src/creature.h @@ -436,7 +436,7 @@ class Creature : virtual public Thing virtual uint64_t getLostExperience() const { return 0; } virtual void dropLoot(Container*, Creature*) {} virtual uint16_t getLookCorpse() const { return 0; } - virtual void getPathSearchParams(const Creature* creature, FindPathParams& fpp) const; + virtual void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const; virtual void death(Creature*) {} virtual bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified); diff --git a/src/monster.cpp b/src/monster.cpp index 5f838345cb..97c232c3cc 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -1995,32 +1995,32 @@ bool Monster::challengeCreature(Creature* creature, bool force /* = false*/) return result; } -void Monster::getPathSearchParams(const Creature* creature, FindPathParams& fpp) const +void Monster::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const { - Creature::getPathSearchParams(creature, fpp); + Creature::buildFindPathParams(creature, findPathParams); - fpp.minTargetDist = 1; - fpp.maxTargetDist = mType->info.targetDistance; + findPathParams.minTargetDist = 1; + findPathParams.maxTargetDist = mType->info.targetDistance; if (isSummon()) { if (getMaster() == creature) { - fpp.maxTargetDist = 2; - fpp.fullPathSearch = true; + findPathParams.maxTargetDist = 2; + findPathParams.fullPathSearch = true; } else if (mType->info.targetDistance <= 1) { - fpp.fullPathSearch = true; + findPathParams.fullPathSearch = true; } else { - fpp.fullPathSearch = !canUseAttack(getPosition(), creature); + findPathParams.fullPathSearch = !canUseAttack(getPosition(), creature); } } else if (isFleeing()) { // Distance should be higher than the client view range (Map::maxClientViewportX/Map::maxClientViewportY) - fpp.maxTargetDist = Map::maxViewportX; - fpp.clearSight = false; - fpp.keepDistance = true; - fpp.fullPathSearch = false; + findPathParams.maxTargetDist = Map::maxViewportX; + findPathParams.clearSight = false; + findPathParams.keepDistance = true; + findPathParams.fullPathSearch = false; } else if (mType->info.targetDistance <= 1) { - fpp.fullPathSearch = true; + findPathParams.fullPathSearch = true; } else { - fpp.fullPathSearch = !canUseAttack(getPosition(), creature); + findPathParams.fullPathSearch = !canUseAttack(getPosition(), creature); } } diff --git a/src/monster.h b/src/monster.h index 1ac5a46893..7455f831dc 100644 --- a/src/monster.h +++ b/src/monster.h @@ -211,7 +211,7 @@ class Monster final : public Creature void dropLoot(Container* corpse, Creature* lastHitCreature) override; uint32_t getDamageImmunities() const override { return mType->info.damageImmunities; } uint32_t getConditionImmunities() const override { return mType->info.conditionImmunities; } - void getPathSearchParams(const Creature* creature, FindPathParams& fpp) const override; + void buildFindPathParams(const Creature*, FindPathParams& findPathParams) const override; bool useCacheMap() const override { return !randomStepping; } friend class LuaScriptInterface; diff --git a/src/player.cpp b/src/player.cpp index 3c057705df..69ce8c4908 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3351,10 +3351,10 @@ void Player::goToFollowCreature() } } -void Player::getPathSearchParams(const Creature* creature, FindPathParams& fpp) const +void Player::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const { - Creature::getPathSearchParams(creature, fpp); - fpp.fullPathSearch = true; + Creature::buildFindPathParams(creature, findPathParams); + findPathParams.fullPathSearch = true; } void Player::doAttacking(uint32_t) diff --git a/src/player.h b/src/player.h index e7d0e5e9ab..60f7a4447d 100644 --- a/src/player.h +++ b/src/player.h @@ -1302,7 +1302,7 @@ class Player final : public Creature, public Cylinder uint32_t getConditionImmunities() const override { return conditionImmunities; } uint32_t getConditionSuppressions() const override { return conditionSuppressions; } uint16_t getLookCorpse() const override; - void getPathSearchParams(const Creature* creature, FindPathParams& fpp) const override; + void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const override; friend class Game; friend class Npc; From 36afb4247072f859a259e23cbe984706e990b2e0 Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Wed, 13 Mar 2024 11:12:51 -0300 Subject: [PATCH 02/10] - fullSearchPath as a param of buildFindPathParams --- src/creature.cpp | 6 +++--- src/creature.h | 2 +- src/monster.cpp | 4 ++-- src/monster.h | 2 +- src/player.cpp | 4 ++-- src/player.h | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index 06565a5425..1f0f8d2ebf 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -939,9 +939,9 @@ bool Creature::setAttackedCreature(Creature* creature) return true; } -void Creature::buildFindPathParams(const Creature*, FindPathParams& findPathParams) const +void Creature::buildFindPathParams(const Creature*, FindPathParams& findPathParams, bool fullPathSearch) const { - findPathParams.fullPathSearch = !hasFollowPath; + findPathParams.fullPathSearch = fullPathSearch; findPathParams.clearSight = true; findPathParams.maxSearchDist = 12; findPathParams.minTargetDist = 1; @@ -952,7 +952,7 @@ void Creature::goToFollowCreature() { if (followCreature) { FindPathParams findPathParams; - buildFindPathParams(followCreature, findPathParams); + buildFindPathParams(followCreature, findPathParams, !hasFollowPath); Monster* monster = getMonster(); if (monster && !monster->getMaster() && (monster->isFleeing() || findPathParams.maxTargetDist > 1)) { diff --git a/src/creature.h b/src/creature.h index fbc5341a3f..10ad9152d9 100644 --- a/src/creature.h +++ b/src/creature.h @@ -436,7 +436,7 @@ class Creature : virtual public Thing virtual uint64_t getLostExperience() const { return 0; } virtual void dropLoot(Container*, Creature*) {} virtual uint16_t getLookCorpse() const { return 0; } - virtual void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const; + virtual void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const; virtual void death(Creature*) {} virtual bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified); diff --git a/src/monster.cpp b/src/monster.cpp index 97c232c3cc..59e07d2e1d 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -1995,9 +1995,9 @@ bool Monster::challengeCreature(Creature* creature, bool force /* = false*/) return result; } -void Monster::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const +void Monster::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const { - Creature::buildFindPathParams(creature, findPathParams); + Creature::buildFindPathParams(creature, findPathParams, fullPathSearch); findPathParams.minTargetDist = 1; findPathParams.maxTargetDist = mType->info.targetDistance; diff --git a/src/monster.h b/src/monster.h index 7455f831dc..d00ef2cda0 100644 --- a/src/monster.h +++ b/src/monster.h @@ -211,7 +211,7 @@ class Monster final : public Creature void dropLoot(Container* corpse, Creature* lastHitCreature) override; uint32_t getDamageImmunities() const override { return mType->info.damageImmunities; } uint32_t getConditionImmunities() const override { return mType->info.conditionImmunities; } - void buildFindPathParams(const Creature*, FindPathParams& findPathParams) const override; + void buildFindPathParams(const Creature*, FindPathParams& findPathParams, bool fullPathSearch) const override; bool useCacheMap() const override { return !randomStepping; } friend class LuaScriptInterface; diff --git a/src/player.cpp b/src/player.cpp index 69ce8c4908..78f9fd46d1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3351,9 +3351,9 @@ void Player::goToFollowCreature() } } -void Player::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const +void Player::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const { - Creature::buildFindPathParams(creature, findPathParams); + Creature::buildFindPathParams(creature, findPathParams, fullPathSearch); findPathParams.fullPathSearch = true; } diff --git a/src/player.h b/src/player.h index 60f7a4447d..d9c4eda5c1 100644 --- a/src/player.h +++ b/src/player.h @@ -1302,7 +1302,7 @@ class Player final : public Creature, public Cylinder uint32_t getConditionImmunities() const override { return conditionImmunities; } uint32_t getConditionSuppressions() const override { return conditionSuppressions; } uint16_t getLookCorpse() const override; - void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams) const override; + void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const override; friend class Game; friend class Npc; From a546b0339723412c8241b2e08bf8180966361509 Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Wed, 13 Mar 2024 11:37:18 -0300 Subject: [PATCH 03/10] - baby steps 1: move out Monster logic from Creature::goToFollowCreature --- src/creature.cpp | 39 +++++---------------------------------- src/monster.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/monster.h | 2 ++ 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index 1f0f8d2ebf..bbcf3535ca 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -954,41 +954,12 @@ void Creature::goToFollowCreature() FindPathParams findPathParams; buildFindPathParams(followCreature, findPathParams, !hasFollowPath); - Monster* monster = getMonster(); - if (monster && !monster->getMaster() && (monster->isFleeing() || findPathParams.maxTargetDist > 1)) { - Direction dir = DIRECTION_NONE; - - if (monster->isFleeing()) { - monster->getDistanceStep(followCreature->getPosition(), dir, true); - } else { // maxTargetDist > 1 - if (!monster->getDistanceStep(followCreature->getPosition(), dir)) { - // if we can't get anything then let the A* calculate - listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { - hasFollowPath = true; - startAutoWalk(); - } else { - hasFollowPath = false; - } - return; - } - } - - if (dir != DIRECTION_NONE) { - listWalkDir.clear(); - listWalkDir.push_back(dir); - - hasFollowPath = true; - startAutoWalk(); - } + listWalkDir.clear(); + if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { + hasFollowPath = true; + startAutoWalk(); } else { - listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { - hasFollowPath = true; - startAutoWalk(); - } else { - hasFollowPath = false; - } + hasFollowPath = false; } } diff --git a/src/monster.cpp b/src/monster.cpp index 59e07d2e1d..93d4d344df 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -581,6 +581,53 @@ bool Monster::searchTarget(TargetSearchType_t searchType /*= TARGETSEARCH_DEFAUL return false; } +void Monster::goToFollowCreature() +{ + if (followCreature) { + FindPathParams findPathParams; + buildFindPathParams(followCreature, findPathParams, !hasFollowPath); + + Monster* monster = getMonster(); + if (monster && !monster->getMaster() && (monster->isFleeing() || findPathParams.maxTargetDist > 1)) { + Direction dir = DIRECTION_NONE; + + if (monster->isFleeing()) { + monster->getDistanceStep(followCreature->getPosition(), dir, true); + } else { // maxTargetDist > 1 + if (!monster->getDistanceStep(followCreature->getPosition(), dir)) { + // if we can't get anything then let the A* calculate + listWalkDir.clear(); + if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { + hasFollowPath = true; + startAutoWalk(); + } else { + hasFollowPath = false; + } + return; + } + } + + if (dir != DIRECTION_NONE) { + listWalkDir.clear(); + listWalkDir.push_back(dir); + + hasFollowPath = true; + startAutoWalk(); + } + } else { + listWalkDir.clear(); + if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { + hasFollowPath = true; + startAutoWalk(); + } else { + hasFollowPath = false; + } + } + } + + onFollowCreatureComplete(followCreature); +} + void Monster::onFollowCreatureComplete(const Creature* creature) { if (creature) { diff --git a/src/monster.h b/src/monster.h index d00ef2cda0..28c9fd911a 100644 --- a/src/monster.h +++ b/src/monster.h @@ -97,6 +97,8 @@ class Monster final : public Creature void onWalk() override; void onWalkComplete() override; bool getNextStep(Direction& direction, uint32_t& flags) override; + + void goToFollowCreature() override; void onFollowCreatureComplete(const Creature* creature) override; void onThink(uint32_t interval) override; From ea73a823f1c8801911633eac455e18ce674a8750 Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Wed, 13 Mar 2024 11:40:22 -0300 Subject: [PATCH 04/10] - baby steps 2: remove monster obj and call Creature::goToFollowCreature --- src/monster.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/monster.cpp b/src/monster.cpp index 93d4d344df..00a44b2417 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -587,14 +587,13 @@ void Monster::goToFollowCreature() FindPathParams findPathParams; buildFindPathParams(followCreature, findPathParams, !hasFollowPath); - Monster* monster = getMonster(); - if (monster && !monster->getMaster() && (monster->isFleeing() || findPathParams.maxTargetDist > 1)) { + if (!getMaster() && (isFleeing() || findPathParams.maxTargetDist > 1)) { Direction dir = DIRECTION_NONE; - if (monster->isFleeing()) { - monster->getDistanceStep(followCreature->getPosition(), dir, true); + if (isFleeing()) { + getDistanceStep(followCreature->getPosition(), dir, true); } else { // maxTargetDist > 1 - if (!monster->getDistanceStep(followCreature->getPosition(), dir)) { + if (!getDistanceStep(followCreature->getPosition(), dir)) { // if we can't get anything then let the A* calculate listWalkDir.clear(); if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { @@ -615,13 +614,8 @@ void Monster::goToFollowCreature() startAutoWalk(); } } else { - listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { - hasFollowPath = true; - startAutoWalk(); - } else { - hasFollowPath = false; - } + Creature::goToFollowCreature(); + return; } } From 3e011d87f612248139589a25ebc5dc8d2057a82e Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Wed, 13 Mar 2024 11:53:36 -0300 Subject: [PATCH 05/10] - baby steps 3: create method for updateFollowPath --- src/creature.cpp | 19 ++++++++++++++----- src/creature.h | 3 ++- src/monster.cpp | 6 +----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index bbcf3535ca..aaf6b29ff8 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -954,18 +954,27 @@ void Creature::goToFollowCreature() FindPathParams findPathParams; buildFindPathParams(followCreature, findPathParams, !hasFollowPath); - listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { - hasFollowPath = true; + if (updateFollowPath(findPathParams)) { startAutoWalk(); - } else { - hasFollowPath = false; } } onFollowCreatureComplete(followCreature); } +bool Creature::updateFollowPath(FindPathParams& findPathParams) +{ + listWalkDir.clear(); + if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { + hasFollowPath = true; + startAutoWalk(); + } else { + hasFollowPath = false; + } + + return hasFollowPath; +} + bool Creature::setFollowCreature(Creature* creature) { if (creature) { diff --git a/src/creature.h b/src/creature.h index 10ad9152d9..d3add8987d 100644 --- a/src/creature.h +++ b/src/creature.h @@ -174,7 +174,6 @@ class Creature : virtual public Thing void startAutoWalk(const std::vector& listDir); void addEventWalk(bool firstStep = false); void stopEventWalk(); - virtual void goToFollowCreature(); // walk events virtual void onWalk(Direction& dir); @@ -184,6 +183,8 @@ class Creature : virtual public Thing // follow functions Creature* getFollowCreature() const { return followCreature; } virtual bool setFollowCreature(Creature* creature); + virtual void goToFollowCreature(); + bool updateFollowPath(FindPathParams& findPathParams); // follow events virtual void onFollowCreature(const Creature*) {} diff --git a/src/monster.cpp b/src/monster.cpp index 00a44b2417..ac003d9100 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -595,12 +595,8 @@ void Monster::goToFollowCreature() } else { // maxTargetDist > 1 if (!getDistanceStep(followCreature->getPosition(), dir)) { // if we can't get anything then let the A* calculate - listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { - hasFollowPath = true; + if (updateFollowPath(findPathParams)) { startAutoWalk(); - } else { - hasFollowPath = false; } return; } From 91388ce49a2749424c4fc76c6264472ebe89f231 Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Wed, 13 Mar 2024 11:55:21 -0300 Subject: [PATCH 06/10] - better naming for goToFollowCreature complete callback --- src/creature.cpp | 2 +- src/creature.h | 2 +- src/monster.cpp | 4 ++-- src/monster.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index aaf6b29ff8..e8d4223ef3 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -959,7 +959,7 @@ void Creature::goToFollowCreature() } } - onFollowCreatureComplete(followCreature); + onGoToFollowCreatureComplete(followCreature); } bool Creature::updateFollowPath(FindPathParams& findPathParams) diff --git a/src/creature.h b/src/creature.h index d3add8987d..73a7e61fde 100644 --- a/src/creature.h +++ b/src/creature.h @@ -188,7 +188,7 @@ class Creature : virtual public Thing // follow events virtual void onFollowCreature(const Creature*) {} - virtual void onFollowCreatureComplete(const Creature*) {} + virtual void onGoToFollowCreatureComplete(const Creature*) {} // combat functions Creature* getAttackedCreature() { return attackedCreature; } diff --git a/src/monster.cpp b/src/monster.cpp index ac003d9100..33cc6c6b02 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -615,10 +615,10 @@ void Monster::goToFollowCreature() } } - onFollowCreatureComplete(followCreature); + onGoToFollowCreatureComplete(followCreature); } -void Monster::onFollowCreatureComplete(const Creature* creature) +void Monster::onGoToFollowCreatureComplete(const Creature* creature) { if (creature) { auto it = std::find(targetList.begin(), targetList.end(), creature); diff --git a/src/monster.h b/src/monster.h index 28c9fd911a..9c61f15d25 100644 --- a/src/monster.h +++ b/src/monster.h @@ -99,7 +99,7 @@ class Monster final : public Creature bool getNextStep(Direction& direction, uint32_t& flags) override; void goToFollowCreature() override; - void onFollowCreatureComplete(const Creature* creature) override; + void onGoToFollowCreatureComplete(const Creature* creature) override; void onThink(uint32_t interval) override; From e77b42236e1abce0e733df4a471ce9e9e76dc7af Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Wed, 13 Mar 2024 17:14:46 -0300 Subject: [PATCH 07/10] - remove duplicated call to startAutoWalk --- src/creature.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/creature.cpp b/src/creature.cpp index e8d4223ef3..815ed8191b 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -967,7 +967,6 @@ bool Creature::updateFollowPath(FindPathParams& findPathParams) listWalkDir.clear(); if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { hasFollowPath = true; - startAutoWalk(); } else { hasFollowPath = false; } From 88c755ce80c6cf939d4421fea8ebc526f66de4d0 Mon Sep 17 00:00:00 2001 From: Danilo Date: Fri, 15 Mar 2024 14:39:00 -0300 Subject: [PATCH 08/10] - fixing code format --- src/creature.h | 3 ++- src/player.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/creature.h b/src/creature.h index 73a7e61fde..030be1ffa0 100644 --- a/src/creature.h +++ b/src/creature.h @@ -437,7 +437,8 @@ class Creature : virtual public Thing virtual uint64_t getLostExperience() const { return 0; } virtual void dropLoot(Container*, Creature*) {} virtual uint16_t getLookCorpse() const { return 0; } - virtual void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const; + virtual void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, + bool fullPathSearch) const; virtual void death(Creature*) {} virtual bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified); diff --git a/src/player.h b/src/player.h index d9c4eda5c1..36b31ab9be 100644 --- a/src/player.h +++ b/src/player.h @@ -1302,7 +1302,8 @@ class Player final : public Creature, public Cylinder uint32_t getConditionImmunities() const override { return conditionImmunities; } uint32_t getConditionSuppressions() const override { return conditionSuppressions; } uint16_t getLookCorpse() const override; - void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const override; + void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, + bool fullPathSearch) const override; friend class Game; friend class Npc; From 1bdeff9f3b5c5a94ac09ccce298c5bd42f8fdee7 Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Sat, 23 Mar 2024 11:54:10 -0300 Subject: [PATCH 09/10] Adressing @marmichalski code review suggestion Co-authored-by: Marcin Michalski --- src/creature.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index 815ed8191b..dd79cc72c1 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -965,13 +965,8 @@ void Creature::goToFollowCreature() bool Creature::updateFollowPath(FindPathParams& findPathParams) { listWalkDir.clear(); - if (getPathTo(followCreature->getPosition(), listWalkDir, findPathParams)) { - hasFollowPath = true; - } else { - hasFollowPath = false; - } - return hasFollowPath; + return hasFollowPath = getPathTo(followCreature->getPosition(), listWalkDir, findPathParams); } bool Creature::setFollowCreature(Creature* creature) From 14ffebc9cc164db875b666c5d3dca02230aeb6d9 Mon Sep 17 00:00:00 2001 From: Danilo Pucci Date: Mon, 25 Mar 2024 13:49:14 -0300 Subject: [PATCH 10/10] - revert name changes from findPathParams to fpp --- src/creature.cpp | 22 +++++++++++----------- src/creature.h | 3 +-- src/monster.cpp | 28 ++++++++++++++-------------- src/monster.h | 2 +- src/player.cpp | 6 +++--- src/player.h | 3 +-- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/creature.cpp b/src/creature.cpp index dd79cc72c1..565e009377 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -939,22 +939,22 @@ bool Creature::setAttackedCreature(Creature* creature) return true; } -void Creature::buildFindPathParams(const Creature*, FindPathParams& findPathParams, bool fullPathSearch) const +void Creature::buildFindPathParams(const Creature*, FindPathParams& fpp, bool fullPathSearch) const { - findPathParams.fullPathSearch = fullPathSearch; - findPathParams.clearSight = true; - findPathParams.maxSearchDist = 12; - findPathParams.minTargetDist = 1; - findPathParams.maxTargetDist = 1; + fpp.fullPathSearch = fullPathSearch; + fpp.clearSight = true; + fpp.maxSearchDist = 12; + fpp.minTargetDist = 1; + fpp.maxTargetDist = 1; } void Creature::goToFollowCreature() { if (followCreature) { - FindPathParams findPathParams; - buildFindPathParams(followCreature, findPathParams, !hasFollowPath); + FindPathParams fpp; + buildFindPathParams(followCreature, fpp, !hasFollowPath); - if (updateFollowPath(findPathParams)) { + if (updateFollowPath(fpp)) { startAutoWalk(); } } @@ -962,11 +962,11 @@ void Creature::goToFollowCreature() onGoToFollowCreatureComplete(followCreature); } -bool Creature::updateFollowPath(FindPathParams& findPathParams) +bool Creature::updateFollowPath(FindPathParams& fpp) { listWalkDir.clear(); - return hasFollowPath = getPathTo(followCreature->getPosition(), listWalkDir, findPathParams); + return hasFollowPath = getPathTo(followCreature->getPosition(), listWalkDir, fpp); } bool Creature::setFollowCreature(Creature* creature) diff --git a/src/creature.h b/src/creature.h index 030be1ffa0..abce3b454f 100644 --- a/src/creature.h +++ b/src/creature.h @@ -437,8 +437,7 @@ class Creature : virtual public Thing virtual uint64_t getLostExperience() const { return 0; } virtual void dropLoot(Container*, Creature*) {} virtual uint16_t getLookCorpse() const { return 0; } - virtual void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, - bool fullPathSearch) const; + virtual void buildFindPathParams(const Creature* creature, FindPathParams& fpp, bool fullPathSearch) const; virtual void death(Creature*) {} virtual bool dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified); diff --git a/src/monster.cpp b/src/monster.cpp index 33cc6c6b02..503776617a 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -2032,32 +2032,32 @@ bool Monster::challengeCreature(Creature* creature, bool force /* = false*/) return result; } -void Monster::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const +void Monster::buildFindPathParams(const Creature* creature, FindPathParams& fpp, bool fullPathSearch) const { - Creature::buildFindPathParams(creature, findPathParams, fullPathSearch); + Creature::buildFindPathParams(creature, fpp, fullPathSearch); - findPathParams.minTargetDist = 1; - findPathParams.maxTargetDist = mType->info.targetDistance; + fpp.minTargetDist = 1; + fpp.maxTargetDist = mType->info.targetDistance; if (isSummon()) { if (getMaster() == creature) { - findPathParams.maxTargetDist = 2; - findPathParams.fullPathSearch = true; + fpp.maxTargetDist = 2; + fpp.fullPathSearch = true; } else if (mType->info.targetDistance <= 1) { - findPathParams.fullPathSearch = true; + fpp.fullPathSearch = true; } else { - findPathParams.fullPathSearch = !canUseAttack(getPosition(), creature); + fpp.fullPathSearch = !canUseAttack(getPosition(), creature); } } else if (isFleeing()) { // Distance should be higher than the client view range (Map::maxClientViewportX/Map::maxClientViewportY) - findPathParams.maxTargetDist = Map::maxViewportX; - findPathParams.clearSight = false; - findPathParams.keepDistance = true; - findPathParams.fullPathSearch = false; + fpp.maxTargetDist = Map::maxViewportX; + fpp.clearSight = false; + fpp.keepDistance = true; + fpp.fullPathSearch = false; } else if (mType->info.targetDistance <= 1) { - findPathParams.fullPathSearch = true; + fpp.fullPathSearch = true; } else { - findPathParams.fullPathSearch = !canUseAttack(getPosition(), creature); + fpp.fullPathSearch = !canUseAttack(getPosition(), creature); } } diff --git a/src/monster.h b/src/monster.h index 9c61f15d25..46728f4002 100644 --- a/src/monster.h +++ b/src/monster.h @@ -213,7 +213,7 @@ class Monster final : public Creature void dropLoot(Container* corpse, Creature* lastHitCreature) override; uint32_t getDamageImmunities() const override { return mType->info.damageImmunities; } uint32_t getConditionImmunities() const override { return mType->info.conditionImmunities; } - void buildFindPathParams(const Creature*, FindPathParams& findPathParams, bool fullPathSearch) const override; + void buildFindPathParams(const Creature*, FindPathParams& fpp, bool fullPathSearch) const override; bool useCacheMap() const override { return !randomStepping; } friend class LuaScriptInterface; diff --git a/src/player.cpp b/src/player.cpp index 78f9fd46d1..d87c00a16c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -3351,10 +3351,10 @@ void Player::goToFollowCreature() } } -void Player::buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, bool fullPathSearch) const +void Player::buildFindPathParams(const Creature* creature, FindPathParams& fpp, bool fullPathSearch) const { - Creature::buildFindPathParams(creature, findPathParams, fullPathSearch); - findPathParams.fullPathSearch = true; + Creature::buildFindPathParams(creature, fpp, fullPathSearch); + fpp.fullPathSearch = true; } void Player::doAttacking(uint32_t) diff --git a/src/player.h b/src/player.h index 36b31ab9be..94b784505b 100644 --- a/src/player.h +++ b/src/player.h @@ -1302,8 +1302,7 @@ class Player final : public Creature, public Cylinder uint32_t getConditionImmunities() const override { return conditionImmunities; } uint32_t getConditionSuppressions() const override { return conditionSuppressions; } uint16_t getLookCorpse() const override; - void buildFindPathParams(const Creature* creature, FindPathParams& findPathParams, - bool fullPathSearch) const override; + void buildFindPathParams(const Creature* creature, FindPathParams& fpp, bool fullPathSearch) const override; friend class Game; friend class Npc;