- Ported the COMPATF2_OLD_RANDOM_GENERATOR compatibility flag from Zandronum and added it to the Doom (Strict) compatibility mode.

Added new compatflag "old random generator", controlled by the new CVAR compat_oldrandom. If this is enabled, the original Doom random table is used to generate random integers in [0,255], which should make for instance the SSG cause a little more damage.
This commit is contained in:
drfrag 2020-08-24 16:11:07 +02:00
parent 479f421007
commit f9bd158211
8 changed files with 80 additions and 9 deletions

View file

@ -598,7 +598,7 @@ CUSTOM_CVAR(Int, compatmode, 0, CVAR_ARCHIVE|CVAR_NOINITCALL)
COMPATF_TRACE | COMPATF_MISSILECLIP | COMPATF_SOUNDTARGET | COMPATF_NO_PASSMOBJ | COMPATF_LIMITPAIN |
COMPATF_DEHHEALTH | COMPATF_INVISIBILITY | COMPATF_CROSSDROPOFF | COMPATF_CORPSEGIBS | COMPATF_HITSCAN |
COMPATF_WALLRUN | COMPATF_NOTOSSDROPS | COMPATF_LIGHT | COMPATF_MASKEDMIDTEX;
w = COMPATF2_BADANGLES | COMPATF2_FLOORMOVE | COMPATF2_POINTONLINE | COMPATF2_EXPLODE2;
w = COMPATF2_BADANGLES | COMPATF2_FLOORMOVE | COMPATF2_POINTONLINE | COMPATF2_EXPLODE2 | COMPATF2_OLD_RANDOM_GENERATOR;
break;
case 3: // Boom compat mode
@ -677,6 +677,7 @@ CVAR (Flag, compat_checkswitchrange, compatflags2, COMPATF2_CHECKSWITCHRANGE);
CVAR (Flag, compat_explode1, compatflags2, COMPATF2_EXPLODE1);
CVAR (Flag, compat_explode2, compatflags2, COMPATF2_EXPLODE2);
CVAR (Flag, compat_railing, compatflags2, COMPATF2_RAILING);
CVAR (Flag, compat_oldrandom, compatflags2, COMPATF2_OLD_RANDOM_GENERATOR);
CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
@ -2123,6 +2124,7 @@ static void D_DoomInit()
srand(rngseed);
FRandom::StaticClearRandom ();
M_ClearRandom();
if (!batchrun) Printf ("M_LoadDefaults: Load system defaults.\n");
M_LoadDefaults (); // load before initing other systems

View file

@ -506,6 +506,7 @@ enum : unsigned int
COMPATF2_EXPLODE2 = 1 << 9, // Use original explosion code throughout.
COMPATF2_RAILING = 1 << 10, // Bugged Strife railings.
COMPATF2_SCRIPTWAIT = 1 << 11, // Use old scriptwait implementation where it doesn't wait on a non-running script.
COMPATF2_OLD_RANDOM_GENERATOR = 1 << 12, // [BB] Use Doom's random table instead of ZDoom's random number generator.
};
// Emulate old bugs for select maps. These are not exposed by a cvar

View file

@ -2683,6 +2683,7 @@ bool G_ProcessIFFDemo (FString &mapname)
if (mapname[0] != 0)
{
FRandom::StaticClearRandom ();
M_ClearRandom();
}
consoleplayer = *demo_p++;
break;

View file

@ -474,6 +474,7 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
rngseed = use_staticrng ? staticrngseed : (rngseed + 1);
}
FRandom::StaticClearRandom ();
M_ClearRandom();
P_ClearACSVars(true);
level.time = 0;
level.maptime = 0;

View file

