Skip to content

Commit

Permalink
Port func_vehicle from cs16-client/regamedll_cs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonomicon committed Jan 20, 2024
1 parent d77a7e4 commit 2a069cd
Show file tree
Hide file tree
Showing 12 changed files with 1,224 additions and 11 deletions.
60 changes: 60 additions & 0 deletions cl_dll/ev_hldm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void EV_TripmineFire( struct event_args_s *args );
void EV_SnarkFire( struct event_args_s *args );

void EV_TrainPitchAdjust( struct event_args_s *args );
void EV_VehiclePitchAdjust( event_args_t *args );
}

#define VECTOR_CONE_1DEGREES Vector( 0.00873f, 0.00873f, 0.00873f )
Expand Down Expand Up @@ -1752,6 +1753,65 @@ void EV_TrainPitchAdjust( event_args_t *args )
}
}

void EV_VehiclePitchAdjust( event_args_t *args )
{
int idx;
vec3_t origin;

unsigned short us_params;
int noise;
float m_flVolume;
int pitch;
int stop;

const char *pszSound;

idx = args->entindex;

VectorCopy( args->origin, origin );

us_params = (unsigned short)args->iparam1;
stop = args->bparam1;

m_flVolume = (float)( us_params & 0x003f ) / 40.0f;
noise = (int)( ( ( us_params ) >> 12 ) & 0x0007 );
pitch = (int)( 10.0f * (float)( ( us_params >> 6 ) & 0x003f ) );

switch( noise )
{
case 1:
pszSound = "plats/vehicle1.wav";
break;
case 2:
pszSound = "plats/vehicle2.wav";
break;
case 3:
pszSound = "plats/vehicle3.wav";
break;
case 4:
pszSound = "plats/vehicle4.wav";
break;
case 5:
pszSound = "plats/vehicle6.wav";
break;
case 6:
pszSound = "plats/vehicle7.wav";
break;
default:
// no sound
return;
}

if( stop )
{
gEngfuncs.pEventAPI->EV_StopSound( idx, CHAN_STATIC, pszSound );
}
else
{
gEngfuncs.pEventAPI->EV_PlaySound( idx, origin, CHAN_STATIC, pszSound, m_flVolume, ATTN_NORM, SND_CHANGE_PITCH, pitch );
}
}

int EV_TFC_IsAllyTeam( int iTeam1, int iTeam2 )
{
return 0;
Expand Down
2 changes: 2 additions & 0 deletions cl_dll/hl/hl_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void EV_TripmineFire( struct event_args_s *args );
void EV_SnarkFire( struct event_args_s *args );

void EV_TrainPitchAdjust( struct event_args_s *args );
void EV_VehiclePitchAdjust( event_args_t *args );
}

