From 2c1e6722d0f10a8837a6be4eb5b59eba33a953fb Mon Sep 17 00:00:00 2001 From: div0 Date: Sat, 25 Jul 2009 13:50:43 +0000 Subject: [PATCH] fix bot AI item decisions git-svn-id: svn://svn.icculus.org/nexuiz/trunk@7261 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/bots.qc | 1 + data/qcsrc/server/havocbot_roles.qc | 113 ++-------------------------- data/qcsrc/server/t_items.qc | 92 +++++++++++++++++++--- 3 files changed, 89 insertions(+), 117 deletions(-) diff --git a/data/qcsrc/server/bots.qc b/data/qcsrc/server/bots.qc index 643df2135..4e28db154 100644 --- a/data/qcsrc/server/bots.qc +++ b/data/qcsrc/server/bots.qc @@ -1486,6 +1486,7 @@ entity navigation_findnearestwaypoint(entity ent, float walkfromwp) org = org + ent.tag_entity.origin; if (navigation_testtracewalk) te_plasmaburn(org); + best = world; bestdist = 1050; diff --git a/data/qcsrc/server/havocbot_roles.qc b/data/qcsrc/server/havocbot_roles.qc index 5f94309b8..591ca114c 100644 --- a/data/qcsrc/server/havocbot_roles.qc +++ b/data/qcsrc/server/havocbot_roles.qc @@ -7,114 +7,11 @@ float bot_ignore_bots; .float max_armorvalue; float havocbot_pickupevalfunc(entity item) { - float i, j, rating, base, position, need_shells, need_nails, need_rockets, need_cells; - entity wi; - - base = item.bot_pickupbasevalue; - rating = 0; - - // Detect needed ammo - for(i = WEP_FIRST; i < WEP_LAST ; ++i) - { - wi = get_weaponinfo(i); - - if not(wi.weapons & self.weapons) - continue; - - if(wi.items & IT_SHELLS) - need_shells = TRUE; - else if(wi.items & IT_NAILS) - need_nails = TRUE; - else if(wi.items & IT_ROCKETS) - need_rockets = TRUE; - else if(wi.items & IT_CELLS) - need_cells = TRUE; - } - - // Rate ammo items - if (item.ammo_shells) - if (self.ammo_shells < g_pickup_shells_max && need_cells ) - rating = rating + max(0, 1 - self.ammo_shells / g_pickup_shells_max); - - if (item.ammo_nails) - if (self.ammo_nails < g_pickup_nails_max && need_nails ) - rating = rating + max(0, 1 - self.ammo_nails / g_pickup_nails_max); - - if (item.ammo_rockets) - if (self.ammo_rockets < g_pickup_rockets_max && need_rockets) - rating = rating + max(0, 1 - self.ammo_rockets / g_pickup_rockets_max); - - if (item.ammo_cells) - if (self.ammo_cells < g_pickup_cells_max && need_cells) - rating = rating + max(0, 1 - self.ammo_cells / g_pickup_cells_max); - - // Rate health items (aim to grab half the max capacity) - if (item.armorvalue) - if (self.armorvalue < item.max_armorvalue * 0.5) - rating = rating + max(0, 1 - self.armorvalue / (item.max_armorvalue * 0.5)); - - if (item.health) - if (self.health < item.max_health * 0.5) - { - rating = rating + max(0, 1 - self.health / (item.max_health * 0.5)); - } - - // Rate weapons - if( item.weapons ) - { - // See if I have it already - if( self.weapons & item.weapons == item.weapons ) - { - // If I can pick it up - if(rating) - if not(cvar("g_weapon_stay")) - { - // Skilled bots will grab more - local float divisor = 2; - rating += bound(0, skill / (10*divisor), 1/divisor); - } - } - else - rating += 1; - - // If custom weapon priorities for bots is enabled rate most wanted weapons higher - if( bot_custom_weapon && rating ) - { - for(i = WEP_FIRST; i < WEP_LAST ; ++i) - { - // Find weapon - if( (get_weaponinfo(i)).weapons & item.weapons != item.weapons ) - continue; - - // Find the highest position on any range - position = -1; - for(j = 0; j < WEP_LAST ; ++j){ - if( - bot_weapons_far[j] == i || - bot_weapons_mid[j] == i || - bot_weapons_close[j] == i - ) - { - position = j; - break; - } - } - - // Rate it - if (position >= 0 ) - { - position = WEP_LAST - position; - // item.bot_pickupbasevalue is overwritten here - base = BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST )); - break; - } - } - } - } - - // TODO: if the item is not recognized then default to item.bot_pickupevalfunc(self, item); - return base * rating; -}; + float r; + r = item.bot_pickupevalfunc(self, item); + // print(item.classname, " ", ftos(r), "\n"); + return r; +} void havocbot_goalrating_items(float ratingscale, vector org, float sradius) { diff --git a/data/qcsrc/server/t_items.qc b/data/qcsrc/server/t_items.qc index 509853b0a..a04bde08f 100644 --- a/data/qcsrc/server/t_items.qc +++ b/data/qcsrc/server/t_items.qc @@ -477,37 +477,111 @@ float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickup float weapon_pickupevalfunc(entity player, entity item) { - // if we already have the weapon, rate it 1/5th normal value - if ((player.weapons & item.weapons) == item.weapons) - return item.bot_pickupbasevalue * 0.2; - return item.bot_pickupbasevalue; + float c, i, j, position; + + // See if I have it already + if(player.weapons & item.weapons == item.weapons) + { + // If I can pick it up + if(g_weapon_stay == 1) + c = 0; + else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets) + { + // Skilled bots will grab more + c = bound(0, skill / 10, 1) * 0.5; + } + else + c = 0; + } + else + c = 1; + + // If custom weapon priorities for bots is enabled rate most wanted weapons higher + if( bot_custom_weapon && c ) + { + for(i = WEP_FIRST; i < WEP_LAST ; ++i) + { + // Find weapon + if( (get_weaponinfo(i)).weapons & item.weapons != item.weapons ) + continue; + + // Find the highest position on any range + position = -1; + for(j = 0; j < WEP_LAST ; ++j){ + if( + bot_weapons_far[j] == i || + bot_weapons_mid[j] == i || + bot_weapons_close[j] == i + ) + { + position = j; + break; + } + } + + // Rate it + if (position >= 0 ) + { + position = WEP_LAST - position; + // item.bot_pickupbasevalue is overwritten here + return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c; + break; + } + } + } + + return item.bot_pickupbasevalue * c; }; float commodity_pickupevalfunc(entity player, entity item) { - float c; + float c, i, need_shells, need_nails, need_rockets, need_cells; + entity wi; c = 0; + + // Detect needed ammo + for(i = WEP_FIRST; i < WEP_LAST ; ++i) + { + wi = get_weaponinfo(i); + + if not(wi.weapons & player.weapons) + continue; + + if(wi.items & IT_SHELLS) + need_shells = TRUE; + else if(wi.items & IT_NAILS) + need_nails = TRUE; + else if(wi.items & IT_ROCKETS) + need_rockets = TRUE; + else if(wi.items & IT_CELLS) + need_cells = TRUE; + } + // TODO: figure out if the player even has the weapon this ammo is for? // may not affect strategy much though... // find out how much more ammo/armor/health the player can hold + if (need_shells) if (item.ammo_shells) if (player.ammo_shells < g_pickup_shells_max) c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max); + if (need_nails) if (item.ammo_nails) if (player.ammo_nails < g_pickup_nails_max) c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max); + if (need_rockets) if (item.ammo_rockets) if (player.ammo_rockets < g_pickup_rockets_max) c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max); + if (need_cells) if (item.ammo_cells) if (player.ammo_cells < g_pickup_cells_max) c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max); if (item.armorvalue) - if (player.armorvalue < item.max_armorvalue) - c = c + max(0, 1 - player.armorvalue / item.max_armorvalue); + if (player.armorvalue < item.max_armorvalue*0.5) + c = c + max(0, 1 - player.armorvalue / (item.max_armorvalue*0.5)); if (item.health) - if (player.health < item.max_health) - c = c + max(0, 1 - player.health / item.max_health); + if (player.health < item.max_health*0.5) + c = c + max(0, 1 - player.health / (item.max_health*0.5)); return item.bot_pickupbasevalue * c; }; -- 2.39.2