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