Cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / modeleffects.qc
1 #include "modeleffects.qh"
2
3 .float cnt;
4 .float scale;
5 .float alpha;
6
7 void ModelEffect_Draw(entity this)
8 {
9         self.angles = self.angles + frametime * self.avelocity;
10         setorigin(self, self.origin + frametime * self.velocity);
11         self.scale = self.scale1 + (self.scale2 - self.scale1) * (time - self.teleport_time) / (self.lifetime + self.fadetime - self.teleport_time);
12         self.alpha = self.cnt * bound(0, 1 - (time - self.lifetime) / self.fadetime, 1);
13         if(self.alpha < ALPHA_MIN_VISIBLE)
14         {
15                 remove(self);
16                 return;
17         }
18         self.drawmask = MASK_NORMAL;
19         if(self.scale <= 0)
20         {
21                 self.drawmask = 0;
22                 return;
23         }
24 }
25
26 NET_HANDLE(ENT_CLIENT_MODELEFFECT, bool isnew)
27 {
28         make_pure(self);
29
30         int f = ReadByte();
31
32         entity e = new(modeleffect);
33         e.model = "from network";
34         e.modelindex = ReadShort();
35         e.skin = ReadByte();
36         e.frame = ReadByte();
37         e.frame1time = time;
38         e.origin_x = ReadCoord();
39         e.origin_y = ReadCoord();
40         e.origin_z = ReadCoord();
41         setorigin(e, e.origin);
42         if(f & 1)
43         {
44                 e.velocity_x = ReadCoord();
45                 e.velocity_y = ReadCoord();
46                 e.velocity_z = ReadCoord();
47         }
48         if(f & 2)
49         {
50                 e.angles_x = ReadAngle();
51                 e.angles_y = ReadAngle();
52                 e.angles_z = ReadAngle();
53         }
54         if(f & 4)
55         {
56                 e.avelocity_x = ReadAngle();
57                 e.avelocity_y = ReadAngle();
58                 e.avelocity_z = ReadAngle();
59         }
60         e.scale1 = ReadShort() / 256.0;
61         e.scale2 = ReadShort() / 256.0;
62         e.lifetime = time + ReadByte() * 0.01;
63         e.fadetime = ReadByte() * 0.01;
64         e.teleport_time = time;
65         e.cnt = ReadByte() / 255.0; // actually alpha
66
67         e.draw = ModelEffect_Draw;
68
69         if (!isnew) remove(e); // yes, this IS stupid, but I don't need to duplicate all the read* stuff then
70         return true;
71 }