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 to, int sf)
76 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE_TELEPORTED);
77 WriteCoord(MSG_ENTITY, self.angles.x);
78 WriteCoord(MSG_ENTITY, self.angles.y);
79 WriteCoord(MSG_ENTITY, self.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 = WarpZone_Teleported_Send;
173 ts.SendFlags = 0xFFFFFF;
174 ts.drawonlytoclient = player;
175 ts.think = SUB_Remove_self;
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 ()
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())
212 if(WarpZone_PlaneDist(self, other.origin + other.view_ofs) >= 0) // wrong side of the trigger_warpzone (don't teleport yet)
214 if(WarpZone_PlaneDist(self, 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(self, other, f, 0))
245 save1 = self.target; self.target = string_null;
246 save2 = self.target3; self.target3 = string_null;
248 if (!self.target) self.target = save1;
249 if (!self.target3) self.target3 = save2;
252 save1 = self.target; self.target = string_null;
253 save2 = self.target2; self.target2 = string_null;
255 if (!self.target) self.target = save1;
256 if (!self.target2) self.target2 = save2;
262 LOG_TRACE("WARPZONE FAIL AHAHAHAHAH))\n");
267 bool WarpZone_Send(entity to, int sendflags)
269 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE);
271 // we must send this flag for clientside to match properly too
273 if(self.warpzone_isboxy)
275 if(self.warpzone_fadestart)
277 if(self.origin != '0 0 0')
279 WriteByte(MSG_ENTITY, f);
281 // we need THESE to render the warpzone (and cull properly)...
284 WriteCoord(MSG_ENTITY, self.origin.x);
285 WriteCoord(MSG_ENTITY, self.origin.y);
286 WriteCoord(MSG_ENTITY, self.origin.z);
289 WriteShort(MSG_ENTITY, self.modelindex);
290 WriteCoord(MSG_ENTITY, self.mins.x);
291 WriteCoord(MSG_ENTITY, self.mins.y);
292 WriteCoord(MSG_ENTITY, self.mins.z);
293 WriteCoord(MSG_ENTITY, self.maxs.x);
294 WriteCoord(MSG_ENTITY, self.maxs.y);
295 WriteCoord(MSG_ENTITY, self.maxs.z);
296 WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255));
298 // we need THESE to calculate the proper transform
299 WriteCoord(MSG_ENTITY, self.warpzone_origin.x);
300 WriteCoord(MSG_ENTITY, self.warpzone_origin.y);
301 WriteCoord(MSG_ENTITY, self.warpzone_origin.z);
302 WriteCoord(MSG_ENTITY, self.warpzone_angles.x);
303 WriteCoord(MSG_ENTITY, self.warpzone_angles.y);
304 WriteCoord(MSG_ENTITY, self.warpzone_angles.z);
305 WriteCoord(MSG_ENTITY, self.warpzone_targetorigin.x);
306 WriteCoord(MSG_ENTITY, self.warpzone_targetorigin.y);
307 WriteCoord(MSG_ENTITY, self.warpzone_targetorigin.z);
308 WriteCoord(MSG_ENTITY, self.warpzone_targetangles.x);
309 WriteCoord(MSG_ENTITY, self.warpzone_targetangles.y);
310 WriteCoord(MSG_ENTITY, self.warpzone_targetangles.z);
314 WriteShort(MSG_ENTITY, self.warpzone_fadestart);
315 WriteShort(MSG_ENTITY, self.warpzone_fadeend);
321 bool WarpZone_Camera_Send(entity to, int sendflags)
324 WriteHeader(MSG_ENTITY, ENT_CLIENT_WARPZONE_CAMERA);
326 if(self.warpzone_fadestart)
328 if(self.origin != '0 0 0')
330 WriteByte(MSG_ENTITY, f);
332 // we need THESE to render the warpzone (and cull properly)...
335 WriteCoord(MSG_ENTITY, self.origin.x);
336 WriteCoord(MSG_ENTITY, self.origin.y);
337 WriteCoord(MSG_ENTITY, self.origin.z);
340 WriteShort(MSG_ENTITY, self.modelindex);
341 WriteCoord(MSG_ENTITY, self.mins.x);
342 WriteCoord(MSG_ENTITY, self.mins.y);
343 WriteCoord(MSG_ENTITY, self.mins.z);
344 WriteCoord(MSG_ENTITY, self.maxs.x);
345 WriteCoord(MSG_ENTITY, self.maxs.y);
346 WriteCoord(MSG_ENTITY, self.maxs.z);
347 WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255));
349 // we need THESE to calculate the proper transform
350 WriteCoord(MSG_ENTITY, self.enemy.origin.x);
351 WriteCoord(MSG_ENTITY, self.enemy.origin.y);
352 WriteCoord(MSG_ENTITY, self.enemy.origin.z);
353 WriteCoord(MSG_ENTITY, self.enemy.angles.x);
354 WriteCoord(MSG_ENTITY, self.enemy.angles.y);
355 WriteCoord(MSG_ENTITY, self.enemy.angles.z);
359 WriteShort(MSG_ENTITY, self.warpzone_fadestart);
360 WriteShort(MSG_ENTITY, self.warpzone_fadeend);
366 #ifdef WARPZONELIB_KEEPDEBUG
367 float WarpZone_CheckProjectileImpact(entity player)
371 .vector orgvec, velvec;
376 orgvec = move_origin;
377 velvec = move_velocity;
380 o0 = player.orgvec + player.view_ofs;
383 // if we teleported shortly before, abort
384 if(time <= player.warpzone_teleport_finishtime + 0.1)
387 // if player hit a warpzone, abort
389 wz = WarpZone_Find(o0 + player.mins, o0 + player.maxs);
393 #ifdef WARPZONELIB_REMOVEHACK
394 LOG_INFO("impactfilter found something - and it no longer gets handled correctly - please tell divVerent whether anything behaves broken now\n");
396 LOG_INFO("impactfilter found something - and it even gets handled correctly - please tell divVerent that this code apparently gets triggered again\n");
398 LOG_INFO("Entity type: ", player.classname, "\n");
399 LOG_INFO("Origin: ", vtos(player.orgvec), "\n");
400 LOG_INFO("Velocity: ", vtos(player.velvec), "\n");
402 #ifdef WARPZONELIB_REMOVEHACK
405 // retry previous move
407 setorigin(player, player.warpzone_oldorigin);
409 player.move_origin = player.warpzone_oldorigin;
411 player.velvec = player.warpzone_oldvelocity;
412 if(WarpZone_Teleport(wz, player, 0, 1))
422 save1 = self.target; self.target = string_null;
423 save2 = self.target3; self.target3 = string_null;
425 if (!self.target) self.target = save1;
426 if (!self.target3) self.target3 = save2;
429 save1 = self.target; self.target = string_null;
430 save2 = self.target2; self.target2 = string_null;
432 if (!self.target) self.target = save1;
433 if (!self.target2) self.target2 = save2;
438 setorigin(player, o0 - player.view_ofs);
448 float WarpZone_Projectile_Touch()
450 if(other.classname == "trigger_warpzone")
453 // no further impacts if we teleported this frame!
454 // this is because even if we did teleport, the engine still may raise
455 // touch events for the previous location
456 // engine now aborts moves on teleport, so this SHOULD not happen any more
457 // but if this is called from TouchAreaGrid of the projectile moving,
458 // then this won't do
459 if(time == self.warpzone_teleport_time)
463 #ifdef WARPZONELIB_KEEPDEBUG
464 // this SEEMS to not happen at the moment, but if it did, it would be more reliable
466 float save_dpstartcontents;
467 float save_dphitcontents;
468 float save_dphitq3surfaceflags;
469 string save_dphittexturename;
471 float save_startsolid;
474 vector save_plane_normal;
475 float save_plane_dist;
479 save_dpstartcontents = trace_dpstartcontents;
480 save_dphitcontents = trace_dphitcontents;
481 save_dphitq3surfaceflags = trace_dphitq3surfaceflags;
482 save_dphittexturename = trace_dphittexturename;
483 save_allsolid = trace_allsolid;
484 save_startsolid = trace_startsolid;
485 save_fraction = trace_fraction;
486 save_endpos = trace_endpos;
487 save_plane_normal = trace_plane_normal;
488 save_plane_dist = trace_plane_dist;
489 save_ent = trace_ent;
490 save_inopen = trace_inopen;
491 save_inwater = trace_inwater;
493 if((f = WarpZone_CheckProjectileImpact(self)) != 0)
495 trace_dpstartcontents = save_dpstartcontents;
496 trace_dphitcontents = save_dphitcontents;
497 trace_dphitq3surfaceflags = save_dphitq3surfaceflags;
498 trace_dphittexturename = save_dphittexturename;
499 trace_allsolid = save_allsolid;
500 trace_startsolid = save_startsolid;
501 trace_fraction = save_fraction;
502 trace_endpos = save_endpos;
503 trace_plane_normal = save_plane_normal;
504 trace_plane_dist = save_plane_dist;
505 trace_ent = save_ent;
506 trace_inopen = save_inopen;
507 trace_inwater = save_inwater;
511 if(WarpZone_Projectile_Touch_ImpactFilter_Callback())
520 void WarpZone_InitStep_FindOriginTarget()
522 if(self.killtarget != "")
524 self.aiment = find(world, targetname, self.killtarget);
525 if(self.aiment == world)
527 error("Warp zone with nonexisting killtarget");
530 self.killtarget = string_null;
534 void WarpZonePosition_InitStep_FindTarget()
536 if(self.target == "")
538 error("Warp zone position with no target");
541 self.enemy = find(world, targetname, self.target);
542 if(self.enemy == world)
544 error("Warp zone position with nonexisting target");
547 if(self.enemy.aiment)
549 // already is positioned
550 error("Warp zone position targeting already oriented warpzone");
553 self.enemy.aiment = self;
556 void WarpZoneCamera_Think()
558 if(self.warpzone_save_origin != self.origin
559 || self.warpzone_save_angles != self.angles
560 || self.warpzone_save_eorigin != self.enemy.origin
561 || self.warpzone_save_eangles != self.enemy.angles)
563 WarpZone_Camera_SetUp(self, self.enemy.origin, self.enemy.angles);
564 self.warpzone_save_origin = self.origin;
565 self.warpzone_save_angles = self.angles;
566 self.warpzone_save_eorigin = self.enemy.origin;
567 self.warpzone_save_eangles = self.enemy.angles;
569 self.nextthink = time;
572 void WarpZoneCamera_InitStep_FindTarget()
576 if(self.target == "")
578 error("Camera with no target");
582 for(e = world, i = 0; (e = find(e, targetname, self.target)); )
583 if(random() * ++i < 1)
585 if(self.enemy == world)
587 error("Camera with nonexisting target");
590 warpzone_cameras_exist = 1;
591 WarpZone_Camera_SetUp(self, self.enemy.origin, self.enemy.angles);
592 self.SendFlags = 0xFFFFFF;
593 if(self.spawnflags & 1)
595 self.think = WarpZoneCamera_Think;
596 self.nextthink = time;
602 void WarpZone_InitStep_UpdateTransform()
604 vector org, ang, norm, point;
606 vector tri, a, b, c, n;
612 org = 0.5 * (self.mins + self.maxs);
614 norm = point = '0 0 0';
616 for(i_s = 0; ; ++i_s)
618 tex = getsurfacetexture(self, i_s);
620 break; // this is beyond the last one
621 if(tex == "textures/common/trigger" || tex == "trigger")
623 n_t = getsurfacenumtriangles(self, i_s);
624 for(i_t = 0; i_t < n_t; ++i_t)
626 tri = getsurfacetriangle(self, i_s, i_t);
627 a = getsurfacepoint(self, i_s, tri.x);
628 b = getsurfacepoint(self, i_s, tri.y);
629 c = getsurfacepoint(self, i_s, tri.z);
630 n = cross(c - a, b - a);
631 area = area + vlen(n);
633 point = point + vlen(n) * (a + b + c);
638 norm = norm * (1 / area);
639 point = point * (1 / (3 * area));
640 if(vdist(norm, <, 0.99))
642 LOG_INFO("trigger_warpzone near ", vtos(self.aiment.origin), " is nonplanar. BEWARE.\n");
643 area = 0; // no autofixing in this case
645 norm = normalize(norm);
651 org = self.aiment.origin;
652 ang = self.aiment.angles;
655 org = org - ((org - point) * norm) * norm; // project to plane
657 if(norm * v_forward < 0)
659 LOG_INFO("Position target of trigger_warpzone near ", vtos(self.aiment.origin), " points into trigger_warpzone. BEWARE.\n");
662 ang = vectoangles2(norm, v_up); // keep rotation, but turn exactly against plane
664 if(norm * v_forward < 0.99)
665 LOG_INFO("trigger_warpzone near ", vtos(self.aiment.origin), " has been turned to match plane orientation (", vtos(self.aiment.angles), " -> ", vtos(ang), "\n");
666 if(vdist(org - self.aiment.origin, >, 0.5))
667 LOG_INFO("trigger_warpzone near ", vtos(self.aiment.origin), " has been moved to match the plane (", vtos(self.aiment.origin), " -> ", vtos(org), ").\n");
673 ang = vectoangles(norm);
677 error("cannot infer origin/angles for this warpzone, please use a killtarget or a trigger_warpzone_position");
679 self.warpzone_origin = org;
680 self.warpzone_angles = ang;
683 void WarpZone_InitStep_ClearTarget()
686 self.enemy.enemy = world;
690 entity warpzone_first; .entity warpzone_next;
691 void WarpZone_InitStep_FindTarget()
699 // this way only one of the two ents needs to target
700 if(self.target != "")
702 self.enemy = self; // so the if(!e.enemy) check also skips self, saves one IF
705 for(e = world, i = 0; (e = find(e, targetname, self.target)); )
707 if(e.classname == self.classname) // possibly non-warpzones may use the same targetname!
708 if(random() * ++i < 1)
713 error("Warpzone with non-existing target");
721 void WarpZone_Think();
722 void WarpZone_InitStep_FinalizeTransform()
724 if(!self.enemy || self.enemy.enemy != self)
726 error("Invalid warp zone detected. Killed.");
730 warpzone_warpzones_exist = 1;
731 WarpZone_SetUp(self, self.warpzone_origin, self.warpzone_angles, self.enemy.warpzone_origin, self.enemy.warpzone_angles);
732 self.touch = WarpZone_Touch;
733 self.SendFlags = 0xFFFFFF;
734 if(self.spawnflags & 1)
736 self.think = WarpZone_Think;
737 self.nextthink = time;
743 float warpzone_initialized;
744 //entity warpzone_first;
745 entity warpzone_position_first;
746 entity warpzone_camera_first;
747 .entity warpzone_next;
748 spawnfunc(misc_warpzone_position)
750 // "target", "angles", "origin"
751 self.warpzone_next = warpzone_position_first;
752 warpzone_position_first = self;
754 spawnfunc(trigger_warpzone_position)
756 spawnfunc_misc_warpzone_position(this);
758 spawnfunc(trigger_warpzone)
760 // warp zone entities must have:
761 // "killtarget" pointing to a target_position with a direction arrow
762 // that points AWAY from the warp zone, and that is inside
763 // the warp zone trigger
764 // "target" pointing to an identical warp zone at another place in
765 // the map, with another killtarget to designate its
769 self.scale = self.modelscale;
774 WarpZoneLib_ExactTrigger_Init();
778 _setmodel(self, m); // no precision needed
780 setorigin(self, self.origin);
782 setsize(self, self.mins * self.scale, self.maxs * self.scale);
784 setsize(self, self.mins, self.maxs);
785 self.SendEntity = WarpZone_Send;
786 self.SendFlags = 0xFFFFFF;
787 BITSET_ASSIGN(self.effects, EF_NODEPTHTEST);
788 self.warpzone_next = warpzone_first;
789 warpzone_first = self;
791 spawnfunc(func_camera)
794 self.scale = self.modelscale;
799 precache_model(self.model);
800 _setmodel(self, self.model); // no precision needed
802 setorigin(self, self.origin);
804 setsize(self, self.mins * self.scale, self.maxs * self.scale);
806 setsize(self, self.mins, self.maxs);
808 self.solid = SOLID_BSP;
809 else if(self.solid < 0)
810 self.solid = SOLID_NOT;
811 self.SendEntity = WarpZone_Camera_Send;
812 self.SendFlags = 0xFFFFFF;
813 self.warpzone_next = warpzone_camera_first;
814 warpzone_camera_first = self;
816 void WarpZones_Reconnect()
818 for(setself(warpzone_first); self; setself(self.warpzone_next))
819 WarpZone_InitStep_ClearTarget();
820 for(setself(warpzone_first); self; setself(self.warpzone_next))
821 WarpZone_InitStep_FindTarget();
822 for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
823 WarpZoneCamera_InitStep_FindTarget();
824 for(setself(warpzone_first); self; setself(self.warpzone_next))
825 WarpZone_InitStep_FinalizeTransform();
829 void WarpZone_Think()
831 if(self.warpzone_save_origin != self.origin
832 || self.warpzone_save_angles != self.angles
833 || self.warpzone_save_eorigin != self.enemy.origin
834 || self.warpzone_save_eangles != self.enemy.angles)
836 WarpZone_InitStep_UpdateTransform();
838 WarpZone_InitStep_UpdateTransform();
840 WarpZone_InitStep_FinalizeTransform();
842 WarpZone_InitStep_FinalizeTransform();
844 self.warpzone_save_origin = self.origin;
845 self.warpzone_save_angles = self.angles;
846 self.warpzone_save_eorigin = self.enemy.origin;
847 self.warpzone_save_eangles = self.enemy.angles;
849 self.nextthink = time;
852 void WarpZone_StartFrame()
855 if (!warpzone_initialized)
857 warpzone_initialized = true;
858 for (setself(warpzone_first); self; setself(self.warpzone_next))
859 WarpZone_InitStep_FindOriginTarget();
860 for (setself(warpzone_position_first); self; setself(self.warpzone_next))
861 WarpZonePosition_InitStep_FindTarget();
862 for (setself(warpzone_first); self; setself(self.warpzone_next))
863 WarpZone_InitStep_UpdateTransform();
865 WarpZones_Reconnect();
866 WarpZone_PostInitialize_Callback();
869 entity oldother = other;
873 if(warpzone_warpzones_exist)
874 WarpZone_StoreProjectileData(it);
876 if((IS_OBSERVER(it) || it.solid == SOLID_NOT))
877 if(IS_CLIENT(it)) // we don't care about it being a bot
879 other = it; // player
882 if (warpzone_warpzones_exist) {
883 setself(WarpZone_Find(it.origin + it.mins, it.origin + it.maxs));
885 if (!WarpZoneLib_ExactTrigger_Touch())
886 if (WarpZone_PlaneDist(self, it.origin + it.view_ofs) <= 0)
887 WarpZone_Teleport(self, it, -1, 0); // NOT triggering targets by this!
891 setself(Teleport_Find(it.origin + it.mins, it.origin + it.maxs));
893 if (!WarpZoneLib_ExactTrigger_Touch())
894 Simple_TeleportPlayer(self, other); // NOT triggering targets by this!
901 .float warpzone_reconnecting;
902 bool visible_to_some_client(entity ent)
904 FOREACH_ENTITY(!IS_NOT_A_CLIENT(it), LAMBDA(
905 if (IS_PLAYER(it) && IS_REAL_CLIENT(it) && checkpvs(it.origin + it.view_ofs, ent)) return true;
909 void trigger_warpzone_reconnect_use()
913 // NOTE: this matches for target, not targetname, but of course
914 // targetname must be set too on the other entities
915 for(setself(warpzone_first); self; setself(self.warpzone_next))
916 self.warpzone_reconnecting = ((e.target == "" || self.target == e.target) && !((e.spawnflags & 1) && (visible_to_some_client(self) || visible_to_some_client(self.enemy))));
917 for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
918 self.warpzone_reconnecting = ((e.target == "" || self.target == e.target) && !((e.spawnflags & 1) && visible_to_some_client(self)));
919 for(setself(warpzone_first); self; setself(self.warpzone_next))
920 if(self.warpzone_reconnecting)
921 WarpZone_InitStep_ClearTarget();
922 for(setself(warpzone_first); self; setself(self.warpzone_next))
923 if(self.warpzone_reconnecting)
924 WarpZone_InitStep_FindTarget();
925 for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
926 if(self.warpzone_reconnecting)
927 WarpZoneCamera_InitStep_FindTarget();
928 for(setself(warpzone_first); self; setself(self.warpzone_next))
929 if(self.warpzone_reconnecting || self.enemy.warpzone_reconnecting)
930 WarpZone_InitStep_FinalizeTransform();
934 spawnfunc(trigger_warpzone_reconnect)
936 self.use = trigger_warpzone_reconnect_use;
939 spawnfunc(target_warpzone_reconnect)
941 spawnfunc_trigger_warpzone_reconnect(this); // both names make sense here :(
944 void WarpZone_PlayerPhysics_FixVAngle()
946 #ifndef WARPZONE_DONT_FIX_VANGLE
947 if(IS_REAL_CLIENT(self))
948 if(self.v_angle.z <= 360) // if not already adjusted
949 if(time - self.ping * 0.001 < self.warpzone_teleport_time)
951 self.v_angle = WarpZone_TransformVAngles(self.warpzone_teleport_zone, self.v_angle);
952 self.v_angle_z += 720; // mark as adjusted