This repository has been archived by the owner on May 4, 2022. It is now read-only.
forked from FWGS/hlsdk-portable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
airtank.cpp
114 lines (93 loc) · 2.62 KB
/
airtank.cpp
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
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
class CAirtank : public CGrenade
{
void Spawn( void );
void Precache( void );
void EXPORT TankThink( void );
void EXPORT TankTouch( CBaseEntity *pOther );
int BloodColor( void ) { return DONT_BLEED; };
void Killed( entvars_t *pevAttacker, int iGib );
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
int m_state;
};
LINK_ENTITY_TO_CLASS( item_airtank, CAirtank )
TYPEDESCRIPTION CAirtank::m_SaveData[] =
{
DEFINE_FIELD( CAirtank, m_state, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CAirtank, CGrenade )
void CAirtank::Spawn( void )
{
Precache();
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
SET_MODEL( ENT( pev ), "models/w_oxygen.mdl" );
UTIL_SetSize( pev, Vector( -16, -16, 0), Vector( 16, 16, 36 ) );
UTIL_SetOrigin( pev, pev->origin );
SetTouch( &CAirtank::TankTouch );
SetThink( &CAirtank::TankThink );
pev->flags |= FL_MONSTER;
pev->takedamage = DAMAGE_YES;
pev->health = 20;
pev->dmg = 50;
m_state = 1;
}
void CAirtank::Precache( void )
{
PRECACHE_MODEL( "models/w_oxygen.mdl" );
PRECACHE_SOUND( "doors/aliendoor3.wav" );
}
void CAirtank::Killed( entvars_t *pevAttacker, int iGib )
{
pev->owner = ENT( pevAttacker );
// UNDONE: this should make a big bubble cloud, not an explosion
Explode( pev->origin, Vector( 0, 0, -1 ) );
}
void CAirtank::TankThink( void )
{
// Fire trigger
m_state = 1;
SUB_UseTargets( this, USE_TOGGLE, 0 );
}
void CAirtank::TankTouch( CBaseEntity *pOther )
{
if( !pOther->IsPlayer() )
return;
if( !m_state )
{
// "no oxygen" sound
EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim2.wav", 1.0, ATTN_NORM );
return;
}
// give player 12 more seconds of air
pOther->pev->air_finished = gpGlobals->time + 12;
// suit recharge sound
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "doors/aliendoor3.wav", 1.0, ATTN_NORM );
// recharge airtank in 30 seconds
pev->nextthink = gpGlobals->time + 30;
m_state = 0;
SUB_UseTargets( this, USE_TOGGLE, 1 );
}