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