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