]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/weapons/csqcprojectile.qc
Update default video settings
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / csqcprojectile.qc
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>
8 #include <server/command/common.qh>
9 #include <server/items/items.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                 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
70 .vector csqcprojectile_oldorigin;
71 void CSQCProjectile_Check(entity e)
72 {
73         if(e.csqcprojectile_clientanimate)
74         if(IS_ONGROUND(e))
75         if(e.origin != e.csqcprojectile_oldorigin)
76                 UpdateCSQCProjectile(e);
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
99 void UpdateCSQCProjectile(entity e)
100 {
101         if(getSendEntity(e) == CSQCProjectile_SendEntity)
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
114 void UpdateCSQCProjectileAfterTeleport(entity e)
115 {
116         if(getSendEntity(e) == CSQCProjectile_SendEntity)
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 }