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