Fix: ammo/weapons respawn behavior (#982)

* `CBasePlayerAmmo`: check spawnflags on `Spawn()`

* `CBasePlayerItem`: check spawnflags on `Materialize()`

* `CBasePlayerItem`: Add `Respawn()` item when hasn't specific spawnflags

* `CBasePlayerItem`: remove `SF_NORESPAWN` flag on `Respawn()`

* Use forgotten `AMMO_RESPAWN_TIME`
This commit is contained in:
Sergey Shorokhov 2024-08-03 20:11:08 +03:00 committed by GitHub
parent 576e967cbd
commit a202425dd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 4 deletions

View File

@ -10,7 +10,11 @@ void CBasePlayerAmmo::Spawn()
SetTouch(&CBasePlayerAmmo::DefaultTouch);
if (g_pGameRules->IsMultiplayer())
if (g_pGameRules->IsMultiplayer()
#ifdef REGAMEDLL_FIXES
&& g_pGameRules->AmmoShouldRespawn(this) == GR_AMMO_RESPAWN_NO
#endif
)
{
SetThink(&CBaseEntity::SUB_Remove);
pev->nextthink = gpGlobals->time + 2.0f;

View File

@ -4321,7 +4321,7 @@ int CHalfLifeMultiplay::AmmoShouldRespawn(CBasePlayerAmmo *pAmmo)
float CHalfLifeMultiplay::FlAmmoRespawnTime(CBasePlayerAmmo *pAmmo)
{
return gpGlobals->time + 20.0f;
return gpGlobals->time + AMMO_RESPAWN_TIME;
}
Vector CHalfLifeMultiplay::VecAmmoRespawnSpot(CBasePlayerAmmo *pAmmo)

View File

@ -518,7 +518,11 @@ void CBasePlayerItem::Materialize()
UTIL_SetOrigin(pev, pev->origin);
SetTouch(&CBasePlayerItem::DefaultTouch);
if (g_pGameRules->IsMultiplayer())
if (g_pGameRules->IsMultiplayer()
#ifdef REGAMEDLL_FIXES
&& g_pGameRules->WeaponShouldRespawn(this) == GR_WEAPON_RESPAWN_NO
#endif
)
{
if (!CanDrop())
{
@ -555,8 +559,12 @@ void CBasePlayerItem::CheckRespawn()
{
switch (g_pGameRules->WeaponShouldRespawn(this))
{
case GR_WEAPON_RESPAWN_YES:
case GR_WEAPON_RESPAWN_YES: {
#ifdef REGAMEDLL_FIXES
Respawn();
#endif
return;
}
case GR_WEAPON_RESPAWN_NO:
return;
}
@ -575,6 +583,10 @@ CBaseEntity *CBasePlayerItem::Respawn()
// invisible for now
pNewWeapon->pev->effects |= EF_NODRAW;
#ifdef REGAMEDLL_ADD
pNewWeapon->pev->spawnflags &= ~SF_NORESPAWN;
#endif
// no touch
pNewWeapon->SetTouch(nullptr);
pNewWeapon->SetThink(&CBasePlayerItem::AttemptToMaterialize);