]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_lights.qc
Merge branch 'master' into TimePath/unified_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_lights.qc
1 #include "_all.qh"
2
3 void train_next();
4
5 const float LOOP = 1;
6
7 const float DNOSHADOW = 2;
8 const float DFOLLOW = 4;
9 .float light_lev;
10 .float lefty;
11 .vector color;
12 .string dtagname;
13
14 /*QUAKED dynlight (0 1 0) (-8 -8 -8) (8 8 8) START_OFF NOSHADOW FOLLOW
15 Dynamic spawnfunc_light.
16 Can do one of these things: sit still and be just a silly spawnfunc_light, travel along a path, follow an entity around, attach to a tag on an entity.
17 It can spin around it's own axis in all the above cases.
18 If targeted, it will toggle between on or off.
19 keys:
20 "light_lev" spawnfunc_light radius, default 200
21 "color" spawnfunc_light color in rgb and brightness, 1 1 1 produces bright white, up to 255 255 255 (nuclear blast), recommended values up to 1 1 1, default 1 1 1
22 "style" lightstyle, same as for static lights
23 "angles" initial orientation
24 "avelocity" a vector value, the direction and speed it rotates in
25 "skin" cubemap number, must be 16 or above
26 "dtagname" will attach to this tag on the entity which "targetname" matches "target". If the "target" is either not an md3 model or is missing tags, it will attach to the targets origin. Note that the "target" must be visible to the spawnfunc_light
27 "targetname" will toggle on and off when triggered
28 "target" if issued with a target, preferrably spawnfunc_path_corner, it will move along the path. If also issued with the FOLLOW spawnflag, then this is the entity it will follow. If issued with the "tagname" key it will attach it to this targets tag called "tagname", does not work together with FOLLOW or path movement
29 "speed" the speed it will travel along the path, default 100
30 flags:
31 "START_OFF" spawnfunc_light will be in off state until targeted
32 "NOSHADOW" will not cast shadows in realtime lighting mode
33 "FOLLOW" will follow the entity which "targetname" matches "target"
34 */
35 void dynlight_think()
36 {
37         if(!self.owner)
38                 remove(self);
39
40         self.nextthink = time + 0.1;
41 }
42 void dynlight_find_aiment()
43 {
44         entity targ;
45         if (!self.target)
46                 objerror ("dynlight: no target to follow");
47
48         targ = find(world, targetname, self.target);
49         self.movetype = MOVETYPE_FOLLOW;
50         self.aiment = targ;
51         self.owner = targ;
52         self.punchangle = targ.angles;
53         self.view_ofs = self.origin - targ.origin;
54         self.v_angle = self.angles - targ.angles;
55         self.think = dynlight_think;
56         self.nextthink = time + 0.1;
57 }
58 void dynlight_find_path()
59 {
60         entity targ;
61         if (!self.target)
62                 objerror ("dynlight: no target to follow");
63
64         targ = find(world, targetname, self.target);
65         self.target = targ.target;
66         setorigin (self, targ.origin);
67         self.think = train_next;
68         self.nextthink = time + 0.1;
69 }
70 void dynlight_find_target()
71 {
72         entity targ;
73         if (!self.target)
74                 objerror ("dynlight: no target to follow");
75
76         targ = find(world, targetname, self.target);
77         setattachment(self, targ, self.dtagname);
78         self.owner = targ;
79         self.think = dynlight_think;
80         self.nextthink = time + 0.1;
81 }
82 void dynlight_use()
83 {
84         if (self.light_lev == 0)
85                 self.light_lev = self.lefty;
86         else
87                 self.light_lev = 0;
88 }
89 spawnfunc(dynlight)
90 {
91         if (!self.light_lev)
92                 self.light_lev = 200;
93         if (!self.color)
94                 self.color = '1 1 1';
95         self.lefty = self.light_lev;
96         self.use = dynlight_use;
97         setsize (self, '0 0 0', '0 0 0');
98         setorigin (self, self.origin);
99         //self.pflags = PFLAGS_FULLDYNAMIC;
100         self.solid = SOLID_NOT;
101         //self.blocked = func_null;
102         //if (self.spawnflags & DNOSHADOW)
103         //      self.pflags = self.pflags + PFLAGS_NOSHADOW;
104         //if (self.spawnflags & START_OFF)
105         //      self.light_lev = 0;
106
107 //tag attaching
108         if (self.dtagname)
109         {
110                 InitializeEntity(self, dynlight_find_target, INITPRIO_FINDTARGET);
111                 return;
112         }
113
114 // entity following
115         if (self.spawnflags & DFOLLOW)
116         {
117                 InitializeEntity(self, dynlight_find_aiment, INITPRIO_FINDTARGET);
118                 return;
119         }
120 // path following
121         if (self.target)
122 //      if (!(self.spawnflags & DFOLLOW))
123         {
124                 self.movetype = MOVETYPE_NOCLIP;
125                 if (!self.speed)
126                         self.speed = 100;
127                 InitializeEntity(self, dynlight_find_path, INITPRIO_FINDTARGET);
128                 return;
129         }
130 }