1 // SuperTuxKart - a fun racing game with go-kart 2 // Copyright (C) 2010-2015 Joerg Henrichs 3 // 4 // This program is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU General Public License 6 // as published by the Free Software Foundation; either version 3 7 // of the License, or (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 #ifndef HEADER_CONTROLLER_HPP 19 #define HEADER_CONTROLLER_HPP 20 21 #include <irrString.h> 22 using namespace irr; 23 24 class BareNetworkString; 25 26 /** 27 * \defgroup controller Karts/controller 28 * Contains kart controllers, which are either human players or AIs 29 * (this module thus contains the AIs) 30 */ 31 32 #include "input/input.hpp" 33 #include "states_screens/state_manager.hpp" 34 35 class AbstractKart; 36 class BareNetworString; 37 class ItemState; 38 class KartControl; 39 class Material; 40 41 /** This is the base class for kart controller - that can be a player 42 * or a a robot. 43 * \ingroup controller 44 */ 45 class Controller 46 { 47 private: 48 49 protected: 50 /** Pointer to the kart that is controlled by this controller. */ 51 AbstractKart *m_kart; 52 53 /** A pointer to the main controller, from which the kart takes 54 * it commands. */ 55 KartControl *m_controls; 56 57 /** The name of the controller, mainly used for debugging purposes. */ 58 std::string m_controller_name; 59 60 public: 61 Controller (AbstractKart *kart); ~Controller()62 virtual ~Controller () {}; 63 virtual void reset () = 0; 64 virtual void update (int ticks) = 0; 65 virtual void handleZipper (bool play_sound) = 0; 66 virtual void collectedItem (const ItemState &item, 67 float previous_energy=0) = 0; 68 virtual void crashed (const AbstractKart *k) = 0; 69 virtual void crashed (const Material *m) = 0; 70 virtual void setPosition (int p) = 0; 71 /** This function checks if this is a local player. A local player will get 72 * special graphical effects enabled, has a camera, and sound effects will 73 * be played with normal volume. */ 74 virtual bool isLocalPlayerController () const = 0; 75 /** This function checks if this player is not an AI, i.e. it is either a 76 * a local or a remote/networked player. This is tested e.g. by the AI for 77 * rubber-banding. */ 78 virtual bool isPlayerController () const = 0; 79 virtual bool disableSlipstreamBonus() const = 0; 80 virtual bool saveState(BareNetworkString *buffer) const = 0; 81 virtual void rewindTo(BareNetworkString *buffer) = 0; 82 83 // --------------------------------------------------------------------------- 84 /** Sets the controller name for this controller. */ setControllerName(const std::string & name)85 virtual void setControllerName(const std::string &name) 86 { m_controller_name = name; } 87 // --------------------------------------------------------------------------- 88 /** Returns the name of this controller. */ getControllerName() const89 const std::string &getControllerName() const { return m_controller_name; } 90 // ------------------------------------------------------------------------ 91 /** Default: ignore actions. Only PlayerController get them. */ 92 virtual bool action(PlayerAction action, int value, bool dry_run=false) = 0; 93 // ------------------------------------------------------------------------ 94 /** Callback whenever a new lap is triggered. Used by the AI 95 * to trigger a recomputation of the way to use. */ 96 virtual void newLap(int lap) = 0; 97 // ------------------------------------------------------------------------ 98 virtual void skidBonusTriggered() = 0; 99 // ------------------------------------------------------------------------ 100 /** Called whan this controller's kart finishes the last lap. */ 101 virtual void finishedRace(float time) = 0; 102 // ------------------------------------------------------------------------ 103 /** Get a pointer on the kart controls. */ getControls()104 virtual KartControl* getControls() { return m_controls; } 105 // ------------------------------------------------------------------------ setControls(KartControl * kc)106 void setControls(KartControl* kc) { m_controls = kc; } 107 // ------------------------------------------------------------------------ 108 /** Only local players can get achievements. */ canGetAchievements() const109 virtual bool canGetAchievements () const { return false; } 110 // ------------------------------------------------------------------------ 111 /** Display name of the controller. 112 * Defaults to kart name; overriden by controller classes 113 * (such as player controllers) to display username. */ 114 virtual core::stringw getName(bool include_handicap_string = true) const; 115 // ------------------------------------------------------------------------ 116 /** Returns the kart controlled by this controller. */ getKart() const117 AbstractKart *getKart() const { return m_kart; } 118 }; // Controller 119 120 #endif 121 122 /* EOF */ 123