Skip to content

Commit

Permalink
New CVar: mp_dying_time (#483)
Browse files Browse the repository at this point in the history
* Add new CVar: mp_dying_time < 0 .. 999>

* Add description

* magic numbers to named const

* magic numbers to named const (№2)

* cvar value handling

* update description

* a better description

* resolve conflicts

* lil order fixes & indent

* remove death animation skip

* DYING_TIME -> DEATH_ANIMATION_TIME

* Fix death animation when mp_dying_time < 3.0 depending on animation

* change desc

* change cvar desc

---------

Co-authored-by: dystopm <fjmunozpena@gmail.com>
  • Loading branch information
wopox1337 and dystopm committed Jul 12, 2023
1 parent e1d1c11 commit 8a18969
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_give_c4_frags | 3 | - | - | How many bonuses (frags) will get the player who defused or exploded the bomb. |
| mp_hostages_rescued_ratio | 1.0 | 0.0 | 1.0 | Ratio of hostages rescued to win the round. |
| mp_legacy_vehicle_block | 1 | 0 | 1 | Legacy func_vehicle behavior when blocked by another entity.<br/>`0` New behavior <br/>`1` Legacy behavior |
| mp_dying_time | 3.0 | 0.0 | - | Time for switch to free observing after death.<br/>`0` - disable spectating around death.<br/>`>0.00001` - time delay to start spectate.<br/>`NOTE`: The countdown starts when the player’s death animation is finished.|
</details>

## How to install zBot for CS 1.6?
Expand Down
8 changes: 8 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,11 @@ mp_hostages_rescued_ratio "1.0"
//
// Default value: "1"
mp_legacy_vehicle_block "1"
// Time for switch to free observing after death.
// NOTE: The countdown starts when the player’s death animation is finished.
// 0 - disable spectating around death
// >0.00001 - time delay to start spectate
//
// Default value: "3.0"
mp_dying_time "3.0"
4 changes: 4 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ cvar_t hostages_rescued_ratio = { "mp_hostages_rescued_ratio", "1.0", 0, 1.0f, n

cvar_t legacy_vehicle_block = { "mp_legacy_vehicle_block", "1", 0, 0.0f, nullptr };

cvar_t dying_time = { "mp_dying_time", "3.0", 0, 3.0f, nullptr };

void GameDLL_Version_f()
{
if (Q_stricmp(CMD_ARGV(1), "version") != 0)
Expand Down Expand Up @@ -418,6 +420,8 @@ void EXT_FUNC GameDLLInit()

CVAR_REGISTER(&legacy_vehicle_block);

CVAR_REGISTER(&dying_time);

// print version
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");

Expand Down
3 changes: 2 additions & 1 deletion regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ extern cvar_t sv_enablebunnyhopping;
extern cvar_t plant_c4_anywhere;
extern cvar_t give_c4_frags;
extern cvar_t hostages_rescued_ratio;

extern cvar_t legacy_vehicle_block;
extern cvar_t dying_time;

#endif

extern cvar_t scoreboard_showmoney;
Expand Down
13 changes: 12 additions & 1 deletion regamedll/dlls/gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const float ROUND_RESPAWN_TIME = 20.0f;
const float ROUND_BEGIN_DELAY = 5.0f; // delay before beginning new round
const float ITEM_KILL_DELAY = 300.0f;
const float RADIO_TIMEOUT = 1.5f;
const float DEATH_ANIMATION_TIME = 3.0f;

const int MAX_INTERMISSION_TIME = 120; // longest the intermission can last, in seconds

Expand Down Expand Up @@ -206,7 +207,7 @@ enum
SCENARIO_BLOCK_PRISON_ESCAPE_TIME = BIT(8), // flag "i"
SCENARIO_BLOCK_BOMB_TIME = BIT(9), // flag "j"
SCENARIO_BLOCK_HOSTAGE_RESCUE_TIME = BIT(10), // flag "k"

};

// Player relationship return codes
Expand Down Expand Up @@ -336,6 +337,7 @@ class CGameRules
inline void SetGameOver() { m_bGameOver = true; }
static float GetItemKillDelay();
static float GetRadioTimeout();
static float GetDyingTime();

public:
BOOL m_bFreezePeriod; // TRUE at beginning of round, set to FALSE when the period expires
Expand Down Expand Up @@ -921,6 +923,15 @@ inline float CGameRules::GetRadioTimeout()
#endif
}

inline float CGameRules::GetDyingTime()
{
#ifdef REGAMEDLL_ADD
return dying_time.value;
#else
return DEATH_ANIMATION_TIME;
#endif
}

bool IsBotSpeaking();
void SV_Continue_f();
void SV_Tutor_Toggle_f();
Expand Down
46 changes: 41 additions & 5 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3857,7 +3857,7 @@ void CBasePlayer::PlayerDeathThink()
{
// if the player has been dead for one second longer than allowed by forcerespawn,
// forcerespawn isn't on. Send the player off to an intermission camera until they choose to respawn.
if (g_pGameRules->IsMultiplayer() && HasTimePassedSinceDeath(3.0f) && !(m_afPhysicsFlags & PFLAG_OBSERVER))
if (g_pGameRules->IsMultiplayer() && HasTimePassedSinceDeath(CGameRules::GetDyingTime()) && !(m_afPhysicsFlags & PFLAG_OBSERVER))
{
// Send message to everybody to spawn a corpse.
SpawnClientSideCorpse();
Expand Down Expand Up @@ -8818,9 +8818,7 @@ void CBasePlayer::SpawnClientSideCorpse()
if (pev->effects & EF_NODRAW)
return;

// do not make a corpse if the player goes to respawn.
if (pev->deadflag == DEAD_RESPAWNABLE)
return;
// deadflag == DEAD_RESPAWNABLE already checked before
#endif

#ifdef REGAMEDLL_ADD
Expand All @@ -8830,6 +8828,41 @@ void CBasePlayer::SpawnClientSideCorpse()

char *infobuffer = GET_INFO_BUFFER(edict());
char *pModel = GET_KEY_VALUE(infobuffer, "model");
float timeDiff = pev->animtime - gpGlobals->time;

#ifdef REGAMEDLL_ADD
if (CGameRules::GetDyingTime() < DEATH_ANIMATION_TIME) // a short time, timeDiff estimates to be small
{
float animDuration = -1.0;

studiohdr_t *pstudiohdr = (studiohdr_t *)GET_MODEL_PTR(ENT(pev));
if (pstudiohdr && pev->sequence < pstudiohdr->numseq) // model ptr and sequence validation
{
// get current sequence time
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + int(pev->sequence);
animDuration = pseqdesc->numframes / pseqdesc->fps;
}

if (animDuration <= 0.0)
{
// in case of failure
animDuration = DEATH_ANIMATION_TIME;
}

// client receives a negative value
animDuration *= -1.0;

if (animDuration < timeDiff) // reasonable way to fix client side unfinished sequence bug
{
// by some reason, if client receives a value less
// than "(negative current sequence time) * 100"
// animation will play visually awkward
// at this function call time, player death animation
// has already finished so we can safely fake it
timeDiff = animDuration;
}
}
#endif

MESSAGE_BEGIN(MSG_ALL, gmsgSendCorpse);
WRITE_STRING(pModel);
Expand All @@ -8839,14 +8872,17 @@ void CBasePlayer::SpawnClientSideCorpse()
WRITE_COORD(pev->angles.x);
WRITE_COORD(pev->angles.y);
WRITE_COORD(pev->angles.z);
WRITE_LONG((pev->animtime - gpGlobals->time) * 100);
WRITE_LONG(timeDiff * 100);
WRITE_BYTE(pev->sequence);
WRITE_BYTE(pev->body);
WRITE_BYTE(m_iTeam);
WRITE_BYTE(entindex());
MESSAGE_END();

#ifndef REGAMEDLL_FIXES
// already defined in StartDeathCam
m_canSwitchObserverModes = true;
#endif

if (TheTutor)
{
Expand Down

0 comments on commit 8a18969

Please sign in to comment.