-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenviron.qc
1687 lines (1329 loc) · 40.8 KB
/
environ.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
/*=======================================================//
// environ.QC - CustomTF 3.2.OfN - 05/8/2004 - //
// by Sergio Fumaña Grunwaldt - OfteN [cp] //
=========================================================//
World environment (special FX's & daylight/brightness)
---------------------------------------------------------//
Brightness/daylight fade in/out's and other environment
stuff is handled here - CREDITS: Thanks Grievre!
Aren't the storm and earthquake awesome?! =)
_________________________________________________________//
*** WARNINGs about Storm and Earthquake use: ***
I don't recommend using earthquake or storm on net
servers as they may cause lag/FPS drops, for LAN they are
great, no problems.
The drawback of the storm is that on some
computer/client combos FPS may get decreased by the
continuous brightness changes. (observed on a P3+Voodoo5
with gl-fuhquake as client mainly specially on big maps).
With software clients and original ID opengl client
there should be no problem, but experiment yourself.
These warnings doesn't apply to DayTime "emulation", as
its brightness changes are done at a maximum rate of
1 per-second, and it wouldn't cause much trouble if any.
But remember, do your own tests and see if people playing
experience any lag/FPS drops, in some circumstances like
a server with only a few players or every player with
good computer and connection it would even not be
noticed at all! Enjoy!
=========================================================*/
void() RemoveFadeTimer;
string(float brightness) ReturnBrightness;
void(float brightness) SetWorldBrightness;
entity(float brightness, float fadetime, float delaytime, float factor) FadeWorld;
void() EnvironmentPrecachees;
void(float oldstorm, float oldearthquake, float olddaytime, float oldrunes) UpdateEnvironment;
void() GetEnvironmentGlobals;
void() ApplyMapFlags;
void() InitDayTime;
void() InitStorm;
void() InitEarthquake;
void(float report) CleanUpDayTime;
void(float report) CleanUpStorm;
void(float report) CleanUpEarthquake;
void(float thundernum, float vol) ThunderSound;
void(entity tstorm, float thunderdelay) StormLightning;
float(entity tstorm) GetThunderDelay;
entity(entity tstorm) StormSelectMachine;
entity(entity tstorm) StormSelectPlayer;
// External
void(vector org, float damage) SpawnBlood;
float(entity tester) IsBuilding;
void() GetRunesGlobal;
void(float oldrunes) UpdateRuneStuff;
/*===============================================================================================
EXPLANATION OF HOW THE ENTITY FIELDS ARE USED (thnx? np.. :P)
---------------------------------------------
For world fade in/out entity:
-----------------------------
.has_tesla - Desired final brightness
.has_sentry - Original brightness when fading started
.heat - Frame counter
.has_sensor - Number of steps calculated for the fading
.has_teleporter - Determines special action on fading end: 0 = nothing, 1 = set special light on 2 = set it off 3 = adjust daylight var along with fade
For storm entity:
-----------------
.has_tesla - Distance from battlefield of the storm (it emulates a real thing!)
.has_sentry - Number of lightning storm events running
.has_holo - Last thunder sound played (will not play again till another sound is played first)
.has_sensor - 2nd last thunder sound played (50% chances will not play consecutively)
For storm event entity:
-----------------------
.heat - Counter for lightning animation
.has_camera - If TRUE lightning flash is finished for this
.has_teleporter - This is set to TRUE if thunder sound is already played
.has_fieldgen - Type of lightning thunder to perform (random)
.demon_one - Points to our main storm entity
.penance_time - Time at which this effect was started
.job_finished - Delay that should occur between lightning and thunder sound
For earthquake entity:
----------------------
.has_holo - It's TRUE if an earthquake is currently happenning
.heat - Used as a counter for eathquakes
.penance_time - Indicates time at which current earthquake was started
.job_finished - Duration of the current earthquake
For daytime entity:
-------------------
.ltime - Time at which daytime started
.count - Total number of days that will occur
.heat - Size in time of a day
.has_tesla - Flag that indicates if we are towards midnight (-1) or noon (1)
================================================================================================*/
// Environment settings
// Brightness settings
#define ENVIRO_DARKNESS 5
#define ENVIRO_MIDBRIGHT 8
#define ENVIRO_ENDBRIGHT 6
#define ENVIRO_DEFAULT_DAYLIGHT 12
// Storm settings
#define STORM_MAXCONCURRENT 2 // Maximum possible concurrent lightning events
#define STORM_MAXVOL 1
#define STORM_MINVOL 0.75
#define STORM_THUNDERSOUND_CHANCEDOUBLE 0.5 // Chance of repeating 2nd last thunder sound
#define STORM_MAXFREQUENCY 20
#define STORM_MINFREQUENCY 5
#define STORM_THUNDER_MINDELAY 0
#define STORM_THUNDER_MAXDELAY 4
#define STORM_LIGHTNINGBRIGHT_MINIMUMFACTOR 0.5 // Factor for minimum lightning bright intensity
#define STORM_DIRECTHIT_DMG 800 // Damage a direct hit of lightning does
// Earthquake settings
#define EARTHQUAKE_MAXHAPPEN 20
#define EARTHQUAKE_MINHAPPEN 10
#define EARTHQUAKE_DURATIONMAX 30
#define EARTHQUAKE_DURATIONMIN 15
#define EARTHQUAKE_PUSHINTENSITY 120
#define EARTHQUAKE_MAXRATE 0.2
#define EARTHQUAKE_MINRATE 0.1
// Daytime settings
#define ENVIRO_MIDNIGHTLIGHT_DEFAULT 5
#define ENVIRO_NOONLIGHT_DEFAULT 19
#define DAYTIME_STEPDELAY_TOBPRINT 4
//==================================================================================
// Called once-per-map on worldspawn to initialize all the environment stuff
void() InitEnvironment =
{
// Precache the sounds
EnvironmentPrecachees();
current_brightness = -1; // To make sure its able to be updated by SetWorldBrightness, see below
// First, apply flags set on the map for environment
ApplyMapFlags();
// Then get the global environment vars (infokeys) which may override map flags
GetEnvironmentGlobals();
// Set initial world brightness
if (no_bright)
lightstyle(0,"m");
else
SetWorldBrightness(#ENVIRO_DARKNESS); //(dark because no clients yet)
// Impide brightness to be altered as we start dark
specialstate = #TRUE;
// Initialize our environment sub-sections as needed
UpdateEnvironment(0,0,0,0);
};
//=================================================================
// These return TRUE if server has the file for current map
float() validatelit =
{
local string st;
st = strcat("maps/",mapname);
st = strcat(st,".lit");
return validatefile(st);
};
float() validatesky =
{
local string st;
st = strcat("maps/",mapname);
st = strcat(st,".sky");
return validatefile(st);
};
float() validatehrt =
{
local string st;
st = strcat("maps/",mapname);
st = strcat(st,".hrt");
return validatefile(st);
};
//=======================================================================
// Gets and applies any environment flags that may be on the map
void() ApplyMapFlags =
{
// Turn on watervis if this map is flagged as watervised and server has autoset_watervis set
if (infokey(world,"autoset_watervis") == "1") // autoset_watervis is enabled?
{
if (world.#mapflags & #MAPFLAG_WATERVISED)
{
bprint(#PRINT_HIGH, "Map Info This map supports transparent liquids.\n");
if (cvar("watervis")!= 1)
{
RPrint("Turning ON watervis... (map flagged as watervised)\n");
//localcmd("watervis 1\n");
cvar_set("watervis","1");
}
}
else
{
if (cvar("watervis")!= 0)
{
RPrint("Turning OFF watervis... (map not flagged as watervised)\n");
//localcmd("watervis 0\n");
cvar_set("watervis","0");
}
}
}
// Inform clients about any existing special extra files for this map...
dprint("Looking for any map extra files...\n");
// Does the server have a coloured lighting file for this map?
if (validatelit())
bprint(#PRINT_HIGH,"Map Info Coloured lighting for this map is avaliable. Type ¢cmd special getlit¢ to download it.\n");
// Does the server have a paked skybox file for this map?
if (validatesky())
bprint(#PRINT_HIGH,"Map Info Packed skybox for this map is avaliable. Type ¢cmd special getsky¢ to download it.\n");
// Does the server have a hi-res textures file for this map?
if (validatehrt())
bprint(#PRINT_HIGH,"Map Info Hi-Res texture file for this map is avaliable. Type ¢cmd special gethrt¢ to download it.\n");
// Get standard environment flags "hard-coded" into the map file (worldspawn field)
if (world.#mapflags & #MAPFLAG_STORM)
storm = 1;
if (world.#mapflags & #MAPFLAG_EARTHQUAKE)
earthquake = 1;
if (world.#mapflags & #MAPFLAG_DAYTIME)
daytime = 10;
if (world.#mapflags & #MAPFLAG_RUNES)
runes = 1;
// Disable custom/stock classes if needed
if (world.#mapflags & #MAPFLAG_NOCUSTOM)
custom_mode = 2;
if (world.#mapflags & #MAPFLAG_NOSTOCK)
stock_mode = 2;
// Make sure 1 of them is enabled at least
if (custom_mode == 2 && stock_mode == 2)
custom_mode = 0;
// Apply hard-coded custom money
if (world.money != 0)
custom_money = world.money;
// Get the teammate's masks
friends1_mask = stof(world.noise1);
friends2_mask = stof(world.noise2);
friends3_mask = stof(world.noise3);
friends4_mask = stof(world.noise4);
// Get disabled/free stuff masks, if map stuff not disabled
if (infokey(world,"no_mapstuff") != "1")
{
disabledstuff1 = world.#disabledstuff1;
disabledstuff2 = world.#disabledstuff2;
disabledstuff3 = world.#disabledstuff3;
disabledstuff4 = world.#disabledstuff4;
disabledstuff5 = world.#disabledstuff5;
givenstuff1 = world.#givenstuff1;
givenstuff2 = world.#givenstuff2;
givenstuff3 = world.#givenstuff3;
givenstuff4 = world.#givenstuff4;
givenstuff5 = world.#givenstuff5;
}
};
//===================================================================
// Gets all the environment globals from the localinfo's
void() GetEnvironmentGlobals =
{
local string st;
// Get custom daylight setting, if any
st = infokey(world,"daylight");
if (st == "") // we should use a default then..
daylight = #ENVIRO_DEFAULT_DAYLIGHT;
else
{
daylight = stof(st); // we use the custom setting..
if (daylight < 0 || daylight > 25) // but only if a valid value
daylight = #ENVIRO_DEFAULT_DAYLIGHT;
}
// Get the storm setting, if any
st = infokey(world,"storm");
if (st != "")
{
storm = stof(st); // we use the custom setting..
if (storm < 0 || storm > 1) // but only if a valid value
storm = 0;
}
// Get the earthquake setting, if any
st = infokey(world,"earthquake");
if (st != "")
{
earthquake = stof(st); // we use the custom setting..
if (earthquake < 0 || earthquake > 1) // but only if a valid value
earthquake = 0;
}
// Get the daytime setting, if any
st = infokey(world,"daytime");
if (st != "")
{
daytime = stof(st); // we use the custom setting..
if (daytime < 0) // but only if a valid value
daytime = 0;
else if (daytime > 100)
daytime = 100;
}
// Get custom noon/midnight brightness settings, if any
st = infokey(world,"noon_light");
if (st == "") // we should use a default then..
noon_light = #ENVIRO_NOONLIGHT_DEFAULT;
else
{
noon_light = stof(st); // we use the custom setting..
if (noon_light < 0 || noon_light > 25) // but only if a valid value
noon_light = #ENVIRO_NOONLIGHT_DEFAULT;
}
st = infokey(world,"midnight_light");
if (st == "") // we should use a default then..
midnight_light = #ENVIRO_MIDNIGHTLIGHT_DEFAULT;
else
{
midnight_light = stof(st); // we use the custom setting..
if (midnight_light < 0 || midnight_light > 25) // but only if a valid value
midnight_light = #ENVIRO_MIDNIGHTLIGHT_DEFAULT;
// If midnight < noonlight just make them the same
if (midnight_light > noon_light)
midnight_light = noon_light;
}
st = infokey(world,"no_bright");
if (st == "") // we should use a default then..
no_bright = #FALSE;
else
{
if (st == "1")
no_bright = #TRUE;
else
no_bright = #FALSE;
}
// Get runes global
GetRunesGlobal();
// Get the disabled/free stuff masks settings on server, if any
st = infokey(world,"dstuff1");
if (st != "")
disabledstuff1 = stof(st);
st = infokey(world,"dstuff2");
if (st != "")
disabledstuff2 = stof(st);
st = infokey(world,"dstuff3");
if (st != "")
disabledstuff3 = stof(st);
st = infokey(world,"dstuff4");
if (st != "")
disabledstuff4 = stof(st);
st = infokey(world,"dstuff5");
if (st != "")
disabledstuff5 = stof(st);
st = infokey(world,"gstuff1");
if (st != "")
givenstuff1 = stof(st);
st = infokey(world,"gstuff2");
if (st != "")
givenstuff2 = stof(st);
st = infokey(world,"gstuff3");
if (st != "")
givenstuff3 = stof(st);
st = infokey(world,"gstuff4");
if (st != "")
givenstuff4 = stof(st);
st = infokey(world,"gstuff5");
if (st != "")
givenstuff5 = stof(st);
};
//===============================================================
// Sounds for the environment stuff
void() EnvironmentPrecachees =
{
// Storm thunder sounds
precache_sound("ambience/thunder1.wav");
precache_sound("environ/thunder2.wav");
precache_sound("environ/thunder3.wav");
precache_sound("environ/thunder4.wav");
precache_sound("environ/thundrk.wav");
// Earthquake sounds
precache_sound("environ/rumble.wav");
precache_sound("environ/rumblend.wav");
};
//====================================================================================
// Called when environment needs an update (admins change enviro variables etc..)
void(float oldstorm, float oldearthquake, float olddaytime, float oldrunes) UpdateEnvironment =
{
// Initialize needed environment stuff
if (oldstorm == 0 && storm != 0)
InitStorm();
if (oldearthquake == 0 && earthquake != 0)
InitEarthquake();
if (olddaytime == 0 && daytime != 0)
InitDayTime();
// Shutdown environment stuff if needed
if (oldstorm != 0 && storm == 0)
CleanUpStorm(#TRUE);
if (oldearthquake != 0 && earthquake == 0)
CleanUpEarthquake(#TRUE);
if (olddaytime != 0 && daytime == 0)
CleanUpDayTime(#TRUE);
// Handled on runes.qc
UpdateRuneStuff(oldrunes);
};
//==============================================================
// Functions to trigger level fade in and out's
void(float delaytime, float fadetime, float factor) World_FadeIn =
{
local entity fadetimer;
specialstate = #TRUE;
fadetimer = FadeWorld(daylight, fadetime, delaytime, factor);
if (fadetimer)
fadetimer.has_teleporter = 2;
else
specialstate = #FALSE;
};
void(float delaytime, float fadetime, float factor) World_FadeOut =
{
specialstate = #TRUE;
FadeWorld(#ENVIRO_DARKNESS, fadetime, delaytime, factor);
};
// Used when observers only in-game brightness and for ceasefire
void(float delaytime, float fadetime, float factor) World_FadeMid =
{
specialstate = #TRUE;
FadeWorld(#ENVIRO_MIDBRIGHT, fadetime, delaytime, factor);
};
// Fade used when intermission runs
void(float delaytime, float fadetime, float factor) World_FadeEnd =
{
local entity fadetimer;
fadetimer = FadeWorld(#ENVIRO_ENDBRIGHT, fadetime, delaytime, factor);
if (fadetimer)
fadetimer.has_teleporter = 3; // Adjust daylight along with fade out
};
//======================================================================================
// Returns the string to be used on a lightstyle call for the given bright intensity
string(float brightness) ReturnBrightness =
{
brightness = rint(brightness);
if (brightness > 25)
return "z";
if (brightness == 0)
return "a";
if (brightness == 1)
return "b";
if (brightness == 2)
return "c";
if (brightness == 3)
return "d";
if (brightness == 4)
return "e";
if (brightness == 5)
return "f";
if (brightness == 6)
return "g";
if (brightness == 7)
return "h";
if (brightness == 8)
return "i";
if (brightness == 9)
return "j";
if (brightness == 10)
return "k";
if (brightness == 11)
return "l";
if (brightness == 12)
return "m";
if (brightness == 13)
return "n";
if (brightness == 14)
return "o";
if (brightness == 15)
return "p";
if (brightness == 16)
return "q";
if (brightness == 17)
return "r";
if (brightness == 18)
return "s";
if (brightness == 19)
return "t";
if (brightness == 20)
return "u";
if (brightness == 21)
return "v";
if (brightness == 22)
return "w";
if (brightness == 23)
return "x";
if (brightness == 24)
return "y";
if (brightness == 25)
return "z";
if (brightness < 0)
return "a";
return "m";
};
//==============================================================================================
// Global function to set overall brightness
// Must be called always, and not directly call lightstyle() ever!
void(float brightness) SetWorldBrightness =
{
if (no_bright) return;
local string st;
brightness = rint(brightness);
if (brightness == current_brightness) return;
st = ReturnBrightness(brightness);
lightstyle(0,st);
current_brightness = brightness;
};
void() FadeWorld_think;
//========================================================================
// Fades the world brightness to the specified one
entity(float brightness, float fadetime, float delaytime, float factor) FadeWorld =
{
if (factor == 0)
factor = 1;
local entity fadetimer;
RemoveFadeTimer();
if (current_brightness == brightness) return world;
fadetimer = spawn();
fadetimer.classname = "fade";
fadetimer.think = FadeWorld_think;
fadetimer.nextthink = time + delaytime;
fadetimer.heat = 0;
fadetimer.has_sentry = current_brightness;
fadetimer.has_tesla = brightness;
fadetimer.has_sensor = current_brightness - brightness; // steps
if (fadetime == 0) // use default rate
fadetimer.has_camera = fabs(fadetimer.has_sensor) * factor;
else
fadetimer.has_camera = fadetime * 10 * factor; // total steps
fadetimer.has_teleporter = 0; // do nothing when fading ends, default
return fadetimer;
};
void() FadeWorld_think =
{
local float bright, current_fraction, current_step;
current_fraction = self.heat / self.has_camera;
current_step = current_fraction * self.has_sensor;
bright = self.has_sentry - current_step;
SetWorldBrightness(bright);
if (self.has_teleporter == 3)
daylight = bright;
self.heat = self.heat + 1;
if (current_brightness == self.has_tesla)
{
if (self.has_teleporter == 1)
specialstate = #TRUE;
else if (self.has_teleporter == 2)
specialstate = #FALSE;
dremove(self);
}
else
self.nextthink = time + 0.1;
};
//=========================================================================
// removes current fade timer
void() RemoveFadeTimer =
{
local entity te;
te = find(world,classname,"fade");
if (te) dremove(te);
};
//-------------------------//
// * Storm * //
// Thunders and lightning //
//-------------------------//
void() Storm_think;
//========================================================================
// Initializes storm stuff and starts it
void() InitStorm =
{
local entity tstorm;
CleanUpStorm(#FALSE);
if (!storm) return;
// Create storm entity
tstorm = spawn();
tstorm.classname = "storm";
tstorm.think = Storm_think;
tstorm.nextthink = time + 1;
// Set starting settings
tstorm.has_holo = -1; // last thunder sound
tstorm.has_sensor = -1; // 2nd last thunder sound
tstorm.has_tesla = 1; // Storm always start far away
bprint(#PRINT_HIGH,"Environment Lightning storm near the battlefield!\n");
};
//=======================================================
// Main think for storm entity
void() Storm_think =
{
local float thunderdelay;
if (self.has_sentry < #STORM_MAXCONCURRENT)
{
thunderdelay = GetThunderDelay(self);
StormLightning(self, thunderdelay);
}
else
{
self.nextthink = time + 1 + random() * 2;
return;
}
self.nextthink = time + #STORM_MINFREQUENCY + (#STORM_MAXFREQUENCY - #STORM_MINFREQUENCY) * (1- self.has_tesla) + random()*random()*10;
};
//===========================================================================
// Gets the delay for a thunder in the storm
float(entity tstorm) GetThunderDelay =
{
return #STORM_THUNDER_MINDELAY + (#STORM_THUNDER_MAXDELAY - #STORM_THUNDER_MINDELAY) * (1- tstorm.has_tesla);
};
//====================================================================
// Cleans up everything related to the storm and ends it
void(float report) CleanUpStorm =
{
local entity tstorm, te;
// remove any storm events out there
te = find(world, classname, "stormevent");
while (te)
{
// remove this one..
dremove(te);
// ..and find the next one (if there is one)
te = find(world, classname, "stormevent");
}
// find main storm entity..
tstorm = find(world, classname, "storm");
// ..and remove it
if (tstorm) dremove(tstorm);
// Reset world brighness to current daylight if needed after any storm lightning
if (!ceasefire && !specialstate)
SetWorldBrightness(daylight);
if (report)
bprint(#PRINT_HIGH,"Environment The lighning storm has gone far away.\n");
};
//==============================================================
// Select and play an appropiate thunder sound from the storm
void(entity tstorm) StormThunder =
{
if (ceasefire)
return;
local float thundernum;
local float th1, th2, th3, counter, done, hs_sensor;
if (tstorm.has_holo == -1 && tstorm.has_sensor == -1)
{
thundernum = rint(random()*3);
}
else
{
th1 = 40;
th2 = 40;
th3 = 40;
if (random() < #STORM_THUNDERSOUND_CHANCEDOUBLE || tstorm.has_sensor < 0)
hs_sensor = tstorm.has_sensor;
else
hs_sensor = 40;
counter = 0;
done = #FALSE;
while (counter < 4 && done == #FALSE)
{
if (counter != tstorm.has_holo && counter != hs_sensor)
{
done = #TRUE;
th1 = counter;
}
counter = counter + 1;
}
counter = 0;
done = #FALSE;
while (counter < 4 && done == #FALSE)
{
if (counter != tstorm.has_holo && counter != hs_sensor && counter != th1)
{
done = #TRUE;
th2 = counter;
}
counter = counter + 1;
}
// third loop if we double use the 2nd last sound
if (hs_sensor == 40)
{
counter = 0;
done = #FALSE;
while (counter < 4 && done == #FALSE)
{
if (counter != tstorm.has_holo && counter != hs_sensor && counter != th1 && counter != th2)
{
done = #TRUE;
th3 = counter;
}
counter = counter + 1;
}
counter = rint(random()*2);
if (counter == 0)
thundernum = th1;
else if (counter == 1)
thundernum = th2;
else if (counter == 2)
thundernum = th3;
}
else
{
counter = rint(random());
if (counter == 0)
thundernum = th1;
else if (counter == 1)
thundernum = th2;
}
}
// Get volume of thunder based on storm distance to battle field :)
counter = #STORM_MINVOL + (#STORM_MAXVOL - #STORM_MINVOL) * tstorm.has_tesla;
// Make thunder sound!
ThunderSound(thundernum,counter);
// Update last used thunder sounds
tstorm.has_sensor = tstorm.has_holo;
tstorm.has_holo = thundernum;
};
//===========================================================================================
// After lightning this is used by a storm event entity to play thunder and do clean up
void() Thunder_think =
{
StormThunder(self.demon_one);
if (self.has_teleporter || self.has_fieldgen != 6) // If not a double thing or 1 thunder of 2 already done..
{
self.demon_one.has_sentry = self.demon_one.has_sentry - 1;
dremove(self);
}
else // this always get executed by a "double type" storm event
{
self.has_fieldgen = 1; // in next think, do the thing above
self.nextthink = time + GetThunderDelay(self.demon_one);
}
};
//=======================================================================
// Subroutine used for any lightning bright adjustments
void(float bright, entity stormevent) SetLightningBrightness =
{
if (ceasefire)
return;
bright = bright - (bright*#STORM_LIGHTNINGBRIGHT_MINIMUMFACTOR)*(1-stormevent.demon_one.has_tesla);
SetWorldBrightness(daylight + bright);
};
//========================================================================================
// Think for storm event entity, does lightning and passes to thunder_think when ended
void() StormEvent_think =
{
if (self.has_camera)
{
SetLightningBrightness(0,self);
if (self.has_teleporter && self.has_fieldgen != 6) // Sound thunder played? then just do cleanup
{
self.demon_one.has_sentry = self.demon_one.has_sentry - 1;
dremove(self);
return;
}
else // we must play the thunder still
{
self.think = Thunder_think;
if (self.has_fieldgen == 6 && self.has_teleporter) // Double lightning/thunder event type
self.nextthink = time + GetThunderDelay(self.demon_one);
else
self.nextthink = self.penance_time + self.job_finished;
return;
}
}
if (self.has_fieldgen == 0) // first type of lightning
{
if (self.heat == 0)
SetLightningBrightness(15,self);
else if (self.heat == 1)
SetLightningBrightness(0,self);
else if (self.heat == 2)
{
SetLightningBrightness(8,self);
self.has_camera = #TRUE;
}
}
else if (self.has_fieldgen == 1) // second type of lightning
{
if (self.heat == 0)
SetLightningBrightness(15,self);
else if (self.heat == 1)
SetLightningBrightness(10,self);
else if (self.heat == 2)
{
SetLightningBrightness(3,self);
self.has_camera = #TRUE;
}
}
else if (self.has_fieldgen == 2) // third type of lightning
{
if (self.heat == 0)
SetLightningBrightness(8,self);
else if (self.heat == 1)
{
SetLightningBrightness(15,self);
self.has_camera = #TRUE;
}
}
else if (self.has_fieldgen == 3) // 4th Only sound
{
self.has_camera = #TRUE;
self.nextthink = time;
}
else if (self.has_fieldgen == 4) // 5th type of thunder
{
if (self.heat == 0)
SetLightningBrightness(5,self);
if (self.heat == 1)
{
SetLightningBrightness(4,self);
self.has_camera = #TRUE;
}
}
else if (self.has_fieldgen == 5) // 6th Only lightning