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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: A volume which bumps portal placement. Keeps a global list loaded in from the map
// and provides an interface with which prop_portal can get this list and avoid successfully
// creating portals partially inside the volume.
//
// $NoKeywords: $
//======================================================================================//
#include "cbase.h"
#include "triggers.h"
#include "portal_player.h"
#include "weapon_portalgun.h"
#include "prop_portal_shared.h"
#include "portal_shareddefs.h"
#include "physobj.h"
#include "portal/weapon_physcannon.h"
#include "model_types.h"
#include "rumble_shared.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
static char *g_pszPortalNonCleansable[] =
{
"func_door",
"func_door_rotating",
"prop_door_rotating",
"func_tracktrain",
"env_ghostanimating",
"physicsshadowclone",
"prop_energy_ball",
NULL,
};
//-----------------------------------------------------------------------------
// Purpose: Removes anything that touches it. If the trigger has a targetname,
// firing it will toggle state.
//-----------------------------------------------------------------------------
class CTriggerPortalCleanser : public CBaseTrigger
{
public:
DECLARE_CLASS( CTriggerPortalCleanser, CBaseTrigger );
void Spawn( void );
void Touch( CBaseEntity *pOther );
DECLARE_DATADESC();
// Outputs
COutputEvent m_OnDissolve;
COutputEvent m_OnFizzle;
COutputEvent m_OnDissolveBox;
};
BEGIN_DATADESC( CTriggerPortalCleanser )
// Outputs
DEFINE_OUTPUT( m_OnDissolve, "OnDissolve" ),
DEFINE_OUTPUT( m_OnFizzle, "OnFizzle" ),
DEFINE_OUTPUT( m_OnDissolveBox, "OnDissolveBox" ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( trigger_portal_cleanser, CTriggerPortalCleanser );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTriggerPortalCleanser::Spawn( void )
{
BaseClass::Spawn();
InitTrigger();
}
// Creates a base entity with model/physics matching the parameter ent.
// Used to avoid higher level functions on a disolving entity, which should be inert
// and not react the way it used to (touches, etc).
// Uses simple physics entities declared in physobj.cpp
CBaseEntity* ConvertToSimpleProp ( CBaseEntity* pEnt )
{
CBaseEntity *pRetVal = NULL;
int modelindex = pEnt->GetModelIndex();
const model_t *model = modelinfo->GetModel( modelindex );
if ( model && modelinfo->GetModelType(model) == mod_brush )
{
pRetVal = CreateEntityByName( "simple_physics_brush" );
}
else
{
pRetVal = CreateEntityByName( "simple_physics_prop" );
}
pRetVal->KeyValue( "model", STRING(pEnt->GetModelName()) );
pRetVal->SetAbsOrigin( pEnt->GetAbsOrigin() );
pRetVal->SetAbsAngles( pEnt->GetAbsAngles() );
pRetVal->Spawn();
pRetVal->VPhysicsInitNormal( SOLID_VPHYSICS, 0, false );
return pRetVal;
}
void CTriggerPortalCleanser::Touch( CBaseEntity *pOther )
{
if ( !PassesTriggerFilters( pOther ) )
return;
if ( pOther->IsPlayer() )
{
CPortal_Player *pPlayer = ToPortalPlayer( pOther );
if ( pPlayer )
{
CWeaponPortalgun *pPortalgun = dynamic_cast<CWeaponPortalgun*>( pPlayer->Weapon_OwnsThisType( "weapon_portalgun" ) );
if ( pPortalgun )
{
bool bFizzledPortal = false;
if ( pPortalgun->CanFirePortal1() )
{
CProp_Portal *pPortal = CProp_Portal::FindPortal( pPortalgun->m_iPortalLinkageGroupID, false );
if ( pPortal && pPortal->m_bActivated )
{
pPortal->DoFizzleEffect( PORTAL_FIZZLE_KILLED, false );
pPortal->Fizzle();
// HACK HACK! Used to make the gun visually change when going through a cleanser!
pPortalgun->m_fEffectsMaxSize1 = 50.0f;
bFizzledPortal = true;
}
// Cancel portals that are still mid flight
if ( pPortal && pPortal->GetNextThink( s_pDelayedPlacementContext ) > gpGlobals->curtime )
{
pPortal->SetContextThink( NULL, gpGlobals->curtime, s_pDelayedPlacementContext );
pPortalgun->m_fEffectsMaxSize2 = 50.0f;
bFizzledPortal = true;
}
}
if ( pPortalgun->CanFirePortal2() )
{
CProp_Portal *pPortal = CProp_Portal::FindPortal( pPortalgun->m_iPortalLinkageGroupID, true );
if ( pPortal && pPortal->m_bActivated )
{
pPortal->DoFizzleEffect( PORTAL_FIZZLE_KILLED, false );
pPortal->Fizzle();
// HACK HACK! Used to make the gun visually change when going through a cleanser!
pPortalgun->m_fEffectsMaxSize2 = 50.0f;
bFizzledPortal = true;
}
// Cancel portals that are still mid flight
if ( pPortal && pPortal->GetNextThink( s_pDelayedPlacementContext ) > gpGlobals->curtime )
{
pPortal->SetContextThink( NULL, gpGlobals->curtime, s_pDelayedPlacementContext );
pPortalgun->m_fEffectsMaxSize2 = 50.0f;
bFizzledPortal = true;
}
}
if ( bFizzledPortal )
{
pPortalgun->SendWeaponAnim( ACT_VM_FIZZLE );
pPortalgun->SetLastFiredPortal( 0 );
m_OnFizzle.FireOutput( pOther, this );
pPlayer->RumbleEffect( RUMBLE_RPG_MISSILE, 0, RUMBLE_FLAG_RESTART );
}
}
}
return;
}
CBaseAnimating *pBaseAnimating = dynamic_cast<CBaseAnimating*>( pOther );
if ( pBaseAnimating && !pBaseAnimating->IsDissolving() )
{
int i = 0;
while ( g_pszPortalNonCleansable[ i ] )
{
if ( FClassnameIs( pBaseAnimating, g_pszPortalNonCleansable[ i ] ) )
{
// Don't dissolve non cleansable objects
return;
}
++i;
}
// The portal weight box, used for puzzles in the portal mod is differentiated by its name
// always being 'box'. We use special logic when the cleanser dissolves a box so this is a special output for it.
if ( pBaseAnimating->NameMatches( "box" ) )
{
m_OnDissolveBox.FireOutput( pOther, this );
}
if ( FClassnameIs( pBaseAnimating, "updateitem2" ) )
{
pBaseAnimating->EmitSound( "UpdateItem.Fizzle" );
}
Vector vOldVel;
AngularImpulse vOldAng;
pBaseAnimating->GetVelocity( &vOldVel, &vOldAng );
IPhysicsObject* pOldPhys = pBaseAnimating->VPhysicsGetObject();
if ( pOldPhys && ( pOldPhys->GetGameFlags() & FVPHYSICS_PLAYER_HELD ) )
{
CPortal_Player *pPlayer = (CPortal_Player *)GetPlayerHoldingEntity( pBaseAnimating );
if( pPlayer )
{
// Modify the velocity for held objects so it gets away from the player
pPlayer->ForceDropOfCarriedPhysObjects( pBaseAnimating );
pPlayer->GetAbsVelocity();
vOldVel = pPlayer->GetAbsVelocity() + Vector( pPlayer->EyeDirection2D().x * 4.0f, pPlayer->EyeDirection2D().y * 4.0f, -32.0f );
}
}
// Swap object with an disolving physics model to avoid touch logic
CBaseEntity *pDisolvingObj = ConvertToSimpleProp( pBaseAnimating );
if ( pDisolvingObj )
{
// Remove old prop, transfer name and children to the new simple prop
pDisolvingObj->SetName( pBaseAnimating->GetEntityName() );
UTIL_TransferPoseParameters( pBaseAnimating, pDisolvingObj );
TransferChildren( pBaseAnimating, pDisolvingObj );
pDisolvingObj->SetCollisionGroup( COLLISION_GROUP_INTERACTIVE_DEBRIS );
pBaseAnimating->AddSolidFlags( FSOLID_NOT_SOLID );
pBaseAnimating->AddEffects( EF_NODRAW );
IPhysicsObject* pPhys = pDisolvingObj->VPhysicsGetObject();
if ( pPhys )
{
pPhys->EnableGravity( false );
Vector vVel = vOldVel;
AngularImpulse vAng = vOldAng;
// Disolving hurts, damp and blur the motion a little
vVel *= 0.5f;
vAng.z += 20.0f;
pPhys->SetVelocity( &vVel, &vAng );
}
pBaseAnimating->AddFlag( FL_DISSOLVING );
UTIL_Remove( pBaseAnimating );
}
CBaseAnimating *pDisolvingAnimating = dynamic_cast<CBaseAnimating*>( pDisolvingObj );
if ( pDisolvingAnimating )
{
pDisolvingAnimating->Dissolve( "", gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
}
m_OnDissolve.FireOutput( pOther, this );
}
}
|