-
Notifications
You must be signed in to change notification settings - Fork 2
/
func.qc
2270 lines (1856 loc) · 55.6 KB
/
func.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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
=========================================================
PLATS
movement options:
linear
smooth start, hard stop
smooth start, smooth stop
start
end
acceleration
speed
deceleration
begin sound
end sound
target fired when reaching end
wait at end
object characteristics that use move segments
---------------------------------------------
movetype_push, or movetype_stop
action when touched
action when blocked
action when used
disabled?
auto trigger spawning
=========================================================
*/
const int PLAT_LOW_TRIGGER = 1;
const int DOOR_START_OPEN = 1;
const int DOOR_REVERSE = 2;
const int DOOR_CRUSHER = 4;
const int DOOR_NOMONSTER = 8;
const int DOOR_TOGGLE = 32;
const int DOOR_X_AXIS = 64;
const int DOOR_Y_AXIS = 128;
const int DOOR_INACTIVE = 8192;
//
// Support routines for movement (changes in origin using velocity)
//
static void(entity ent) Move_Done =
{
ent.velocity = vec3_origin;
ent.moveinfo.endfunc(ent);
}
static void(entity ent) Move_Final =
{
if (ent.moveinfo.remaining_distance == 0) {
Move_Done(ent);
return;
}
ent.velocity = ent.moveinfo.dir * (ent.moveinfo.remaining_distance / FRAMETIME);
ent.think = Move_Done;
ent.nextthink = level.framenum + 1;
}
static void(entity ent) Move_Begin =
{
float frames;
if ((ent.moveinfo.speed * FRAMETIME) >= ent.moveinfo.remaining_distance) {
Move_Final(ent);
return;
}
ent.velocity = ent.moveinfo.dir * ent.moveinfo.speed;
frames = floor((ent.moveinfo.remaining_distance / ent.moveinfo.speed) / FRAMETIME);
ent.moveinfo.remaining_distance -= frames * ent.moveinfo.speed * FRAMETIME;
ent.nextthink = level.framenum + (int)frames;
ent.think = Move_Final;
}
// from func.qc
static void(entity ent) Think_AccelMove;
static void(entity ent) plat_CalcAcceleratedMove;
void(entity ent, vector dest, void(entity) func) Move_Calc =
{
ent.velocity = vec3_origin;
ent.moveinfo.dir = dest - ent.s.origin;
ent.moveinfo.remaining_distance = VectorNormalize(ent.moveinfo.dir);
ent.moveinfo.endfunc = func;
if (ent.moveinfo.speed == ent.moveinfo.accel && ent.moveinfo.speed == ent.moveinfo.decel) {
if (level.current_entity == ((ent.flags & FL_TEAMSLAVE) ? ent.teammaster : ent)) {
Move_Begin(ent);
} else {
ent.nextthink = level.framenum + 1;
ent.think = Move_Begin;
}
} else {
// accelerative
plat_CalcAcceleratedMove(ent);
ent.moveinfo.current_speed = 0;
ent.think = Think_AccelMove;
ent.nextthink = level.framenum + 1;
}
}
//
// Support routines for angular movement (changes in angle using avelocity)
//
static void(entity ent) AngleMove_Done =
{
ent.avelocity = vec3_origin;
ent.moveinfo.endfunc(ent);
}
static void(entity ent) AngleMove_Final =
{
vector move;
if (ent.moveinfo.state == STATE_UP)
move = ent.moveinfo.end_angles - ent.s.angles;
else
move = ent.moveinfo.start_angles - ent.s.angles;
if (!move) {
AngleMove_Done(ent);
return;
}
ent.avelocity = move * (1.0f / FRAMETIME);
ent.think = AngleMove_Done;
ent.nextthink = level.framenum + 1;
}
static void(entity ent) AngleMove_Begin =
{
vector destdelta;
float len;
float traveltime;
float frames;
#ifdef GROUND_ZERO
// accelerate as needed
if(ent.moveinfo.speed < ent.speed)
{
ent.moveinfo.speed += ent.accel;
if(ent.moveinfo.speed > ent.speed)
ent.moveinfo.speed = ent.speed;
}
#endif
// set destdelta to the vector needed to move
if (ent.moveinfo.state == STATE_UP)
destdelta = ent.moveinfo.end_angles - ent.s.angles;
else
destdelta = ent.moveinfo.start_angles - ent.s.angles;
// calculate length of vector
len = VectorLength(destdelta);
// divide by speed to get time to reach dest
traveltime = len / ent.moveinfo.speed;
if (traveltime < FRAMETIME) {
AngleMove_Final(ent);
return;
}
frames = floor(traveltime / FRAMETIME);
// scale the destdelta vector by the time spent traveling to get velocity
ent.avelocity = destdelta * (1.0f / traveltime);
#ifdef GROUND_ZERO
// if we're done accelerating, act as a normal rotation
if(ent.moveinfo.speed >= ent.speed)
{
#endif
// set nextthink to trigger a think when dest is reached
ent.nextthink = level.framenum + (int)frames;
ent.think = AngleMove_Final;
#ifdef GROUND_ZERO
}
else
{
ent.nextthink = level.framenum + 1;
ent.think = AngleMove_Begin;
}
#endif
}
static void(entity ent, void(entity) func) AngleMove_Calc =
{
ent.avelocity = vec3_origin;
ent.moveinfo.endfunc = func;
#ifdef GROUND_ZERO
// if we're supposed to accelerate, this will tell anglemove_begin to do so
if(ent.accel != ent.speed)
ent.moveinfo.speed = 0;
#endif
if (level.current_entity == ((ent.flags & FL_TEAMSLAVE) ? ent.teammaster : ent))
AngleMove_Begin(ent);
else
{
ent.nextthink = level.framenum + 1;
ent.think = AngleMove_Begin;
}
}
/*
==============
Think_AccelMove
The team has completed a frame of movement, so
change the speed for the next frame
==============
*/
#define AccelerationDistance(target, rate) (target * ((target / rate) + 1) / 2)
static void(entity ent) plat_CalcAcceleratedMove =
{
float accel_dist;
float decel_dist;
ent.moveinfo.move_speed = ent.moveinfo.speed;
if (ent.moveinfo.remaining_distance < ent.moveinfo.accel) {
ent.moveinfo.current_speed = ent.moveinfo.remaining_distance;
return;
}
accel_dist = AccelerationDistance(ent.moveinfo.speed, ent.moveinfo.accel);
decel_dist = AccelerationDistance(ent.moveinfo.speed, ent.moveinfo.decel);
if ((ent.moveinfo.remaining_distance - accel_dist - decel_dist) < 0) {
float f;
f = (ent.moveinfo.accel + ent.moveinfo.decel) / (ent.moveinfo.accel * ent.moveinfo.decel);
ent.moveinfo.move_speed = (-2 + sqrt(4 - 4 * f * (-2 * ent.moveinfo.remaining_distance))) / (2 * f);
decel_dist = AccelerationDistance(ent.moveinfo.move_speed, ent.moveinfo.decel);
}
ent.moveinfo.decel_distance = decel_dist;
}
static void(entity ent) plat_Accelerate =
{
// are we decelerating?
if (ent.moveinfo.remaining_distance <= ent.moveinfo.decel_distance) {
if (ent.moveinfo.remaining_distance < ent.moveinfo.decel_distance) {
if (ent.moveinfo.next_speed) {
ent.moveinfo.current_speed = ent.moveinfo.next_speed;
ent.moveinfo.next_speed = 0;
return;
}
if (ent.moveinfo.current_speed > ent.moveinfo.decel)
ent.moveinfo.current_speed -= ent.moveinfo.decel;
}
return;
}
// are we at full speed and need to start decelerating during this move?
if (ent.moveinfo.current_speed == ent.moveinfo.move_speed)
if ((ent.moveinfo.remaining_distance - ent.moveinfo.current_speed) < ent.moveinfo.decel_distance) {
float p1_distance;
float p2_distance;
float distance;
p1_distance = ent.moveinfo.remaining_distance - ent.moveinfo.decel_distance;
p2_distance = ent.moveinfo.move_speed * (1.0f - (p1_distance / ent.moveinfo.move_speed));
distance = p1_distance + p2_distance;
ent.moveinfo.current_speed = ent.moveinfo.move_speed;
ent.moveinfo.next_speed = ent.moveinfo.move_speed - ent.moveinfo.decel * (p2_distance / distance);
return;
}
// are we accelerating?
if (ent.moveinfo.current_speed < ent.moveinfo.speed) {
float old_speed;
float p1_distance;
float p1_speed;
float p2_distance;
float distance;
old_speed = ent.moveinfo.current_speed;
// figure simple acceleration up to move_speed
ent.moveinfo.current_speed += ent.moveinfo.accel;
if (ent.moveinfo.current_speed > ent.moveinfo.speed)
ent.moveinfo.current_speed = ent.moveinfo.speed;
// are we accelerating throughout this entire move?
if ((ent.moveinfo.remaining_distance - ent.moveinfo.current_speed) >= ent.moveinfo.decel_distance)
return;
// during this move we will accelrate from current_speed to move_speed
// and cross over the decel_distance; figure the average speed for the
// entire move
p1_distance = ent.moveinfo.remaining_distance - ent.moveinfo.decel_distance;
p1_speed = (old_speed + ent.moveinfo.move_speed) / 2.0f;
p2_distance = ent.moveinfo.move_speed * (1.0f - (p1_distance / p1_speed));
distance = p1_distance + p2_distance;
ent.moveinfo.current_speed = (p1_speed * (p1_distance / distance)) + (ent.moveinfo.move_speed * (p2_distance / distance));
ent.moveinfo.next_speed = ent.moveinfo.move_speed - ent.moveinfo.decel * (p2_distance / distance);
return;
}
// we are at constant velocity (move_speed)
}
static void(entity ent) Think_AccelMove =
{
ent.moveinfo.remaining_distance -= ent.moveinfo.current_speed;
//plat_CalcAcceleratedMove(ent);
plat_Accelerate(ent);
// will the entire move complete on next frame?
if (ent.moveinfo.remaining_distance <= ent.moveinfo.current_speed) {
Move_Final(ent);
return;
}
ent.velocity = ent.moveinfo.dir * (ent.moveinfo.current_speed * 10);
ent.nextthink = level.framenum + 1;
ent.think = Think_AccelMove;
}
static void(entity ent) plat_go_down;
static void(entity ent) plat_hit_top =
{
if (!(ent.flags & FL_TEAMSLAVE)) {
if (ent.moveinfo.sound_end)
gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent.moveinfo.sound_end, 1, ATTN_STATIC, 0);
ent.s.sound = 0;
}
ent.moveinfo.state = STATE_TOP;
ent.think = plat_go_down;
ent.nextthink = level.framenum + 3 * BASE_FRAMERATE;
}
#if defined(GROUND_ZERO) && defined(SINGLE_PLAYER)
void(entity ent) plat2_kill_danger_area;
void(entity ent) plat2_spawn_danger_area;
#endif
static void(entity ent) plat_hit_bottom =
{
if (!(ent.flags & FL_TEAMSLAVE)) {
if (ent.moveinfo.sound_end)
gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent.moveinfo.sound_end, 1, ATTN_STATIC, 0);
ent.s.sound = 0;
}
ent.moveinfo.state = STATE_BOTTOM;
#if defined(GROUND_ZERO) && defined(SINGLE_PLAYER)
plat2_kill_danger_area (ent);
#endif
}
static void(entity ent) plat_go_down =
{
if (!(ent.flags & FL_TEAMSLAVE)) {
if (ent.moveinfo.sound_start)
gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent.moveinfo.sound_start, 1, ATTN_STATIC, 0);
ent.s.sound = ent.moveinfo.sound_middle;
}
ent.moveinfo.state = STATE_DOWN;
Move_Calc(ent, ent.moveinfo.end_origin, plat_hit_bottom);
#if defined(GROUND_ZERO) && defined(SINGLE_PLAYER)
plat2_spawn_danger_area(ent);
#endif
}
static void(entity ent) plat_go_up =
{
if (!(ent.flags & FL_TEAMSLAVE)) {
if (ent.moveinfo.sound_start)
gi.sound(ent, CHAN_NO_PHS_ADD + CHAN_VOICE, ent.moveinfo.sound_start, 1, ATTN_STATIC, 0);
ent.s.sound = ent.moveinfo.sound_middle;
}
ent.moveinfo.state = STATE_UP;
Move_Calc(ent, ent.moveinfo.start_origin, plat_hit_top);
}
static void(entity self, entity other) plat_blocked =
{
if (!(other.svflags & SVF_MONSTER) && (!other.is_client)) {
// give it a chance to go away on it's own terms (like gibs)
T_Damage(other, self, self, vec3_origin, other.s.origin, vec3_origin, 100000, 1, 0, MOD_CRUSH);
// if it's still there, nuke it
if (other.inuse)
BecomeExplosion1(other);
return;
}
#ifdef GROUND_ZERO
// gib dead things
if(other.health < 1)
T_Damage(other, self, self, vec3_origin, other.s.origin, vec3_origin, 100, 1, 0, MOD_CRUSH);
#endif
T_Damage(other, self, self, vec3_origin, other.s.origin, vec3_origin, self.dmg, 1, 0, MOD_CRUSH);
if (self.moveinfo.state == STATE_UP)
plat_go_down(self);
else if (self.moveinfo.state == STATE_DOWN)
plat_go_up(self);
}
static void(entity ent, entity other, entity cactivator) Use_Plat =
{
#ifdef GROUND_ZERO
// if a monster is using us, then allow the activity when stopped.
if (other.svflags & SVF_MONSTER)
{
if (ent.moveinfo.state == STATE_TOP)
plat_go_down (ent);
else if (ent.moveinfo.state == STATE_BOTTOM)
plat_go_up (ent);
return;
}
#endif
if (ent.think)
return; // already down
plat_go_down(ent);
}
static void(entity ent, entity other, vector plane, csurface_t surf) Touch_Plat_Center =
{
if (!other.is_client)
return;
if (other.health <= 0)
return;
ent = ent.enemy; // now point at the plat, not the trigger
if (ent.moveinfo.state == STATE_BOTTOM)
plat_go_up(ent);
else if (ent.moveinfo.state == STATE_TOP)
ent.nextthink = level.framenum + 1 * BASE_FRAMERATE; // the player is still on the plat, so delay going down
}
entity(entity ent) plat_spawn_inside_trigger =
{
entity trigger;
vector tmin, tmax;
//
// middle trigger
//
trigger = G_Spawn();
trigger.touch = Touch_Plat_Center;
trigger.movetype = MOVETYPE_NONE;
trigger.solid = SOLID_TRIGGER;
trigger.enemy = ent;
tmin.x = ent.mins.x + 25;
tmin.y = ent.mins.y + 25;
tmin.z = ent.mins.z;
tmax.x = ent.maxs.x - 25;
tmax.y = ent.maxs.y - 25;
tmax.z = ent.maxs.z + 8;
tmin.z = tmax.z - (ent.pos1.z - ent.pos2.z + st.lip);
if (ent.spawnflags & PLAT_LOW_TRIGGER)
tmax.z = tmin.z + 8;
if (tmax.x - tmin.x <= 0) {
tmin.x = (ent.mins.x + ent.maxs.x) * 0.5f;
tmax.x = tmin.x + 1;
}
if (tmax.y - tmin.y <= 0) {
tmin.y = (ent.mins.y + ent.maxs.y) * 0.5f;
tmax.y = tmin.y + 1;
}
trigger.mins = tmin;
trigger.maxs = tmax;
gi.linkentity(trigger);
return trigger;
}
/*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER
speed default 150
Plats are always drawn in the extended position, so they will light correctly.
If the plat is the target of another trigger or button, it will start out disabled in the extended position until it is trigger, when it will lower and become a normal plat.
"speed" overrides default 200.
"accel" overrides default 500
"lip" overrides default 8 pixel lip
If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determoveinfoned by the model's height.
Set "sounds" to one of the following:
1) base fast
2) chain slow
*/
API_FUNC static void(entity ent) SP_func_plat =
{
ent.s.angles = vec3_origin;
ent.solid = SOLID_BSP;
ent.movetype = MOVETYPE_PUSH;
gi.setmodel(ent, ent.model);
ent.blocked = plat_blocked;
if (!ent.speed)
ent.speed = 20f;
else
ent.speed *= 0.1f;
if (!ent.accel)
ent.accel = 5f;
else
ent.accel *= 0.1f;
if (!ent.decel)
ent.decel = 5f;
else
ent.decel *= 0.1f;
if (!ent.dmg)
ent.dmg = 2;
if (!st.lip)
st.lip = 8;
// pos1 is the top position, pos2 is the bottom
ent.pos1 = ent.s.origin;
ent.pos2 = ent.s.origin;
if (st.height)
ent.pos2.z -= st.height;
else
ent.pos2.z -= (ent.maxs.z - ent.mins.z) - st.lip;
ent.use = Use_Plat;
plat_spawn_inside_trigger(ent); // the "start moving" trigger
if (ent.targetname) {
ent.moveinfo.state = STATE_UP;
} else {
ent.s.origin = ent.pos2;
gi.linkentity(ent);
ent.moveinfo.state = STATE_BOTTOM;
}
ent.moveinfo.speed = ent.speed;
ent.moveinfo.accel = ent.accel;
ent.moveinfo.decel = ent.decel;
ent.moveinfo.wait = ent.wait;
ent.moveinfo.start_origin = ent.pos1;
ent.moveinfo.start_angles = ent.s.angles;
ent.moveinfo.end_origin = ent.pos2;
ent.moveinfo.end_angles = ent.s.angles;
ent.moveinfo.sound_start = gi.soundindex("plats/pt1_strt.wav");
ent.moveinfo.sound_middle = gi.soundindex("plats/pt1_mid.wav");
ent.moveinfo.sound_end = gi.soundindex("plats/pt1_end.wav");
}
//====================================================================
/*QUAKED func_rotating (0 .5 .8) ? START_ON REVERSE X_AXIS Y_AXIS TOUCH_PAIN STOP ANIMATED ANIMATED_FAST
You need to have an origin brush as part of this entity. The center of that brush will be
the point around which it is rotated. It will rotate around the Z axis by default. You can
check either the X_AXIS or Y_AXIS box to change that.
"speed" determines how fast it moves; default value is 100.
"dmg" damage to inflict when blocked (2 default)
REVERSE will cause the it to rotate in the opposite direction.
STOP mean it will stop moving instead of pushing entities
*/
#ifdef GROUND_ZERO
static void(entity self) rotating_accel =
{
float current_speed;
current_speed = VectorLength (self.avelocity);
if (current_speed >= (self.speed - self.accel)) // done
{
self.avelocity = self.movedir * self.speed;
G_UseTargets (self, self);
}
else
{
current_speed += self.accel;
self.avelocity = self.movedir * current_speed;
self.think = rotating_accel;
self.nextthink = level.framenum + 1;
}
}
static void(entity self) rotating_decel =
{
float current_speed;
current_speed = VectorLength (self.avelocity);
if(current_speed <= self.decel) // done
{
self.avelocity = vec3_origin;
G_UseTargets (self, self);
self.touch = 0;
}
else
{
current_speed -= self.decel;
self.avelocity = self.movedir * current_speed;
self.think = rotating_decel;
self.nextthink = level.framenum + 1;
}
}
#endif
static void(entity self, entity other) rotating_blocked =
{
T_Damage(other, self, self, vec3_origin, other.s.origin, vec3_origin, self.dmg, 1, 0, MOD_CRUSH);
}
static void(entity self, entity other, vector plane, csurface_t surf) rotating_touch =
{
if (self.avelocity)
T_Damage(other, self, self, vec3_origin, other.s.origin, vec3_origin, self.dmg, 1, 0, MOD_CRUSH);
}
static void(entity self, entity other, entity cactivator) rotating_use =
{
if (self.avelocity)
{
self.s.sound = 0;
#ifdef GROUND_ZERO
if(self.spawnflags & 8192) // Decelerate
rotating_decel (self);
else
{
G_UseTargets (self, self);
#endif
self.avelocity = vec3_origin;
self.touch = 0;
#ifdef GROUND_ZERO
}
#endif
}
else
{
self.s.sound = self.moveinfo.sound_middle;
#ifdef GROUND_ZERO
if(self.spawnflags & 8192) // accelerate
rotating_accel (self);
else
{
G_UseTargets (self, self);
#endif
self.avelocity = self.movedir * self.speed;
#ifdef GROUND_ZERO
}
#endif
if (self.spawnflags & 16)
self.touch = rotating_touch;
}
}
API_FUNC static void(entity ent) SP_func_rotating =
{
ent.solid = SOLID_BSP;
if (ent.spawnflags & 32)
ent.movetype = MOVETYPE_STOP;
else
ent.movetype = MOVETYPE_PUSH;
// set the axis of rotation
ent.movedir = vec3_origin;
if (ent.spawnflags & 4)
ent.movedir.z = 1.0f;
else if (ent.spawnflags & 8)
ent.movedir.x = 1.0f;
else // Z_AXIS
ent.movedir.y = 1.0f;
// check for reverse rotation
if (ent.spawnflags & 2)
ent.movedir = -ent.movedir;
if (!ent.speed)
ent.speed = 100f;
if (!ent.dmg)
ent.dmg = 2;
// ent.moveinfo.sound_middle = "doors/hydro1.wav";
ent.use = rotating_use;
if (ent.dmg)
ent.blocked = rotating_blocked;
if (ent.spawnflags & 1)
ent.use(ent, 0, 0);
if (ent.spawnflags & 64)
ent.s.effects |= EF_ANIM_ALL;
if (ent.spawnflags & 128)
ent.s.effects |= EF_ANIM_ALLFAST;
#ifdef GROUND_ZERO
if(ent.spawnflags & 8192) // Accelerate / Decelerate
{
if(!ent.accel)
ent.accel = 1f;
else if (ent.accel > ent.speed)
ent.accel = ent.speed;
if(!ent.decel)
ent.decel = 1f;
else if (ent.decel > ent.speed)
ent.decel = ent.speed;
}
#endif
gi.setmodel(ent, ent.model);
gi.linkentity(ent);
}
/*
======================================================================
BUTTONS
======================================================================
*/
/*QUAKED func_button (0 .5 .8) ?
When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.
"angle" determines the opening direction
"target" all entities with a matching targetname will be used
"speed" override the default 40 speed
"wait" override the default 1 second wait (-1 = never return)
"lip" override the default 4 pixel lip remaining at end of move
"health" if set, the button must be killed instead of touched
"sounds"
1) silent
2) steam metal
3) wooden clunk
4) metallic click
5) in-out
*/
static void(entity self) button_done =
{
self.moveinfo.state = STATE_BOTTOM;
self.s.effects &= ~EF_ANIM23;
self.s.effects |= EF_ANIM01;
}
static void(entity self) button_return =
{
self.moveinfo.state = STATE_DOWN;
Move_Calc(self, self.moveinfo.start_origin, button_done);
self.s.frame = 0;
if (self.health)
self.takedamage = true;
}
static void(entity self) button_wait =
{
self.moveinfo.state = STATE_TOP;
self.s.effects &= ~EF_ANIM01;
self.s.effects |= EF_ANIM23;
G_UseTargets(self, self.activator);
self.s.frame = 1;
if (self.moveinfo.wait >= 0) {
self.nextthink = level.framenum + (int)(self.moveinfo.wait * BASE_FRAMERATE);
self.think = button_return;
}
}
static void(entity self) button_fire =
{
if (self.moveinfo.state == STATE_UP || self.moveinfo.state == STATE_TOP)
return;
self.moveinfo.state = STATE_UP;
if (self.moveinfo.sound_start && !(self.flags & FL_TEAMSLAVE))
gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self.moveinfo.sound_start, 1, ATTN_STATIC, 0);
Move_Calc(self, self.moveinfo.end_origin, button_wait);
}
static void(entity self, entity other, entity cactivator) button_use =
{
self.activator = cactivator;
button_fire(self);
}
static void(entity self, entity other, vector plane, csurface_t surf) button_touch =
{
if (!other.is_client)
return;
if (other.health <= 0)
return;
self.activator = other;
button_fire(self);
}
static void(entity self, entity inflictor, entity attacker, int damage, vector point) button_killed =
{
self.activator = attacker;
self.health = self.max_health;
self.takedamage = false;
button_fire(self);
}
API_FUNC static void(entity ent) SP_func_button =
{
vector abs_movedir;
float dist;
G_SetMovedir(ent.s.angles, ent.movedir);
ent.movetype = MOVETYPE_STOP;
ent.solid = SOLID_BSP;
gi.setmodel(ent, ent.model);
if (ent.sounds != 1)
ent.moveinfo.sound_start = gi.soundindex("switches/butn2.wav");
if (!ent.speed)
ent.speed = 40f;
if (!ent.accel)
ent.accel = ent.speed;
if (!ent.decel)
ent.decel = ent.speed;
if (!ent.wait)
ent.wait = 3f;
if (!st.lip)
st.lip = 4;
ent.pos1 = ent.s.origin;
abs_movedir.x = fabs(ent.movedir.x);
abs_movedir.y = fabs(ent.movedir.y);
abs_movedir.z = fabs(ent.movedir.z);
dist = abs_movedir.x * ent.size.x + abs_movedir.y * ent.size.y + abs_movedir.z * ent.size.z - st.lip;
ent.pos2 = ent.pos1 + (dist * ent.movedir);
ent.use = button_use;
ent.s.effects |= EF_ANIM01;
if (ent.health) {
ent.max_health = ent.health;
ent.die = button_killed;
ent.takedamage = true;
} else if (! ent.targetname)
ent.touch = button_touch;
ent.moveinfo.state = STATE_BOTTOM;
ent.moveinfo.speed = ent.speed;
ent.moveinfo.accel = ent.accel;
ent.moveinfo.decel = ent.decel;
ent.moveinfo.wait = ent.wait;
ent.moveinfo.start_origin = ent.pos1;
ent.moveinfo.start_angles = ent.s.angles;
ent.moveinfo.end_origin = ent.pos2;
ent.moveinfo.end_angles = ent.s.angles;
gi.linkentity(ent);
}
/*
======================================================================
DOORS
spawn a trigger surrounding the entire team unless it is
already targeted by another
======================================================================
*/
/*QUAKED func_door (0 .5 .8) ? START_OPEN x CRUSHER NOMONSTER ANIMATED TOGGLE ANIMATED_FAST
TOGGLE wait in both the start and end states for a trigger event.
START_OPEN the door to moves to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not useful for touch or takedamage doors).
NOMONSTER monsters will not trigger this door
"message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet
"angle" determines the opening direction
"targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.
"health" if set, door must be shot open
"speed" movement speed (100 default)
"wait" wait before returning (3 default, -1 = never return)
"lip" lip remaining at end of move (8 default)
"dmg" damage to inflict when blocked (2 default)
"sounds"
1) silent
2) light
3) medium
4) heavy
*/
static void(entity self, bool open) door_use_areaportals =
{
entity t = world;
if (!self.target)
return;
while ((t = G_Find(t, targetname, self.target)))
if (striequals(t.classname, "func_areaportal"))
gi.SetAreaPortalState(t.style, open);
}
static void(entity self) door_go_down;
static void(entity self) door_hit_top =
{
if (!(self.flags & FL_TEAMSLAVE)) {
if (self.moveinfo.sound_end)
gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self.moveinfo.sound_end, 1, ATTN_STATIC, 0);
self.s.sound = 0;
}
self.moveinfo.state = STATE_TOP;
if (self.spawnflags & DOOR_TOGGLE)
return;
if (self.moveinfo.wait >= 0) {
self.think = door_go_down;
self.nextthink = level.framenum + (int)(self.moveinfo.wait * BASE_FRAMERATE);
}
}
static void(entity self) door_hit_bottom =
{
if (!(self.flags & FL_TEAMSLAVE)) {
if (self.moveinfo.sound_end)
gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self.moveinfo.sound_end, 1, ATTN_STATIC, 0);
self.s.sound = 0;
}
self.moveinfo.state = STATE_BOTTOM;
door_use_areaportals(self, false);
}
static void(entity self) door_go_down =
{
if (!(self.flags & FL_TEAMSLAVE)) {
if (self.moveinfo.sound_start)
gi.sound(self, CHAN_NO_PHS_ADD + CHAN_VOICE, self.moveinfo.sound_start, 1, ATTN_STATIC, 0);
self.s.sound = self.moveinfo.sound_middle;
}
if (self.max_health) {
self.takedamage = true;
self.health = self.max_health;
}
self.moveinfo.state = STATE_DOWN;
if (self.classname == "func_door")
Move_Calc(self, self.moveinfo.start_origin, door_hit_bottom);
else if (self.classname == "func_door_rotating")
AngleMove_Calc(self, door_hit_bottom);
}
static void(entity self, entity cactivator) door_go_up =
{
if (self.moveinfo.state == STATE_UP)
return; // already going up
if (self.moveinfo.state == STATE_TOP) {