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