Added classic flashlight from Doom BFA and detection for Doom 2004/2019

This commit is contained in:
Robert Beckebans 2024-06-27 21:05:51 +02:00
parent e7dfa30783
commit d147b7f038
8 changed files with 139 additions and 24 deletions

View file

@ -68,7 +68,6 @@ EVENT( EV_Activate, idLight::Event_ToggleOnOff )
EVENT( EV_PostSpawn, idLight::Event_SetSoundHandles )
EVENT( EV_Light_FadeOut, idLight::Event_FadeOut )
EVENT( EV_Light_FadeIn, idLight::Event_FadeIn )
EVENT( EV_Light_FadeIn, idLight::Event_FadeIn )
EVENT( EV_Light_UpdateModelTarget, idLight::Event_UpdateModelTarget )
END_CLASS

View file

@ -4123,7 +4123,8 @@ bool idPlayer::GiveItem( idItem* item, unsigned int giveFlags )
return false;
}
if( idStr::FindText( item->GetName(), "weapon_flashlight" ) > -1 )
//GK: Classic mode
if( idStr::FindText( item->GetName(), "weapon_flashlight" ) > -1 && !UsesClassicFlashlight() )
{
// don't allow flashlight weapon unless classic mode is enabled
return false;
@ -5096,7 +5097,7 @@ void idPlayer::NextBestWeapon()
while( w > 0 )
{
w--;
if( w == weapon_flashlight && !gc_classicFlashlight.GetBool() )
if( w == weapon_flashlight && !UsesClassicFlashlight() )
{
continue;
}
@ -5129,7 +5130,7 @@ void idPlayer::NextBestWeapon()
//GK: A small logic HACK for the orginal Doom 3 Flashlight
weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
if( gc_classicFlashlight.GetBool() )
if( UsesClassicFlashlight() )
{
if( !idStr::Icmp( "weapon_flashlight", weap ) )
{
@ -5180,12 +5181,12 @@ void idPlayer::NextWeapon()
}
const char* weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
if( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) && !( !idStr::Icmp( "weapon_flashlight", weap ) && gc_classicFlashlight.GetBool() ) )
if( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) && !( !idStr::Icmp( "weapon_flashlight", weap ) && UsesClassicFlashlight() ) )
{
continue;
}
if( ( !idStr::Icmp( "weapon_flashlight", weap ) && gc_classicFlashlight.GetBool() ) && flashlightBattery < flashlight_batteryDrainTimeMS.GetInteger() && !flashlight.GetEntity()->lightOn )
if( ( !idStr::Icmp( "weapon_flashlight", weap ) && UsesClassicFlashlight() ) && flashlightBattery < flashlight_batteryDrainTimeMS.GetInteger() && !flashlight.GetEntity()->lightOn )
{
continue;
}
@ -5209,7 +5210,7 @@ void idPlayer::NextWeapon()
//GK: A small logic HACK for the orginal Doom 3 Flashlight
const char* weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
if( gc_classicFlashlight.GetBool() )
if( UsesClassicFlashlight() )
{
if( !idStr::Icmp( "weapon_flashlight", weap ) )
{
@ -5246,6 +5247,10 @@ void idPlayer::PrevWeapon()
while( 1 )
{
w--;
if( w == 0 )
{
break;
}
if( w < 0 )
{
w = MAX_WEAPONS - 1;
@ -5260,7 +5265,15 @@ void idPlayer::PrevWeapon()
continue;
}
const char* weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
if( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) )
//GK: And another def HACK for the original flashlight
if( !spawnArgs.GetBool( va( "weapon%d_cycle", w ) ) && !( !idStr::Icmp( "weapon_flashlight", weap ) && UsesClassicFlashlight() ) )
{
continue;
}
//GK: Make sure the player to be unable to change to the flashlight if it is charging
if( ( !idStr::Icmp( "weapon_flashlight", weap ) && UsesClassicFlashlight() ) && flashlightBattery < flashlight_batteryDrainTimeMS.GetInteger() && !flashlight.GetEntity()->lightOn )
{
continue;
}
@ -5279,6 +5292,20 @@ void idPlayer::PrevWeapon()
idealWeapon = w;
weaponSwitchTime = gameLocal.time + WEAPON_SWITCH_DELAY;
UpdateHudWeapon();
//GK: A small logic HACK for the orginal Doom 3 Flashlight
const char* weap = spawnArgs.GetString( va( "def_weapon%d", w ) );
if( UsesClassicFlashlight() )
{
if( !idStr::Icmp( "weapon_flashlight", weap ) )
{
flashlight.GetEntity()->lightOn = true;
}
else
{
flashlight.GetEntity()->lightOn = false;
}
}
}
}
@ -5301,7 +5328,8 @@ void idPlayer::SelectWeapon( int num, bool force )
return;
}
if( num == weapon_flashlight )
// GK: classic flash light
if( num == weapon_flashlight && !UsesClassicFlashlight() )
{
return;
}
@ -5408,6 +5436,21 @@ void idPlayer::SelectWeapon( int num, bool force )
idealWeapon = num;
}
UpdateHudWeapon();
//GK: A small logic HACK for the orginal Doom 3 Flashlight
const char* weap_ = spawnArgs.GetString( va( "def_weapon%d", num ) );
if( UsesClassicFlashlight() )
{
if( !idStr::Icmp( "weapon_flashlight", weap_ ) )
{
flashlight.GetEntity()->lightOn = true;
}
else
{
flashlight.GetEntity()->lightOn = false;
}
}
}
}
@ -5914,6 +5957,12 @@ void idPlayer::UpdateWeapon()
weapon.GetEntity()->PresentWeapon( CanShowWeaponViewmodel() );
}
// RB
bool idPlayer::UsesClassicFlashlight()
{
return ( ng_classicFlashlight.GetBool() || fileSystem->IsDoom2004() );
}
/*
===============
idPlayer::UpdateFlashLight
@ -5922,7 +5971,7 @@ idPlayer::UpdateFlashLight
void idPlayer::UpdateFlashlight()
{
//GK: Classic mode
if( idealWeapon == weapon_flashlight && !gc_classicFlashlight.GetBool() )
if( idealWeapon == weapon_flashlight && !UsesClassicFlashlight() )
{
// force classic flashlight to go away
NextWeapon();
@ -5967,13 +6016,13 @@ void idPlayer::UpdateFlashlight()
}
}
//GK: don't waste the battery without flashlight
if( gc_classicFlashlight.GetBool() && idealWeapon != weapon_flashlight && flashlightBattery > 0 )
if( UsesClassicFlashlight() && idealWeapon != weapon_flashlight && flashlightBattery > 0 )
{
flashlightBattery = flashlight_batteryDrainTimeMS.GetInteger();
}
//GK: Well aparently the original flashlight had no battery
if( gc_classicFlashlight.GetBool() == 1 && flashlightBattery != flashlight_batteryDrainTimeMS.GetInteger() )
if( UsesClassicFlashlight() == 1 && flashlightBattery != flashlight_batteryDrainTimeMS.GetInteger() )
{
flashlightBattery = flashlight_batteryDrainTimeMS.GetInteger();
}
@ -6011,7 +6060,7 @@ void idPlayer::UpdateFlashlight()
if( !flashlight.GetEntity()->IsLinked() )
{
//GK: hiding the BFG flashlight when the original is active
if( gc_classicFlashlight.GetBool() )
if( UsesClassicFlashlight() )
{
flashlight.GetEntity()->GetWeaponDef( "weapon_flashlight", 0 );
}
@ -6023,7 +6072,7 @@ void idPlayer::UpdateFlashlight()
// adjust position / orientation of flashlight
idAnimatedEntity* worldModel = flashlight.GetEntity()->GetWorldModel();
if( !gc_classicFlashlight.GetBool() )
if( !UsesClassicFlashlight() )
{
worldModel->BindToJoint( this, "Chest", true );
@ -6037,7 +6086,7 @@ void idPlayer::UpdateFlashlight()
// this positions the third person flashlight model! (as seen in the mirror)
idAnimatedEntity* worldModel = flashlight.GetEntity()->GetWorldModel();
if( !gc_classicFlashlight.GetBool() )
if( !UsesClassicFlashlight() )
{
static const idVec3 fl_pos = idVec3( 3.0f, 9.0f, 2.0f );
worldModel->GetPhysics()->SetOrigin( fl_pos );
@ -6067,7 +6116,7 @@ void idPlayer::UpdateFlashlight()
flashlight.GetEntity()->PresentWeapon( true );
if( !gc_classicFlashlight.GetBool() ) //GK: Not legacy no care
if( !UsesClassicFlashlight() ) //GK: Not legacy no care
{
if( gameLocal.world->spawnArgs.GetBool( "no_Weapons" ) || gameLocal.inCinematic || spectating || fl.hidden )
{
@ -7683,14 +7732,30 @@ void idPlayer::PerformImpulse( int impulse )
{
if( flashlight.IsValid() )
{
// GK: support old flash light
if( flashlight.GetEntity()->lightOn && UsesClassicFlashlight() && currentWeapon != weapon_flashlight )
{
flashlight.GetEntity()->lightOn = false;
}
if( flashlight.GetEntity()->lightOn )
{
// select previous weapon when the flashlight is switched off
if( UsesClassicFlashlight() )
{
SelectWeapon( previousWeapon, false );
}
FlashlightOff();
}
else if( !spectating && weaponEnabled && !hiddenWeapon && !gameLocal.world->spawnArgs.GetBool( "no_Weapons" ) )
{
if( UsesClassicFlashlight() )
{
SelectWeapon( weapon_flashlight, false );
}
FlashlightOn();
}
// GK end
}
break;
}

View file

@ -925,6 +925,7 @@ private:
void Weapon_NPC();
void Weapon_GUI();
void UpdateWeapon();
bool UsesClassicFlashlight();
void UpdateFlashlight();
void FlashlightOn();
void FlashlightOff();

View file

@ -324,6 +324,6 @@ idCVar g_grabberDamping( "g_grabberDamping", "0.5", CVAR_GAME | CVAR_FLOAT
idCVar g_xp_bind_run_once( "g_xp_bind_run_once", "0", CVAR_GAME | CVAR_BOOL | CVAR_ARCHIVE, "Rebind all controls once for D3XP." );
// RB begin
idCVar gc_classicFlashlight( "gc_classicFlashlight", "0", CVAR_GAME | CVAR_BOOL | CVAR_ARCHIVE, "Classic flash light weapon" );
// RB: new game mode vars
idCVar ng_classicFlashlight( "ng_classicFlashlight", "0", CVAR_GAME | CVAR_BOOL | CVAR_ARCHIVE, "Classic flash light weapon" );
// RB end

View file

@ -271,8 +271,8 @@ extern idCVar g_CTFArrows;
extern idCVar net_clientSelfSmoothing;
// RB: classic mode vars
extern idCVar gc_classicFlashlight;
// RB: new game mode vars
extern idCVar ng_classicFlashlight;
// RB end
#endif /* !__SYS_CVAR_H__ */

