X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fsteerlib.qc;h=92c918f00ca2281d360282312cfc3b3b9e1fc5df;hp=2cccbf41c06ab428e75150b64408e15687c708da;hb=76dd66af43f0f01131d019c3a8dacfe35a6f6a18;hpb=eac60648c4017e495060dd3ba9e50ac4bad5000a diff --git a/qcsrc/server/steerlib.qc b/qcsrc/server/steerlib.qc index 2cccbf41c..92c918f00 100644 --- a/qcsrc/server/steerlib.qc +++ b/qcsrc/server/steerlib.qc @@ -2,15 +2,17 @@ #if defined(CSQC) #elif defined(MENUQC) #elif defined(SVQC) + #include "pathlib/utility.qh" #endif /** Uniform pull towards a point **/ -vector steerlib_pull(entity this, vector point) +#define steerlib_pull(ent,point) normalize(point - (ent).origin) +/*vector steerlib_pull(entity this, vector point) { return normalize(point - this.origin); -} +}*/ /** Uniform push from a point @@ -27,11 +29,8 @@ vector steerlib_push(entity this, vector point) **/ vector steerlib_arrive(entity this, vector point, float maximal_distance) { - float distance; - vector direction; - - distance = bound(0.001,vlen(this.origin - point),maximal_distance); - direction = normalize(point - this.origin); + float distance = bound(0.001,vlen(this.origin - point),maximal_distance); + vector direction = normalize(point - this.origin); return direction * (distance / maximal_distance); } @@ -40,25 +39,18 @@ vector steerlib_arrive(entity this, vector point, float maximal_distance) **/ vector steerlib_attract(entity this, vector point, float maximal_distance) { - float distance; - vector direction; - - distance = bound(0.001,vlen(this.origin - point),maximal_distance); - direction = normalize(point - this.origin); + float distance = bound(0.001,vlen(this.origin - point),maximal_distance); + vector direction = normalize(point - this.origin); return direction * (1-(distance / maximal_distance)); } vector steerlib_attract2(entity this, vector point, float min_influense,float max_distance,float max_influense) { - float distance; - vector direction; - float influense; - - distance = bound(0.00001,vlen(this.origin - point),max_distance); - direction = normalize(point - this.origin); + float distance = bound(0.00001,vlen(this.origin - point),max_distance); + vector direction = normalize(point - this.origin); - influense = 1 - (distance / max_distance); + float influense = 1 - (distance / max_distance); influense = min_influense + (influense * (max_influense - min_influense)); return direction * influense; @@ -143,7 +135,7 @@ vector steerlib_wander(entity this, float range, float tresh, vector oldpoint) vector wander_point; wander_point = v_forward - oldpoint; - if (vlen(wander_point) > tresh) + if (vdist(wander_point, >, tresh)) return oldpoint; range = bound(0,range,1); @@ -275,25 +267,25 @@ vector steerlib_traceavoid(entity this, float pitch,float length) traceline(this.origin, this.origin + vup_left,MOVE_NOMONSTERS,this); fup_left = trace_fraction; - //te_lightning1(world,this.origin, trace_endpos); + //te_lightning1(NULL,this.origin, trace_endpos); vup_right = (v_forward + (v_right * pitch + v_up * pitch)) * length; traceline(this.origin,this.origin + vup_right ,MOVE_NOMONSTERS,this); fup_right = trace_fraction; - //te_lightning1(world,this.origin, trace_endpos); + //te_lightning1(NULL,this.origin, trace_endpos); vdown_left = (v_forward + (v_left * pitch + v_down * pitch)) * length; traceline(this.origin,this.origin + vdown_left,MOVE_NOMONSTERS,this); fdown_left = trace_fraction; - //te_lightning1(world,this.origin, trace_endpos); + //te_lightning1(NULL,this.origin, trace_endpos); vdown_right = (v_forward + (v_right * pitch + v_down * pitch)) * length; traceline(this.origin,this.origin + vdown_right,MOVE_NOMONSTERS,this); fdown_right = trace_fraction; - //te_lightning1(world,this.origin, trace_endpos); + //te_lightning1(NULL,this.origin, trace_endpos); upwish = v_up * (fup_left + fup_right); downwish = v_down * (fdown_left + fdown_right); leftwish = v_left * (fup_left + fdown_left); @@ -324,13 +316,13 @@ vector steerlib_traceavoid_flat(entity this, float pitch, float length, vector v traceline(this.origin + vofs, this.origin + vofs + vt_left,MOVE_NOMONSTERS,this); f_left = trace_fraction; - //te_lightning1(world,this.origin, trace_endpos); + //te_lightning1(NULL,this.origin, trace_endpos); vt_right = (v_forward + (v_right * pitch)) * length; traceline(this.origin + vofs, this.origin + vofs + vt_right ,MOVE_NOMONSTERS,this); f_right = trace_fraction; - //te_lightning1(world,this.origin, trace_endpos); + //te_lightning1(NULL,this.origin, trace_endpos); leftwish = v_left * f_left; rightwish = v_right * f_right; @@ -339,50 +331,11 @@ vector steerlib_traceavoid_flat(entity this, float pitch, float length, vector v return normalize(leftwish + rightwish + frontwish); } -float beamsweep_badpoint(vector point,float waterok) -{ - float pc,pc2; - - if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) - return 1; - - pc = pointcontents(point); - pc2 = pointcontents(point - '0 0 1'); - - switch(pc) - { - case CONTENT_SOLID: break; - case CONTENT_SLIME: break; - case CONTENT_LAVA: break; - - case CONTENT_SKY: - return 1; - - case CONTENT_EMPTY: - if (pc2 == CONTENT_SOLID) - return 0; - - if (pc2 == CONTENT_WATER) - if(waterok) - return 0; - - break; - - case CONTENT_WATER: - if(waterok) - return 0; - - break; - } - - return 1; -} - //#define BEAMSTEER_VISUAL float beamsweep(entity this, vector from, vector dir,float length, float step,float step_up, float step_down) { float i; - vector a,b,u,d; + vector a, b, u, d; u = '0 0 1' * step_up; d = '0 0 1' * step_down; @@ -391,7 +344,7 @@ float beamsweep(entity this, vector from, vector dir,float length, float step,fl if(trace_fraction == 1.0) return 0; - if(beamsweep_badpoint(trace_endpos,0)) + if(!location_isok(trace_endpos, false, false)) return 0; a = trace_endpos; @@ -407,11 +360,11 @@ float beamsweep(entity this, vector from, vector dir,float length, float step,fl if(trace_fraction == 1.0) return i / length; - if(beamsweep_badpoint(trace_endpos,0)) + if(!location_isok(trace_endpos, false, false)) return i / length; #ifdef BEAMSTEER_VISUAL - te_lightning1(world,a+u,b+u); - te_lightning1(world,b+u,b-d); + te_lightning1(NULL,a+u,b+u); + te_lightning1(NULL,b+u,b-d); #endif a = trace_endpos; } @@ -464,8 +417,8 @@ vector steerlib_beamsteer(entity this, vector dir, float length, float step, flo if(bm_left + bm_right < 0.15) { - vr = normalize((v_forward*-1) + v_right * 0.75); - vl = normalize((v_forward*-1) - v_right * 0.75); + vr = normalize((v_forward*-1) + v_right * 0.90); + vl = normalize((v_forward*-1) - v_right * 0.90); bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); @@ -484,179 +437,3 @@ vector steerlib_beamsteer(entity this, vector dir, float length, float step, flo return normalize(vr + vl); } - - -////////////////////////////////////////////// -// Testting // -// Everything below this point is a mess :D // -////////////////////////////////////////////// -//#define TLIBS_TETSLIBS -#ifdef TLIBS_TETSLIBS -void flocker_die(entity this) -{ - Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1); - - this.owner.cnt += 1; - this.owner = world; - - this.nextthink = time; - setthink(this, SUB_Remove); -} - - -void flocker_think(entity this) -{ - vector dodgemove,swarmmove; - vector reprellmove,wandermove,newmove; - - this.angles_x = this.angles.x * -1; - makevectors(this.angles); - this.angles_x = this.angles.x * -1; - - dodgemove = steerlib_traceavoid(this, 0.35,1000); - swarmmove = steerlib_flock(this, 500,75,700,500); - reprellmove = steerlib_repell(this, this.owner.enemy.origin+this.enemy.velocity,2000) * 700; - - if(dodgemove == '0 0 0') - { - this.pos1 = steerlib_wander(this, 0.5,0.1,this.pos1); - wandermove = this.pos1 * 50; - } - else - this.pos1 = normalize(this.velocity); - - dodgemove = dodgemove * vlen(this.velocity) * 5; - - newmove = swarmmove + reprellmove + wandermove + dodgemove; - this.velocity = movelib_inertmove_byspeed(this, newmove,300,0.2,0.9); - //this.velocity = movelib_inertmove(this, dodgemove,0.65); - - this.velocity = movelib_dragvec(this, 0.01,0.6); - - this.angles = vectoangles(this.velocity); - - if(this.health <= 0) - flocker_die(this); - else - this.nextthink = time + 0.1; -} - -MODEL(FLOCKER, "models/turrets/rocket.md3"); - -void spawn_flocker(entity this) -{ - entity flocker = new(flocker); - - setorigin(flocker, this.origin + '0 0 32'); - setmodel (flocker, MDL_FLOCKER); - setsize (flocker, '-3 -3 -3', '3 3 3'); - - flocker.flock_id = this.flock_id; - flocker.owner = this; - setthink(flocker, flocker_think); - flocker.nextthink = time + random() * 5; - PROJECTILE_MAKETRIGGER(flocker); - flocker.movetype = MOVETYPE_BOUNCEMISSILE; - flocker.effects = EF_LOWPRECISION; - flocker.velocity = randomvec() * 300; - flocker.angles = vectoangles(flocker.velocity); - flocker.health = 10; - flocker.pos1 = normalize(flocker.velocity + randomvec() * 0.1); - - this.cnt = this.cnt -1; - -} - -void flockerspawn_think(entity this) -{ - if(this.cnt > 0) - spawn_flocker(this); - - this.nextthink = time + this.delay; - -} - -void flocker_hunter_think(entity this) -{ - vector dodgemove,attractmove,newmove; - entity e,ee; - float d,bd; - - this.angles_x = this.angles.x * -1; - makevectors(this.angles); - this.angles_x = this.angles.x * -1; - - if(this.enemy) - if(vdist(this.enemy.origin - this.origin, <, 64)) - { - ee = this.enemy; - ee.health = -1; - this.enemy = world; - - } - - if(!this.enemy) - { - e = findchainfloat(flock_id,this.flock_id); - while(e) - { - d = vlen(this.origin - e.origin); - - if(e != this.owner) - if(e != ee) - if(d > bd) - { - this.enemy = e; - bd = d; - } - e = e.chain; - } - } - - if(this.enemy) - attractmove = steerlib_attract(this, this.enemy.origin+this.enemy.velocity * 0.1,5000) * 1250; - else - attractmove = normalize(this.velocity) * 200; - - dodgemove = steerlib_traceavoid(this, 0.35,1500) * vlen(this.velocity); - - newmove = dodgemove + attractmove; - this.velocity = movelib_inertmove_byspeed(this, newmove,1250,0.3,0.7); - this.velocity = movelib_dragvec(this, 0.01,0.5); - - - this.angles = vectoangles(this.velocity); - this.nextthink = time + 0.1; -} - - -float globflockcnt; -spawnfunc(flockerspawn) -{ - ++globflockcnt; - - if(!this.cnt) this.cnt = 20; - if(!this.delay) this.delay = 0.25; - if(!this.flock_id) this.flock_id = globflockcnt; - - setthink(this, flockerspawn_think); - this.nextthink = time + 0.25; - - this.enemy = new(FLock Hunter); - - setmodel(this.enemy, MDL_FLOCKER); - setorigin(this.enemy,this.origin + '0 0 768' + (randomvec() * 128)); - - this.enemy.scale = 3; - this.enemy.effects = EF_LOWPRECISION; - this.enemy.movetype = MOVETYPE_BOUNCEMISSILE; - PROJECTILE_MAKETRIGGER(this.enemy); - setthink(this.enemy, flocker_hunter_think); - this.enemy.nextthink = time + 10; - this.enemy.flock_id = this.flock_id; - this.enemy.owner = this; -} -#endif - - -