]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/warpzonelib/client.qc
rewrote warpzonelib view fixing
[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 void WarpZone_View_Inside()
168 {
169         if(warpzone_fixingview)
170                 return;
171         warpzone_fixingview = 1;
172         warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel");
173         cvar_set("r_drawexteriormodel", "0");
174 }
175
176 void WarpZone_View_Outside()
177 {
178         if(!warpzone_fixingview)
179                 return;
180         warpzone_fixingview = 0;
181         cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel));
182         //cvar_set("cl_sidespeed", ftos(warpzone_fixingview_sidespeed));
183         //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed));
184 }
185
186 vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3)
187 {
188         vector mi, ma;
189         entity e;
190         float pd;
191
192         mi_x = min5(o_x, c0_x, c1_x, c2_x, c3_x);
193         ma_x = max5(o_x, c0_x, c1_x, c2_x, c3_x);
194         mi_y = min5(o_y, c0_y, c1_y, c2_y, c3_y);
195         ma_y = max5(o_y, c0_y, c1_y, c2_y, c3_y);
196         mi_z = min5(o_z, c0_z, c1_z, c2_z, c3_z);
197         ma_z = max5(o_z, c0_z, c1_z, c2_z, c3_z);
198
199         e = WarpZone_Find(mi, ma);
200         if(e)
201         {
202                 if(WarpZone_PlaneDist(e, o) < 0)
203                         return '0 0 0';
204                         // can't really be, though, but if it is, this is not my warpzone, but a random different one in the same mins/maxs
205                 pd = min4(
206                                 WarpZone_PlaneDist(e, c0),
207                                 WarpZone_PlaneDist(e, c1),
208                                 WarpZone_PlaneDist(e, c2),
209                                 WarpZone_PlaneDist(e, c3)
210                         );
211                 if(pd < 0)
212                         return e.warpzone_forward * -pd;
213         }
214
215         return '0 0 0';
216 }
217
218 void WarpZone_FixPMove()
219 {
220         entity e;
221         e = WarpZone_Find(pmove_org, pmove_org);
222         if(e)
223         {
224                 pmove_org = WarpZone_TransformOrigin(e, pmove_org);
225                 input_angles = WarpZone_TransformVAngles(e, input_angles);
226         }
227 }
228
229 #ifndef KEEP_ROLL
230 var float autocvar_cl_rollkillspeed = 10;
231 #endif
232 void WarpZone_FixView()
233 {
234         entity e;
235         vector org, ang, nearclip, corner0, corner1, corner2, corner3, o;
236         float f;
237
238         org = R_SetView3fv(VF_ORIGIN);
239         ang = R_SetView3fv(VF_ANGLES);
240
241         e = WarpZone_Find(org, org);
242         if(e)
243         {
244                 org = WarpZone_TransformOrigin(e, org);
245                 ang = WarpZone_TransformVAngles(e, ang);
246                 WarpZone_View_Inside();
247         }
248         else
249                 WarpZone_View_Outside();
250
251 #ifndef KEEP_ROLL
252         float rick;
253         if(autocvar_cl_rollkillspeed)
254                 f = max(0, (1 - frametime * autocvar_cl_rollkillspeed));
255         else
256                 f = 0;
257
258         rick = R_SetView(VF_CL_VIEWANGLES_Z);
259         rick *= f;
260         R_SetView(VF_CL_VIEWANGLES_Z, rick);
261
262         ang_z *= f;
263 #endif
264
265         R_SetView(VF_ORIGIN, org);
266         R_SetView(VF_ANGLES, ang);
267
268         nearclip = '0 0 1' * (cvar("r_nearclip") * 1.125);
269         corner0 = cs_unproject('0 0 0' + nearclip);
270         corner1 = cs_unproject('1 0 0' * cvar("vid_conwidth") + nearclip);
271         corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip);
272         corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip);
273         o = WarpZone_FixNearClip(org, corner0, corner1, corner2, corner3);
274         if(o != '0 0 0')
275                 R_SetView(VF_ORIGIN, org + o);
276 }
277
278 void WarpZone_Init()
279 {
280 }
281
282 void WarpZone_Shutdown()
283 {
284         WarpZone_View_Outside();
285 }