]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/laser.qc
Merge branch 'master' into Mario/weapons
[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 .float cnt; // end effect
5 .vector colormod;
6 .float state; // on-off
7 .float 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         float f;
67         InterpolateOrigin_Undo();
68
69         // 30 bytes, or 13 bytes for just moving
70         f = ReadByte();
71         self.count = (f & 0xF0);
72
73         if(self.count & 0x80)
74                 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
75         else
76                 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
77
78         if(f & 1)
79         {
80                 self.origin_x = ReadCoord();
81                 self.origin_y = ReadCoord();
82                 self.origin_z = ReadCoord();
83                 setorigin(self, self.origin);
84         }
85         if(f & 8)
86         {
87                 self.colormod_x = ReadByte() / 255.0;
88                 self.colormod_y = ReadByte() / 255.0;
89                 self.colormod_z = ReadByte() / 255.0;
90                 if(f & 0x40)
91                         self.alpha = ReadByte() / 255.0;
92                 else
93                         self.alpha = 0;
94                 self.scale = 2;
95                 self.modelscale = 50;
96                 if(f & 0x20)
97                 {
98                         self.scale *= ReadByte() / 16.0; // beam radius
99                         self.modelscale *= ReadByte() / 16.0; // dlight radius
100                 }
101                 if((f & 0x80) || !(f & 0x10))
102                         self.cnt = ReadShort() - 1; // effect number
103                 else
104                         self.cnt = 0;
105         }
106         if(f & 2)
107         {
108                 if(f & 0x80)
109                 {
110                         self.velocity_x = ReadCoord();
111                         self.velocity_y = ReadCoord();
112                         self.velocity_z = ReadCoord();
113                 }
114                 else
115                 {
116                         self.angles_x = ReadAngle();
117                         self.angles_y = ReadAngle();
118                 }
119         }
120         if(f & 4)
121                 self.state = ReadByte();
122         InterpolateOrigin_Note();
123         self.draw = Draw_Laser;
124 }