From bfc1a5e14ca55f91a0d9dc801f4e5e148473675d Mon Sep 17 00:00:00 2001 From: auria Date: Tue, 4 Sep 2012 00:39:14 +0000 Subject: [PATCH] Give nolok some special powers in the last fight against him. Changing the swatter and bubble gum to different models might help make it more dramatic of course git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11538 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/challenges/fortmagma.challenge | 6 ++-- src/challenges/challenge_data.cpp | 18 +++++++++++ src/challenges/challenge_data.hpp | 1 + src/karts/controller/skidding_ai.cpp | 47 ++++++++++++++++++++++++++++ src/karts/controller/skidding_ai.hpp | 3 ++ src/race/race_manager.cpp | 1 + src/race/race_manager.hpp | 17 +++++++++- 7 files changed, 89 insertions(+), 4 deletions(-) diff --git a/data/challenges/fortmagma.challenge b/data/challenges/fortmagma.challenge index c8a1df7cb..80ff7bd05 100644 --- a/data/challenges/fortmagma.challenge +++ b/data/challenges/fortmagma.challenge @@ -5,15 +5,15 @@ - + - + - + diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index b91b3f78c..b8076c395 100644 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -51,6 +51,7 @@ ChallengeData::ChallengeData(const std::string& filename) m_position[d] = -1; m_time[d] = -1.0f; m_energy[d] = -1; + m_ai_superpower[d] = RaceManager::SUPERPOWER_NONE; } // we are using auto_ptr to make sure the XML node is released when leaving @@ -158,6 +159,19 @@ ChallengeData::ChallengeData(const std::string& filename) if (karts_node->get("aiIdent", &ai_kart_ident)) m_ai_kart_ident[d] = ai_kart_ident; + std::string superPower; + if (karts_node->get("superPower", &superPower)) + { + if (superPower == "nolokBoss") + { + m_ai_superpower[d] = RaceManager::SUPERPOWER_NOLOK_BOSS; + } + else + { + fprintf(stderr, "[ChallengeData] WARNING: Unknown AI superpower '%s'\n", superPower.c_str()); + } + } + const XMLNode* requirements_node = difficulties[d]->getNode("requirements"); if (requirements_node == NULL) error(""); @@ -372,6 +386,10 @@ void ChallengeData::setRace(RaceManager::Difficulty d) const { race_manager->setAIKartOverride(m_ai_kart_ident[d]); } + if (m_ai_superpower[d] != RaceManager::SUPERPOWER_NONE) + { + race_manager->setAISuperPower(m_ai_superpower[d]); + } } // setRace // ---------------------------------------------------------------------------- diff --git a/src/challenges/challenge_data.hpp b/src/challenges/challenge_data.hpp index 42519e990..228594a49 100644 --- a/src/challenges/challenge_data.hpp +++ b/src/challenges/challenge_data.hpp @@ -61,6 +61,7 @@ private: std::string m_ai_kart_ident[RaceManager::DIFFICULTY_COUNT]; float m_time[RaceManager::DIFFICULTY_COUNT]; int m_energy[RaceManager::DIFFICULTY_COUNT]; + RaceManager::AISuperPower m_ai_superpower[RaceManager::DIFFICULTY_COUNT]; std::string m_gp_id; std::string m_track_id; std::string m_filename; diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 76b202511..40ecb3b77 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -128,6 +128,8 @@ SkiddingAI::SkiddingAI(AbstractKart *kart) setSkiddingFraction(2.0f); break; } + + m_superpower = race_manager->getAISuperPower(); #ifdef AI_DEBUG m_debug_sphere = irr_driver->getSceneManager()->addSphereSceneNode(1.0f); @@ -247,6 +249,32 @@ void SkiddingAI::update(float dt) if(m_kart->getKartAnimation()) return; + if (m_superpower == RaceManager::SUPERPOWER_NOLOK_BOSS) + { + if (m_kart->getPowerup()->getType() == NULL || + m_kart->getPowerup()->getType()==PowerupManager::POWERUP_NOTHING) + { + if (m_kart->getAttachment()->getType() == Attachment::ATTACH_SWATTER) + { + int r = rand() % 4; + if (r < 3) + m_kart->setPowerup(PowerupManager::POWERUP_BUBBLEGUM, 1); + else + m_kart->setPowerup(PowerupManager::POWERUP_BOWLING, 1); + } + else + { + int r = rand() % 5; + if (r == 0 || r == 1) + m_kart->setPowerup(PowerupManager::POWERUP_BUBBLEGUM, 1); + else if (r == 2 || r == 3) + m_kart->setPowerup(PowerupManager::POWERUP_SWATTER, 1); + else + m_kart->setPowerup(PowerupManager::POWERUP_BOWLING, 1); + } + } + } + // Having a non-moving AI can be useful for debugging, e.g. aiming // or slipstreaming. #undef AI_DOES_NOT_MOVE_FOR_DEBUGGING @@ -985,6 +1013,25 @@ void SkiddingAI::handleItems(const float dt) return; m_time_since_last_shot += dt; + + if (m_superpower == RaceManager::SUPERPOWER_NOLOK_BOSS) + { + m_controls->m_look_back = (m_kart->getPowerup()->getType() == PowerupManager::POWERUP_BOWLING); + + if( m_time_since_last_shot > 3.5f ) + { + m_controls->m_fire = true; + if (m_kart->getPowerup()->getType() == PowerupManager::POWERUP_SWATTER) + m_time_since_last_shot = 3.5f; + else + m_time_since_last_shot = (rand() % 1000) / 1000.0f * 3.0f - 1.50f; // to make things less predictable :) + } + else + { + m_controls->m_fire = false; + } + return; + } // Tactic 1: wait ten seconds, then use item // ----------------------------------------- diff --git a/src/karts/controller/skidding_ai.hpp b/src/karts/controller/skidding_ai.hpp index 8a8bc6c7c..2b000113d 100644 --- a/src/karts/controller/skidding_ai.hpp +++ b/src/karts/controller/skidding_ai.hpp @@ -22,6 +22,7 @@ #define HEADER_SKIDDING_AI__HPP #include "karts/controller/ai_base_controller.hpp" +#include "race/race_manager.hpp" #include "tracks/graph_node.hpp" class LinearWorld; @@ -69,6 +70,8 @@ private: void clear() {m_road = false; m_kart = -1;} } m_crashes; + RaceManager::AISuperPower m_superpower; + /*Difficulty handling variables*/ /** Chance of a false start. */ float m_false_start_probability; diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 237a34a76..392241275 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -57,6 +57,7 @@ RaceManager::RaceManager() m_difficulty = RD_HARD; m_major_mode = MAJOR_MODE_SINGLE; m_minor_mode = MINOR_MODE_NORMAL_RACE; + m_ai_superpower = SUPERPOWER_NONE; m_track_number = 0; m_coin_target = 0; m_started_from_overworld = false; diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index 913c5f64b..dc3305065 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -108,6 +108,13 @@ public: MINOR_MODE_CUTSCENE = BATTLE_ARENA(1) }; + + enum AISuperPower + { + SUPERPOWER_NONE = 0, + SUPERPOWER_NOLOK_BOSS = 1 + }; + /** Returns a string identifier for each minor race mode. * \param mode Minor race mode. */ @@ -268,6 +275,8 @@ private: /** If set, specifies which kart to use for AI(s) */ std::string m_ai_kart_override; + AISuperPower m_ai_superpower; + /** The list of AI karts to use. This is stored here so that the * same list of AIs is used for all tracks of a GP. */ std::vector m_ai_kart_list; @@ -317,6 +326,10 @@ public: void setAIKartOverride(const std::string& kart) { m_ai_kart_override = kart; } + void setAISuperPower(AISuperPower superpower) { m_ai_superpower = superpower; } + + AISuperPower getAISuperPower() const { return m_ai_superpower; } + /** In case of non GP mode set the track to use. * \param track Pointer to the track to use. */ @@ -339,7 +352,9 @@ public: { m_major_mode = mode; } void setMinorMode(MinorRaceModeType mode) { m_minor_mode = mode; } - void setNumKarts(int num) { m_num_karts = num; m_ai_kart_override = ""; } + void setNumKarts(int num) { m_num_karts = num; + m_ai_kart_override = ""; + m_ai_superpower = SUPERPOWER_NONE;} void setCoinTarget(int num) { m_coin_target = num; } /** \} */