forked from ShakaUVM/CustomTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIELD.QC
1335 lines (1077 loc) · 35.9 KB
/
FIELD.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
/*=======================================================//
// field.QC - CustomTF 3.2.OfN - 30/1/2001 - //
// by Sergio Fumaña Grunwaldt - OfteN [cp] //
=========================================================//
Field generator stuff - Written all by myself! :)
I took the model and some sounds from deadlode mod
One sound is from megaTF
=========================================================*/
// field generator status flags, DO NOT MODIFY
#define FIELDGEN_ISOFF 0 // no field, not linked, and its not trying to link (several possible reasons)
#define FIELDGEN_ISIDLE 1 // no field, not linked, trying to link with other generator
#define FIELDGEN_ISDISABLED 2 // no field, linked, its disabled temporary (teammate passing thru field)
#define FIELDGEN_ISENABLED 3 // field, linked, and cells enough, waiting for shock, only hum sound
#define FIELDGEN_ISWORKING 4 // field, linked, glowing and all the field visual/sound effects are on
// field generator settings
#define FIELDGEN_WORKTIME 3 // seconds the generators remain "working", glowing and doing lightning after a shock
#define FIELDGEN_WORKING_RATE 1 // interval in seconds for fieldgens to use cells
#define FIELDGEN_LINKTIME 3.5 // seconds between tries to link with other generator (only visual)
#define FIELDGEN_TIMEDISABLED 1.5 // time fieldgens remain disabled
#define FIELDGEN_CELLSCOST 2 // cells cost for each "FIELDGEN_ISWORKING" pass
// force field settings
#define FIELD_DMG 250//160 //was 80 - normal damag when touching
#define FIELD_DMGINSIDE 500//420 //was 120 - damage when trapped inside field
#define FIELD_SOUNDSRATE 1 // Rate in seconds at which hum/shield sound is played
#define FIELD_VISUALFACTOR 0.5 // 1 = always generate lightning for visuals, when working. 0 = never
/*===============================================================================================
EXPLANATION OF HOW THE ENTITY FIELDS ARE USED (thnx? np.. :P)
---------------------------------------------
For field generator entity:
---------------------------
.has_holo - Holds current status of every field generator, FIELDGEN_ISXXXX determines
.has_sensor - Boolean value, determines if field generator is currently supporting a force field
.martyr_enemy - This points to the force field, if none its always 'world'
.no_grenades_1 - Controls delay between tries to link (only affects sound/flash, it tries to link every frame)
.no_grenades_2 - Controls delay for field to go up again after beeing disabled
.tp_grenades_1 - Controls delay of the WORKING status
.has_teleporter - Used to flash generators when field is activated
.has_camera - Controls delay between cells take
.has_tesla - Boolean, forced status.
For force field entity:
-----------------------
.demon_one - Points to the first field generator
.demon_two - Points to the 2nd generator
.has_holo - Hum sound running, boolean
.has_sensor - Shield sound running, boolean
.has_tesla - Controls delay between hums
.has_sentry - Controls delay between shield sounds
.cnt - Orientation of field (x or y)
.dmg - Next damage the field will do
.has_camera - Used to control the rate at which the field touch sound/visual effects are done (4hz)
================================================================================================*/
void() CheckDistance;
entity(entity fieldgen) Find_OtherGen;
float(entity fieldgen1, entity fieldgen2) FieldGens_CanLink;
float(entity fieldgen) FieldGen_CanIdle;
float(entity fieldgen) IsValidFieldGen;
float (vector targ, vector check) vis2orig;
float(entity field) IsValidField;
void(entity tfield, entity gen1) Field_UpdateSounds;
void(entity tfield) Field_StopSounds;
void(entity tfield) Field_MakeVisual;
float(entity tfield) FieldIsImproved;
float(entity tfield) FieldIsMalfunctioning;
void() Field_touch;
void() Field_touch_SUB;
float(entity e1, entity e2) EntsTouching2;
void(entity tfield, vector where, entity thing) FieldExplosion;
void(entity field) PutFieldWork;
float(entity tfield, entity who) Field_ItCanPass;
float(entity tfield, entity who) Field_ShouldDamage;
#ifdef FIELD_FORCEMODE
entity(entity myself) GetMyFieldGen;
float(entity tfield) Field_GetForcedStatus;
void(float value) SetFieldForcedStatus; // player function (self = player) cuts disabled time also
float() GetFieldForcedStatus; // player
#endif
//=========================================================================================
// field generator model and sounds
void() Field_Precache =
{
precache_sound ("misc/null.wav");
precache_sound2("misc/ffhum.wav");
precache_sound2("misc/ffbeep.wav");
precache_sound2("misc/ffield.wav");
precache_sound2("misc/ffact.wav");
precache_sound2("misc/fffail.wav");
precache_model2("progs/ffgen2.mdl");
};
//==================================================================================================
// checks for field generators and removes itself if needed, checks for stuck entities inside field
void() Field_think =
{
/* NOT NEEDED - if (self.classname != "force_field")
{
RPrint("BUG: Not a force field entity was in 'FieldThink()'!\n");
return;
}*/
self.has_camera = #FALSE; // resets flag for visuals
// check field generators, removal of this field if needed... (for safety only)
if (!IsValidFieldGen(self.demon_one) || !IsValidFieldGen(self.demon_two))
{
if (IsValidFieldGen(self.demon_one))
{
self.demon_one.has_sensor = #FALSE;
self.demon_one.martyr_enemy = world;
}
if (IsValidFieldGen(self.demon_two))
{
self.demon_two.has_sensor = #FALSE;
self.demon_two.martyr_enemy = world;
}
self.demon_one = world;
self.demon_two = world;
dremove(self);
// report this, as it shouldnt happen
RPrint("Debug: Field entity removed in Field_think()\n");
return;
}
else
self.nextthink = time + 0.25; // 4hz rate
// Make visuals if needed
if (self.demon_one.has_holo == #FIELDGEN_ISWORKING)
Field_MakeVisual(self);
// checks for anything stuck in field :)
local entity te;
local float frange;
frange = #FIELDGEN_RANGE;
if (FieldIsImproved(self) & #IMPROVED_FOUR)
{
frange = #FIELDGEN_HACKEDRANGE; // at least 1 hacked for range
if (self.demon_one.all_active & #IMPROVED_FOUR && self.demon_two.all_active & #IMPROVED_FOUR)
frange = #FIELDGEN_HACKEDRANGE2; // both field generators hacked
}
te = findradius(self.origin,frange);
while (te)
{
if (te != self)
if (te != self.demon_one)
if (te != self.demon_two)
if (te.velocity == '0 0 0')
if (te.classname != "force_field")
if (EntsTouching2(te,self))
{
other = te;
deathmsg = #DMSG_STUCK_FORCEFIELD;
self.dmg = #FIELD_DMGINSIDE; // this gonna hurt
Field_touch_SUB();
}
te = te.chain;
}
};
//=============================================================================================
// is one entity actually intersecting the other one? (this avoids using a stupid trigger)
float(entity e1, entity e2) EntsTouching2 =
{
if (e1.absmin_x > e2.absmax_x)
return #FALSE;
if (e1.absmin_y > e2.absmax_y)
return #FALSE;
if (e1.absmin_z > e2.absmax_z)
return #FALSE;
if (e1.absmax_x < e2.absmin_x)
return #FALSE;
if (e1.absmax_y < e2.absmin_y)
return #FALSE;
if (e1.absmax_z < e2.absmin_z)
return #FALSE;
return #TRUE;
};
//=================================================================================
// these 2 functions return the current hacks that should apply to the field
float(entity tfield) FieldIsImproved =
{
if (IsValidFieldGen(tfield.demon_one) && IsValidFieldGen(tfield.demon_two))
return tfield.demon_one.all_active | tfield.demon_two.all_active;
if (IsValidFieldGen(tfield.demon_one))
return tfield.demon_one.all_active;
if (IsValidFieldGen(tfield.demon_two))
return tfield.demon_two.all_active;
return 0;
};
float(entity tfield) FieldIsMalfunctioning =
{
if (IsValidFieldGen(tfield.demon_one) && IsValidFieldGen(tfield.demon_two))
return tfield.demon_one.is_malfunctioning | tfield.demon_two.is_malfunctioning;
if (IsValidFieldGen(tfield.demon_one))
return tfield.demon_one.is_malfunctioning;
if (IsValidFieldGen(tfield.demon_two))
return tfield.demon_two.is_malfunctioning;
return 0;
};
//=================================================================
// disables force field
void(entity tfield, float timedisable) DisableField =
{
if (IsValidFieldGen(tfield.demon_one))
{
tfield.demon_one.has_holo = #FIELDGEN_ISDISABLED;
if (tfield.demon_one.no_grenades_2 < time + timedisable)
tfield.demon_one.no_grenades_2 = time + timedisable;
}
if (IsValidFieldGen(tfield.demon_two))
{
tfield.demon_two.has_holo = #FIELDGEN_ISDISABLED;
if (tfield.demon_two.no_grenades_2 < time + timedisable)
tfield.demon_two.no_grenades_2 = time + timedisable;
}
sound (tfield, #CHAN_VOICE, "misc/ffbeep.wav", 0.4, #ATTN_IDLE);
};
//=========================================================================================
// applies damage and makes the sound and visual effect for the forcefield shock
void() Field_touch_SUB =
{
if (FieldIsMalfunctioning(self) & #SCREWUP_THREE) // reduce output
self.dmg = 1;
#ifdef GIBABLE_CORPSES
if (other.#corpseflag == #STRFLAG_CORPSE) // Corpses
{
if (Field_ItCanPass(self, other))
{
DisableField(self,#FIELDGEN_TIMEDISABLED);
return;
}
else
{
if (Field_ShouldDamage(self,other))
TF_T_Damage (other, self, self.real_owner, self.dmg, 0, #TF_TD_ELECTRICITY);
}
}
else
#endif
if (other.classname == "player" && other.health > 0) // PLAYERS (alive)
{
if (other.playerclass == #PC_UNDEFINED) // Observers (they have 1 hp)
return;
if (Field_ItCanPass(self, other))
{
DisableField(self,#FIELDGEN_TIMEDISABLED);
return;
}
else
{
if (Field_ShouldDamage(self,other))
TF_T_Damage (other, self, self.real_owner, self.dmg, #TF_TD_NOTTEAM, #TF_TD_ELECTRICITY);
}
}
else // non player entities (or player heads)
{
if (IsMonster(other))
{
if (Field_ItCanPass(self, other))
{
DisableField(self,#FIELDGEN_TIMEDISABLED);
return;
}
else if (Field_ShouldDamage(self,other))
TF_T_Damage (other, self, self.real_owner, self.dmg, #TF_TD_NOTTEAM, #TF_TD_ELECTRICITY);
}
else // non-monsters non-alive-players entities (EVERYTHING ELSE)
{
// excludes entities that shouldnt be moved, doors plats etc..
if(other.movetype == #MOVETYPE_NONE
|| other.movetype == #MOVETYPE_PUSH
|| other == world)
return;
if (other.flags & #FL_ONGROUND)
other.velocity_z = other.velocity_z + 100 + 160*random();
other.flags = other.flags - (other.flags & #FL_ONGROUND);
if (self.cnt) // Y Alignment
{
if (other.origin_x < self.origin_x)
other.velocity_x = (0 - other.velocity_x) - (80 + 100 * random());
else
other.velocity_x = (0 - other.velocity_x) + (80 + 100 * random());
}
else // X Alignment
{
if (other.origin_y < self.origin_y)
other.velocity_y = (0 - other.velocity_y) - (80 + 100 * random());
else
other.velocity_y = (0 - other.velocity_y) + (80 + 100 * random());
}
}
}
// Do the effects for shock
FieldExplosion(self,other.origin,other);
PutFieldWork(self);
};
#ifdef FIELD_FORCEMODE
//==========================================================================
// gets one of our field generators
entity(entity myself) GetMyFieldGen =
{
local entity te;
local float foundit;
te = world;
foundit = #FALSE;
te = find(world, classname, "building_fieldgen");
while (te != world && foundit == #FALSE)
{
if (te.real_owner == myself) // is it ours?
foundit = #TRUE; // yeah, found it
if (foundit == #FALSE) // our search must continue...
te = find(te, classname, "building_fieldgen");
}
return te;
};
//=========================================================================
// these functions retrieve and set the current 'forced status' on a field
float(entity tfield) Field_GetForcedStatus =
{
if (IsValidFieldGen(tfield.demon_one) && IsValidFieldGen(tfield.demon_two))
{
if (tfield.demon_two.has_tesla || tfield.demon_one.has_tesla)
return #TRUE;
}
else if (IsValidFieldGen(tfield.demon_one))
{
if (tfield.demon_one.has_tesla)
return #TRUE;
}
else if (IsValidFieldGen(tfield.demon_two))
{
if (tfield.demon_two.has_tesla)
return #TRUE;
}
return #FALSE;
};
//==============================================================================
// player functions called on menu.qc to disable/enable forced status on field
void(float value) SetFieldForcedStatus =
{
local entity gen1, gen2;
gen1 = GetMyFieldGen(self);
gen2 = Find_OtherGen(gen1);
if (IsValidFieldGen(gen1))
{
gen1.has_tesla = value;
if (value)
gen1.no_grenades_2 = time;
}
if (IsValidFieldGen(gen2))
{
gen2.has_tesla = value;
if (value)
gen2.no_grenades_2 = time;
}
};
float() GetFieldForcedStatus =
{
local entity gen1, gen2;
gen1 = GetMyFieldGen(self);
gen2 = Find_OtherGen(gen1);
if (IsValidFieldGen(gen1) && IsValidFieldGen(gen2))
{
if (gen1.has_tesla || gen2.has_tesla)
return #TRUE;
}
else if (IsValidFieldGen(gen1))
return gen1.has_tesla;
else if (IsValidFieldGen(gen2))
return gen2.has_tesla;
return #FALSE;
};
#endif
//=========================================================================
// returns TRUE if 'who' entity should be able to pass thru the field
float(entity tfield, entity who) Field_ItCanPass =
{
#ifdef FIELD_TEST
return #FALSE;
#endif
if (FieldIsMalfunctioning(tfield) & #SCREWUP_ONE) // Malfunctioning, always block
return #FALSE;
if (who == tfield.real_owner) // field owner - always pass
return #TRUE;
#ifdef FIELD_FORCEMODE
if (Field_GetForcedStatus(tfield))
return #FALSE;
#endif
if (who.classname == "player") // PLAYERS
{
if (who.job & #JOB_TKD) //WK 4/27/7 TKD people are so tough they can walk through field gens!
return #TRUE;
if (Teammate(who, tfield.real_owner)) // teammate
return #TRUE;
if (UndercoverTeammate(who, tfield.real_owner)) // spies disguised as our team
{
return #TRUE;
}
}
else if (IsMonster(who)) // MONSTERS/ARMY
{
if (Teammate(who.real_owner, tfield.real_owner)) // team monster
return #TRUE;
}
#ifdef GIBABLE_CORPSES
else if (who.#corpseflag == #STRFLAG_CORPSE) // CORPSES
{
if (Teammate(who, tfield.real_owner)) // team corpse
return #TRUE;
}
#endif
return #FALSE;
};
//=========================================================================
// returns TRUE if 'who' entity should be damaged by the field
float(entity tfield, entity who) Field_ShouldDamage =
{
#ifdef FIELD_TEST
return #TRUE;
#endif
if (FieldIsMalfunctioning(tfield) & #SCREWUP_ONE) // Malfunctioning, hurts always
return #TRUE;
if (who.classname == "player") // PLAYERS
{
if (who.job & #JOB_TKD) //WK 4/27/7 TKD people are so tough they can walk through field gens!
return #FALSE;
if (who == tfield.real_owner) // field owner
return #FALSE;
if (Teammate(who, tfield.real_owner)) // teammate
return #FALSE;
if (UndercoverTeammate(who, tfield.real_owner)) // spies disguised as our team
{
return #FALSE;
}
}
else if (IsMonster(who)) // MONSTERS/ARMY
{
if (Teammate(who.real_owner, tfield.real_owner)) // team monster
return #FALSE;
}
#ifdef GIBABLE_CORPSES
else if (who.#corpseflag == #STRFLAG_CORPSE) // CORPSES
{
if (Teammate(who, tfield.real_owner)) // team corpse
return #FALSE;
}
#endif
return #TRUE;
};
//=============================================================================
// applies the particle effect and electric sound (at max 4hz rate)
void(entity tfield, vector where, entity thing) FieldExplosion =
{
if (!tfield.has_camera)
{
if (thing == world || thing.is_removed) return;
local vector whereFX;
whereFX = where;
whereFX_z = tfield.origin_z;
spawnFOG(whereFX);
sound(tfield,#CHAN_BODY,"effects/crunch.wav",0.5,#ATTN_NORM);
tfield.has_camera = #TRUE; // cya soon (this gets reset on every field think)
}
};
//================================================================
// Refresh working time for the force field
void(entity field) PutFieldWork =
{
if (IsValidFieldGen(field.demon_one))
field.demon_one.tp_grenades_1 = time + #FIELDGEN_WORKTIME;
if (IsValidFieldGen(field.demon_two))
field.demon_two.tp_grenades_1 = time + #FIELDGEN_WORKTIME;
};
//==============================================================
// Force field touch function
void() Field_touch =
{
if (other.classname == "force_field") return; //avoid weird loops with other fields
self.dmg = #FIELD_DMG;
deathmsg = #DMSG_FORCEFIELD;
Field_touch_SUB();
};
//===================================================================================
// creates the force field between the 2 generators (only if none currently on)
void(entity gen1, entity gen2) Create_Field =
{
// Check for existing force field, and abort if any
if (gen1.has_sensor || gen2.has_sensor)
return;
if (gen1.martyr_enemy != world || gen2.martyr_enemy != world) // 2nd CHECK
return;
// already checked b4 on CanLink -> CanIdle
/*if (!IsValidFieldGen(gen1) || !IsValidFieldGen(gen2))
return;*/
gen1.has_holo = #FIELDGEN_ISENABLED;
gen2.has_holo = #FIELDGEN_ISENABLED;
gen1.has_sensor = #TRUE;
gen2.has_sensor = #TRUE;
local entity tfield;
// generate field
tfield = spawn();
tfield.classname = "force_field";
tfield.owner = world;
tfield.real_owner = gen1.real_owner; // --> player
tfield.think = Field_think;
tfield.touch = Field_touch;
tfield.nextthink = time + 0.25;
// set pos and size
tfield.origin = gen1.origin + '0 0 32';
tfield.absmin_z = gen1.origin_z - 32;
tfield.absmax_z = gen1.origin_z + 32;
tfield.mins_z = 0 - 32;
tfield.maxs_z = 32;
tfield.size_z = 64;
local float diff;
if (gen1.origin_x == gen2.origin_x)
{
tfield.cnt = 0;
tfield.origin_x = gen1.origin_x;
tfield.absmin_x = gen1.origin_x - 2;
tfield.absmax_x = gen1.origin_x + 2;
tfield.maxs_x = 2;
tfield.mins_x = 0 - 2;
tfield.size_x = 4;
if (gen1.origin_y > gen2.origin_y)
{
diff = (gen1.origin_y - gen2.origin_y)/2;
tfield.origin_y = gen1.origin_y - diff;
tfield.absmin_y = gen2.origin_y;
tfield.absmax_y = gen1.origin_y;
tfield.maxs_y = diff;
tfield.mins_y = 0 - diff;
tfield.size_y = diff * 2;
}
else
{
diff = (gen2.origin_y - gen1.origin_y)/2;
tfield.origin_y = gen2.origin_y - diff;
tfield.absmin_y = gen1.origin_y;
tfield.absmax_y = gen2.origin_y;
tfield.maxs_y = diff;
tfield.mins_y = 0 - diff;
tfield.size_y = diff * 2;
}
}
else
{
tfield.cnt = 1;
tfield.origin_y = gen1.origin_y;
tfield.absmin_y = gen1.origin_y - 2;
tfield.absmax_y = gen1.origin_y + 2;
tfield.maxs_y = 2;
tfield.mins_y = 0 - 2;
tfield.size_y = 4;
if (gen1.origin_x > gen2.origin_x)
{
diff = (gen1.origin_x - gen2.origin_x)/2;
tfield.origin_x = gen1.origin_x - diff;
tfield.absmin_x = gen2.origin_x;
tfield.absmax_x = gen1.origin_x;
tfield.maxs_x = diff;
tfield.mins_x = 0 - diff;
tfield.size_x = diff * 2;
}
else
{
diff = (gen2.origin_x - gen1.origin_x)/2;
tfield.origin_x = gen2.origin_x - diff;
tfield.absmin_x = gen1.origin_x;
tfield.absmax_x = gen2.origin_x;
tfield.maxs_x = diff;
tfield.mins_x = 0 - diff;
tfield.size_x = diff * 2;
}
}
// apply stuff
tfield.movetype = #MOVETYPE_NONE;
tfield.solid = #SOLID_BBOX;
setsize(tfield, tfield.mins, tfield.maxs);
setorigin(tfield, tfield.origin);
// assign the pointers on the field generators
gen1.martyr_enemy = tfield;
gen2.martyr_enemy = tfield;
// assign the pointers to generators on ourselves
tfield.demon_one = gen1;
tfield.demon_two = gen2;
// make activation sound
sound (tfield, #CHAN_VOICE, "misc/ffact.wav", 0.2, #ATTN_NORM);
// initialize sound flags on field
tfield.has_sensor = #FALSE;
tfield.has_holo = #FALSE;
// flash generators
gen1.effects = #EF_DIMLIGHT | #EF_RED;
gen1.has_teleporter = #TRUE;
gen1.skin = 2;
gen2.effects = #EF_DIMLIGHT | #EF_RED;
gen2.has_teleporter = #TRUE;
gen2.skin = 2;
};
//=================================================================
// removes the force field (if any)
void(entity gen1, entity gen2) Remove_Field =
{
local float soundsoff;
soundsoff = #FALSE;
if (IsValidFieldGen(gen1))
{
gen1.has_sensor = #FALSE;
if (IsValidField(gen1.martyr_enemy))
{
Field_StopSounds(gen1.martyr_enemy); // Stops sounds on force field
soundsoff = #TRUE;
dremove(gen1.martyr_enemy);
gen1.martyr_enemy = world;
}
}
if (IsValidFieldGen(gen2))
{
gen2.has_sensor = #FALSE;
if (IsValidField(gen2.martyr_enemy))
{
if (!soundsoff)
Field_StopSounds(gen2.martyr_enemy); // Stops sounds on force field if not done
dremove(gen2.martyr_enemy);
gen2.martyr_enemy = world;
}
}
};
//======================================================================
// The following 2 functions are used for safety everywhere
float(entity field) IsValidField =
{
if (field == world)
return #FALSE;
if (field.classname != "force_field")
return #FALSE;
return #TRUE;
};
float(entity fieldgen) IsValidFieldGen =
{
if (fieldgen == world)
return #FALSE;
if (fieldgen.classname != "building_fieldgen")
return #FALSE;
return #TRUE;
};
//========================================================
// starts or removes sounds on the field
void(entity tfield, entity gen1) Field_UpdateSounds =
{
//.has_holo : hum
//.has_sensor : shield
if (IsValidField(tfield)) // only if there is a field currently
{
local float playhum, playshield;
playhum = #FALSE;
playshield = #FALSE;
/*if (gen1.has_holo == #FIELDGEN_ISOFF) // for some reason we r not working
{
playhum = #FALSE;
playshield = #FALSE;
}
else if (gen1.has_holo == #FIELDGEN_ISIDLE) // awaiting for link
{
playhum = #FALSE;
playshield = #FALSE;
}
else if (gen1.has_holo == #FIELDGEN_ISDISABLED) // teammate passing thru the field?
{
playhum = #FALSE;
playshield = #FALSE;
}
else*/
if (gen1.has_holo == #FIELDGEN_ISENABLED)
{
playhum = #TRUE;
playshield = #FALSE;
}
else if (gen1.has_holo == #FIELDGEN_ISWORKING)
{
playhum = #TRUE;
playshield = #TRUE;
}
// ok, lets update the sounds if needed..
if (!playhum)
{
if (tfield.has_holo)
{
sound(tfield,#CHAN_MISC,"misc/null.wav",0.5,#ATTN_NORM);
tfield.has_holo = #FALSE;
}
}
else
{
if (!tfield.has_holo || tfield.has_tesla < time)
{
sound(tfield,#CHAN_MISC,"misc/ffhum.wav",0.4,#ATTN_NORM);
tfield.has_tesla = time + #FIELD_SOUNDSRATE;
tfield.has_holo = #TRUE;
}
}
if (!playshield)
{
if (tfield.has_sensor)
{
sound(tfield,#CHAN_ITEM,"misc/null.wav",0.5,#ATTN_NORM);
tfield.has_sensor = #FALSE;
}
}
else
{
if (!tfield.has_sensor || tfield.has_sentry < time)
{
//TODO?: lower volume as (FIELDGEN_WORKTIME - time) decreases
sound(tfield,#CHAN_ITEM,"misc/ffield.wav",0.5,#ATTN_NORM);
tfield.has_sentry = time + #FIELD_SOUNDSRATE;
tfield.has_sensor = #TRUE;
}
}
}
};
//====================================================================
// Called on each force field removal to stop any sounds from it
void(entity tfield) Field_StopSounds =
{
// We dont do any check because this function is called with everything already checked
sound(tfield,#CHAN_ITEM,"misc/null.wav",0.5,#ATTN_NORM);
sound(tfield,#CHAN_MISC,"misc/null.wav",0.5,#ATTN_NORM);
tfield.has_sensor = #FALSE;
tfield.has_holo = #FALSE;
};
//====================================================================
// do the lightning stuff while field is FIELDGEN_ISWORKING
void(entity tfield) Field_MakeVisual =
{
// To avoid some overhead, only do visual lightning effect sometimes
if (random() < #FIELD_VISUALFACTOR)
return;
if (IsValidField(tfield))
{
local float fx, fy;
local vector tmpvec;
if (tfield.cnt)
{
fy = tfield.origin_y;
fx = tfield.origin_x + (tfield.size_x/2 - tfield.size_x * random());
}
else
{
fx = tfield.origin_x;
fy = tfield.origin_y + (tfield.size_y/2 - tfield.size_y * random());
}
tmpvec_x = fx;
tmpvec_y = fy;
tmpvec_z = tfield.origin_z - 12;
WriteByte (#MSG_BROADCAST, #SVC_TEMPENTITY);
if (random() > 0.5)
WriteByte (#MSG_BROADCAST, #TE_LIGHTNING2);
else
WriteByte (#MSG_BROADCAST, #TE_LIGHTNING1);
WriteEntity (#MSG_BROADCAST, tfield);
if (random() > 0.5)
{
WriteCoord (#MSG_BROADCAST, fx);
WriteCoord (#MSG_BROADCAST, fy);
WriteCoord (#MSG_BROADCAST, tfield.origin_z - 12);
WriteCoord (#MSG_BROADCAST, fx);
WriteCoord (#MSG_BROADCAST, fy);
WriteCoord (#MSG_BROADCAST, tfield.origin_z + 12);
}
else
{
WriteCoord (#MSG_BROADCAST, fx);
WriteCoord (#MSG_BROADCAST, fy);
WriteCoord (#MSG_BROADCAST, tfield.origin_z + 22);
WriteCoord (#MSG_BROADCAST, fx);
WriteCoord (#MSG_BROADCAST, fy);
WriteCoord (#MSG_BROADCAST, tfield.origin_z - 2);
}
#ifdef QUAKE_WORLD
multicast (tmpvec, #MULTICAST_PHS);
#endif
}
};
//==================================================
// called every frame by the field generators
void() FieldGen_think =
{
local entity othergen;
othergen = Find_OtherGen(self); // get our brother
// Create the force field if it's possible, or remove it if not and exists
if (FieldGens_CanLink(self,othergen))
Create_Field(self,othergen); // checks redundancy itself
else
Remove_Field(self,othergen); // checks redundancy itself
// field gens main loop (ai? heh.. my cat is smarter than these force fields)
if (self.has_holo == #FIELDGEN_ISOFF) // for some reason we r not working
{
self.effects = 0;
self.skin = 0;
if (FieldGen_CanIdle(self)) // can we go idle?
self.has_holo = #FIELDGEN_ISIDLE;
}
else if (self.has_holo == #FIELDGEN_ISIDLE) // trying to link
{
self.effects = 0;
self.skin = 0;
if (self.no_grenades_1 < time) // trying to link sound/flash time
{
sound (self, #CHAN_WEAPON, "misc/fffail.wav", 0.5, #ATTN_IDLE);
self.skin = 1;
self.effects = #EF_DIMLIGHT;
self.no_grenades_1 = time + #FIELDGEN_LINKTIME;
}
}
else if (self.has_holo == #FIELDGEN_ISDISABLED) // teammate passing thru the field?
{
self.effects = 0;
self.skin = 0;
// time check
if (self.no_grenades_2 < time) // can we go idle?
{
self.has_holo = #FIELDGEN_ISIDLE;