]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_lights.qc
Merge branch 'master' into terencehill/accuracy_shotgun
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_lights.qc
1 #include "g_lights.qh"
2
3 #include <server/defs.qh>
4 #include <server/miscfunctions.qh>
5
6 void train_next(entity this);
7
8 const float LOOP = 1;
9
10 .float speed;
11
12 const float DNOSHADOW = 2;
13 const float DFOLLOW = 4;
14 .float light_lev;
15 .float lefty;
16 .vector color;
17 .string dtagname;
18
19 /*QUAKED dynlight (0 1 0) (-8 -8 -8) (8 8 8) START_OFF NOSHADOW FOLLOW
20 Dynamic spawnfunc_light.
21 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.
22 It can spin around it's own axis in all the above cases.
23 If targeted, it will toggle between on or off.
24 keys:
25 "light_lev" spawnfunc_light radius, default 200
26 "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
27 "style" lightstyle, same as for static lights
28 "angles" initial orientation
29 "avelocity" a vector value, the direction and speed it rotates in
30 "skin" cubemap number, must be 16 or above
31 "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
32 "targetname" will toggle on and off when triggered
33 "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
34 "speed" the speed it will travel along the path, default 100
35 flags:
36 "START_OFF" spawnfunc_light will be in off state until targeted
37 "NOSHADOW" will not cast shadows in realtime lighting mode
38 "FOLLOW" will follow the entity which "targetname" matches "target"
39 */
40 void dynlight_think(entity this)
41 {
42         if(!this.owner)
43                 delete(this);
44
45         this.nextthink = time + 0.1;
46 }
47 void dynlight_find_aiment(entity this)
48 {
49         entity targ;
50         if (!this.target)
51                 objerror (this, "dynlight: no target to follow");
52
53         targ = find(NULL, targetname, this.target);
54         set_movetype(this, MOVETYPE_FOLLOW);
55         this.aiment = targ;
56         this.owner = targ;
57         this.punchangle = targ.angles;
58         this.view_ofs = this.origin - targ.origin;
59         this.v_angle = this.angles - targ.angles;
60         setthink(this, dynlight_think);
61         this.nextthink = time + 0.1;
62 }
63 void dynlight_find_path(entity this)
64 {
65         entity targ;
66         if (!this.target)
67                 objerror (this, "dynlight: no target to follow");
68
69         targ = find(NULL, targetname, this.target);
70         this.target = targ.target;
71         setorigin(this, targ.origin);
72         setthink(this, train_next);
73         this.nextthink = time + 0.1;
74 }
75 void dynlight_find_target(entity this)
76 {
77         entity targ;
78         if (!this.target)
79                 objerror (this, "dynlight: no target to follow");
80
81         targ = find(NULL, targetname, this.target);
82         setattachment(this, targ, this.dtagname);
83         this.owner = targ;
84         setthink(this, dynlight_think);
85         this.nextthink = time + 0.1;
86 }
87 void dynlight_use(entity this, entity actor, entity trigger)
88 {
89         if (this.light_lev == 0)
90                 this.light_lev = this.lefty;
91         else
92                 this.light_lev = 0;
93 }
94 spawnfunc(dynlight)
95 {
96         if (!this.light_lev)
97                 this.light_lev = 200;
98         if (!this.color)
99                 this.color = '1 1 1';
100         this.lefty = this.light_lev;
101         this.use = dynlight_use;
102         setsize (this, '0 0 0', '0 0 0');
103         setorigin(this, this.origin);
104         //this.pflags = PFLAGS_FULLDYNAMIC;
105         this.solid = SOLID_NOT;
106         //this.blocked = func_null;
107         //if (this.spawnflags & DNOSHADOW)
108         //      this.pflags = this.pflags + PFLAGS_NOSHADOW;
109         //if (this.spawnflags & START_OFF)
110         //      this.light_lev = 0;
111
112 //tag attaching
113         if (this.dtagname)
114         {
115                 InitializeEntity(this, dynlight_find_target, INITPRIO_FINDTARGET);
116                 return;
117         }
118
119 // entity following
120         if (this.spawnflags & DFOLLOW)
121         {
122                 InitializeEntity(this, dynlight_find_aiment, INITPRIO_FINDTARGET);
123                 return;
124         }
125 // path following
126         if (this.target)
127 //      if (!(this.spawnflags & DFOLLOW))
128         {
129                 set_movetype(this, MOVETYPE_NOCLIP);
130                 if (!this.speed)
131                         this.speed = 100;
132                 InitializeEntity(this, dynlight_find_path, INITPRIO_FINDTARGET);
133                 return;
134         }
135 }