]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/csqcprojectile.qc
Fix projectile colormap support
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / csqcprojectile.qc
1 #include "csqcprojectile.qh"
2
3 #include <common/t_items.qh>
4
5 #include "../command/common.qh"
6
7 #include <common/constants.qh>
8 #include <common/net_linked.qh>
9 #include <common/weapons/_all.qh>
10
11 .float csqcprojectile_type;
12
13 bool CSQCProjectile_SendEntity(entity this, entity to, int sf)
14 {
15         float ft, fr;
16
17         // note: flag 0x08 = no trail please (teleport bit)
18         sf = sf & 0x0F;
19
20         if(this.csqcprojectile_clientanimate)
21                 sf |= 0x80; // client animated, not interpolated
22
23         if(IS_ONGROUND(this))
24                 sf |= 0x40;
25
26         ft = fr = 0;
27         if(this.fade_time != 0 || this.fade_rate != 0)
28         {
29                 ft = (this.fade_time - time) / sys_frametime;
30                 fr = (1 / this.fade_rate) / sys_frametime;
31                 if(ft <= 255 && fr <= 255 && fr >= 1)
32                         sf |= 0x20;
33         }
34
35         if(this.gravity != 0)
36                 sf |= 0x10;
37
38         WriteHeader(MSG_ENTITY, ENT_CLIENT_PROJECTILE);
39         WriteByte(MSG_ENTITY, sf);
40
41         if(sf & 1)
42         {
43                 WriteCoord(MSG_ENTITY, this.origin.x);
44                 WriteCoord(MSG_ENTITY, this.origin.y);
45                 WriteCoord(MSG_ENTITY, this.origin.z);
46
47                 if(sf & 0x80)
48                 {
49                         WriteCoord(MSG_ENTITY, this.velocity.x);
50                         WriteCoord(MSG_ENTITY, this.velocity.y);
51                         WriteCoord(MSG_ENTITY, this.velocity.z);
52                         if(sf & 0x10)
53                                 WriteCoord(MSG_ENTITY, this.gravity);
54                 }
55
56                 if(sf & 0x20)
57                 {
58                         WriteByte(MSG_ENTITY, ft);
59                         WriteByte(MSG_ENTITY, fr);
60                 }
61
62                 if(teamplay)
63                         WriteByte(MSG_ENTITY, this.realowner.team);
64                 else
65                         WriteByte(MSG_ENTITY, this.realowner.clientcolors); // NOTE: doesn't work on non-clients
66         }
67
68         if(sf & 2)
69                 WriteByte(MSG_ENTITY, this.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(IS_ONGROUND(e))
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.move_movetype == MOVETYPE_TOSS || e.move_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(getSendEntity(e) == CSQCProjectile_SendEntity)
106         {
107                 // send new origin data
108                 e.SendFlags |= 0x01;
109         }
110 // FIXME HACK
111         else if(getSendEntity(e) == ItemSend)
112         {
113                 ItemUpdate(e);
114         }
115 // END HACK
116 }
117
118 void UpdateCSQCProjectileAfterTeleport(entity e)
119 {
120         if(getSendEntity(e) == CSQCProjectile_SendEntity)
121         {
122                 // send new origin data
123                 e.SendFlags |= 0x01;
124                 // mark as teleported
125                 e.SendFlags |= 0x08;
126         }
127 }