Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monster Pathing Fixes #7703

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,17 @@ bool IsTileAvailable(Point position)
*/
bool IsTileAccessible(const Monster &monster, Point position)
{
for (const TriggerStruct &trig : trigs) {
if (position == trig.position && IsAnyOf(trig._tmsg, WM_DIABNEXTLVL, WM_DIABPREVLVL, WM_DIABTOWNWARP)) {
if (!std::any_of(Players.begin(), Players.end(), [&](const Player &player) {
return position.WalkingDistance(player.position.tile) < 2;
})) {
return false;
}
break;
}
}

if (dPlayer[position.x][position.y] != 0 || dMonster[position.x][position.y] != 0)
return false;

Expand All @@ -1695,7 +1706,9 @@ bool AiPlanWalk(Monster &monster)
/** Maps from walking path step to facing direction. */
const Direction plr2monst[9] = { Direction::South, Direction::NorthEast, Direction::NorthWest, Direction::SouthEast, Direction::SouthWest, Direction::North, Direction::East, Direction::South, Direction::West };

if (FindPath(CanStep, [&monster](Point position) { return IsTileAccessible(monster, position); }, monster.position.tile, monster.enemyPosition, path, MaxPathLengthMonsters) == 0) {
if (FindPath(
CanStep, [&monster](Point position) { return IsTileAccessible(monster, position); }, monster.position.tile, monster.enemyPosition, path, MaxPathLengthMonsters)
== 0) {
return false;
}

Expand Down Expand Up @@ -2384,17 +2397,19 @@ void GargoyleAi(Monster &monster)

void ButcherAi(Monster &monster)
{
if (monster.mode != MonsterMode::Stand || monster.activeForTicks == 0) {
if (monster.mode != MonsterMode::Stand || monster.activeForTicks == 0)
return;
}

Direction md = GetDirection(monster.position.tile, monster.position.last);
Direction md = GetMonsterDirection(monster);
monster.direction = md;

if (monster.distanceToEnemy() >= 2)
RandomWalk(monster, md);
else
if (monster.distanceToEnemy() >= 2) {
if (!AiPlanWalk(monster)) {
RandomWalk(monster, md);
}
} else {
StartAttack(monster);
}

monster.checkStandAnimationIsLoaded(md);
}
Expand Down
Loading