-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathweapons.qc
508 lines (443 loc) · 10.9 KB
/
weapons.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
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
/*
===============================================================================
PLAYER WEAPONS
individual weapons moved to their own files, as this one was getting long
===============================================================================
*/
// called by worldspawn
void() W_Precache =
{
precache_sound ("weapons/r_exp3.wav");
precache_sound ("weapons/rocket1i.wav"); // nailgun
precache_sound ("weapons/sgun1.wav");
precache_sound ("weapons/guncock.wav"); // sg
precache_sound ("weapons/ric1.wav"); // ricochet (used in c code)
precache_sound ("weapons/ric2.wav"); // ricochet (used in c code)
precache_sound ("weapons/ric3.wav"); // ricochet (used in c code)
precache_sound ("weapons/spike2.wav"); // super spikes
precache_sound ("weapons/tink1.wav"); // spikes tink (used in c code)
precache_sound ("weapons/grenade.wav"); // grenade launcher
precache_sound ("weapons/bounce.wav"); // grenade bounce
precache_sound ("weapons/shotgn2.wav"); // ssg
precache_model2 ("progs/k_spike.mdl");
precache_model ("progs/lavaball.mdl");
precache_sound ("weapons/lhit.wav"); //lightning
precache_sound ("weapons/lstart.wav"); //lightning start
// precache_sound ("items/damage3.wav");
// ax sounds
precache_sound ("weapons/ax1.wav"); // ax swoosh
precache_sound2 ("weapons/axhit1.wav"); // ax hit meat
precache_sound2 ("weapons/axhit2.wav"); // ax hit meat 2
precache_sound ("player/axhit1.wav"); // ax hit me
precache_sound ("player/axhit2.wav"); // ax hit world
precache_sound ("zombie/z_hit.wav");
precache_model ("progs/v_axe2.mdl");
precache_model ("progs/v_shot.mdl");
precache_model ("progs/v_nail.mdl");
precache_model ("progs/v_rock.mdl");
precache_model ("progs/v_shot2.mdl");
precache_model ("progs/v_nail2.mdl");
precache_model ("progs/v_rock2.mdl");
precache_model ("progs/v_light.mdl");
}
/*
========
SuperDamageSound
========
*/
void() SuperDamageSound =
{
if (!has_quad(self)) return;
if (self.super_damage_finished < time + 3) return;
if (self.super_sound < time)
{
self.super_sound = time + 0.9;
sound (self, CHAN_POWERUP, "items/damage3.wav", 1, ATTN_NORM);
}
}
// ==================================================================
float(float w) W_RankForWeapon =
{
if (!w)
return 666;
if (w == IT_LIGHTNING)
return 1;
if (w == IT_ROCKET_LAUNCHER)
return 2;
if (w == IT_SUPER_NAILGUN)
return 3;
if (w == IT_GRENADE_LAUNCHER)
return 4;
if (w == IT_SUPER_SHOTGUN)
return 5;
if (w == IT_NAILGUN)
return 6;
return 7;
}
/*
=============
W_BetterWeapon
Deathmatch weapon change rules for picking up a weapon
=============
*/
void(entity e, float new) W_BetterWeapon =
{
entity oself = self;
if (!deathmatch)
{
// don't switch to explosive weapons with quad
// 1.12: don't switch to explosives when invisible either, since you can't see the stupid viewmodel
if ( (has_quad(e) || has_invis(e)) &&
(new == IT_ROCKET_LAUNCHER || new == IT_GRENADE_LAUNCHER))
return;
// don't switch to a lightning gun when standing in water
if (e.waterlevel >= 2 && new == IT_LIGHTNING)
return;
}
self = e;
if (!deathmatch || W_RankForWeapon (new) < W_RankForWeapon (self.weapon) )
W_Select(new);
self = oself;
}
float(float weap) W_HasAmmo =
{
if (!weap || weap == IT_AXE) return TRUE;
if (weap == IT_SUPER_SHOTGUN) return (self.ammo_shells >= 2);
if (weap == IT_SHOTGUN) return (self.ammo_shells >= 1);
if (weap == IT_NAILGUN) return (self.ammo_nails >= 1);
if (weap == IT_SUPER_NAILGUN) return (self.ammo_nails >= 2);
if (weap == IT_LIGHTNING) return (self.ammo_cells >= 1);
if (weap == IT_GRENADE_LAUNCHER || weap == IT_ROCKET_LAUNCHER)
return (self.ammo_rockets >= 1);
return FALSE;
}
float() W_BestWeapon =
{
if(self.items & (IT_SUPER_NAILGUN) && W_HasAmmo(IT_SUPER_NAILGUN))
return IT_SUPER_NAILGUN;
if(self.items & (IT_SUPER_SHOTGUN) && W_HasAmmo (IT_SUPER_SHOTGUN))
return IT_SUPER_SHOTGUN;
if (self.items & (IT_LIGHTNING) && self.waterlevel <= 1 && W_HasAmmo(IT_LIGHTNING))
return IT_LIGHTNING;
if(self.items & (IT_NAILGUN) && W_HasAmmo(IT_NAILGUN))
return IT_NAILGUN;
if(self.items & (IT_SHOTGUN) && W_HasAmmo(IT_SHOTGUN))
return IT_SHOTGUN;
if (self.items & IT_AXE)
return IT_AXE;
if(self.items & (IT_ROCKET_LAUNCHER) && W_HasAmmo(IT_ROCKET_LAUNCHER))
return IT_ROCKET_LAUNCHER;
if(self.items & (IT_GRENADE_LAUNCHER) && W_HasAmmo (IT_GRENADE_LAUNCHER))
return IT_GRENADE_LAUNCHER;
return 0;
}
void() W_SelectBestWeapon =
{
W_Select(W_BestWeapon());
}
void() W_SelectBestShotgun =
{
if (self.items & (IT_SHOTGUN|IT_SUPER_SHOTGUN))
{
if (!W_Select(IT_SHOTGUN) && !W_Select(IT_SUPER_SHOTGUN))
sprint (self, "not enough ammo.\n");
}
else
{
sprint(self, "no weapon.\n");
}
}
void() W_SelectBestNailgun =
{
if (self.items & (IT_NAILGUN|IT_SUPER_NAILGUN))
{
if (!W_Select(IT_NAILGUN) && !W_Select(IT_SUPER_NAILGUN))
sprint (self, "not enough ammo.\n");
}
else
{
sprint(self, "no weapon.\n");
}
}
/*
============
W_ChangeWeapon
============
*/
void() W_ChangeWeapon =
{
local float it, am, fl;
if (self.customflags & CFL_PLUNGE)
return;
it = self.items;
am = 0;
if (self.impulse == 1)
{
fl = IT_AXE;
}
else if (self.impulse == 2)
{
fl = IT_SHOTGUN;
if (self.ammo_shells < 1)
am = 1;
}
else if (self.impulse == 3)
{
fl = IT_SUPER_SHOTGUN;
if (self.ammo_shells < 2)
am = 1;
}
else if (self.impulse == 4)
{
fl = IT_NAILGUN;
if (self.ammo_nails < 1)
am = 1;
}
else if (self.impulse == 5)
{
fl = IT_SUPER_NAILGUN;
if (self.ammo_nails < 2)
am = 1;
}
else if (self.impulse == 6)
{
fl = IT_GRENADE_LAUNCHER;
if (self.ammo_rockets < 1)
am = 1;
}
else if (self.impulse == 7)
{
fl = IT_ROCKET_LAUNCHER;
if (self.ammo_rockets < 1)
am = 1;
}
else if (self.impulse == 8)
{
fl = IT_LIGHTNING;
if (self.ammo_cells < 1)
am = 1;
}
self.impulse = 0;
if (!(self.items & fl))
{ // don't have the weapon or the ammo
sprint (self, "no weapon.\n");
return;
}
if (am)
{ // don't have the ammo
sprint (self, "not enough ammo.\n");
return;
}
W_Select(fl);
}
/*
============
Weapon Cycling
for players who insist on shuffling through their inventory the slow way
============
*/
float W_Next(float w) =
{
if (w == IT_AXE) return IT_SHOTGUN;
else if (w == IT_LIGHTNING) return IT_AXE;
else return w * 2;
}
float W_Prev(float w) =
{
if (w == IT_SHOTGUN) return IT_AXE;
else if (w == IT_AXE) return IT_LIGHTNING;
else return w / 2;
}
// cycle weapon up
void() CycleWeaponCommand =
{
float weap = self.weapon;
self.impulse = 0;
if (!weap)
weap = W_BestWeapon();
else do {
weap = W_Next(weap);
if (self.items & weap && W_HasAmmo(weap))
break;
} while (weap != self.weapon);
W_Select (weap);
}
// cycle weapon down
void() CycleWeaponReverseCommand =
{
float weap = self.weapon;
self.impulse = 0;
if (!weap)
weap = W_BestWeapon();
else do {
weap = W_Prev(weap);
if (self.items & weap && W_HasAmmo(weap))
break;
} while (weap != self.weapon);
W_Select (weap);
}
// ==================================================================
void() W_SetIdleWeaponFrame =
{
self.weaponframe = 0;
}
void() W_SetCurrentAmmo =
{
self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
if (self.weapon == IT_SHOTGUN || self.weapon == IT_SUPER_SHOTGUN)
{
self.currentammo = self.ammo_shells;
self.items = self.items | IT_SHELLS;
}
else if (self.weapon == IT_NAILGUN || self.weapon == IT_SUPER_NAILGUN)
{
self.currentammo = self.ammo_nails;
self.items = self.items | IT_NAILS;
}
else if (self.weapon == IT_GRENADE_LAUNCHER || self.weapon == IT_ROCKET_LAUNCHER)
{
self.currentammo = self.ammo_rockets;
self.items = self.items | IT_ROCKETS;
}
else if (self.weapon == IT_LIGHTNING)
{
self.currentammo = self.ammo_cells;
self.items = self.items | IT_CELLS;
}
else // axes, etc
{
self.currentammo = 0;
}
}
void() W_ResetWeaponState =
{
player_run (); // get out of any weapon firing states
self.lip = 0; // reset nailgun barrel cycle
self.weaponframe = 0;
//self.attack_finished = 0; // don't lose attack debounce time from last attack,
// if any, or picking up/switching weapons can cause double attacks
if (self.weapon == IT_AXE )
self.weaponmodel = "progs/v_axe2.mdl";
else if (self.weapon == IT_SHOTGUN)
self.weaponmodel = "progs/v_shot.mdl";
else if (self.weapon == IT_SUPER_SHOTGUN)
self.weaponmodel = "progs/v_shot2.mdl";
else if (self.weapon == IT_NAILGUN)
self.weaponmodel = "progs/v_nail.mdl";
else if (self.weapon == IT_SUPER_NAILGUN)
self.weaponmodel = "progs/v_nail2.mdl";
else if (self.weapon == IT_GRENADE_LAUNCHER)
self.weaponmodel = "progs/v_rock.mdl";
else if (self.weapon == IT_ROCKET_LAUNCHER)
self.weaponmodel = "progs/v_rock2.mdl";
else if (self.weapon == IT_LIGHTNING)
self.weaponmodel = "progs/v_light.mdl";
else
self.weaponmodel = string_null;
W_SetCurrentAmmo();
}
void() W_SelectLastWeapon =
{
if (self.attack_state)
W_Select(self.attack_state);
}
/*
============
W_Select
This should be the only function that changes .weapon
============
*/
float(float weap) W_Select =
{
if (weap)
{
if (self.weapon == weap) return TRUE;
if (self.items & weap == 0) return FALSE;
if (!W_HasAmmo(weap)) return FALSE;
self.attack_state = self.weapon;
}
self.weapon = weap;
W_ResetWeaponState();
return TRUE;
}
// ==================================================================
/*
============
W_Attack
An attack impulse can be triggered now
============
*/
void() W_Attack =
{
if (self.weapon && !W_HasAmmo(self.weapon))
{
W_SelectBestWeapon();
if (!self.weapon || self.weapon == IT_AXE)
{
sprint (self, "not enough ammo.\n");
return;
}
}
if (self.customflags & (CFL_PLUNGE|CFL_LIMBO))
return;
makevectors (self.v_angle); // calculate forward angle for velocity
if (self.weapon == IT_AXE)
{
player_axe();
W_AxeSwing();
return;
}
// moved after axe so that silent swings don't wake monsters
self.show_hostile = time + 1;
if (self.weapon == IT_SHOTGUN)
{
player_shot1 ();
W_FireShotgun ();
}
else if (self.weapon == IT_SUPER_SHOTGUN)
{
player_shot1 ();
W_FireSuperShotgun ();
}
else if (self.weapon == IT_NAILGUN || self.weapon == IT_SUPER_NAILGUN)
{
player_nail();
W_FireSpikes ();
}
else if (self.weapon == IT_GRENADE_LAUNCHER)
{
player_rocket1();
W_FireGrenade();
}
else if (self.weapon == IT_ROCKET_LAUNCHER)
{
player_rocket1();
W_FireRocket();
}
else if (self.weapon == IT_LIGHTNING)
{
player_light1();
self.attack_finished = time + 0.1;
sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
}
}
/*
============
W_WeaponFrame
Called every frame so impulse events can be handled as well as possible
============
*/
void() W_WeaponFrame =
{
if (self.impulse)
ImpulseCommands();
if (time < self.attack_finished)
return;
// check for attack
if (self.button0)
{
SuperDamageSound ();
W_Attack ();
}
}
// impulses also moved to their own file