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