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 ts.SendEntity = SendEntity_self;
173 ts.SendEntity3 = WarpZone_Teleported_Send;
174 ts.SendFlags = 0xFFFFFF;
175 ts.drawonlytoclient = player;
176 ts.think = SUB_Remove_self;
177 ts.nextthink = time + 1;
180 ts.effects = EF_NODEPTHTEST;
181 ts.angles = wz.warpzone_transform;
184 setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(wz, getpropertyvec(VF_CL_VIEWANGLES)));
185 //if(checkextension("DP_CSQC_ROTATEMOVES"))
186 //CL_RotateMoves(wz.warpzone_transform);
193 void WarpZone_Touch ()
195 if(other.classname == "trigger_warpzone")
198 if(time <= other.warpzone_teleport_finishtime) // already teleported this frame
201 // FIXME needs a better check to know what is safe to teleport and what not
203 if(other.movetype == MOVETYPE_NONE || other.movetype == MOVETYPE_FOLLOW || other.tag_entity)
205 if(other.move_movetype == MOVETYPE_NONE || other.move_movetype == MOVETYPE_FOLLOW || other.tag_networkentity)
209 if(WarpZoneLib_ExactTrigger_Touch())
213 if(WarpZone_PlaneDist(this, other.origin + other.view_ofs) >= 0) // wrong side of the trigger_warpzone (don't teleport yet)
215 if(WarpZone_PlaneDist(this, other.move_origin + other.view_ofs) >= 0) // wrong side of the trigger_warpzone (don't teleport yet)
220 // number of frames we need to go back:
221 // dist = 16*sqrt(2) qu
224 // 24 qu = v*frametime*n
225 // n = 24 qu/(v*frametime)
226 // for clients go only one frame though, may be too irritating otherwise
227 // but max 0.25 sec = 0.25/frametime frames
228 // 24/(0.25/frametime)
231 d = 24 + max(vlen(other.mins), vlen(other.maxs));
232 if(IS_NOT_A_CLIENT(other))
234 f = -d / bound(frametime * d * 1, frametime * vlen(other.velocity), d);
236 f = -d / bound(frametime * d * 1, frametime * vlen(other.move_velocity), d);
240 if(WarpZone_Teleport(this, other, f, 0))
245 save1 = this.target; this.target = string_null;
246 save2 = this.target3; this.target3 = string_null;
247 SUB_UseTargets(this, other, other); // use other too?
248 if (!this.target) this.target = save1;
249 if (!this.target3) this.target3 = save2;
251 save1 = this.target; this.target = string_null;
252 save2 = this.target2; this.target2 = string_null;
253 SUB_UseTargets(this.enemy, other, other); // use other too?
254 if (!this.target) this.target = save1;
255 if (!this.target2) this.target2 = save2;
260 LOG_TRACE("WARPZONE FAIL AHAHAHAHAH))\n");
265 bool WarpZone_Send(entity this, entity to, int sendflags)
267 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE);
269 // we must send this flag for clientside to match properly too
271 if(this.warpzone_isboxy)
273 if(this.warpzone_fadestart)
275 if(this.origin != '0 0 0')
277 WriteByte(MSG_ENTITY, f);
279 // we need THESE to render the warpzone (and cull properly)...
282 WriteCoord(MSG_ENTITY, this.origin.x);
283 WriteCoord(MSG_ENTITY, this.origin.y);
284 WriteCoord(MSG_ENTITY, this.origin.z);
287 WriteShort(MSG_ENTITY, this.modelindex);
288 WriteCoord(MSG_ENTITY, this.mins.x);
289 WriteCoord(MSG_ENTITY, this.mins.y);
290 WriteCoord(MSG_ENTITY, this.mins.z);
291 WriteCoord(MSG_ENTITY, this.maxs.x);
292 WriteCoord(MSG_ENTITY, this.maxs.y);
293 WriteCoord(MSG_ENTITY, this.maxs.z);
294 WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
296 // we need THESE to calculate the proper transform
297 WriteCoord(MSG_ENTITY, this.warpzone_origin.x);
298 WriteCoord(MSG_ENTITY, this.warpzone_origin.y);
299 WriteCoord(MSG_ENTITY, this.warpzone_origin.z);
300 WriteCoord(MSG_ENTITY, this.warpzone_angles.x);
301 WriteCoord(MSG_ENTITY, this.warpzone_angles.y);
302 WriteCoord(MSG_ENTITY, this.warpzone_angles.z);
303 WriteCoord(MSG_ENTITY, this.warpzone_targetorigin.x);
304 WriteCoord(MSG_ENTITY, this.warpzone_targetorigin.y);
305 WriteCoord(MSG_ENTITY, this.warpzone_targetorigin.z);
306 WriteCoord(MSG_ENTITY, this.warpzone_targetangles.x);
307 WriteCoord(MSG_ENTITY, this.warpzone_targetangles.y);
308 WriteCoord(MSG_ENTITY, this.warpzone_targetangles.z);
312 WriteShort(MSG_ENTITY, this.warpzone_fadestart);
313 WriteShort(MSG_ENTITY, this.warpzone_fadeend);
319 bool WarpZone_Camera_Send(entity this, entity to, int sendflags)
322 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE_CAMERA);
324 if(this.warpzone_fadestart)
326 if(this.origin != '0 0 0')
328 WriteByte(MSG_ENTITY, f);
330 // we need THESE to render the warpzone (and cull properly)...
333 WriteCoord(MSG_ENTITY, this.origin.x);
334 WriteCoord(MSG_ENTITY, this.origin.y);
335 WriteCoord(MSG_ENTITY, this.origin.z);
338 WriteShort(MSG_ENTITY, this.modelindex);
339 WriteCoord(MSG_ENTITY, this.mins.x);
340 WriteCoord(MSG_ENTITY, this.mins.y);
341 WriteCoord(MSG_ENTITY, this.mins.z);
342 WriteCoord(MSG_ENTITY, this.maxs.x);
343 WriteCoord(MSG_ENTITY, this.maxs.y);
344 WriteCoord(MSG_ENTITY, this.maxs.z);
345 WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
347 // we need THESE to calculate the proper transform
348 WriteCoord(MSG_ENTITY, this.enemy.origin.x);
349 WriteCoord(MSG_ENTITY, this.enemy.origin.y);
350 WriteCoord(MSG_ENTITY, this.enemy.origin.z);
351 WriteCoord(MSG_ENTITY, this.enemy.angles.x);
352 WriteCoord(MSG_ENTITY, this.enemy.angles.y);
353 WriteCoord(MSG_ENTITY, this.enemy.angles.z);
357 WriteShort(MSG_ENTITY, this.warpzone_fadestart);
358 WriteShort(MSG_ENTITY, this.warpzone_fadeend);
364 #ifdef WARPZONELIB_KEEPDEBUG
365 float WarpZone_CheckProjectileImpact(entity player)
369 .vector orgvec, velvec;
374 orgvec = move_origin;
375 velvec = move_velocity;
378 o0 = player.orgvec + player.view_ofs;
381 // if we teleported shortly before, abort
382 if(time <= player.warpzone_teleport_finishtime + 0.1)
385 // if player hit a warpzone, abort
387 wz = WarpZone_Find(o0 + player.mins, o0 + player.maxs);
391 #ifdef WARPZONELIB_REMOVEHACK
392 LOG_INFO("impactfilter found something - and it no longer gets handled correctly - please tell divVerent whether anything behaves broken now\n");
394 LOG_INFO("impactfilter found something - and it even gets handled correctly - please tell divVerent that this code apparently gets triggered again\n");
396 LOG_INFO("Entity type: ", player.classname, "\n");
397 LOG_INFO("Origin: ", vtos(player.orgvec), "\n");
398 LOG_INFO("Velocity: ", vtos(player.velvec), "\n");
400 #ifdef WARPZONELIB_REMOVEHACK
403 // retry previous move
405 setorigin(player, player.warpzone_oldorigin);
407 player.move_origin = player.warpzone_oldorigin;
409 player.velvec = player.warpzone_oldvelocity;
410 if(WarpZone_Teleport(wz, player, 0, 1))
414 save1 = wz.target; wz.target = string_null;
415 save2 = wz.target3; wz.target3 = string_null;
416 SUB_UseTargets(wz, player, player);
417 if (!wz.target) wz.target = save1;
418 if (!wz.target3) wz.target3 = save2;
420 save1 = wz.enemy.target; wz.enemy.target = string_null;
421 save2 = wz.enemy.target2; wz.enemy.target2 = string_null;
422 SUB_UseTargets(wz.enemy, player, player);
423 if (!wz.enemy.target) wz.enemy.target = save1;
424 if (!wz.enemy.target2) wz.enemy.target2 = save2;
428 setorigin(player, o0 - player.view_ofs);
438 float WarpZone_Projectile_Touch()
440 if(other.classname == "trigger_warpzone")
443 // no further impacts if we teleported this frame!
444 // this is because even if we did teleport, the engine still may raise
445 // touch events for the previous location
446 // engine now aborts moves on teleport, so this SHOULD not happen any more
447 // but if this is called from TouchAreaGrid of the projectile moving,
448 // then this won't do
449 if(time == this.warpzone_teleport_time)
453 #ifdef WARPZONELIB_KEEPDEBUG
454 // this SEEMS to not happen at the moment, but if it did, it would be more reliable
456 float save_dpstartcontents;
457 float save_dphitcontents;
458 float save_dphitq3surfaceflags;
459 string save_dphittexturename;
461 float save_startsolid;
464 vector save_plane_normal;
465 float save_plane_dist;
469 save_dpstartcontents = trace_dpstartcontents;
470 save_dphitcontents = trace_dphitcontents;
471 save_dphitq3surfaceflags = trace_dphitq3surfaceflags;
472 save_dphittexturename = trace_dphittexturename;
473 save_allsolid = trace_allsolid;
474 save_startsolid = trace_startsolid;
475 save_fraction = trace_fraction;
476 save_endpos = trace_endpos;
477 save_plane_normal = trace_plane_normal;
478 save_plane_dist = trace_plane_dist;
479 save_ent = trace_ent;
480 save_inopen = trace_inopen;
481 save_inwater = trace_inwater;
483 if((f = WarpZone_CheckProjectileImpact(this)) != 0)
485 trace_dpstartcontents = save_dpstartcontents;
486 trace_dphitcontents = save_dphitcontents;
487 trace_dphitq3surfaceflags = save_dphitq3surfaceflags;
488 trace_dphittexturename = save_dphittexturename;
489 trace_allsolid = save_allsolid;
490 trace_startsolid = save_startsolid;
491 trace_fraction = save_fraction;
492 trace_endpos = save_endpos;
493 trace_plane_normal = save_plane_normal;
494 trace_plane_dist = save_plane_dist;
495 trace_ent = save_ent;
496 trace_inopen = save_inopen;
497 trace_inwater = save_inwater;
501 if(WarpZone_Projectile_Touch_ImpactFilter_Callback())
510 void WarpZone_InitStep_FindOriginTarget(entity this)
512 if(this.killtarget != "")
514 this.aiment = find(world, targetname, this.killtarget);
515 if(this.aiment == world)
517 error("Warp zone with nonexisting killtarget");
520 this.killtarget = string_null;
524 void WarpZonePosition_InitStep_FindTarget(entity this)
526 if(this.target == "")
528 error("Warp zone position with no target");
531 this.enemy = find(world, targetname, this.target);
532 if(this.enemy == world)
534 error("Warp zone position with nonexisting target");
537 if(this.enemy.aiment)
539 // already is positioned
540 error("Warp zone position targeting already oriented warpzone");
543 this.enemy.aiment = this;
546 void WarpZoneCamera_Think()
548 if(this.warpzone_save_origin != this.origin
549 || this.warpzone_save_angles != this.angles
550 || this.warpzone_save_eorigin != this.enemy.origin
551 || this.warpzone_save_eangles != this.enemy.angles)
553 WarpZone_Camera_SetUp(this, this.enemy.origin, this.enemy.angles);
554 this.warpzone_save_origin = this.origin;
555 this.warpzone_save_angles = this.angles;
556 this.warpzone_save_eorigin = this.enemy.origin;
557 this.warpzone_save_eangles = this.enemy.angles;
559 this.nextthink = time;
562 void WarpZoneCamera_InitStep_FindTarget(entity this)
566 if(this.target == "")
568 error("Camera with no target");
572 for(e = world, i = 0; (e = find(e, targetname, this.target)); )
573 if(random() * ++i < 1)
575 if(this.enemy == world)
577 error("Camera with nonexisting target");
580 warpzone_cameras_exist = 1;
581 WarpZone_Camera_SetUp(this, this.enemy.origin, this.enemy.angles);
582 this.SendFlags = 0xFFFFFF;
583 if(this.spawnflags & 1)
585 this.think = WarpZoneCamera_Think;
586 this.nextthink = time;
592 void WarpZone_InitStep_UpdateTransform(entity this)
594 vector org, ang, norm, point;
596 vector tri, a, b, c, n;
602 org = 0.5 * (this.mins + this.maxs);
604 norm = point = '0 0 0';
606 for(i_s = 0; ; ++i_s)
608 tex = getsurfacetexture(this, i_s);
610 break; // this is beyond the last one
611 if(tex == "textures/common/trigger" || tex == "trigger")
613 n_t = getsurfacenumtriangles(this, i_s);
614 for(i_t = 0; i_t < n_t; ++i_t)
616 tri = getsurfacetriangle(this, i_s, i_t);
617 a = getsurfacepoint(this, i_s, tri.x);
618 b = getsurfacepoint(this, i_s, tri.y);
619 c = getsurfacepoint(this, i_s, tri.z);
620 n = cross(c - a, b - a);
621 area = area + vlen(n);
623 point = point + vlen(n) * (a + b + c);
628 norm = norm * (1 / area);
629 point = point * (1 / (3 * area));
630 if(vdist(norm, <, 0.99))
632 LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " is nonplanar. BEWARE.\n");
633 area = 0; // no autofixing in this case
635 norm = normalize(norm);
641 org = this.aiment.origin;
642 ang = this.aiment.angles;
645 org = org - ((org - point) * norm) * norm; // project to plane
647 if(norm * v_forward < 0)
649 LOG_INFO("Position target of trigger_warpzone near ", vtos(this.aiment.origin), " points into trigger_warpzone. BEWARE.\n");
652 ang = vectoangles2(norm, v_up); // keep rotation, but turn exactly against plane
654 if(norm * v_forward < 0.99)
655 LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " has been turned to match plane orientation (", vtos(this.aiment.angles), " -> ", vtos(ang), "\n");
656 if(vdist(org - this.aiment.origin, >, 0.5))
657 LOG_INFO("trigger_warpzone near ", vtos(this.aiment.origin), " has been moved to match the plane (", vtos(this.aiment.origin), " -> ", vtos(org), ").\n");
663 ang = vectoangles(norm);
667 error("cannot infer origin/angles for this warpzone, please use a killtarget or a trigger_warpzone_position");
669 this.warpzone_origin = org;
670 this.warpzone_angles = ang;
673 void WarpZone_InitStep_ClearTarget(entity this)
676 this.enemy.enemy = world;
680 entity warpzone_first; .entity warpzone_next;
681 void WarpZone_InitStep_FindTarget(entity this)
689 // this way only one of the two ents needs to target
690 if(this.target != "")
692 this.enemy = this; // so the if(!e.enemy) check also skips this, saves one IF
695 for(e = world, i = 0; (e = find(e, targetname, this.target)); )
697 if(e.classname == this.classname) // possibly non-warpzones may use the same targetname!
698 if(random() * ++i < 1)
703 error("Warpzone with non-existing target");
711 void WarpZone_Think();
712 void WarpZone_InitStep_FinalizeTransform(entity this)
714 if(!this.enemy || this.enemy.enemy != this)
716 error("Invalid warp zone detected. Killed.");
720 warpzone_warpzones_exist = 1;
721 WarpZone_SetUp(this, this.warpzone_origin, this.warpzone_angles, this.enemy.warpzone_origin, this.enemy.warpzone_angles);
722 this.touch = WarpZone_Touch;
723 this.SendFlags = 0xFFFFFF;
724 if(this.spawnflags & 1)
726 this.think = WarpZone_Think;
727 this.nextthink = time;
733 float warpzone_initialized;
734 //entity warpzone_first;
735 entity warpzone_position_first;
736 entity warpzone_camera_first;
737 .entity warpzone_next;
738 spawnfunc(misc_warpzone_position)
740 // "target", "angles", "origin"
741 this.warpzone_next = warpzone_position_first;
742 warpzone_position_first = this;
744 spawnfunc(trigger_warpzone_position)
746 spawnfunc_misc_warpzone_position(this);
748 spawnfunc(trigger_warpzone)
750 // warp zone entities must have:
751 // "killtarget" pointing to a target_position with a direction arrow
752 // that points AWAY from the warp zone, and that is inside
753 // the warp zone trigger
754 // "target" pointing to an identical warp zone at another place in
755 // the map, with another killtarget to designate its
759 this.scale = this.modelscale;
764 WarpZoneLib_ExactTrigger_Init();
768 _setmodel(this, m); // no precision needed
770 setorigin(this, this.origin);
772 setsize(this, this.mins * this.scale, this.maxs * this.scale);
774 setsize(this, this.mins, this.maxs);
775 this.SendEntity = SendEntity_self;
776 this.SendEntity3 = WarpZone_Send;
777 this.SendFlags = 0xFFFFFF;
778 BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
779 this.warpzone_next = warpzone_first;
780 warpzone_first = this;
782 spawnfunc(func_camera)
785 this.scale = this.modelscale;
790 precache_model(this.model);
791 _setmodel(this, this.model); // no precision needed
793 setorigin(this, this.origin);
795 setsize(this, this.mins * this.scale, this.maxs * this.scale);
797 setsize(this, this.mins, this.maxs);
799 this.solid = SOLID_BSP;
800 else if(this.solid < 0)
801 this.solid = SOLID_NOT;
802 this.SendEntity = SendEntity_self;
803 this.SendEntity3 = WarpZone_Camera_Send;
804 this.SendFlags = 0xFFFFFF;
805 this.warpzone_next = warpzone_camera_first;
806 warpzone_camera_first = this;
808 void WarpZones_Reconnect()
810 for(entity e = warpzone_first; e; e = e.warpzone_next)
811 WarpZone_InitStep_ClearTarget(e);
812 for(entity e = warpzone_first; e; e = e.warpzone_next)
813 WarpZone_InitStep_FindTarget(e);
814 for(entity e = warpzone_camera_first; e; e = e.warpzone_next)
815 WarpZoneCamera_InitStep_FindTarget(e);
816 for(entity e = warpzone_first; e; e = e.warpzone_next)
817 WarpZone_InitStep_FinalizeTransform(e);
820 void WarpZone_Think()
822 if(this.warpzone_save_origin != this.origin
823 || this.warpzone_save_angles != this.angles
824 || this.warpzone_save_eorigin != this.enemy.origin
825 || this.warpzone_save_eangles != this.enemy.angles)
827 WarpZone_InitStep_UpdateTransform(this);
828 WarpZone_InitStep_UpdateTransform(this.enemy);
829 WarpZone_InitStep_FinalizeTransform(this);
830 WarpZone_InitStep_FinalizeTransform(this.enemy);
831 this.warpzone_save_origin = this.origin;
832 this.warpzone_save_angles = this.angles;
833 this.warpzone_save_eorigin = this.enemy.origin;
834 this.warpzone_save_eangles = this.enemy.angles;
836 this.nextthink = time;
839 void WarpZone_StartFrame()
842 if (!warpzone_initialized)
844 warpzone_initialized = true;
845 for(entity e = warpzone_first; e; e = e.warpzone_next)
846 WarpZone_InitStep_FindOriginTarget(e);
847 for(entity e = warpzone_position_first; e; e = e.warpzone_next)
848 WarpZonePosition_InitStep_FindTarget(e);
849 for(entity e = warpzone_first; e; e = e.warpzone_next)
850 WarpZone_InitStep_UpdateTransform(e);
851 WarpZones_Reconnect();
852 WarpZone_PostInitialize_Callback();
855 entity oldother = other;
857 FOREACH_ENTITY(!is_pure(it),
859 if(warpzone_warpzones_exist)
860 WarpZone_StoreProjectileData(it);
862 if(IS_OBSERVER(it) || it.solid == SOLID_NOT)
863 if(IS_CLIENT(it)) // we don't care about it being a bot
865 other = it; // player
868 if (warpzone_warpzones_exist) {
869 setself(WarpZone_Find(it.origin + it.mins, it.origin + it.maxs));
871 if (!WarpZoneLib_ExactTrigger_Touch())
872 if (WarpZone_PlaneDist(self, it.origin + it.view_ofs) <= 0)
873 WarpZone_Teleport(self, it, -1, 0); // NOT triggering targets by this!
877 if(other.teleportable)
879 setself(Teleport_Find(it.origin + it.mins, it.origin + it.maxs));
881 if (!WarpZoneLib_ExactTrigger_Touch())
882 Simple_TeleportPlayer(self, other); // NOT triggering targets by this!
890 .float warpzone_reconnecting;
891 bool visible_to_some_client(entity ent)
893 FOREACH_ENTITY(!IS_NOT_A_CLIENT(it), LAMBDA(
894 if (IS_PLAYER(it) && IS_REAL_CLIENT(it) && checkpvs(it.origin + it.view_ofs, ent)) return true;
898 void trigger_warpzone_reconnect_use(entity this, entity actor, entity trigger)
900 // NOTE: this matches for target, not targetname, but of course
901 // targetname must be set too on the other entities
902 for(entity e = warpzone_first; e; e = e.warpzone_next)
903 e.warpzone_reconnecting = ((this.target == "" || e.target == this.target) && !((this.spawnflags & 1) && (visible_to_some_client(e) || visible_to_some_client(e.enemy))));
904 for(entity e = warpzone_camera_first; e; e = e.warpzone_next)
905 e.warpzone_reconnecting = ((this.target == "" || e.target == this.target) && !((this.spawnflags & 1) && visible_to_some_client(e)));
906 for(entity e = warpzone_first; e; e = e.warpzone_next)
907 if(e.warpzone_reconnecting)
908 WarpZone_InitStep_ClearTarget(e);
909 for(entity e = warpzone_first; e; e = e.warpzone_next)
910 if(e.warpzone_reconnecting)
911 WarpZone_InitStep_FindTarget(e);
912 for(entity e = warpzone_camera_first; e; e = e.warpzone_next)
913 if(e.warpzone_reconnecting)
914 WarpZoneCamera_InitStep_FindTarget(e);
915 for(entity e = warpzone_first; e; e = e.warpzone_next)
916 if(e.warpzone_reconnecting || e.enemy.warpzone_reconnecting)
917 WarpZone_InitStep_FinalizeTransform(e);
920 spawnfunc(trigger_warpzone_reconnect)
922 this.use1 = trigger_warpzone_reconnect_use;
925 spawnfunc(target_warpzone_reconnect)
927 spawnfunc_trigger_warpzone_reconnect(this); // both names make sense here :(
930 void WarpZone_PlayerPhysics_FixVAngle(entity this)
932 #ifndef WARPZONE_DONT_FIX_VANGLE
933 if(IS_REAL_CLIENT(this))
934 if(this.v_angle.z <= 360) // if not already adjusted
935 if(time - this.ping * 0.001 < this.warpzone_teleport_time)
937 this.v_angle = WarpZone_TransformVAngles(this.warpzone_teleport_zone, this.v_angle);
938 this.v_angle_z += 720; // mark as adjusted