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