]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/csqcprojectile.qc
Merge remote-tracking branch 'origin/master' into terencehill/cursormode
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / 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
53         if(sf & 2)
54                 WriteByte(MSG_ENTITY, self.csqcprojectile_type); // TODO maybe put this into sf?
55         
56         return 1;
57 }
58
59 .vector csqcprojectile_oldorigin;
60 void CSQCProjectile_Check(entity e)
61 {
62         if(e.csqcprojectile_clientanimate)
63         if(e.flags & FL_ONGROUND)
64         if(e.origin != e.csqcprojectile_oldorigin)
65                 UpdateCSQCProjectile(e);
66         e.csqcprojectile_oldorigin = e.origin;
67 }
68
69 void CSQCProjectile(entity e, float clientanimate, float type, float docull)
70 {
71         Net_LinkEntity(e, docull, 0, CSQCProjectile_SendEntity);
72         
73         e.csqcprojectile_clientanimate = clientanimate;
74         
75         if(e.movetype == MOVETYPE_TOSS || e.movetype == MOVETYPE_BOUNCE)
76         {
77                 if(e.gravity == 0)
78                         e.gravity = 1;
79         }
80         else
81                 e.gravity = 0;
82
83         if(!sound_allowed(MSG_BROADCAST, e))
84                 type |= 0x80;
85         e.csqcprojectile_type = type;
86 }
87
88 void UpdateCSQCProjectile(entity e)
89 {
90         if(e.SendEntity == CSQCProjectile_SendEntity)
91         {
92                 // send new origin data
93                 e.SendFlags |= 0x01;
94         }
95 }
96
97 void UpdateCSQCProjectileAfterTeleport(entity e)
98 {
99         if(e.SendEntity == CSQCProjectile_SendEntity)
100         {
101                 // send new origin data
102                 e.SendFlags |= 0x01;
103                 // mark as teleported
104                 e.SendFlags |= 0x08;
105         }
106 }