From f5d3db75faaa76b2df7f85014b6914d4f2753f20 Mon Sep 17 00:00:00 2001 From: Freddy Date: Fri, 9 Mar 2018 23:19:45 +0100 Subject: [PATCH] func_vectormamamam: remove magic numbers and better variable names --- qcsrc/common/triggers/func/vectormamamam.qc | 29 +++++++++------------ qcsrc/common/triggers/func/vectormamamam.qh | 4 +++ qcsrc/common/triggers/spawnflags.qh | 6 +++++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/qcsrc/common/triggers/func/vectormamamam.qc b/qcsrc/common/triggers/func/vectormamamam.qc index 951a740a2..8812930b2 100644 --- a/qcsrc/common/triggers/func/vectormamamam.qc +++ b/qcsrc/common/triggers/func/vectormamamam.qc @@ -6,20 +6,20 @@ .float targetfactor, target2factor, target3factor, target4factor; .vector targetnormal, target2normal, target3normal, target4normal; -vector func_vectormamamam_origin(entity o, float t) +vector func_vectormamamam_origin(entity o, float timestep) { vector v, p; - float f; + float flags; entity e; - f = o.spawnflags; + flags = o.spawnflags; v = '0 0 0'; e = o.wp00; if(e) { - p = e.origin + t * e.velocity; - if(f & 1) + p = e.origin + timestep * e.velocity; + if(flags & PROJECT_ON_TARGETNORMAL) v = v + (p * o.targetnormal) * o.targetnormal * o.targetfactor; else v = v + (p - (p * o.targetnormal) * o.targetnormal) * o.targetfactor; @@ -28,8 +28,8 @@ vector func_vectormamamam_origin(entity o, float t) e = o.wp01; if(e) { - p = e.origin + t * e.velocity; - if(f & 2) + p = e.origin + timestep * e.velocity; + if(flags & PROJECT_ON_TARGET2NORMAL) v = v + (p * o.target2normal) * o.target2normal * o.target2factor; else v = v + (p - (p * o.target2normal) * o.target2normal) * o.target2factor; @@ -38,8 +38,8 @@ vector func_vectormamamam_origin(entity o, float t) e = o.wp02; if(e) { - p = e.origin + t * e.velocity; - if(f & 4) + p = e.origin + timestep * e.velocity; + if(flags & PROJECT_ON_TARGET3NORMAL) v = v + (p * o.target3normal) * o.target3normal * o.target3factor; else v = v + (p - (p * o.target3normal) * o.target3normal) * o.target3factor; @@ -48,8 +48,8 @@ vector func_vectormamamam_origin(entity o, float t) e = o.wp03; if(e) { - p = e.origin + t * e.velocity; - if(f & 8) + p = e.origin + timestep * e.velocity; + if(flags & PROJECT_ON_TARGET4NORMAL) v = v + (p * o.target4normal) * o.target4normal * o.target4factor; else v = v + (p - (p * o.target4normal) * o.target4normal) * o.target4factor; @@ -60,7 +60,7 @@ vector func_vectormamamam_origin(entity o, float t) void func_vectormamamam_controller_think(entity this) { - this.nextthink = time + 0.1; + this.nextthink = time + vectormamamam_timestep; if(this.owner.active != ACTIVE_ACTIVE) { @@ -69,7 +69,7 @@ void func_vectormamamam_controller_think(entity this) } if(this.owner.classname == "func_vectormamamam") // don't brake stuff if the func_vectormamamam was killtarget'ed - this.owner.velocity = (this.owner.destvec + func_vectormamamam_origin(this.owner, 0.1) - this.owner.origin) * 10; + this.owner.velocity = (this.owner.destvec + func_vectormamamam_origin(this.owner, vectormamamam_timestep) - this.owner.origin) * 10; } void func_vectormamamam_findtarget(entity this) @@ -139,9 +139,6 @@ spawnfunc(func_vectormamamam) this.dmgtime = 0.25; this.dmgtime2 = time; - if(this.netname == "") - this.netname = "1 0 0 0 1"; - if (!InitMovingBrushTrigger(this)) return; diff --git a/qcsrc/common/triggers/func/vectormamamam.qh b/qcsrc/common/triggers/func/vectormamamam.qh index 6f70f09be..4f40f6292 100644 --- a/qcsrc/common/triggers/func/vectormamamam.qh +++ b/qcsrc/common/triggers/func/vectormamamam.qh @@ -1 +1,5 @@ #pragma once +#include "../spawnflags.qh" + + +const float vectormamamam_timestep = 0.1; diff --git a/qcsrc/common/triggers/spawnflags.qh b/qcsrc/common/triggers/spawnflags.qh index fb34b3f16..7eac49917 100644 --- a/qcsrc/common/triggers/spawnflags.qh +++ b/qcsrc/common/triggers/spawnflags.qh @@ -61,6 +61,12 @@ const int VIEWLOC_NOSIDESCROLL = BIT(0); // NOTE: currently unimplemented const int VIEWLOC_FREEAIM = BIT(1); const int VIEWLOC_FREEMOVE = BIT(2); +// vectormamamam +const int PROJECT_ON_TARGETNORMAL = BIT(0); +const int PROJECT_ON_TARGET2NORMAL = BIT(1); +const int PROJECT_ON_TARGET3NORMAL = BIT(2); +const int PROJECT_ON_TARGET4NORMAL = BIT(3); + // platforms const int PLAT_LOW_TRIGGER = BIT(0); const int PLAT_CRUSH = BIT(2); -- 2.39.2