Skip to content

Commit

Permalink
fix: AI: spellcasters: look at enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
kiedtl committed Jun 26, 2024
1 parent 0a81394 commit e1ddbdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/ai.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,11 @@ pub fn watcherFight(mob: *Mob, alloc: mem.Allocator) void {
if (!mob.cansee(target.coord)) {
mob.tryMoveTo(target.coord);
} else {
if (!runAwayFromEnemies(mob, 8))
if (runAwayFromEnemies(mob, 8)) {
mob.facing = mob.coord.closestDirectionTo(target.coord, state.mapgeometry);
} else {
meleeFight(mob, alloc);
}
}
}

Expand Down Expand Up @@ -1607,6 +1610,9 @@ pub fn alchemistFight(mob: *Mob, alloc: mem.Allocator) void {
}

pub fn mageFight(mob: *Mob, alloc: mem.Allocator) void {
const target = closestEnemy(mob);
mob.facing = mob.coord.closestDirectionTo(target.mob.coord, state.mapgeometry);

if (mob.ai.flag(.SocialFighter) or mob.ai.flag(.SocialFighter2)) {
// Check if there's an ally that satisfies the following conditions
// - Isn't the current mob
Expand All @@ -1621,7 +1627,6 @@ pub fn mageFight(mob: *Mob, alloc: mem.Allocator) void {
} else false;

if (!found_ally) {
mob.facing = mob.coord.closestDirectionTo(closestEnemy(mob).mob.coord, state.mapgeometry);
tryRest(mob);
return;
}
Expand All @@ -1638,9 +1643,10 @@ pub fn mageFight(mob: *Mob, alloc: mem.Allocator) void {
switch (mob.ai.spellcaster_backup_action) {
.Melee => meleeFight(mob, alloc),
.KeepDistance => if (!mob.immobile) {
const dist = @intCast(usize, mob.stat(.Vision) -| 1);
const dist = @intCast(usize, mob.stat(.Vision) -| 2);
const moved = runAwayFromEnemies(mob, dist);
if (!moved) meleeFight(mob, alloc);
mob.facing = mob.coord.closestDirectionTo(target.mob.coord, state.mapgeometry);
} else {
tryRest(mob);
},
Expand Down
2 changes: 0 additions & 2 deletions src/mobs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,6 @@ pub const BrimstoneMageTemplate = MobTemplate{
.ai = AI{
.profession_name = "brimstone mage",
.profession_description = "watching",
// Stand still and don't be curious; don't want emberling followers
// to burn the world down
.work_fn = ai.standStillAndGuardWork,
.fight_fn = ai.mageFight,
.spellcaster_backup_action = .KeepDistance,
Expand Down

0 comments on commit e1ddbdb

Please sign in to comment.