4 #include <client/items/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 vector forward, right, up;
75 FIXED_MAKE_VECTORS(my_ang, forward, right, up);
76 e.warpzone_forward = forward;
77 FIXED_MAKE_VECTORS(other_ang, forward, right, up);
78 e.warpzone_targetforward = forward;
79 setcamera_transform(e, WarpZone_camera_transform);
82 vector WarpZone_Camera_camera_transform(entity this, vector org, vector ang)
84 // a fixed camera view
85 if(this.warpzone_fadestart)
86 if(vdist(org - this.origin - 0.5 * (this.mins + this.maxs), >, this.warpzone_fadeend + 400))
88 // don't transform if zone faded out (plus 400qu safety margin for typical speeds and latencies)
89 // unneeded on client, on server this helps a lot
90 trace_endpos = this.warpzone_origin;
91 makevectors(this.warpzone_angles);
92 return this.warpzone_origin;
95 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
97 e.warpzone_origin = my_org;
98 e.warpzone_angles = my_ang;
99 setcamera_transform(e, WarpZone_Camera_camera_transform);
104 vector WarpZoneLib_BoxTouchesBrush_mins;
105 vector WarpZoneLib_BoxTouchesBrush_maxs;
106 entity WarpZoneLib_BoxTouchesBrush_ent;
107 entity WarpZoneLib_BoxTouchesBrush_ignore;
108 float WarpZoneLib_BoxTouchesBrush_Recurse()
114 tracebox('0 0 0', WarpZoneLib_BoxTouchesBrush_mins, WarpZoneLib_BoxTouchesBrush_maxs, '0 0 0', MOVE_NOMONSTERS, WarpZoneLib_BoxTouchesBrush_ignore);
116 if (trace_networkentity)
118 LOG_TRACE("hit a network ent, cannot continue WarpZoneLib_BoxTouchesBrush");
119 // we cannot continue, as a player blocks us...
126 if (trace_ent == WarpZoneLib_BoxTouchesBrush_ent)
131 se.solid = SOLID_NOT;
132 f = WarpZoneLib_BoxTouchesBrush_Recurse();
138 float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig)
142 if(!e.modelindex || e.warpzone_isboxy)
147 WarpZoneLib_BoxTouchesBrush_mins = mi;
148 WarpZoneLib_BoxTouchesBrush_maxs = ma;
149 WarpZoneLib_BoxTouchesBrush_ent = e;
150 WarpZoneLib_BoxTouchesBrush_ignore = ig;
151 f = WarpZoneLib_BoxTouchesBrush_Recurse();
157 entity WarpZone_Find(vector mi, vector ma)
159 // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
160 if(!warpzone_warpzones_exist)
162 IL_EACH(g_warpzones, WarpZoneLib_BoxTouchesBrush(mi, ma, it, NULL),
169 void WarpZone_MakeAllSolid()
171 if(!warpzone_warpzones_exist)
173 IL_EACH(g_warpzones, true,
175 it.solid = SOLID_BSP;
179 void WarpZone_MakeAllOther()
181 if(!warpzone_warpzones_exist)
183 IL_EACH(g_warpzones, true,
185 it.solid = SOLID_TRIGGER;
189 void WarpZone_Trace_InitTransform()
191 if(!WarpZone_trace_transform)
193 WarpZone_trace_transform = new_pure(warpzone_trace_transform);
195 WarpZone_Accumulator_Clear(WarpZone_trace_transform);
197 void WarpZone_Trace_AddTransform(entity wz)
199 WarpZone_Accumulator_Add(WarpZone_trace_transform, wz);
202 void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent, entity zone, WarpZone_trace_callback_t cb)
204 float nomonsters_adjusted;
210 WarpZone_trace_forent = forent;
211 WarpZone_trace_firstzone = NULL;
212 WarpZone_trace_lastzone = NULL;
213 WarpZone_Trace_InitTransform();
214 if(!warpzone_warpzones_exist)
216 if(nomonsters == MOVE_NOTHING)
221 cb(org, trace_endpos, end);
226 tracebox(org, mi, ma, end, nomonsters, WarpZone_trace_forent);
228 cb(org, trace_endpos, end);
241 nomonsters_adjusted = MOVE_NOMONSTERS;
244 nomonsters_adjusted = nomonsters;
247 if((contentshack = (WarpZone_trace_forent.dphitcontentsmask && !(WarpZone_trace_forent.dphitcontentsmask & DPCONTENTS_SOLID))))
248 BITSET_ASSIGN(WarpZone_trace_forent.dphitcontentsmask, DPCONTENTS_SOLID);
250 // if starting in warpzone, first transform
251 wz = WarpZone_Find(org + mi, org + ma);
254 WarpZone_trace_firstzone = wz;
255 WarpZone_trace_lastzone = wz;
256 if(zone && wz != zone)
258 // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return.
264 WarpZone_Trace_AddTransform(wz);
265 org = WarpZone_TransformOrigin(wz, org);
266 end = WarpZone_TransformOrigin(wz, end);
268 WarpZone_MakeAllSolid();
276 LOG_TRACE("Too many warpzones in sequence, aborting trace.");
280 tracebox(org, mi, ma, end, nomonsters_adjusted, WarpZone_trace_forent);
282 cb(org, trace_endpos, end);
284 sol = trace_startsolid;
286 frac = trace_fraction = frac + (1 - frac) * trace_fraction;
287 if(trace_fraction >= 1)
289 if(trace_ent.classname != "trigger_warpzone")
291 if((nomonsters == MOVE_NOTHING) || ((nomonsters == MOVE_WORLDONLY) && trace_ent) || (contentshack && (trace_dphitcontents & WarpZone_trace_forent.dphitcontentsmask) == DPCONTENTS_SOLID))
293 // continue the trace, ignoring this hit (we only care for warpzones)
294 org = trace_endpos + normalize(end - org);
296 // we cannot do an inverted trace here, as we do care for further warpzones inside that "solid" to be found
297 // otherwise, players could block entrances that way
301 /*if(trace_ent == wz)
303 // FIXME can this check be removed? Do we really need it?
304 LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace");
309 if(!WarpZone_trace_firstzone)
310 WarpZone_trace_firstzone = wz;
311 WarpZone_trace_lastzone = wz;
312 if(zone && wz != zone)
314 WarpZone_Trace_AddTransform(wz);
315 // we hit a warpzone... so, let's perform the trace after the warp again
316 org = WarpZone_TransformOrigin(wz, trace_endpos);
317 end = WarpZone_TransformOrigin(wz, end);
319 // we got warped, so let's step back a bit
320 tracebox(org, mi, ma, org + normalize(org - end) * 32, nomonsters_adjusted, WarpZone_trace_forent);
323 WarpZone_MakeAllOther();
326 BITCLR_ASSIGN(WarpZone_trace_forent.dphitcontentsmask, DPCONTENTS_SOLID);
327 trace_startsolid = sol;
333 void WarpZone_TraceBox(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent)
335 WarpZone_TraceBox_ThroughZone(org, mi, ma, end, nomonsters, forent, NULL, WarpZone_trace_callback_t_null);
338 void WarpZone_TraceLine(vector org, vector end, float nomonsters, entity forent)
340 WarpZone_TraceBox(org, '0 0 0', '0 0 0', end, nomonsters, forent);
343 void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZone_trace_callback_t cb)
346 vector vf, vr, vu, v0, o0;
351 g = cvar("sv_gravity") * e.gravity;
353 WarpZone_trace_forent = forent;
354 WarpZone_trace_firstzone = NULL;
355 WarpZone_trace_lastzone = NULL;
356 WarpZone_Trace_InitTransform();
357 WarpZone_tracetoss_time = 0;
358 if(!warpzone_warpzones_exist)
360 tracetoss(e, WarpZone_trace_forent);
362 cb(e.origin, trace_endpos, trace_endpos);
363 dt = vlen(e.origin - o0) / vlen(e.velocity);
364 WarpZone_tracetoss_time += dt;
365 e.velocity_z -= dt * g;
366 WarpZone_tracetoss_velocity = e.velocity;
375 // if starting in warpzone, first transform
376 wz = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs);
379 WarpZone_trace_firstzone = wz;
380 WarpZone_trace_lastzone = wz;
381 if(zone && wz != zone)
383 // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return.
385 WarpZone_tracetoss_time = 0;
389 WarpZone_Trace_AddTransform(wz);
390 vector org = WarpZone_TransformOrigin(wz, e.origin);
392 e.velocity = WarpZone_TransformVelocity(wz, e.velocity);
394 WarpZone_MakeAllSolid();
400 LOG_TRACE("Too many warpzones in sequence, aborting trace.");
404 tracetoss(e, WarpZone_trace_forent);
406 cb(e.origin, trace_endpos, trace_endpos);
407 dt = vlen(trace_endpos - e.origin) / vlen(e.velocity);
408 WarpZone_tracetoss_time += dt;
409 e.origin = trace_endpos;
410 e.velocity_z -= dt * g;
411 if(trace_fraction >= 1)
413 if(trace_ent.classname != "trigger_warpzone")
417 // FIXME can this check be removed? Do we really need it?
418 LOG_TRACE("I transformed into the same zone again, wtf, aborting the trace");
423 if(!WarpZone_trace_firstzone)
424 WarpZone_trace_firstzone = wz;
425 WarpZone_trace_lastzone = wz;
426 if(zone && wz != zone)
428 WarpZone_Trace_AddTransform(wz);
429 // we hit a warpzone... so, let's perform the trace after the warp again
430 e.origin = WarpZone_TransformOrigin(wz, e.origin);
431 e.velocity = WarpZone_TransformVelocity(wz, e.velocity);
433 // we got warped, so let's step back a bit
434 e.velocity = -e.velocity;
435 tracetoss(e, WarpZone_trace_forent);
436 dt = vlen(trace_endpos - e.origin) / vlen(e.velocity);
437 WarpZone_tracetoss_time -= dt;
438 e.origin = trace_endpos;
439 e.velocity = -e.velocity;
441 WarpZone_MakeAllOther();
443 WarpZone_tracetoss_velocity = e.velocity;
447 // restore old entity data (caller just uses trace_endpos, WarpZone_tracetoss_velocity and the transform)
452 void WarpZone_TraceToss(entity e, entity forent)
454 WarpZone_TraceToss_ThroughZone(e, forent, NULL, WarpZone_trace_callback_t_null);
457 entity WarpZone_TrailParticles_trace_callback_own;
458 float WarpZone_TrailParticles_trace_callback_eff;
459 void WarpZone_TrailParticles_trace_callback(vector from, vector endpos, vector to)
461 __trailparticles(WarpZone_TrailParticles_trace_callback_own, WarpZone_TrailParticles_trace_callback_eff, from, endpos);
464 void WarpZone_TrailParticles(entity own, float eff, vector org, vector end)
466 WarpZone_TrailParticles_trace_callback_own = own;
467 WarpZone_TrailParticles_trace_callback_eff = eff;
468 WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, NULL, NULL, WarpZone_TrailParticles_trace_callback);
472 float WarpZone_TrailParticles_trace_callback_f;
473 float WarpZone_TrailParticles_trace_callback_flags;
474 void WarpZone_TrailParticles_WithMultiplier_trace_callback(vector from, vector endpos, vector to)
476 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);
479 void WarpZone_TrailParticles_WithMultiplier(entity own, float eff, vector org, vector end, float f, int boxflags)
481 WarpZone_TrailParticles_trace_callback_own = own;
482 WarpZone_TrailParticles_trace_callback_eff = eff;
483 WarpZone_TrailParticles_trace_callback_f = f;
484 WarpZone_TrailParticles_trace_callback_flags = boxflags | PARTICLES_DRAWASTRAIL;
485 WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, NULL, NULL, WarpZone_TrailParticles_WithMultiplier_trace_callback);
489 float WarpZone_PlaneDist(entity wz, vector v)
491 return (v - wz.warpzone_origin) * wz.warpzone_forward;
494 float WarpZone_TargetPlaneDist(entity wz, vector v)
496 return (v - wz.warpzone_targetorigin) * wz.warpzone_targetforward;
499 vector WarpZone_TransformOrigin(entity wz, vector v)
501 return wz.warpzone_shift + AnglesTransform_Apply(wz.warpzone_transform, v);
504 vector WarpZone_TransformVelocity(entity wz, vector v)
506 return AnglesTransform_Apply(wz.warpzone_transform, v);
509 vector WarpZone_TransformAngles(entity wz, vector v)
511 return AnglesTransform_ApplyToAngles(wz.warpzone_transform, v);
514 vector WarpZone_TransformVAngles(entity wz, vector ang)
522 ang = AnglesTransform_ApplyToVAngles(wz.warpzone_transform, ang);
525 ang = AnglesTransform_Normalize(ang, true);
526 ang = AnglesTransform_CancelRoll(ang);
529 ang = AnglesTransform_Normalize(ang, false);
535 vector WarpZone_UnTransformOrigin(entity wz, vector v)
537 return AnglesTransform_Apply(AnglesTransform_Invert(wz.warpzone_transform), v - wz.warpzone_shift);
540 vector WarpZone_UnTransformVelocity(entity wz, vector v)
542 return AnglesTransform_Apply(AnglesTransform_Invert(wz.warpzone_transform), v);
545 vector WarpZone_UnTransformAngles(entity wz, vector v)
547 return AnglesTransform_ApplyToAngles(AnglesTransform_Invert(wz.warpzone_transform), v);
550 vector WarpZone_UnTransformVAngles(entity wz, vector ang)
557 ang = AnglesTransform_ApplyToVAngles(AnglesTransform_Invert(wz.warpzone_transform), ang);
558 ang = AnglesTransform_Normalize(ang, true);
559 ang = AnglesTransform_CancelRoll(ang);
565 vector WarpZoneLib_NearestPointOnBox(vector mi, vector ma, vector org)
568 nearest.x = bound(mi.x, org.x, ma.x);
569 nearest.y = bound(mi.y, org.y, ma.y);
570 nearest.z = bound(mi.z, org.z, ma.z);
574 bool WarpZoneLib_BadEntity(entity e)
576 if (is_pure(e)) return true;
577 string s = e.classname;
579 //if (s == "net_linked") return true; // actually some real entities are linked without classname, fail
580 if (s == "") return true;
582 if (startsWith(s, "target_")) return true;
584 if (startsWith(s, "info_")) return true;
589 .float WarpZone_findradius_hit;
590 .entity WarpZone_findradius_next;
591 void WarpZone_FindRadius_Recurse(
592 /** blast origin of current search */
595 /** original blast origin */
597 /** how to untransform (victim to blast system) */
600 bool needlineofsight)
602 if (rad <= 0) return;
604 FOREACH_ENTITY_RADIUS(org, rad, !WarpZoneLib_BadEntity(it), {
605 vector p = WarpZoneLib_NearestPointOnBox(it.origin + it.mins, it.origin + it.maxs, org0);
608 traceline(org, p, MOVE_NOMONSTERS, it);
609 if (trace_fraction < 1) continue;
611 if (!it.WarpZone_findradius_hit || vlen2(it.WarpZone_findradius_dist) > vlen2(org0 - p))
613 it.WarpZone_findradius_nearest = p;
614 it.WarpZone_findradius_dist = org0 - p;
615 it.WarpZone_findradius_findorigin = org;
616 it.WarpZone_findradius_findradius = rad;
617 if (it.classname == "warpzone_refsys")
619 // ignore, especially: do not overwrite the refsys parameters
621 else if (it.classname == "trigger_warpzone")
623 it.WarpZone_findradius_next = wz;
625 it.WarpZone_findradius_hit = 1;
626 it.enemy.WarpZone_findradius_dist = '0 0 0'; // we don't want to go through this zone ever again
627 it.enemy.WarpZone_findradius_hit = 1;
631 it.warpzone_transform = transform;
632 it.warpzone_shift = shift;
633 it.WarpZone_findradius_hit = 1;
637 for(entity e = wz; e; e = e.WarpZone_findradius_next)
639 if (WarpZoneLib_BadEntity(e)) continue;
641 vector org0_new = WarpZone_TransformOrigin(e, org);
642 traceline(e.warpzone_targetorigin, org0_new, MOVE_NOMONSTERS, e);
643 vector org_new = trace_endpos;
645 vector transform_new = AnglesTransform_Multiply(e.warpzone_transform, transform);
646 vector shift_new = AnglesTransform_Multiply_GetPostShift(e.warpzone_transform, e.warpzone_shift, transform, shift);
647 WarpZone_FindRadius_Recurse(
649 bound(0, rad - vlen(org_new - org0_new), rad - 8),
651 transform_new, shift_new,
653 e.WarpZone_findradius_hit = 0;
654 e.enemy.WarpZone_findradius_hit = 0;
657 entity WarpZone_FindRadius(vector org, float rad, bool needlineofsight)
659 // FIXME: why can't we do this? (sometimes finds nothing, breaking explosions)
660 // if (!warpzone_warpzones_exist && !needlineofsight) return findradius(org, rad);
661 WarpZone_FindRadius_Recurse(org, rad, org, '0 0 0', '0 0 0', needlineofsight);
662 entity list_first = findchainfloat(WarpZone_findradius_hit, 1);
663 FOREACH_LIST(list, chain, true, it.WarpZone_findradius_hit = 0);
667 .entity WarpZone_refsys;
668 void WarpZone_RefSys_GC(entity this)
670 // garbage collect unused reference systems
671 this.nextthink = time + 1;
672 if(this.owner.WarpZone_refsys != this)
675 void WarpZone_RefSys_CheckCreate(entity me)
677 if(me.WarpZone_refsys.owner != me)
679 me.WarpZone_refsys = new(warpzone_refsys);
680 me.WarpZone_refsys.owner = me;
681 setthink(me.WarpZone_refsys, WarpZone_RefSys_GC);
682 me.WarpZone_refsys.nextthink = time + 1;
683 WarpZone_Accumulator_Clear(me.WarpZone_refsys);
686 void WarpZone_RefSys_Clear(entity me)
688 if(me.WarpZone_refsys)
690 delete(me.WarpZone_refsys);
691 me.WarpZone_refsys = NULL;
694 void WarpZone_RefSys_AddTransform(entity me, vector t, vector s)
696 if(t != '0 0 0' || s != '0 0 0')
698 WarpZone_RefSys_CheckCreate(me);
699 WarpZone_Accumulator_AddTransform(me.WarpZone_refsys, t, s);
702 void WarpZone_RefSys_Add(entity me, entity wz)
704 WarpZone_RefSys_AddTransform(me, wz.warpzone_transform, wz.warpzone_shift);
706 void WarpZone_RefSys_AddInverseTransform(entity me, vector t, vector s)
708 if(t != '0 0 0' || s != '0 0 0')
710 WarpZone_RefSys_CheckCreate(me);
711 WarpZone_Accumulator_AddInverseTransform(me.WarpZone_refsys, t, s);
714 void WarpZone_RefSys_AddInverse(entity me, entity wz)
716 WarpZone_RefSys_AddInverseTransform(me, wz.warpzone_transform, wz.warpzone_shift);
718 .vector WarpZone_refsys_incremental_shift;
719 .vector WarpZone_refsys_incremental_transform;
720 void WarpZone_RefSys_AddIncrementally(entity me, entity ref)
723 if(me.WarpZone_refsys_incremental_transform == ref.WarpZone_refsys.warpzone_transform)
724 if(me.WarpZone_refsys_incremental_shift == ref.WarpZone_refsys.warpzone_shift)
726 WarpZone_Accumulator_AddInverseTransform(me.WarpZone_refsys, me.WarpZone_refsys_incremental_transform, me.WarpZone_refsys_incremental_shift);
727 WarpZone_Accumulator_Add(me.WarpZone_refsys, ref.WarpZone_refsys);
728 me.WarpZone_refsys_incremental_shift = ref.WarpZone_refsys.warpzone_shift;
729 me.WarpZone_refsys_incremental_transform = ref.WarpZone_refsys.warpzone_transform;
731 void WarpZone_RefSys_BeginAddingIncrementally(entity me, entity ref)
733 me.WarpZone_refsys_incremental_shift = ref.WarpZone_refsys.warpzone_shift;
734 me.WarpZone_refsys_incremental_transform = ref.WarpZone_refsys.warpzone_transform;
736 vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org)
738 if(from.WarpZone_refsys)
739 org = WarpZone_UnTransformOrigin(from.WarpZone_refsys, org);
740 if(to.WarpZone_refsys)
741 org = WarpZone_TransformOrigin(to.WarpZone_refsys, org);
744 vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel)
746 if(from.WarpZone_refsys)
747 vel = WarpZone_UnTransformVelocity(from.WarpZone_refsys, vel);
748 if(to.WarpZone_refsys)
749 vel = WarpZone_TransformVelocity(to.WarpZone_refsys, vel);
752 vector WarpZone_RefSys_TransformAngles(entity from, entity to, vector ang)
754 if(from.WarpZone_refsys)
755 ang = WarpZone_UnTransformAngles(from.WarpZone_refsys, ang);
756 if(to.WarpZone_refsys)
757 ang = WarpZone_TransformAngles(to.WarpZone_refsys, ang);
760 vector WarpZone_RefSys_TransformVAngles(entity from, entity to, vector ang)
762 if(from.WarpZone_refsys)
763 ang = WarpZone_UnTransformVAngles(from.WarpZone_refsys, ang);
764 if(to.WarpZone_refsys)
765 ang = WarpZone_TransformVAngles(to.WarpZone_refsys, ang);
768 void WarpZone_RefSys_Copy(entity me, entity from)
770 if(from.WarpZone_refsys)
772 WarpZone_RefSys_CheckCreate(me);
773 me.WarpZone_refsys.warpzone_shift = from.WarpZone_refsys.warpzone_shift;
774 me.WarpZone_refsys.warpzone_transform = from.WarpZone_refsys.warpzone_transform;
777 WarpZone_RefSys_Clear(me);
779 entity WarpZone_RefSys_SpawnSameRefSys(entity me)
782 WarpZone_RefSys_Copy(e, me);
786 bool WarpZoneLib_ExactTrigger_Touch(entity this, entity toucher)
788 vector emin = toucher.absmin, emax = toucher.absmax;
791 // DP's tracebox enlarges absolute bounding boxes by a single quake unit
792 // we must undo that here to allow accurate touching
796 return !WarpZoneLib_BoxTouchesBrush(emin, emax, this, toucher);
800 void WarpZoneLib_MoveOutOfSolid_Expand(entity e, vector by)
802 const float eps = 0.0625;
803 tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
804 if (trace_startsolid)
806 if (trace_fraction < 1)
809 // adjust origin in the other direction...
810 setorigin(e, e.origin - by * (1 - trace_fraction));
814 bool WarpZoneLib_MoveOutOfSolid(entity e)
817 traceline(o, o, MOVE_WORLDONLY, e);
818 if (trace_startsolid)
821 tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
822 if (!trace_startsolid)
829 WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m0.x); e.mins_x = m0.x;
830 WarpZoneLib_MoveOutOfSolid_Expand(e, eX * m1.x); e.maxs_x = m1.x;
831 WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m0.y); e.mins_y = m0.y;
832 WarpZoneLib_MoveOutOfSolid_Expand(e, eY * m1.y); e.maxs_y = m1.y;
833 WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m0.z); e.mins_z = m0.z;
834 WarpZoneLib_MoveOutOfSolid_Expand(e, eZ * m1.z); e.maxs_z = m1.z;
835 setorigin(e, e.origin);
837 tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
838 if (trace_startsolid)