Skip to content

Commit f7f45cb

Browse files
committed
Fix some sight_blind() bugs
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.
1 parent a299993 commit f7f45cb

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/bank0.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ const u8 sightdiff[] = {
148148
0x11, 0x21, 0x32, 0x12, 0x23, 0x22,
149149
};
150150

151+
const u8 sightdiffblind[] = {
152+
0x00, 0x0f, 0xf0, 0x10, 0x01,
153+
};
154+
151155
const u8 sightskip[] = {
152156
0,
153157
5, 0, 1, 0, 1, 0,

src/gameplay.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#define MOB_FLASH_FRAMES 20
6060

6161
#define SIGHT_DIFF_COUNT 57
62+
#define SIGHT_DIFF_BLIND_COUNT 5
6263

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

9394
extern const u8 sightdiff[];
9495
extern const u8 sightskip[];
96+
extern const u8 sightdiffblind[];
9597

9698

9799
// TODO: move to its own file
@@ -144,6 +146,7 @@ void gameplay_init(void) {
144146
inv_init();
145147
targeting_init();
146148

149+
recover = 0;
147150
floor = 0;
148151
counter_zero(&st_floor);
149152
counter_zero(&st_steps);
@@ -714,27 +717,24 @@ void sight(void) NONBANKED {
714717

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

718-
pos = mob_pos[PLAYER_MOB];
719-
if (fogmap[pos]) unfog_center(pos);
720-
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
721-
--pos; // C -> L
722-
if (fogmap[pos]) unfog_center(pos);
723-
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
724-
pos += 2; // L -> R
725-
if (fogmap[pos]) unfog_center(pos);
726-
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
727-
pos -= 17; // R -> U
728-
if (fogmap[pos]) unfog_center(pos);
729-
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
730-
pos += 32; // U -> D
731-
if (fogmap[pos]) unfog_center(pos);
732-
if (IS_OPAQUE_POS(pos)) unfog_neighbors(pos);
724+
if (!IS_OPAQUE_POS(pos)) {
725+
unfog_neighbors(pos);
726+
}
727+
}
728+
}
733729

734730
for (index = 0; index < SIGHT_DIFF_COUNT; ++index) {
735731
if (is_new_pos_valid(mob_pos[PLAYER_MOB], sightdiff[index])) {
736-
mobsightmap[pos_result] = 1;
732+
mobsightmap[pos = pos_result] = 1;
733+
if (!IS_OPAQUE_POS(pos)) {
734+
continue;
735+
}
737736
}
737+
index += sightskip[index];
738738
}
739739
}
740740

0 commit comments

Comments
 (0)