-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathg_func.c
3976 lines (3332 loc) · 72.5 KB
/
g_func.c
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
/*
* =======================================================================
*
* Level functions. Platforms, buttons, dooors and so on.
*
* =======================================================================
*/
#include "header/local.h"
#define PLAT_LOW_TRIGGER 1
#define PLAT2_TOGGLE 2
#define PLAT2_TOP 4
#define PLAT2_TRIGGER_TOP 8
#define PLAT2_TRIGGER_BOTTOM 16
#define PLAT2_BOX_LIFT 32
#define STATE_TOP 0
#define STATE_BOTTOM 1
#define STATE_UP 2
#define STATE_DOWN 3
#define DOOR_START_OPEN 1
#define DOOR_REVERSE 2
#define DOOR_CRUSHER 4
#define DOOR_NOMONSTER 8
#define DOOR_TOGGLE 32
#define DOOR_X_AXIS 64
#define DOOR_Y_AXIS 128
#define DOOR_INACTIVE 8192
#define AccelerationDistance(target, rate) (target * ((target / rate) + 1) / 2)
#define PLAT2_CALLED 1
#define PLAT2_MOVING 2
#define PLAT2_WAITING 4
#define TRAIN_START_ON 1
#define TRAIN_TOGGLE 2
#define TRAIN_BLOCK_STOPS 4
#define SECRET_ALWAYS_SHOOT 1
#define SECRET_1ST_LEFT 2
#define SECRET_1ST_DOWN 4
void door_secret_move1(edict_t *self);
void door_secret_move2(edict_t *self);
void door_secret_move3(edict_t *self);
void door_secret_move4(edict_t *self);
void door_secret_move5(edict_t *self);
void door_secret_move6(edict_t *self);
void door_secret_done(edict_t *self);
void train_next(edict_t *self);
void door_go_down(edict_t *self);
void plat2_go_down(edict_t *ent);
void plat2_go_up(edict_t *ent);
void plat2_spawn_danger_area(edict_t *ent);
void plat2_kill_danger_area(edict_t *ent);
void Think_AccelMove(edict_t *ent);
void plat_go_down(edict_t *ent);
/*
* =========================================================
*
* 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
*
*
* =========================================================
*/
/* Support routines for movement (changes in origin using velocity) */
void
Move_Done(edict_t *ent)
{
if (!ent)
{
return;
}
VectorClear(ent->velocity);
ent->moveinfo.endfunc(ent);
}
void
Move_Final(edict_t *ent)
{
if (!ent)
{
return;
}
if (ent->moveinfo.remaining_distance == 0)
{
Move_Done(ent);
return;
}
VectorScale(ent->moveinfo.dir,
ent->moveinfo.remaining_distance / FRAMETIME,
ent->velocity);
ent->think = Move_Done;
ent->nextthink = level.time + FRAMETIME;
}
void
Move_Begin(edict_t *ent)
{
if (!ent)
{
return;
}
float frames;
if ((ent->moveinfo.speed * FRAMETIME) >= ent->moveinfo.remaining_distance)
{
Move_Final(ent);
return;
}
VectorScale(ent->moveinfo.dir, ent->moveinfo.speed, ent->velocity);
frames = floor( (ent->moveinfo.remaining_distance /
ent->moveinfo.speed) / FRAMETIME);
ent->moveinfo.remaining_distance -= frames * ent->moveinfo.speed * FRAMETIME;
ent->nextthink = level.time + (frames * FRAMETIME);
ent->think = Move_Final;
}
void
Move_Calc(edict_t *ent, vec3_t dest, void (*func)(edict_t *))
{
if (!ent || !func)
{
return;
}
VectorClear(ent->velocity);
VectorSubtract(dest, ent->s.origin, ent->moveinfo.dir);
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.time + FRAMETIME;
ent->think = Move_Begin;
}
}
else
{
/* accelerative */
ent->moveinfo.current_speed = 0;
ent->think = Think_AccelMove;
ent->nextthink = level.time + FRAMETIME;
}
}
/* Support routines for angular movement
(changes in angle using avelocity) */
void
AngleMove_Done(edict_t *ent)
{
if (!ent)
{
return;
}
VectorClear(ent->avelocity);
ent->moveinfo.endfunc(ent);
}
void
AngleMove_Final(edict_t *ent)
{
vec3_t move;
if (!ent)
{
return;
}
if (ent->moveinfo.state == STATE_UP)
{
VectorSubtract(ent->moveinfo.end_angles, ent->s.angles, move);
}
else
{
VectorSubtract(ent->moveinfo.start_angles, ent->s.angles, move);
}
if (VectorCompare(move, vec3_origin))
{
AngleMove_Done(ent);
return;
}
VectorScale(move, 1.0 / FRAMETIME, ent->avelocity);
ent->think = AngleMove_Done;
ent->nextthink = level.time + FRAMETIME;
}
void
AngleMove_Begin(edict_t *ent)
{
vec3_t destdelta;
float len;
float traveltime;
float frames;
if (!ent)
{
return;
}
/* 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;
}
}
/* set destdelta to the vector needed to move */
if (ent->moveinfo.state == STATE_UP)
{
VectorSubtract(ent->moveinfo.end_angles, ent->s.angles, destdelta);
}
else
{
VectorSubtract(ent->moveinfo.start_angles, ent->s.angles, destdelta);
}
/* 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 */
VectorScale(destdelta, 1.0 / traveltime, ent->avelocity);
/* if we're done accelerating, act as a normal rotation */
if (ent->moveinfo.speed >= ent->speed)
{
/* set nextthink to trigger a think when dest is reached */
ent->nextthink = level.time + frames * FRAMETIME;
ent->think = AngleMove_Final;
}
else
{
ent->nextthink = level.time + FRAMETIME;
ent->think = AngleMove_Begin;
}
}
void
AngleMove_Calc(edict_t *ent, void (*func)(edict_t *))
{
if (!ent || !func)
{
return;
}
VectorClear(ent->avelocity);
ent->moveinfo.endfunc = func;
/* if we're supposed to accelerate, this will
tell anglemove_begin to do so */
if (ent->accel != ent->speed)
{
ent->moveinfo.speed = 0;
}
if (level.current_entity ==
((ent->flags & FL_TEAMSLAVE) ? ent->teammaster : ent))
{
AngleMove_Begin(ent);
}
else
{
ent->nextthink = level.time + FRAMETIME;
ent->think = AngleMove_Begin;
}
}
/*
* The team has completed a frame of movement, so
* change the speed for the next frame
*/
void
plat_CalcAcceleratedMove(moveinfo_t *moveinfo)
{
float accel_dist;
float decel_dist;
if (!moveinfo)
{
return;
}
moveinfo->move_speed = moveinfo->speed;
if (moveinfo->remaining_distance < moveinfo->accel)
{
moveinfo->current_speed = moveinfo->remaining_distance;
return;
}
accel_dist = AccelerationDistance(moveinfo->speed, moveinfo->accel);
decel_dist = AccelerationDistance(moveinfo->speed, moveinfo->decel);
if ((moveinfo->remaining_distance - accel_dist - decel_dist) < 0)
{
float f;
f = (moveinfo->accel + moveinfo->decel) / (moveinfo->accel * moveinfo->decel);
moveinfo->move_speed = (-2 + sqrt(4 - 4 * f * (-2 * moveinfo->remaining_distance))) / (2 * f);
decel_dist = AccelerationDistance(moveinfo->move_speed, moveinfo->decel);
}
moveinfo->decel_distance = decel_dist;
}
void
plat_Accelerate(moveinfo_t *moveinfo)
{
if (!moveinfo)
{
return;
}
/* are we decelerating? */
if (moveinfo->remaining_distance <= moveinfo->decel_distance)
{
if (moveinfo->remaining_distance < moveinfo->decel_distance)
{
if (moveinfo->next_speed)
{
moveinfo->current_speed = moveinfo->next_speed;
moveinfo->next_speed = 0;
return;
}
if (moveinfo->current_speed > moveinfo->decel)
{
moveinfo->current_speed -= moveinfo->decel;
}
}
return;
}
/* are we at full speed and need to start decelerating during this move? */
if (moveinfo->current_speed == moveinfo->move_speed)
{
if ((moveinfo->remaining_distance - moveinfo->current_speed) <
moveinfo->decel_distance)
{
float p1_distance;
float p2_distance;
float distance;
p1_distance = moveinfo->remaining_distance -
moveinfo->decel_distance;
p2_distance = moveinfo->move_speed *
(1.0 - (p1_distance / moveinfo->move_speed));
distance = p1_distance + p2_distance;
moveinfo->current_speed = moveinfo->move_speed;
moveinfo->next_speed = moveinfo->move_speed - moveinfo->decel *
(p2_distance / distance);
return;
}
}
/* are we accelerating? */
if (moveinfo->current_speed < moveinfo->speed)
{
float old_speed;
float p1_distance;
float p1_speed;
float p2_distance;
float distance;
old_speed = moveinfo->current_speed;
/* figure simple acceleration up to move_speed */
moveinfo->current_speed += moveinfo->accel;
if (moveinfo->current_speed > moveinfo->speed)
{
moveinfo->current_speed = moveinfo->speed;
}
/* are we accelerating throughout this entire move? */
if ((moveinfo->remaining_distance - moveinfo->current_speed) >=
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 = moveinfo->remaining_distance - moveinfo->decel_distance;
p1_speed = (old_speed + moveinfo->move_speed) / 2.0;
p2_distance = moveinfo->move_speed * (1.0 - (p1_distance / p1_speed));
distance = p1_distance + p2_distance;
moveinfo->current_speed = (p1_speed * (p1_distance /
distance)) + (moveinfo->move_speed * (p2_distance / distance));
moveinfo->next_speed = moveinfo->move_speed - moveinfo->decel *
(p2_distance / distance);
return;
}
/* we are at constant velocity (move_speed) */
return;
}
void
Think_AccelMove(edict_t *ent)
{
if (!ent)
{
return;
}
ent->moveinfo.remaining_distance -= ent->moveinfo.current_speed;
plat_CalcAcceleratedMove(&ent->moveinfo);
plat_Accelerate(&ent->moveinfo);
/* will the entire move complete on next frame? */
if (ent->moveinfo.remaining_distance <= ent->moveinfo.current_speed)
{
Move_Final(ent);
return;
}
VectorScale(ent->moveinfo.dir, ent->moveinfo.current_speed * 10,
ent->velocity);
ent->nextthink = level.time + FRAMETIME;
ent->think = Think_AccelMove;
}
void
plat_hit_top(edict_t *ent)
{
if (!ent)
{
return;
}
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.time + 3;
}
void
plat_hit_bottom(edict_t *ent)
{
if (!ent)
{
return;
}
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;
plat2_kill_danger_area(ent);
}
void
plat_go_down(edict_t *ent)
{
if (!ent)
{
return;
}
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);
}
void
plat_go_up(edict_t *ent)
{
if (!ent)
{
return;
}
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);
plat2_spawn_danger_area(ent);
}
void
plat_blocked(edict_t *self, edict_t *other)
{
if (!self || !other)
{
return;
}
if (!(other->svflags & SVF_MONSTER) && (!other->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)
{
/* Hack for entity without it's origin near the model */
VectorMA(other->absmin, 0.5, other->size, other->s.origin);
BecomeExplosion1(other);
}
return;
}
/* gib dead things */
if (other->health < 1)
{
T_Damage(other, self, self, vec3_origin, other->s.origin,
vec3_origin, 100, 1, 0, MOD_CRUSH);
}
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);
}
}
void
Use_Plat(edict_t *ent, edict_t *other, edict_t *activator /* unused */)
{
if (!ent || !other)
{
return;
}
/* 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;
}
if (ent->think)
{
return; /* already down */
}
plat_go_down(ent);
}
void
wait_and_change_think(edict_t* ent)
{
void (*afterwaitfunc)(edict_t *) = ent->moveinfo.endfunc;
ent->moveinfo.endfunc = NULL;
afterwaitfunc(ent);
}
/*
* In coop mode, this waits for coop_elevator_delay seconds
* before calling afterwaitfunc(ent); otherwise it just calls
* afterwaitfunc(ent);
*/
static void
wait_and_change(edict_t* ent, void (*afterwaitfunc)(edict_t *))
{
float waittime = coop_elevator_delay->value;
if (coop->value && waittime > 0.0f)
{
if(ent->nextthink == 0)
{
ent->moveinfo.endfunc = afterwaitfunc;
ent->think = wait_and_change_think;
ent->nextthink = level.time + waittime;
}
}
else
{
afterwaitfunc(ent);
}
}
void
Touch_Plat_Center(edict_t *ent, edict_t *other, cplane_t *plane /* unsed */,
csurface_t *surf /* unused */)
{
if (!ent || !other)
{
return;
}
if (!other->client)
{
return;
}
if (other->health <= 0)
{
return;
}
ent = ent->enemy; /* now point at the plat, not the trigger */
if (ent->moveinfo.state == STATE_BOTTOM)
{
wait_and_change(ent, plat_go_up);
}
else if (ent->moveinfo.state == STATE_TOP)
{
ent->nextthink = level.time + 1; /* the player is still on the plat, so delay going down */
}
}
edict_t *
plat_spawn_inside_trigger(edict_t *ent)
{
edict_t *trigger;
vec3_t tmin, tmax;
if (!ent)
{
return NULL;
}
/* middle trigger */
trigger = G_Spawn();
trigger->touch = Touch_Plat_Center;
trigger->movetype = MOVETYPE_NONE;
trigger->solid = SOLID_TRIGGER;
trigger->enemy = ent;
tmin[0] = ent->mins[0] + 25;
tmin[1] = ent->mins[1] + 25;
tmax[0] = ent->maxs[0] - 25;
tmax[1] = ent->maxs[1] - 25;
tmax[2] = ent->maxs[2] + 8;
tmin[2] = tmax[2] - (ent->pos1[2] - ent->pos2[2] + st.lip);
if (ent->spawnflags & PLAT_LOW_TRIGGER)
{
tmax[2] = tmin[2] + 8;
}
if (tmax[0] - tmin[0] <= 0)
{
tmin[0] = (ent->mins[0] + ent->maxs[0]) * 0.5;
tmax[0] = tmin[0] + 1;
}
if (tmax[1] - tmin[1] <= 0)
{
tmin[1] = (ent->mins[1] + ent->maxs[1]) * 0.5;
tmax[1] = tmin[1] + 1;
}
VectorCopy(tmin, trigger->mins);
VectorCopy(tmax, trigger->maxs);
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
*/
void
SP_func_plat(edict_t *ent)
{
if (!ent)
{
return;
}
VectorClear(ent->s.angles);
ent->solid = SOLID_BSP;
ent->movetype = MOVETYPE_PUSH;
gi.setmodel(ent, ent->model);
ent->blocked = plat_blocked;
if (!ent->speed)
{
ent->speed = 20;
}
else
{
ent->speed *= 0.1;
}
if (!ent->accel)
{
ent->accel = 5;
}
else
{
ent->accel *= 0.1;
}
if (!ent->decel)
{
ent->decel = 5;
}
else
{
ent->decel *= 0.1;
}
if (!ent->dmg)
{
ent->dmg = 2;
}
if (!st.lip)
{
st.lip = 8;
}
/* pos1 is the top position, pos2 is the bottom */
VectorCopy(ent->s.origin, ent->pos1);
VectorCopy(ent->s.origin, ent->pos2);
if (st.height)
{
ent->pos2[2] -= st.height;
}
else
{
ent->pos2[2] -= (ent->maxs[2] - ent->mins[2]) - st.lip;
}
ent->use = Use_Plat;
plat_spawn_inside_trigger(ent); /* the "start moving" trigger */
if (ent->targetname)
{
ent->moveinfo.state = STATE_UP;
}
else
{
VectorCopy(ent->pos2, ent->s.origin);
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;
VectorCopy(ent->pos1, ent->moveinfo.start_origin);
VectorCopy(ent->s.angles, ent->moveinfo.start_angles);
VectorCopy(ent->pos2, ent->moveinfo.end_origin);
VectorCopy(ent->s.angles, ent->moveinfo.end_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");
}
void
plat2_spawn_danger_area(edict_t *ent)
{
if (!ent)
{
return;
}
vec3_t mins, maxs;
VectorCopy(ent->mins, mins);
VectorCopy(ent->maxs, maxs);
maxs[2] = ent->mins[2] + 64;
SpawnBadArea(mins, maxs, 0, ent);
}
void
plat2_kill_danger_area(edict_t *ent)
{
edict_t *t;
if (!ent)
{
return;
}
t = NULL;
while ((t = G_Find(t, FOFS(classname), "bad_area")))
{
if (t->owner == ent)
{
G_FreeEdict(t);
}
}
}
void
plat2_hit_top(edict_t *ent)
{
if (!ent)
{
return;
}
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;
if (ent->plat2flags & PLAT2_CALLED)
{
ent->plat2flags = PLAT2_WAITING;
if (!(ent->spawnflags & PLAT2_TOGGLE))
{
ent->think = plat2_go_down;
ent->nextthink = level.time + 5.0;
}
if (deathmatch->value)
{
ent->last_move_time = level.time - 1.0;
}
else
{
ent->last_move_time = level.time - 2.0;
}
}
else if (!(ent->spawnflags & PLAT2_TOP) &&
!(ent->spawnflags & PLAT2_TOGGLE))
{
ent->plat2flags = 0;
ent->think = plat2_go_down;
ent->nextthink = level.time + 2.0;
ent->last_move_time = level.time;
}
else
{
ent->plat2flags = 0;
ent->last_move_time = level.time;
}
G_UseTargets(ent, ent);
}
void
plat2_hit_bottom(edict_t *ent)
{
if (!ent)