From: terencehill Date: Tue, 7 Mar 2017 01:45:29 +0000 (+0100) Subject: Fix nearest waypoint not updated for dropped flags, keys and keepaway ball causing... X-Git-Tag: xonotic-v0.8.2~117 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=110173afd486084f9940a8d205f76811c5e33322;p=xonotic%2Fxonotic-data.pk3dir.git Fix nearest waypoint not updated for dropped flags, keys and keepaway ball causing bots to often not being able to reach them --- diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh index d8b7fd044..5f05f7658 100644 --- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh +++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qh @@ -70,9 +70,6 @@ bool ons_stalemate; .float teleport_antispam; -// waypoint sprites -.entity bot_basewaypoint; // generator waypointsprite - .bool isgenneighbor[17]; .bool iscpneighbor[17]; float ons_notification_time[17]; diff --git a/qcsrc/server/bot/api.qh b/qcsrc/server/bot/api.qh index b0f457df4..fbf1a982c 100644 --- a/qcsrc/server/bot/api.qh +++ b/qcsrc/server/bot/api.qh @@ -68,6 +68,11 @@ void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius); void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius); +.entity bot_basewaypoint; +.bool navigation_dynamicgoal; +void navigation_dynamicgoal_init(entity this, bool initially_static); +void navigation_dynamicgoal_set(entity this); +void navigation_dynamicgoal_unset(entity this); entity navigation_findnearestwaypoint(entity ent, float walkfromwp); void navigation_goalrating_end(entity this); void navigation_goalrating_start(entity this); diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 65ba4d00b..857d6222f 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -15,6 +15,28 @@ .float speed; +void navigation_dynamicgoal_init(entity this, bool initially_static) +{ + this.navigation_dynamicgoal = true; + this.bot_basewaypoint = this.nearestwaypoint; + if(initially_static) + this.nearestwaypointtimeout = time + 1000000000; + else + this.nearestwaypointtimeout = time; +} + +void navigation_dynamicgoal_set(entity this) +{ + this.nearestwaypointtimeout = time; +} + +void navigation_dynamicgoal_unset(entity this) +{ + if(this.bot_basewaypoint) + this.nearestwaypoint = this.bot_basewaypoint; + this.nearestwaypointtimeout = time + 1000000000; +} + // rough simulation of walking from one point to another to test if a path // can be traveled, used for waypoint linking and havocbot @@ -799,21 +821,7 @@ void navigation_routerating(entity this, entity e, float f, float rangebias) } else { - bool search = true; - - if((e.flags & FL_ITEM) && e.nearestwaypoint) - { - if (e.flags & FL_WEAPON) - { - if(e.classname != "droppedweapon") - search = false; - } - else - search = false; - } - - if(search) - if (time > e.nearestwaypointtimeout) + if ((!e.nearestwaypoint || e.navigation_dynamicgoal) && time > e.nearestwaypointtimeout) { nwp = navigation_findnearestwaypoint(e, true); if(nwp) @@ -822,16 +830,8 @@ void navigation_routerating(entity this, entity e, float f, float rangebias) { LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e)); - if(e.flags & FL_ITEM) - { - if (e.flags & FL_WEAPON) - { - if(e.classname != "droppedweapon") - e.blacklisted = true; - } - else - e.blacklisted = true; - } + if(!e.navigation_dynamicgoal) + e.blacklisted = true; if(e.blacklisted) { @@ -840,11 +840,8 @@ void navigation_routerating(entity this, entity e, float f, float rangebias) } } - // TODO: Cleaner solution, probably handling this timeout from ctf.qc - if(e.classname=="item_flag_team") + if(e.navigation_dynamicgoal) e.nearestwaypointtimeout = time + 2; - else - e.nearestwaypointtimeout = time + random() * 3 + 5; } nwp = e.nearestwaypoint; } diff --git a/qcsrc/server/bot/default/navigation.qh b/qcsrc/server/bot/default/navigation.qh index e5097563c..889169163 100644 --- a/qcsrc/server/bot/default/navigation.qh +++ b/qcsrc/server/bot/default/navigation.qh @@ -47,6 +47,13 @@ entity bot_waypoint_queue_goal; // Head of the temporary list of goals entity bot_waypoint_queue_bestgoal; float bot_waypoint_queue_bestgoalrating; +.entity bot_basewaypoint; +.bool navigation_dynamicgoal; +void navigation_dynamicgoal_init(entity this, bool initially_static); +void navigation_dynamicgoal_set(entity this); +void navigation_dynamicgoal_unset(entity this); + + /* * Functions */ diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 5506a9d0f..0e84ec824 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -651,6 +651,7 @@ void PutClientInServer(entity this) IL_PUSH(g_bot_targets, this); this.bot_attack = true; this.monster_attack = true; + navigation_dynamicgoal_init(this, false); PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_JUMP(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false; diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index b20718ef7..b1d0ab646 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -479,6 +479,7 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype) flag.solid = SOLID_TRIGGER; flag.ctf_dropper = player; flag.ctf_droptime = time; + navigation_dynamicgoal_set(flag); flag.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND for MOVETYPE_TOSS @@ -1197,6 +1198,7 @@ void ctf_RespawnFlag(entity flag) flag.ctf_pickuptime = 0; flag.ctf_droptime = 0; flag.ctf_flagdamaged_byworld = false; + navigation_dynamicgoal_unset(flag); ctf_CheckStalemate(); } @@ -1225,8 +1227,7 @@ void ctf_DelayedFlagSetup(entity this) // called after a flag is placed on a map { // bot waypoints waypoint_spawnforitem_force(this, this.origin); - this.nearestwaypointtimeout = 0; // activate waypointing again - this.bot_basewaypoint = this.nearestwaypoint; + navigation_dynamicgoal_init(this, true); // waypointsprites entity basename; diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qh b/qcsrc/server/mutators/mutator/gamemode_ctf.qh index 2c67372b4..c0b803422 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qh +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qh @@ -67,7 +67,6 @@ entity ctf_worldflaglist; .entity ctf_staleflagnext; // waypoint sprites -.entity bot_basewaypoint; // flag waypointsprite .entity wps_helpme; .entity wps_flagbase; .entity wps_flagcarrier; diff --git a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc index 07c015f25..0b4bd54aa 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keepaway.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keepaway.qc @@ -38,7 +38,6 @@ void ka_EventLog(string mode, entity actor) // use an alias for easy changing an } void ka_TouchEvent(entity this, entity toucher); -void ka_RespawnBall(entity this); void ka_RespawnBall(entity this) // runs whenever the ball needs to be relocated { if(game_stopped) return; @@ -59,6 +58,7 @@ void ka_RespawnBall(entity this) // runs whenever the ball needs to be relocated settouch(this, ka_TouchEvent); setthink(this, ka_RespawnBall); this.nextthink = time + autocvar_g_keepawayball_respawntime; + navigation_dynamicgoal_set(this); Send_Effect(EFFECT_ELECTRO_COMBO, oldballorigin, '0 0 0', 1); Send_Effect(EFFECT_ELECTRO_COMBO, this.origin, '0 0 0', 1); @@ -114,6 +114,7 @@ void ka_TouchEvent(entity this, entity toucher) // runs any time that the ball c setthink(this, ka_TimeScoring); this.nextthink = time + autocvar_g_keepaway_score_timeinterval; this.takedamage = DAMAGE_NO; + navigation_dynamicgoal_unset(this); // apply effects to player toucher.glow_color = autocvar_g_keepawayball_trail_color; @@ -158,6 +159,7 @@ void ka_DropEvent(entity plyr) // runs any time that a player is supposed to los ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom(); ball.owner.ballcarried = world; // I hope nothing checks to see if the world has the ball in the rest of my code :P ball.owner = NULL; + navigation_dynamicgoal_set(ball); // reset the player effects plyr.glow_trail = false; @@ -457,6 +459,7 @@ void ka_SpawnBall() // loads various values for the ball, runs only once at star settouch(e, ka_TouchEvent); e.owner = NULL; ka_ball = e; + navigation_dynamicgoal_init(ka_ball, false); InitializeEntity(e, ka_RespawnBall, INITPRIO_SETLOCATION); // is this the right priority? Neh, I have no idea.. Well-- it works! So. } diff --git a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc index 0c3d27be4..6750d48d0 100644 --- a/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/mutator/gamemode_keyhunt.qc @@ -256,6 +256,7 @@ void kh_Key_Attach(entity key) // runs when a player picks up a key and several key.damageforcescale = 0; key.takedamage = DAMAGE_NO; key.modelindex = kh_key_carried; + navigation_dynamicgoal_unset(key); } void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs several times times when all the keys are captured @@ -295,6 +296,7 @@ void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs key.takedamage = DAMAGE_YES; // let key.team stay key.modelindex = kh_key_dropped; + navigation_dynamicgoal_set(key); key.kh_previous_owner = key.owner; key.kh_previous_owner_playerid = key.owner.playerid; } @@ -742,6 +744,7 @@ void kh_Key_Spawn(entity initial_owner, float _angle, float i) // runs every ti setsize(key, KH_KEY_MIN, KH_KEY_MAX); key.colormod = Team_ColorRGB(initial_owner.team) * KH_KEY_BRIGHTNESS; key.reset = key_reset; + navigation_dynamicgoal_init(key, false); switch(initial_owner.team) { diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index d68256628..53e68d9eb 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -47,6 +47,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto wep.flags |= FL_TOSSED; wep.colormap = own.colormap; wep.glowmod = weaponentity_glowmod(info, own, own.clientcolors, own.(weaponentity)); + navigation_dynamicgoal_init(wep, false); W_DropEvent(wr_drop,own,wpn,wep,weaponentity);