-
Notifications
You must be signed in to change notification settings - Fork 2
/
trigger.qc
705 lines (577 loc) · 15.5 KB
/
trigger.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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
enumflags : int
{
TRIGGER_MONSTER,
TRIGGER_NOT_PLAYER,
TRIGGER_TRIGGERED,
TRIGGER_TOGGLE
};
void(entity self) InitTrigger =
{
if (self.s.angles)
G_SetMovedir(self.s.angles, self.movedir);
self.solid = SOLID_TRIGGER;
self.movetype = MOVETYPE_NONE;
gi.setmodel(self, self.model);
self.svflags = SVF_NOCLIENT;
}
// the wait time has passed, so set back up for another activation
static void(entity ent) multi_wait =
{
ent.nextthink = 0;
}
// the trigger was just activated
// ent.activator should be set to the activator so it can be held through a delay
// so wait for the delay time before firing
static void(entity ent) multi_trigger =
{
if (ent.nextthink)
return; // already been triggered
G_UseTargets(ent, ent.activator);
if (ent.wait > 0) {
ent.think = multi_wait;
ent.nextthink = level.framenum + (int)(ent.wait * BASE_FRAMERATE);
} else {
// we can't just remove (self) here, because this is a touch function
// called while looping through area links...
ent.touch = 0;
ent.nextthink = level.framenum + 1;
ent.think = G_FreeEdict;
}
}
static void(entity ent, entity other, entity cactivator) Use_Multi =
{
#ifdef GROUND_ZERO
if (ent.spawnflags & TRIGGER_TOGGLE)
{
if (ent.solid == SOLID_TRIGGER)
ent.solid = SOLID_NOT;
else
ent.solid = SOLID_TRIGGER;
gi.linkentity (ent);
}
else
{
#endif
ent.activator = cactivator;
multi_trigger(ent);
#ifdef GROUND_ZERO
}
#endif
}
static void(entity self, entity other, vector plane, csurface_t surf) Touch_Multi =
{
if (other.is_client) {
if (self.spawnflags & 2)
return;
} else if (other.svflags & SVF_MONSTER) {
if (!(self.spawnflags & 1))
return;
} else
return;
if (self.movedir) {
vector forward;
AngleVectors(other.s.angles, &forward, 0, 0);
if (forward * self.movedir < 0)
return;
}
self.activator = other;
multi_trigger(self);
}
/*QUAKED trigger_multiple (.5 .5 .5) ? MONSTER NOT_PLAYER TRIGGERED
Variable sized repeatable trigger. Must be targeted at one or more entities.
If "delay" is set, the trigger waits some time after activating before firing.
"wait" : Seconds between triggerings. (.2 default)
sounds
1) secret
2) beep beep
3) large switch
4)
set "message" to text string
*/
static void(entity self, entity other, entity cactivator) trigger_enable =
{
self.solid = SOLID_TRIGGER;
self.use = Use_Multi;
gi.linkentity(self);
}
API_FUNC static void(entity ent) SP_trigger_multiple =
{
if (ent.sounds == 1)
ent.noise_index = gi.soundindex("misc/secret.wav");
else if (ent.sounds == 2)
ent.noise_index = gi.soundindex("misc/talk.wav");
else if (ent.sounds == 3)
ent.noise_index = gi.soundindex("misc/trigger1.wav");
if (!ent.wait)
ent.wait = 0.2f;
ent.touch = Touch_Multi;
ent.movetype = MOVETYPE_NONE;
ent.svflags |= SVF_NOCLIENT;
#ifdef GROUND_ZERO
if (ent.spawnflags & (TRIGGER_TRIGGERED | TRIGGER_TOGGLE))
#else
if (ent.spawnflags & 4)
#endif
{
ent.solid = SOLID_NOT;
ent.use = trigger_enable;
} else {
ent.solid = SOLID_TRIGGER;
ent.use = Use_Multi;
}
if (ent.s.angles)
G_SetMovedir(ent.s.angles, ent.movedir);
gi.setmodel(ent, ent.model);
gi.linkentity(ent);
}
/*QUAKED trigger_once (.5 .5 .5) ? x x TRIGGERED
Triggers once, then removes itself.
You must set the key "target" to the name of another object in the level that has a matching "targetname".
If TRIGGERED, this trigger must be triggered before it is live.
sounds
1) secret
2) beep beep
3) large switch
4)
"message" string to be displayed when triggered
*/
API_FUNC static void(entity ent) SP_trigger_once =
{
// make old maps work because I messed up on flag assignments here
// triggered was on bit 1 when it should have been on bit 4
if (ent.spawnflags & 1) {
vector v;
v = ent.mins + (0.5f * ent.size);
ent.spawnflags &= ~1;
ent.spawnflags |= 4;
gi.dprintf("fixed TRIGGERED flag on %s at %s\n", ent.classname, vtos(v));
}
ent.wait = -1f;
SP_trigger_multiple(ent);
}
/*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
This fixed size trigger cannot be touched, it can only be fired by other events.
*/
static void(entity self, entity other, entity cactivator) trigger_relay_use =
{
G_UseTargets(self, cactivator);
}
API_FUNC static void(entity self) SP_trigger_relay =
{
self.use = trigger_relay_use;
}
#ifdef SINGLE_PLAYER
/*
==============================================================================
trigger_key
==============================================================================
*/
/*QUAKED trigger_key (.5 .5 .5) (-8 -8 -8) (8 8 8)
A relay trigger that only fires it's targets if player has the proper key.
Use "item" to specify the required key, for example "key_data_cd"
*/
static void(entity self, entity other, entity cactivator) trigger_key_use =
{
if (!self.item)
return;
if (!cactivator.is_client)
return;
int index = self.item->id;
if (!cactivator.client.pers.inventory[index])
{
if (level.framenum < self.touch_debounce_framenum)
return;
self.touch_debounce_framenum = level.framenum + (int)(5.0f * BASE_FRAMERATE);
gi.centerprintf(cactivator, "You need the %s", self.item->pickup_name);
gi.sound(cactivator, CHAN_AUTO, gi.soundindex("misc/keytry.wav"), 1, ATTN_NORM, 0);
return;
}
gi.sound(cactivator, CHAN_AUTO, gi.soundindex("misc/keyuse.wav"), 1, ATTN_NORM, 0);
if (coop.intVal)
{
int player;
entity ent;
if (self.item->classname == "key_power_cube")
{
int cube;
for (cube = 0; cube < 8; cube++)
if (cactivator.client.pers.power_cubes & (1 << cube))
break;
for (player = 1; player <= game.maxclients; player++)
{
ent = itoe(player);
if (!ent.inuse)
continue;
if (!ent.is_client)
continue;
if (ent.client.pers.power_cubes & (1 << cube))
{
ent.client.pers.inventory[index]--;
ent.client.pers.power_cubes &= ~(1 << cube);
}
}
}
else
{
for (player = 1; player <= game.maxclients; player++)
{
ent = itoe(player);
if (!ent.inuse)
continue;
if (!ent.is_client)
continue;
ent.client.pers.inventory[index] = 0;
}
}
}
else
cactivator.client.pers.inventory[index]--;
G_UseTargets(self, cactivator);
self.use = 0;
}
API_FUNC static void(entity self) SP_trigger_key =
{
if (!st.item)
{
gi.dprintf("no key item for trigger_key at %s\n", vtos(self.s.origin));
return;
}
self.item = FindItemByClassname(st.item);
if (!self.item)
{
gi.dprintf("item %s not found for trigger_key at %s\n", st.item, vtos(self.s.origin));
return;
}
if (!self.target)
{
gi.dprintf("%s at %s has no target\n", self.classname, vtos(self.s.origin));
return;
}
gi.soundindex("misc/keytry.wav");
gi.soundindex("misc/keyuse.wav");
self.use = trigger_key_use;
}
#endif
/*
==============================================================================
trigger_counter
==============================================================================
*/
/*QUAKED trigger_counter (.5 .5 .5) ? nomessage
Acts as an intermediary for an action that takes multiple inputs.
If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
*/
static void(entity self, entity other, entity cactivator) trigger_counter_use =
{
if (self.count == 0)
return;
self.count--;
if (self.count) {
if (!(self.spawnflags & 1)) {
gi.centerprintf(cactivator, "%i more to go...", self.count);
gi.sound(cactivator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
}
return;
}
if (!(self.spawnflags & 1)) {
gi.centerprintf(cactivator, "Sequence completed!");
gi.sound(cactivator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
}
self.activator = cactivator;
multi_trigger(self);
}
API_FUNC static void(entity self) SP_trigger_counter =
{
self.wait = -1f;
if (!self.count)
self.count = 2;
self.use = trigger_counter_use;
}
/*
==============================================================================
trigger_always
==============================================================================
*/
/*QUAKED trigger_always (.5 .5 .5) (-8 -8 -8) (8 8 8)
This trigger will always fire. It is activated by the world.
*/
API_FUNC static void(entity ent) SP_trigger_always
{
// we must have some delay to make sure our use targets are present
if (ent.delay < 0.2f)
ent.delay = 0.2f;
G_UseTargets(ent, ent);
}
/*
==============================================================================
trigger_push
==============================================================================
*/
enumflags : int
{
PUSH_ONCE,
PUSH_START_OFF,
PUSH_SILENT,
};
PROGS_LOCAL_STATIC int windsound;
static void(entity self, entity other, vector plane, csurface_t surf) trigger_push_touch =
{
if (other.classname == "grenade") {
other.velocity = self.movedir * (self.speed * 10);
} else if (other.health > 0) {
other.velocity = self.movedir * (self.speed * 10);
if (other.is_client) {
// don't take falling damage immediately from this
other.client.oldvelocity = other.velocity;
if (
#ifdef GROUND_ZERO
!(self.spawnflags & PUSH_SILENT) &&
#endif
other.fly_sound_debounce_framenum < level.framenum)
{
other.fly_sound_debounce_framenum = level.framenum + (int)(1.5f * BASE_FRAMERATE);
gi.sound(other, CHAN_AUTO, windsound, 1, ATTN_NORM, 0);
}
}
}
if (self.spawnflags & PUSH_ONCE)
G_FreeEdict(self);
}
#ifdef GROUND_ZERO
static void(entity self, entity other, entity cactivator) trigger_push_use =
{
if (self.solid == SOLID_NOT)
self.solid = SOLID_TRIGGER;
else
self.solid = SOLID_NOT;
gi.linkentity (self);
}
#endif
#ifdef THE_RECKONING
static void(entity self) trigger_effect =
{
vector origin;
int i;
origin = self.absmin + (self.size * 0.5);
for (i=0; i<10; i++)
{
origin[2] += (self.speed * 0.01f) * (i + random());
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_TUNNEL_SPARKS);
gi.WriteByte (1);
gi.WritePosition (origin);
gi.WriteDir (vec3_origin);
gi.WriteByte (0x74 + (Q_rand()&7));
gi.multicast (self.s.origin, MULTICAST_PVS);
}
}
static void(entity self) trigger_push_active;
static void(entity self) trigger_push_inactive =
{
if (self.delay > level.time)
{
self.nextthink = level.framenum + 1;
}
else
{
self.touch = trigger_push_touch;
self.think = trigger_push_active;
self.nextthink = level.framenum + 1;
self.delay = self.nextthink + self.wait;
}
}
static void(entity self) trigger_push_active =
{
if (self.delay > level.time)
{
self.nextthink = level.framenum + 1;
trigger_effect (self);
}
else
{
self.touch = 0;
self.think = trigger_push_inactive;
self.nextthink = level.framenum + 1;
self.delay = self.nextthink + self.wait;
}
}
#endif
/*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
Pushes the player
"speed" defaults to 1000
*/
API_FUNC static void(entity self) SP_trigger_push =
{
InitTrigger(self);
windsound = gi.soundindex("misc/windfly.wav");
self.touch = trigger_push_touch;
#ifdef GROUND_ZERO
if (self.targetname) // toggleable
{
self.use = trigger_push_use;
if (self.spawnflags & PUSH_START_OFF)
self.solid = SOLID_NOT;
}
#endif
#ifdef THE_RECKONING
#ifdef GROUND_ZERO
else
#endif
if (self.spawnflags & 2)
{
if (!self.wait)
self.wait = 10f;
self.think = trigger_push_active;
self.nextthink = level.framenum + 1;
self.delay = self.nextthink + self.wait;
}
#endif
if (!self.speed)
self.speed = 1000f;
gi.linkentity(self);
}
/*
==============================================================================
trigger_hurt
==============================================================================
*/
/*QUAKED trigger_hurt (.5 .5 .5) ? START_OFF TOGGLE SILENT NO_PROTECTION SLOW
Any entity that touches this will be hurt.
It does dmg points of damage each server frame
SILENT supresses playing the sound
SLOW changes the damage rate to once per second
NO_PROTECTION *nothing* stops the damage
"dmg" default 5 (whole numbers only)
*/
static void(entity self, entity other, entity cactivator) hurt_use =
{
if (self.solid == SOLID_NOT)
self.solid = SOLID_TRIGGER;
else
self.solid = SOLID_NOT;
gi.linkentity(self);
if (!(self.spawnflags & 2))
self.use = 0;
}
static void(entity self, entity other, vector plane, csurface_t surf) hurt_touch =
{
int dflags;
if (!other.takedamage)
return;
if (self.timestamp > level.framenum)
return;
if (self.spawnflags & 16)
self.timestamp = level.framenum + 1 * BASE_FRAMERATE;
else
self.timestamp = level.framenum + 1;
if (!(self.spawnflags & 4)) {
if ((level.framenum % 10) == 0)
gi.sound(other, CHAN_AUTO, self.noise_index, 1, ATTN_NORM, 0);
}
if (self.spawnflags & 8)
dflags = DAMAGE_NO_PROTECTION;
else
dflags = 0;
T_Damage(other, self, self, vec3_origin, other.s.origin, vec3_origin, self.dmg, self.dmg, dflags, MOD_TRIGGER_HURT);
}
API_FUNC static void(entity self) SP_trigger_hurt =
{
InitTrigger(self);
self.noise_index = gi.soundindex("world/electro.wav");
self.touch = hurt_touch;
if (!self.dmg)
self.dmg = 5;
if (self.spawnflags & 1)
self.solid = SOLID_NOT;
else
self.solid = SOLID_TRIGGER;
if (self.spawnflags & 2)
self.use = hurt_use;
gi.linkentity(self);
}
/*
==============================================================================
trigger_gravity
==============================================================================
*/
/*QUAKED trigger_gravity (.5 .5 .5) ?
Changes the touching entites gravity to
the value of "gravity". 1.0 is standard
gravity for the level.
*/
#ifdef GROUND_ZERO
static void(entity self, entity other, entity cactivator) trigger_gravity_use =
{
if (self.solid == SOLID_NOT)
self.solid = SOLID_TRIGGER;
else
self.solid = SOLID_NOT;
gi.linkentity (self);
}
#endif
static void(entity self, entity other, vector plane, csurface_t surf) trigger_gravity_touch =
{
other.gravity = self.gravity;
}
API_FUNC static void(entity self) SP_trigger_gravity =
{
if (!st.gravity) {
gi.dprintf("trigger_gravity without gravity set at %s\n", vtos(self.s.origin));
G_FreeEdict(self);
return;
}
InitTrigger(self);
self.gravity = stof(st.gravity);
#ifdef GROUND_ZERO
if(self.spawnflags & 1) // TOGGLE
self.use = trigger_gravity_use;
if(self.spawnflags & 2) // START_OFF
{
self.use = trigger_gravity_use;
self.solid = SOLID_NOT;
}
#endif
self.touch = trigger_gravity_touch;
gi.linkentity(self);
}
#ifdef SINGLE_PLAYER
/*
==============================================================================
trigger_monsterjump
==============================================================================
*/
/*QUAKED trigger_monsterjump (.5 .5 .5) ?
Walking monsters that touch this will jump in the direction of the trigger's angle
"speed" default to 200, the speed thrown forward
"height" default to 200, the speed thrown upwards
*/
static void(entity self, entity other, vector plane, csurface_t surf) trigger_monsterjump_touch =
{
if (other.flags & (FL_FLY | FL_SWIM))
return;
if (other.svflags & SVF_DEADMONSTER)
return;
if (!(other.svflags & SVF_MONSTER))
return;
// set XY even if not on ground, so the jump will clear lips
other.velocity.x = self.movedir.x * self.speed;
other.velocity.y = self.movedir.y * self.speed;
if (other.groundentity == null_entity)
return;
other.groundentity = null_entity;
other.velocity.z = self.movedir.z;
}
API_FUNC static void(entity self) SP_trigger_monsterjump =
{
if (!self.speed)
self.speed = 200f;
if (!st.height)
st.height = 200;
if (self.s.angles[YAW] == 0)
self.s.angles[YAW] = 360f;
InitTrigger(self);
self.touch = trigger_monsterjump_touch;
self.movedir.z = (float)st.height;
}
#endif