diff --git a/src/d_player.h b/src/d_player.h index 48649de7ad..e932223aaa 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -532,7 +532,10 @@ public: void TickPSprites(); void DestroyPSprites(); DPSprite *FindPSprite(int layer); - DPSprite *GetPSprite(PSPLayers layer); // Used ONLY for compatibility with the old hardcoded layers. + // Used ONLY for compatibility with the old hardcoded layers. + // Make sure that a state is properly set after calling this unless + // you are 100% sure the context already implies the layer exists. + DPSprite *GetPSprite(PSPLayers layer); }; // Bookkeeping on players - state. diff --git a/src/g_heretic/a_chicken.cpp b/src/g_heretic/a_chicken.cpp index b70e4ff080..7f62d5f0e1 100644 --- a/src/g_heretic/a_chicken.cpp +++ b/src/g_heretic/a_chicken.cpp @@ -123,9 +123,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_Feathers) void P_UpdateBeak (AActor *self) { - if (self->player != nullptr) + DPSprite *pspr; + if (self->player != nullptr && (pspr = self->player->FindPSprite(PSP_WEAPON)) != nullptr) { - self->player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP + self->player->chickenPeck / 2; + pspr->y = WEAPONTOP + self->player->chickenPeck / 2; } } diff --git a/src/g_strife/a_strifestuff.cpp b/src/g_strife/a_strifestuff.cpp index 4e49121fac..4533016ec1 100644 --- a/src/g_strife/a_strifestuff.cpp +++ b/src/g_strife/a_strifestuff.cpp @@ -352,22 +352,12 @@ DEFINE_ACTION_FUNCTION(AActor, A_ItBurnsItBurns) if (self->player != nullptr && self->player->mo == self) { - FState *firehands = self->FindState("FireHands"); - if (firehands != NULL) - { - DPSprite *psp = self->player->GetPSprite(PSP_STRIFEHANDS); - if (psp != nullptr) - { - psp->SetState(firehands); - psp->Flags &= PSPF_ADDWEAPON | PSPF_ADDBOB; - psp->y = WEAPONTOP; - } + P_SetPsprite(self->player, PSP_STRIFEHANDS, self->FindState("FireHands")); - self->player->ReadyWeapon = nullptr; - self->player->PendingWeapon = WP_NOCHANGE; - self->player->playerstate = PST_LIVE; - self->player->extralight = 3; - } + self->player->ReadyWeapon = nullptr; + self->player->PendingWeapon = WP_NOCHANGE; + self->player->playerstate = PST_LIVE; + self->player->extralight = 3; } return 0; } @@ -388,14 +378,22 @@ DEFINE_ACTION_FUNCTION(AActor, A_CrispyPlayer) if (self->player != nullptr && self->player->mo == self) { - self->player->playerstate = PST_DEAD; - DPSprite *psp; psp = self->player->GetPSprite(PSP_STRIFEHANDS); + FState *firehandslower = self->FindState("FireHandsLower"); FState *firehands = self->FindState("FireHands"); - if (firehandslower != NULL && firehands != NULL && firehands < firehandslower) - psp->SetState(psp->GetState() + (firehandslower - firehands)); + FState *state = psp->GetState(); + + if (state != nullptr && firehandslower != nullptr && firehands != nullptr && firehands < firehandslower) + { + self->player->playerstate = PST_DEAD; + psp->SetState(state + (firehandslower - firehands)); + } + else if (state == nullptr) + { + psp->SetState(nullptr); + } } return 0; } @@ -407,13 +405,20 @@ DEFINE_ACTION_FUNCTION(AActor, A_HandLower) if (self->player != nullptr) { DPSprite *psp = self->player->GetPSprite(PSP_STRIFEHANDS); + + if (psp->GetState() == nullptr) + { + psp->SetState(nullptr); + return 0; + } + psp->y += 9; if (psp->y > WEAPONBOTTOM*2) { psp->SetState(nullptr); } + if (self->player->extralight > 0) self->player->extralight--; } return 0; } - diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index e634901108..2e285b34a7 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -216,15 +216,29 @@ DPSprite *player_t::GetPSprite(PSPLayers layer) } // Always update the caller here in case we switched weapon - // or if the layer was being used by an inventory item before. + // or if the layer was being used by something else before. pspr->Caller = newcaller; if (newcaller != oldcaller) - { // Only change the flags if this layer was created now or if we updated the caller. + { // Only reset stuff if this layer was created now or if it was being used before. if (layer >= PSP_TARGETCENTER) { // The targeter layers were affected by those. - pspr->Flags |= (PSPF_CVARFAST|PSPF_POWDOUBLE); + pspr->Flags = (PSPF_CVARFAST|PSPF_POWDOUBLE); } + else + { + pspr->Flags = (PSPF_ADDWEAPON|PSPF_ADDBOB|PSPF_CVARFAST|PSPF_POWDOUBLE); + } + if (layer == PSP_STRIFEHANDS) + { + // Some of the old hacks rely on this layer coming from the FireHands state. + // This is the ONLY time a psprite's state is actually null. + pspr->State = nullptr; + pspr->y = WEAPONTOP; + } + + pspr->oldx = pspr->x; + pspr->oldy = pspr->y; } return pspr; diff --git a/src/p_pspr.h b/src/p_pspr.h index e00f8916fe..d86dafd48c 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -42,7 +42,7 @@ class FArchive; // drawn directly on the view screen, // coordinates are given for a 320*200 view screen. // -enum PSPLayers // These are all called by the owner's ReadyWeapon. +enum PSPLayers { PSP_STRIFEHANDS = -1, PSP_WEAPON = 1, diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 4f4d887794..1b1c7b2cf6 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -329,13 +329,19 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetDistance) // NON-ACTION function to get the angle in degrees (normalized to -180..180) // //========================================================================== +enum GAFlags +{ + GAF_RELATIVE = 1, + GAF_SWITCH = 1 << 1, +}; + DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetAngle) { if (numret > 0) { assert(ret != NULL); PARAM_SELF_PROLOGUE(AActor); - PARAM_BOOL(relative); + PARAM_INT(flags); PARAM_INT_OPT(ptr) { ptr = AAPTR_TARGET; } AActor *target = COPY_AAPTR(self, ptr); @@ -346,9 +352,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetAngle) } else { - DVector3 diff = self->Vec3To(target); + DVector3 diff = (flags & GAF_SWITCH) ? target->Vec3To(self) : self->Vec3To(target); DAngle angto = diff.Angle(); - if (relative) angto = deltaangle(self->Angles.Yaw, angto); + DAngle yaw = (flags & GAF_SWITCH) ? target->Angles.Yaw : self->Angles.Yaw; + if (flags & GAF_RELATIVE) angto = deltaangle(yaw, angto); ret->SetFloat(angto.Degrees); } return 1; @@ -5669,7 +5676,9 @@ enum RadiusGiveFlags RGF_MONSTERS | RGF_OBJECTS | RGF_VOODOO | - RGF_CORPSES | RGF_MISSILES, + RGF_CORPSES | + RGF_MISSILES | + RGF_ITEMS, }; static bool DoRadiusGive(AActor *self, AActor *thing, PClassActor *item, int amount, double distance, int flags, PClassActor *filter, FName species, double mindist) diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 901d7a553d..cb6ff4d934 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -41,7 +41,7 @@ ACTOR Actor native //: Thinker native bool IsPointerEqual(int ptr_select1, int ptr_select2); native int CountInv(class itemtype, int ptr_select = AAPTR_DEFAULT); native float GetDistance(bool checkz, int ptr = AAPTR_DEFAULT); - native float GetAngle(bool relative, int ptr = AAPTR_DEFAULT); + native float GetAngle(int flags, int ptr = AAPTR_DEFAULT); native float GetZAt(float px = 0, float py = 0, float angle = 0, int flags = 0, int pick_pointer = AAPTR_DEFAULT); native int GetSpawnHealth(); native int GetGibHealth(); diff --git a/wadsrc/static/actors/constants.txt b/wadsrc/static/actors/constants.txt index 7b75b481d1..46e810a7f7 100644 --- a/wadsrc/static/actors/constants.txt +++ b/wadsrc/static/actors/constants.txt @@ -652,3 +652,9 @@ enum BT_USER3 = 1<<23, BT_USER4 = 1<<24, }; +// Flags for GetAngle +enum +{ + GAF_RELATIVE = 1, + GAF_SWITCH = 1 << 1, +}; \ No newline at end of file