File indexing completed on 2024-04-14 14:31:59

0001 // Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com>
0002 //
0003 // This library is free software; you can redistribute it and/or
0004 // modify it under the terms of the GNU Lesser General Public
0005 // License version 2.1 as published by the Free Software Foundation.
0006 //
0007 // This library is distributed in the hope that it will be useful,
0008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0010 // Lesser General Public License for more details.
0011 //
0012 // You should have received a copy of the GNU Lesser General Public License
0013 // along with this library; see the file COPYING.LIB.  If not, write to
0014 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015 // Boston, MA 02110-1301, USA.
0016 
0017 #include "player.h"
0018 #include "estate.h"
0019 
0020 Player::Player(int playerId)
0021     : QObject()
0022     , m_id(playerId)
0023     , m_changed(false)
0024     , m_isSelf(false)
0025     , m_bankrupt(false)
0026     , m_hasDebt(false)
0027     , m_hasTurn(false)
0028     , m_canRoll(false)
0029     , m_canBuy(false)
0030     , m_canAuction(false)
0031     , m_canUseCard(false)
0032     , m_inJail(false)
0033     , m_spectator(false)
0034     , m_money(0)
0035     , m_game(nullptr)
0036     , m_location(nullptr)
0037     , m_destination(nullptr)
0038 {
0039 }
0040 
0041 void Player::setGame(Game *game)
0042 {
0043     if (m_game != game)
0044     {
0045         m_game = game;
0046         m_changed = true;
0047     }
0048 }
0049 
0050 Game *Player::game() const
0051 {
0052     return m_game;
0053 }
0054 
0055 void Player::setLocation(Estate *location)
0056 {
0057     if (m_location != location)
0058     {
0059         m_location = location;
0060         m_changed = true;
0061     }
0062 }
0063 
0064 void Player::setDestination(Estate *destination)
0065 {
0066     if (m_destination != destination)
0067     {
0068         m_destination = destination;
0069         m_changed = true;
0070     }
0071 }
0072 
0073 void Player::setBankrupt(bool bankrupt)
0074 {
0075     if (m_bankrupt != bankrupt)
0076     {
0077         m_bankrupt = bankrupt;
0078         m_changed = true;
0079     }
0080 }
0081 
0082 void Player::setHasDebt(bool hasDebt)
0083 {
0084     if (m_hasDebt != hasDebt)
0085     {
0086         m_hasDebt = hasDebt;
0087         m_changed = true;
0088     }
0089 }
0090 
0091 void Player::setHasTurn(bool hasTurn)
0092 {
0093     if (m_hasTurn != hasTurn)
0094     {
0095         m_hasTurn = hasTurn;
0096         m_changed = true;
0097         if (m_hasTurn && m_isSelf)
0098             Q_EMIT gainedTurn();
0099     }
0100 }
0101 
0102 void Player::setCanRoll(bool canRoll)
0103 {
0104     if (m_canRoll != canRoll)
0105     {
0106         m_canRoll = canRoll;
0107         m_changed = true;
0108     }
0109 }
0110 
0111 void Player::setCanBuy(bool canBuy)
0112 {
0113     if (m_canBuy != canBuy)
0114     {
0115         m_canBuy = canBuy;
0116         m_changed = true;
0117     }
0118 }
0119 
0120 void Player::setCanAuction(bool canAuction)
0121 {
0122     if (m_canAuction != canAuction)
0123     {
0124         m_canAuction = canAuction;
0125         m_changed = true;
0126     }
0127 }
0128 
0129 void Player::setCanUseCard(bool canUseCard)
0130 {
0131     if (m_canUseCard != canUseCard)
0132     {
0133         m_canUseCard = canUseCard;
0134         m_changed = true;
0135     }
0136 }
0137 
0138 void Player::setInJail(bool inJail)
0139 {
0140     if (m_inJail != inJail)
0141     {
0142         m_inJail = inJail;
0143         m_changed = true;
0144     }
0145 }
0146 
0147 void Player::setName(const QString &_n)
0148 {
0149     if (m_name != _n)
0150     {
0151         m_name = _n;
0152         m_changed = true;
0153     }
0154 }
0155 
0156 void Player::setHost(const QString &host)
0157 {
0158     if (m_host != host)
0159     {
0160         m_host = host;
0161         m_changed = true;
0162     }
0163 }
0164 
0165 void Player::setImage(const QString &image)
0166 {
0167     if (m_image != image)
0168     {
0169         m_image = image;
0170         m_changed = true;
0171     }
0172 }
0173 
0174 void Player::setMoney(unsigned int money)
0175 {
0176     if (m_money != money)
0177     {
0178         m_money = money;
0179         m_changed = true;
0180     }
0181 }
0182 
0183 void Player::setSpectator(bool spectator)
0184 {
0185     if (m_spectator != spectator)
0186     {
0187         m_spectator = spectator;
0188         m_changed = true;
0189     }
0190 }
0191 
0192 void Player::update(bool force)
0193 {
0194     if (m_changed || force)
0195     {
0196         Q_EMIT changed(this);
0197         m_changed = false;
0198     }
0199 }
0200 
0201 #include "moc_player.cpp"