File: game.h

package info (click to toggle)
monopd 0.9.3-4.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 788 kB
  • ctags: 575
  • sloc: cpp: 5,666; sh: 712; makefile: 27
file content (196 lines) | stat: -rw-r--r-- 7,451 bytes parent folder | download | duplicates (4)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright (c) 2001-2004 Rob Kaper <cap@capsi.com>,
//               2001 Erik Bourget <ebourg@cs.mcgill.ca>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation.
//
// 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; see the file COPYING.  If not, write to
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

#ifndef MONOP_GAME_H
#define MONOP_GAME_H

#include <vector>
#include <string>

#include "gameobject.h"

class Auction;
class Card;
class CardGroup;
class Debt;
class Estate;
class EstateGroup;
class Player;
class Trade;

class Game : public GameObject
{
	public:
		Game(int id);
		virtual ~Game();

		enum Status { Config, Init, Run, End };

		void ioWrite(const char *data, ...);
		void ioWrite(const std::string data);
		void ioInfo(const char *data, ...);
		void ioInfo(const std::string data);
		void ioError(const std::string data);

		void loadGameType(const std::string &gameType);

		GameObject *findConfigOption(const std::string &name);
		void editConfiguration(Player *pInput, char *data);
		void editConfig(Player *pInput, char *data);
		void start(Player *pInput);

		void setTokenLocation(Player *pInput, unsigned int estateId);
		void tokenMovementTimeout();
		unsigned int auctionTimeout();
		unsigned int clientsMoving();
		void setAllClientsMoving(Estate *estate);

		// Member management
		void setStatus(Status status) { m_status = status; }
		void setDescription(const std::string data);
		void setHouses(int _h) { m_houses = _h; }
		void setHotels(int _h) { m_hotels = _h; }
		void setCollectFines(const bool collectFines);
		void setAuctionsEnabled(const bool auctionsEnabled);
		void setDoublePassMoney(bool doublePassMoney);
		void setAlwaysShuffle(bool alwaysShuffle);
		void setUnlimitedHouses(bool unlimitedHouses);
		void setNoRentInJail(bool noRentInJail);
		void setAllowEstateSales(bool allowEstateSales);

		Status status() { return m_status; }
		const std::string statusLabel();
		Player *master() { return m_master; }
		Estate *goEstate() { return m_goEstate; }
		const std::string gameType() { return m_gameType; }
		const std::string bgColor() { return m_bgColor; }
		int houses() { return m_houses; }
		int hotels() { return m_hotels; }
		const bool isValid() { return m_isValid; }

		bool sendChildXMLUpdate(Player *pOutput, bool emptyUpdate);
		void unsetChildProperties();

		unsigned int players();
		unsigned int connectedPlayers();
		Player *addPlayer(Player *, const bool &isMaster = false, const bool &isSpectator = false);
		Player *findPlayer(int playerId);
		Player *kickPlayer(Player *player, int playerId);
		void upgradePlayer(Player *player, int playerId);
		unsigned int playerAssets(Player *player);

		void updateTurn();
		bool landPlayer(Player *pTurn, const bool directMove, const std::string &rentmath = "");
		bool giveCard(Player *player, Estate *estate, Card *card);
		void declareBankrupt(Player *player);
		void bankruptPlayer(Player *player);
		void setDisplay(Estate *estate, bool clearText, bool clearButtons, const char *data, ...);
		void sendMsgEstateUpdate(Estate *);
		void sendStatus(Player *player);
		void sendEstateList(Player *player);
		void sendEstateGroupList(Player *player);
		void sendPlayerList(Player *player, bool includeCards = false);
		void sendFullUpdate(Player *player, bool userRequest = false);

		int debts();
		void newDebtToAll(Player *from, int amount);
		Debt *newDebt(Player *from, Player *toPlayer, Estate *toEstate, int amount);
		Debt *findDebt(Player *player);
		Debt *findDebtByCreditor(Player *player);
		void delDebt(Debt *);
		void solveDebts(Player *player, const bool &verbose = false);
		bool solveDebt(Debt *debt);
		void enforceDebt(Player *pBroke, Debt *debt = 0);
		void newAuction(Player *pInput);
		Auction *auction();
		// Returns 0 on succesful bid, 1 on error.
		int bidInAuction(Player *pInput, char *data);
		void delAuction();

		void newTrade(Player *pInput, unsigned int playerId);
		Trade *findTrade(Player *player);
		Trade *findTrade(unsigned int tradeId);
		void delTrade(Trade *trade);
		void acceptTrade(Player *pInput, char *);
		void rejectTrade(Player *pInput, unsigned int tradeId);
		void completeTrade(Trade *trade);
		void completeAuction();

		EstateGroup *newGroup(const std::string &name);
		EstateGroup *findGroup(const std::string &name);
		unsigned int estateGroupSize(EstateGroup *estateGroup);
		Estate *newEstate(const std::string &name);
		Estate *findEstate(int estateId);
		Estate *findNextEstate(EstateGroup *group, Estate *startEstate = NULL);
		Estate *findNextJailEstate(Estate *startEstate = NULL);
		unsigned int estates() const { return m_estates.size(); }
		void setPausedForDialog(const bool paused);
		const bool pausedForDialog();
		void delEstate(Estate *);
		void transferEstate(Estate *estate, Player *player, const bool verbose = false);
		CardGroup *newCardGroup(const std::string name);
		CardGroup *findCardGroup(const std::string name);
		Card *newCard(CardGroup *cardGroup, const std::string name);
		Card *findCard(unsigned int id);
		void transferCard(Card *card, Player *player, const bool verbose = false);
		void transferObject(const enum GameObject::Type, unsigned int id, Player *player, const bool verbose = false);
		void removePlayer(Player *);
		int lowestFreeId();
		int totalAssets();
		void rollDice();
		int dice[2];

private:
	void loadConfig();
	void parseConfigEntry(Estate *es, const std::string &key, const std::string &value);
	void parseConfigEntry(Card *card, const std::string &key, const std::string &value);
	void parseConfigEntry(EstateGroup *group, const std::string &key, const std::string &value);

	void addConfigOption(const std::string &name, const std::string &description, const std::string &defaultValue, bool editable = false);
	void addConfigOption(const std::string &name, const std::string &description, int defaultValue, bool editable = false);
	void addBoolConfigOption(const std::string &name, const std::string &description, bool defaultValue, bool editable = false);
	GameObject *findConfigOption(int configId);
	void sendConfiguration(Player *player);

	/*
	 * Consider this method to be not just private, but to be very internal.
	 * It should only be called from the various addConfigOption
	 * implementations.
	 */
	GameObject *newConfigOption(const std::string &name, const std::string &description, bool editable);

	Status m_status;
	unsigned int m_nextCardGroupId, m_nextEstateId, m_nextEstateGroupId, m_nextTradeId, m_nextAuctionId;

	Player *m_master, *m_pTurn, *m_pWinner;
	Estate *m_goEstate;
	int m_houses, m_hotels, m_startMoney;
	bool m_isValid, m_pausedForDialog;

	Auction *m_auction;
	Debt *m_auctionDebt;
	std::vector<CardGroup *> m_cardGroups;
	std::vector<Debt *> m_debts;
	std::vector<EstateGroup *> m_estateGroups;
	std::vector<Estate *> m_estates;
	std::vector<Player *> m_players;
	std::vector<Trade *> m_trades;
	std::vector<GameObject *> m_configOptions;
	std::string m_gameType, m_bgColor;
};

#endif // MONOP_GAME_H