/*
Expand Down Expand Up @@ -76,4 +77,5 @@ void Game_HookEvents( void )
gEngfuncs.pfnHookEvent( "events/firehornet.sc", EV_HornetGunFire );
gEngfuncs.pfnHookEvent( "events/tripfire.sc", EV_TripmineFire );
gEngfuncs.pfnHookEvent( "events/snarkfire.sc", EV_SnarkFire );
gEngfuncs.pfnHookEvent( "events/vehicle.sc", EV_VehiclePitchAdjust );
}
1 change: 1 addition & 0 deletions contrib/iZarif/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ files{"dlls/agrunt.cpp",
"dlls/triggers.cpp",
"dlls/turret.cpp",
"dlls/util.cpp",
"dlls/vehicle.cpp",
"dlls/weapons.cpp",
"dlls/world.cpp",
"dlls/xen.cpp",
Expand Down
1 change: 1 addition & 0 deletions dlls/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ LOCAL_SRC_FILES := agrunt.cpp airtank.cpp \
tripmine.cpp \
turret.cpp \
util.cpp \
vehicle.cpp \
weapons.cpp \
world.cpp \
xen.cpp \
Expand Down
1 change: 1 addition & 0 deletions dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ set (SVDLL_SOURCES
tripmine.cpp
turret.cpp
util.cpp
vehicle.cpp
weapons.cpp
world.cpp
xen.cpp
Expand Down
1 change: 1 addition & 0 deletions dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef void(CBaseEntity::*USEPTR)( CBaseEntity *pActivator, CBaseEntity *pCalle
#define CLASS_PLAYER_ALLY 11
#define CLASS_PLAYER_BIOWEAPON 12 // hornets and snarks.launched by players
#define CLASS_ALIEN_BIOWEAPON 13 // hornets and snarks.launched by the alien menace
#define CLASS_VEHICLE 14
#define CLASS_BARNACLE 99 // special because no one pays attention to it, and it eats a wide cross-section of creatures.

class CBaseEntity;
Expand Down
2 changes: 2 additions & 0 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ void ClientPrecache( void )

PRECACHE_SOUND( "plats/train_use1.wav" ); // use a train

PRECACHE_SOUND( "plats/vehicle_ignition.wav" );

PRECACHE_SOUND( "buttons/spark5.wav" ); // hit computer texture
PRECACHE_SOUND( "buttons/spark6.wav" );
PRECACHE_SOUND( "debris/glass1.wav" );
Expand Down
1 change: 1 addition & 0 deletions dlls/compile.bat
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ set SOURCES=agrunt.cpp ^
tripmine.cpp ^
turret.cpp ^
util.cpp ^
vehicle.cpp ^
weapons.cpp ^
world.cpp ^
xen.cpp ^
Expand Down
11 changes: 11 additions & 0 deletions dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "voice_gamemgr.h"
#endif
#include "hltv.h"
#include "trains.h"

extern DLL_GLOBAL CGameRules *g_pGameRules;
extern DLL_GLOBAL BOOL g_fGameOver;
Expand Down Expand Up @@ -647,6 +648,16 @@ void CHalfLifeMultiplay::PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller,
CBaseEntity *ktmp = CBaseEntity::Instance( pKiller );
if( ktmp && (ktmp->Classify() == CLASS_PLAYER ) )
peKiller = (CBasePlayer*)ktmp;
else if( ktmp && ktmp->Classify() == CLASS_VEHICLE )
{
CBasePlayer *pDriver = (CBasePlayer *)( (CFuncVehicle *)ktmp )->m_pDriver;

if( pDriver != NULL )
{
pKiller = pDriver->pev;
peKiller = (CBasePlayer *)pDriver;
}
}

if( pVictim->pev == pKiller )
{
Expand Down
74 changes: 63 additions & 11 deletions dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,18 +1484,31 @@ void CBasePlayer::PlayerUse( void )
{
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = TRAIN_NEW|TRAIN_OFF;

CBaseEntity *pTrain = Instance( pev->groundentity );
if( pTrain && pTrain->Classify() == CLASS_VEHICLE )
{
( (CFuncVehicle *)pTrain )->m_pDriver = NULL;
}
return;
}
else
{ // Start controlling the train!
CBaseEntity *pTrain = CBaseEntity::Instance( pev->groundentity );

if( pTrain && !( pev->button & IN_JUMP ) && FBitSet( pev->flags, FL_ONGROUND ) && (pTrain->ObjectCaps() & FCAP_DIRECTIONAL_USE ) && pTrain->OnControls( pev ) )
if( pTrain && !( pev->button & IN_JUMP ) && FBitSet( pev->flags, FL_ONGROUND ) && ( pTrain->ObjectCaps() & FCAP_DIRECTIONAL_USE ) && pTrain->OnControls( pev ) )
{
m_afPhysicsFlags |= PFLAG_ONTRAIN;
m_iTrain = TrainSpeed( (int)pTrain->pev->speed, pTrain->pev->impulse );
m_iTrain |= TRAIN_NEW;
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "plats/train_use1.wav", 0.8, ATTN_NORM );

if( pTrain->Classify() == CLASS_VEHICLE )
{
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "plats/vehicle_ignition.wav", 0.8, ATTN_NORM );
( (CFuncVehicle *)pTrain )->m_pDriver = this;
}
else
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "plats/train_use1.wav", 0.8, ATTN_NORM );
return;
}
}
Expand Down Expand Up @@ -1609,9 +1622,17 @@ void CBasePlayer::Jump()

// If you're standing on a conveyor, add it's velocity to yours (for momentum)
entvars_t *pevGround = VARS( pev->groundentity );
if( pevGround && ( pevGround->flags & FL_CONVEYOR ) )
if( pevGround )
{
pev->velocity = pev->velocity + pev->basevelocity;
if( pevGround->flags & FL_CONVEYOR )
{
pev->velocity = pev->velocity + pev->basevelocity;
}

if( FClassnameIs( pevGround, "func_vehicle" ))
{
pev->velocity = pevGround->velocity + pev->velocity;
}
}
}

Expand Down Expand Up @@ -1876,6 +1897,8 @@ void CBasePlayer::PreThink( void )
//ALERT( at_error, "In train mode with no train!\n" );
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = TRAIN_NEW|TRAIN_OFF;
if( pTrain )
( (CFuncVehicle *)pTrain )->m_pDriver = NULL;
return;
}
}
Expand All @@ -1884,22 +1907,51 @@ void CBasePlayer::PreThink( void )
// Turn off the train if you jump, strafe, or the train controls go dead
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = TRAIN_NEW | TRAIN_OFF;
( (CFuncVehicle *)pTrain )->m_pDriver = NULL;
return;
}

pev->velocity = g_vecZero;
vel = 0;
if( m_afButtonPressed & IN_FORWARD )

if( pTrain->Classify() == CLASS_VEHICLE )
{
vel = 1;
pTrain->Use( this, this, USE_SET, (float)vel );
if( pev->button & IN_FORWARD )
{
vel = 1;
pTrain->Use( this, this, USE_SET, vel );
}

if( pev->button & IN_BACK )
{
vel = -1;
pTrain->Use( this, this, USE_SET, vel );
}

if( pev->button & IN_MOVELEFT )
{
vel = 20;
pTrain->Use( this, this, USE_SET, vel );
}
if( pev->button & IN_MOVERIGHT )
{
vel = 30;
pTrain->Use( this, this, USE_SET, vel );
}
}
else if( m_afButtonPressed & IN_BACK )
else
{
vel = -1;
pTrain->Use( this, this, USE_SET, (float)vel );
if( m_afButtonPressed & IN_FORWARD )
{
vel = 1;
pTrain->Use( this, this, USE_SET, vel );
}
else if( m_afButtonPressed & IN_BACK )
{
vel = -1;
pTrain->Use( this, this, USE_SET, vel );
}
}

iGearId = TrainSpeed( pTrain->pev->speed, pTrain->pev->impulse );

if( iGearId != ( m_iTrain & 0x0F ) ) // Vit_amiN: speed changed
Expand Down
85 changes: 85 additions & 0 deletions dlls/trains.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,89 @@ class CFuncTrackTrain : public CBaseEntity
private:
unsigned short m_usAdjustPitch;
};

class CFuncVehicle: public CBaseEntity
{
public:
virtual void Spawn();
virtual void Precache();
virtual void Restart();
virtual void KeyValue( KeyValueData *pkvd );
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
virtual int ObjectCaps() { return ( CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION ) | FCAP_DIRECTIONAL_USE; }
virtual int Classify();
virtual void OverrideReset();
virtual BOOL OnControls( entvars_t *pev );
virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
virtual void Blocked( CBaseEntity *pOther );

public:
void EXPORT Next();
void EXPORT Find();
void EXPORT NearestPath();
void EXPORT DeadEnd();

void NextThink( float thinkTime, BOOL alwaysThink );
void CollisionDetection();
void TerrainFollowing();
void CheckTurning();

void SetTrack( CPathTrack *track ) { m_ppath = track->Nearest( pev->origin ); }
void SetControls( entvars_t *pevControls );

void StopSound();
void UpdateSound();

public:
static CFuncVehicle *Instance( edict_t *pent );
static TYPEDESCRIPTION m_SaveData[12];

CPathTrack *m_ppath;
float m_length;
float m_width;
float m_height;
float m_speed;
float m_dir;
float m_startSpeed;
Vector m_controlMins;
Vector m_controlMaxs;
int m_soundPlaying;
int m_sounds;
int m_acceleration;
float m_flVolume;
float m_flBank;
float m_oldSpeed;
int m_iTurnAngle;
float m_flSteeringWheelDecay;
float m_flAcceleratorDecay;
float m_flTurnStartTime;
float m_flLaunchTime;
float m_flLastNormalZ;
float m_flCanTurnNow;
float m_flUpdateSound;
Vector m_vFrontLeft;
Vector m_vFront;
Vector m_vFrontRight;
Vector m_vBackLeft;
Vector m_vBack;
Vector m_vBackRight;
Vector m_vSurfaceNormal;
Vector m_vVehicleDirection;
CBaseEntity *m_pDriver;

private:
unsigned short m_usAdjustPitch;
};

class CFuncVehicleControls: public CBaseEntity
{
public:
virtual void Spawn();
virtual int ObjectCaps() { return CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }

public:
void EXPORT Find();
};

#endif
Loading

0 comments on commit 2a069cd

Please sign in to comment.