1 void WarpZone_Accumulator_Clear(entity acc)
3 acc.warpzone_transform = '0 0 0';
4 acc.warpzone_shift = '0 0 0';
6 void WarpZone_Accumulator_AddTransform(entity acc, vector t, vector s)
9 tr = AnglesTransform_Multiply(t, acc.warpzone_transform);
10 st = AnglesTransform_Multiply_GetPostShift(t, s, acc.warpzone_transform, acc.warpzone_shift);
11 acc.warpzone_transform = tr;
12 acc.warpzone_shift = st;
14 void WarpZone_Accumulator_Add(entity acc, entity wz)
17 t = AnglesTransform_Multiply(wz.warpzone_transform, acc.warpzone_transform);
18 st = AnglesTransform_Multiply_GetPostShift(wz.warpzone_transform, wz.warpzone_shift, acc.warpzone_transform, acc.warpzone_shift);
19 acc.warpzone_transform = t;
20 acc.warpzone_shift = st;
23 .vector(vector, vector) camera_transform;
24 var float autocvar_cl_warpzone_usetrace = 1;
25 vector WarpZone_camera_transform(vector org, vector ang)
31 org = WarpZone_TransformOrigin(self, org);
32 vf = WarpZone_TransformVelocity(self, vf);
33 vr = WarpZone_TransformVelocity(self, vr);
34 vu = WarpZone_TransformVelocity(self, vu);
35 if(autocvar_cl_warpzone_usetrace)
36 traceline(self.warpzone_targetorigin, org, MOVE_NOMONSTERS, world);
38 trace_endpos = self.warpzone_targetorigin;
45 void WarpZone_SetUp(entity e, vector my_org, vector my_ang, vector other_org, vector other_ang)
47 e.warpzone_transform = AnglesTransform_Divide(other_ang, AnglesTransform_TurnDirectionFR(my_ang));
48 e.warpzone_shift = AnglesTransform_PrePostShift_GetPostShift(my_org, e.warpzone_transform, other_org);
49 e.warpzone_origin = my_org;
50 e.warpzone_targetorigin = other_org;
51 e.warpzone_angles = my_ang;
52 e.warpzone_targetangles = other_ang;
53 fixedmakevectors(my_ang); e.warpzone_forward = v_forward;
54 fixedmakevectors(other_ang); e.warpzone_targetforward = v_forward;
55 e.camera_transform = WarpZone_camera_transform;
60 vector WarpZoneLib_BoxTouchesBrush_mins;
61 vector WarpZoneLib_BoxTouchesBrush_maxs;
62 entity WarpZoneLib_BoxTouchesBrush_ent;
63 entity WarpZoneLib_BoxTouchesBrush_ignore;
64 float WarpZoneLib_BoxTouchesBrush_Recurse()
70 tracebox('0 0 0', WarpZoneLib_BoxTouchesBrush_mins, WarpZoneLib_BoxTouchesBrush_maxs, '0 0 0', MOVE_NOMONSTERS, WarpZoneLib_BoxTouchesBrush_ignore);
72 if (trace_networkentity)
74 dprint("hit a network ent, cannot continue WarpZoneLib_BoxTouchesBrush\n");
75 // we cannot continue, as a player blocks us...
82 if (trace_ent == WarpZoneLib_BoxTouchesBrush_ent)
88 f = WarpZoneLib_BoxTouchesBrush_Recurse();
94 float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig)
103 WarpZoneLib_BoxTouchesBrush_mins = mi;
104 WarpZoneLib_BoxTouchesBrush_maxs = ma;
105 WarpZoneLib_BoxTouchesBrush_ent = e;
106 WarpZoneLib_BoxTouchesBrush_ignore = ig;
107 f = WarpZoneLib_BoxTouchesBrush_Recurse();
113 entity WarpZone_Find(vector mi, vector ma)
115 // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
117 for(e = world; (e = find(e, classname, "trigger_warpzone")); )
118 if(WarpZoneLib_BoxTouchesBrush(mi, ma, e, world))
123 void WarpZone_MakeAllSolid()
126 for(e = world; (e = find(e, classname, "trigger_warpzone")); )
130 void WarpZone_MakeAllOther()
133 for(e = world; (e = find(e, classname, "trigger_warpzone")); )
134 e.solid = SOLID_TRIGGER;
137 void WarpZone_Trace_InitTransform()
139 if(!WarpZone_trace_transform)
141 WarpZone_trace_transform = spawn();
142 WarpZone_trace_transform.classname = "warpzone_trace_transform";
144 WarpZone_Accumulator_Clear(WarpZone_trace_transform);
146 void WarpZone_Trace_AddTransform(entity wz)
148 WarpZone_Accumulator_Add(WarpZone_trace_transform, wz);
151 void WarpZone_TraceBox_ThroughZone(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent, entity zone, WarpZone_trace_callback_t cb)
162 WarpZone_Trace_InitTransform();
163 // if starting in warpzone, first transform
164 wz = WarpZone_Find(org + mi, org + ma);
167 if(zone && wz != zone)
169 // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return.
175 WarpZone_Trace_AddTransform(wz);
176 org = WarpZone_TransformOrigin(wz, trace_endpos);
177 end = WarpZone_TransformOrigin(wz, end);
179 WarpZone_MakeAllSolid();
187 dprint("Too many warpzones in sequence, aborting trace.\n");
190 tracebox(org, mi, ma, end, nomonsters, forent);
192 cb(org, trace_endpos, end);
194 sol = trace_startsolid;
196 frac = trace_fraction = frac + (1 - frac) * trace_fraction;
197 if(trace_fraction >= 1)
199 if(trace_ent.classname != "trigger_warpzone")
203 dprint("I transformed into the same zone again, wtf, aborting the trace\n");
207 if(zone && wz != zone)
209 WarpZone_Trace_AddTransform(wz);
210 // we hit a warpzone... so, let's perform the trace after the warp again
211 org = WarpZone_TransformOrigin(wz, trace_endpos);
212 end = WarpZone_TransformOrigin(wz, end);
214 WarpZone_MakeAllOther();
216 trace_startsolid = sol;
222 void WarpZone_TraceBox(vector org, vector mi, vector ma, vector end, float nomonsters, entity forent)
224 WarpZone_TraceBox_ThroughZone(org, mi, ma, end, nomonsters, forent, world, WarpZone_trace_callback_t_null);
227 void WarpZone_TraceLine(vector org, vector end, float nomonsters, entity forent)
229 WarpZone_TraceBox(org, '0 0 0', '0 0 0', end, nomonsters, forent);
232 void WarpZone_TraceToss_ThroughZone(entity e, entity forent, entity zone, WarpZone_trace_callback_t cb)
235 vector vf, vr, vu, v0, o0;
243 WarpZone_Trace_InitTransform();
244 // if starting in warpzone, first transform
245 wz = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs);
248 if(zone && wz != zone)
250 // we are in ANOTHER warpzone. This is bad. Make a zero length trace and return.
252 WarpZone_tracetoss_time = 0;
256 WarpZone_Trace_AddTransform(wz);
257 setorigin(e, WarpZone_TransformOrigin(wz, e.origin));
258 e.velocity = WarpZone_TransformVelocity(wz, e.velocity);
260 WarpZone_MakeAllSolid();
261 g = cvar("sv_gravity") * e.gravity;
262 WarpZone_tracetoss_time = 0;
268 dprint("Too many warpzones in sequence, aborting trace.\n");
271 tracetoss(e, forent);
273 cb(e.origin, trace_endpos, trace_endpos);
274 e.origin = trace_endpos;
275 e.velocity_z -= WarpZone_tracetoss_time * g;
276 dt = vlen(e.origin - o0) / vlen(e.velocity);
277 WarpZone_tracetoss_time += dt;
278 if(trace_fraction >= 1)
280 if(trace_ent.classname != "trigger_warpzone")
284 dprint("I transformed into the same zone again, wtf, aborting the trace\n");
288 if(zone && wz != zone)
290 WarpZone_Trace_AddTransform(wz);
291 // we hit a warpzone... so, let's perform the trace after the warp again
292 e.origin = WarpZone_TransformOrigin(wz, e.origin);
293 e.velocity = WarpZone_TransformVelocity(wz, e.velocity);
295 WarpZone_MakeAllOther();
297 WarpZone_tracetoss_velocity = e.velocity;
301 // restore old entity data (caller just uses trace_endpos, WarpZone_tracetoss_velocity and the transform)
306 void WarpZone_TraceToss(entity e, entity forent)
308 WarpZone_TraceToss_ThroughZone(e, forent, world, WarpZone_trace_callback_t_null);
311 entity WarpZone_TrailParticles_trace_callback_own;
312 float WarpZone_TrailParticles_trace_callback_eff;
313 void WarpZone_TrailParticles_trace_callback(vector from, vector endpos, vector to)
315 trailparticles(WarpZone_TrailParticles_trace_callback_own, WarpZone_TrailParticles_trace_callback_eff, from, endpos);
318 void WarpZone_TrailParticles(entity own, float eff, vector org, vector end)
320 WarpZone_TrailParticles_trace_callback_own = own;
321 WarpZone_TrailParticles_trace_callback_eff = eff;
322 WarpZone_TraceBox_ThroughZone(org, '0 0 0', '0 0 0', end, MOVE_NOMONSTERS, world, world, WarpZone_TrailParticles_trace_callback);
325 float WarpZone_PlaneDist(entity wz, vector v)
327 return (v - wz.warpzone_origin) * wz.warpzone_forward;
330 float WarpZone_TargetPlaneDist(entity wz, vector v)
332 return (v - wz.warpzone_targetorigin) * wz.warpzone_targetforward;
335 vector WarpZone_TransformOrigin(entity wz, vector v)
337 return wz.warpzone_shift + AnglesTransform_Apply(wz.warpzone_transform, v);
340 vector WarpZone_TransformVelocity(entity wz, vector v)
342 return AnglesTransform_Apply(wz.warpzone_transform, v);
345 vector WarpZone_TransformAngles(entity wz, vector v)
347 return AnglesTransform_ApplyToAngles(wz.warpzone_transform, v);
350 vector WarpZone_TransformVAngles(entity wz, vector ang)
358 ang = AnglesTransform_ApplyToVAngles(wz.warpzone_transform, ang);
361 ang = AnglesTransform_Normalize(ang, TRUE);
362 ang = AnglesTransform_CancelRoll(ang);
365 ang = AnglesTransform_Normalize(ang, FALSE);
371 vector WarpZone_UnTransformOrigin(entity wz, vector v)
373 return AnglesTransform_Apply(AnglesTransform_Invert(wz.warpzone_transform), v - wz.warpzone_shift);
376 vector WarpZone_UnTransformVelocity(entity wz, vector v)
378 return AnglesTransform_Apply(AnglesTransform_Invert(wz.warpzone_transform), v);
381 vector WarpZone_UnTransformAngles(entity wz, vector v)
383 return AnglesTransform_ApplyToAngles(AnglesTransform_Invert(wz.warpzone_transform), v);
386 vector WarpZone_UnTransformVAngles(entity wz, vector ang)
393 ang = AnglesTransform_ApplyToVAngles(AnglesTransform_Invert(wz.warpzone_transform), ang);
394 ang = AnglesTransform_Normalize(ang, TRUE);
395 ang = AnglesTransform_CancelRoll(ang);
401 vector WarpZoneLib_NearestPointOnBox(vector mi, vector ma, vector org)
404 nearest_x = bound(mi_x, org_x, ma_x);
405 nearest_y = bound(mi_y, org_y, ma_y);
406 nearest_z = bound(mi_z, org_z, ma_z);
410 .float WarpZone_findradius_hit;
411 .entity WarpZone_findradius_next;
412 void WarpZone_FindRadius_Recurse(vector org, float rad, vector org0, vector transform, vector shift, float needlineofsight)
413 // blast origin of current search original blast origin how to untransform (victim to blast system)
417 vector shift_new, transform_new;
423 e0 = findradius(org, rad);
426 for(e = e0; e; e = e.chain)
428 p = WarpZoneLib_NearestPointOnBox(e.origin + e.mins, e.origin + e.maxs, org0);
431 traceline(org, p, MOVE_NOMONSTERS, e);
432 if(trace_fraction < 1)
435 if(!e.WarpZone_findradius_hit || vlen(e.WarpZone_findradius_dist) > vlen(org0 - p))
437 e.WarpZone_findradius_nearest = p;
438 e.WarpZone_findradius_dist = org0 - p;
439 e.WarpZone_findradius_findorigin = org;
440 e.WarpZone_findradius_findradius = rad;
441 if(e.classname == "warpzone_refsys")
443 // ignore, especially: do not overwrite the refsys parameters
445 else if(e.classname == "trigger_warpzone")
447 e.WarpZone_findradius_next = wz;
449 e.WarpZone_findradius_hit = 1;
450 e.enemy.WarpZone_findradius_dist = '0 0 0'; // we don't want to go through this zone ever again
451 e.enemy.WarpZone_findradius_hit = 1;
455 e.warpzone_transform = transform;
456 e.warpzone_shift = shift;
457 e.WarpZone_findradius_hit = 1;
461 for(e = wz; e; e = e.WarpZone_findradius_next)
463 org0_new = WarpZone_TransformOrigin(e, org);
464 traceline(e.warpzone_targetorigin, org0_new, MOVE_NOMONSTERS, e);
465 org_new = trace_endpos;
467 transform_new = AnglesTransform_Multiply(e.warpzone_transform, transform);
468 shift_new = AnglesTransform_Multiply_GetPostShift(e.warpzone_transform, e.warpzone_shift, transform, shift);
469 WarpZone_FindRadius_Recurse(
471 bound(0, rad - vlen(org_new - org0_new), rad - 8),
473 transform_new, shift_new,
475 e.WarpZone_findradius_hit = 0;
476 e.enemy.WarpZone_findradius_hit = 0;
479 entity WarpZone_FindRadius(vector org, float rad, float needlineofsight)
482 WarpZone_FindRadius_Recurse(org, rad, org, '0 0 0', '0 0 0', needlineofsight);
483 e0 = findchainfloat(WarpZone_findradius_hit, 1);
484 for(e = e0; e; e = e.chain)
485 e.WarpZone_findradius_hit = 0;
489 .entity WarpZone_refsys;
490 void WarpZone_RefSys_GC()
492 // garbage collect unused reference systems
493 self.nextthink = time + 1;
494 if(self.owner.WarpZone_refsys != self)
497 void WarpZone_RefSys_Add(entity me, entity wz)
499 if(me.WarpZone_refsys.owner != me)
501 me.WarpZone_refsys = spawn();
502 me.WarpZone_refsys.classname = "warpzone_refsys";
503 me.WarpZone_refsys.owner = me;
504 me.WarpZone_refsys.think = WarpZone_RefSys_GC;
505 me.WarpZone_refsys.nextthink = time + 1;
506 WarpZone_Accumulator_Clear(me.WarpZone_refsys);
509 WarpZone_Accumulator_Add(me.WarpZone_refsys, wz);
511 .vector WarpZone_refsys_incremental_shift;
512 .vector WarpZone_refsys_incremental_transform;
513 void WarpZone_RefSys_AddIncrementally(entity me, entity ref)
516 if(me.WarpZone_refsys_incremental_transform == ref.WarpZone_refsys.warpzone_transform)
517 if(me.WarpZone_refsys_incremental_shift == ref.WarpZone_refsys.warpzone_shift)
519 if(me.WarpZone_refsys.owner != me)
521 me.WarpZone_refsys = spawn();
522 me.WarpZone_refsys.classname = "warpzone_refsys";
523 me.WarpZone_refsys.owner = me;
524 me.WarpZone_refsys.think = WarpZone_RefSys_GC;
525 me.WarpZone_refsys.nextthink = time + 1;
526 WarpZone_Accumulator_Clear(me.WarpZone_refsys);
528 t = AnglesTransform_Invert(me.WarpZone_refsys_incremental_transform);
529 s = AnglesTransform_PrePostShift_GetPostShift(me.WarpZone_refsys_incremental_shift, t, '0 0 0');
530 WarpZone_Accumulator_AddTransform(me.WarpZone_refsys, t, s);
531 WarpZone_Accumulator_Add(me.WarpZone_refsys, ref);
532 me.WarpZone_refsys_incremental_shift = ref.WarpZone_refsys.warpzone_shift;
533 me.WarpZone_refsys_incremental_transform = ref.WarpZone_refsys.warpzone_transform;
535 void WarpZone_RefSys_BeginAddingIncrementally(entity me, entity ref)
537 me.WarpZone_refsys_incremental_shift = ref.WarpZone_refsys.warpzone_shift;
538 me.WarpZone_refsys_incremental_transform = ref.WarpZone_refsys.warpzone_transform;
540 vector WarpZone_RefSys_TransformOrigin(entity from, entity to, vector org)
542 if(from.WarpZone_refsys)
543 org = WarpZone_UnTransformOrigin(from.WarpZone_refsys, org);
544 if(to.WarpZone_refsys)
545 org = WarpZone_TransformOrigin(to.WarpZone_refsys, org);
548 vector WarpZone_RefSys_TransformVelocity(entity from, entity to, vector vel)
550 if(from.WarpZone_refsys)
551 vel = WarpZone_UnTransformVelocity(from.WarpZone_refsys, vel);
552 if(to.WarpZone_refsys)
553 vel = WarpZone_TransformVelocity(to.WarpZone_refsys, vel);
556 vector WarpZone_RefSys_TransformAngles(entity from, entity to, vector ang)
558 if(from.WarpZone_refsys)
559 ang = WarpZone_UnTransformAngles(from.WarpZone_refsys, ang);
560 if(to.WarpZone_refsys)
561 ang = WarpZone_TransformAngles(to.WarpZone_refsys, ang);
564 vector WarpZone_RefSys_TransformVAngles(entity from, entity to, vector ang)
566 if(from.WarpZone_refsys)
567 ang = WarpZone_UnTransformVAngles(from.WarpZone_refsys, ang);
568 if(to.WarpZone_refsys)
569 ang = WarpZone_TransformVAngles(to.WarpZone_refsys, ang);
572 entity WarpZone_RefSys_SpawnSameRefSys(entity me)
576 if(me.WarpZone_refsys)
578 e.WarpZone_refsys = spawn();
579 e.WarpZone_refsys.classname = "warpzone_refsys";
580 e.WarpZone_refsys.owner = e;
581 e.WarpZone_refsys.think = WarpZone_RefSys_GC;
582 e.WarpZone_refsys.nextthink = time + 1;
583 e.WarpZone_refsys.warpzone_shift = me.WarpZone_refsys.warpzone_shift;
584 e.WarpZone_refsys.warpzone_transform = me.WarpZone_refsys.warpzone_transform;