Skip to content

Commit

Permalink
Fix some sight_blind() bugs
Browse files Browse the repository at this point in the history
I really messed this up when implementing the optimizations from
ef32a06.

* Instead of `IS_OPAQUE_POS` it should be `!IS_OPAQUE_POS`; this causes
  the code unfog the wrong neighbors.
* We still need to check whether the surrounding positions are valid
* When updating the `mobsightmap`, we still need to check
  `IS_OPAQUE_POS` and use `sightskip`, or else monsters can see through
  walls.

Not exactly sure how that would cause the bug in #5, though.
  • Loading branch information
binji committed Nov 22, 2022
1 parent a299993 commit f7f45cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/bank0.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ const u8 sightdiff[] = {
0x11, 0x21, 0x32, 0x12, 0x23, 0x22,
};

const u8 sightdiffblind[] = {
0x00, 0x0f, 0xf0, 0x10, 0x01,
};

const u8 sightskip[] = {
0,
5, 0, 1, 0, 1, 0,
Expand Down
32 changes: 16 additions & 16 deletions src/gameplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#define MOB_FLASH_FRAMES 20

#define SIGHT_DIFF_COUNT 57
#define SIGHT_DIFF_BLIND_COUNT 5

#define IS_UNSPECIAL_WALL_TILE(tile) \
((flags_bin[tile] & 0b00000011) == 0b00000001)
Expand Down Expand Up @@ -92,6 +93,7 @@ extern const u8 drop_diff[];

extern const u8 sightdiff[];
extern const u8 sightskip[];
extern const u8 sightdiffblind[];


// TODO: move to its own file
Expand Down Expand Up @@ -144,6 +146,7 @@ void gameplay_init(void) {
inv_init();
targeting_init();

recover = 0;
floor = 0;
counter_zero(&st_floor);
counter_zero(&st_steps);
Expand Down Expand Up @@ -714,27 +717,24 @@ void sight(void) NONBANKED {

void sight_blind(void) NONBANKED {
u8 index, pos;
for (index = 0; index < SIGHT_DIFF_BLIND_COUNT; ++index) {
if (is_new_pos_valid(mob_pos[PLAYER_MOB], sightdiffblind[index])) {
if (fogmap[pos = pos_result]) unfog_center(pos);

pos = mob_pos[PLAYER_MOB];
if (fogmap[pos]) unfog_center(pos);
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
--pos; // C -> L
if (fogmap[pos]) unfog_center(pos);
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
pos += 2; // L -> R
if (fogmap[pos]) unfog_center(pos);
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
pos -= 17; // R -> U
if (fogmap[pos]) unfog_center(pos);
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
pos += 32; // U -> D
if (fogmap[pos]) unfog_center(pos);
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
if (!IS_OPAQUE_POS(pos)) {
unfog_neighbors(pos);
}
}
}

for (index = 0; index < SIGHT_DIFF_COUNT; ++index) {
if (is_new_pos_valid(mob_pos[PLAYER_MOB], sightdiff[index])) {
mobsightmap[pos_result] = 1;
mobsightmap[pos = pos_result] = 1;
if (!IS_OPAQUE_POS(pos)) {
continue;
}
}
index += sightskip[index];
}
}

Expand Down

0 comments on commit f7f45cb

Please sign in to comment.