Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 126 additions & 1 deletion src/game/client/jbmod/c_weapon_physgun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
#include "c_weapon__stubs.h"
#include "clienteffectprecachesystem.h"
#include "c_jbmod_player.h"
#include "c_baseplayer.h"
#include "usercmd.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"


// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

ConVar physgun_beam_color( "physgun_beam_color", "255 255 255", FCVAR_ARCHIVE );
ConVar physgun_model_color( "physgun_model_color", "255 0 255", FCVAR_ARCHIVE );
ConVar physgun_draw_beam("physgun_draw_beam", "1", FCVAR_ARCHIVE);

CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectGravityGun )
CLIENTEFFECT_MATERIAL( "sprites/physbeam" )
CLIENTEFFECT_REGISTER_END()
Expand Down Expand Up @@ -80,9 +89,88 @@ class C_WeaponGravityGun : public C_BaseCombatWeapon
return BaseClass::KeyInput( down, keynum, pszCurrentBinding );
}

void CreateMove( float flInputSampleTime, CUserCmd *pCmd, const QAngle &vecOldViewAngles )
{
BaseClass::CreateMove( flInputSampleTime, pCmd, vecOldViewAngles );

if ( !pCmd )
return;

C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;

if ( pPlayer->GetActiveWeapon() != this )
return;

if ( !m_beam.m_active )
return;

if ( !( pCmd->buttons & IN_USE ) )
return;

const short nMouseX = pCmd->mousedx;
const short nMouseY = pCmd->mousedy;
if ( nMouseX == 0 && nMouseY == 0 )
return;

// Use the raw mouse deltas for server-side physgun rotation, but keep the local
// camera from turning while we're in rotate mode.
pCmd->mousedx = nMouseX;
pCmd->mousedy = nMouseY;
pCmd->viewangles = vecOldViewAngles;
QAngle localViewAngles = vecOldViewAngles;
engine->SetViewAngles( localViewAngles );
}

static void ApplyPhysgunModelColor()
{
int ir = 255, ig = 0, ib = 255;

if ( sscanf( physgun_model_color.GetString(), "%d %d %d", &ir, &ig, &ib ) != 3 )
return;

ir = clamp( ir, 0, 255 );
ig = clamp( ig, 0, 255 );
ib = clamp( ib, 0, 255 );

float r = ir / 255.0f;
float g = ig / 255.0f;
float b = ib / 255.0f;





IMaterial *pMat = materials->FindMaterial(
"models/weapons/v_physcannon/v_superphyscannon_sheet",
TEXTURE_GROUP_MODEL
);

if ( !pMat || pMat->IsErrorMaterial() )

return;

bool found = false;
IMaterialVar *pTint = pMat->FindVar( "$selfillumtint", &found );

if ( found && pTint )
{

pTint->SetVecValue( r, g, b );
}
}





void OnDataChanged( DataUpdateType_t updateType )
{


BaseClass::OnDataChanged( updateType );
ApplyPhysgunModelColor();
m_beam.Update( this );
}

Expand Down Expand Up @@ -135,6 +223,9 @@ void C_BeamQuadratic::Update( C_BaseEntity *pOwner )
}





int C_BeamQuadratic::DrawModel( int )
{
Vector points[3];
Expand All @@ -149,21 +240,54 @@ int C_BeamQuadratic::DrawModel( int )
return 0;
pEnt->GetAttachment( 1, points[0], tmpAngle );





points[1] = 0.5 * ( m_targetPosition + points[0] );

// a little noise 11t & 13t should be somewhat non-periodic looking
//points[1].z += 4*sin( gpGlobals->curtime*11 ) + 5*cos( gpGlobals->curtime*13 );
points[2] = m_worldPosition;


if (physgun_draw_beam.GetFloat() == 0)
{
return 0;
}

IMaterial *pMat = materials->FindMaterial( "sprites/physbeam", TEXTURE_GROUP_CLIENT_EFFECTS );
Vector color;





if ( m_glueTouching )
{
color.Init( 1, 0, 0 );
}
else
{
color.Init( 1, 1, 1 );
int ir = 255, ig = 255, ib = 255;

// Try to read 3 integers
if ( sscanf( physgun_beam_color.GetString(), "%d %d %d", &ir, &ig, &ib ) != 3 )
{
ir = ig = ib = 255; // fallback to white
}

// Clamp to valid 0–255 range
ir = clamp( ir, 0, 255 );
ig = clamp( ig, 0, 255 );
ib = clamp( ib, 0, 255 );

// Convert to 0.0–1.0
float r = ir / 255.0f;
float g = ig / 255.0f;
float b = ib / 255.0f;

color.Init( r, g, b );
}

float scrollOffset = gpGlobals->curtime - (int)gpGlobals->curtime;
Expand All @@ -179,3 +303,4 @@ const matrix3x4_t &C_BeamQuadratic::RenderableToWorldTransform()
AngleMatrix( GetRenderAngles(), GetRenderOrigin(), mat );
return mat;
}

Loading