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