| 1 |
// Copyright © 2001-2004 Rob Kaper <[email protected]>, |
| 2 |
// 2001 Erik Bourget <[email protected]> |
| 3 |
// 2010-2015 Sylvain Rochet <[email protected]> |
| 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 |
// version 2 as published by the Free Software Foundation. |
| 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 GNU |
| 12 |
// 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; see the file COPYING. If not, see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
#ifndef MONOP_GAME_H |
| 19 |
#define MONOP_GAME_H |
| 20 |
|
| 21 |
#include <vector> |
| 22 |
#include <string> |
| 23 |
#include <random> |
| 24 |
|
| 25 |
#include "gameobject.h" |
| 26 |
#include "display.h" |
| 27 |
|
| 28 |
class Auction; |
| 29 |
class Card; |
| 30 |
class CardGroup; |
| 31 |
class Debt; |
| 32 |
class Estate; |
| 33 |
class EstateGroup; |
| 34 |
class Player; |
| 35 |
class Trade; |
| 36 |
|
| 37 |
class Game : public GameObject |
| 38 |
{ |
| 39 |
public: |
| 40 |
Game(int id); |
| 41 |
virtual ~Game(); |
| 42 |
|
| 43 |
enum Status { Config, Init, Run, End }; |
| 44 |
|
| 45 |
std::default_random_engine m_randomEngine; |
| 46 |
|
| 47 |
void ioWrite(const char *data, ...); |
| 48 |
void ioWrite(const std::string data); |
| 49 |
void ioInfo(const char *data, ...); |
| 50 |
void ioInfo(const std::string data); |
| 51 |
void ioError(const std::string data); |
| 52 |
|
| 53 |
void loadGameType(const std::string &gameType); |
| 54 |
|
| 55 |
GameObject *findConfigOption(const std::string &name); |
| 56 |
bool getBoolConfigOption(const std::string &name); |
| 57 |
void editConfiguration(Player *pInput, char *data); |
| 58 |
void start(Player *pInput); |
| 59 |
|
| 60 |
void setTokenLocation(Player *pInput, unsigned int estateId); |
| 61 |
void tokenMovementTimeout(); |
| 62 |
unsigned int auctionTimeout(); |
| 63 |
unsigned int clientsMoving(); |
| 64 |
void setAllClientsMoving(Estate *estate); |
| 65 |
|
| 66 |
// Member management |
| 67 |
void setDescription(const std::string data); |
| 68 |
void setHouses(int _h) { m_houses = _h; } |
| 69 |
void setHotels(int _h) { m_hotels = _h; } |
| 70 |
|
| 71 |
Status status() { return m_status; } |
| 72 |
Player *master() { return m_master; } |
| 73 |
Estate *goEstate() { return m_goEstate; } |
| 74 |
const std::string gameType() { return m_gameType; } |
| 75 |
const std::string bgColor() { return m_bgColor; } |
| 76 |
int houses() { return m_houses; } |
| 77 |
int hotels() { return m_hotels; } |
| 78 |
bool isValid() { return m_isValid; } |
| 79 |
|
| 80 |
bool sendChildXMLUpdate(Player *pOutput, bool emptyUpdate); |
| 81 |
void unsetChildProperties(); |
| 82 |
|
| 83 |
int players(bool includeSpectators = false); |
| 84 |
Player *addPlayer(Player *, const bool &isSpectator = false, const bool &isFirst = false); |
| 85 |
Player *findPlayer(int playerId); |
| 86 |
Player *kickPlayer(Player *player, int playerId); |
| 87 |
void upgradePlayer(Player *player, int playerId); |
| 88 |
unsigned int playerAssets(Player *player); |
| 89 |
|
| 90 |
void updateTurn(); |
| 91 |
void landPlayer(Player *pTurn, const bool directMove, const std::string &rentmath = ""); |
| 92 |
void giveCard(Player *player, Card *card); |
| 93 |
void declareBankrupt(Player *player); |
| 94 |
void bankruptPlayer(Player *player); |
| 95 |
void sendDisplayMsg(Display *display, Player *except = NULL); |
| 96 |
void sendMsgEstateUpdate(Estate *); |
| 97 |
void sendStatus(Status status, Player *player = NULL); |
| 98 |
void sendEstateList(Player *player); |
| 99 |
void sendEstateGroupList(Player *player); |
| 100 |
void sendPlayerList(Player *player); |
| 101 |
void sendCardList(Player *pOut); |
| 102 |
void sendFullUpdate(Player *player); |
| 103 |
|
| 104 |
int debts(); |
| 105 |
void newDebtToAll(Player *from, int amount); |
| 106 |
Debt *newDebt(Player *from, Player *toPlayer, Estate *toEstate, int amount); |
| 107 |
Debt *findDebt(Player *player); |
| 108 |
Debt *findDebtByCreditor(Player *player); |
| 109 |
void delDebt(Debt *); |
| 110 |
void solveDebts(Player *player, const bool &verbose = false); |
| 111 |
void enforceDebt(Player *pBroke, Debt *debt = 0); |
| 112 |
void newAuction(Player *pInput); |
| 113 |
Auction *auction(); |
| 114 |
// Returns 0 on successful bid, 1 on error. |
| 115 |
int bidInAuction(Player *pInput, char *data); |
| 116 |
|
| 117 |
void newTrade(Player *pInput, unsigned int playerId); |
| 118 |
Trade *findTrade(Player *player); |
| 119 |
Trade *findTrade(int tradeId); |
| 120 |
void delTrade(Trade *trade); |
| 121 |
void acceptTrade(Player *pInput, char *); |
| 122 |
void rejectTrade(Player *pInput, unsigned int tradeId, const bool verbose = true); |
| 123 |
void completeTrade(Trade *trade); |
| 124 |
void abortAuction(); |
| 125 |
void completeAuction(); |
| 126 |
|
| 127 |
EstateGroup *newGroup(const std::string &name); |
| 128 |
EstateGroup *findGroup(const std::string &name); |
| 129 |
unsigned int estateGroupSize(EstateGroup *estateGroup); |
| 130 |
Estate *newEstate(const std::string &name); |
| 131 |
Estate *findEstate(int estateId); |
| 132 |
Estate *findNextEstate(EstateGroup *group, Estate *startEstate = NULL); |
| 133 |
Estate *findNextJailEstate(Estate *startEstate = NULL); |
| 134 |
unsigned int estates() const { return m_estates.size(); } |
| 135 |
void setPausedForDialog(const bool paused); |
| 136 |
bool pausedForDialog(); |
| 137 |
void transferEstate(Estate *estate, Player *player, const bool verbose = false); |
| 138 |
CardGroup *newCardGroup(const std::string name); |
| 139 |
CardGroup *findCardGroup(const std::string name); |
| 140 |
Card *newCard(CardGroup *cardGroup, const std::string name); |
| 141 |
Card *findCard(unsigned int id); |
| 142 |
void transferCard(Card *card, Player *player, const bool verbose = false); |
| 143 |
void transferObject(const enum GameObject::Type, unsigned int id, Player *player, const bool verbose = false); |
| 144 |
void removePlayer(Player *); |
| 145 |
int totalAssets(); |
| 146 |
void rollDice(); |
| 147 |
int dice[2]; |
| 148 |
|
| 149 |
private: |
| 150 |
void loadConfig(); |
| 151 |
void parseConfigEntry(Estate *es, const std::string &key, const std::string &value); |
| 152 |
void parseConfigEntry(Card *card, const std::string &key, const std::string &value); |
| 153 |
void parseConfigEntry(EstateGroup *group, const std::string &key, const std::string &value); |
| 154 |
|
| 155 |
void addConfigOption(const std::string &name, const std::string &description, const std::string &defaultValue, bool editable = false); |
| 156 |
void addConfigOption(const std::string &name, const std::string &description, int defaultValue, bool editable = false); |
| 157 |
void addBoolConfigOption(const std::string &name, const std::string &description, bool defaultValue, bool editable = false); |
| 158 |
GameObject *findConfigOption(int configId); |
| 159 |
void sendConfiguration(Player *player); |
| 160 |
|
| 161 |
/* |
| 162 |
* Consider this method to be not just private, but to be very internal. |
| 163 |
* It should only be called from the various addConfigOption |
| 164 |
* implementations. |
| 165 |
*/ |
| 166 |
GameObject *newConfigOption(const std::string &name, const std::string &description, bool editable); |
| 167 |
|
| 168 |
bool solveDebt(Debt *debt); |
| 169 |
|
| 170 |
Status m_status; |
| 171 |
unsigned int m_nextCardGroupId, m_nextEstateId, m_nextEstateGroupId, m_nextTradeId, m_nextAuctionId; |
| 172 |
|
| 173 |
Player *m_master, *m_pTurn; |
| 174 |
Estate *m_goEstate; |
| 175 |
int m_houses, m_hotels, m_startMoney; |
| 176 |
bool m_isValid, m_pausedForDialog; |
| 177 |
|
| 178 |
Auction *m_auction; |
| 179 |
Debt *m_auctionDebt; |
| 180 |
std::vector<CardGroup *> m_cardGroups; |
| 181 |
std::vector<Debt *> m_debts; |
| 182 |
std::vector<EstateGroup *> m_estateGroups; |
| 183 |
std::vector<Estate *> m_estates; |
| 184 |
std::vector<Player *> m_players; |
| 185 |
std::vector<Trade *> m_trades; |
| 186 |
std::vector<GameObject *> m_configOptions; |
| 187 |
std::string m_gameType, m_bgColor; |
| 188 |
}; |
| 189 |
|
| 190 |
#endif // MONOP_GAME_H |