File: playersmanager.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 (117 lines) | stat: -rw-r--r-- 3,120 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
114
115
116
117
/*
 * Copyright (C) 2008-2010 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_PLAYERSMANAGER_H
#define WL_LOGIC_PLAYERSMANAGER_H

#include <string>
#include <vector>

#include "logic/constants.h"
#include "logic/widelands.h"

namespace Widelands {

class EditorGameBase;
class Player;
class Player;

enum class PlayerEndResult : uint8_t {
	PLAYER_LOST = 0,
	PLAYER_WON = 1,
	PLAYER_RESIGNED = 2,
	UNDEFINED = 255
};

/**
 * Hold data once a player left the game, or on game ends.
 * Allowed values for the info string, as key=value pairs separated
 * by semi-comma (;) :
 * \e wc_name : The win condition name (string)
 * \e wc_version : The win condition version (uint8)
 * \e score : The player score (uint16)
 * \e resign_reason : The reason for resigning (forfeit, disconnection, ..) (string)
 */
struct PlayerEndStatus {
	PlayerNumber player;
	PlayerEndResult result;
	uint32_t time;
	std::string info;
};

class PlayersManager {
public:
	PlayersManager(EditorGameBase& egbase);
	virtual ~PlayersManager();

	void cleanup();

	void remove_player(PlayerNumber);

	/**
	 * Create the player structure for the given plnum.
	 * Note that AI player structures and the InteractivePlayer are created when
	 * the game starts. Similar for remote players.
	*/
	Player* add_player(PlayerNumber,
	                   uint8_t initialization_index,
	                   const std::string& tribe,
	                   const std::string& name,
	                   TeamNumber team = 0);
	Player* get_player(int32_t n) const {
		assert(1 <= n);
		assert(n <= MAX_PLAYERS);
		return players_[n - 1];
	}
	Player& player(int32_t n) const {
		assert(1 <= n);
		assert(n <= MAX_PLAYERS);
		return *players_[n - 1];
	}

	/**
	 * \return the number of players (human or ai)
	 */
	uint8_t get_number_of_players() {
		return number_of_players_;
	}

	const std::vector<PlayerEndStatus>& get_players_end_status() {
		return players_end_status_;
	}

	/**
	* Adds a new player status for a player that left the game.
	*/
	void add_player_end_status(const PlayerEndStatus& status);

	/**
	 * Changes an already existing player end status
	 */
	void set_player_end_status(const PlayerEndStatus& status);

private:
	Player* players_[MAX_PLAYERS];
	EditorGameBase& egbase_;
	uint8_t number_of_players_;
	std::vector<PlayerEndStatus> players_end_status_;
};
}

#endif  // end of include guard: WL_LOGIC_PLAYERSMANAGER_H