-
Notifications
You must be signed in to change notification settings - Fork 17
/
item_health_armor.qc
353 lines (297 loc) · 8.48 KB
/
item_health_armor.qc
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
/*
=========================================================================
HEALTH BOXES
=========================================================================
*/
float ITEM_HEALTH_ROTTEN = 1;
float ITEM_HEALTH_MEGA = 2;
void() health_touch =
{
if (!CheckValidTouch()) return;
if (!T_Heal(other, self.healamount, (self.spawnflags & ITEM_HEALTH_MEGA)))
return;
// coop 1 megahealth brings all other clients up to 100
entity pl;
if (coop == 1 && self.spawnflags & ITEM_HEALTH_MEGA)
{
pl = get_next_client(other);
while (pl != other)
{
if (T_Heal(pl, 100, FALSE))
{
sprint(pl, "You were restored by ");
sprint(pl, other.netname);
sprint(pl, "'s Megahealth\n");
sound(pl, CHAN_ITEM, self.noise, 1, ATTN_NORM);
}
pl = get_next_client(pl);
}
}
sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
ItemTouched();
}
/*
================================
item_health & item_health_go
split up precaches and business code for late game health spawns
================================
*/
void() item_health_go
{
self.touch = health_touch;
self.type = "health";
if (self.spawnflags & ITEM_HEALTH_ROTTEN)
{
setmodel(self, "progs/m_h15.mdl");
self.noise = "items/r_item1.wav";
self.healamount = 15;
}
else if (self.spawnflags & ITEM_HEALTH_MEGA)
{
setmodel(self, "progs/m_h100.mdl");
self.noise = "items/r_item2.wav";
self.healamount = 100;
}
else
{
setmodel(self, "progs/m_h25.mdl");
self.noise = "items/health1.wav";
self.healamount = 25;
}
setsize (self, '0 0 0', '32 32 56');
if (deathmatch == 1 || deathmatch == 3)
{
if (self.spawnflags & ITEM_HEALTH_MEGA)
// 20 seconds after health <= 100, minimum 25 seconds
// Copper doesn't handle megahealth the same way, so we can't do that.
// This is a longer time, picked somewhat arbitrarily.
// This will be slower than vanilla id1 if you're taking a lot of damage,
// but faster if you're being relatively safe.
self.wait = 40;
else
self.wait = 20;
}
StartItem ();
}
// ===============================================================================
/*QUAKED item_health (0 .5 .5) (0 0 0) (32 32 24) SMALL MEGA SUSPENDED
Health box. Normally gives 25 points.
Flags:
"mega" will add 100 health, then rot you down to your maximum health limit, one point per second
"small" gives 15 points
Keys:
"target/2/3/4/k" - entity to trigger when picked up
"targetname" - will not spawn until triggered
"wait" - will respawn after 'wait' seconds. fires targets every time.
"count" - limit number of times to respawn
*/
/*FGD
@PointClass size(0 0 0, 32 32 24) color(0 128 128) base(Item)
model(
{{
spawnflags & 2 -> ":maps/b_bh100.bsp",
spawnflags & 1 -> ":maps/b_bh10.bsp",
":maps/b_bh25.bsp"
}}
) =
item_health : "Health pack, +25"
[
spawnflags(flags) =
[
1 : "Small, +15" : 0
2 : "Megahealth, +100" : 0
]
]
*/
void() item_health =
{
if (!SUB_ShouldSpawn()) return;
if (self.spawnflags & ITEM_HEALTH_MEGA)
{
precache_model_safe("progs/m_h100.mdl");
precache_sound_safe("items/r_item2.wav");
}
else if (self.spawnflags & ITEM_HEALTH_ROTTEN)
{
precache_model_safe("progs/m_h15.mdl");
precache_sound_safe("items/r_item1.wav");
}
else
{
precache_model_safe("progs/m_h25.mdl");
precache_sound_safe("items/health1.wav");
}
item_health_go();
}
/*
===============================================================================
ARMOR
armorvalue = hit point quantity
armortype = 0-1 protection rate
===============================================================================
*/
float ARMORTYPE_GREEN = 0.3;
float ARMORTYPE_YELLOW = 0.5;
float ARMORTYPE_RED = 0.7;
/*
============
armor_set_type
============
*/
void(entity e) armor_set_type =
{
if (e.classname != "player")
return;
e.items = not(e.items, (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3));
if (!e.armorvalue)
{
e.armortype = 0.0;
return;
}
if (e.armortype < ARMORTYPE_YELLOW)
e.items |= IT_ARMOR1;
else if (e.armortype < ARMORTYPE_RED)
e.items |= IT_ARMOR2;
else
e.items |= IT_ARMOR3;
e.armorvalue = min(e.armorvalue, 500);
}
/*
============
armor_give
============
*/
float(entity e, float amt, float absorb, float replace) armor_give =
{
if (!amt)
return FALSE;
if (replace)
{
if (absorb < e.armortype)
{
// strength downgrade, quantity upgrade
// quake's original armor comparison test weighted both amounts by their protection
// strength with a straight multiply (a.type * a.amt > e.type * e.amt) to determine
// which was "worth" more. with the current values, those breakeven points fall on
// 42, 60, and 107, so we round those off to make it easier for players to notice
// and learn the pickup cutoffs
if (absorb == ARMORTYPE_GREEN && e.armortype == ARMORTYPE_RED && e.armorvalue > 40)
return FALSE;
if (absorb == ARMORTYPE_GREEN && e.armortype == ARMORTYPE_YELLOW && e.armorvalue > 60)
return FALSE;
if (absorb == ARMORTYPE_YELLOW && e.armortype == ARMORTYPE_RED && e.armorvalue > 100)
return FALSE;
}
else if (absorb == e.armortype)
{ // strength match or strict downgrade
if (amt <= e.armorvalue)
return FALSE;
}
else
{ // strength upgrade
if (amt < e.armorvalue)
{ // weird edge case: strength upgrade, quantity downgrade
// we can accumulate enough of a weak armor (by picking up backpacks or
// through target_items horseplay) that we can be shut out of picking up
// a stronger one, so let the player keep a portion of their saved-up
// extra armor at the new strength
if (absorb == ARMORTYPE_RED && e.armortype == ARMORTYPE_GREEN)
amt = floor((amt * 3 + e.armorvalue) / 4); // keep 1/4 of the excess
else
amt = floor((amt + e.armorvalue) / 2); // keep 1/2 if it
}
}
e.armorvalue = amt;
e.armortype = absorb;
}
else
{
if (absorb > e.armortype)
e.armortype = absorb;
else if (e.armortype == 0)
e.armortype = ARMORTYPE_GREEN;
e.armorvalue += amt;
}
armor_set_type(e);
return TRUE;
}
/*
============
armor_touch
============
*/
void() armor_touch =
{
if (!CheckValidTouch()) return;
if (!armor_give(other, self.armorvalue, self.armortype, TRUE))
return;
sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM);
sprint(other, "You got armor\n");
stuffcmd (other, "bf\n");
ItemTouched();
}
// ===============================================================================
/*
============
StartArmor
============
*/
void(float skn, float amt) StartArmor =
{
if (!SUB_ShouldSpawn()) return;
self.skin = skn;
self.armorvalue = amt;
if (skn == 2)
self.armortype = ARMORTYPE_RED;
else if (skn == 1)
self.armortype = ARMORTYPE_YELLOW;
else
self.armortype = ARMORTYPE_GREEN;
self.touch = armor_touch;
self.type = "armor";
precache_model_safe ("progs/armor.mdl");
setmodel (self, "progs/armor.mdl");
if (deathmatch == 1 || deathmatch == 3)
self.wait = 20;
setsize (self, '-16 -16 0', '16 16 56');
StartItem ();
}
/*QUAKED item_armor1 (0 .5 .5) (-16 -16 0) (16 16 32) ? ? SUSPENDED
Green armor, gives 100 points.
Keys:
"target/2/3/4/k" - entity to trigger when picked up
"targetname" - will not spawn until triggered
"wait" - will respawn after 'wait' seconds. fires targets every time.
"count" - limit number of times to respawn
*/
/*FGD
@PointClass size(-16 -16 0, 16 16 56) color(0 180 180) base(Item) model({ "path": ":progs/armor.mdl" }) =
item_armor1 : "Green armor (100pts, 30%)" []
*/
void() item_armor1 = { StartArmor(0,100); }
/*QUAKED item_armor2 (0 .5 .5) (-16 -16 0) (16 16 32) ? ? SUSPENDED
Yellow armor, gives 150 points.
Keys:
"target/2/3/4/k" - entity to trigger when picked up
"targetname" - will not spawn until triggered
"wait" - will respawn after 'wait' seconds. fires targets every time.
"count" - limit number of times to respawn
*/
/*FGD
@PointClass size(-16 -16 0, 16 16 56) color(180 0 180) base(Item) model({ "path": ":progs/armor.mdl", "skin": 1 }) =
item_armor2 : "Yellow armor (150pts, 50%)" []
*/
void() item_armor2 = { StartArmor(1,150); }
/*QUAKED item_armorInv (0 .5 .5) (-16 -16 0) (16 16 32) ? ? SUSPENDED
Red armor, gives 200 armor points.
Keys:
"target/2/3/4/k" - entity to trigger when picked up
"targetname" - will not spawn until triggered
"wait" - will respawn after 'wait' seconds. fires targets every time.
"count" - limit number of times to respawn
*/
/*FGD
@PointClass size(-16 -16 0, 16 16 56) color(180 0 0) base(Item) model({ "path": ":progs/armor.mdl", "skin": 2 }) =
item_armorInv : "Red armor (200pts, 70%)" []
*/
void() item_armorInv = { StartArmor(2,200); }