Xonotic
csqcprojectile.qc
Go to the documentation of this file.
1 #include "csqcprojectile.qh"
2 
3 #include <common/constants.qh>
4 #include <common/net_linked.qh>
5 #include <common/stats.qh>
6 #include <common/weapons/_all.qh>
7 #include <common/weapons/_all.qh>
9 #include <server/items/items.qh>
10 
12 
14 {
15  float ft, fr;
16 
17  // note: flag 0x08 = no trail please (teleport bit)
18  sf = sf & 0x0F;
19 
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  WriteVector(MSG_ENTITY, this.origin);
44 
45  if(sf & 0x80)
46  {
47  WriteVector(MSG_ENTITY, this.velocity);
48  if(sf & 0x10)
49  WriteCoord(MSG_ENTITY, this.gravity);
50  }
51 
52  if(sf & 0x20)
53  {
54  WriteByte(MSG_ENTITY, ft);
55  WriteByte(MSG_ENTITY, fr);
56  }
57 
58  if(teamplay)
59  WriteByte(MSG_ENTITY, this.realowner.team);
60  else
61  WriteByte(MSG_ENTITY, this.realowner.clientcolors); // NOTE: doesn't work on non-clients
62  }
63 
64  if(sf & 2)
65  WriteByte(MSG_ENTITY, this.csqcprojectile_type); // TODO maybe put this into sf?
66 
67  return true;
68 }
69 
72 {
73  if(e.csqcprojectile_clientanimate)
74  if(IS_ONGROUND(e))
75  if(e.origin != e.csqcprojectile_oldorigin)
77  e.csqcprojectile_oldorigin = e.origin;
78 }
79 
80 void CSQCProjectile(entity e, float clientanimate, int type, float docull)
81 {
82  Net_LinkEntity(e, docull, 0, CSQCProjectile_SendEntity);
83 
84  e.csqcprojectile_clientanimate = clientanimate;
85 
86  if(e.move_movetype == MOVETYPE_TOSS || e.move_movetype == MOVETYPE_BOUNCE)
87  {
88  if(e.gravity == 0)
89  e.gravity = 1;
90  }
91  else
92  e.gravity = 0;
93 
94  if(!sound_allowed(MSG_BROADCAST, e))
95  type |= 0x80;
96  e.csqcprojectile_type = type;
97 }
98 
100 {
102  {
103  // send new origin data
104  e.SendFlags |= 0x01;
105  }
106 // FIXME HACK
107  else if(getSendEntity(e) == ItemSend)
108  {
109  ItemUpdate(e);
110  }
111 // END HACK
112 }
113 
115 {
117  {
118  // send new origin data
119  e.SendFlags |= 0x01;
120  // send full data as the projectile may need resetting
121  // this is a workaround for client-side projectiles erroneously calling their SUB_Stop touch function occasionally
122  // when passing through a warpzone
123  e.SendFlags |= 2;
124  // mark as teleported
125  e.SendFlags |= 0x08;
126  }
127 }
float MOVETYPE_TOSS
Definition: progsdefs.qc:252
fade_rate
Definition: projectile.qh:14
entity() spawn
#define IS_ONGROUND(s)
Definition: movetypes.qh:16
void CSQCProjectile_Check(entity e)
entity to
Definition: self.qh:96
origin
Definition: ent_cs.qc:114
float MOVETYPE_BOUNCE
Definition: progsdefs.qc:256
void CSQCProjectile(entity e, float clientanimate, int type, float docull)
float sys_frametime
Definition: common.qh:57
void UpdateCSQCProjectile(entity e)
bool CSQCProjectile_SendEntity(entity this, entity to, int sf)
vector csqcprojectile_oldorigin
float teamplay
Definition: progsdefs.qc:31
void ItemUpdate(entity this)
Definition: items.qc:86
bool ItemSend(entity this, entity to, int sf)
Definition: items.qc:31
float gravity
Definition: items.qh:16
#define getSendEntity(e)
Definition: self.qh:98
float fade_time
Definition: common.qh:22
entity realowner
Definition: common.qh:25
void UpdateCSQCProjectileAfterTeleport(entity e)
float csqcprojectile_type
float csqcprojectile_clientanimate
float time
Definition: csprogsdefs.qc:16
vector velocity
Definition: csprogsdefs.qc:103