Skip to content

Commit

Permalink
Update func_vehicle for multiplayer (#792)
Browse files Browse the repository at this point in the history
* Update func_vehicle for multiplayer. Added mp_legacy_vehicle_block cvar.

* Update dist/game.cfg

Co-authored-by: Sergey Shorokhov <[email protected]>

* Update regamedll/dlls/game.cpp

Co-authored-by: Sergey Shorokhov <[email protected]>

* Fix default behavior

* Optimization

Thanks to #737 (comment) help!

* Update README.md

Co-authored-by: Sergey Shorokhov <[email protected]>
  • Loading branch information
Unreal Karaulov and SergeyShorokhov authored Dec 6, 2022
1 parent 86e7215 commit cf8deb9
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_plant_c4_anywhere | 0 | 0 | 1 | When set, players can plant anywhere, not only in bombsites.<br/>`0` disabled <br/>`1` enabled |
| 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 |
</details>

## How to install zBot for CS 1.6?
Expand Down
9 changes: 9 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,12 @@ mp_give_c4_frags "3"
//
// Default value: "1.0"
mp_hostages_rescued_ratio "1.0"
// Legacy func_vehicle behavior when blocked by another entity.
// New one is more useful for playing multiplayer.
//
// 0 - New behavior
// 1 - Legacy behavior
//
// Default value: "1"
mp_legacy_vehicle_block "1"
4 changes: 4 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ cvar_t give_c4_frags = { "mp_give_c4_frags", "3", 0, 3.0f, n

cvar_t hostages_rescued_ratio = { "mp_hostages_rescued_ratio", "1.0", 0, 1.0f, nullptr };

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

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

CVAR_REGISTER(&hostages_rescued_ratio);

CVAR_REGISTER(&legacy_vehicle_block);

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

Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ extern cvar_t plant_c4_anywhere;
extern cvar_t give_c4_frags;
extern cvar_t hostages_rescued_ratio;

extern cvar_t legacy_vehicle_block;
#endif

extern cvar_t scoreboard_showmoney;
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3926,7 +3926,11 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(PlayerKilled)(CBasePlayer *pVictim,
else if (ktmp && ktmp->Classify() == CLASS_VEHICLE)
{
CBasePlayer *pDriver = static_cast<CBasePlayer *>(((CFuncVehicle *)ktmp)->m_pDriver);
#ifdef REGAMEDLL_FIXES
if (pDriver && !pDriver->has_disconnected)
#else
if (pDriver)
#endif
{
pKiller = pDriver->pev;
peKiller = static_cast<CBasePlayer *>(pDriver);
Expand Down
15 changes: 15 additions & 0 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4030,7 +4030,12 @@ void CBasePlayer::PlayerUse()
CBaseEntity *pTrain = Instance(pev->groundentity);
if (pTrain && pTrain->Classify() == CLASS_VEHICLE)
{
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#else
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#endif
}
return;
}
Expand Down Expand Up @@ -4572,7 +4577,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)()
{
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = (TRAIN_NEW | TRAIN_OFF);
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#else
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#endif
return;
}
}
Expand All @@ -4581,7 +4591,12 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)()
// Turn off the train if you jump, strafe, or the train controls go dead
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = (TRAIN_NEW | TRAIN_OFF);
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#else
((CFuncVehicle *)pTrain)->m_pDriver = nullptr;
#endif
return;
}

Expand Down
43 changes: 36 additions & 7 deletions regamedll/dlls/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther)
pevOther->velocity.z += 300;
pev->velocity = pev->velocity * 0.85;

ALERT(at_aiconsole, "TRAIN(%s): Blocked by %s (dmg:%.2f)\n", STRING(pev->targetname), STRING(pOther->pev->classname), pev->dmg);
ALERT(at_aiconsole, "TRAIN(%s): Blocked by %s (dmg:%.2f)\n", STRING(pev->targetname), STRING(pevOther->classname), pev->dmg);
UTIL_MakeVectors(pev->angles);

Vector forward, right, vOrigin;
Expand All @@ -131,13 +131,42 @@ void CFuncVehicle::Blocked(CBaseEntity *pOther)
float maxz = pev->origin.z + (2 * Q_abs(int(pev->mins.z - pev->maxs.z)));
#endif

if (pOther->pev->origin.x < minx
|| pOther->pev->origin.x > maxx
|| pOther->pev->origin.y < miny
|| pOther->pev->origin.y > maxy
|| pOther->pev->origin.z < minz
|| pOther->pev->origin.z > maxz)
if (pevOther->origin.x < minx
|| pevOther->origin.x > maxx
|| pevOther->origin.y < miny
|| pevOther->origin.y > maxy
|| pevOther->origin.z < minz
|| pevOther->origin.z > maxz)
{
#ifdef REGAMEDLL_ADD
if (legacy_vehicle_block.value)
{
pOther->TakeDamage(pev, pev, 150, DMG_CRUSH);
return;
}

CBasePlayer* playerDriver = static_cast<CBasePlayer*>(m_pDriver);

if (pOther->Classify() == CLASS_PLAYER)
{
CBasePlayer* playerOther = static_cast<CBasePlayer*>(pOther);
if (!playerDriver || (!friendlyfire.value && playerDriver->m_iTeam == playerOther->m_iTeam))

This comment has been minimized.

Copy link
@Vaqtincha

Vaqtincha Dec 7, 2022

Contributor

Don't use m_iTeam == m_iTeam check!
Use g_pGameRules->PlayerRelationship

This comment has been minimized.

Copy link
@UnrealKaraulov

UnrealKaraulov Jan 22, 2023

Contributor

Этот гад взял сломал из-за тебя friendlyfire )

ab2bfd4 ^_^

This comment has been minimized.

Copy link
@Vaqtincha

Vaqtincha Jan 22, 2023

Contributor

Ошибочка вышла. Правильно было FPlayerCanTakeDamage юзать.

{
// Just kick player
return;
}
else
{
playerOther->TakeDamage(pev, playerDriver->pev, 150, DMG_CRUSH);
return;
}
}
else if (FClassnameIs(pevOther, "hostage_entity") && playerDriver)
{
pOther->TakeDamage(playerDriver->pev, playerDriver->pev, 150, DMG_CRUSH);
return;
}
#endif
pOther->TakeDamage(pev, pev, 150, DMG_CRUSH);
}
}
Expand Down

0 comments on commit cf8deb9

Please sign in to comment.