32119283e937833e4a10d2cd817c5a32b4299e8c
[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 // TODO move these into a heade file
14 float trace_dphitq3surfaceflags;
15 float Q3SURFACEFLAG_SKY = 4; // sky surface (also has NOIMPACT and NOMARKS set)
16 float Q3SURFACEFLAG_NOIMPACT = 16; // projectiles should remove themselves on impact (this is set on sky)
17
18 void Draw_Laser()
19 {
20         if(!self.state)
21                 return;
22         InterpolateOrigin_Do();
23         if(self.count & 0x80)
24         {
25                 if(self.count & 0x10)
26                 {
27                         trace_endpos = self.velocity,
28                         trace_dphitq3surfaceflags = 0;
29                 }
30                 else
31                         traceline(self.origin, self.velocity, 0, self);
32         }
33         else
34         {
35                 if(self.count & 0x10)
36                 {
37                         trace_endpos = self.origin + v_forward * 1048576;
38                         trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
39                 }
40                 else
41                 {
42                         makevectors(self.angles);
43                         traceline(self.origin, self.origin + v_forward * 32768, 0, self);
44                         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
45                                 trace_endpos = self.origin + v_forward * 1048576;
46                 }
47         }
48         if(self.scale != 0)
49         {
50                 if(self.alpha)
51                 {
52                         Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL, view_origin);
53                 }
54                 else
55                 {
56                         Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
57                 }
58         }
59         if not(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT))
60         {
61                 if(self.cnt >= 0)
62                         pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
63                 if(self.colormod != '0 0 0' && self.modelscale != 0)
64                         R_AddDynamicLight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
65         }
66 }
67
68 void Ent_Laser()
69 {
70         float f;
71         InterpolateOrigin_Undo();
72
73         // 30 bytes, or 13 bytes for just moving
74         f = ReadByte();
75         self.count = (f & 0xF0);
76
77         if(self.count & 0x80)
78                 self.iflags = IFLAG_VELOCITY;
79         else
80                 self.iflags = IFLAG_ANGLES;
81
82         if(f & 1)
83         {
84                 self.origin_x = ReadCoord();
85                 self.origin_y = ReadCoord();
86                 self.origin_z = ReadCoord();
87         }
88         if(f & 8)
89         {
90                 self.colormod_x = ReadByte() / 255.0;
91                 self.colormod_y = ReadByte() / 255.0;
92                 self.colormod_z = ReadByte() / 255.0;
93                 if(f & 0x40)
94                         self.alpha = ReadByte() / 255.0;
95                 else
96                         self.alpha = 0;
97                 self.scale = 2;
98                 self.modelscale = 50;
99                 if(f & 0x20)
100                 {
101                         self.scale *= ReadByte() / 16.0; // beam radius
102                         self.modelscale *= ReadByte() / 16.0; // dlight radius
103                 }
104                 self.cnt = ReadShort() - 1; // effect number
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 }