From 2903025268686a9c2d3200066d9d14a8e6fbaec9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 1 Feb 2019 12:31:08 +0100 Subject: [PATCH] - a few minor fixes. --- src/p_acs.cpp | 4 ++-- src/p_conversation.cpp | 2 +- src/p_effect.cpp | 27 ++++++++++++++++++--------- src/p_enemy.cpp | 4 ++-- src/p_mobj.cpp | 9 ++++++--- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 723f89c67..e4d58b23f 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -8623,8 +8623,8 @@ scriptwait: { screen = screen->target; } - if (pcd == PCD_ENDHUDMESSAGEBOLD || screen == NULL || - players[consoleplayer].mo == screen) + if (Level->isPrimaryLevel() && (pcd == PCD_ENDHUDMESSAGEBOLD || screen == NULL || + players[consoleplayer].mo == screen)) { int type = Stack[optstart-6]; int id = Stack[optstart-5]; diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index ff5f8241e..dd84bad64 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -739,7 +739,7 @@ void P_StartConversation (AActor *npc, AActor *pc, bool facetalker, bool saveang int i; // Make sure this is actually a player. - if (pc == nullptr || pc->player == nullptr || npc == nullptr || pc->Level != currentUILevel) return; + if (pc == nullptr || pc->player == nullptr || npc == nullptr || !pc->Level->isPrimaryLevel()) return; auto Level = pc->Level; // [CW] If an NPC is talking to a PC already, then don't let diff --git a/src/p_effect.cpp b/src/p_effect.cpp index 82c4e40b1..1f3af0059 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -631,14 +631,23 @@ void P_DrawRailTrail(AActor *source, TArray &portalhits, int color1, seg.extend = (tempvec - (seg.dir | tempvec) * seg.dir) * 3; length += seg.length; - // Only consider sound in 2D (for now, anyway) - // [BB] You have to divide by lengthsquared here, not multiply with it. - AActor *mo = players[consoleplayer].camera; - - double r = ((seg.start.Y - mo->Y()) * (-seg.dir.Y) - (seg.start.X - mo->X()) * (seg.dir.X)) / (seg.length * seg.length); - r = clamp(r, 0., 1.); - seg.soundpos = seg.start + r * seg.dir; - seg.sounddist = (seg.soundpos - mo->Pos()).LengthSquared(); + if (source->Level->isPrimaryLevel()) + { + // Only consider sound in 2D (for now, anyway) + // [BB] You have to divide by lengthsquared here, not multiply with it. + AActor *mo = players[consoleplayer].camera; + + double r = ((seg.start.Y - mo->Y()) * (-seg.dir.Y) - (seg.start.X - mo->X()) * (seg.dir.X)) / (seg.length * seg.length); + r = clamp(r, 0., 1.); + seg.soundpos = seg.start + r * seg.dir; + seg.sounddist = (seg.soundpos - mo->Pos()).LengthSquared(); + } + else + { + // Set to invalid for secondary levels. + seg.soundpos = {0,0}; + seg.sounddist = -1; + } trail.Push(seg); } @@ -647,7 +656,7 @@ void P_DrawRailTrail(AActor *source, TArray &portalhits, int color1, if (steps) { - if (!(flags & RAF_SILENT)) + if (!(flags & RAF_SILENT) && source->Level->isPrimaryLevel()) { FSoundID sound; diff --git a/src/p_enemy.cpp b/src/p_enemy.cpp index ade5c445a..b53cd8d18 100644 --- a/src/p_enemy.cpp +++ b/src/p_enemy.cpp @@ -997,7 +997,7 @@ void P_RandomChaseDir (AActor *actor) if (actor->FriendPlayer != 0) { - player = players[i = actor->FriendPlayer - 1].mo; + player = actor->Level->Players[i = actor->FriendPlayer - 1]->mo; } else { @@ -1600,7 +1600,7 @@ int P_LookForPlayers (AActor *actor, INTBOOL allaround, FLookExParams *params) actor->IsFriend(p->mo) && (anyone || P_IsVisible(actor, p->mo, allaround))) { - actor->target = players[c].mo; + actor->target = Level->Players[c]->mo; // killough 12/98: // get out of refiring loop, to avoid hitting player accidentally diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index a8aef7705..75a70ad5a 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1040,22 +1040,25 @@ bool AActor::IsInsideVisibleAngles() const // // Returns true if this actor should be seen by the console player. // +// Not that even for secondary maps this must check the real player! +// //============================================================================ bool AActor::IsVisibleToPlayer() const { + auto &p = players[consoleplayer]; // [BB] Safety check. This should never be NULL. Nevertheless, we return true to leave the default ZDoom behavior unaltered. - if ( players[consoleplayer].camera == NULL ) + if ( p.camera == nullptr ) return true; if (VisibleToTeam != 0 && teamplay && - (signed)(VisibleToTeam-1) != players[consoleplayer].userinfo.GetTeam() ) + (signed)(VisibleToTeam-1) != p.userinfo.GetTeam() ) return false; auto &vis = GetInfo()->VisibleToPlayerClass; if (vis.Size() == 0) return true; // early out for the most common case. - const player_t* pPlayer = players[consoleplayer].camera->player; + const player_t* pPlayer = p.camera->player; if (pPlayer) {