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