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