1
// Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com>
3
// This program is free software; you can redistribute it and/or
4
// modify it under the terms of the GNU General Public License
5
// version 2 as published by the Free Software Foundation.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
// General Public License for more details.
12
// You should have received a copy of the GNU General Public License
13
// along with this program; see the file COPYING. If not, write to
14
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
15
// Boston, MA 02111-1307, USA.
19
#include <math++/nodes.h>
22
#include "estategroup.h"
27
EstateGroup::EstateGroup(int id, Game *game, std::string name) : GameObject(id, GameObject::Unknown, game)
29
setProperty("name", name, game);
30
m_rentMath = m_rentVar = "";
31
m_price = m_housePrice = 0;
34
void EstateGroup::setPrice(unsigned int price)
40
unsigned int EstateGroup::price()
45
void EstateGroup::setHousePrice(unsigned int housePrice)
47
if (m_housePrice != housePrice)
48
m_housePrice = housePrice;
51
unsigned int EstateGroup::housePrice()
56
void EstateGroup::setRentMath(const std::string rentMath)
58
if (m_rentMath != rentMath)
59
m_rentMath = rentMath;
62
void EstateGroup::setRentVar(const std::string rentVar)
64
if (m_rentVar != rentVar)
68
int EstateGroup::rent(Player *pLand, const std::string &rentMath)
70
std::string mathStr = rentMath.size() ? rentMath : m_rentMath;
74
Estate *estate = pLand->estate();
76
stringReplace(mathStr, "${DICE}", std::string(itoa((m_game->dice[0] + m_game->dice[1]))));
77
stringReplace(mathStr, "${GROUPOWNED}", std::string(itoa(estate->groupSize(estate->owner()))));
78
stringReplace(mathStr, "${HOUSES}", std::string(itoa(estate->getIntProperty("houses"))));
81
std::string exprStr(mathStr);
82
std::auto_ptr<math::TNode<double> >expr(math::TReader<double>::parse(exprStr));
83
std::auto_ptr<math::TNode<double> >se(math::TSimplifier<double>::simplify(expr.get()));
84
return atoi(math::TPrinter<double>::print(se.get()).c_str());
85
} catch (const math::EMath& e) {