forked from itslunaranyo/copper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doors.qc
1284 lines (1107 loc) · 32.6 KB
/
doors.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
/*
=============================================================================
Doors are similar to buttons, but can spawn a fat trigger field around them
to open without a touch, and they link together to form simultaneous
double/quad doors.
Door.owner is the master door. If there is only one door, it points to itself.
If multiple doors, all will point to a single one.
Door.enemy chains from the master door through all doors linked in the chain.
=============================================================================
*/
float DOOR_START_OPEN = 1;
float DOOR_SPECIAL = 2;
float DOOR_DONT_LINK = 4;
float DOOR_GOLD_KEY = 8;
float DOOR_SILVER_KEY = 16;
float DOOR_TOGGLE = 32;
float DOOR_CRUSHER = 64;
/*
=============================================================================
THINK FUNCTIONS
=============================================================================
*/
void() door_blocked =
{
T_Damage (other, self, self, self.dmg, DMGTYPE_CRUSH);
// if a door has a negative wait, it would never come back if blocked,
// so let it just squash the object to death real fast
if (self.wait >= 0 && !(self.spawnflags & DOOR_CRUSHER))
{
if (self.state == STATE_DOWN)
door_go_up ();
else
door_go_down ();
}
}
void() door_hit_top =
{
sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
self.state = STATE_TOP;
SUB_UseTargetsAlt(target2);
if (self.spawnflags & DOOR_TOGGLE)
return; // don't come down automatically
self.think = door_go_down;
self.nextthink = self.ltime + self.wait;
}
void() door_hit_bottom =
{
sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
self.frame = self.skin;
self.state = STATE_BOTTOM;
SUB_UseTargetsAlt(target4);
}
void() door_go_down =
{
//dprint("door_go_down\n");
sound (self, CHAN_VOICE, self.noise2, 1, ATTN_NORM);
if (self.max_health)
{
self.takedamage = DAMAGE_YES;
self.health = self.max_health;
}
self.state = STATE_DOWN;
SUB_CalcMoveLight(self.pos2, self.pos1, self.speed2, door_hit_bottom, TRUE);
SUB_UseTargetsAlt(target3);
}
void() door_go_up =
{
//dprint("door_go_up\n");
if (self.state == STATE_UP)
return; // already going up
if (self.state == STATE_TOP)
{ // reset top wait time
if (self.spawnflags & DOOR_TOGGLE)
return; // don't come down automatically
self.nextthink = self.ltime + self.wait;
return;
}
sound (self, CHAN_VOICE, self.noise2, 1, ATTN_NORM);
self.state = STATE_UP;
SUB_CalcMoveLight(self.pos1, self.pos2, self.speed, door_hit_top, FALSE);
self.frame = !self.skin;
if (!SUB_UseTargetsAlt(target))
SUB_UseTargetsSilent(); // door messages are for when they *don't* open
}
/*
=============================================================================
ACTIVATION FUNCTIONS
=============================================================================
*/
void() door_fire =
{
local entity oself;
local entity starte;
//dprint("door_fire\n");
if (self.owner != self)
objerror ("door_fire: self.owner != self");
// play use key sound
if (self.items)
sound (self, CHAN_BODY, self.noise4, 1, ATTN_NORM); // was chan_voice, door move sound was cutting it off
if (!( self.spawnflags & DOOR_TOGGLE ) )
{
self.message = string_null; // no more message
}
else
{
oself = self;
if (self.state == STATE_TOP || self.state == STATE_UP )
{
starte = self;
do {
door_go_down ();
self = self.enemy;
} while ( (self != starte) && (self != world) );
self = oself;
return;
}
}
// trigger all paired doors
starte = self;
if ( !( self.spawnflags & DOOR_TOGGLE ) ||
( self.spawnflags & DOOR_TOGGLE && (self.state == STATE_BOTTOM || self.state == STATE_DOWN) ) )
do {
door_go_up ();
self = self.enemy;
} while ( (self != starte) && (self != world) );
self = oself;
}
void() door_use =
{
//dprint("door_use\n");
if (self.customflags & CFL_LOCKED) return;
if (!( self.spawnflags & DOOR_TOGGLE ) )
{
self.message = string_null; // door message are for touch only
self.owner.message = string_null;
self.enemy.message = string_null;
}
self.takedamage = DAMAGE_NO; // wil be reset upon return
SUB_CallAsSelf(door_fire,self.owner);
}
void() door_trigger_touch =
{
if (other.health <= 0) return;
if (other.movetype == MOVETYPE_NOCLIP) return;
if (time < self.attack_finished) return;
// silly fix for sleeping monsters standing behind doors inside their touch fields causing them to open
if (other.flags & FL_MONSTER && other.enemy == world && other.goalentity == world) return;
self.attack_finished = time + 1;
activator = other;
self = self.owner;
door_use ();
}
void() door_killed =
{
local entity oself;
oself = self;
self = self.owner;
self.health = self.max_health;
door_use ();
self = oself;
}
void(entity d) door_force =
{
entity od;
od = d.owner;
do {
od.items = 0;
od = od.enemy;
} while (od != d);
SUB_CallAsSelf(door_fire,d.owner);
}
/*
================
door_touch
Prints messages and opens key doors
================
*/
void() door_touch =
{
if (!CheckValidTouch()) return;
self = self.owner;
if (self.attack_finished > time)
return;
self.attack_finished = time + 1;
if (self.message != string_null && self.state == STATE_BOTTOM && !(self.items))
{
centerprint (other, self.message);
sound (other, CHAN_VOICE, self.noise3, 1, ATTN_NORM);
}
// from here on is key door stuff
if (!self.items)
return;
// key doors don't spawn trigger fields, so door_touch does a lot of what door_trigger_touch does
if ( (self.items & other.items) != self.items || self.customflags & CFL_LOCKED )
{
centerprint (other, self.owner.message);
sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM);
return;
}
if (self.items & IT_KEY1)
{
key_take_silver(other);
}
else if (self.items & IT_KEY2)
{
key_take_gold(other);
}
else
{
other.items = other.items - self.items;
}
self.touch = SUB_Null;
entity t = self.enemy;
while (t != self)// get paired doors
{
t.touch = SUB_Null;
t = t.enemy;
}
activator = other;
door_use ();
}
void(float unlock) door_lock =
{
entity c;
//dprint("door_lock\n");
if (unlock) door_unlock_do(self);
else door_lock_do(self);
// inner loop checks for doors that are linked by touch and not targetname
c = self.enemy;
do {
if (c.targetname != self.targetname) // outer loop will find this one
if (unlock) door_unlock_do(c);
else door_lock_do(c);
c = c.enemy;
} while (c != self);
}
void(entity d) door_lock_do =
{
//dprint("door_lock_do\n");
entity e;
if (d.customflags & CFL_LOCKED)
return;
d.customflags = d.customflags | CFL_LOCKED;
// close any open doors immediately
if (d.state != STATE_BOTTOM && !(d.spawnflags & DOOR_TOGGLE || d.wait == -1))
{
e = d;
do {
SUB_CallAsSelf(door_go_down,e);
e = e.enemy;
}
while ( e != d && e != world );
}
if (d.max_health)
{
d.takedamage = DAMAGE_NO;
}
else
{
/*if (d.owner.trigger_field == world && !d.owner.items && !(d.spawnflags & DOOR_TOGGLE))
objerror("door being locked doesn't have a trigger");
else*/ if (d.owner.trigger_field)
d.owner.trigger_field.touch = SUB_Null;
}
}
void(entity d) door_unlock_do =
{
//dprint("door_unlock_do\n");
if (!(d.customflags & CFL_LOCKED))
return;
d.customflags = not(d.customflags, CFL_LOCKED);
if (d.max_health)
{
d.takedamage = DAMAGE_YES;
d.health = d.max_health;
}
else
{
/*if (d.owner.trigger_field == world && !d.owner.items && !(d.spawnflags & DOOR_TOGGLE))
objerror("door being unlocked doesn't have a trigger");
else*/ if (d.owner.trigger_field)
d.owner.trigger_field.touch = door_trigger_touch;
}
}
// checks if a door ONLY has locks targeting it
float(entity d) door_getslocked =
{
if (d.targetname == string_null)
return FALSE;
entity t;
float found = FALSE;
t = find(world, target, d.targetname);
while (t) {
found = TRUE;
if (t.classname != "target_lock") return FALSE;
t = find(t, target, d.targetname);
}
t = find(world, target2, d.targetname);
while (t) {
found = TRUE;
if (t.classname != "target_lock") return FALSE;
t = find(t, target2, d.targetname);
}
t = find(world, target3, d.targetname);
while (t) {
found = TRUE;
if (t.classname != "target_lock") return FALSE;
t = find(t, target3, d.targetname);
}
t = find(world, target4, d.targetname);
while (t) {
found = TRUE;
if (t.classname != "target_lock") return FALSE;
t = find(t, target4, d.targetname);
}
return found; // no targeters has to be FALSE
}
/*
=============================================================================
SPAWNING FUNCTIONS
=============================================================================
*/
entity(vector fmins, vector fmaxs) door_spawn_field =
{
local entity trigger;
local vector t1, t2;
//dprint("spawning door field\n");
trigger = spawn();
trigger.movetype = MOVETYPE_NONE;
trigger.solid = SOLID_TRIGGER;
trigger.owner = self;
trigger.touch = door_trigger_touch;
t1 = fmins;
t2 = fmaxs;
setsize (trigger, t1 - '60 60 8', t2 + '60 60 8');
return (trigger);
}
void(vector cmins, vector cmaxs) door_finalize =
{
entity t;
// switch positions after linking so START_OPEN doors link properly
t = self;
do {
// DOOR_START_OPEN is to allow an entity to be lighted in the closed position
// but spawn in the open position
if (t.spawnflags & DOOR_START_OPEN)
{
setorigin (t, t.pos2);
t.pos2 = t.pos1;
t.pos1 = t.origin;
}
t = t.enemy;
} while (t != self);
if (self.items)
{
door_key_init();
return;
}
if (self.style < 0)
{
self.style *= -1;
self.customflags |= CFL_INVLIGHT;
}
if (self.spawnflags & DOOR_START_OPEN)
{
if (self.customflags & CFL_INVLIGHT)
self.customflags -= CFL_INVLIGHT;
else
self.customflags |= CFL_INVLIGHT;
}
bmodel_lightstyle(self, 1);
if (self.health)
return;
if (self.targetname != string_null)
if (!door_getslocked(self) || self.spawnflags & DOOR_TOGGLE)
return;
self.trigger_field = door_spawn_field(cmins, cmaxs);
if (self.customflags & CFL_LOCKED)
door_lock(FALSE);
}
float(entity door, entity master) door_can_link =
{
if (door == master) return TRUE; // first door
if (door.enemy) return FALSE; // already linked
if (door.spawnflags & DOOR_DONT_LINK) return FALSE; // will finalize itself later
if (door.targetname != string_null && master.targetname != string_null && master.targetname != door.targetname)
return FALSE; // part of different systems, might only touch coincidentally
if (door.items && master.items && !(master.items & door.items))
return FALSE; // different items requirements
return TRUE;
}
/*
=============
door_link
=============
*/
void() door_link =
{
entity t, masterdoor;
vector cmins, cmaxs;
if (self.enemy)
return; // already linked by another door
if (self.spawnflags & DOOR_DONT_LINK)
{
self.owner = self.enemy = self;
door_finalize(self.mins, self.maxs);
return; // don't want to link this door
}
cmins = self.mins;
cmaxs = self.maxs;
masterdoor = self;
t = self;
do
{
self.owner = masterdoor;
if (self != masterdoor)
{
if ((self.targetname != string_null && masterdoor.targetname == string_null) ||
self.targetname == masterdoor.targetname)
{
// all the doors in the chain having the same targetname will cause
// the whole chain to be triggered once for every door in the chain
masterdoor.targetname = self.targetname;
self.targetname = string_null;
}
if (self.items) // keylocked
{
masterdoor.items |= self.items;
masterdoor.noise3 = self.noise3;
masterdoor.noise4 = self.noise4;
}
if (self.health != 0 && masterdoor.health == 0)
masterdoor.health = self.health;
SUB_MergeTargets(masterdoor);
self.target = string_null;
self.target2 = string_null;
self.target3 = string_null;
self.target4 = string_null;
self.killtarget = string_null;
if (self.message != string_null && masterdoor.message == string_null)
masterdoor.message = self.message;
}
// skip doors with other targetnames to not fold them into the loop
do {
t = find (t, classname, self.classname);
} while (t && (!door_can_link(t,masterdoor) || !EntitiesTouching(self,t)));
if (!t)
{
self.enemy = masterdoor; // make the chain a loop
self = self.owner;
door_finalize(cmins, cmaxs);
return;
}
self.enemy = t;
self = t;
cmins_x = min(t.mins_x, cmins_x);
cmins_y = min(t.mins_y, cmins_y);
cmins_z = min(t.mins_z, cmins_z);
cmaxs_x = max(t.maxs_x, cmaxs_x);
cmaxs_y = max(t.maxs_y, cmaxs_y);
cmaxs_z = max(t.maxs_z, cmaxs_z);
} while (t);
}
void() LinkDoors = {door_link();}
void() door_key_init =
{
if (self.message == string_null)
{
if (self.items & IT_KEY1)
{
if (world.worldtype == 2)
self.message = "You need the Silver Keycard";
else if (world.worldtype == 1)
self.message = "You need the Silver Runekey";
else if (world.worldtype == 0)
self.message = "You need the Silver Key";
}
else if (self.items & IT_KEY2)
{
if (world.worldtype == 2)
self.message = "You need the Gold Keycard";
else if (world.worldtype == 1)
self.message = "You need the Gold Runekey";
else if (world.worldtype == 0)
self.message = "You need the Gold Key";
}
}
if (self.items)
{
if (self.owner != self)
{
self.noise3 = self.owner.noise3;
self.noise4 = self.owner.noise4;
}
entity t = self;
do {
t.wait = -1;
t = t.enemy;
} while (t != self);
}
}
// always let specific noise fields on a door override 'sounds' regardless
// of number - maps that use custom door sounds can use 'sounds 5' to skip
// the sound code as a hack, but the sounds menu is longer in copper
void(.string nois, string path) door_set_sound =
{
if (self.nois == string_null) self.nois = path;
}
void() door_sounds_init =
{
if (self.items & (IT_KEY1 | IT_KEY2))
{
if (world.worldtype == 1)
{
door_set_sound(noise3, "doors/runetry.wav");
door_set_sound(noise4, "doors/runeuse.wav");
}
else if (world.worldtype == 2)
{
door_set_sound(noise3, "doors/basetry.wav");
door_set_sound(noise4, "doors/baseuse.wav");
}
else
{
door_set_sound(noise3, "doors/medtry.wav");
door_set_sound(noise4, "doors/meduse.wav");
}
}
else
{
if (world.worldtype == 2)
{
door_set_sound(noise3, "doors/locked5.wav");
}
else
{
door_set_sound(noise3, "doors/locked4.wav");
}
door_set_sound(noise4, "misc/null.wav");
}
if (self.sounds == 0)
{
door_set_sound(noise1, "misc/null.wav");
door_set_sound(noise2, "misc/null.wav");
}
else if (self.sounds == 1)
{
door_set_sound(noise1, "doors/drclos4.wav");
door_set_sound(noise2, "doors/doormv1.wav");
}
else if (self.sounds == 2)
{
door_set_sound(noise1, "doors/hydro2.wav");
door_set_sound(noise2, "doors/hydro1.wav");
}
else if (self.sounds == 3)
{
door_set_sound(noise1, "doors/stndr2.wav");
door_set_sound(noise2, "doors/stndr1.wav");
}
else if (self.sounds == 4)
{
door_set_sound(noise1, "doors/ddoor2.wav");
door_set_sound(noise2, "doors/ddoor1.wav");
}
else if (self.sounds == 5)
{
door_set_sound(noise1, "doors/drclos4.wav");
door_set_sound(noise2, "doors/winch2.wav");
}
else if (self.sounds == 6)
{
door_set_sound(noise1, "doors/basesec2.wav");
door_set_sound(noise2, "doors/basesec1.wav");
}
precache_sound_safe(self.noise1);
precache_sound_safe(self.noise2);
precache_sound_safe(self.noise3);
precache_sound_safe(self.noise4);
//precache_sound_safe("doors/locked4.wav");
}
/*QUAKED func_door (0 .5 .8) ? START_OPEN ? DONT_LINK GOLD_KEY SILVER_KEY TOGGLE CRUSHER
Door. Opens; closes.
If two doors touch, they are assumed to be connected and operate as a unit. Targets, targetnames, and the Crusher and Toggle spawnflags are safely shared between linked doors automatically.
Doors will not link if either has the "dont_link" spawnflag, if they have different targetnames, or different key requirements.
SPAWNFLAGS
"start_open" causes the door to move to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not usefull for touch or takedamage doors).
"dont_link" don't link to any touching doors
"toggle" causes the door to wait in both the start and end states for a trigger event.
"crusher" do not reverse when blocked
Key doors are always wait -1.
"message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet. if locked, will print this instead of default silver/gold message.
"angle" determines the opening direction
"targetname" if set, no touch field will be spawned and a remote button or trigger activates the door, unless the door is only targeted by a target_lock.
"health" if set, door must be shot open
"speed" movement speed (100 default)
"speed2" make close speed different from open speed
"wait" wait before returning (3 default, -1 = never return)
"lip" lip remaining at end of move (8 default)
"distance" specify movement distance directly, overrides lip (-1 to explicitly not move)
"dmg" damage to inflict when blocked (2 default)
"noise1-4" override stop/open/locked/unlocked sounds, respectively
"sounds"
0) silent
1) stone
2) base
3) stone chain
4) hissy metal
5) winchy secret door
6) base secret door
Alt Target Pattern: 'target' when starting to open, 'target2' when opened, 'target3' when starting to close, 'target4' when closed.
*/
/*FGD
@SolidClass base(Angle, Appearflags, Targetname, Target, Func, FuncInvis, AltTarget) = func_door :
"Door. Opens; closes.
If two doors touch, they are assumed to be connected and operate as a unit. Targets, targetnames, and the Crusher and Toggle spawnflags are safely shared between linked doors automatically.
Doors will not link if either has the 'don't link' spawnflag, if they have different targetnames, or different key requirements.
Alt Target Pattern: 'target' when starting to open, 'target2' when opened, 'target3' when starting to close, 'target4' when closed."
[
speed(integer) : "Speed" : 100
speed2(integer) : "Close Speed (if different from open speed)" : 0
sounds(choices) : "Sound" : 0 =
[
0: "Silent"
1: "Stone"
2: "Machine"
3: "Stone Chain"
4: "Screechy Metal"
5: "Winchy secret door"
6: "Base secret door"
]
noise1(string) : "Override stop sound"
noise2(string) : "Override move sound"
noise3(string) : "Override key-required sound"
noise4(string) : "Override key-unlocked sound"
wait(string) : "Wait before close" : "3"
lip(integer) : "Lip remaining at end of move" : 8
distance(string) : "Distance to travel (overrides Lip)" : "0.0"
dmg(integer) : "Damage inflicted when blocked" : 2
message(string) : "Message printed when the door is touched if it is a trigger door and it hasn't been fired yet. If locked, will print this instead of default silver/gold message."
health(integer) : "Health (shootable)" : 0
targetname(target_source) : "Name. If set, no touch field will be spawned and a remote button or trigger must activates the door, UNLESS the door is only targeted by a target_lock."
spawnflags(flags) =
[
1 : "Starts Open" : 0
4 : "Don't link with touching" : 0
8 : "Gold Key" : 0
16 : "Silver Key" : 0
32 : "Toggle" : 0
64 : "Crusher" : 0
]
]
*/
void() func_door =
{
if (!SUB_ShouldSpawn()) return;
SetMovedir ();
self.max_health = self.health;
//self.classname = "door";
if (!self.speed)
self.speed = 100;
if (!self.speed2)
self.speed2 = self.speed;
self.dmg = zeroconvertdefault(self.dmg, 2);
if (!self.lip)
self.lip = 8;
if (self.spawnflags & DOOR_SILVER_KEY)
{
self.items = IT_KEY1;
self.wait = -1;
}
else if (self.spawnflags & DOOR_GOLD_KEY)
{
self.items = IT_KEY2;
self.wait = -1;
}
door_sounds_init();
//door_key_init();
if (!self.wait)
self.wait = 3;
if (self.spawnflags & 128)
self.use = func_door_spawn;
else
func_door_spawn();
}
void() func_door_spawn =
{
self.solid = SOLID_BSP;
self.movetype = MOVETYPE_PUSH;
setorigin (self, self.origin);
setmodel (self, self.model);
self.distance = zeroconvertdefault(self.distance,
BoundsAngleSize( self.movedir, self.size ) - self.lip);
// ^^ janky for non-cardinal angles
if (self.pos1 && self.pos2)
{
setorigin(self, self.pos1);
}
else
{
self.pos1 = self.origin;
self.pos2 = self.pos1 + self.movedir * self.distance;
}
self.state = STATE_BOTTOM;
if (self.health)
{
self.takedamage = DAMAGE_YES;
self.th_die = door_killed;
}
self.blocked = door_blocked;
self.use = door_use;
self.touch = door_touch;
self.lock = door_lock;
// door_link can't be done until all of the doors have been spawned, so
// the sizes can be detected properly.
if (self.spawnflags & DOOR_DONT_LINK)
{
self.owner = self.enemy = self;
door_finalize(self.mins, self.maxs);
return; // don't want to link this door
}
self.think = door_link;
self.nextthink = self.ltime + 0.1;
}
/*
=============================================================================
SECRET DOORS
=============================================================================
*/
void() secretdoor_move1;
void() secretdoor_move2;
void() secretdoor_move3;
void() secretdoor_move4;
void() secretdoor_move5;
void() secretdoor_move6;
void() secretdoor_done;
float SECRET_OPEN_ONCE = 1; // stays open
float SECRET_1ST_LEFT = 2; // 1st move is left of angle
float SECRET_1ST_DOWN = 4; // 1st move is down from angle
float SECRET_NO_SHOOT = 8; // only opened by trigger
float SECRET_YES_SHOOT = 16; // shootable even if targeted
void () secretdoor_use =
{
self.health = self.max_health;
// enter correct phase of opening if retriggered while moving
if (self.origin != self.oldorigin)
{
secret_door_force(self);
return;
}
self.message = string_null; // no more message
SUB_UseTargetsSilent(); // fire all targets / killtargets
if (!(self.spawnflags & SECRET_NO_SHOOT))
{
// self.th_pain = SUB_Null;
self.takedamage = DAMAGE_NO;
}
self.velocity = '0 0 0';
secretdoor_move0();
}
// hodor correctly depending on what state the door is in
void(entity door) secret_door_force =
{
entity oself;
oself = self;
self = door;
if (self.think == secretdoor_move4) // waiting in open pos, extend timer
{
self.nextthink = self.ltime + self.wait;
}
else if (self.think1 == secretdoor_move5) // 2nd reverse move in progress or done
{
secretdoor_move2(); // restart 2nd open move
}
else if (self.think == secretdoor_move6 || self.origin == self.oldorigin) // 1st reverse move in progress or done
{
secretdoor_move0(); // restart 1st open move
}
self = oself;
}
void(entity attacker, float damage) secretdoor_pain =
{
if (attacker.classname != "player") return; // no monsters opening secrets for you
secretdoor_use();
}
void() secret_shadowmonitor_go =
{
float opac, done;
vector mv, p;
entity o = self.owner;
self.nextthink = time + min(0.05, (o.nextthink - o.ltime));
if (o.think == secretdoor_move2 || o.think == secretdoor_move6)
{
opac = 1;
done = TRUE;
}
else if (o.think == SUB_Null)
{
opac = 0;
if (o.wait == -1)
done = TRUE;
}
else if (o.think == secretdoor_move4)
{
opac = 0;
self.nextthink += o.wait;
}
else
{
mv = o.dest2 - o.dest1;
p = o.origin - o.dest2;
opac = vlen(p) / vlen(mv);
}
bmodel_lightstyle(o, opac);
if (done)
{
remove(self);
return;
}
self.think = secret_shadowmonitor_go;
}
// Make a sound, wait a little...
void () secretdoor_move0 =
{
self.state = STATE_UP;
if (self.noise1 != string_null)
sound(self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
self.nextthink = self.ltime + 0.1;
SUB_CalcMove(self.dest1, self.speed, secretdoor_move1);
if (self.noise2 != string_null)
sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM);
}
// Wait after first movement...
void () secretdoor_move1 =
{
self.nextthink = self.ltime + 1.0;
self.think = secretdoor_move2;
if (self.noise3 != string_null)
sound(self, CHAN_VOICE, self.noise3, 1, ATTN_NORM);
}
// Start moving sideways w/sound...
void () secretdoor_move2 =
{
if (self.noise2 != string_null)
sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM);
SUB_CalcMoveLight(self.dest1, self.dest2, self.speed2, secretdoor_move3, FALSE);
}
// Wait here until time to go back...
void () secretdoor_move3 =
{
self.state = STATE_TOP;
if (self.noise3 != string_null)
sound(self, CHAN_VOICE, self.noise3, 1, ATTN_NORM);
if (!(self.spawnflags & SECRET_OPEN_ONCE) || self.wait > 0)
{
self.nextthink = self.ltime + self.wait;
self.think = secretdoor_move4;
return;
}
self.think = SUB_Null;
}