]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/laser.qc
Make client includes order insensitive
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / laser.qc
1 #if defined(CSQC)
2         #include "../dpdefs/csprogsdefs.qh"
3         #include "../common/buffs.qh"
4         #include "../csqcmodellib/interpolate.qh"
5         #include "hook.qh"
6         #include "main.qh"
7         #include "../csqcmodellib/cl_model.qh"
8 #elif defined(MENUQC)
9 #elif defined(SVQC)
10 #endif
11
12
13 // a laser goes from origin in direction angles
14 // it has color 'colormod'
15 // and stops when something is in the way
16 entityclass(Laser)
17 class(Laser) .int cnt; // end effect
18 class(Laser) .vector colormod;
19 class(Laser) .int state; // on-off
20 class(Laser) .int count; // flags for the laser
21 class(Laser) .vector velocity;
22 class(Laser) .float alpha;
23 class(Laser) .float scale; // scaling factor of the thickness
24 class(Laser) .float modelscale; // scaling factor of the dlight
25
26 void Draw_Laser()
27 {
28         if(!self.state)
29                 return;
30         InterpolateOrigin_Do();
31         if(self.count & 0x80)
32         {
33                 if(self.count & 0x10)
34                 {
35                         trace_endpos = self.velocity;
36                         trace_dphitq3surfaceflags = 0;
37                 }
38                 else
39                         traceline(self.origin, self.velocity, 0, self);
40         }
41         else
42         {
43                 if(self.count & 0x10)
44                 {
45                         makevectors(self.angles);
46                         trace_endpos = self.origin + v_forward * 1048576;
47                         trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
48                 }
49                 else
50                 {
51                         makevectors(self.angles);
52                         traceline(self.origin, self.origin + v_forward * 32768, 0, self);
53                         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
54                                 trace_endpos = self.origin + v_forward * 1048576;
55                 }
56         }
57         if(self.scale != 0)
58         {
59                 if(self.alpha)
60                 {
61                         Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL, view_origin);
62                 }
63                 else
64                 {
65                         Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
66                 }
67         }
68         if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
69         {
70                 if(self.cnt >= 0)
71                         pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
72                 if(self.colormod != '0 0 0' && self.modelscale != 0)
73                         adddynamiclight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
74         }
75 }
76
77 void Ent_Laser()
78 {
79         InterpolateOrigin_Undo();
80
81         // 30 bytes, or 13 bytes for just moving
82         int f = ReadByte();
83         self.count = (f & 0xF0);
84
85         if(self.count & 0x80)
86                 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
87         else
88                 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
89
90         if(f & 1)
91         {
92                 self.origin_x = ReadCoord();
93                 self.origin_y = ReadCoord();
94                 self.origin_z = ReadCoord();
95                 setorigin(self, self.origin);
96         }
97         if(f & 8)
98         {
99                 self.colormod_x = ReadByte() / 255.0;
100                 self.colormod_y = ReadByte() / 255.0;
101                 self.colormod_z = ReadByte() / 255.0;
102                 if(f & 0x40)
103                         self.alpha = ReadByte() / 255.0;
104                 else
105                         self.alpha = 0;
106                 self.scale = 2;
107                 self.modelscale = 50;
108                 if(f & 0x20)
109                 {
110                         self.scale *= ReadByte() / 16.0; // beam radius
111                         self.modelscale *= ReadByte() / 16.0; // dlight radius
112                 }
113                 if((f & 0x80) || !(f & 0x10))
114                         self.cnt = ReadShort() - 1; // effect number
115                 else
116                         self.cnt = 0;
117         }
118         if(f & 2)
119         {
120                 if(f & 0x80)
121                 {
122                         self.velocity_x = ReadCoord();
123                         self.velocity_y = ReadCoord();
124                         self.velocity_z = ReadCoord();
125                 }
126                 else
127                 {
128                         self.angles_x = ReadAngle();
129                         self.angles_y = ReadAngle();
130                 }
131         }
132         if(f & 4)
133                 self.state = ReadByte();
134         InterpolateOrigin_Note();
135         self.draw = Draw_Laser;
136 }