]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/csqcprojectile.qc
Merge branch 'DefaultUser/more_damagetext' into 'master'
[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                 WriteByte(MSG_ENTITY, this.realowner.team);
63         }
64
65         if(sf & 2)
66                 WriteByte(MSG_ENTITY, this.csqcprojectile_type); // TODO maybe put this into sf?
67
68         return true;
69 }
70
71 .vector csqcprojectile_oldorigin;
72 void CSQCProjectile_Check(entity e)
73 {
74         if(e.csqcprojectile_clientanimate)
75         if(IS_ONGROUND(e))
76         if(e.origin != e.csqcprojectile_oldorigin)
77                 UpdateCSQCProjectile(e);
78         e.csqcprojectile_oldorigin = e.origin;
79 }
80
81 void CSQCProjectile(entity e, float clientanimate, int type, float docull)
82 {
83         Net_LinkEntity(e, docull, 0, CSQCProjectile_SendEntity);
84
85         e.csqcprojectile_clientanimate = clientanimate;
86
87         if(e.move_movetype == MOVETYPE_TOSS || e.move_movetype == MOVETYPE_BOUNCE)
88         {
89                 if(e.gravity == 0)
90                         e.gravity = 1;
91         }
92         else
93                 e.gravity = 0;
94
95         if(!sound_allowed(MSG_BROADCAST, e))
96                 type |= 0x80;
97         e.csqcprojectile_type = type;
98 }
99
100 void UpdateCSQCProjectile(entity e)
101 {
102         if(getSendEntity(e) == CSQCProjectile_SendEntity)
103         {
104                 // send new origin data
105                 e.SendFlags |= 0x01;
106         }
107 // FIXME HACK
108         else if(getSendEntity(e) == ItemSend)
109         {
110                 ItemUpdate(e);
111         }
112 // END HACK
113 }
114
115 void UpdateCSQCProjectileAfterTeleport(entity e)
116 {
117         if(getSendEntity(e) == CSQCProjectile_SendEntity)
118         {
119                 // send new origin data
120                 e.SendFlags |= 0x01;
121                 // mark as teleported
122                 e.SendFlags |= 0x08;
123         }
124 }