From: Mario Date: Sun, 11 Aug 2019 08:57:36 +0000 (+1000) Subject: Clean up steerlib a bit X-Git-Tag: xonotic-v0.8.5~1409 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=bbf6e24301b0a18003230d078328afc8dcb7f9d2 Clean up steerlib a bit --- diff --git a/qcsrc/common/gamemodes/gamemode/assault/sv_assault.qc b/qcsrc/common/gamemodes/gamemode/assault/sv_assault.qc index 835073d07d..9a9a654de9 100644 --- a/qcsrc/common/gamemodes/gamemode/assault/sv_assault.qc +++ b/qcsrc/common/gamemodes/gamemode/assault/sv_assault.qc @@ -1,5 +1,7 @@ #include "sv_assault.qh" +#include + .entity sprite; #define AS_ROUND_DELAY 5 @@ -347,7 +349,6 @@ bool destructible_heal(entity targ, entity inflictor, float amount, float limit) return true; } -spawnfunc(func_breakable); spawnfunc(func_assault_destructible) { if (!g_assault) { delete(this); return; } diff --git a/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc b/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc index 5ff31c7bea..21d9208bf9 100644 --- a/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc +++ b/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc @@ -23,6 +23,7 @@ float autocvar_g_balance_keyhunt_throwvelocity; int autocvar_g_keyhunt_teams_override; // #define KH_PLAYER_USE_ATTACHMENT +// TODO? no model exists for this // #define KH_PLAYER_USE_CARRIEDMODEL #ifdef KH_PLAYER_USE_ATTACHMENT diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc index d4303efbd9..3128bae266 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc @@ -988,7 +988,7 @@ void ons_GeneratorThink(entity this) { Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM); msg_entity = it; - soundto(MSG_ONE, this, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound? + soundto(MSG_ONE, this, CHAN_AUTO, SND(ONS_GENERATOR_ALARM), VOL_BASE, ATTEN_NONE); } else Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED)); diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index c6a853d0e1..8dc82dbcf9 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -1033,7 +1033,7 @@ void nades_GiveBonus(entity player, float score) if ( STAT(NADE_BONUS_SCORE, player) >= 1 ) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_NADE_BONUS); - play2(player, SND(KH_ALARM)); + play2(player, SND(NADE_BONUS)); STAT(NADE_BONUS, player)++; STAT(NADE_BONUS_SCORE, player) -= 1; } diff --git a/qcsrc/common/sounds/all.inc b/qcsrc/common/sounds/all.inc index 31b5ed4873..29f2946b05 100644 --- a/qcsrc/common/sounds/all.inc +++ b/qcsrc/common/sounds/all.inc @@ -198,6 +198,7 @@ SOUND(ONS_CONTROLPOINT_BUILT, "onslaught/controlpoint_built"); SOUND(ONS_CONTROLPOINT_UNDERATTACK, "onslaught/controlpoint_underattack"); SOUND(ONS_DAMAGEBLOCKEDBYSHIELD, "onslaught/damageblockedbyshield"); SOUND(ONS_ELECTRICITY_EXPLODE, "onslaught/electricity_explode"); +SOUND(ONS_GENERATOR_ALARM, "kh/alarm"); // FIXME: unique sound SOUND(ONS_GENERATOR_DECAY, "onslaught/generator_decay"); SOUND(ONS_GENERATOR_UNDERATTACK, "onslaught/generator_underattack"); SOUND(ONS_HIT1, "onslaught/ons_hit1"); @@ -236,6 +237,7 @@ SOUND(VEH_SPIDERBOT_STRAFE, "vehicles/spiderbot_strafe"); SOUND(VEH_SPIDERBOT_WALK, "vehicles/spiderbot_walk"); SOUND(NADE_BEEP, "overkill/grenadebip"); +SOUND(NADE_BONUS, "kh/alarm"); // FIXME: unique sound SOUND(BUFF_LOST, "relics/relic_effect"); diff --git a/qcsrc/server/steerlib.qc b/qcsrc/server/steerlib.qc index 92c918f00c..310835c5ce 100644 --- a/qcsrc/server/steerlib.qc +++ b/qcsrc/server/steerlib.qc @@ -17,7 +17,7 @@ /** Uniform push from a point **/ -#define steerlib_push(ent,point) normalize(ent.origin - point) +#define steerlib_push(ent,point) normalize((ent).origin - point) /* vector steerlib_push(entity this, vector point) { @@ -29,7 +29,7 @@ vector steerlib_push(entity this, vector point) **/ vector steerlib_arrive(entity this, vector point, float maximal_distance) { - float distance = bound(0.001,vlen(this.origin - point),maximal_distance); + float distance = bound(0.001, vlen(this.origin - point), maximal_distance); vector direction = normalize(point - this.origin); return direction * (distance / maximal_distance); } @@ -39,21 +39,21 @@ vector steerlib_arrive(entity this, vector point, float maximal_distance) **/ vector steerlib_attract(entity this, vector point, float maximal_distance) { - float distance = bound(0.001,vlen(this.origin - point),maximal_distance); + float distance = bound(0.001, vlen(this.origin - point), maximal_distance); vector direction = normalize(point - this.origin); - return direction * (1-(distance / maximal_distance)); + return direction * (1 - (distance / maximal_distance)); } -vector steerlib_attract2(entity this, vector point, float min_influense,float max_distance,float max_influense) +vector steerlib_attract2(entity this, vector point, float min_influense, float max_distance, float max_influense) { - float distance = bound(0.00001,vlen(this.origin - point),max_distance); + float distance = bound(0.00001, vlen(this.origin - point), max_distance); vector direction = normalize(point - this.origin); float influense = 1 - (distance / max_distance); influense = min_influense + (influense * (max_influense - min_influense)); - return direction * influense; + return direction * influense; } /* @@ -89,27 +89,21 @@ vector steerlib_attract2(vector point, float maximal_distance,float min_influens /** Move away from a point. **/ -vector steerlib_repell(entity this, vector point,float maximal_distance) +vector steerlib_repel(entity this, vector point, float maximal_distance) { - float distance; - vector direction; - - distance = bound(0.001,vlen(this.origin - point),maximal_distance); - direction = normalize(this.origin - point); + float distance = bound(0.001, vlen(this.origin - point), maximal_distance); + vector direction = normalize(this.origin - point); - return direction * (1-(distance / maximal_distance)); + return direction * (1 - (distance / maximal_distance)); } /** Try to keep at ideal_distance away from point **/ -vector steerlib_standoff(entity this, vector point,float ideal_distance) +vector steerlib_standoff(entity this, vector point, float ideal_distance) { - float distance; vector direction; - - distance = vlen(this.origin - point); - + float distance = vlen(this.origin - point); if(distance < ideal_distance) { @@ -123,22 +117,22 @@ vector steerlib_standoff(entity this, vector point,float ideal_distance) } /** - A random heading in a forward halfcicrle + A random heading in a forward semicircle - use like: - this.target = steerlib_wander(256,32,this.target) + usage: + this.target = steerlib_wander(256, 32, this.target) - where range is the cicrle radius and tresh is how close we need to be to pick a new heading. + where range is the circle radius and threshold is how close we need to be to pick a new heading. + Assumes v_forward is set by makevectors **/ -vector steerlib_wander(entity this, float range, float tresh, vector oldpoint) +vector steerlib_wander(entity this, float range, float threshold, vector oldpoint) { - vector wander_point; - wander_point = v_forward - oldpoint; + vector wander_point = v_forward - oldpoint; - if (vdist(wander_point, >, tresh)) + if (vdist(wander_point, >, threshold)) return oldpoint; - range = bound(0,range,1); + range = bound(0, range, 1); wander_point = this.origin + v_forward * 128; wander_point = wander_point + randomvec() * (range * 128) - randomvec() * (range * 128); @@ -147,17 +141,15 @@ vector steerlib_wander(entity this, float range, float tresh, vector oldpoint) } /** - Dodge a point. dont work to well. + Dodge a point NOTE: doesn't work well **/ vector steerlib_dodge(entity this, vector point, vector dodge_dir, float min_distance) { - float distance; - - distance = max(vlen(this.origin - point),min_distance); + float distance = max(vlen(this.origin - point), min_distance); if (min_distance < distance) return '0 0 0'; - return dodge_dir * (min_distance/distance); + return dodge_dir * (min_distance / distance); } /** @@ -165,20 +157,19 @@ vector steerlib_dodge(entity this, vector point, vector dodge_dir, float min_dis Group will move towards the unified direction while keeping close to eachother. **/ .float flock_id; -vector steerlib_flock(entity this, float _radius, float standoff,float separation_force,float flock_force) +vector steerlib_flock(entity this, float _radius, float standoff, float separation_force, float flock_force) { - entity flock_member; vector push = '0 0 0', pull = '0 0 0'; - float ccount = 0; + int ccount = 0; - flock_member = findradius(this.origin, _radius); + entity flock_member = findradius(this.origin, _radius); while(flock_member) { if(flock_member != this) if(flock_member.flock_id == this.flock_id) { ++ccount; - push = push + (steerlib_repell(this, flock_member.origin,standoff) * separation_force); + push = push + (steerlib_repel(this, flock_member.origin,standoff) * separation_force); pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force); } flock_member = flock_member.chain; @@ -191,20 +182,19 @@ vector steerlib_flock(entity this, float _radius, float standoff,float separatio Group will move towards the unified direction while keeping close to eachother. xy only version (for ground movers). **/ -vector steerlib_flock2d(entity this, float _radius, float standoff,float separation_force,float flock_force) +vector steerlib_flock2d(entity this, float _radius, float standoff, float separation_force, float flock_force) { - entity flock_member; vector push = '0 0 0', pull = '0 0 0'; - float ccount = 0; + int ccount = 0; - flock_member = findradius(this.origin,_radius); + entity flock_member = findradius(this.origin,_radius); while(flock_member) { if(flock_member != this) if(flock_member.flock_id == this.flock_id) { ++ccount; - push = push + (steerlib_repell(this, flock_member.origin, standoff) * separation_force); + push = push + (steerlib_repel(this, flock_member.origin, standoff) * separation_force); pull = pull + (steerlib_arrive(this, flock_member.origin + flock_member.velocity, _radius) * flock_force); } flock_member = flock_member.chain; @@ -218,25 +208,23 @@ vector steerlib_flock2d(entity this, float _radius, float standoff,float separat /** 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. + The further from the center the more they want to be there. This results in a aligned movement (?!) much like flocking. **/ -vector steerlib_swarm(entity this, float _radius, float standoff,float separation_force,float swarm_force) +vector steerlib_swarm(entity this, float _radius, float standoff, float separation_force, float swarm_force) { - entity swarm_member; vector force = '0 0 0', center = '0 0 0'; - float ccount = 0; - - swarm_member = findradius(this.origin,_radius); + int ccount = 0; + entity swarm_member = findradius(this.origin,_radius); while(swarm_member) { if(swarm_member.flock_id == this.flock_id) { ++ccount; center = center + swarm_member.origin; - force = force + (steerlib_repell(this, swarm_member.origin,standoff) * separation_force); + force = force + (steerlib_repel(this, swarm_member.origin,standoff) * separation_force); } swarm_member = swarm_member.chain; } @@ -252,93 +240,80 @@ vector steerlib_swarm(entity this, float _radius, float standoff,float separatio 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(entity this, float pitch,float length) +vector steerlib_traceavoid(entity this, float pitch, float length) { - vector vup_left,vup_right,vdown_left,vdown_right; - float fup_left,fup_right,fdown_left,fdown_right; - vector upwish,downwish,leftwish,rightwish; - vector v_left,v_down; - + vector v_left = v_right * -1; + vector v_down = v_up * -1; - v_left = v_right * -1; - v_down = v_up * -1; - - vup_left = (v_forward + (v_left * pitch + v_up * pitch)) * length; - traceline(this.origin, this.origin + vup_left,MOVE_NOMONSTERS,this); - fup_left = trace_fraction; + vector vup_left = (v_forward + (v_left * pitch + v_up * pitch)) * length; + traceline(this.origin, this.origin + vup_left, MOVE_NOMONSTERS, this); + float fup_left = trace_fraction; //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; + vector vup_right = (v_forward + (v_right * pitch + v_up * pitch)) * length; + traceline(this.origin, this.origin + vup_right, MOVE_NOMONSTERS, this); + float fup_right = trace_fraction; //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; + vector vdown_left = (v_forward + (v_left * pitch + v_down * pitch)) * length; + traceline(this.origin, this.origin + vdown_left, MOVE_NOMONSTERS, this); + float fdown_left = trace_fraction; //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; + vector vdown_right = (v_forward + (v_right * pitch + v_down * pitch)) * length; + traceline(this.origin, this.origin + vdown_right, MOVE_NOMONSTERS, this); + float fdown_right = trace_fraction; //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); - rightwish = v_right * (fup_right + fdown_right); + vector upwish = v_up * (fup_left + fup_right); + vector downwish = v_down * (fdown_left + fdown_right); + vector leftwish = v_left * (fup_left + fdown_left); + vector rightwish = v_right * (fup_right + fdown_right); - return (upwish+leftwish+downwish+rightwish) * 0.25; + return (upwish + leftwish + downwish + rightwish) * 0.25; } /** Steer towards the direction least obstructed. Run tracelines in a forward trident, bias each direction 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_flat(entity this, float pitch, float length, vector vofs) { - vector vt_left, vt_right,vt_front; - float f_left, f_right,f_front; - vector leftwish, rightwish,frontwish, v_left; + vector v_left = v_right * -1; - v_left = v_right * -1; - - - vt_front = v_forward * length; + vector vt_front = v_forward * length; traceline(this.origin + vofs, this.origin + vofs + vt_front,MOVE_NOMONSTERS,this); - f_front = trace_fraction; + float f_front = trace_fraction; - vt_left = (v_forward + (v_left * pitch)) * length; + vector vt_left = (v_forward + (v_left * pitch)) * length; traceline(this.origin + vofs, this.origin + vofs + vt_left,MOVE_NOMONSTERS,this); - f_left = trace_fraction; + float f_left = trace_fraction; //te_lightning1(NULL,this.origin, trace_endpos); - vt_right = (v_forward + (v_right * pitch)) * length; + vector vt_right = (v_forward + (v_right * pitch)) * length; traceline(this.origin + vofs, this.origin + vofs + vt_right ,MOVE_NOMONSTERS,this); - f_right = trace_fraction; + float f_right = trace_fraction; //te_lightning1(NULL,this.origin, trace_endpos); - leftwish = v_left * f_left; - rightwish = v_right * f_right; - frontwish = v_forward * f_front; + vector leftwish = v_left * f_left; + vector rightwish = v_right * f_right; + vector frontwish = v_forward * f_front; return normalize(leftwish + rightwish + frontwish); } //#define BEAMSTEER_VISUAL -float beamsweep(entity this, vector from, vector dir,float length, float step,float step_up, float step_down) +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; - - u = '0 0 1' * step_up; - d = '0 0 1' * step_down; + vector u = '0 0 1' * step_up; + vector d = '0 0 1' * step_down; traceline(from + u, from - d,MOVE_NORMAL,this); if(trace_fraction == 1.0) @@ -347,11 +322,11 @@ float beamsweep(entity this, vector from, vector dir,float length, float step,fl if(!location_isok(trace_endpos, false, false)) return 0; - a = trace_endpos; - for(i = 0; i < length; i += step) + vector a = trace_endpos; + for(int i = 0; i < length; i += step) { - b = a + dir * step; + vector b = a + dir * step; tracebox(a + u,'-4 -4 -4','4 4 4', b + u,MOVE_NORMAL,this); if(trace_fraction != 1.0) return i / length; @@ -374,31 +349,27 @@ float beamsweep(entity this, vector from, vector dir,float length, float step,fl vector steerlib_beamsteer(entity this, vector dir, float length, float step, float step_up, float step_down) { - float bm_forward, bm_right, bm_left,p; - vector vr,vl; - dir.z *= 0.15; - vr = vectoangles(dir); - //vr_x *= -1; + vector vr = vectoangles(dir); + //vr.x *= -1; tracebox(this.origin + '0 0 1' * step_up, this.mins, this.maxs, ('0 0 1' * step_up) + this.origin + (dir * length), MOVE_NOMONSTERS, this); if(trace_fraction == 1.0) { - //te_lightning1(this,this.origin,this.origin + (dir * length)); + //te_lightning1(this,this.origin,this.origin + (dir * length)); return dir; } makevectors(vr); - bm_forward = beamsweep(this, this.origin, v_forward, length, step, step_up, step_down); + float bm_forward = beamsweep(this, this.origin, v_forward, length, step, step_up, step_down); vr = normalize(v_forward + v_right * 0.125); - vl = normalize(v_forward - v_right * 0.125); + vector vl = normalize(v_forward - v_right * 0.125); - 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); + float bm_right = beamsweep(this, this.origin, vr, length, step, step_up, step_down); + float bm_left = beamsweep(this, this.origin, vl, length, step, step_up, step_down); - - p = bm_left + bm_right; + float p = bm_left + bm_right; if(p == 2) { //te_lightning1(this,this.origin + '0 0 32',this.origin + '0 0 32' + vr * length); @@ -435,5 +406,4 @@ vector steerlib_beamsteer(entity this, vector dir, float length, float step, flo vl = vl * bm_left; return normalize(vr + vl); - }