forked from itslunaranyo/copper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shooters.qc
473 lines (416 loc) · 12.8 KB
/
shooters.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
//============================================================================
float SF_SHOOT_SUPERSPIKE = 1;
float SF_SHOOT_LASER = 2;
float SF_SHOOT_OGRENADE = 4;
float SF_SHOOT_ACTIVATOR = 16;
/*FGD
@baseclass base(Appearflags, Target, Targetname, Angle) color(220 150 150) = Shooter
[
spawnflags(Flags) =
[
1 : "Spike" : 0
2 : "Laser" : 0
4 : "Ogre Grenade" : 0
16 : "Fire At Activator" : 0
]
movedir(string) : "Override launch vector (x y z)"
volume(string) : "Override sound volume" : "1.0"
delay(string) : "Pause before first shot" : "0"
speed(integer) : "Launch velocity for grenades"
]
*/
void() spikeshooter_fire =
{
if (self.state) return;
vector dir;
entity e;
if (self.spawnflags & SF_SHOOT_ACTIVATOR)
{
if (!self.enemy)
self.enemy = activator;
dir = normalize(self.enemy.origin - self.origin);
}
else
{
if (self.target != string_null)
e = find(world, targetname, self.target);
if (e)
dir = normalize(BoundsCenter(e) - self.origin);
else
dir = self.movedir;
}
if (self.spawnflags & SF_SHOOT_LASER)
{
sound (self, CHAN_VOICE, "enforcer/enfire.wav", self.volume, ATTN_NORM);
dprint5("shot from ", vtos(self.origin), " at ",vtos(dir), "\n");
launch_laser (self.origin, dir*600);
}
else if (self.spawnflags & SF_SHOOT_OGRENADE)
{
sound (self, CHAN_VOICE, "weapons/grenade.wav", self.volume, ATTN_NORM);
e = launch_grenade(self.origin, dir * self.speed);
e.touch = OgreGrenadeTouch;
e.th_die = OgreGrenadeExplode;
}
else
{
sound (self, CHAN_VOICE, "weapons/spike2.wav", self.volume, ATTN_NORM);
e = launch_nail (self.origin, dir * 500);
if (self.spawnflags & SF_SHOOT_SUPERSPIKE)
{
e.classname = "superspike";
e.skin = 1;
e.dmg = 18;
}
}
}
void() shooter_proxy_think =
{
self.buddy.enemy = self.enemy;
SUB_CallAsSelf(spikeshooter_fire,self.buddy);
remove(self);
}
void() shooter_once_think =
{
// iw - if a shooter is triggered more often than its .delay, nextthink is
// repeatedly overwritten and the shooter never fires (bbin1)
// lunaran - spawn a proxy that'll fire at the right time to 'queue up'
// shots, so that none are missed
if (self.nextthink)
{
entity shooty = spawn();
shooty.buddy = self;
shooty.enemy = activator;
shooty.think = shooter_proxy_think;
shooty.nextthink = time + self.delay;
return;
}
self.enemy = activator;
self.think = spikeshooter_fire;
self.nextthink = time + self.delay;
}
void() shooter_think =
{
spikeshooter_fire ();
self.nextthink = time + self.wait + self.rand * random();
}
void() spikeshooter_use = {spikeshooter_fire();} // for id1 hacks
void() shooter_use =
{
self.state = !(self.state);
if (self.state) return;
self.nextthink = time + self.delay;
self.enemy = activator;
}
/*QUAKED trap_spikeshooter (0 .5 .8) (-8 -8 -8) (8 8 8) SUPERSPIKE LASER OGRENADE ? AT_ACTIVATOR
When triggered, fires a spike in the direction set by "angle".
"movedir" override angle with a launch vector of your choosing
"target" aim at an entity instead. can be moving (like a train.)
"delay" delay before firing (for staggering shooters)
"volume" override how loud these things are because damn
"speed" override launch velocity for grenades only (laser and nail speed is standardized for the player's sake)
*/
/*FGD
@PointClass base(Shooter) = trap_spikeshooter : "Triggered shooter. Trigger to fire one shot." []
*/
void() trap_spikeshooter =
{
if (!SUB_ShouldSpawn()) return;
SetMovedir ();
self.volume = zeroconvertdefault(self.volume, 1);
self.use = shooter_once_think;
if (self.spawnflags & SF_SHOOT_OGRENADE)
{
self.speed = zeroconvertdefault(self.speed, 400);
}
if (self.spawnflags & SF_SHOOT_LASER)
{
precache_model2 ("progs/laser.mdl");
precache_sound2 ("enforcer/enfire.wav");
precache_sound2 ("enforcer/enfstop.wav");
}
else
precache_sound_safe ("weapons/spike2.wav");
}
/*QUAKED trap_shooter (0 .5 .8) (-8 -8 -8) (8 8 8) SUPERSPIKE LASER OGRENADE ? AT_ACTIVATOR
Continuously fires spikes in the direction set by "angle". Trigger to turn on, trigger again to turn off.
Laser is only for REGISTERED. YOU PAY FOR LASER
"wait" time between shots (1.0 default)
"delay" delay before firing first spike, so multiple shooters can be staggered
"movedir" override angle with a launch vector of your choosing
"speed" override launch velocity for grenades only (laser and nail speed is standardized for the player's sake)
*/
/*FGD
@PointClass base(Shooter) = trap_shooter : "Continuous shooter. Trigger to turn on and off."
[
delay(string) : "Delay before first shot, so multiple shooters can be staggered"
wait(string) : "Interval between shots"
rand(string) : "Random extra time between shots"
]
*/
void() trap_shooter =
{
if (!SUB_ShouldSpawn()) return;
trap_spikeshooter ();
if (self.targetname != string_null) // start off if something targets us
self.state = 1;
self.use = shooter_use;
if (self.wait == 0)
self.wait = 1;
// original id trap_shooter used nextthink as a mapper-editable delay, which is dumb
// add it to nextthink here anyway for backwards compatibility
self.nextthink = self.nextthink + self.delay + self.wait + self.ltime;
self.think = shooter_think;
}
//============================================================================
float SF_LSHOOT_ONESHOT = 1;
float SF_LSHOOT_TRACKME = 2;
void(vector tgt) trap_lightning_effect =
{
WriteByte (MSG_ALL, SVC_TEMPENTITY);
if (self.strength == 3)
{
WriteByte (MSG_ALL, TE_LIGHTNING3);
}
else if (self.strength == 2)
{
WriteByte (MSG_ALL, TE_LIGHTNING1);
}
else
{
WriteByte (MSG_ALL, TE_LIGHTNING2);
}
WriteEntity (MSG_ALL, self);
WriteCoord (MSG_ALL, self.origin_x);
WriteCoord (MSG_ALL, self.origin_y);
WriteCoord (MSG_ALL, self.origin_z);
WriteCoord (MSG_ALL, tgt_x);
WriteCoord (MSG_ALL, tgt_y);
WriteCoord (MSG_ALL, tgt_z);
}
void() trap_lightning_fire =
{
vector tgt, org, nudge;
entity last, oself;
float i = 0;
if (!self.enemy) // might already be activator
self.enemy = findunlockedtarget(self, world);
if (!self.enemy)
{
if (self.target != string_null || self.target2 != string_null ||
self.target3 != string_null || self.target4 != string_null)
{
return; // has targets, but none are unlocked
}
else
{
tgt = self.origin + self.movedir; // has no targets
}
}
else
{
tgt = BoundsCenter(self.enemy); // for aiming at trains or bobboes
}
//self.enemy = world;
nudge = normalize(tgt - self.origin) * 8;
if ( !(self.spawnflags & SF_LSHOOT_ONESHOT) || self.strength == 3)
{
if (time >= self.nextmovesound)
{
sound (self, CHAN_VOICE, "misc/power.wav", self.volume, ATTN_NORM);
self.nextmovesound = time + 1.2;
}
}
if (self.strength == 1)
{
// do 10 dmg every think
traceline2(self.origin, tgt, self, 0); // hit one target and stop
tgt = trace_endpos;
if (trace_ent.takedamage)
{
T_Damage(trace_ent, self, self, 10);
particle (trace_endpos + nudge, nudge * -8, 225, 40);
sound (trace_ent, CHAN_BODY, "weapons/lhit.wav", 1, ATTN_NORM);
}
}
else
{
// str 2 and 3 lightnings pierce creatures to world
traceline2(self.origin, tgt, self, TRACE_NOMONSTERS);
tgt = trace_endpos;
if (!(self.spawnflags & SF_LSHOOT_ONESHOT) || // always dmg on think in continuous mode
(self.strength == 2 && self.count == 3) || // dmg on first think only in oneshot mode
self.strength == 3 ) // fatbeam is instakill so do it either way
{
org = self.origin;
last = self;
do {
i++;
traceline2(org, tgt, last, 0);
// end on buttons and shootable bmodels
if ( (trace_ent.solid != SOLID_BBOX && trace_ent.solid != SOLID_SLIDEBOX) &&
(!trace_ent.movetype || trace_ent.movetype == MOVETYPE_PUSH) )
{
i = 8;
tgt = trace_endpos;
}
org = trace_endpos + nudge;
if (trace_ent.takedamage)
{
last = trace_ent;
if (self.strength == 2)
{
T_Damage(trace_ent, self, self, 30);
particle (org, nudge * -8, 225, 120);
}
else
{
// handle chthons and shubs intelligently
if (trace_ent.classname == "monster_boss" || trace_ent.classname == "monster_oldone")
{
if (self.count == 10) // first tic only so we don't melt the boss
{
if (trace_ent.classname == "monster_boss")
{
T_Damage (trace_ent, self, self, 1000);
}
else if (trace_ent.classname == "monster_oldone")
{
dprint4(ftos(self.count)," ", ftos(self.strength), " zapping shub with a thing\n");
T_Damage (trace_ent, self, self, 10001); // auto-trigger one pain warble
}
}
}
else
{
T_Damage (trace_ent, self, self, trace_ent.health + min(trace_ent.armorvalue, trace_ent.health / trace_ent.armortype) + 50);
}
}
sound (trace_ent, CHAN_BODY, "weapons/lhit.wav", 1, ATTN_NORM);
}
else if (trace_ent.classname == "monster_boss" && self.strength == 3 && self.count == 10)
{
last = trace_ent;
// get non-takedamage cthons too
dprint4(ftos(self.count)," ", ftos(self.strength), " zapping cthon with a thing\n");
oself = self;
self = trace_ent;
self.health = self.health - 1;
boss_pain(activator, 1);
self = oself;
}
} while (i < 8 && trace_ent != world);
}
}
if (self.strength == 3)
tgt -= nudge * 12; // fatbeams are extra long
trap_lightning_effect(tgt);
if (self.spawnflags & SF_LSHOOT_ONESHOT)
{
self.count = self.count - 1;
if (self.count <= 0)
return;
}
self.think = trap_lightning_fire;
self.nextthink = time + 0.1;
}
void() trap_lightning_proxy =
{
if (self.buddy.spawnflags & SF_LSHOOT_TRACKME)
self.buddy.enemy = self.enemy;
SUB_CallAsSelf(trap_lightning_fire, self.buddy);
sound(self, CHAN_WEAPON, "weapons/lstart.wav", self.volume, ATTN_NORM);
remove(self);
}
void() trap_lightning_use =
{
entity proxy;
if (self.spawnflags & SF_LSHOOT_TRACKME)
self.enemy = activator;
if (self.spawnflags & SF_LSHOOT_ONESHOT)
{
if (time < self.attack_finished) return;
self.attack_finished = time + 0.1;
if (self.strength == 3) self.count = 10;
else if (self.strength == 2) self.count = 3;
else self.count = 1;
if (self.delay > 0)
{
proxy = spawn();
proxy.think = trap_lightning_proxy;
proxy.nextthink = time + self.delay;
proxy.buddy = self;
proxy.enemy = activator;
return;
}
sound(self, CHAN_WEAPON, "weapons/lstart.wav", self.volume, ATTN_NORM);
trap_lightning_fire();
return;
}
// is a toggle zapper
self.state = !self.state;
self.nextmovesound = 0;
if (self.state)
{
sound(self, CHAN_WEAPON, "weapons/lstart.wav", self.volume, ATTN_NORM);
trap_lightning_fire();
}
else
{
sound (self, CHAN_VOICE, "misc/null.wav", 1, ATTN_NORM); // stop zap noise
self.nextthink = 0;
}
}
/*QUAKED trap_lightning (0 .5 .8) (-8 -8 -8) (8 8 8) BURST AT_ACTIVATOR
Continuously fires lightning in the direction set by "angle". Trigger to turn on, trigger again to turn off.
Spawnflags
BURST Fire once when triggered rather than toggling
AT_ACTIVATOR Ignore target and fire at whatever activated it if LOS is not broken
"delay" delay before firing if BURST
"movedir" override angle with a launch vector of your choosing (length sets distance)
"target" override angle by aiming at an entity (will also search target2/3/4)
"strength" choose type of beam:
1 - thin beam, 100dps (burst 10), stops at first target, default
2 - thicker beam, 300dps, burst 30
3 - fat anti-Chthon beam, death to touch, can hurt Chthons and Shubs
*/
/*FGD
@PointClass base(Appearflags, Target, Targetname, Angle) color(220 150 150) = trap_lightning : "Lightning shooter. Trigger to turn on, trigger again to turn off. Fires 10 times per second, unless 'One-shot' spawnflag is checked.
You can choose from three power levels, set by selecting 'strength':
1: 10dmg/100dps. Does not penetrate targets. Uses thin LG beam. One-shot lasts 0.1 seconds. Default.
2: 30dmg/300dps. Penetrates targets. Uses thick Shambler beam. One-shot lasts 0.3 seconds.
3: Instakill. Penetrates targets. Uses fat Chthon beam. One-shot lasts 1 second. Does 1k damage to a Chthon and 10k damage to a Shub." [
spawnflags(Flags) =
[
1 : "One-shot" : 0
2 : "Aim At Activator" : 0
]
movedir(string) : "Override aim vector (x y z) - length of vector sets distance"
delay(string) : "Pause before firing, if oneshot" : "0"
strength(choices) : "Beam Power" =
[
1 : "Small, 10dmg"
2 : "Medium, 30dmg"
3 : "Large, instagib"
]
]
*/
void() trap_lightning =
{
if (!SUB_ShouldSpawn()) return;
SetMovedir();
if (vlen(self.movedir) < 32)
{
self.movedir = normalize(self.movedir) * 768;
}
self.strength = min(3, max(1, self.strength));
precache_sound ("weapons/lstart.wav");
precache_sound ("misc/power.wav");
precache_sound ("weapons/lhit.wav");
self.volume = zeroconvertdefault(self.volume, 1);
self.state = 0;
self.count = 0;
self.use = trap_lightning_use;
if (self.deathtype == string_null)
self.deathtype = "was fried by a bolt of lightning";
}