From 46c2c88461a10c6b57f0f8c20091c587b5c49bba Mon Sep 17 00:00:00 2001 From: Alayan Date: Sat, 22 Sep 2018 22:02:11 +0200 Subject: [PATCH] Give a boosted AI to some AI karts in races and GP --- src/karts/controller/skidding_ai.cpp | 1 - src/modes/world.cpp | 2 +- src/race/race_manager.cpp | 25 +++++++++++++++++++++++++ src/race/race_manager.hpp | 9 ++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 9780e5fca..05583822a 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -1063,7 +1063,6 @@ void SkiddingAI::evaluateItems(const Item *item, Vec3 kart_aim_direction, * Level 2 to 5 AI : strategy detailed before each item * Each successive level is overall stronger (5 the strongest, 2 the weakest of * non-random strategies), but two levels may share a strategy for a given item. - * (level 5 is not yet used ; meant for SuperTux GP preferred karts or boss races) * \param dt Time step size. * STATE: shield on -> avoid usage of offensive items (with certain tolerance) * STATE: swatter on -> avoid usage of shield diff --git a/src/modes/world.cpp b/src/modes/world.cpp index e02c9e777..5f167230f 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -229,8 +229,8 @@ void World::init() global_player_id, race_manager->getKartType(i), race_manager->getPlayerDifficulty(i)); } + new_kart->setBoostAI(race_manager->hasBoostedAI(i)); m_karts.push_back(new_kart); - } // for i // Load other custom models if needed diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 21471396b..a329e2606 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -511,6 +511,31 @@ void RaceManager::startNextRace() } } // not first race + // set boosted AI status for AI karts + int boosted_ai_count = std::min(m_ai_kart_list.size(), + (m_kart_status.size()-2)/4 + 1); + if (boosted_ai_count > 4) boosted_ai_count = 4; + int ai_count = m_ai_kart_list.size(); + + for (unsigned int i=0;i 0 && + (UserConfigParams::m_gp_most_points_first || + ai_count == boosted_ai_count)) + { + m_kart_status[i].m_boosted_ai = true; + boosted_ai_count--; + } + else + { + m_kart_status[i].m_boosted_ai = false; + } + ai_count--; + } + } + // the constructor assigns this object to the global // variable world. Admittedly a bit ugly, but simplifies // handling of objects which get created in the constructor diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index 9982d2f91..7cf993504 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -276,6 +276,8 @@ public: /** In GPs, at the end, will hold the overall rank of this kart * (0<=m_gp_rank < num_karts-1). */ int m_gp_rank; + /** Boosted status (AI only). */ + bool m_boosted_ai; /** The difficulty for this player. */ PerPlayerDifficulty m_difficulty; @@ -289,7 +291,7 @@ public: m_local_player_id(local_player_id), m_global_player_id(global_player_id), m_gp_rank(init_gp_rank), m_difficulty(difficulty) - {} + { m_boosted_ai = false; } }; // KartStatus private: @@ -643,6 +645,11 @@ public: return m_kart_status[kart].m_difficulty; } // getPlayerDifficulty // ------------------------------------------------------------------------ + float hasBoostedAI(int kart) const + { + return m_kart_status[kart].m_boosted_ai; + } // getKartRaceTime + // ------------------------------------------------------------------------ int getCoinTarget() const { return m_coin_target; } // ------------------------------------------------------------------------ float getTimeTarget() const { return m_time_target; }