lib updates
authortzork <tzork@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Wed, 4 Nov 2009 13:27:14 +0000 (13:27 +0000)
committertzork <tzork@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Wed, 4 Nov 2009 13:27:14 +0000 (13:27 +0000)
git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8207 f962a42d-fe04-0410-a3ab-8c8b0445ebaa

data/qcsrc/server/steerlib.qc
data/qcsrc/server/verbstack.qc

index bf324a2..d512cf9 100644 (file)
@@ -11,11 +11,13 @@ vector steerlib_pull(vector point)
 /**
     Uniform push from a point
 **/
+#define steerlib_push(point) normalize(self.origin - point)
+/*
 vector steerlib_push(vector point)
 {
     return normalize(self.origin - point);
 }
-
+*/
 /**
     Pull toward a point, The further away, the stronger the pull.
 **/
@@ -156,6 +158,8 @@ vector steerlib_dodge(vector point,vector dodge_dir,float min_distance)
     float distance;
 
     distance = max(vlen(self.origin - point),min_distance);
+    if (min_distance < distance)
+        return '0 0 0';
 
     return dodge_dir * (min_distance/distance);
 }
@@ -186,6 +190,36 @@ vector steerlib_flock(float radius, float standoff,float separation_force,float
     return push + (pull* (1 / ccount));
 }
 
