SuperTuxKart
Loading...
Searching...
No Matches
ghost_controller.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2016 SuperTuxKart-Team
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_GHOST_CONTROLLER_HPP
20#define HEADER_GHOST_CONTROLLER_HPP
21
22#include "karts/controller/controller.hpp"
23#include "states_screens/state_manager.hpp"
24
25#include <vector>
26
31{
32private:
35 unsigned int m_current_index;
36
39
41 core::stringw m_display_name;
42
44 std::vector<float> m_all_times;
45
46public:
47 GhostController(AbstractKart *kart, core::stringw display_name);
48 virtual ~GhostController() {};
49 virtual void reset() OVERRIDE;
50 virtual void update (int ticks) OVERRIDE;
51 virtual bool disableSlipstreamBonus() const OVERRIDE { return true; }
52 virtual void crashed(const Material *m) OVERRIDE {}
53 virtual void crashed(const AbstractKart *k) OVERRIDE {}
54 virtual void handleZipper(bool play_sound) OVERRIDE {}
55 virtual void finishedRace(float time) OVERRIDE {}
56 virtual void collectedItem(const ItemState &item,
57 float previous_energy=0) OVERRIDE {}
58 virtual void setPosition(int p) OVERRIDE {}
59 virtual bool isPlayerController() const OVERRIDE { return false; }
60 virtual bool isLocalPlayerController() const OVERRIDE { return false; }
61 virtual bool action(PlayerAction action, int value,
62 bool dry_run=false) OVERRIDE;
63 virtual void skidBonusTriggered() OVERRIDE {}
64 virtual void newLap(int lap) OVERRIDE {}
65 virtual bool saveState(BareNetworkString *buffer) const OVERRIDE
66 { return false; }
67 virtual void rewindTo(BareNetworkString *buffer) OVERRIDE {}
68
69 void addReplayTime(float time);
70 // ------------------------------------------------------------------------
71 bool isReplayEnd() const
72 { return m_current_index + 1 >= m_all_times.size(); }
73 // ------------------------------------------------------------------------
74 float getReplayDelta() const
75 {
76 assert(m_current_index < m_all_times.size());
79 }
80 // ------------------------------------------------------------------------
81 unsigned int getCurrentReplayIndex() const
82 { return m_current_index; }
83
84 // ------------------------------------------------------------------------
85 float getTimeAtIndex(unsigned int index) const
86 {
87 assert(index < m_all_times.size());
88 return m_all_times[index];
89 }
90
91 // ------------------------------------------------------------------------
93 core::stringw getName(bool include_handicap_string = true) const OVERRIDE
94 {
95 return m_display_name.empty() ?
96 Controller::getName(include_handicap_string) : m_display_name;
97 }
98}; // GhostController
99
100#endif
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
virtual core::stringw getName(bool include_handicap_string=true) const
Display name of the controller.
Definition: controller.cpp:39
A class for Ghost controller.
Definition: ghost_controller.hpp:31
virtual void newLap(int lap) OVERRIDE
Callback whenever a new lap is triggered.
Definition: ghost_controller.hpp:64
virtual bool isPlayerController() const OVERRIDE
This function checks if this player is not an AI, i.e.
Definition: ghost_controller.hpp:59
virtual bool isLocalPlayerController() const OVERRIDE
This function checks if this is a local player.
Definition: ghost_controller.hpp:60
virtual void finishedRace(float time) OVERRIDE
Called whan this controller's kart finishes the last lap.
Definition: ghost_controller.hpp:55
std::vector< float > m_all_times
The list of the times at which the events of kart were reached.
Definition: ghost_controller.hpp:44
core::stringw getName(bool include_handicap_string=true) const OVERRIDE
Return the display name; if not set, use default display name (kart name)
Definition: ghost_controller.hpp:93
float m_current_time
The current world time.
Definition: ghost_controller.hpp:38
virtual bool action(PlayerAction action, int value, bool dry_run=false) OVERRIDE
Default: ignore actions.
Definition: ghost_controller.cpp:85
core::stringw m_display_name
Player name of the ghost kart.
Definition: ghost_controller.hpp:41
unsigned int m_current_index
Pointer to the last index in m_all_times that is smaller than the current world time.
Definition: ghost_controller.hpp:35
Contains the state information of an item, i.e.
Definition: item.hpp:53
Definition: material.hpp:48
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:117