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