+/**
+    flocking by .flock_id
+    Group will move towards the unified direction while keeping close to eachother.
+    xy only version (for ground movers).
+**/
+vector steerlib_flock2d(float radius, float standoff,float separation_force,float flock_force)
+{
+    entity flock_member;
+    vector push,pull;
+    float ccount;
+
+    flock_member = findradius(self.origin,radius);
+    while(flock_member)
+    {
+        if(flock_member != self)
+        if(flock_member.flock_id == self.flock_id)
+        {
+            ++ccount;
+            push = push + (steerlib_repell(flock_member.origin, standoff) * separation_force);
+            pull = pull + (steerlib_arrive(flock_member.origin + flock_member.velocity, radius) * flock_force);
+        }
+        flock_member = flock_member.chain;
+    }
+
+    push_z = 0;
+    pull_z = 0;
+
+    return push + (pull * (1 / ccount));
+}
+
 /**
     All members want to be in the center, and keep away from eachother.
     The furtehr form the center the more they want to be there.
@@ -220,6 +254,7 @@ vector steerlib_swarm(float radius, float standoff,float separation_force,float
 /**
     Steer towards the direction least obstructed.
     Run four tracelines in a forward funnel, bias each diretion negative if something is found there.
+    You need to call makevectors() (or equivalent) before this function to set v_forward and v_right
 **/
 vector steerlib_traceavoid(float pitch,float length)
 {
@@ -228,6 +263,7 @@ vector steerlib_traceavoid(float pitch,float length)
     vector upwish,downwish,leftwish,rightwish;
     vector v_left,v_down;
 
+
     v_left = v_right * -1;
     v_down = v_up * -1;
 
@@ -254,7 +290,6 @@ vector steerlib_traceavoid(float pitch,float length)
     fdown_right = trace_fraction;
 
     //te_lightning1(world,self.origin, trace_endpos);
-
     upwish    = v_up    * (fup_left   + fup_right);
     downwish  = v_down  * (fdown_left + fdown_right);
     leftwish  = v_left  * (fup_left   + fdown_left);
@@ -266,7 +301,7 @@ vector steerlib_traceavoid(float pitch,float length)
 
 /**
     Steer towards the direction least obstructed.
-    Run two tracelines in a forward trident, bias each diretion negative if something is found there.
+    Run tracelines in a forward trident, bias each direction negative if something is found there.
 **/
 vector steerlib_traceavoid_flat(float pitch, float length, vector vofs)
 {
@@ -339,6 +374,7 @@ float beamsweep_badpoint(vector point,float waterok)
     return 1;
 }
 
+//#define BEAMSTEER_VISUAL
 float beamsweep(vector from, vector dir,float length, float step,float step_up, float step_down)
 {
     float i;
@@ -369,10 +405,10 @@ float beamsweep(vector from, vector dir,float length, float step,float step_up,
 
         if(beamsweep_badpoint(trace_endpos,0))
             return i / length;
-
-        //te_lightning1(world,a+u,b+u);
-        //te_lightning1(world,b+u,b-d);
-
+#ifdef BEAMSTEER_VISUAL
+        te_lightning1(world,a+u,b+u);
+        te_lightning1(world,b+u,b-d);
+#endif
         a = trace_endpos;
     }
 
@@ -386,7 +422,17 @@ vector steerlib_beamsteer(vector dir, float length, float step, float step_up, f
 
     dir_z *= 0.15;
     vr = vectoangles(dir);
-    vr_x *= -1;
+    //vr_x *= -1;
+
+    tracebox(self.origin , self.mins,self.maxs,self.origin +  (dir * length) ,MOVE_NOMONSTERS,self);
+    if(trace_fraction == 1.0)
+    {
+        //te_lightning1(self,self.origin,self.origin +  (dir * length));
+        return dir;
+    }
+
+
+
 
     makevectors(vr);
     bm_forward = beamsweep(self.origin, v_forward, length, step, step_up, step_down);
index b7c29d4..b0601af 100644 (file)
@@ -2,9 +2,12 @@
 .entity verbs_idle;
 .entity verbs_attack;
 .entity verbs_move;
+//.entity vchain;
 
 /// This global gets set to the verb in question each time the stack manager calls verb_call
 entity verb;
+//.entity current_verb;
+//.float verb_done;
 
 /// Execure this verb
 #define VCM_DO     0
@@ -31,6 +34,54 @@ entity verb;
 /// verb_call(VCM_DO) returns this when a verb should be deleted by the stack manager
 #define VS_CALL_REMOVE    -3
 
+/*
+void verbstack_updatechain(entity stack)
+{
+    entity vrb, v;
+    if not (stack)
+        return;
+
+    dprint("verbstack_updatechain\n");
+
+    vrb = findchainentity(verbstack, stack);
+    if not (vrb)
+    {
+        stack.vchain = world;
+        return;
+    }
+
+    stack.vchain = vrb;
+    v = vrb;
+
+    while(vrb)
+    {
+        vrb = vrb.chain;
+
+
+    }
+}
+
+void verbstack_remove(entity vverb)
+{
+    entity vstack;
+    dprint("verbstack_remove\n");
+
+    vstack = verb.verbstack;
+    remove(vverb);
+    vverb.verbstack = world;
+    verbstack_updatechain(vstack);
+
+    //vverb.think = SUB_Remove;
+    //vverb.nextthink = time;
+}
+
+void verbstack_thinkremove()
+{
+    dprint("verbstack_thinkremove\n");
+    verbstack_remove(self);
+}
+*/
+
 /**
     Push a new verb onto the specified stack. Set vrb_life to make it time-limited.
 **/
@@ -50,12 +101,18 @@ entity verbstack_push(entity stack, float(float eval) vrb_call, float val_static
     vrb.verb_call         = vrb_call;
     vrb.verb_static_value = val_static;
 
+    vrb.classname         = "verb";
+    stack.classname       = "verbstack";
+
     if(vrb_life)
     {
+        //vrb.think     = verbstack_thinkremove;
         vrb.think     = SUB_Remove;
         vrb.nextthink = time + vrb_life;
     }
 
+    //verbstack_updatechain(stack);
+
     return vrb;
 }
 
@@ -71,8 +128,11 @@ float verbstack_pop(entity stack)
     oldself = self;
 
     vrb = findchainentity(verbstack,stack);
+    //vrb = stack.vchain;
+    //dprint("owner:", stack.owner.classname, " vsn:", stack.classname,"\n");
     while(vrb)
     {
+        //dprint("vn:", vrb.classname,"\n");
         verb  = vrb;
         vrb   = vrb.chain;
         self  = verb.owner;
@@ -151,7 +211,7 @@ entity verbstack_pull(entity stack)
         vrb   = vrb.chain;
         value = verb.verb_call(VCM_EVAL);
 
-        if(value > 0)
+        if(value < 0)
         {
             if(value == VS_CALL_REMOVE)
                 remove(verb);
@@ -197,4 +257,18 @@ void verbstack_flush(entity stack)
     }
 
     self = oldself;
+
+    //stack.vchain = world;
+}
+
+void verbstack_doverb(entity vrb)
+{
+    float value;
+
+    verb  = vrb;
+    self  = verb.owner;
+    value = verb.verb_call(VCM_DO);
+
+    if(value == VS_CALL_REMOVE)
+        remove(vrb);
 }