From 88df663ce7c9c0a2b525ab06f240be253027473d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 22 Aug 2003 06:56:31 +0000 Subject: [PATCH] make sisible more generic (still ick) and make lookForCrap look for waypoints, too. --- fbxa/bot_ai.qc | 24 +++++++++++++++++++----- fbxa/bot_misc.qc | 6 +++--- fbxa/libfrikbot.h | 5 ++++- fbxa/target.r | 3 +-- fbxa/waypoint.r | 22 ++++++++++++++++++++++ 5 files changed, 49 insertions(+), 11 deletions(-) diff --git a/fbxa/bot_ai.qc b/fbxa/bot_ai.qc index ba3bf74..c0d8fad 100644 --- a/fbxa/bot_ai.qc +++ b/fbxa/bot_ai.qc @@ -559,28 +559,42 @@ the bot finds things it wants to kill/grab. -(void)lookForCrap:(integer)scope { local Target foe, best = NIL; + local Waypoint way; local integer thatp, bestp; - local float dist; + local float radius; if (scope == 1) - foe = [Target forEntity:findradius (ent.origin, 13000)]; + radius = 13000; else - foe = [Target forEntity:findradius (ent.origin, 500)]; + radius = 500; + foe = [Target forEntity:findradius (ent.origin, radius)]; bestp = 1; while (foe) { thatp = [self priorityForThing:foe]; if (thatp) if (!scope) - if (!sisible (ent, foe.ent)) + if (!sisible (ent, foe.ent, foe.ent.origin)) thatp = 0; if (thatp > bestp) { bestp = thatp; best = foe; - dist = vlen (ent.origin - foe.ent.origin); } foe = [Target forEntity:foe.ent.chain]; } + way = [Waypoint find:ent.origin radius:radius]; + while (way) { + thatp = [self priorityForThing:way]; + if (thatp) + if (!scope) + if (!sisible (ent, NIL, way.origin)) + thatp = 0; + if (thatp > bestp) { + bestp = thatp; + best = way; + } + way = way.chain; + } if (best == NIL) return; if (![self targetOnstack:best]) { diff --git a/fbxa/bot_misc.qc b/fbxa/bot_misc.qc index cd96675..8180a8b 100644 --- a/fbxa/bot_misc.qc +++ b/fbxa/bot_misc.qc @@ -165,11 +165,11 @@ sisible Now this is getting ridiculous. Simple visible, used when we need just a simple traceline nothing else */ -float (entity ent, entity targ) +float (entity ent, entity targ, vector targ_origin) sisible = { - traceline (ent.origin, targ.origin, TRUE, ent); - if (trace_ent == targ) + traceline (ent.origin, targ_origin, TRUE, ent); + if (targ && trace_ent == targ) return TRUE; else if (trace_fraction == 1) return TRUE; diff --git a/fbxa/libfrikbot.h b/fbxa/libfrikbot.h index 59f23b1..4f6f360 100644 --- a/fbxa/libfrikbot.h +++ b/fbxa/libfrikbot.h @@ -37,6 +37,8 @@ typedef struct bot_data_t bot_data_t; float items; Waypoint enemy; float search_time; + + Waypoint chain; } +(void)clearAll; +(Waypoint)waypointForNum:(integer)num; @@ -44,6 +46,7 @@ typedef struct bot_data_t bot_data_t; +(void)clearRouteTable; +(void)clearMyRoute:(Bot) bot; ++(Waypoint)find:(vector)org radius:(float)rad; -(void)fix; -(id)init; @@ -299,7 +302,7 @@ typedef struct bot_data_t bot_data_t; // ai & misc @extern float(float y1, float y2) angcomp; -@extern float(entity ent, entity targ) sisible; +@extern float(entity ent, entity targ, vector targ_origin) sisible; @extern vector(entity ent) realorigin; @extern float(float v) frik_anglemod; diff --git a/fbxa/target.r b/fbxa/target.r index 15c5c1d..b29ac79 100644 --- a/fbxa/target.r +++ b/fbxa/target.r @@ -221,8 +221,7 @@ Finds the closest, fisible, waypoint to e if (!(t.flags & AI_IGNORE_TYPES) || ishuman) { tdst = vlen (t.origin - org); if (tdst < dst) { - traceline (ent.origin, t.origin, TRUE, ent); - if (trace_fraction == 1) { + if (sisible (ent, NIL, t.origin)) { dst = tdst; best = t; } diff --git a/fbxa/waypoint.r b/fbxa/waypoint.r index f7fbe0b..48c826e 100644 --- a/fbxa/waypoint.r +++ b/fbxa/waypoint.r @@ -219,6 +219,28 @@ Waypoint Loading from file [waypoint_array makeObjectsPerformSelector:@selector(fix)]; } ++(Waypoint)find:(vector)org radius:(float)rad +{ + local vector dif; + local float dist; + local integer i, count; + local Waypoint way = NIL, w; + + rad = rad * rad; // radius squared + + count = [waypoint_array count]; + for (i = 1; i < count; i++) { + w = [waypoint_array getItemAt:i]; + dif = w.origin - org; + dist = dif * dif; // dist squared, really + if (dist < rad) { + w.chain = way; + way = w; + } + } + return way; +} + /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=