View file

@ -124,6 +124,8 @@ for instance to base a mod of D3 + D3XP assets, fs_game mymod, fs_game_base d3xp
#define MAX_ZIPPED_FILE_NAME 2048
#define FILE_HASH_SIZE 1024
#define DOOM3_PAK0_CHECKSUM 0x28d208f1
struct searchpath_t
{
idStr path; // c:\doom
@ -184,16 +186,30 @@ public:
// RB begin
virtual bool InProductionMode();
// Returns true if Doom 2004 is detected
virtual bool IsDoom2004() const
{
return doom2004Found;
}
// Returns true if Doom 2019 is detected
// that one is BFG without Doom 1 & 2 and without multiplayer
virtual bool IsDoom2019() const
{
return doom2019Found;
}
virtual bool UsingZipFiles()
{
return zipFilesFound;
}
// RB end
virtual bool UsingResourceFiles()
{
// was return resourceFiles.Num() > 0;
return resourceFilesFound;
}
virtual bool UsingZipFiles()
{
return zipFilesFound;
}
virtual void UnloadMapResources( const char* name );
virtual void UnloadResourceContainer( const char* name );
@ -274,6 +290,8 @@ private:
// RB: shortcut
bool resourceFilesFound = false;
bool zipFilesFound = false;
bool doom2004Found = false;
bool doom2019Found = false;
private:
@ -3201,6 +3219,12 @@ void idFileSystemLocal::AddGameDirectory( const char* path, const char* dir )
//com_productionMode.SetInteger( 2 );
zipFilesFound = true;
if( zip->GetChecksum() == DOOM3_PAK0_CHECKSUM )
{
doom2004Found = true;
common->Warning( "Doom 3 2004 Edition detected\n" );
}
}
}
}
@ -3342,6 +3366,15 @@ void idFileSystemLocal::Init()
// try to start up normally
Startup();
// RB: check for Doom 3 2019 Edition
// This edition does not come with .crc files but the game content is almost the same except for some updated magics in the binary file headers.
// We also don't have the luxury of .pk4 files where we can calculate quickly a checksum from the files inside
// so we just test for a file that isn't in the BFG edition
if( ReadFile( "generated/images/ui/assets/guicursor_hand_xbone_a#__0200.bimage", NULL, NULL ) > 0 )
{
doom2019Found = true;
}
// if we can't find default.cfg, assume that the paths are
// busted and error out now, rather than getting an unreadable
// graphics screen when the font fails to load

View file

@ -245,6 +245,15 @@ public:
virtual void AddParticlePreload( const char* resName ) = 0;
virtual void AddCollisionPreload( const char* resName ) = 0;
// RB begin
// Returns true if Doom 2004 is detected
virtual bool IsDoom2004() const = 0;
// Returns true if Doom 2019 is detected
// that one is BFG without Doom 1 & 2 and without multiplayer
virtual bool IsDoom2019() const = 0;
// RB end
};
extern idFileSystem* fileSystem;

View file

@ -589,10 +589,18 @@ float idSoundSample_XAudio2::GetAmplitude( int timeMS ) const
{
return 0.0f;
}
if( IsDefault() )
{
return 1.0f;
}
// RB: don't have amplitudes for the original Doom 3 so return 1.0 to avoid many missing lights
if( fileSystem->IsDoom2004() )
{
return 1.0f;
}
int index = timeMS * 60 / 1000;
if( index < 0 || index >= amplitude.Num() )
{