]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/csqcprojectile.qc
Merge branch 'TimePath/cleanup'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / csqcprojectile.qc
1 #include "csqcprojectile.qh"
2
3 #include "../t_items.qh"
4
5 #include "../command/common.qh"
6
7 #include "../../common/constants.qh"
8 #include "../../common/weapons/all.qh"
9
10 .float csqcprojectile_type;
11
12 bool CSQCProjectile_SendEntity(entity this, entity to, int sf)
13 {
14         float ft, fr;
15
16         // note: flag 0x08 = no trail please (teleport bit)
17         sf = sf & 0x0F;
18
19         if(self.csqcprojectile_clientanimate)
20                 sf |= 0x80; // client animated, not interpolated
21
22         if(self.flags & FL_ONGROUND)
23                 sf |= 0x40;
24
25         ft = fr = 0;
26         if(self.fade_time != 0 || self.fade_rate != 0)
27         {
28                 ft = (self.fade_time - time) / sys_frametime;
29                 fr = (1 / self.fade_rate) / sys_frametime;
30                 if(ft <= 255 && fr <= 255 && fr >= 1)
31                         sf |= 0x20;
32         }
33
34         if(self.gravity != 0)
35                 sf |= 0x10;
36
37         WriteByte(MSG_ENTITY, ENT_CLIENT_PROJECTILE);
38         WriteByte(MSG_ENTITY, sf);
39
40         if(sf & 1)
41         {
42                 WriteCoord(MSG_ENTITY, self.origin.x);
43                 WriteCoord(MSG_ENTITY, self.origin.y);
44                 WriteCoord(MSG_ENTITY, self.origin.z);
45
46                 if(sf & 0x80)
47                 {
48                         WriteCoord(MSG_ENTITY, self.velocity.x);
49                         WriteCoord(MSG_ENTITY, self.velocity.y);
50                         WriteCoord(MSG_ENTITY, self.velocity.z);
51                         if(sf & 0x10)
52                                 WriteCoord(MSG_ENTITY, self.gravity);
53                 }
54
55                 if(sf & 0x20)
56                 {
57                         WriteByte(MSG_ENTITY, ft);
58                         WriteByte(MSG_ENTITY, fr);
59                 }
60
61                 WriteByte(MSG_ENTITY, self.realowner.team);
62         }
63
64         if(sf & 2)
65                 WriteByte(MSG_ENTITY, self.csqcprojectile_type); // TODO maybe put this into sf?
66
67         return true;
68 }
69
70 .vector csqcprojectile_oldorigin;
71 void CSQCProjectile_Check(entity e)
72 {
73         if(e.csqcprojectile_clientanimate)
74         if(e.flags & FL_ONGROUND)
75         if(e.origin != e.csqcprojectile_oldorigin)
76                 UpdateCSQCProjectile(e);
77         e.csqcprojectile_oldorigin = e.origin;
78 }
79
80 void CSQCProjectile(entity e, float clientanimate, int type, float docull)
81 {
82         Net_LinkEntity(e, docull, 0, CSQCProjectile_SendEntity);
83
84         e.csqcprojectile_clientanimate = clientanimate;
85
86         if(e.movetype == MOVETYPE_TOSS || e.movetype == MOVETYPE_BOUNCE)
87         {
88                 if(e.gravity == 0)
89                         e.gravity = 1;
90         }
91         else
92                 e.gravity = 0;
93
94         if(!sound_allowed(MSG_BROADCAST, e))
95                 type |= 0x80;
96         e.csqcprojectile_type = type;
97 }
98
99 void UpdateCSQCProjectile(entity e)
100 {
101         if(e.SendEntity3 == CSQCProjectile_SendEntity)
102         {
103                 // send new origin data
104                 e.SendFlags |= 0x01;
105         }
106 // FIXME HACK
107         else if(e.SendEntity3 == ItemSend)
108         {
109                 ItemUpdate(e);
110         }
111 // END HACK
112 }
113
114 void UpdateCSQCProjectileAfterTeleport(entity e)
115 {
116         if(e.SendEntity3 == CSQCProjectile_SendEntity)
117         {
118                 // send new origin data
119                 e.SendFlags |= 0x01;
120                 // mark as teleported
121                 e.SendFlags |= 0x08;
122         }
123 }