Skip to content

Commit

Permalink
fix: properly cleanup linked fovs of mobs that were dead or on previo…
Browse files Browse the repository at this point in the history
…us level
  • Loading branch information
kiedtl committed Sep 23, 2022
1 parent 590ad13 commit ee71a47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/surfaces.zig
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,6 @@ pub const StalkerStation = Machine{
.Guard => |g| g,
};

// Clear out linked-fovs list for player, as its a fixed size and might be full.
var new_linked_fovs = @TypeOf(state.player.linked_fovs).init(null);
for (state.player.linked_fovs.constSlice()) |linked_fov_mob|
if (!linked_fov_mob.is_dead)
new_linked_fovs.append(linked_fov_mob) catch unreachable;
state.player.linked_fovs = new_linked_fovs;

var spawned_ctr: usize = 0;
var first_stalker: ?*Mob = null;
for (&DIRECTIONS) |d| if (state.player.coord.move(d, state.mapgeometry)) |neighbor| {
Expand Down
12 changes: 11 additions & 1 deletion src/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2018,10 +2018,19 @@ pub const Mob = struct { // {{{
};
self.fov[self.coord.y][self.coord.x] = 100;

// Clear out linked-fovs list of dead/non-z-level mobs
if (self.linked_fovs.len > 0) {
var new_linked_fovs = @TypeOf(self.linked_fovs).init(null);
for (self.linked_fovs.constSlice()) |linked_fov_mob|
if (!linked_fov_mob.is_dead and linked_fov_mob.coord.z == self.coord.z)
new_linked_fovs.append(linked_fov_mob) catch unreachable;
self.linked_fovs = new_linked_fovs;
}

for (self.linked_fovs.constSlice()) |linked_fov_mob| {
for (linked_fov_mob.fov) |row, y| for (row) |_, x| {
if (linked_fov_mob.fov[y][x] > 0) {
state.player.fov[y][x] = 100;
self.fov[y][x] = 100;
}
};
}
Expand All @@ -2036,6 +2045,7 @@ pub const Mob = struct { // {{{
self.push_flag = false;
self.MP = math.clamp(self.MP + 1, 0, self.max_MP);

// Gases
const gases = state.dungeon.atGas(self.coord);
for (gases) |quantity, gasi| {
if ((rng.range(usize, 0, 100) < self.resistance(.rFume) or gas.Gases[gasi].not_breathed) and quantity > 0.0) {
Expand Down

0 comments on commit ee71a47

Please sign in to comment.