Skip to content

Commit

Permalink
copy func_vehicle from HL25
Browse files Browse the repository at this point in the history
ValveSoftware/halflife@b59688c
https://www.youtube.com/watch?v=kdo9HZTgr6s

modified to play sounds server-side because the sound event isn't working. Also using CHAN_VOICE to prevent overlapping car sounds.
  • Loading branch information
wootguy committed Sep 7, 2024
1 parent e8b9b3c commit b2b8c14
Show file tree
Hide file tree
Showing 7 changed files with 1,246 additions and 13 deletions.
69 changes: 61 additions & 8 deletions dlls/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "CTripmine.h"
#include "skill.h"
#include "CBreakable.h"
#include "CFuncVehicle.h"

// #define DUCKFIX

Expand Down Expand Up @@ -1733,6 +1734,11 @@ void CBasePlayer::PlayerUse ( void )
{
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = TRAIN_NEW|TRAIN_OFF;

CBaseEntity* pTrain = CBaseEntity::Instance(pev->groundentity);
if (pTrain && (pTrain->Classify() == CLASS_VEHICLE))
((CFuncVehicle*)pTrain)->m_pDriver = NULL;

return;
}
else
Expand All @@ -1744,7 +1750,13 @@ void CBasePlayer::PlayerUse ( void )
m_afPhysicsFlags |= PFLAG_ONTRAIN;
m_iTrain = TrainSpeed(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 @@ -1883,6 +1895,16 @@ void CBasePlayer::Jump()
{
pev->velocity = pev->velocity + pev->basevelocity;
}

// JoshA: CS behaviour does this for tracktrain + train as well,
// but let's just do this for func_vehicle to avoid breaking existing content.
//
// If you're standing on a moving train... then add the velocity of the train to yours.
if (pevGround && ( /*(!strcmp( "func_tracktrain", STRING(pevGround->classname))) ||
(!strcmp( "func_train", STRING(pevGround->classname))) ) ||*/
(!strcmp("func_vehicle", STRING(pevGround->classname))))) {
pev->velocity = pev->velocity + pevGround->velocity;
}
}

// This is a glorious hack to find free space when you've crouched into some solid space
Expand Down Expand Up @@ -2252,28 +2274,59 @@ 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->Classify() == CLASS_VEHICLE)
((CFuncVehicle*)pTrain)->m_pDriver = NULL;
return;
}
}
else if ( !FBitSet( pev->flags, FL_ONGROUND ) || FBitSet( pTrain->pev->spawnflags, SF_TRACKTRAIN_NOCONTROL ) || (pev->button & (IN_MOVELEFT|IN_MOVERIGHT) ) )
else if (!FBitSet(pev->flags, FL_ONGROUND) || FBitSet(pTrain->pev->spawnflags, SF_TRACKTRAIN_NOCONTROL) || ((pev->button & (IN_MOVELEFT | IN_MOVERIGHT)) && pTrain->Classify() != CLASS_VEHICLE))
{
// Turn off the train if you jump, strafe, or the train controls go dead
// and it isn't a func_vehicle.
m_afPhysicsFlags &= ~PFLAG_ONTRAIN;
m_iTrain = TRAIN_NEW|TRAIN_OFF;
if (pTrain->Classify() == CLASS_VEHICLE)
((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, (float)vel);
}
if (pev->button & IN_BACK)
{
vel = -1;
pTrain->Use(this, this, USE_SET, (float)vel);
}
if (pev->button & IN_MOVELEFT)
{
vel = 20;
pTrain->Use(this, this, USE_SET, (float)vel);
}
if (pev->button & IN_MOVERIGHT)
{
vel = 30;
pTrain->Use(this, this, USE_SET, (float)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, (float)vel);
}
else if (m_afButtonPressed & IN_BACK)
{
vel = -1;
pTrain->Use(this, this, USE_SET, (float)vel);
}
}

if (vel)
Expand Down
2 changes: 2 additions & 0 deletions dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ set(FUNC_HDR
func/CFuncTank.h
func/CFuncTrackChange.h
func/CFuncTrackTrain.h
func/CFuncVehicle.h
func/CFuncWall.h
func/CPlatTrigger.h
)
Expand Down Expand Up @@ -278,6 +279,7 @@ set(FUNC_SRC
func/CFuncTrackTrain.cpp
func/CFuncTrain.cpp
func/CFuncTrainControls.cpp
func/CFuncVehicle.cpp
func/CFuncWall.cpp
func/CFuncWallToggle.cpp
func/CGunTarget.cpp
Expand Down
8 changes: 4 additions & 4 deletions dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,26 +477,26 @@ edict_t * EHANDLE::GetEdict( void )
}

return NULL;
};
}

CBaseEntity* EHANDLE::GetEntity(void)
{
return (CBaseEntity*)GET_PRIVATE(GetEdict());
};
}

edict_t * EHANDLE::Set( edict_t *pent )
{
m_pent = pent;
if (pent)
m_serialnumber = m_pent->serialnumber;
return pent;
};
}


EHANDLE :: operator CBaseEntity *()
{
return (CBaseEntity *)GET_PRIVATE( GetEdict() );
};
}

CBaseEntity * EHANDLE :: operator = (CBaseEntity *pEntity)
{
Expand Down
1 change: 1 addition & 0 deletions dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef void (CBaseEntity::*USEPTR)( CBaseEntity *pActivator, CBaseEntity *pCall
#define CLASS_ALIEN_BIOWEAPON 13 // hornets and snarks.launched by the alien menace
#define CLASS_ALIEN_RACE_X 14
#define CLASS_ALIEN_RACE_X_PITDRONE 15 // TODO: use this
#define CLASS_VEHICLE 16
#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
Loading

0 comments on commit b2b8c14

Please sign in to comment.