summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hexen/p_enemy.c12
-rw-r--r--src/strife/p_enemy.c12
2 files changed, 20 insertions, 4 deletions
diff --git a/src/hexen/p_enemy.c b/src/hexen/p_enemy.c
index 456cc7a9..a8477b22 100644
--- a/src/hexen/p_enemy.c
+++ b/src/hexen/p_enemy.c
@@ -539,8 +539,16 @@ boolean P_LookForPlayers(mobj_t * actor, boolean allaround)
}
sector = actor->subsector->sector;
c = 0;
- stop = (actor->lastlook - 1) & 3;
- for (;; actor->lastlook = (actor->lastlook + 1) & 3)
+
+ // NOTE: This behavior has been changed from the Vanilla behavior, where
+ // an infinite loop can occur if players 0-3 all quit the game. Although
+ // technically this is not what Vanilla does, fixing this is highly
+ // desirable, and having the game simply lock up is not acceptable.
+ // stop = (actor->lastlook - 1) & 3;
+ // for (;; actor->lastlook = (actor->lastlook + 1) & 3)
+
+ stop = (actor->lastlook + MAXPLAYERS - 1) % MAXPLAYERS;
+ for (;; actor->lastlook = (actor->lastlook + 1) % MAXPLAYERS)
{
if (!playeringame[actor->lastlook])
continue;
diff --git a/src/strife/p_enemy.c b/src/strife/p_enemy.c
index 79e6ffb8..c7104a75 100644
--- a/src/strife/p_enemy.c
+++ b/src/strife/p_enemy.c
@@ -803,9 +803,17 @@ P_LookForPlayers
sector = actor->subsector->sector;
c = 0;
- stop = (actor->lastlook-1)&3;
- for ( ; ; actor->lastlook = (actor->lastlook+1)&3 )
+ // NOTE: This behavior has been changed from the Vanilla behavior, where
+ // an infinite loop can occur if players 0-3 all quit the game. Although
+ // technically this is not what Vanilla does, fixing this is highly
+ // desirable, and having the game simply lock up is not acceptable.
+ // stop = (actor->lastlook - 1) & 3;
+ // for (;; actor->lastlook = (actor->lastlook + 1) & 3)
+
+ stop = (actor->lastlook + MAXPLAYERS - 1) % MAXPLAYERS;
+
+ for ( ; ; actor->lastlook = (actor->lastlook + 1) % MAXPLAYERS)
{
if (!playeringame[actor->lastlook])
continue;