diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 49e8211785..4239ae3d3b 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1353,7 +1353,7 @@ static int PatchFrame (int frameNum) if (keylen == 8 && stricmp (Line1, "Duration") == 0) { - tics = clamp (val, -1, 65534); + tics = clamp (val, -1, SHRT_MAX); } else if (keylen == 9 && stricmp (Line1, "Unknown 1") == 0) { diff --git a/src/info.cpp b/src/info.cpp index 69476d2903..4d3225344e 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -55,6 +55,8 @@ extern void LoadActors (); extern void InitBotStuff(); extern void ClearStrifeTypes(); +FRandom FState::pr_statetics; + //========================================================================== // // diff --git a/src/info.h b/src/info.h index c2962512d7..87e623814d 100644 --- a/src/info.h +++ b/src/info.h @@ -45,6 +45,7 @@ #include "doomdef.h" #include "m_fixed.h" +#include "m_random.h" struct Baggage; class FScanner; @@ -61,18 +62,19 @@ enum struct FState { + FState *NextState; + actionf_p ActionFunc; WORD sprite; SWORD Tics; - int Misc1; // Was changed to SBYTE, reverted to long for MBF compat - int Misc2; // Was changed to BYTE, reverted to long for MBF compat + WORD TicRange; BYTE Frame; BYTE DefineFlags; // Unused byte so let's use it during state creation. + int Misc1; // Was changed to SBYTE, reverted to long for MBF compat + int Misc2; // Was changed to BYTE, reverted to long for MBF compat short Light; BYTE Fullbright:1; // State is fullbright BYTE SameFrame:1; // Ignore Frame (except when spawning actor) BYTE Fast:1; - FState *NextState; - actionf_p ActionFunc; int ParameterIndex; inline int GetFrame() const @@ -89,7 +91,11 @@ struct FState } inline int GetTics() const { - return Tics; + if (TicRange == 0) + { + return Tics; + } + return Tics + pr_statetics.GenRand32() % (TicRange + 1); } inline int GetMisc1() const { @@ -134,6 +140,7 @@ struct FState } static const PClass *StaticFindStateOwner (const FState *state); static const PClass *StaticFindStateOwner (const FState *state, const FActorInfo *info); + static FRandom pr_statetics; }; struct FStateLabels; diff --git a/src/thingdef/olddecorations.cpp b/src/thingdef/olddecorations.cpp index 421ff1e888..d4db28e96e 100644 --- a/src/thingdef/olddecorations.cpp +++ b/src/thingdef/olddecorations.cpp @@ -199,6 +199,7 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def) if (info->NumOwnedStates == 1) { info->OwnedStates->Tics = -1; + info->OwnedStates->TicRange = 0; info->OwnedStates->Misc1 = 0; } else @@ -226,6 +227,7 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def) else { info->OwnedStates[i].Tics = -1; + info->OwnedStates[i].TicRange = 0; info->OwnedStates[i].Misc1 = 0; } @@ -273,6 +275,7 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def) else { info->OwnedStates[i].Tics = -1; + info->OwnedStates[i].TicRange = 0; info->OwnedStates[i].Misc1 = 0; } @@ -307,12 +310,14 @@ void ParseOldDecoration(FScanner &sc, EDefinitionType def) } info->OwnedStates[i].NextState = &info->OwnedStates[info->NumOwnedStates-1]; info->OwnedStates[i].Tics = 5; + info->OwnedStates[i].TicRange = 0; info->OwnedStates[i].Misc1 = 0; info->OwnedStates[i].SetAction(FindGlobalActionFunction("A_FreezeDeath")); i = info->NumOwnedStates - 1; info->OwnedStates[i].NextState = &info->OwnedStates[i]; info->OwnedStates[i].Tics = 1; + info->OwnedStates[i].TicRange = 0; info->OwnedStates[i].Misc1 = 0; info->OwnedStates[i].SetAction(FindGlobalActionFunction("A_FreezeDeathChunks")); bag.statedef.SetStateLabel("Ice", &info->OwnedStates[extra.IceDeathStart]); @@ -671,6 +676,7 @@ static void ParseSpriteFrames (FActorInfo *info, TArray &states, FScanne } state.Tics = rate; + state.TicRange = 0; while (*token) { diff --git a/src/thingdef/thingdef_states.cpp b/src/thingdef/thingdef_states.cpp index 31d49db5d0..5c2d81602b 100644 --- a/src/thingdef/thingdef_states.cpp +++ b/src/thingdef/thingdef_states.cpp @@ -56,6 +56,7 @@ #include "colormatcher.h" #include "thingdef_exp.h" #include "version.h" +#include "templates.h" //========================================================================== //*** @@ -237,8 +238,30 @@ do_stop: sc.MustGetString(); statestring = sc.String; - sc.MustGetNumber(); - state.Tics = clamp(sc.Number, -1, 32767); + if (sc.CheckString("RANDOM")) + { + int min, max; + + sc.MustGetStringName("("); + sc.MustGetNumber(); + min = clamp(sc.Number, -1, SHRT_MAX); + sc.MustGetStringName(","); + sc.MustGetNumber(); + max = clamp(sc.Number, -1, SHRT_MAX); + sc.MustGetStringName(")"); + if (min > max) + { + swapvalues(min, max); + } + state.Tics = min; + state.TicRange = max - min; + } + else + { + sc.MustGetNumber(); + state.Tics = clamp(sc.Number, -1, SHRT_MAX); + state.TicRange = 0; + } while (sc.GetString() && !sc.Crossed) {