]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/laser.qc
more alpha again
[divverent/nexuiz.git] / data / 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                 traceline(self.origin, self.velocity, 0, self);
26         }
27         else
28         {
29                 makevectors(self.angles);
30                 traceline(self.origin, self.origin + v_forward * 32768, 0, self);
31                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
32                         trace_endpos = self.origin + v_forward * 1048576;
33         }
34         if(self.scale != 0)
35         {
36                 if(self.alpha)
37                 {
38                         Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL); // TODO make a texture to make the laser look smoother
39                 }
40                 else
41                 {
42                         Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE); // TODO make a texture to make the laser look smoother
43                 }
44         }
45         if not(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT))
46         {
47                 if(self.cnt >= 0)
48                         pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
49                 if(self.colormod != '0 0 0' && self.modelscale != 0)
50                         R_AddDynamicLight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
51         }
52 }
53
54 void Ent_Laser()
55 {
56         float f;
57         InterpolateOrigin_Undo();
58
59         // 30 bytes, or 13 bytes for just moving
60         f = ReadByte();
61         self.count = (f & 0xE0);
62
63         if(self.count & 0x80)
64                 self.iflags = IFLAG_VELOCITY;
65         else
66                 self.iflags = IFLAG_ANGLES;
67
68         if(f & 1)
69         {
70                 self.origin_x = ReadCoord();
71                 self.origin_y = ReadCoord();
72                 self.origin_z = ReadCoord();
73         }
74         if(f & 8)
75         {
76                 self.colormod_x = ReadByte() / 255.0;
77                 self.colormod_y = ReadByte() / 255.0;
78                 self.colormod_z = ReadByte() / 255.0;
79                 if(f & 0x40)
80                         self.alpha = ReadByte() / 255.0;
81                 else
82                         self.alpha = 0;
83                 self.scale = 2;
84                 self.modelscale = 50;
85                 if(f & 0x20)
86                 {
87                         self.scale *= ReadByte() / 16.0; // beam radius
88                         self.modelscale *= ReadByte() / 16.0; // dlight radius
89                 }
90                 self.cnt = ReadShort() - 1; // effect number
91         }
92         if(f & 2)
93         {
94                 if(f & 0x80)
95                 {
96                         self.velocity_x = ReadCoord();
97                         self.velocity_y = ReadCoord();
98                         self.velocity_z = ReadCoord();
99                 }
100                 else
101                 {
102                         self.angles_x = ReadAngle();
103                         self.angles_y = ReadAngle();
104                 }
105         }
106         if(f & 4)
107                 self.state = ReadByte();
108         InterpolateOrigin_Note();
109         self.draw = Draw_Laser;
110 }