From: terencehill Date: Mon, 23 Oct 2017 12:58:51 +0000 (+0200) Subject: Bot AI: make bots aware of items that can be reached by a standard jumppad trajectory... X-Git-Tag: xonotic-v0.8.5~2378^2~39 X-Git-Url: http://de.git.xonotic.org/?a=commitdiff_plain;h=435bcc06520ed9fb4afb20099245e06963ca5c3d;p=xonotic%2Fxonotic-data.pk3dir.git Bot AI: make bots aware of items that can be reached by a standard jumppad trajectory (e.g. Boil's mega armor) --- diff --git a/qcsrc/common/triggers/trigger/jumppads.qc b/qcsrc/common/triggers/trigger/jumppads.qc index 533f65989..c9729f522 100644 --- a/qcsrc/common/triggers/trigger/jumppads.qc +++ b/qcsrc/common/triggers/trigger/jumppads.qc @@ -212,7 +212,7 @@ bool jumppad_push(entity this, entity targ) animdecide_setaction(targ, ANIMACTION_JUMP, true); } else - targ.jumppadcount = true; + targ.jumppadcount = 1; // reset tracking of who pushed you into a hazard (for kill credit) targ.pushltime = 0; @@ -302,7 +302,10 @@ bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vecto return true; } #endif -void trigger_push_findtarget(entity this) + +/// if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise +/// if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter) +bool trigger_push_test(entity this, entity item) { // first calculate a typical start point for the jump vector org = (this.absmin + this.absmax) * 0.5; @@ -325,6 +328,16 @@ void trigger_push_findtarget(entity this) setsize(e, PL_MIN_CONST, PL_MAX_CONST); e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP; e.velocity = trigger_push_calculatevelocity(org, t, this.height); + + if(item) + { + setorigin(e, org); + tracetoss(e, e); + bool r = (trace_ent == item); + delete(e); + return r; + } + vel = e.velocity; vector best_target = '0 0 0'; vector best_org = '0 0 0'; @@ -389,13 +402,16 @@ void trigger_push_findtarget(entity this) #endif } + if(item) + return false; + if(!n) { // no dest! #ifdef SVQC objerror (this, "Jumppad with nonexistant target"); #endif - return; + return false; } else if(n == 1) { @@ -417,6 +433,12 @@ void trigger_push_findtarget(entity this) setorigin(e, org); e.velocity = this.movedir; tracetoss(e, e); + if(item) + { + bool r = (trace_ent == item); + delete(e); + return r; + } if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, trace_endpos + PL_MIN_CONST, trace_endpos + PL_MAX_CONST))) waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity), e); delete(e); @@ -424,6 +446,12 @@ void trigger_push_findtarget(entity this) defer(this, 0.1, trigger_push_updatelink); #endif + return true; +} + +void trigger_push_findtarget(entity this) +{ + trigger_push_test(this, NULL); } #ifdef SVQC @@ -488,6 +516,8 @@ spawnfunc(trigger_push) trigger_push_link(this); // link it now + IL_PUSH(g_jumppads, this); + // this must be called to spawn the teleport waypoints for bots InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET); } diff --git a/qcsrc/common/triggers/trigger/jumppads.qh b/qcsrc/common/triggers/trigger/jumppads.qh index a1260c4e5..819b90995 100644 --- a/qcsrc/common/triggers/trigger/jumppads.qh +++ b/qcsrc/common/triggers/trigger/jumppads.qh @@ -1,5 +1,8 @@ #pragma once +IntrusiveList g_jumppads; +STATIC_INIT(g_jumppads) { g_jumppads = IL_NEW(); } + const float PUSH_ONCE = 1; const float PUSH_SILENT = 2; @@ -14,6 +17,7 @@ const int NUM_JUMPPADSUSED = 3; #ifdef SVQC void SUB_UseTargets(entity this, entity actor, entity trigger); void trigger_push_use(entity this, entity actor, entity trigger); +bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vector org); #endif /* @@ -32,6 +36,7 @@ vector trigger_push_calculatevelocity(vector org, entity tgt, float ht); void trigger_push_touch(entity this, entity toucher); .vector dest; +bool trigger_push_test(entity this, entity item); void trigger_push_findtarget(entity this); /* diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index cfaec7f26..08e1cffe2 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -849,6 +849,20 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom best = it; } }); + if(!best && !ent.navigation_dynamicgoal) + { + int solid_save = ent.solid; + ent.solid = SOLID_BSP; + IL_EACH(g_jumppads, true, + { + if(trigger_push_test(it, ent)) + { + best = it.nearestwaypoint; + break; + } + }); + ent.solid = solid_save; + } return best; } entity navigation_findnearestwaypoint(entity ent, float walkfromwp)