Remove `-Wno-double-declaration`
[xonotic/xonotic-data.pk3dir.git] / qcsrc / warpzonelib / client.qc
1 void WarpZone_Fade_PreDraw()
2 {
3         vector org;
4         org = getpropertyvec(VF_ORIGIN);
5         if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
6                 self.alpha = 0;
7         else if(self.warpzone_fadestart)
8                 self.alpha = bound(0, (self.warpzone_fadeend - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.warpzone_fadeend - self.warpzone_fadestart), 1);
9         else
10                 self.alpha = 1;
11         //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
12         if(self.alpha <= 0)
13                 self.drawmask = 0;
14         else
15                 self.drawmask = MASK_NORMAL;
16 }
17
18 void WarpZone_Read(float isnew)
19 {
20         warpzone_warpzones_exist = 1;
21         if (!self.enemy)
22         {
23                 self.enemy = spawn();
24                 self.enemy.classname = "warpzone_from";
25         }
26         self.classname = "trigger_warpzone";
27
28         int f = ReadByte();
29         self.warpzone_isboxy = (f & 1);
30         if(f & 4)
31         {
32                 self.origin_x = ReadCoord();
33                 self.origin_y = ReadCoord();
34                 self.origin_z = ReadCoord();
35         }
36         else
37                 self.origin = '0 0 0';
38         self.modelindex = ReadShort();
39         self.mins_x = ReadCoord();
40         self.mins_y = ReadCoord();
41         self.mins_z = ReadCoord();
42         self.maxs_x = ReadCoord();
43         self.maxs_y = ReadCoord();
44         self.maxs_z = ReadCoord();
45         self.scale = ReadByte() / 16;
46         self.enemy.oldorigin_x = ReadCoord();
47         self.enemy.oldorigin_y = ReadCoord();
48         self.enemy.oldorigin_z = ReadCoord();
49         self.enemy.avelocity_x = ReadCoord();
50         self.enemy.avelocity_y = ReadCoord();
51         self.enemy.avelocity_z = ReadCoord();
52         self.oldorigin_x = ReadCoord();
53         self.oldorigin_y = ReadCoord();
54         self.oldorigin_z = ReadCoord();
55         self.avelocity_x = ReadCoord();
56         self.avelocity_y = ReadCoord();
57         self.avelocity_z = ReadCoord();
58
59         if(f & 2)
60         {
61                 self.warpzone_fadestart = ReadShort();
62                 self.warpzone_fadeend = max(self.warpzone_fadestart + 1, ReadShort());
63         }
64         else
65         {
66                 self.warpzone_fadestart = 0;
67                 self.warpzone_fadeend = 0;
68         }
69
70         // common stuff
71         WarpZone_SetUp(self, self.enemy.oldorigin, self.enemy.avelocity, self.oldorigin, self.avelocity);
72
73         // link me
74         //setmodel(self, self.model);
75         setorigin(self, self.origin);
76         setsize(self, self.mins, self.maxs);
77
78         // how to draw
79         // engine currently wants this
80         self.predraw = WarpZone_Fade_PreDraw;
81 }
82
83 void WarpZone_Camera_Read(float isnew)
84 {
85         warpzone_cameras_exist = 1;
86         self.classname = "func_warpzone_camera";
87
88         int f = ReadByte();
89         if(f & 4)
90         {
91                 self.origin_x = ReadCoord();
92                 self.origin_y = ReadCoord();
93                 self.origin_z = ReadCoord();
94         }
95         else
96                 self.origin = '0 0 0';
97         self.modelindex = ReadShort();
98         self.mins_x = ReadCoord();
99         self.mins_y = ReadCoord();
100         self.mins_z = ReadCoord();
101         self.maxs_x = ReadCoord();
102         self.maxs_y = ReadCoord();
103         self.maxs_z = ReadCoord();
104         self.scale = ReadByte() / 16;
105         self.oldorigin_x = ReadCoord();
106         self.oldorigin_y = ReadCoord();
107         self.oldorigin_z = ReadCoord();
108         self.avelocity_x = ReadCoord();
109         self.avelocity_y = ReadCoord();
110         self.avelocity_z = ReadCoord();
111
112         if(f & 2)
113         {
114                 self.warpzone_fadestart = ReadShort();
115                 self.warpzone_fadeend = max(self.warpzone_fadestart + 1, ReadShort());
116         }
117         else
118         {
119                 self.warpzone_fadestart = 0;
120                 self.warpzone_fadeend = 0;
121         }
122
123         // common stuff
124         WarpZone_Camera_SetUp(self, self.oldorigin, self.avelocity);
125
126         // engine currently wants this
127         self.drawmask = MASK_NORMAL;
128
129         // link me
130         //setmodel(self, self.model);
131         setorigin(self, self.origin);
132         setsize(self, self.mins, self.maxs);
133
134         // how to draw
135         // engine currently wants this
136         self.predraw = WarpZone_Fade_PreDraw;
137 }
138
139 void CL_RotateMoves(vector ang) = #638;
140 void WarpZone_Teleported_Read(float isnew)
141 {
142         vector v;
143         self.classname = "warpzone_teleported";
144         v_x = ReadCoord();
145         v_y = ReadCoord();
146         v_z = ReadCoord();
147         if(!isnew)
148                 return;
149         self.warpzone_transform = v;
150         setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(self, getpropertyvec(VF_CL_VIEWANGLES)));
151         if(checkextension("DP_CSQC_ROTATEMOVES"))
152                 CL_RotateMoves(v);
153                 //CL_RotateMoves('0 90 0');
154 }
155
156 float warpzone_fixingview;
157 float warpzone_fixingview_drawexteriormodel;
158
159 void WarpZone_View_Outside()
160 {
161         if(!warpzone_fixingview)
162                 return;
163         warpzone_fixingview = 0;
164         cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel));
165 }
166
167 void WarpZone_View_Inside()
168 {
169         if(autocvar_chase_active)
170         {
171                 WarpZone_View_Outside();
172                 return;
173         }
174         if(warpzone_fixingview)
175                 return;
176         warpzone_fixingview = 1;
177         warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel");
178         cvar_set("r_drawexteriormodel", "0");
179 }
180
181 vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3)
182 {
183         vector mi, ma;
184         entity e;
185         float pd;
186
187         mi_x = min(o.x, c0_x, c1_x, c2_x, c3_x);
188         ma_x = max(o.x, c0_x, c1_x, c2_x, c3_x);
189         mi_y = min(o.y, c0_y, c1_y, c2_y, c3_y);
190         ma_y = max(o.y, c0_y, c1_y, c2_y, c3_y);
191         mi_z = min(o.z, c0_z, c1_z, c2_z, c3_z);
192         ma_z = max(o.z, c0_z, c1_z, c2_z, c3_z);
193
194         e = WarpZone_Find(mi, ma);
195         if(e)
196         {
197                 if(WarpZone_PlaneDist(e, o) < 0)
198                         return '0 0 0';
199                         // can't really be, though, but if it is, this is not my warpzone, but a random different one in the same mins/maxs
200                 pd = min(
201                                 WarpZone_PlaneDist(e, c0),
202                                 WarpZone_PlaneDist(e, c1),
203                                 WarpZone_PlaneDist(e, c2),
204                                 WarpZone_PlaneDist(e, c3)
205                         );
206                 if(pd < 0)
207                         return e.warpzone_forward * -pd;
208         }
209
210         return '0 0 0';
211 }
212
213 void WarpZone_FixPMove()
214 {
215         entity e;
216         e = WarpZone_Find(pmove_org, pmove_org);
217         if(e)
218         {
219                 pmove_org = WarpZone_TransformOrigin(e, pmove_org);
220                 input_angles = WarpZone_TransformVAngles(e, input_angles);
221         }
222 }
223
224 #ifndef KEEP_ROLL
225 float autocvar_cl_rollkillspeed = 10;
226 #endif
227 void WarpZone_FixView()
228 {
229         entity e;
230         vector org, ang, nearclip, corner0, corner1, corner2, corner3, o;
231         float f;
232
233         warpzone_save_view_origin = org = getpropertyvec(VF_ORIGIN);
234         warpzone_save_view_angles = ang = getpropertyvec(VF_ANGLES);
235
236         e = WarpZone_Find(org, org);
237         if(e)
238         {
239                 org = WarpZone_TransformOrigin(e, org);
240                 ang = WarpZone_TransformVAngles(e, ang);
241                 WarpZone_View_Inside();
242         }
243         else
244                 WarpZone_View_Outside();
245
246 #ifndef KEEP_ROLL
247         float rick;
248         if(autocvar_cl_rollkillspeed)
249                 f = max(0, (1 - frametime * autocvar_cl_rollkillspeed));
250         else
251                 f = 0;
252
253         rick = getproperty(VF_CL_VIEWANGLES_Z);
254         rick *= f;
255         setproperty(VF_CL_VIEWANGLES_Z, rick);
256         ang.z *= f;
257 #endif
258
259         setproperty(VF_ORIGIN, org);
260         setproperty(VF_ANGLES, ang);
261
262         nearclip = '0 0 1' * (cvar("r_nearclip") * 1.125);
263         corner0 = cs_unproject('0 0 0' + nearclip);
264         corner1 = cs_unproject('1 0 0' * cvar("vid_conwidth") + nearclip);
265         corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip);
266         corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip);
267         o = WarpZone_FixNearClip(org, corner0, corner1, corner2, corner3);
268         if(o != '0 0 0')
269                 setproperty(VF_ORIGIN, org + o);
270 }
271
272 void WarpZone_Init()
273 {
274 }
275
276 void WarpZone_Shutdown()
277 {
278         WarpZone_View_Outside();
279 }