From 75100d76fb58dfafd4617e70bd28439d214e35c6 Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Mon, 12 Oct 2015 11:06:55 -0500 Subject: [PATCH 1/3] - Added Threshold Manipulation. - Added 'threshold' and 'defthreshold' to DECORATE expression exposure. - ChaseThreshold sets the default threshold for how long a monster must chase one target before it can switch targets. Default is 100, must not be negative. - A_SetChaseThreshold can be used to alter the current or default threshold of an actor . - Changing current threshold has no effect on what the default will be once it hits 0 and something makes it infight with another. --- src/actor.h | 1 + src/namedef.h | 2 ++ src/p_interaction.cpp | 4 ++-- src/p_mobj.cpp | 4 ++++ src/thingdef/thingdef_codeptr.cpp | 27 +++++++++++++++++++++++++++ src/thingdef/thingdef_expression.cpp | 3 ++- src/thingdef/thingdef_properties.cpp | 11 +++++++++++ src/version.h | 2 +- wadsrc/static/actors/actor.txt | 4 ++++ 9 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/actor.h b/src/actor.h index 468dcc0c6..ff011cb78 100644 --- a/src/actor.h +++ b/src/actor.h @@ -932,6 +932,7 @@ public: // player to freeze a bit after teleporting SDWORD threshold; // if > 0, the target will be chased // no matter what (even if shot) + SDWORD DefThreshold; // [MC] Default threshold which the actor will reset its threshold to after switching targets player_t *player; // only valid if type of APlayerPawn TObjPtr LastLookActor; // Actor last looked for (if TIDtoHate != 0) fixed_t SpawnPoint[3]; // For nightmare respawn diff --git a/src/namedef.h b/src/namedef.h index 0d49bba76..f420aca96 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -294,6 +294,8 @@ xx(Z) xx(MomX) xx(MomY) xx(MomZ) +xx(Threshold) +xx(DefThreshold) xx(Abs) xx(ACS_NamedExecuteWithResult) xx(CallACS) diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index 25724172c..9d9db5167 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -1516,7 +1516,7 @@ dopain: { if (source == target->target) { - target->threshold = BASETHRESHOLD; + target->threshold = target->DefThreshold; //BASETHRESHOLD is no longer used here. if (target->state == target->SpawnState && target->SeeState != NULL) { target->SetState (target->SeeState); @@ -1537,7 +1537,7 @@ dopain: target->lastenemy = target->target; // remember last enemy - killough } target->target = source; - target->threshold = BASETHRESHOLD; + target->threshold = target->DefThreshold; if (target->state == target->SpawnState && target->SeeState != NULL) { target->SetState (target->SeeState); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 901372eef..3a55e2232 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -344,6 +344,10 @@ void AActor::Serialize (FArchive &arc) << RipLevelMin << RipLevelMax; } + if (SaveVersion >= 4525) + { + arc << DefThreshold; + } { FString tagstr; diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index f56fa6633..dfb3b5407 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -5870,6 +5870,33 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetRipMax) self->RipLevelMax = max; } +//=========================================================================== +// +// A_SetChaseThreshold(int threshold, bool def, int ptr) +// +// Sets the current chase threshold of the actor (pointer). If def is true, +// changes the default threshold which the actor resets to once it switches +// targets and doesn't have the +QUICKTORETALIATE flag. +//=========================================================================== +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SetChaseThreshold) +{ + ACTION_PARAM_START(3); + ACTION_PARAM_INT(threshold, 0); + ACTION_PARAM_BOOL(def, 1); + ACTION_PARAM_INT(ptr, 2); + + AActor *mobj = COPY_AAPTR(self, ptr); + if (!mobj) + { + ACTION_SET_RESULT(false); + return; + } + if (def) + mobj->DefThreshold = (threshold >= 0) ? threshold : 0; + else + mobj->threshold = (threshold >= 0) ? threshold : 0; +} + /*=========================================================================== A_CheckBlock (state block, int flags, int ptr) diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index 3746a6ca7..7c352d8d7 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -90,7 +90,8 @@ DEFINE_MEMBER_VARIABLE(reactiontime, AActor) DEFINE_MEMBER_VARIABLE(meleerange, AActor) DEFINE_MEMBER_VARIABLE(Speed, AActor) DEFINE_MEMBER_VARIABLE(roll, AActor) - +DEFINE_MEMBER_VARIABLE(threshold, AActor) +DEFINE_MEMBER_VARIABLE(DefThreshold, AActor) //========================================================================== // diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 183cf2709..c32379051 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -532,6 +532,17 @@ DEFINE_PROPERTY(painthreshold, I, Actor) defaults->PainThreshold = id; } +//========================================================================== +// +//========================================================================== +DEFINE_PROPERTY(chasethreshold, I, Actor) +{ + PROP_INT_PARM(id, 0); + if (id < 0) + I_Error("ChaseThreshold cannot be negative."); + defaults->DefThreshold = id; +} + //========================================================================== // //========================================================================== diff --git a/src/version.h b/src/version.h index 913c9bd18..168cb7519 100644 --- a/src/version.h +++ b/src/version.h @@ -76,7 +76,7 @@ const char *GetVersionString(); // Use 4500 as the base git save version, since it's higher than the // SVN revision ever got. -#define SAVEVER 4524 +#define SAVEVER 4525 #define SAVEVERSTRINGIFY2(x) #x #define SAVEVERSTRINGIFY(x) SAVEVERSTRINGIFY2(x) diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index d44dd4627..0c42ea574 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -31,6 +31,7 @@ ACTOR Actor native //: Thinker RipperLevel 0 RipLevelMin 0 RipLevelMax 0 + ChaseThreshold 100 // Variables for the expression evaluator // NOTE: fixed_t and angle_t are only used here to ensure proper conversion @@ -69,6 +70,8 @@ ACTOR Actor native //: Thinker native fixed_t meleerange; native fixed_t speed; native angle_t roll; + native int threshold; + native int DefThreshold; // Meh, MBF redundant functions. Only for DeHackEd support. action native A_Turn(float angle = 0); @@ -337,6 +340,7 @@ ACTOR Actor native //: Thinker action native A_SetRipperLevel(int level); action native A_SetRipMin(int min); action native A_SetRipMax(int max); + action native A_SetChaseThreshold(int threshold, bool def = false, int ptr = AAPTR_DEFAULT); action native A_CheckBlock(state block, int flags = 0, int ptr = AAPTR_DEFAULT); action native A_CheckSightOrRange(float distance, state label, bool two_dimension = false); action native A_CheckRange(float distance, state label, bool two_dimension = false); From c5f433d80a51f2faa72af3aa2a7709c49059129d Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Wed, 14 Oct 2015 07:36:30 -0500 Subject: [PATCH 2/3] No more BASETHRESHOLD. --- src/g_strife/a_rebels.cpp | 2 +- src/p_local.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/g_strife/a_rebels.cpp b/src/g_strife/a_rebels.cpp index 81490c361..ec4a36be6 100644 --- a/src/g_strife/a_rebels.cpp +++ b/src/g_strife/a_rebels.cpp @@ -85,7 +85,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Beacon) self->flags &= ~MF_SPECIAL; static_cast(self)->DropTime = 0; // Set up the new rebel. - rebel->threshold = BASETHRESHOLD; + rebel->threshold = rebel->DefThreshold; rebel->target = NULL; rebel->flags4 |= MF4_INCOMBAT; rebel->LastHeard = owner; // Make sure the rebels look for targets diff --git a/src/p_local.h b/src/p_local.h index 95d7541a8..394382e8f 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -87,7 +87,8 @@ inline int GetSafeBlockY(long long blocky) #define PLAYERMISSILERANGE (8192*FRACUNIT) // [RH] New MISSILERANGE for players // follow a player exlusively for 3 seconds -#define BASETHRESHOLD 100 +// No longer used. +// #define BASETHRESHOLD 100 // From ccf887c9784f0bfb2ecf6c94904ced0a018a3c3b Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Sat, 6 Feb 2016 13:49:16 -0600 Subject: [PATCH 3/3] Fixed wrong type. --- src/thingdef/thingdef_data.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thingdef/thingdef_data.cpp b/src/thingdef/thingdef_data.cpp index fd99cf515..82fe3a739 100644 --- a/src/thingdef/thingdef_data.cpp +++ b/src/thingdef/thingdef_data.cpp @@ -651,6 +651,6 @@ void InitThingdef() symt.AddSymbol(new PField(NAME_ReactionTime,TypeSInt32, VARF_Native, myoffsetof(AActor,reactiontime))); symt.AddSymbol(new PField(NAME_MeleeRange, TypeFixed, VARF_Native, myoffsetof(AActor,meleerange))); symt.AddSymbol(new PField(NAME_Speed, TypeFixed, VARF_Native, myoffsetof(AActor,Speed))); - symt.AddSymbol(new PField(NAME_Threshold, TypeFixed, VARF_Native, myoffsetof(AActor,threshold))); - symt.AddSymbol(new PField(NAME_DefThreshold,TypeFixed, VARF_Native, myoffsetof(AActor,DefThreshold))); + symt.AddSymbol(new PField(NAME_Threshold, TypeSInt32, VARF_Native, myoffsetof(AActor,threshold))); + symt.AddSymbol(new PField(NAME_DefThreshold,TypeSInt32, VARF_Native, myoffsetof(AActor,DefThreshold))); }