Skip to content

Commit 26ec969

Browse files
committed
Add TFC Railgun
1 parent b26db70 commit 26ec969

File tree

8 files changed

+268
-0
lines changed

8 files changed

+268
-0
lines changed

cl_dll/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_subdirectory(halo_weapons)
44
add_subdirectory(hl)
55
add_subdirectory(op4_weapons)
66
add_subdirectory(vgui)
7+
add_subdirectory(s10_weapons)
78

89
add_sources(
910
achievement_manager.cpp

cl_dll/ev_hldm.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void EV_FireM249(struct event_args_s* args);
121121
void EV_SniperRifle(struct event_args_s* args);
122122
void EV_Knife(struct event_args_s* args);
123123
void EV_PenguinFire(event_args_t* args);
124+
void EV_RayTouch(particle_s* particle);
125+
void EV_FireRailgun(event_args_t* args);
124126

125127
#ifdef _HALO
126128
void EV_FireSMG(event_args_t* args);
@@ -1093,6 +1095,86 @@ void EV_FireBattleRifle(event_args_t* args)
10931095
// BATTLERIFLE END
10941096
//======================
10951097

1098+
//======================
1099+
// RAILGUN START
1100+
//======================
1101+
void EV_RayTouch(particle_s* particle)
1102+
{
1103+
vec3_t start = particle->org - particle->vel.Normalize() * 32;
1104+
vec3_t end = particle->org + particle->vel.Normalize() * 32;
1105+
1106+
pmtrace_t tr;
1107+
gEngfuncs.pEventAPI->EV_SetUpPlayerPrediction(false, true);
1108+
gEngfuncs.pEventAPI->EV_PushPMStates();
1109+
gEngfuncs.pEventAPI->EV_SetSolidPlayers(-1);
1110+
gEngfuncs.pEventAPI->EV_SetTraceHull(2);
1111+
gEngfuncs.pEventAPI->EV_PlayerTrace(start, end, PM_STUDIO_BOX, -1, &tr);
1112+
1113+
int idx;
1114+
char decalname[32];
1115+
physent_t* pe;
1116+
1117+
pe = gEngfuncs.pEventAPI->EV_GetPhysent(tr.ent);
1118+
if (pe && (/*pev->solid == SOLID_BSP || */pe->movetype == MOVETYPE_PUSHSTEP))
1119+
{
1120+
decalname[0] = '\0';
1121+
idx = gEngfuncs.pfnRandomLong(0, 4);
1122+
sprintf(decalname, "{shot%i", idx + 1);
1123+
EV_HLDM_GunshotDecalTrace(&tr, decalname);
1124+
1125+
if (gEngfuncs.PM_PointContents(tr.endpos, NULL) != CONTENTS_WATER)
1126+
gEngfuncs.pEfxAPI->R_SparkShower(tr.endpos);
1127+
}
1128+
1129+
gEngfuncs.pEventAPI->EV_PopPMStates();
1130+
}
1131+
1132+
void EV_FireRailgun(event_args_t* args)
1133+
{
1134+
int idx;
1135+
vec3_t origin, forward, right, up;
1136+
1137+
idx = args->entindex;
1138+
EV_GetGunPosition(args, origin, args->origin);
1139+
AngleVectors(args->angles, forward, right, up);
1140+
1141+
origin = origin - up * 4 + right * 4 + forward * 2;
1142+
1143+
vec3_t dest;
1144+
VectorMA(origin, 8192, forward, dest);
1145+
1146+
pmtrace_t tr;
1147+
gEngfuncs.pEventAPI->EV_SetUpPlayerPrediction(false, true);
1148+
gEngfuncs.pEventAPI->EV_PushPMStates();
1149+
gEngfuncs.pEventAPI->EV_SetSolidPlayers(idx - 1);
1150+
gEngfuncs.pEventAPI->EV_SetTraceHull(2);
1151+
gEngfuncs.pEventAPI->EV_PlayerTrace(origin, dest, PM_STUDIO_BOX, -1, &tr);
1152+
gEngfuncs.pEventAPI->EV_PopPMStates();
1153+
1154+
vec3_t vel, dir, end;
1155+
VectorCopy(tr.endpos, end);
1156+
VectorSubtract(end, origin, dir);
1157+
1158+
float len = dir.Length();
1159+
float speed = 2000;
1160+
1161+
VectorNormalize(dir);
1162+
VectorScale(dir, speed, vel);
1163+
1164+
gEngfuncs.pEfxAPI->R_UserTracerParticle(origin, vel, len / speed, 2, 0.2, 0, EV_RayTouch);
1165+
1166+
gEngfuncs.pEventAPI->EV_PlaySound(idx, origin, CHAN_WEAPON, "weapons/railgun.wav", 1.0, ATTN_NORM, 0, PITCH_NORM);
1167+
1168+
if (EV_IsLocal(idx))
1169+
{
1170+
gEngfuncs.pEventAPI->EV_WeaponAnimation(1, 0); // 1 == RAILGUN_FIRE. cba to put the enum in the header tbh.
1171+
Punch(-3, 0, 0);
1172+
}
1173+
}
1174+
//======================
1175+
// RAILGUN END
1176+
//======================
1177+
10961178
//======================
10971179
// PHYTON START
10981180
// ( .357 )

cl_dll/hl/hl_events.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void EV_FireDisplacer(struct event_args_s* args);
4949
void EV_FireM249(struct event_args_s* args);
5050
void EV_PenguinFire(event_args_t* args);
5151
void EV_FireBattleRifle(event_args_t* args);
52+
void EV_RayTouch(particle_s* particle);
53+
void EV_FireRailgun(event_args_t* args);
5254

5355
#ifdef _HALO
5456
void EV_FireSMG(event_args_t* args);
@@ -105,6 +107,8 @@ void Game_HookEvents( void )
105107
gEngfuncs.pfnHookEvent("events/m249.sc", EV_FireM249);
106108
gEngfuncs.pfnHookEvent("events/penguinfire.sc", EV_PenguinFire);
107109
gEngfuncs.pfnHookEvent("events/olr.sc", EV_FireBattleRifle);
110+
//gEngfuncs.pfnHookEvent("events/tf_railtouch.sc", EV_RayTouch);
111+
gEngfuncs.pfnHookEvent("events/tf_rail.sc", EV_FireRailgun);
108112

109113
#ifdef _HALO
110114
gEngfuncs.pfnHookEvent("events/m7.sc", EV_FireSMG);

cl_dll/hl/hl_weapons.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ CShockRifle g_ShockRifle;
9898
CSporeLauncher g_SporeLauncher;
9999
CM249 g_M249;
100100
CPenguin g_Penguin;
101+
CRailgun g_Railgun;
101102
#endif
102103

103104
/*
@@ -705,6 +706,7 @@ void HUD_InitClientWeapons( void )
705706
HUD_PrepEntity(&g_Displacer, &player);
706707
HUD_PrepEntity(&g_M249, &player);
707708
HUD_PrepEntity(&g_Penguin, &player);
709+
HUD_PrepEntity(&g_Railgun, &player);
708710
#endif
709711
}
710712

@@ -770,6 +772,7 @@ CBasePlayerWeapon* GetLocalWeapon(int id)
770772
case WEAPON_GRAPPLE: return &g_Grapple;
771773
case WEAPON_M249: return &g_M249;
772774
case WEAPON_PENGUIN: return &g_Penguin;
775+
case WEAPON_RAILGUN: return &g_Railgun;
773776
case WEAPON_KNIFE: return &g_Knife;
774777
case WEAPON_EAGLE: return &g_Eagle;
775778
case WEAPON_PIPEWRENCH: return &g_Pipewrench;

cl_dll/s10_weapons/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_sources(railgun.cpp)

cl_dll/s10_weapons/railgun.cpp

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/****
2+
*
3+
* Copyright (c) 2021-2025 The Phoenix Project Software. Some Rights Reserved.
4+
*
5+
* AURA
6+
*
7+
* railgun: super cool laser thingy
8+
*
9+
*
10+
****/
11+
12+
#ifndef _HALO
13+
14+
#include "extdll.h"
15+
#include "util.h"
16+
#include "cbase.h"
17+
#include "player.h"
18+
#include "weapons.h"
19+
#include "weapon_hierarchy.h"
20+
#include "gamerules.h"
21+
22+
enum railgun_e
23+
{
24+
RAILGUN_IDLE = 0,
25+
RAILGUN_FIRE,
26+
RAILGUN_DRAW,
27+
RAILGUN_HOLSTER,
28+
};
29+
30+
LINK_ENTITY_TO_CLASS(weapon_railgun, CRailgun);
31+
32+
void CRailgun::Spawn()
33+
{
34+
Precache();
35+
m_iId = WEAPON_RAILGUN;
36+
SET_MODEL(ENT(pev), "models/w_railgun.mdl");
37+
38+
m_iDefaultAmmo = RAILGUN_DEFAULT_GIVE;
39+
40+
FallInit();
41+
}
42+
43+
void CRailgun::Precache(void)
44+
{
45+
PRECACHE_MODEL("models/w_railgun.mdl");
46+
PRECACHE_MODEL("models/p_railgun.mdl");
47+
PRECACHE_MODEL("models/v_railgun.mdl");
48+
49+
PRECACHE_SOUND("weapons/railgun.wav");
50+
51+
UTIL_PrecacheOther("railgun_ray");
52+
53+
m_usRailgun = PRECACHE_EVENT(1, "events/tf_rail.sc");
54+
}
55+
56+
int CRailgun::GetItemInfo(ItemInfo* p)
57+
{
58+
p->pszName = STRING(pev->classname);
59+
p->pszAmmo1 = "uranium";
60+
p->iMaxAmmo1 = URANIUM_MAX_CARRY;
61+
p->pszAmmo2 = NULL;
62+
p->iMaxAmmo2 = -1;
63+
p->iMaxClip = WEAPON_NOCLIP;
64+
p->iSlot = WPN_AUTO_SLOT;
65+
p->iPosition = WPN_RAILGUN_POS;
66+
p->iId = WEAPON_RAILGUN;
67+
p->iFlags = 0;
68+
p->iWeight = GAUSS_WEIGHT;
69+
70+
return 1;
71+
}
72+
73+
void CRailgun::Fire(void)
74+
{
75+
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
76+
{
77+
PlayEmptySound();
78+
return;
79+
}
80+
81+
if (m_pPlayer->pev->waterlevel == 3)
82+
{
83+
PlayEmptySound();
84+
return;
85+
}
86+
87+
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
88+
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
89+
90+
#ifndef CLIENT_DLL
91+
Vector vecSrc = m_pPlayer->GetGunPosition() + gpGlobals->v_right * 4 - gpGlobals->v_up * 4 + gpGlobals->v_forward * 2;
92+
Vector vecDir = m_pPlayer->GetAutoaimVector(AUTOAIM_5DEGREES);
93+
#else
94+
Legacy_Vector vecSrc = m_pPlayer->GetGunPosition() + gpGlobals->v_right * 4 - gpGlobals->v_up * 4 + gpGlobals->v_forward * 2;
95+
Legacy_Vector vecDir = m_pPlayer->GetAutoaimVector(AUTOAIM_5DEGREES);
96+
#endif
97+
98+
#ifndef CLIENT_DLL
99+
CBaseEntity* pRay = CBaseEntity::Create("raingun_ray", vecSrc, m_pPlayer->pev->v_angle, m_pPlayer->edict());
100+
pRay->pev->velocity = pRay->pev->vuser1 = vecDir * 2000;
101+
pRay->pev->angles = UTIL_VecToAngles(pRay->pev->velocity);
102+
#endif
103+
104+
PLAYBACK_EVENT_FULL(0, edict(), m_usRailgun, 0.0, (float*)&g_vecZero, (float*)&g_vecZero, 0.0, 0.0, 0, 0, 0, 0);
105+
}
106+
107+
void CRailgun::PrimaryAttack(void)
108+
{
109+
if (m_flNextPrimaryAttack > UTIL_WeaponTimeBase())
110+
{
111+
return;
112+
}
113+
114+
Fire();
115+
116+
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
117+
}
118+
119+
void CRailgun::SecondaryAttack(void)
120+
{
121+
if (m_flNextSecondaryAttack > UTIL_WeaponTimeBase())
122+
{
123+
return;
124+
}
125+
126+
Fire();
127+
128+
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
129+
130+
}
131+
132+
BOOL CRailgun::Deploy()
133+
{
134+
return DefaultDeploy("models/v_railgun.mdl", "models/p_railgun.mdl", RAILGUN_DRAW, "hive");
135+
}
136+
137+
void CRailgun::Holster(int skiplocal)
138+
{
139+
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
140+
SendWeaponAnim(RAILGUN_HOLSTER);
141+
}
142+
143+
void CRailgun::WeaponIdle(void)
144+
{
145+
m_pPlayer->GetAutoaimVector(AUTOAIM_2DEGREES);
146+
ResetEmptySound();
147+
148+
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
149+
return;
150+
151+
SendWeaponAnim(RAILGUN_IDLE);
152+
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_WeaponTimeBase() + 31.0 / 10.0;
153+
}
154+
155+
#endif // _HALO

dlls/weapon_hierarchy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define WPN_GAUSS_POS 2
3131
#define WPN_EGON_POS 3
3232
#define WPN_HIVEHAND_POS 4
33+
#define WPN_RAILGUN_POS 5
3334

3435
// Slot 5 - explosives
3536
#define WPN_EXPL_SLOT 4

dlls/weapons.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class CGrenade : public CBaseMonster
106106

107107
#define WEAPON_BATTLERIFLE 30
108108
#define WEAPON_HLDMAR 32
109+
#define WEAPON_RAILGUN 33
109110

110111
#define WEAPON_ALLWEAPONS (~(1<<WEAPON_SUIT))
111112

@@ -272,6 +273,7 @@ class CGrenade : public CBaseMonster
272273
#define SNIPERRIFLE_DEFAULT_GIVE 5
273274
#define M249_DEFAULT_GIVE 100
274275
#define DISPLACER_DEFAULT_GIVE 40
276+
#define RAILGUN_DEFAULT_GIVE 20
275277
#endif
276278
#define BR_DEFAULT_GIVE BR_MAX_CLIP
277279

@@ -853,6 +855,25 @@ class CBattleRifle : public CBasePlayerWeapon
853855
int m_iBurstShotsFired;
854856
};
855857

858+
#ifndef _HALO
859+
class CRailgun : public CBasePlayerWeapon
860+
{
861+
public:
862+
void Spawn(void);
863+
void Precache(void);
864+
int GetItemInfo(ItemInfo* p);
865+
void Fire(void);
866+
void PrimaryAttack(void);
867+
void SecondaryAttack(void);
868+
BOOL Deploy();
869+
void Holster(int skiplocal = 0) override;
870+
void WeaponIdle(void);
871+
872+
private:
873+
unsigned short m_usRailgun;
874+
};
875+
#endif
876+
856877
enum m7_e
857878
{
858879
M7_LONGIDLE = 0,

0 commit comments

Comments
 (0)