123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- /* Copyright (C) 1996-2022 id Software LLC
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- See file, 'COPYING', for details.
- */
- const string LightStyles[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
- const float LightStyles_MAX = LightStyles.length - 1;
- const string LightStylesHalf[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"};
- const float LightStylesHalf_MAX = LightStylesHalf.length - 1;
- //============================================================================
- // No special functionality, just to hold dynamic shadowcasting lights for KEX
- const float DYNAMICLIGHT_NOT_IN_COOP = 1;
- void dynamiclight()
- {
- if(coop && self.spawnflags & DYNAMICLIGHT_NOT_IN_COOP)
- {
- remove(self);
- }
- }
- //============================================================================
- void InitLightStyles()
- {
- //
- // Setup light animation tables. 'a' is total darkness, 'z' is maxbright.
- //
- // 0 normal
- lightstyle(0, "m");
-
- // 1 FLICKER (first variety)
- lightstyle(1, "mmnmmommommnonmmonqnmmo");
- // 2 SLOW STRONG PULSE
- lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
- // 3 CANDLE (first variety)
- lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
- // 4 FAST STROBE
- lightstyle(4, "ma");
- // 5 GENTLE PULSE 1
- lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
- // 6 FLICKER (second variety)
- lightstyle(6, "nmonqnmomnmomomno");
- // 7 CANDLE (second variety)
- lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm");
- // 8 CANDLE (third variety)
- lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
- // 9 SLOW STROBE (fourth variety)
- lightstyle(9, "aaaaaaaazzzzzzzz");
- // 10 FLUORESCENT FLICKER
- lightstyle(10, "mmamammmmammamamaaamammma");
- // 11 SLOW PULSE NOT FADE TO BLACK
- lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
- // New styles under here if needed:
- // styles 32-62 are assigned by the light program for switchable lights
- // 63 testing
- lightstyle(63, "a");
- }
- //============================================================================
- string LightFractionToStyle(float frac)
- {
- if(frac <= 0) return LightStyles[0];
- if(frac >= 1) return LightStyles[LightStyles_MAX];
- frac*= LightStyles.length;
- frac = floor(frac);
- return LightStyles[frac];
- }
- string LightFractionToStyleHalf(float frac)
- {
- if(frac <= 0) return LightStylesHalf[0];
- if(frac >= 1) return LightStylesHalf[LightStylesHalf_MAX];
- frac*= LightStylesHalf.length;
- frac = floor(frac);
- return LightStylesHalf[frac];
- }
- enum : int
- {
- LightRampStateOff,
- LightRampStateFadeUp,
- LightRampStateOn,
- LightRampStateFadeDown
- };
- float LIGHTRAMP_FULLRANGE = 1;
- void target_lightramp_setlight(float style, float frac)
- {
- if(self.spawnflags & LIGHTRAMP_FULLRANGE)
- lightstyle(style, LightFractionToStyle(frac));
- else
- lightstyle(style, LightFractionToStyleHalf(frac));
- }
- void target_lightramp_tick(float dt)
- {
- float diff = dt * self.delay;
- switch(self.state)
- {
- case LightRampStateFadeDown:
- self.cnt-= diff;
- break;
-
- case LightRampStateFadeUp:
- self.cnt+= diff;
- break;
- }
- target_lightramp_setlight(self.owner.style, self.cnt);
- if(self.cnt >= 1)
- {
- self.cnt = 1;
- self.state = LightRampStateOn;
- RemoveFrameTickEntity(self);
- }
- if(self.cnt <= 0)
- {
- self.cnt = 0;
- self.state = LightRampStateOff;
- RemoveFrameTickEntity(self);
- }
- }
- void target_lightramp_use()
- {
- switch(self.state)
- {
- case LightRampStateFadeDown:
- self.state = LightRampStateFadeUp;
- return;
- case LightRampStateOff:
- self.state = LightRampStateFadeUp;
- RegisterFrameTickEntity(self);
- return;
- case LightRampStateOn:
- self.state = LightRampStateFadeDown;
- RegisterFrameTickEntity(self);
- return;
-
- case LightRampStateFadeUp:
- self.state = LightRampStateFadeDown;
- return;
- }
- }
- void target_lightramp_init()
- {
- self.think = SUB_Null;
- if(!self.target) objerror("\n\ntarget_lightramp with no target.\n\n");
- if(!self.targetname) objerror("\n\ntarget_lightramp with no targetname.\n\n");
-
- self.owner = find(world, targetname, self.target);
- if(!self.owner) objerror("\n\ntarget_lightramp with unmatched target.\n\n");
- if(self.owner.spawnflags & START_OFF)
- {
- self.state = LightRampStateOff;
- self.cnt = 0;
- }
- else
- {
- self.state = LightRampStateOn;
- self.cnt = 1;
- }
-
- self.use = target_lightramp_use;
- self.tick = target_lightramp_tick;
- }
- void target_lightramp()
- {
-
- if(!self.delay) self.delay = 1;
- self.delay = 1 / self.delay;
- self.think = target_lightramp_init;
- self.nextthink = time + 0.1;
- }
- //============================================================================
- const float LIGHT_TARGETNAME_IS_STYLE = 2;
- void() light_use =
- {
- if (self.spawnflags & START_OFF)
- {
- lightstyle(self.style, "m");
- self.spawnflags = self.spawnflags - START_OFF;
- }
- else
- {
- lightstyle(self.style, "a");
- self.spawnflags = self.spawnflags + START_OFF;
- }
- };
- /*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) START_OFF
- Non-displayed light.
- Default light value is 300
- Default style is 0
- If targeted, it will toggle between on or off.
- */
- void() light =
- {
- if (!self.targetname)
- { // inert light
- remove(self);
- return;
- }
-
- if (self.style >= 32)
- {
- if(self.spawnflags & LIGHT_TARGETNAME_IS_STYLE)
- {
- lightstyle(self.style, self.targetname);
- remove(self);
- return;
- }
- self.use = light_use;
- if (self.spawnflags & START_OFF)
- lightstyle(self.style, "a");
- else
- lightstyle(self.style, "m");
- }
- };
- /*QUAKED light_fluoro (0 1 0) (-8 -8 -8) (8 8 8) START_OFF
- Non-displayed light.
- Default light value is 300
- Default style is 0
- If targeted, it will toggle between on or off.
- Makes steady fluorescent humming sound
- */
- void() light_fluoro =
- {
- if (self.style >= 32)
- {
- self.use = light_use;
- if (self.spawnflags & START_OFF)
- lightstyle(self.style, "a");
- else
- lightstyle(self.style, "m");
- }
-
- precache_sound ("ambience/fl_hum1.wav");
- ambientsound (self.origin, "ambience/fl_hum1.wav", 0.5, ATTN_STATIC);
- };
- /*QUAKED light_fluorospark (0 1 0) (-8 -8 -8) (8 8 8)
- Non-displayed light.
- Default light value is 300
- Default style is 10
- Makes sparking, broken fluorescent sound
- */
- void() light_fluorospark =
- {
- if (!self.style)
- self.style = 10;
- precache_sound ("ambience/buzz1.wav");
- ambientsound (self.origin, "ambience/buzz1.wav", 0.5, ATTN_STATIC);
- };
- /*QUAKED light_globe (0 1 0) (-8 -8 -8) (8 8 8)
- Sphere globe light.
- Default light value is 300
- Default style is 0
- */
- void() light_globe =
- {
- precache_model ("progs/s_light.spr");
- setmodel (self, "progs/s_light.spr");
- makestatic (self);
- };
- void() FireAmbient =
- {
- precache_sound ("ambience/fire1.wav");
- // attenuate fast
- ambientsound (self.origin, "ambience/fire1.wav", 0.5, ATTN_STATIC);
- };
- const float UPSIDEDOWN = 4;
- /*QUAKED light_torch_small_walltorch (0 .5 0) (-10 -10 -20) (10 10 20)
- Short wall torch
- Default light value is 200
- Default style is 0
- */
- void() light_torch_small_walltorch =
- {
- precache_model ("progs/flame.mdl");
- setmodel (self, "progs/flame.mdl");
-
- if (self.spawnflags & UPSIDEDOWN)
- self.angles = '180 0 0';
-
- FireAmbient ();
- makestatic (self);
- };
- /*QUAKED light_flame_large_yellow (0 1 0) (-10 -10 -12) (12 12 18)
- Large yellow flame ball
- */
- void() light_flame_large_yellow =
- {
- precache_model ("progs/flame2.mdl");
- setmodel (self, "progs/flame2.mdl");
- self.frame = 1;
-
- if (self.spawnflags & UPSIDEDOWN)
- self.angles = '180 0 0';
-
- FireAmbient ();
- makestatic (self);
- };
- /*QUAKED light_flame_small_yellow (0 1 0) (-8 -8 -8) (8 8 8) START_OFF
- Small yellow flame ball
- */
- void() light_flame_small_yellow =
- {
- precache_model ("progs/flame2.mdl");
- setmodel (self, "progs/flame2.mdl");
-
- if (self.spawnflags & UPSIDEDOWN)
- self.angles = '180 0 0';
-
- FireAmbient ();
- makestatic (self);
- };
- /*QUAKED light_flame_small_white (0 1 0) (-10 -10 -40) (10 10 40) START_OFF
- Small white flame ball
- */
- void() light_flame_small_white =
- {
- precache_model ("progs/flame2.mdl");
- setmodel (self, "progs/flame2.mdl");
-
- if (self.spawnflags & UPSIDEDOWN)
- self.angles = '180 0 0';
-
- FireAmbient ();
- makestatic (self);
- };
- /*QUAKED light_flame_gas (0 1 0) (-10 -10 -40) (10 10 40) START_OFF
- Gas flare (spawns two entites)
- */
- void() light_flame_gas =
- {
- precache_model ("progs/flame3.mdl");
- setmodel (self, "progs/flame3.mdl");
- self.alpha = 0.6;
- entity s = spawn();
- setorigin(s, self.origin);
- setmodel (s, "progs/flame3.mdl");
- s.alpha = 0.4;
- s.frame = 1;
- };
- /*QUAKED light_candle (0 .5 0) (-4 -4 -10) (4 4 10)
- Candle
- Default light value is 200
- Default style is 0
- */
- void() light_candle =
- {
- precache_model ("progs/candle.mdl");
- setmodel (self, "progs/candle.mdl");
- makestatic (self);
- };
|