SuperTuxKart
Loading...
Searching...
No Matches
controller.hpp
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>
22using namespace irr;
23
25
32#include "input/input.hpp"
33#include "states_screens/state_manager.hpp"
34
35class AbstractKart;
36class BareNetworString;
37class ItemState;
38class KartControl;
39class Material;
40
46{
47private:
48
49protected:
52
56
58 std::string m_controller_name;
59
60public:
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;
74 virtual bool isLocalPlayerController () const = 0;
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 virtual void rumble(float strength_low, float strength_high, uint16_t duration) {}
83 // ---------------------------------------------------------------------------
85 virtual void setControllerName(const std::string &name)
86 { m_controller_name = name; }
87 // ---------------------------------------------------------------------------
89 const std::string &getControllerName() const { return m_controller_name; }
90 // ------------------------------------------------------------------------
92 virtual bool action(PlayerAction action, int value, bool dry_run=false) = 0;
93 // ------------------------------------------------------------------------
96 virtual void newLap(int lap) = 0;
97 // ------------------------------------------------------------------------
98 virtual void skidBonusTriggered() = 0;
99 // ------------------------------------------------------------------------
101 virtual void finishedRace(float time) = 0;
102 // ------------------------------------------------------------------------
104 virtual KartControl* getControls() { return m_controls; }
105 // ------------------------------------------------------------------------
106 void setControls(KartControl* kc) { m_controls = kc; }
107 // ------------------------------------------------------------------------
109 virtual bool canGetAchievements () const { return false; }
110 // ------------------------------------------------------------------------
114 virtual core::stringw getName(bool include_handicap_string = true) const;
115 // ------------------------------------------------------------------------
117 AbstractKart *getKart() const { return m_kart; }
118}; // Controller
119
120#endif
121
122/* EOF */
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
This is the base class for kart controller - that can be a player or a a robot.
Definition: controller.hpp:46
std::string m_controller_name
The name of the controller, mainly used for debugging purposes.
Definition: controller.hpp:58
virtual void finishedRace(float time)=0
Called whan this controller's kart finishes the last lap.
virtual bool isLocalPlayerController() const =0
This function checks if this is a local player.
AbstractKart * getKart() const
Returns the kart controlled by this controller.
Definition: controller.hpp:117
virtual void newLap(int lap)=0
Callback whenever a new lap is triggered.
KartControl * m_controls
A pointer to the main controller, from which the kart takes it commands.
Definition: controller.hpp:55
virtual KartControl * getControls()
Get a pointer on the kart controls.
Definition: controller.hpp:104
const std::string & getControllerName() const
Returns the name of this controller.
Definition: controller.hpp:89
virtual core::stringw getName(bool include_handicap_string=true) const
Display name of the controller.
Definition: controller.cpp:39
AbstractKart * m_kart
Pointer to the kart that is controlled by this controller.
Definition: controller.hpp:51
virtual void setControllerName(const std::string &name)
Sets the controller name for this controller.
Definition: controller.hpp:85
virtual bool action(PlayerAction action, int value, bool dry_run=false)=0
Default: ignore actions.
virtual bool isPlayerController() const =0
This function checks if this player is not an AI, i.e.
virtual bool canGetAchievements() const
Only local players can get achievements.
Definition: controller.hpp:109
Contains the state information of an item, i.e.
Definition: item.hpp:53
Definition: kart_control.hpp:30
Definition: material.hpp:48
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:117