File: game_controller.h

package info (click to toggle)
widelands 1:19+repack-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 370,608 kB
  • ctags: 20,609
  • sloc: cpp: 108,404; ansic: 18,695; python: 5,155; sh: 487; xml: 460; makefile: 233
file content (113 lines) | stat: -rw-r--r-- 3,143 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (C) 2008-2011, 2013, 2015-2016 by the Widelands Development Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#ifndef WL_LOGIC_GAME_CONTROLLER_H
#define WL_LOGIC_GAME_CONTROLLER_H

#include <string>

#include "logic/widelands.h"

namespace Widelands {
class Game;
class PlayerCommand;
enum class PlayerEndResult : uint8_t;
}

/**
 * A game controller implements the policies surrounding the actual
 * game simulation. For example, the GameController decides where
 * player commands go and how fast the simulation runs.
 *
 * The idea is to empty the current \ref Game class from singleplayer
 * vs. multiplayer vs. replay issues and have a \ref GameController
 * handle all that.
 */
class GameController {
public:
	enum class GameType : uint8_t {
		SINGLEPLAYER = 1,  // we don't want SINGLEPLAYER just because a value is empty
		NETCLIENT,
		NETHOST,
		REPLAY
	};

	virtual ~GameController() {
	}

	virtual void think() = 0;
	virtual void send_player_command(Widelands::PlayerCommand&) = 0;
	virtual int32_t get_frametime() = 0;
	virtual GameType get_game_type() = 0;

	/**
	 * \return the effective speed, in milliseconds per second,
	 * that the game is running at.
	 */
	virtual uint32_t real_speed() = 0;

	/**
	 * \return the speed that the local player wants the game to run at.
	 */
	virtual uint32_t desired_speed() = 0;

	/**
	 * Indicate to the game controller the speed (in milliseconds per second)
	 * that the local player wants the game to run at.
	 */
	virtual void set_desired_speed(uint32_t speed) = 0;

	/**
	 * Whether the game is paused.
	 */
	virtual bool is_paused() = 0;

	/**
	 * Whether the game is stopped.
	 */
	bool is_paused_or_zero_speed() {
		return is_paused() || real_speed() == 0;
	}

	/**
	 * Sets whether the game is paused.
	 */
	virtual void set_paused(const bool paused) = 0;

	/**
	 * Toggle pause state (convenience function)
	 */
	void toggle_paused() {
		set_paused(!is_paused());
	}

	/**
	 * Report a player result once he has left the game. This may be done through lua
	 * by the win_condition scripts.
	 * \param player : the player idx;
	 * \param result : the player result
	 * \param info : The info string (\see \struct PlayerEndStatus)
	 */
	virtual void report_result(uint8_t /* player */,
	                           Widelands::PlayerEndResult /*result*/,
	                           const std::string& /* info */) {
	}
};

#endif  // end of include guard: WL_LOGIC_GAME_CONTROLLER_H