From ca6da8c5371cc5618f9ca3f28d34609a3a99315d Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 10 Dec 2015 01:21:01 +0800 Subject: [PATCH] Make AI smarter 1. Correct fire angle for bowling 2. When swapper is used, follow a closest kart instead. --- src/karts/controller/battle_ai.cpp | 28 ++++++++++++++++++++-------- src/karts/controller/battle_ai.hpp | 2 -- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/karts/controller/battle_ai.cpp b/src/karts/controller/battle_ai.cpp index 486e22c61..2c4cd746c 100644 --- a/src/karts/controller/battle_ai.cpp +++ b/src/karts/controller/battle_ai.cpp @@ -316,7 +316,8 @@ void BattleAI::findClosestKart(bool difficulty) void BattleAI::findTarget() { // Find a suitable target to drive to, either powerup or kart - if (m_kart->getPowerup()->getType() == PowerupManager::POWERUP_NOTHING) + if (m_kart->getPowerup()->getType() == PowerupManager::POWERUP_NOTHING && + m_kart->getAttachment()->getType() != Attachment::ATTACH_SWATTER) handleItemCollection(&m_target_point , &m_target_node); else { @@ -699,7 +700,7 @@ void BattleAI::handleItems(const float dt) const bool fire_behind = m_closest_kart_pos_data.behind && !difficulty; - const bool perfect_aim = m_closest_kart_pos_data.angle < 0.5f; + const bool perfect_aim = m_closest_kart_pos_data.angle < 0.2f; switch(m_kart->getPowerup()->getType()) { @@ -767,7 +768,7 @@ void BattleAI::handleItems(const float dt) // Leave some time between shots if (m_time_since_last_shot < 1.0f) break; - if (m_closest_kart_pos_data.distance < 5.0f && + if (m_closest_kart_pos_data.distance < 6.0f && (difficulty || perfect_aim)) { m_controls->m_fire = true; @@ -833,12 +834,12 @@ void BattleAI::handleItemCollection(Vec3* aim_point, int* target_node) float distance = 99999.9f; const std::vector< std::pair >& item_list = BattleGraph::get()->getItemList(); - unsigned int items_count = item_list.size(); + const unsigned int items_count = item_list.size(); unsigned int closest_item_num = 0; for (unsigned int i = 0; i < items_count; ++i) { - Item* item = item_list[i].first; + const Item* item = item_list[i].first; if (item->wasCollected()) continue; @@ -859,7 +860,18 @@ void BattleAI::handleItemCollection(Vec3* aim_point, int* target_node) } } - m_item_to_collect = item_list[closest_item_num].first; - *aim_point = (item_list[closest_item_num].first)->getXYZ(); - *target_node = item_list[closest_item_num].second; + const Item *item_selected = item_list[closest_item_num].first; + if (item_selected->getType() == Item::ITEM_BONUS_BOX || + item_selected->getType() == Item::ITEM_NITRO_BIG || + item_selected->getType() == Item::ITEM_NITRO_SMALL) + { + *aim_point = item_selected->getXYZ(); + *target_node = item_list[closest_item_num].second; + } + else + { + // Handle when all targets are swapped, which make AIs follow karts + *aim_point = m_closest_kart_point; + *target_node = m_closest_kart_node; + } } // handleItemCollection diff --git a/src/karts/controller/battle_ai.hpp b/src/karts/controller/battle_ai.hpp index e90ec8590..75fa575dc 100644 --- a/src/karts/controller/battle_ai.hpp +++ b/src/karts/controller/battle_ai.hpp @@ -78,8 +78,6 @@ private: * m_time_since_uturn is counting down. */ bool m_is_uturn; - const Item *m_item_to_collect; - /** Holds the unique node ai has driven through, useful to tell if AI is * stuck by determine the size of this set. */ std::set m_on_node;