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