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

0001 // Copyright (c) 2002 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 "estate.h"
0018 #include "player.h"
0019 
0020 Estate::Estate(int estateId)
0021     : QObject()
0022     , m_changed(false)
0023     , m_id(estateId)
0024     , m_owner(nullptr)
0025     , m_estateGroup(nullptr)
0026     , m_houses(0)
0027     , m_price(0)
0028     , m_housePrice(0)
0029     , m_houseSellPrice(0)
0030     , m_mortgagePrice(0)
0031     , m_unmortgagePrice(0)
0032     , m_money(0)
0033     , m_canBeOwned(false)
0034     , m_canBuyHouses(false)
0035     , m_canSellHouses(false)
0036     , m_isMortgaged(false)
0037     , m_canToggleMortgage(false)
0038 {
0039 }
0040 
0041 void Estate::setEstateGroup(EstateGroup *estateGroup)
0042 {
0043     if (m_estateGroup != estateGroup)
0044     {
0045         m_estateGroup = estateGroup;
0046         m_changed = true;
0047     }
0048 }
0049 
0050 void Estate::setOwner(Player *player)
0051 {
0052     if (m_owner != player)
0053     {
0054         m_owner = player;
0055         m_changed = true;
0056     }
0057 }
0058 bool Estate::isOwned() const
0059 {
0060     if (m_owner)
0061         return true;
0062     else
0063         return false;
0064 }
0065 
0066 bool Estate::isOwnedBySelf() const
0067 {
0068     if (m_owner && m_owner->isSelf())
0069         return true;
0070     else
0071         return false;
0072 }
0073 
0074 void Estate::setHouses(unsigned int houses)
0075 {
0076     if (m_houses != houses)
0077     {
0078         m_houses = houses;
0079         m_changed = true;
0080     }
0081 }
0082 
0083 void Estate::setName(const QString& name)
0084 {
0085     if (m_name != name)
0086     {
0087         m_name = name;
0088         m_changed = true;
0089     }
0090 }
0091 
0092 QString Estate::name() const
0093 {
0094     return m_name;
0095 }
0096 
0097 void Estate::setColor(QColor color)
0098 {
0099     if (m_color != color)
0100     {
0101         m_color = color;
0102         m_changed = true;
0103     }
0104 }
0105 
0106 void Estate::setBgColor(QColor color)
0107 {
0108     if (m_bgColor != color)
0109     {
0110         m_bgColor = color;
0111         m_changed = true;
0112     }
0113 }
0114 
0115 void Estate::setCanBeOwned(bool canBeOwned)
0116 {
0117     if (m_canBeOwned != canBeOwned)
0118     {
0119         m_canBeOwned = canBeOwned;
0120         m_changed = true;
0121     }
0122 }
0123 
0124 void Estate::setCanBuyHouses(bool canBuyHouses)
0125 {
0126     if (m_canBuyHouses != canBuyHouses)
0127     {
0128         m_canBuyHouses = canBuyHouses;
0129         m_changed = true;
0130     }
0131 }
0132 
0133 void Estate::setCanSellHouses(bool canSellHouses)
0134 {
0135     if (m_canSellHouses != canSellHouses)
0136     {
0137         m_canSellHouses = canSellHouses;
0138         m_changed = true;
0139     }
0140 }
0141 
0142 void Estate::setHousePrice(unsigned int housePrice)
0143 {
0144     if (m_housePrice != housePrice)
0145     {
0146         m_housePrice = housePrice;
0147         m_changed = true;
0148     }
0149 }
0150 
0151 void Estate::setHouseSellPrice(unsigned int houseSellPrice)
0152 {
0153     if (m_houseSellPrice != houseSellPrice)
0154     {
0155         m_houseSellPrice = houseSellPrice;
0156         m_changed = true;
0157     }
0158 }
0159 
0160 void Estate::setIsMortgaged(bool isMortgaged)
0161 {
0162     if (m_isMortgaged != isMortgaged)
0163     {
0164         m_isMortgaged = isMortgaged;
0165         m_changed = true;
0166     }
0167 }
0168 
0169 void Estate::setCanToggleMortgage(bool canToggleMortgage)
0170 {
0171     if (m_canToggleMortgage != canToggleMortgage)
0172     {
0173         m_canToggleMortgage = canToggleMortgage;
0174         m_changed = true;
0175     }
0176 }
0177 
0178 void Estate::setMortgagePrice(unsigned int mortgagePrice)
0179 {
0180     if (m_mortgagePrice != mortgagePrice)
0181     {
0182         m_mortgagePrice = mortgagePrice;
0183         m_changed = true;
0184     }
0185 }
0186 
0187 void Estate::setUnmortgagePrice(unsigned int unmortgagePrice)
0188 {
0189     if (m_unmortgagePrice != unmortgagePrice)
0190     {
0191         m_unmortgagePrice = unmortgagePrice;
0192         m_changed = true;
0193     }
0194 }
0195 
0196 void Estate::setPrice(unsigned int price)
0197 {
0198     if (m_price != price)
0199     {
0200         m_price = price;
0201         m_changed = true;
0202     }
0203 }
0204 
0205 void Estate::setMoney(int money)
0206 {
0207     if (m_money != money)
0208     {
0209         m_money = money;
0210         m_changed = true;
0211     }
0212 }
0213 
0214 int Estate::money() const
0215 {
0216     return m_money;
0217 }
0218 
0219 void Estate::setIcon(const QString &icon)
0220 {
0221     if (m_icon != icon)
0222     {
0223         m_icon = icon;
0224         m_changed = true;
0225     }
0226 }
0227 
0228 void Estate::update(bool force)
0229 {
0230     if (m_changed || force)
0231     {
0232         Q_EMIT changed();
0233         m_changed = false;
0234     }
0235 }
0236 
0237 #include "moc_estate.cpp"