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