4 #include <common/t_items.qh>
7 #include <common/weapons/all.qh>
10 void WarpZone_Accumulator_Clear(entity acc)
12 acc.warpzone_transform = '0 0 0';
13 acc.warpzone_shift = '0 0 0';
15 void WarpZone_Accumulator_AddTransform(entity acc, vector t, vector s)
18 tr = AnglesTransform_Multiply(t, acc.warpzone_transform);
19 st = AnglesTransform_Multiply_GetPostShift(t, s, acc.warpzone_transform, acc.warpzone_shift);
20 acc.warpzone_transform = tr;
21 acc.warpzone_shift = st;
23 void WarpZone_Accumulator_Add(entity acc, entity wz)
25 WarpZone_Accumulator_AddTransform(acc, wz.warpzone_transform, wz.warpzone_shift);
27 void WarpZone_Accumulator_AddInverseTransform(entity acc, vector t, vector s)
30 tt = AnglesTransform_Invert(t);
31 ss = AnglesTransform_PrePostShift_GetPostShift(s, tt, '0 0 0');
32 WarpZone_Accumulator_AddTransform(acc, tt, ss);
33 // yes, this probably can be done simpler... but this way is "obvious" :)
35 void WarpZone_Accumulator_AddInverse(entity acc, entity wz)
37 WarpZone_Accumulator_AddInverseTransform(acc, wz.warpzone_transform, wz.warpzone_shift);
40 float autocvar_cl_warpzone_usetrace = 1;
41 vector WarpZone_camera_transform(entity this, vector org, vector ang)
44 if(this.warpzone_fadestart)
45 if(vdist(org - this.origin - 0.5 * (this.mins + this.maxs), >, this.warpzone_fadeend + 400))
47 // don't transform if zone faded out (plus 400qu safety margin for typical speeds and latencies)
48 // unneeded on client, on server this helps a lot
52 org = WarpZone_TransformOrigin(this, org);
53 vf = WarpZone_TransformVelocity(this, vf);
54 vr = WarpZone_TransformVelocity(this, vr);
55 vu = WarpZone_TransformVelocity(this, vu);
56 if(autocvar_cl_warpzone_usetrace)
57 traceline(this.warpzone_targetorigin, org, MOVE_NOMONSTERS, NULL);
59 trace_endpos = this.warpzone_targetorigin;
66 void WarpZone_SetUp(entity e, vector my_org, vector my_ang, vector other_org, vector other_ang)
68 e.warpzone_transform = AnglesTransform_RightDivide(other_ang, AnglesTransform_TurnDirectionFR(my_ang));
69 e.warpzone_shift = AnglesTransform_PrePostShift_GetPostShift(my_org, e.warpzone_transform, other_org);
70 e.warpzone_origin = my_org;
71 e.warpzone_targetorigin = other_org;
72 e.warpzone_angles = my_ang;
73 e.warpzone_targetangles = other_ang;
74 fixedmakevectors(my_ang); e.warpzone_forward = v_forward;
75 fixedmakevectors(other_ang); e.warpzone_targetforward = v_forward;
76 setcamera_transform(e, WarpZone_camera_transform);
79 vector WarpZone_Camera_camera_transform(entity this, vector org, vector ang)
81 // a fixed camera view
82 if(this.warpzone_fadestart)
83 if(vdist(org - this.origin - 0.5 * (this.mins + this.maxs), >, this.warpzone_fadeend + 400))
85 // don't transform if zone faded out (plus 400qu safety margin for typical speeds and latencies)
86 // unneeded on client, on server this helps a lot
87 trace_endpos = this.warpzone_origin;
88 makevectors(this.warpzone_angles);
89 return this.warpzone_origin;
92 void WarpZone_Camera_SetUp(entity e, vector my_org, vector my_ang) // we assume that e.oldorigin and e.avelocity point to view origin and direction
94 e.warpzone_origin = my_org;
95 e.warpzone_angles = my_ang;
96 setcamera_transform(e, WarpZone_Camera_camera_transform);
101 vector WarpZoneLib_BoxTouchesBrush_mins;
102 vector WarpZoneLib_BoxTouchesBrush_maxs;
103 entity WarpZoneLib_BoxTouchesBrush_ent;
104 entity WarpZoneLib_BoxTouchesBrush_ignore;
105 float WarpZoneLib_BoxTouchesBrush_Recurse()
111 tracebox('0 0 0', WarpZoneLib_BoxTouchesBrush_mins, WarpZoneLib_BoxTouchesBrush_maxs, '0 0 0', MOVE_NOMONSTERS, WarpZoneLib_BoxTouchesBrush_ignore);
113 if (trace_networkentity)
115 LOG_TRACE("hit a network ent, cannot continue WarpZoneLib_BoxTouchesBrush\n");
116 // we cannot continue, as a player blocks us...
123 if (trace_ent == WarpZoneLib_BoxTouchesBrush_ent)
128 se.solid = SOLID_NOT;
129 f = WarpZoneLib_BoxTouchesBrush_Recurse();
135 float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig)
139 if(!e.modelindex || e.warpzone_isboxy)
144 WarpZoneLib_BoxTouchesBrush_mins = mi;
145 WarpZoneLib_BoxTouchesBrush_maxs = ma;
146 WarpZoneLib_BoxTouchesBrush_ent = e;
147 WarpZoneLib_BoxTouchesBrush_ignore = ig;
148 f = WarpZoneLib_BoxTouchesBrush_Recurse();
154 entity WarpZone_Find(vector mi, vector ma)
156 // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
158 if(!warpzone_warpzones_exist)
160 for(e = NULL; (e = find(e, classname, "trigger_warpzone")); )
161 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, NULL))
166 void WarpZone_MakeAllSolid()
169 if(!warpzone_warpzones_exist)
171 for(e = NULL; (e = find(e, classname, "trigger_warpzone")); )
175 void WarpZone_MakeAllOther()
178 if(!warpzone_warpzones_exist)
180 for(e = NULL; (e = find(e, classname, "trigger_warpzone")); )
181 e.solid = SOLID_TRIGGER;
184 void WarpZone_Trace_InitTransform()
186 if(!WarpZone_trace_transform)
188 WarpZone_trace_transform = new_pure(warpzone_trace_transform);
190 WarpZone_Accumulator_Clear(WarpZone_trace_transform);
192 void WarpZone_Trace_AddTransform(entity wz)
194 WarpZone_Accumulator_Add(WarpZone_trace_transform, wz);
197 void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent, entity zone, WarpZone_trace_callback_t cb)
199 float nomonsters_adjusted;
206 WarpZone_trace_forent = forent;
207 WarpZone_trace_firstzone = NULL;
208 WarpZone_trace_lastzone = NULL;
209 WarpZone_Trace_InitTransform();
210 if(!warpzone_warpzones_exist)
212 if(nomonsters == MOVE_NOTHING)
217 cb(org, trace_endpos, end);
222 tracebox(org, mi, ma, end, nomonsters, WarpZone_trace_forent);
224 cb(org, trace_endpos, end);
239 nomonsters_adjusted = MOVE_NOMONSTERS;
242 nomonsters_adjusted = nomonsters;
245 if((contentshack = (WarpZone_trace_forent.dphitcontentsmask && !(WarpZone_trace_forent.dphitcontentsmask & DPCONTENTS_SOLID))))
246 BITSET_ASSIGN(WarpZone_trace_forent.dphitcontentsmask, DPCONTENTS_SOLID);
248 // if starting in warpzone, first transform
249 wz = WarpZone_Find(org + mi, org + ma);
252 WarpZone_trace_firstzone = wz;
253 WarpZone_trace_lastzone = wz;
254 if(zone && wz != zone)
256 // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return.
262 WarpZone_Trace_AddTransform(wz);
263 org = WarpZone_TransformOrigin(wz, org);
264 end = WarpZone_TransformOrigin(wz, end);
266 WarpZone_MakeAllSolid();
274 LOG_TRACE("Too many warpzones in sequence, aborting trace.\n");
278 tracebox(org, mi, ma, end, nomonsters_adjusted, WarpZone_trace_forent);
280 cb(org, trace_endpos, end);
282 sol = trace_startsolid;
284 frac = trace_fraction = frac + (1 - frac) * trace_fraction;
285 if(trace_fraction >= 1)
287 if(trace_ent.classname != "trigger_warpzone")
289 if((nomonsters == MOVE_NOTHING) || ((nomonsters == MOVE_WORLDONLY) && trace_ent) || (contentshack && (trace_dphitcontents & WarpZone_trace_forent.dphitcontentsmask) == DPCONTENTS_SOLID))
291 // continue the trace, ignoring this hit (we only care for warpzones)
292 org = trace_endpos + normalize(end - org);
294 // we cannot do an inverted trace here, as we do care for further warpzones inside that "solid" to be found
295 // otherwise, players could block entrances that way
301 // FIXME can this check be removed? Do we really need it?
302 LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace\n");
307 if(!WarpZone_trace_firstzone)
308 WarpZone_trace_firstzone = wz;
309 WarpZone_trace_lastzone = wz;
310 if(zone && wz != zone)
312 WarpZone_Trace_AddTransform(wz);
313 // we hit a warpzone... so, let's perform the trace after the warp again
314 org = WarpZone_TransformOrigin(wz, trace_endpos);
315 end = WarpZone_TransformOrigin(wz, end);
317 // we got warped, so let's step back a bit
318 tracebox(org, mi, ma, org + normalize(org - end) * 32, nomonsters_adjusted, WarpZone_trace_forent);
321 WarpZone_MakeAllOther();
324 BITCLR_ASSIGN(WarpZone_trace_forent.dphitcontentsmask, DPCONTENTS_SOLID);
325 trace_startsolid = sol;
331 void WarpZone_TraceBox(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent)
333 WarpZone_TraceBox_ThroughZone(org, mi, ma, end, nomonsters, forent, NULL, WarpZone_trace_callback_t_null);
336 void WarpZone_TraceLine(vector org, vector end, float nomonsters, entity forent)
338 WarpZone_TraceBox(org, '0 0 0', '0 0 0', end, nomonsters, forent);
341 void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZone_trace_callback_t cb)
344 vector vf, vr, vu, v0, o0;
349 g = cvar("sv_gravity") * e.gravity;
351 WarpZone_trace_forent = forent;
352 WarpZone_trace_firstzone = NULL;
353 WarpZone_trace_lastzone = NULL;
354 WarpZone_Trace_InitTransform();
355 WarpZone_tracetoss_time = 0;
356 if(!warpzone_warpzones_exist)
358 tracetoss(e, WarpZone_trace_forent);
360 cb(e.origin, trace_endpos, trace_endpos);
361 dt = vlen(e.origin - o0) / vlen(e.velocity);
362 WarpZone_tracetoss_time += dt;
363 e.velocity_z -= dt * g;
364 WarpZone_tracetoss_velocity = e.velocity;
373 // if starting in warpzone, first transform
374 wz = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs);
377 WarpZone_trace_firstzone = wz;
378 WarpZone_trace_lastzone = wz;
379 if(zone && wz != zone)
381 // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return.
383 WarpZone_tracetoss_time = 0;
387 WarpZone_Trace_AddTransform(wz);
388 vector org = WarpZone_TransformOrigin(wz, e.origin);
390 e.velocity = WarpZone_TransformVelocity(wz, e.velocity);
392 WarpZone_MakeAllSolid();
398 LOG_TRACE("Too many warpzones in sequence, aborting trace.\n");
402 tracetoss(e, WarpZone_trace_forent);
404 cb(e.origin, trace_endpos, trace_endpos);
405 dt = vlen(trace_endpos - e.origin) / vlen(e.velocity);
406 WarpZone_tracetoss_time += dt;
407 e.origin = trace_endpos;
408 e.velocity_z -= dt * g;
409 if(trace_fraction >= 1)
411 if(trace_ent.classname != "trigger_warpzone")
415 // FIXME can this check be removed? Do we really need it?
416 LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace\n");
421 if(!WarpZone_trace_firstzone)
422 WarpZone_trace_firstzone = wz;
423 WarpZone_trace_lastzone = wz;
424 if(zone && wz != zone)
426 WarpZone_Trace_AddTransform(wz);
427 // we hit a warpzone... so, let's perform the trace after the warp again
428 e.origin = WarpZone_TransformOrigin(wz, e.origin);
429 e.velocity = WarpZone_TransformVelocity(wz, e.velocity);
431 // we got warped, so let's step back a bit
432 e.velocity = -e.velocity;
433 tracetoss(e, WarpZone_trace_forent);
434 dt = vlen(trace_endpos - e.origin) / vlen(e.velocity);
435 WarpZone_tracetoss_time -= dt;
436 e.origin = trace_endpos;
437 e.velocity = -e.velocity;
439 WarpZone_MakeAllOther();
441 WarpZone_tracetoss_velocity = e.velocity;
445 // restore old entity data (caller just uses trace_endpos, WarpZone_tracetoss_velocity and the transform)
450 void WarpZone_TraceToss(entity e, entity forent)
452 WarpZone_TraceToss_ThroughZone(e, forent, NULL, WarpZone_trace_callback_t_null);
455 entity WarpZone_TrailParticles_trace_callback_own;
456 float WarpZone_TrailParticles_trace_callback_eff;
457 void WarpZone_TrailParticles_trace_callback(vector from, vector endpos, vector to)
459 __trailparticles(WarpZone_TrailParticles_trace_callback_own, WarpZone_TrailParticles_trace_callback_eff, from, endpos);
462 void WarpZone_TrailParticles(entity own, float eff, vector org, vector end)
464 WarpZone_TrailParticles_trace_callback_own = own;
465 WarpZone_TrailParticles_trace_callback_eff = eff;
466 WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, NULL, NULL, WarpZone_TrailParticles_trace_callback);
470 float WarpZone_TrailParticles_trace_callback_f;
471 float WarpZone_TrailParticles_trace_callback_flags;
472 void WarpZone_TrailParticles_WithMultiplier_trace_callback(vector from, vector endpos, vector to)
474 boxparticles(WarpZone_TrailParticles_trace_callback_eff, WarpZone_TrailParticles_trace_callback_own, from, endpos, WarpZone_TrailParticles_trace_callback_own.velocity, WarpZone_TrailParticles_trace_callback_own.velocity, WarpZone_TrailParticles_trace_callback_f, WarpZone_TrailParticles_trace_callback_flags);
477 void WarpZone_TrailParticles_WithMultiplier(entity own, float eff, vector org, vector end, float f, int boxflags)
479 WarpZone_TrailParticles_trace_callback_own = own;
480 WarpZone_TrailParticles_trace_callback_eff = eff;
481 WarpZone_TrailParticles_trace_callback_f = f;
482 WarpZone_TrailParticles_trace_callback_flags = boxflags | PARTICLES_DRAWASTRAIL;
483 WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, NULL, NULL, WarpZone_TrailParticles_WithMultiplier_trace_callback);
487 float WarpZone_PlaneDist(entity wz, vector v)
489 return (v - wz.warpzone_origin) * wz.warpzone_forward;
492 float WarpZone_TargetPlaneDist(entity wz, vector v)
494 return (v - wz.warpzone_targetorigin) * wz.warpzone_targetforward;
497 vector WarpZone_TransformOrigin(entity wz, vector v)
499 return wz.warpzone_shift + AnglesTransform_Apply(wz.warpzone_transform, v);
502 vector WarpZone_TransformVelocity(entity wz, vector v)
504 return AnglesTransform_Apply(wz.warpzone_transform, v);
507 vector WarpZone_TransformAngles(entity wz, vector v)
509 return AnglesTransform_ApplyToAngles(wz.warpzone_transform, v);
512 vector WarpZone_TransformVAngles(entity wz, vector ang)
520 ang = AnglesTransform_ApplyToVAngles(wz.warpzone_transform, ang);
523 ang = AnglesTransform_Normalize(ang, true);
524 ang = AnglesTransform_CancelRoll(ang);
527 ang = AnglesTransform_Normalize(ang, false);
533 vector WarpZone_UnTransformOrigin(entity wz, vector v)
535 return AnglesTransform_Apply(AnglesTransform_Invert(wz.warpzone_transform), v - wz.warpzone_shift);
538 vector WarpZone_UnTransformVelocity(entity wz, vector v)
540 return AnglesTransform_Apply(AnglesTransform_Invert(wz.warpzone_transform), v);
543 vector WarpZone_UnTransformAngles(entity wz, vector v)
545 return AnglesTransform_ApplyToAngles(AnglesTransform_Invert(wz.warpzone_transform), v);
548 vector WarpZone_UnTransformVAngles(entity wz, vector ang)
555 ang = AnglesTransform_ApplyToVAngles(AnglesTransform_Invert(wz.warpzone_transform), ang);
556 ang = AnglesTransform_Normalize(ang, true);
557 ang = AnglesTransform_CancelRoll(ang);
563 vector WarpZoneLib_NearestPointOnBox(vector mi, vector ma, vector org)
566 nearest.x = bound(mi.x, org.x, ma.x);
567 nearest.y = bound(mi.y, org.y, ma.y);
568 nearest.z = bound(mi.z, org.z, ma.z);
572 bool WarpZoneLib_BadEntity(entity e)
574 if (is_pure(e)) return true;
575 string s = e.classname;
578 // case "net_linked": // actually some real entities are linked without classname, fail
583 if (startsWith(s, "target_")) return true;
585 if (startsWith(s, "info_")) return true;
590 .float WarpZone_findradius_hit;
591 .entity WarpZone_findradius_next;
592 void WarpZone_FindRadius_Recurse(
593 /** blast origin of current search */
596 /** original blast origin */
598 /** how to untransform (victim to blast system) */
601 bool needlineofsight)
603 if (rad <= 0) return;
605 FOREACH_ENTITY_RADIUS(org, rad, !WarpZoneLib_BadEntity(it), {
606 vector p = WarpZoneLib_NearestPointOnBox(it.origin + it.mins, it.origin + it.maxs, org0);
609 traceline(org, p, MOVE_NOMONSTERS, it);
610 if (trace_fraction < 1) continue;
612 if (!it.WarpZone_findradius_hit || vlen2(it.WarpZone_findradius_dist) > vlen2(org0 - p))
614 it.WarpZone_findradius_nearest = p;
615 it.WarpZone_findradius_dist = org0 - p;
616 it.WarpZone_findradius_findorigin = org;
617 it.WarpZone_findradius_findradius = rad;
618 if (it.classname == "warpzone_refsys")
620 // ignore, especially: do not overwrite the refsys parameters
622 else if (it.classname == "trigger_warpzone")
624 it.WarpZone_findradius_next = wz;
626 it.WarpZone_findradius_hit = 1;
627 it.enemy.WarpZone_findradius_dist = '0 0 0'; // we don't want to go through this zone ever again
628 it.enemy.WarpZone_findradius_hit = 1;
632 it.warpzone_transform = transform;
633 it.warpzone_shift = shift;
634 it.WarpZone_findradius_hit = 1;
638 for(entity e = wz; e; e = e.WarpZone_findradius_next)
640 if (WarpZoneLib_BadEntity(e)) continue;
642 vector org0_new = WarpZone_TransformOrigin(e, org);
643 traceline(e.warpzone_targetorigin, org0_new, MOVE_NOMONSTERS, e);
644 vector org_new = trace_endpos;
646 vector transform_new = AnglesTransform_Multiply(e.warpzone_transform, transform);
647 vector shift_new = AnglesTransform_Multiply_GetPostShift(e.warpzone_transform, e.warpzone_shift, transform, shift);
648 WarpZone_FindRadius_Recurse(
650 bound(0, rad - vlen(org_new - org0_new), rad - 8),
652 transform_new, shift_new,
654 e.WarpZone_findradius_hit = 0;
655 e.enemy.WarpZone_findradius_hit = 0;
658 entity WarpZone_FindRadius(vector org, float rad, bool needlineofsight)
660 // FIXME: why can't we do this? (sometimes finds nothing, breaking explosions)
661 // if (!warpzone_warpzones_exist && !needlineofsight) return findradius(org, rad);
662 WarpZone_FindRadius_Recurse(org, rad, org, '0 0 0', '0 0 0', needlineofsight);
663 entity list_first = findchainfloat(WarpZone_findradius_hit, 1);
664 FOREACH_LIST(list, chain, true, it.WarpZone_findradius_hit = 0);
668 .entity WarpZone_refsys;
669 void WarpZone_RefSys_GC(entity this)
671 // garbage collect unused reference systems
672 this.nextthink = time + 1;
673 if(this.owner.WarpZone_refsys != this)
676 void WarpZone_RefSys_CheckCreate(entity me)
678 if(me.WarpZone_refsys.owner != me)
680 me.WarpZone_refsys = new(warpzone_refsys);
681 me.WarpZone_refsys.owner = me;
682 setthink(me.WarpZone_refsys, WarpZone_RefSys_GC);
683 me.WarpZone_refsys.nextthink = time + 1;
684 WarpZone_Accumulator_Clear(me.WarpZone_refsys);
687 void WarpZone_RefSys_Clear(entity me)
689 if(me.WarpZone_refsys)
691 delete(me.WarpZone_refsys);
692 me.WarpZone_refsys = NULL;
695 void WarpZone_RefSys_AddTransform(entity me, vector t, vector s)
697 if(t != '0 0 0' || s != '0 0 0')
699 WarpZone_RefSys_CheckCreate(me);
700 WarpZone_Accumulator_AddTransform(me.WarpZone_refsys, t, s);
703 void WarpZone_RefSys_Add(entity me, entity wz)
705 WarpZone_RefSys_AddTransform(me, wz.warpzone_transform, wz.warpzone_shift);
707 void WarpZone_RefSys_AddInverseTransform(entity me, vector t, vector s)
709 if(t != '0 0 0' || s != '0 0 0')
711 WarpZone_RefSys_CheckCreate(me);
712 WarpZone_Accumulator_AddInverseTransform(me.WarpZone_refsys, t, s);
715 void WarpZone_RefSys_AddInverse(entity me, entity wz)
717 WarpZone_RefSys_AddInverseTransform(me, wz.warpzone_transform, wz.warpzone_shift);
719 .vector WarpZone_refsys_incremental_shift;
720 .vector WarpZone_refsys_incremental_transform;
721 void WarpZone_RefSys_AddIncrementally(entity me, entity ref)
724 if(me.WarpZone_refsys_incremental_transform == ref.WarpZone_refsys.warpzone_transform)
725 if(me.WarpZone_refsys_incremental_shift == ref.WarpZone_refsys.warpzone_shift)
727 WarpZone_Accumulator_AddInverseTransform(me.WarpZone_refsys, me.WarpZone_refsys_incremental_transform, me.WarpZone_refsys_incremental_shift);
728 WarpZone_Accumulator_Add(me.WarpZone_refsys, ref.WarpZone_refsys);
729 me.WarpZone_refsys_incremental_shift = ref.WarpZone_refsys.warpzone_shift;
730 me.WarpZone_refsys_incremental_transform = ref.WarpZone_refsys.warpzone_transform;
732 void WarpZone_RefSys_BeginAddingIncrementally(entity me, entity ref)
734 me.WarpZone_refsys_incremental_shift = ref.WarpZone_refsys.warpzone_shift;
735 me.WarpZone_refsys_incremental_transform = ref.WarpZone_refsys.warpzone_transform;
737 vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org)
739 if(from.WarpZone_refsys)
740 org = WarpZone_UnTransformOrigin(from.WarpZone_refsys, org);
741 if(to.WarpZone_refsys)
742 org = WarpZone_TransformOrigin(to.WarpZone_refsys, org);
745 vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel)
747 if(from.WarpZone_refsys)
748 vel = WarpZone_UnTransformVelocity(from.WarpZone_refsys, vel);
749 if(to.WarpZone_refsys)
750 vel = WarpZone_TransformVelocity(to.WarpZone_refsys, vel);
753 vector WarpZone_RefSys_TransformAngles(entity from, entity to, vector ang)
755 if(from.WarpZone_refsys)
756 ang = WarpZone_UnTransformAngles(from.WarpZone_refsys, ang);
757 if(to.WarpZone_refsys)
758 ang = WarpZone_TransformAngles(to.WarpZone_refsys, ang);
761 vector WarpZone_RefSys_TransformVAngles(entity from, entity to, vector ang)
763 if(from.WarpZone_refsys)
764 ang = WarpZone_UnTransformVAngles(from.WarpZone_refsys, ang);
765 if(to.WarpZone_refsys)
766 ang = WarpZone_TransformVAngles(to.WarpZone_refsys, ang);
769 void WarpZone_RefSys_Copy(entity me, entity from)
771 if(from.WarpZone_refsys)
773 WarpZone_RefSys_CheckCreate(me);
774 me.WarpZone_refsys.warpzone_shift = from.WarpZone_refsys.warpzone_shift;
775 me.WarpZone_refsys.warpzone_transform = from.WarpZone_refsys.warpzone_transform;
778 WarpZone_RefSys_Clear(me);
780 entity WarpZone_RefSys_SpawnSameRefSys(entity me)
784 WarpZone_RefSys_Copy(e, me);
788 float WarpZoneLib_ExactTrigger_Touch(entity this, entity toucher)
790 return !WarpZoneLib_BoxTouchesBrush(toucher.absmin, toucher.absmax, this, toucher);
794 void WarpZoneLib_MoveOutOfSolid_Expand(entity e, vector by)
797 tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
798 if (trace_startsolid)
800 if (trace_fraction < 1)
803 // adjust origin in the other direction...
804 setorigin(e, e.origin - by * (1 - trace_fraction));
808 float WarpZoneLib_MoveOutOfSolid(entity e)
813 traceline(o, o, MOVE_WORLDONLY, e);
814 if (trace_startsolid)
817 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
818 if (!trace_startsolid)
825 WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m0_x);
827 WarpZoneLib_MoveOutOfSolid_Expand(e, '1 0 0' * m1_x);
829 WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m0_y);
831 WarpZoneLib_MoveOutOfSolid_Expand(e, '0 1 0' * m1_y);
833 WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m0_z);
835 WarpZoneLib_MoveOutOfSolid_Expand(e, '0 0 1' * m1_z);
837 setorigin(e, e.origin);
839 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
840 if (trace_startsolid)