]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/warpzone/client.qc
Merge branch 'AriosJentu/DisconnectDialog' into 'master'
[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         if(!warpzone_warpzones_exist)
32         {
33                 cvar_settemp("r_water", "1"); // HACK for DarkPlaces: always enable reflections when a map has warpzones
34                 cvar_settemp("r_water_resolutionmultiplier", "1"); // HACK for DarkPlaces: enforce full quality so entities can be seen clearly through warpzones
35         }
36         warpzone_warpzones_exist = 1;
37         if (!this.enemy)
38         {
39                 this.enemy = new(warpzone_from);
40         }
41         this.classname = "trigger_warpzone";
42
43         if(isnew)
44                 IL_PUSH(g_warpzones, this);
45
46         int f = ReadByte();
47         this.warpzone_isboxy = (f & 1);
48         if(f & 4)
49         {
50                 this.origin = ReadVector();
51         }
52         else
53                 this.origin = '0 0 0';
54         this.modelindex = ReadShort();
55         this.mins = ReadVector();
56         this.maxs = ReadVector();
57         this.scale = ReadByte() / 16;
58         this.enemy.oldorigin = ReadVector();
59         this.enemy.avelocity = ReadVector();
60         this.oldorigin = ReadVector();
61         this.avelocity = ReadVector();
62
63         if(f & 2)
64         {
65                 this.warpzone_fadestart = ReadShort();
66                 this.warpzone_fadeend = max(this.warpzone_fadestart + 1, ReadShort());
67         }
68         else
69         {
70                 this.warpzone_fadestart = 0;
71                 this.warpzone_fadeend = 0;
72         }
73
74         // common stuff
75         WarpZone_SetUp(this, this.enemy.oldorigin, this.enemy.avelocity, this.oldorigin, this.avelocity);
76
77         // link me
78         //setmodel(this, this.model);
79         setorigin(this, this.origin);
80         setsize(this, this.mins, this.maxs);
81
82         // how to draw
83         // engine currently wants this
84         setpredraw(this, WarpZone_Fade_PreDraw);
85
86         //settouch(this, WarpZone_Touch);
87         return true;
88 }
89
90 NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew)
91 {
92         if(!warpzone_cameras_exist)
93         {
94                 cvar_settemp("r_water", "1"); // HACK for DarkPlaces: always enable reflections when a map has cameras
95                 cvar_settemp("r_water_resolutionmultiplier", "1"); // HACK for DarkPlaces: enforce full quality so entities can be seen clearly through warpzones
96         }
97         warpzone_cameras_exist = 1;
98         this.classname = "func_warpzone_camera";
99
100         int f = ReadByte();
101         if(f & 4)
102         {
103                 this.origin = ReadVector();
104         }
105         else
106                 this.origin = '0 0 0';
107         this.modelindex = ReadShort();
108         this.mins = ReadVector();
109         this.maxs = ReadVector();
110         this.scale = ReadByte() / 16;
111         this.oldorigin = ReadVector();
112         this.avelocity = ReadVector();
113
114         if(f & 2)
115         {
116                 this.warpzone_fadestart = ReadShort();
117                 this.warpzone_fadeend = max(this.warpzone_fadestart + 1, ReadShort());
118         }
119         else
120         {
121                 this.warpzone_fadestart = 0;
122                 this.warpzone_fadeend = 0;
123         }
124
125         // common stuff
126         WarpZone_Camera_SetUp(this, this.oldorigin, this.avelocity);
127
128         // engine currently wants this
129         this.drawmask = MASK_NORMAL;
130
131         // link me
132         //setmodel(this, this.model);
133         setorigin(this, this.origin);
134         setsize(this, this.mins, this.maxs);
135
136         // how to draw
137         // engine currently wants this
138         setpredraw(this, WarpZone_Fade_PreDraw);
139         return true;
140 }
141
142 void CL_RotateMoves(vector ang) = #638;
143 NET_HANDLE(ENT_CLIENT_WARPZONE_TELEPORTED, bool isnew)
144 {
145         this.classname = "warpzone_teleported";
146         vector v = ReadVector();
147         return = true;
148         if (!isnew) return;
149         this.warpzone_transform = v;
150         setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(this, 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 = WarpZone_Find(pmove_org, pmove_org);
216         if(e)
217         {
218                 pmove_org = WarpZone_TransformOrigin(e, pmove_org);
219                 input_angles = WarpZone_TransformVAngles(e, input_angles);
220         }
221 }
222
223 #ifndef KEEP_ROLL
224 float autocvar_cl_rollkillspeed = 10;
225 #endif
226 void WarpZone_FixView()
227 {
228         entity e;
229         vector org, ang, nearclip, corner0, corner1, corner2, corner3, o;
230
231         warpzone_save_view_origin = org = getpropertyvec(VF_ORIGIN);
232         warpzone_save_view_angles = ang = getpropertyvec(VF_ANGLES);
233
234         e = WarpZone_Find(org, org);
235         if(e)
236         {
237                 org = WarpZone_TransformOrigin(e, org);
238                 ang = WarpZone_TransformVAngles(e, ang);
239                 WarpZone_View_Inside();
240         }
241         else
242                 WarpZone_View_Outside();
243
244 #ifndef KEEP_ROLL
245         float rick;
246         float f;
247         static float rollkill;
248         if (STAT(HEALTH) > 0 || STAT(HEALTH) == -666 || STAT(HEALTH) == -2342)
249         {
250                 f = 0;
251                 // reset roll when passing through a warpzone that change player's roll angle
252                 if(autocvar_cl_rollkillspeed)
253                         f = max(0, (1 - frametime * autocvar_cl_rollkillspeed));
254                 if(rollkill)
255                         rollkill = 0;
256         }
257         else
258         {
259                 f = 1;
260                 // roll the view when killed (v_deathtilt)
261                 if(autocvar_cl_rollkillspeed)
262                 {
263                         rollkill += frametime * autocvar_cl_rollkillspeed;
264                         f = min(1, rollkill);
265                 }
266                 else if(rollkill)
267                         rollkill = 0;
268         }
269
270         rick = getproperty(VF_CL_VIEWANGLES_Z);
271         rick *= f;
272         setproperty(VF_CL_VIEWANGLES_Z, rick);
273         ang.z *= f;
274 #endif
275
276         setproperty(VF_ORIGIN, org);
277         setproperty(VF_ANGLES, ang);
278
279         nearclip = '0 0 1' * (cvar("r_nearclip") * 1.125);
280         corner0 = cs_unproject('0 0 0' + nearclip);
281         corner1 = cs_unproject('1 0 0' * cvar("vid_conwidth") + nearclip);
282         corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip);
283         corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip);
284         o = WarpZone_FixNearClip(org, corner0, corner1, corner2, corner3);
285         if(o != '0 0 0')
286                 setproperty(VF_ORIGIN, org + o);
287 }
288
289 void WarpZone_Shutdown()
290 {
291         WarpZone_View_Outside();
292 }