5 #include <lib/csqcmodel/cl_model.qh>
10 void WarpZone_Fade_PreDraw(entity this)
13 org = getpropertyvec(VF_ORIGIN);
14 if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
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);
20 //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
24 this.drawmask = MASK_NORMAL;
27 void WarpZone_Touch(entity this, entity toucher);
28 NET_HANDLE(ENT_CLIENT_WARPZONE, bool isnew)
30 if(!warpzone_warpzones_exist)
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
35 warpzone_warpzones_exist = 1;
38 this.enemy = new(warpzone_from);
40 this.classname = "trigger_warpzone";
43 IL_PUSH(g_warpzones, this);
46 this.warpzone_isboxy = (f & 1);
49 this.origin = ReadVector();
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();
64 this.warpzone_fadestart = ReadShort();
65 this.warpzone_fadeend = max(this.warpzone_fadestart + 1, ReadShort());
69 this.warpzone_fadestart = 0;
70 this.warpzone_fadeend = 0;
74 WarpZone_SetUp(this, this.enemy.oldorigin, this.enemy.avelocity, this.oldorigin, this.avelocity);
77 //setmodel(this, this.model);
78 setorigin(this, this.origin);
79 setsize(this, this.mins, this.maxs);
82 // engine currently wants this
83 setpredraw(this, WarpZone_Fade_PreDraw);
85 //settouch(this, WarpZone_Touch);
89 NET_HANDLE(ENT_CLIENT_WARPZONE_CAMERA, bool isnew)
91 if(!warpzone_cameras_exist)
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
96 warpzone_cameras_exist = 1;
97 this.classname = "func_warpzone_camera";
102 this.origin = ReadVector();
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();
115 this.warpzone_fadestart = ReadShort();
116 this.warpzone_fadeend = max(this.warpzone_fadestart + 1, ReadShort());
120 this.warpzone_fadestart = 0;
121 this.warpzone_fadeend = 0;
125 WarpZone_Camera_SetUp(this, this.oldorigin, this.avelocity);
127 // engine currently wants this
128 this.drawmask = MASK_NORMAL;
131 //setmodel(this, this.model);
132 setorigin(this, this.origin);
133 setsize(this, this.mins, this.maxs);
136 // engine currently wants this
137 setpredraw(this, WarpZone_Fade_PreDraw);
141 void CL_RotateMoves(vector ang) = #638;
142 NET_HANDLE(ENT_CLIENT_WARPZONE_TELEPORTED, bool isnew)
144 this.classname = "warpzone_teleported";
145 vector v = ReadVector();
148 this.warpzone_transform = v;
149 setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(this, getpropertyvec(VF_CL_VIEWANGLES)));
150 if(checkextension("DP_CSQC_ROTATEMOVES"))
152 //CL_RotateMoves('0 90 0');
155 float warpzone_fixingview;
156 float warpzone_fixingview_drawexteriormodel;
158 void WarpZone_View_Outside()
160 if(!warpzone_fixingview)
162 warpzone_fixingview = 0;
163 cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel));
166 void WarpZone_View_Inside()
168 if(autocvar_chase_active)
170 WarpZone_View_Outside();
173 if(warpzone_fixingview)
175 warpzone_fixingview = 1;
176 warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel");
177 cvar_set("r_drawexteriormodel", "0");
180 vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3)
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);
193 e = WarpZone_Find(mi, ma);
196 if(WarpZone_PlaneDist(e, o) < 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
200 WarpZone_PlaneDist(e, c0),
201 WarpZone_PlaneDist(e, c1),
202 WarpZone_PlaneDist(e, c2),
203 WarpZone_PlaneDist(e, c3)
206 return e.warpzone_forward * -pd;
212 void WarpZone_FixPMove()
214 entity e = WarpZone_Find(pmove_org, pmove_org);
217 pmove_org = WarpZone_TransformOrigin(e, pmove_org);
218 input_angles = WarpZone_TransformVAngles(e, input_angles);
223 float autocvar_cl_rollkillspeed = 10;
225 void WarpZone_FixView()
228 vector org, ang, nearclip, corner0, corner1, corner2, corner3, o;
230 warpzone_save_view_origin = org = getpropertyvec(VF_ORIGIN);
231 warpzone_save_view_angles = ang = getpropertyvec(VF_ANGLES);
233 e = WarpZone_Find(org, org);
236 org = WarpZone_TransformOrigin(e, org);
237 ang = WarpZone_TransformVAngles(e, ang);
238 WarpZone_View_Inside();
241 WarpZone_View_Outside();
246 static float rollkill;
247 if (STAT(HEALTH) > 0 || STAT(HEALTH) == -666 || STAT(HEALTH) == -2342)
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));
259 // roll the view when killed (v_deathtilt)
260 if(autocvar_cl_rollkillspeed)
262 rollkill += frametime * autocvar_cl_rollkillspeed;
263 f = min(1, rollkill);
269 rick = getproperty(VF_CL_VIEWANGLES_Z);
271 setproperty(VF_CL_VIEWANGLES_Z, rick);
275 setproperty(VF_ORIGIN, org);
276 setproperty(VF_ANGLES, ang);
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);
285 setproperty(VF_ORIGIN, org + o);
288 void WarpZone_Shutdown()
290 WarpZone_View_Outside();