@ -60,6 +60,7 @@
#include <assert.h>
#include "doomstat.h"
#include "doomdef.h"
#include "m_random.h"
#include "serializer.h"
#include "b_bot.h"
@ -75,6 +76,36 @@
// TYPES -------------------------------------------------------------------
// Doom's original random number generator.
//
// M_Random
// Returns a 0-255 number
//
unsigned char rndtable[256] = {
0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66 ,
74, 21, 211, 47, 80, 242, 154, 27, 205, 128, 161, 89, 77, 36 ,
95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188 ,
52, 140, 202, 120, 68, 145, 62, 70, 184, 190, 91, 197, 152, 224 ,
149, 104, 25, 178, 252, 182, 202, 182, 141, 197, 4, 81, 181, 242 ,
145, 42, 39, 227, 156, 198, 225, 193, 219, 93, 122, 175, 249, 0 ,
175, 143, 70, 239, 46, 246, 163, 53, 163, 109, 168, 135, 2, 235 ,
25, 92, 20, 145, 138, 77, 69, 166, 78, 176, 173, 212, 166, 113 ,
94, 161, 41, 50, 239, 49, 111, 164, 70, 60, 2, 37, 171, 75 ,
136, 156, 11, 56, 42, 146, 138, 229, 73, 146, 77, 61, 98, 196 ,
135, 106, 63, 197, 195, 86, 96, 203, 113, 101, 170, 247, 181, 113 ,
80, 250, 108, 7, 255, 237, 129, 226, 79, 107, 112, 166, 103, 241 ,
24, 223, 239, 120, 198, 58, 60, 82, 128, 3, 184, 66, 143, 224 ,
145, 224, 81, 206, 163, 45, 63, 90, 168, 114, 59, 33, 159, 95 ,
28, 139, 123, 98, 125, 196, 15, 70, 194, 253, 54, 14, 109, 226 ,
71, 17, 161, 93, 186, 87, 244, 138, 20, 52, 123, 251, 26, 36 ,
17, 46, 52, 231, 232, 76, 31, 221, 84, 37, 216, 165, 212, 106 ,
197, 242, 98, 43, 39, 175, 254, 145, 190, 84, 118, 222, 187, 136 ,
120, 163, 236, 249
};
int prndindex = 0;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
@ -139,6 +170,18 @@ static TDeletingArray<FRandom *> NewRNGs;
// CODE --------------------------------------------------------------------
// Which one is deterministic?
int P_Random (void)
{
prndindex = (prndindex+1)&0xff;
return rndtable[prndindex];
}
void M_ClearRandom (void)
{
prndindex = 0;
}
//==========================================================================
//
// FRandom - Nameless constructor
@ -230,6 +273,26 @@ FRandom::~FRandom ()
}
}
// [BB] Moved implementation here.
int FRandom::operator()()
{
// [BB] Use Doom's original random numbers if the user wants it.
if ( compatflags2 & COMPATF2_OLD_RANDOM_GENERATOR )
return P_Random();
return GenRand32() & 255;
}
// [BB] Moved implementation here.
int FRandom::Random2()
{
// [BB] Use Doom's original random numbers if the user wants it.
if ( compatflags2 & COMPATF2_OLD_RANDOM_GENERATOR )
return ( P_Random() - P_Random() );
return Random2(255);
}
//==========================================================================
//
// FRandom :: StaticClearRandom
@ -336,6 +399,7 @@ void FRandom::StaticReadRNGState(FSerializer &arc)
// Call StaticClearRandom in order to ensure that SFMT is initialized
FRandom::StaticClearRandom ();
M_ClearRandom();
if (arc.BeginArray("rngs"))
{

View file

@ -49,10 +49,8 @@ public:
~FRandom ();
// Returns a random number in the range [0,255]
int operator()()
{
return GenRand32() & 255;
}
// [BB] Moved the implementation to m_random.cpp.
int operator()();
// Returns a random number in the range [0,mod)
int operator() (int mod)
@ -63,10 +61,8 @@ public:
}
// Returns rand# - rand#
int Random2()
{
return Random2(255);
}
// [BB] Moved the implementation to m_random.cpp.
int Random2();
// Returns (rand# & mask) - (rand# & mask)
int Random2(int mask)
@ -224,4 +220,8 @@ extern bool use_staticrng;
// M_Random can be used for numbers that do not affect gameplay
extern FRandom M_Random;
// Returns a number from 0 to 255, from a lookup table.
int P_Random (void);
void M_ClearRandom (void);
#endif

View file

@ -2219,6 +2219,7 @@ CMPTMNU_CHECKSWITCHRANGE = "Enable buggy CheckSwitchRange behavior";
CMPTMNU_EXPLODE1 = "No vertical thrust from explosions";
CMPTMNU_EXPLODE2 = "Use original Doom explosion behavior";
CMPTMNU_RAILINGHACK = "Enable buggy Strife railing";
CMPTMNU_OLDRANDOM = "Use original Doom pseudo-RNG";
// Sound Options
SNDMNU_TITLE = "SOUND OPTIONS";

View file

@ -1675,6 +1675,7 @@ OptionMenu "CompatActorMenu" protected
Option "$CMPTMNU_INVISIBILITY", "compat_INVISIBILITY", "YesNo"
Option "$CMPTMNU_MINOTAUR", "compat_MINOTAUR", "YesNo"
Option "$CMPTMNU_NOTOSSDROPS", "compat_NOTOSSDROPS", "YesNo"
Option "$CMPTMNU_OLDRANDOM", "compat_oldrandom", "YesNo"
Class "CompatibilityMenu"
}