]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/server/csqcprojectile.qc
Get the swallow model working as intended. Adjustments still needed however
[voretournament/voretournament.git] / data / qcsrc / server / csqcprojectile.qc
1 .float csqcprojectile_type;\r
2 \r
3 float CSQCProjectile_SendEntity(entity to, float sf)\r
4 {\r
5         float ft, fr;\r
6 \r
7         // note: flag 0x10 = no trail please\r
8         sf = sf & 0x1F;\r
9 \r
10         if(self.csqcprojectile_clientanimate)\r
11                 sf |= 0x80; // client animated, not interpolated\r
12 \r
13         if(self.flags & FL_ONGROUND)\r
14                 sf |= 0x40;\r
15 \r
16         if(self.fade_time != 0 && self.fade_rate != 0)\r
17         {\r
18                 ft = (self.fade_time - time) / sys_frametime;\r
19                 fr = (1 / self.fade_rate) / sys_frametime;\r
20                 if(ft <= 255 && fr <= 255 && fr >= 1)\r
21                         sf |= 0x20;\r
22         }\r
23 \r
24         WriteByte(MSG_ENTITY, ENT_CLIENT_PROJECTILE);\r
25         WriteByte(MSG_ENTITY, sf);\r
26 \r
27         if(sf & 1)\r
28         {\r
29                 WriteCoord(MSG_ENTITY, self.origin_x);\r
30                 WriteCoord(MSG_ENTITY, self.origin_y);\r
31                 WriteCoord(MSG_ENTITY, self.origin_z);\r
32 \r
33                 if(sf & 0x80)\r
34                 {\r
35                         WriteCoord(MSG_ENTITY, self.velocity_x);\r
36                         WriteCoord(MSG_ENTITY, self.velocity_y);\r
37                         WriteCoord(MSG_ENTITY, self.velocity_z);\r
38                         WriteCoord(MSG_ENTITY, self.gravity);\r
39                 }\r
40 \r
41                 if(sf & 0x20)\r
42                 {\r
43                         WriteByte(MSG_ENTITY, ft);\r
44                         WriteByte(MSG_ENTITY, fr);\r
45                 }\r
46         }\r
47 \r
48         if(sf & 2)\r
49                 WriteByte(MSG_ENTITY, self.csqcprojectile_type); // TODO maybe put this into sf?\r
50         \r
51         return 1;\r
52 }\r
53 \r
54 .vector csqcprojectile_oldorigin;\r
55 void CSQCProjectile_Check(entity e)\r
56 {\r
57         if(e.csqcprojectile_clientanimate)\r
58         if(e.flags & FL_ONGROUND)\r
59         if(e.origin != e.csqcprojectile_oldorigin)\r
60                 UpdateCSQCProjectile(e);\r
61         e.csqcprojectile_oldorigin = e.origin;\r
62 }\r
63 \r
64 void CSQCProjectile(entity e, float clientanimate, float type, float docull)\r
65 {\r
66         Net_LinkEntity(e, docull, 0, CSQCProjectile_SendEntity);\r
67         \r
68         e.csqcprojectile_clientanimate = clientanimate;\r
69         \r
70         if(e.movetype == MOVETYPE_TOSS || e.movetype == MOVETYPE_BOUNCE)\r
71         {\r
72                 if(e.gravity == 0)\r
73                         e.gravity = 1;\r
74         }\r
75         else\r
76                 e.gravity = 0;\r
77 \r
78         e.csqcprojectile_type = type;\r
79         if(!sound_allowed(MSG_BROADCAST, e))\r
80                 type |= 0x80;\r
81 }\r
82 \r
83 void UpdateCSQCProjectile(entity e)\r
84 {\r
85         if(e.SendEntity == CSQCProjectile_SendEntity)\r
86         {\r
87                 // send new origin data\r
88                 e.SendFlags |= 1;\r
89         }\r
90 }\r
91 \r
92 void UpdateCSQCProjectileAfterTeleport(entity e)\r
93 {\r
94         if(e.SendEntity == CSQCProjectile_SendEntity)\r
95         {\r
96                 // send new origin data and mark as teleported\r
97                 e.SendFlags |= 0x11;\r
98         }\r
99 }\r
100 \r
101 .void(void) csqcprojectile_oldthink;\r
102 .float csqcprojectile_oldnextthink;\r
103 \r
104 void CSQCProjectile_Update_Think()\r
105 {\r
106         UpdateCSQCProjectile(self);\r
107         self.think = self.csqcprojectile_oldthink;\r
108         self.nextthink = max(time, self.csqcprojectile_oldnextthink);\r
109 }\r
110 \r
111 void UpdateCSQCProjectileNextFrame(entity e)\r
112 {\r
113         if(e.SendEntity == CSQCProjectile_SendEntity)\r
114         if(e.think != CSQCProjectile_Update_Think)\r
115         {\r
116                 e.csqcprojectile_oldthink = e.think;\r
117                 e.csqcprojectile_oldnextthink = e.nextthink;\r
118                 e.think = CSQCProjectile_Update_Think;\r
119                 e.nextthink = time;\r
120         }\r
121 }\r