This repository has been archived by the owner on Sep 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
health.cpp
266 lines (228 loc) · 5.64 KB
/
health.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
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
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/health.cpp $
// $Revision:: 20 $
// $Author:: Aldie $
// $Date:: 3/19/99 5:03p $
//
// Copyright (C) 1997 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// $Log:: /Quake 2 Engine/Sin/code/game/health.cpp $
//
// 20 3/19/99 5:03p Aldie
// Added REGENERATION TECH support
//
// 19 11/17/98 6:08a Jimdose
// made PickupHealth take health from player's inventory before checking if
// they can pick it up. Fixes bug where player can't pickup health due to
// health somehow being in their inventory.
//
// 18 10/27/98 5:19p Aldie
// Added a few items for health
//
// 17 10/09/98 2:06a Aldie
// Updated DMFLAGS
//
// 16 8/27/98 2:33p Aldie
// Changed adrenaline to megahealth
//
// 15 7/23/98 11:25p Aldie
// Fixed health for hopefully the last time.
//
// 14 7/15/98 11:22p Markd
// Don't set the model unless one hasn't been setup yet
//
// 13 7/14/98 6:58p Aldie
// Updated healths
//
// 12 6/25/98 8:47p Markd
// Added keyed items for Triggers, Rewrote Item class, rewrote every pickup
// method
//
// 11 6/24/98 1:36p Aldie
// Implementation of inventory system and picking stuff up
//
// 10 5/27/98 7:33p Markd
// clear out damage if healed
//
// 9 5/24/98 8:46p Jimdose
// Made a lot of functions more str-friendly.
// Got rid of a lot of char * based strings
// Cleaned up get spawn arg functions and sound functions
// sound functions now use consistant syntax
//
// 8 5/13/98 4:45p Jimdose
// Startup event is now posted with 0 delay
//
// 7 5/08/98 2:56p Markd
// Put in health pickup sounds
//
// 6 4/18/98 3:41p Markd
// Changed health types to health_ instead of item_health_
//
// 5 4/07/98 6:43p Jimdose
// turned off respawn in single player
//
// 4 4/04/98 6:04p Jimdose
// Made response from EV_Trigger_ActivateTargets to EV_Trigger_Effect
//
// 3 3/30/98 9:54p Jimdose
// Changed location of .def files
//
// 2 3/30/98 2:30p Jimdose
// Created file
//
// DESCRIPTION:
// Health powerup
//
#include "g_local.h"
#include "item.h"
#include "sentient.h"
#include "health.h"
#include "ctf.h"
CLASS_DECLARATION( Item, Health, "health_020" );
ResponseDef Health::Responses[] =
{
{ &EV_Item_Pickup, ( Response )Health::PickupHealth },
{ NULL, NULL }
};
Health::Health()
{
if ( DM_FLAG( DF_NO_HEALTH ) )
{
PostEvent( EV_Remove, 0 );
return;
}
Set( 20 );
if ( !edict->s.modelindex )
setModel( "health.def" );
}
void Health::PickupHealth
(
Event *ev
)
{
Sentient *sen;
Item * item;
Entity *other;
other = ev->GetEntity( 1 );
if ( !other || !other->isSubclassOf( Sentient ) )
{
return;
}
sen = ( Sentient * )other;
//
// We don't want the player to hold on to a box of health!
// This can happen if a player is given a health object,
// so as a precaution, get rid of any health he's carrying.
//
item = sen->FindItem( getClassname() );
if ( item )
{
sen->RemoveItem( item );
item->PostEvent( EV_Remove, 0 );
}
if ( !ItemPickup( other ) )
{
return;
}
sen->health += amount;
if ( ctf->value && sen->HasItem( "CTF_Tech_Regeneration" ) )
{
if ( sen->health > CTF_TECH_REGENERATION_HEALTH )
{
sen->health = CTF_TECH_REGENERATION_HEALTH;
}
}
else if ( sen->health > 200 )
{
sen->health = 200;
}
//
// clear out damage if healed
//
if ( sen->health > 90 )
{
// clear the damage states
memset( sen->edict->s.groups, 0, sizeof( sen->edict->s.groups ) );
}
//
// we don't want the player to hold on to a box of health!
//
item = sen->FindItem( getClassname() );
if ( item )
{
sen->RemoveItem( item );
item->PostEvent( EV_Remove, 0 );
}
}
CLASS_DECLARATION( Health, SmallHealth, "health_005" );
ResponseDef SmallHealth::Responses[] =
{
{ NULL, NULL }
};
SmallHealth::SmallHealth()
{
Set( 5 );
setModel( "health_small.def" );
}
CLASS_DECLARATION( Health, LargeHealth, "health_050" );
ResponseDef LargeHealth::Responses[] =
{
{ NULL, NULL }
};
LargeHealth::LargeHealth()
{
Set( 50 );
setModel( "health_large.def" );
}
CLASS_DECLARATION( Health, MegaHealth, "health_100" );
ResponseDef MegaHealth::Responses[] =
{
{ NULL, NULL }
};
MegaHealth::MegaHealth()
{
Set( 100 );
setModel( "health_medkit.def" );
}
CLASS_DECLARATION( Health, Apple, NULL );
ResponseDef Apple::Responses[] =
{
{ NULL, NULL }
};
Apple::Apple()
{
setModel( "health_apple.def" );
}
CLASS_DECLARATION( Health, Banana, NULL );
ResponseDef Banana::Responses[] =
{
{ NULL, NULL }
};
Banana::Banana()
{
setModel( "health_banana.def" );
}
CLASS_DECLARATION( Health, Sandwich, NULL );
ResponseDef Sandwich::Responses[] =
{
{ NULL, NULL }
};
Sandwich::Sandwich()
{
setModel( "health_sandwich.def" );
}
CLASS_DECLARATION( Health, Soda, NULL );
ResponseDef Soda::Responses[] =
{
{ NULL, NULL }
};
Soda::Soda()
{
setModel( "health_soda.def" );
}