7 #include <common/constants.qh>
8 #include <common/triggers/subs.qh>
9 #include <common/util.qh>
10 #include <server/command/common.qh>
11 #include <server/constants.qh>
12 #include <server/defs.qh>
15 #ifdef WARPZONELIB_KEEPDEBUG
16 #define WARPZONELIB_REMOVEHACK
20 .vector warpzone_save_origin;
21 .vector warpzone_save_angles;
22 .vector warpzone_save_eorigin;
23 .vector warpzone_save_eangles;
26 .vector warpzone_oldorigin, warpzone_oldvelocity, warpzone_oldangles;
27 .float warpzone_teleport_time;
28 .float warpzone_teleport_finishtime;
29 .entity warpzone_teleport_zone;
32 #define WarpZone_StoreProjectileData(e_) MACRO_BEGIN { \
34 e.warpzone_oldorigin = e.origin; \
35 e.warpzone_oldvelocity = e.velocity; \
36 e.warpzone_oldangles = e.angles; \
39 #define WarpZone_StoreProjectileData(e_) MACRO_BEGIN { \
41 e.warpzone_oldorigin = e.move_origin; \
42 e.warpzone_oldvelocity = e.move_velocity; \
43 e.warpzone_oldangles = e.move_angles; \
47 void WarpZone_TeleportPlayer(entity teleporter, entity player, vector to, vector to_angles, vector to_velocity)
50 setorigin (player, to); // NOTE: this also aborts the move, when this is called by touch
51 player.oldorigin = to; // for DP's unsticking
52 player.angles = to_angles;
53 player.fixangle = true;
54 player.velocity = to_velocity;
56 player.move_origin = to;
57 player.move_angles = to_angles;
58 player.move_velocity = to_velocity;
61 BITXOR_ASSIGN(player.effects, EF_TELEPORT_BIT);
65 BITCLR_ASSIGN(player.flags, FL_ONGROUND);
67 BITCLR_ASSIGN(player.move_flags, FL_ONGROUND);
70 WarpZone_PostTeleportPlayer_Callback(player);
74 bool WarpZone_Teleported_Send(entity this, entity to, int sf)
76 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE_TELEPORTED);
77 WriteCoord(MSG_ENTITY, this.angles.x);
78 WriteCoord(MSG_ENTITY, this.angles.y);
79 WriteCoord(MSG_ENTITY, this.angles.z);
84 float WarpZone_Teleport(entity wz, entity player, float f0, float f1)
86 vector o0, a0, v0, o1, a1, v1, o10;
89 o0 = player.origin + player.view_ofs;
93 o0 = player.move_origin + player.view_ofs;
94 v0 = player.move_velocity;
95 a0 = player.move_angles;
98 o10 = o1 = WarpZone_TransformOrigin(wz, o0);
99 v1 = WarpZone_TransformVelocity(wz, v0);
100 if (!IS_NOT_A_CLIENT(player))
101 a1 = WarpZone_TransformVAngles(wz, PHYS_INPUT_ANGLES(player));
103 a1 = WarpZone_TransformAngles(wz, a0);
105 if(f0 != 0 || f1 != 0)
107 // retry last move but behind the warpzone!
108 // we must first go back as far as we can, then forward again, to not cause double touch events!
110 tracebox(o1 - player.view_ofs + v1 * frametime * f1, player.mins, player.maxs, o1 - player.view_ofs + v1 * frametime * f0, MOVE_WORLDONLY, player);
114 player.owner = world;
115 tracebox(trace_endpos, player.mins, player.maxs, o1 - player.view_ofs + v1 * frametime * f1, MOVE_NORMAL, player); // this should get us through the warpzone
118 o1 = trace_endpos + player.view_ofs;
121 md = max(vlen(player.mins), vlen(player.maxs));
122 d = WarpZone_TargetPlaneDist(wz, o1);
123 dv = WarpZone_TargetPlaneDist(wz, v1);
125 o1 = o1 - v1 * (d / dv);
128 // put him out of solid
129 tracebox(o1 - player.view_ofs, player.mins, player.maxs, o1 - player.view_ofs, MOVE_NOMONSTERS, player);
132 setorigin(player, o1 - player.view_ofs);
133 if(WarpZoneLib_MoveOutOfSolid(player))
135 o1 = player.origin + player.view_ofs;
136 setorigin(player, o0 - player.view_ofs);
140 LOG_INFO("would have to put player in solid, won't do that\n");
141 setorigin(player, o0 - player.view_ofs);
147 WarpZone_RefSys_Add(player, wz);
148 WarpZone_TeleportPlayer(wz, player, o1 - player.view_ofs, a1, v1);
149 WarpZone_StoreProjectileData(player);
150 player.warpzone_teleport_time = time;
151 player.warpzone_teleport_finishtime = time;
152 player.warpzone_teleport_zone = wz;
155 // prevent further teleports back
156 float dt = (o1 - o10) * v1 * (1 / (v1 * v1));
157 if(dt < PHYS_INPUT_FRAMETIME)
158 player.warpzone_teleport_finishtime += PHYS_INPUT_FRAMETIME - dt;
161 #ifndef WARPZONE_USE_FIXANGLE
163 if(IS_VEHICLE(player) && player.owner)
164 player = player.owner; // hax
165 if(IS_PLAYER(player))
167 // instead of fixangle, send the transform to the client for smoother operation
168 player.fixangle = false;
170 entity ts = new(warpzone_teleported);
171 setmodel(ts, MDL_Null);
172 setSendEntity(ts, WarpZone_Teleported_Send);
173 ts.SendFlags = 0xFFFFFF;
174 ts.drawonlytoclient = player;
175 setthink(ts, SUB_Remove);
176 ts.nextthink = time + 1;
179 ts.effects = EF_NODEPTHTEST;
180 ts.angles = wz.warpzone_transform;
183 setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(wz, getpropertyvec(VF_CL_VIEWANGLES)));
184 //if(checkextension("DP_CSQC_ROTATEMOVES"))
185 //CL_RotateMoves(wz.warpzone_transform);
192 void WarpZone_Touch (entity this)
194 if(other.classname == "trigger_warpzone")
197 if(time <= other.warpzone_teleport_finishtime) // already teleported this frame
200 // FIXME needs a better check to know what is safe to teleport and what not
202 if(other.movetype == MOVETYPE_NONE || other.movetype == MOVETYPE_FOLLOW || other.tag_entity)
204 if(other.move_movetype == MOVETYPE_NONE || other.move_movetype == MOVETYPE_FOLLOW || other.tag_networkentity)
208 if(WarpZoneLib_ExactTrigger_Touch(this, other))
212 if(WarpZone_PlaneDist(this, other.origin + other.view_ofs) >= 0) // wrong side of the trigger_warpzone (don't teleport yet)
214 if(WarpZone_PlaneDist(this, other.move_origin + other.view_ofs) >= 0) // wrong side of the trigger_warpzone (don't teleport yet)
219 // number of frames we need to go back:
220 // dist = 16*sqrt(2) qu
223 // 24 qu = v*frametime*n
224 // n = 24 qu/(v*frametime)
225 // for clients go only one frame though, may be too irritating otherwise
226 // but max 0.25 sec = 0.25/frametime frames
227 // 24/(0.25/frametime)
230 d = 24 + max(vlen(other.mins), vlen(other.maxs));
231 if(IS_NOT_A_CLIENT(other))
233 f = -d / bound(frametime * d * 1, frametime * vlen(other.velocity), d);
235 f = -d / bound(frametime * d * 1, frametime * vlen(other.move_velocity), d);
239 if(WarpZone_Teleport(this, other, f, 0))
244 save1 = this.target; this.target = string_null;
245 save2 = this.target3; this.target3 = string_null;
246 SUB_UseTargets(this, other, other); // use other too?
247 if (!this.target) this.target = save1;
248 if (!this.target3) this.target3 = save2;
250 save1 = this.target; this.target = string_null;
251 save2 = this.target2; this.target2 = string_null;
252 SUB_UseTargets(this.enemy, other, other); // use other too?
253 if (!this.target) this.target = save1;
254 if (!this.target2) this.target2 = save2;
259 LOG_TRACE("WARPZONE FAIL AHAHAHAHAH))\n");
264 bool WarpZone_Send(entity this, entity to, int sendflags)
266 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE);
268 // we must send this flag for clientside to match properly too
270 if(this.warpzone_isboxy)
272 if(this.warpzone_fadestart)
274 if(this.origin != '0 0 0')
276 WriteByte(MSG_ENTITY, f);
278 // we need THESE to render the warpzone (and cull properly)...
281 WriteCoord(MSG_ENTITY, this.origin.x);
282 WriteCoord(MSG_ENTITY, this.origin.y);
283 WriteCoord(MSG_ENTITY, this.origin.z);
286 WriteShort(MSG_ENTITY, this.modelindex);
287 WriteCoord(MSG_ENTITY, this.mins.x);
288 WriteCoord(MSG_ENTITY, this.mins.y);
289 WriteCoord(MSG_ENTITY, this.mins.z);
290 WriteCoord(MSG_ENTITY, this.maxs.x);
291 WriteCoord(MSG_ENTITY, this.maxs.y);
292 WriteCoord(MSG_ENTITY, this.maxs.z);
293 WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
295 // we need THESE to calculate the proper transform
296 WriteCoord(MSG_ENTITY, this.warpzone_origin.x);
297 WriteCoord(MSG_ENTITY, this.warpzone_origin.y);
298 WriteCoord(MSG_ENTITY, this.warpzone_origin.z);
299 WriteCoord(MSG_ENTITY, this.warpzone_angles.x);
300 WriteCoord(MSG_ENTITY, this.warpzone_angles.y);
301 WriteCoord(MSG_ENTITY, this.warpzone_angles.z);
302 WriteCoord(MSG_ENTITY, this.warpzone_targetorigin.x);
303 WriteCoord(MSG_ENTITY, this.warpzone_targetorigin.y);
304 WriteCoord(MSG_ENTITY, this.warpzone_targetorigin.z);
305 WriteCoord(MSG_ENTITY, this.warpzone_targetangles.x);
306 WriteCoord(MSG_ENTITY, this.warpzone_targetangles.y);
307 WriteCoord(MSG_ENTITY, this.warpzone_targetangles.z);
311 WriteShort(MSG_ENTITY, this.warpzone_fadestart);
312 WriteShort(MSG_ENTITY, this.warpzone_fadeend);
318 bool WarpZone_Camera_Send(entity this, entity to, int sendflags)
321 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE_CAMERA);
323 if(this.warpzone_fadestart)
325 if(this.origin != '0 0 0')
327 WriteByte(MSG_ENTITY, f);
329 // we need THESE to render the warpzone (and cull properly)...
332 WriteCoord(MSG_ENTITY, this.origin.x);
333 WriteCoord(MSG_ENTITY, this.origin.y);
334 WriteCoord(MSG_ENTITY, this.origin.z);
337 WriteShort(MSG_ENTITY, this.modelindex);
338 WriteCoord(MSG_ENTITY, this.mins.x);
339 WriteCoord(MSG_ENTITY, this.mins.y);
340 WriteCoord(MSG_ENTITY, this.mins.z);
341 WriteCoord(MSG_ENTITY, this.maxs.x);
342 WriteCoord(MSG_ENTITY, this.maxs.y);
343 WriteCoord(MSG_ENTITY, this.maxs.z);
344 WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
346 // we need THESE to calculate the proper transform
347 WriteCoord(MSG_ENTITY, this.enemy.origin.x);
348 WriteCoord(MSG_ENTITY, this.enemy.origin.y);
349 WriteCoord(MSG_ENTITY, this.enemy.origin.z);
350 WriteCoord(MSG_ENTITY, this.enemy.angles.x);
351 WriteCoord(MSG_ENTITY, this.enemy.angles.y);
352 WriteCoord(MSG_ENTITY, this.enemy.angles.z);
356 WriteShort(MSG_ENTITY, this.warpzone_fadestart);
357 WriteShort(MSG_ENTITY, this.warpzone_fadeend);
363 #ifdef WARPZONELIB_KEEPDEBUG
364 float WarpZone_CheckProjectileImpact(entity player)
368 .vector orgvec, velvec;
373 orgvec = move_origin;
374 velvec = move_velocity;
377 o0 = player.orgvec + player.view_ofs;
380 // if we teleported shortly before, abort
381 if(time <= player.warpzone_teleport_finishtime + 0.1)
384 // if player hit a warpzone, abort
386 wz = WarpZone_Find(o0 + player.mins, o0 + player.maxs);
390 #ifdef WARPZONELIB_REMOVEHACK
391 LOG_INFO("impactfilter found something - and it no longer gets handled correctly - please tell divVerent whether anything behaves broken now\n");
393 LOG_INFO("impactfilter found something - and it even gets handled correctly - please tell divVerent that this code apparently gets triggered again\n");
395 LOG_INFO("Entity type: ", player.classname, "\n");
396 LOG_INFO("Origin: ", vtos(player.orgvec), "\n");
397 LOG_INFO("Velocity: ", vtos(player.velvec), "\n");
399 #ifdef WARPZONELIB_REMOVEHACK
402 // retry previous move
404 setorigin(player, player.warpzone_oldorigin);
406 player.move_origin = player.warpzone_oldorigin;
408 player.velvec = player.warpzone_oldvelocity;
409 if(WarpZone_Teleport(wz, player, 0, 1))
413 save1 = wz.target; wz.target = string_null;
414 save2 = wz.target3; wz.target3 = string_null;
415 SUB_UseTargets(wz, player, player);
416 if (!wz.target) wz.target = save1;
417 if (!wz.target3) wz.target3 = save2;
419 save1 = wz.enemy.target; wz.enemy.target = string_null;
420 save2 = wz.enemy.target2; wz.enemy.target2 = string_null;
421 SUB_UseTargets(wz.enemy, player, player);
422 if (!wz.enemy.target) wz.enemy.target = save1;
423 if (!wz.enemy.target2) wz.enemy.target2 = save2;
427 setorigin(player, o0 - player.view_ofs);
437 float WarpZone_Projectile_Touch(entity this)
439 if(other.classname == "trigger_warpzone")
442 // no further impacts if we teleported this frame!
443 // this is because even if we did teleport, the engine still may raise
444 // touch events for the previous location
445 // engine now aborts moves on teleport, so this SHOULD not happen any more
446 // but if this is called from TouchAreaGrid of the projectile moving,
447 // then this won't do
448 if(time == this.warpzone_teleport_time)
452 #ifdef WARPZONELIB_KEEPDEBUG
453 // this SEEMS to not happen at the moment, but if it did, it would be more reliable
455 float save_dpstartcontents;
456 float save_dphitcontents;
457 float save_dphitq3surfaceflags;
458 string save_dphittexturename;
460 float save_startsolid;
463 vector save_plane_normal;
464 float save_plane_dist;
468 save_dpstartcontents = trace_dpstartcontents;
469 save_dphitcontents = trace_dphitcontents;
470 save_dphitq3surfaceflags = trace_dphitq3surfaceflags;
471 save_dphittexturename = trace_dphittexturename;
472 save_allsolid = trace_allsolid;
473 save_startsolid = trace_startsolid;
474 save_fraction = trace_fraction;
475 save_endpos = trace_endpos;
476 save_plane_normal = trace_plane_normal;
477 save_plane_dist = trace_plane_dist;
478 save_ent = trace_ent;
479 save_inopen = trace_inopen;
480 save_inwater = trace_inwater;
481 float f = WarpZone_CheckProjectileImpact(this);
482 if (f) return (f > 0);
483 trace_dpstartcontents = save_dpstartcontents;
484 trace_dphitcontents = save_dphitcontents;
485 trace_dphitq3surfaceflags = save_dphitq3surfaceflags;
486 trace_dphittexturename = save_dphittexturename;
487 trace_allsolid = save_allsolid;
488 trace_startsolid = save_startsolid;
489 trace_fraction = save_fraction;
490 trace_endpos = save_endpos;
491 trace_plane_normal = save_plane_normal;
492 trace_plane_dist = save_plane_dist;
493 trace_ent = save_ent;
494 trace_inopen = save_inopen;
495 trace_inwater = save_inwater;
499 if(WarpZone_Projectile_Touch_ImpactFilter_Callback(this, other))
508 void WarpZone_InitStep_FindOriginTarget(entity this)
510 if(this.killtarget != "")
512 this.aiment = find(world, targetname, this.killtarget);
513 if(this.aiment == world)
515 error("Warp zone with nonexisting killtarget");
518 this.killtarget = string_null;
522 void WarpZonePosition_InitStep_FindTarget(entity this)
524 if(this.target == "")
526 error("Warp zone position with no target");
529 this.enemy = find(world, targetname, this.target);
530 if(this.enemy == world)
532 error("Warp zone position with nonexisting target");
535 if(this.enemy.aiment)
537 // already is positioned
538 error("Warp zone position targeting already oriented warpzone");
541 this.enemy.aiment = this;
544 void WarpZoneCamera_Think(entity this)
546 if(this.warpzone_save_origin != this.origin
547 || this.warpzone_save_angles != this.angles
548 || this.warpzone_save_eorigin != this.enemy.origin
549 || this.warpzone_save_eangles != this.enemy.angles)
551 WarpZone_Camera_SetUp(this, this.enemy.origin, this.enemy.angles);
552 this.warpzone_save_origin = this.origin;
553 this.warpzone_save_angles = this.angles;
554 this.warpzone_save_eorigin = this.enemy.origin;
555 this.warpzone_save_eangles = this.enemy.angles;
557 this.nextthink = time;
560 void WarpZoneCamera_InitStep_FindTarget(entity this)
564 if(this.target == "")
566 error("Camera with no target");
570 for(e = world, i = 0; (e = find(e, targetname, this.target)); )
571 if(random() * ++i < 1)
573 if(this.enemy == world)
575 error("Camera with nonexisting target");
578 warpzone_cameras_exist = 1;
579 WarpZone_Camera_SetUp(this, this.enemy.origin, this.enemy.angles);
580 this.SendFlags = 0xFFFFFF;
581 if(this.spawnflags & 1)
583 setthink(this, WarpZoneCamera_Think);
584 this.nextthink = time;
590 void WarpZone_InitStep_UpdateTransform(entity this)
592 vector org, ang, norm, point;
594 vector tri, a, b, c, n;
600 org = 0.5 * (this.mins + this.maxs);
602 norm = point = '0 0 0';
604 for(i_s = 0; ; ++i_s)
606 tex = getsurfacetexture(this, i_s);
608 break; // this is beyond the last one
609 if(tex == "textures/common/trigger" || tex == "trigger")
611 n_t = getsurfacenumtriangles(this, i_s);
612 for(i_t = 0; i_t < n_t; ++i_t)
614 tri = getsurfacetriangle(this, i_s, i_t);
615 a = getsurfacepoint(this, i_s, tri.x);
616 b = getsurfacepoint(this, i_s, tri.y);
617 c = getsurfacepoint(this, i_s, tri.z);
618 n = cross(c - a, b - a);
619 area = area + vlen(n);
621 point = point + vlen(n) * (a + b + c);
626 norm = norm * (1 / area);
627 point = point * (1 / (3 * area));
628 if(vdist(norm, <, 0.99))
630 LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " is nonplanar. BEWARE.\n");
631 area = 0; // no autofixing in this case
633 norm = normalize(norm);
639 org = this.aiment.origin;
640 ang = this.aiment.angles;
643 org = org - ((org - point) * norm) * norm; // project to plane
645 if(norm * v_forward < 0)
647 LOG_INFO("Position target of trigger_warpzone near ", vtos(this.aiment.origin), " points into trigger_warpzone. BEWARE.\n");
650 ang = vectoangles2(norm, v_up); // keep rotation, but turn exactly against plane
652 if(norm * v_forward < 0.99)
653 LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " has been turned to match plane orientation (", vtos(this.aiment.angles), " -> ", vtos(ang), "\n");
654 if(vdist(org - this.aiment.origin, >, 0.5))
655 LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " has been moved to match the plane (", vtos(this.aiment.origin), " -> ", vtos(org), ").\n");
661 ang = vectoangles(norm);
665 error("cannot infer origin/angles for this warpzone, please use a killtarget or a trigger_warpzone_position");
667 this.warpzone_origin = org;
668 this.warpzone_angles = ang;
671 void WarpZone_InitStep_ClearTarget(entity this)
674 this.enemy.enemy = world;
678 entity warpzone_first; .entity warpzone_next;
679 void WarpZone_InitStep_FindTarget(entity this)
687 // this way only one of the two ents needs to target
688 if(this.target != "")
690 this.enemy = this; // so the if(!e.enemy) check also skips this, saves one IF
693 for(e = world, i = 0; (e = find(e, targetname, this.target)); )
695 if(e.classname == this.classname) // possibly non-warpzones may use the same targetname!
696 if(random() * ++i < 1)
701 error("Warpzone with non-existing target");
709 void WarpZone_Think(entity this);
710 void WarpZone_InitStep_FinalizeTransform(entity this)
712 if(!this.enemy || this.enemy.enemy != this)
714 error("Invalid warp zone detected. Killed.");
718 warpzone_warpzones_exist = 1;
719 WarpZone_SetUp(this, this.warpzone_origin, this.warpzone_angles, this.enemy.warpzone_origin, this.enemy.warpzone_angles);
720 settouch(this, WarpZone_Touch);
721 this.SendFlags = 0xFFFFFF;
722 if(this.spawnflags & 1)
724 setthink(this, WarpZone_Think);
725 this.nextthink = time;
731 float warpzone_initialized;
732 //entity warpzone_first;
733 entity warpzone_position_first;
734 entity warpzone_camera_first;
735 .entity warpzone_next;
736 spawnfunc(misc_warpzone_position)
738 // "target", "angles", "origin"
739 this.warpzone_next = warpzone_position_first;
740 warpzone_position_first = this;
742 spawnfunc(trigger_warpzone_position)
744 spawnfunc_misc_warpzone_position(this);
746 spawnfunc(trigger_warpzone)
748 // warp zone entities must have:
749 // "killtarget" pointing to a target_position with a direction arrow
750 // that points AWAY from the warp zone, and that is inside
751 // the warp zone trigger
752 // "target" pointing to an identical warp zone at another place in
753 // the map, with another killtarget to designate its
757 this.scale = this.modelscale;
762 WarpZoneLib_ExactTrigger_Init(this);
766 _setmodel(this, m); // no precision needed
768 setorigin(this, this.origin);
770 setsize(this, this.mins * this.scale, this.maxs * this.scale);
772 setsize(this, this.mins, this.maxs);
773 setSendEntity(this, WarpZone_Send);
774 this.SendFlags = 0xFFFFFF;
775 BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
776 this.warpzone_next = warpzone_first;
777 warpzone_first = this;
779 spawnfunc(func_camera)
782 this.scale = this.modelscale;
787 precache_model(this.model);
788 _setmodel(this, this.model); // no precision needed
790 setorigin(this, this.origin);
792 setsize(this, this.mins * this.scale, this.maxs * this.scale);
794 setsize(this, this.mins, this.maxs);
796 this.solid = SOLID_BSP;
797 else if(this.solid < 0)
798 this.solid = SOLID_NOT;
799 setSendEntity(this, WarpZone_Camera_Send);
800 this.SendFlags = 0xFFFFFF;
801 this.warpzone_next = warpzone_camera_first;
802 warpzone_camera_first = this;
804 void WarpZones_Reconnect()
806 for(entity e = warpzone_first; e; e = e.warpzone_next)
807 WarpZone_InitStep_ClearTarget(e);
808 for(entity e = warpzone_first; e; e = e.warpzone_next)
809 WarpZone_InitStep_FindTarget(e);
810 for(entity e = warpzone_camera_first; e; e = e.warpzone_next)
811 WarpZoneCamera_InitStep_FindTarget(e);
812 for(entity e = warpzone_first; e; e = e.warpzone_next)
813 WarpZone_InitStep_FinalizeTransform(e);
816 void WarpZone_Think(entity this)
818 if(this.warpzone_save_origin != this.origin
819 || this.warpzone_save_angles != this.angles
820 || this.warpzone_save_eorigin != this.enemy.origin
821 || this.warpzone_save_eangles != this.enemy.angles)
823 WarpZone_InitStep_UpdateTransform(this);
824 WarpZone_InitStep_UpdateTransform(this.enemy);
825 WarpZone_InitStep_FinalizeTransform(this);
826 WarpZone_InitStep_FinalizeTransform(this.enemy);
827 this.warpzone_save_origin = this.origin;
828 this.warpzone_save_angles = this.angles;
829 this.warpzone_save_eorigin = this.enemy.origin;
830 this.warpzone_save_eangles = this.enemy.angles;
832 this.nextthink = time;
835 void WarpZone_StartFrame()
837 if (!warpzone_initialized)
839 warpzone_initialized = true;
840 for(entity e = warpzone_first; e; e = e.warpzone_next)
841 WarpZone_InitStep_FindOriginTarget(e);
842 for(entity e = warpzone_position_first; e; e = e.warpzone_next)
843 WarpZonePosition_InitStep_FindTarget(e);
844 for(entity e = warpzone_first; e; e = e.warpzone_next)
845 WarpZone_InitStep_UpdateTransform(e);
846 WarpZones_Reconnect();
847 WarpZone_PostInitialize_Callback();
850 entity oldother = other;
852 FOREACH_ENTITY(!is_pure(it),
854 if(warpzone_warpzones_exist)
855 WarpZone_StoreProjectileData(it);
857 if(IS_OBSERVER(it) || it.solid == SOLID_NOT)
858 if(IS_CLIENT(it)) // we don't care about it being a bot
860 other = it; // player
863 if (warpzone_warpzones_exist) {
864 entity e = WarpZone_Find(it.origin + it.mins, it.origin + it.maxs);
866 if (!WarpZoneLib_ExactTrigger_Touch(e, other))
867 if (WarpZone_PlaneDist(e, it.origin + it.view_ofs) <= 0)
868 WarpZone_Teleport(e, it, -1, 0); // NOT triggering targets by this!
872 if(other.teleportable)
874 entity ent = Teleport_Find(it.origin + it.mins, it.origin + it.maxs);
876 if (!WarpZoneLib_ExactTrigger_Touch(ent, other))
877 Simple_TeleportPlayer(ent, other); // NOT triggering targets by this!
884 .float warpzone_reconnecting;
885 bool visible_to_some_client(entity ent)
887 FOREACH_ENTITY(!IS_NOT_A_CLIENT(it), LAMBDA(
888 if (IS_PLAYER(it) && IS_REAL_CLIENT(it) && checkpvs(it.origin + it.view_ofs, ent)) return true;
892 void trigger_warpzone_reconnect_use(entity this, entity actor, entity trigger)
894 // NOTE: this matches for target, not targetname, but of course
895 // targetname must be set too on the other entities
896 for(entity e = warpzone_first; e; e = e.warpzone_next)
897 e.warpzone_reconnecting = ((this.target == "" || e.target == this.target) && !((this.spawnflags & 1) && (visible_to_some_client(e) || visible_to_some_client(e.enemy))));
898 for(entity e = warpzone_camera_first; e; e = e.warpzone_next)
899 e.warpzone_reconnecting = ((this.target == "" || e.target == this.target) && !((this.spawnflags & 1) && visible_to_some_client(e)));
900 for(entity e = warpzone_first; e; e = e.warpzone_next)
901 if(e.warpzone_reconnecting)
902 WarpZone_InitStep_ClearTarget(e);
903 for(entity e = warpzone_first; e; e = e.warpzone_next)
904 if(e.warpzone_reconnecting)
905 WarpZone_InitStep_FindTarget(e);
906 for(entity e = warpzone_camera_first; e; e = e.warpzone_next)
907 if(e.warpzone_reconnecting)
908 WarpZoneCamera_InitStep_FindTarget(e);
909 for(entity e = warpzone_first; e; e = e.warpzone_next)
910 if(e.warpzone_reconnecting || e.enemy.warpzone_reconnecting)
911 WarpZone_InitStep_FinalizeTransform(e);
914 spawnfunc(trigger_warpzone_reconnect)
916 this.use = trigger_warpzone_reconnect_use;
919 spawnfunc(target_warpzone_reconnect)
921 spawnfunc_trigger_warpzone_reconnect(this); // both names make sense here :(
924 void WarpZone_PlayerPhysics_FixVAngle(entity this)
926 #ifndef WARPZONE_DONT_FIX_VANGLE
927 if(IS_REAL_CLIENT(this))
928 if(this.v_angle.z <= 360) // if not already adjusted
929 if(time - this.ping * 0.001 < this.warpzone_teleport_time)
931 this.v_angle = WarpZone_TransformVAngles(this.warpzone_teleport_zone, this.v_angle);
932 this.v_angle_z += 720; // mark as adjusted