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