1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "in_buttons.h"
#include "takedamageinfo.h"
#include "ammodef.h"
#include "portal_gamerules.h"
#ifdef CLIENT_DLL
extern IVModelInfoClient* modelinfo;
#else
extern IVModelInfo* modelinfo;
#endif
#if defined( CLIENT_DLL )
#include "vgui/ISurface.h"
#include "vgui_controls/Controls.h"
#include "c_portal_player.h"
#include "hud_crosshair.h"
#include "PortalRender.h"
#else
#include "portal_player.h"
#include "vphysics/constraints.h"
#endif
#include "weapon_portalbase.h"
// ----------------------------------------------------------------------------- //
// Global functions.
// ----------------------------------------------------------------------------- //
bool IsAmmoType( int iAmmoType, const char *pAmmoName )
{
return GetAmmoDef()->Index( pAmmoName ) == iAmmoType;
}
static const char * s_WeaponAliasInfo[] =
{
"none", // WEAPON_NONE = 0,
//Melee
"shotgun", //WEAPON_AMERKNIFE,
NULL, // end of list marker
};
// ----------------------------------------------------------------------------- //
// CWeaponPortalBase tables.
// ----------------------------------------------------------------------------- //
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponPortalBase, DT_WeaponPortalBase )
BEGIN_NETWORK_TABLE( CWeaponPortalBase, DT_WeaponPortalBase )
#ifdef CLIENT_DLL
#else
// world weapon models have no aminations
// SendPropExclude( "DT_AnimTimeMustBeFirst", "m_flAnimTime" ),
// SendPropExclude( "DT_BaseAnimating", "m_nSequence" ),
// SendPropExclude( "DT_LocalActiveWeaponData", "m_flTimeWeaponIdle" ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CWeaponPortalBase )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( weapon_portal_base, CWeaponPortalBase );
#ifdef GAME_DLL
BEGIN_DATADESC( CWeaponPortalBase )
END_DATADESC()
#endif
// ----------------------------------------------------------------------------- //
// CWeaponPortalBase implementation.
// ----------------------------------------------------------------------------- //
CWeaponPortalBase::CWeaponPortalBase()
{
SetPredictionEligible( true );
AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches.
m_flNextResetCheckTime = 0.0f;
}
bool CWeaponPortalBase::IsPredicted() const
{
return false;
}
void CWeaponPortalBase::WeaponSound( WeaponSound_t sound_type, float soundtime /* = 0.0f */ )
{
#ifdef CLIENT_DLL
// If we have some sounds from the weapon classname.txt file, play a random one of them
const char *shootsound = GetWpnData().aShootSounds[ sound_type ];
if ( !shootsound || !shootsound[0] )
return;
CBroadcastRecipientFilter filter; // this is client side only
if ( !te->CanPredict() )
return;
CBaseEntity::EmitSound( filter, GetPlayerOwner()->entindex(), shootsound, &GetPlayerOwner()->GetAbsOrigin() );
#else
BaseClass::WeaponSound( sound_type, soundtime );
#endif
}
CBasePlayer* CWeaponPortalBase::GetPlayerOwner() const
{
return dynamic_cast< CBasePlayer* >( GetOwner() );
}
CPortal_Player* CWeaponPortalBase::GetPortalPlayerOwner() const
{
return dynamic_cast< CPortal_Player* >( GetOwner() );
}
#ifdef CLIENT_DLL
void CWeaponPortalBase::OnDataChanged( DataUpdateType_t type )
{
BaseClass::OnDataChanged( type );
if ( GetPredictable() && !ShouldPredict() )
ShutdownPredictable();
}
int CWeaponPortalBase::DrawModel( int flags )
{
if ( !m_bReadyToDraw )
return 0;
if ( GetOwner() && (GetOwner() == C_BasePlayer::GetLocalPlayer()) && !g_pPortalRender->IsRenderingPortal() && !C_BasePlayer::ShouldDrawLocalPlayer() )
return 0;
//Sometimes the return value of ShouldDrawLocalPlayer() fluctuates too often to draw the correct model all the time, so this is a quick fix if it's changed too fast
int iOriginalIndex = GetModelIndex();
bool bChangeModelBack = false;
int iWorldModelIndex = GetWorldModelIndex();
if( iOriginalIndex != iWorldModelIndex )
{
SetModelIndex( iWorldModelIndex );
bChangeModelBack = true;
}
int iRetVal = BaseClass::DrawModel( flags );
if( bChangeModelBack )
SetModelIndex( iOriginalIndex );
return iRetVal;
}
bool CWeaponPortalBase::ShouldDraw( void )
{
if ( !GetOwner() || GetOwner() != C_BasePlayer::GetLocalPlayer() )
return true;
if ( !IsActiveByLocalPlayer() )
return false;
//if ( GetOwner() && GetOwner() == C_BasePlayer::GetLocalPlayer() && materials->GetRenderTarget() == 0 )
// return false;
return true;
}
bool CWeaponPortalBase::ShouldPredict()
{
if ( GetOwner() && GetOwner() == C_BasePlayer::GetLocalPlayer() )
return true;
return BaseClass::ShouldPredict();
}
//-----------------------------------------------------------------------------
// Purpose: Draw the weapon's crosshair
//-----------------------------------------------------------------------------
void CWeaponPortalBase::DrawCrosshair()
{
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if ( !player )
return;
Color clr = gHUD.m_clrNormal;
CHudCrosshair *crosshair = GET_HUDELEMENT( CHudCrosshair );
if ( !crosshair )
return;
// Check to see if the player is in VGUI mode...
if (player->IsInVGuiInputMode())
{
CHudTexture *pArrow = gHUD.GetIcon( "arrow" );
crosshair->SetCrosshair( pArrow, gHUD.m_clrNormal );
return;
}
// Find out if this weapon's auto-aimed onto a target
bool bOnTarget = ( m_iState == WEAPON_IS_ONTARGET );
if ( player->GetFOV() >= 90 )
{
// normal crosshairs
if ( bOnTarget && GetWpnData().iconAutoaim )
{
clr[3] = 255;
crosshair->SetCrosshair( GetWpnData().iconAutoaim, clr );
}
else if ( GetWpnData().iconCrosshair )
{
clr[3] = 255;
crosshair->SetCrosshair( GetWpnData().iconCrosshair, clr );
}
else
{
crosshair->ResetCrosshair();
}
}
else
{
Color white( 255, 255, 255, 255 );
// zoomed crosshairs
if (bOnTarget && GetWpnData().iconZoomedAutoaim)
crosshair->SetCrosshair(GetWpnData().iconZoomedAutoaim, white);
else if ( GetWpnData().iconZoomedCrosshair )
crosshair->SetCrosshair( GetWpnData().iconZoomedCrosshair, white );
else
crosshair->ResetCrosshair();
}
}
void CWeaponPortalBase::DoAnimationEvents( CStudioHdr *pStudioHdr )
{
// HACK: Because this model renders view and world models in the same frame
// it's using the wrong studio model when checking the sequences.
C_BasePlayer *pPlayer = UTIL_PlayerByIndex( 1 );
if ( pPlayer && pPlayer->GetActiveWeapon() == this )
{
C_BaseViewModel *pViewModel = pPlayer->GetViewModel();
if ( pViewModel )
{
pStudioHdr = pViewModel->GetModelPtr();
}
}
if ( pStudioHdr )
{
BaseClass::DoAnimationEvents( pStudioHdr );
}
}
void CWeaponPortalBase::GetRenderBounds( Vector& theMins, Vector& theMaxs )
{
if ( IsRagdoll() )
{
m_pRagdoll->GetRagdollBounds( theMins, theMaxs );
}
else if ( GetModel() )
{
CStudioHdr *pStudioHdr = NULL;
// HACK: Because this model renders view and world models in the same frame
// it's using the wrong studio model when checking the sequences.
C_BasePlayer *pPlayer = UTIL_PlayerByIndex( 1 );
if ( pPlayer && pPlayer->GetActiveWeapon() == this )
{
C_BaseViewModel *pViewModel = pPlayer->GetViewModel();
if ( pViewModel )
{
pStudioHdr = pViewModel->GetModelPtr();
}
}
else
{
pStudioHdr = GetModelPtr();
}
if ( !pStudioHdr || !pStudioHdr->SequencesAvailable() || GetSequence() == -1 )
{
theMins = vec3_origin;
theMaxs = vec3_origin;
return;
}
if (!VectorCompare( vec3_origin, pStudioHdr->view_bbmin() ) || !VectorCompare( vec3_origin, pStudioHdr->view_bbmax() ))
{
// clipping bounding box
VectorCopy ( pStudioHdr->view_bbmin(), theMins);
VectorCopy ( pStudioHdr->view_bbmax(), theMaxs);
}
else
{
// movement bounding box
VectorCopy ( pStudioHdr->hull_min(), theMins);
VectorCopy ( pStudioHdr->hull_max(), theMaxs);
}
mstudioseqdesc_t &seqdesc = pStudioHdr->pSeqdesc( GetSequence() );
VectorMin( seqdesc.bbmin, theMins, theMins );
VectorMax( seqdesc.bbmax, theMaxs, theMaxs );
}
else
{
theMins = vec3_origin;
theMaxs = vec3_origin;
}
}
#else
void CWeaponPortalBase::Spawn()
{
BaseClass::Spawn();
// Set this here to allow players to shoot dropped weapons
SetCollisionGroup( COLLISION_GROUP_WEAPON );
// Use less bloat for the collision box for this weapon. (bug 43800)
CollisionProp()->UseTriggerBounds( true, 20 );
}
void CWeaponPortalBase:: Materialize( void )
{
if ( IsEffectActive( EF_NODRAW ) )
{
// changing from invisible state to visible.
EmitSound( "AlyxEmp.Charge" );
RemoveEffects( EF_NODRAW );
DoMuzzleFlash();
}
if ( HasSpawnFlags( SF_NORESPAWN ) == false )
{
VPhysicsInitNormal( SOLID_BBOX, GetSolidFlags() | FSOLID_TRIGGER, false );
SetMoveType( MOVETYPE_VPHYSICS );
//PortalRules()->AddLevelDesignerPlacedObject( this );
}
if ( HasSpawnFlags( SF_NORESPAWN ) == false )
{
if ( GetOriginalSpawnOrigin() == vec3_origin )
{
m_vOriginalSpawnOrigin = GetAbsOrigin();
m_vOriginalSpawnAngles = GetAbsAngles();
}
}
SetPickupTouch();
SetThink (NULL);
}
#endif
const CPortalSWeaponInfo &CWeaponPortalBase::GetPortalWpnData() const
{
const FileWeaponInfo_t *pWeaponInfo = &GetWpnData();
const CPortalSWeaponInfo *pPortalInfo;
#ifdef _DEBUG
pPortalInfo = dynamic_cast< const CPortalSWeaponInfo* >( pWeaponInfo );
Assert( pPortalInfo );
#else
pPortalInfo = static_cast< const CPortalSWeaponInfo* >( pWeaponInfo );
#endif
return *pPortalInfo;
}
void CWeaponPortalBase::FireBullets( const FireBulletsInfo_t &info )
{
FireBulletsInfo_t modinfo = info;
modinfo.m_iPlayerDamage = GetPortalWpnData().m_iPlayerDamage;
BaseClass::FireBullets( modinfo );
}
#if defined( CLIENT_DLL )
#include "c_te_effect_dispatch.h"
#define NUM_MUZZLE_FLASH_TYPES 4
bool CWeaponPortalBase::OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options )
{
return BaseClass::OnFireEvent( pViewModel, origin, angles, event, options );
}
void UTIL_ClipPunchAngleOffset( QAngle &in, const QAngle &punch, const QAngle &clip )
{
QAngle final = in + punch;
//Clip each component
for ( int i = 0; i < 3; i++ )
{
if ( final[i] > clip[i] )
{
final[i] = clip[i];
}
else if ( final[i] < -clip[i] )
{
final[i] = -clip[i];
}
//Return the result
in[i] = final[i] - punch[i];
}
}
#endif
|