summaryrefslogtreecommitdiffstats
path: root/atlantik/libatlantic
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /atlantik/libatlantic
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'atlantik/libatlantic')
-rw-r--r--atlantik/libatlantic/Makefile.am15
-rw-r--r--atlantik/libatlantic/atlantic_core.cpp369
-rw-r--r--atlantik/libatlantic/atlantic_core.h105
-rw-r--r--atlantik/libatlantic/auction.cpp56
-rw-r--r--atlantik/libatlantic/auction.h57
-rw-r--r--atlantik/libatlantic/configoption.cpp99
-rw-r--r--atlantik/libatlantic/configoption.h51
-rw-r--r--atlantik/libatlantic/estate.cpp163
-rw-r--r--atlantik/libatlantic/estate.h95
-rw-r--r--atlantik/libatlantic/estategroup.cpp41
-rw-r--r--atlantik/libatlantic/estategroup.h44
-rw-r--r--atlantik/libatlantic/game.cpp130
-rw-r--r--atlantik/libatlantic/game.h62
-rw-r--r--atlantik/libatlantic/libatlantic_export.h25
-rw-r--r--atlantik/libatlantic/player.cpp183
-rw-r--r--atlantik/libatlantic/player.h84
-rw-r--r--atlantik/libatlantic/trade.cpp200
-rw-r--r--atlantik/libatlantic/trade.h152
18 files changed, 1931 insertions, 0 deletions
diff --git a/atlantik/libatlantic/Makefile.am b/atlantik/libatlantic/Makefile.am
new file mode 100644
index 00000000..314a0215
--- /dev/null
+++ b/atlantik/libatlantic/Makefile.am
@@ -0,0 +1,15 @@
+KDE_OPTIONS = qtonly
+
+INCLUDES = $(all_includes)
+lib_LTLIBRARIES = libatlantic.la
+libatlantic_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -no-undefined -version-info 3:0:2
+libatlantic_la_LIBADD = $(LIB_QT)
+
+libatlantic_la_SOURCES = atlantic_core.cpp auction.cpp configoption.cpp estate.cpp \
+ estategroup.cpp game.cpp player.cpp trade.cpp
+
+libatlanticincludedir = $(includedir)/atlantic
+libatlanticinclude_HEADERS = atlantic_core.h auction.h configoption.h estate.h \
+ estategroup.h game.h player.h trade.h libatlantic_export.h
+
+METASOURCES = AUTO
diff --git a/atlantik/libatlantic/atlantic_core.cpp b/atlantik/libatlantic/atlantic_core.cpp
new file mode 100644
index 00000000..39e1200e
--- /dev/null
+++ b/atlantik/libatlantic/atlantic_core.cpp
@@ -0,0 +1,369 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <iostream>
+
+#include "atlantic_core.h"
+
+#include "auction.h"
+#include "configoption.h"
+#include "estate.h"
+#include "estategroup.h"
+#include "game.h"
+#include "player.h"
+#include "trade.h"
+
+AtlanticCore::AtlanticCore(QObject *parent, const char *name) : QObject(parent, name)
+{
+ m_playerSelf = 0;
+}
+
+void AtlanticCore::reset(bool deletePermanents)
+{
+ m_auctions.setAutoDelete(true);
+ m_auctions.clear();
+ m_auctions.setAutoDelete(false);
+ m_estates.setAutoDelete(true);
+ m_estates.clear();
+ m_estates.setAutoDelete(false);
+ m_estateGroups.setAutoDelete(true);
+ m_estateGroups.clear();
+ m_estateGroups.setAutoDelete(false);
+ m_configOptions.setAutoDelete(true);
+ m_configOptions.clear();
+ m_configOptions.setAutoDelete(false);
+
+ Trade *trade = 0;
+ for (QPtrListIterator<Trade> it(m_trades); (trade = *it) ; ++it)
+ {
+ emit removeGUI(trade);
+ trade->deleteLater();
+ }
+ m_trades.clear();
+
+ Player *player = 0;
+ for (QPtrListIterator<Player> it(m_players); (player = *it) ; ++it)
+ {
+ if (deletePermanents)
+ {
+ emit removeGUI(player);
+ player->deleteLater();
+ }
+ else
+ {
+ player->setLocation(0);
+ player->setDestination(0);
+ }
+ }
+ if (deletePermanents)
+ {
+ m_players.clear();
+ m_playerSelf = 0;
+
+ Game *game = 0;
+ for (QPtrListIterator<Game> it(m_games); (game = *it) ; ++it)
+ {
+ emit removeGUI(game);
+ game->deleteLater();
+ }
+ m_games.clear();
+ }
+}
+
+bool AtlanticCore::selfIsMaster() const
+{
+ return (m_playerSelf && m_playerSelf->game() && m_playerSelf->game()->master() == m_playerSelf);
+}
+
+void AtlanticCore::setPlayerSelf(Player *player)
+{
+ m_playerSelf = player;
+}
+
+Player *AtlanticCore::playerSelf()
+{
+ return m_playerSelf;
+}
+
+QPtrList<Player> AtlanticCore::players()
+{
+ return m_players;
+}
+
+Player *AtlanticCore::newPlayer(int playerId, const bool &playerSelf)
+{
+ Player *player = new Player(playerId);
+ m_players.append(player);
+
+ if (playerSelf)
+ {
+ player->setIsSelf(playerSelf);
+ m_playerSelf = player;
+ }
+
+ emit createGUI(player);
+
+ return player;
+}
+
+Player *AtlanticCore::findPlayer(int playerId)
+{
+ Player *player = 0;
+ for (QPtrListIterator<Player> it(m_players); (player = *it) ; ++it)
+ if (player->id() == playerId)
+ return player;
+
+ return 0;
+}
+
+void AtlanticCore::removePlayer(Player *player)
+{
+ m_players.remove(player);
+ emit removeGUI(player);
+ player->deleteLater();
+}
+
+QPtrList<Game> AtlanticCore::games()
+{
+ return m_games;
+}
+
+Game *AtlanticCore::newGame(int gameId, const QString &type)
+{
+ Game *game = new Game(gameId);
+ m_games.append(game);
+
+ if ( !type.isNull() )
+ game->setType(type);
+
+ emit createGUI(game);
+
+ return game;
+}
+
+Game *AtlanticCore::findGame(const QString &type)
+{
+ Game *game = 0;
+ for (QPtrListIterator<Game> it(m_games); (game = *it) ; ++it)
+ if (game->id() == -1 && game->type() == type)
+ return game;
+
+ return 0;
+}
+
+Game *AtlanticCore::findGame(int gameId)
+{
+ if (gameId == -1)
+ return 0;
+
+ Game *game = 0;
+ for (QPtrListIterator<Game> it(m_games); (game = *it) ; ++it)
+ if (game->id() == gameId)
+ return game;
+
+ return 0;
+}
+
+Game *AtlanticCore::gameSelf()
+{
+ return( m_playerSelf ? m_playerSelf->game() : 0 );
+}
+
+void AtlanticCore::removeGame(Game *game)
+{
+ m_games.remove(game);
+ emit removeGUI(game);
+ game->deleteLater();
+}
+
+void AtlanticCore::emitGames()
+{
+ for (QPtrListIterator<Game> it(m_games); (*it) ; ++it)
+ emit createGUI( (*it) );
+}
+
+QPtrList<Estate> AtlanticCore::estates()
+{
+ return m_estates;
+}
+
+Estate *AtlanticCore::newEstate(int estateId)
+{
+ Estate *estate = new Estate(estateId);
+ m_estates.append(estate);
+ return estate;
+}
+
+Estate *AtlanticCore::findEstate(int estateId)
+{
+ Estate *estate = 0;
+ for (QPtrListIterator<Estate> it(m_estates); (estate = *it) ; ++it)
+ if (estate->id() == estateId)
+ return estate;
+
+ return 0;
+}
+
+Estate *AtlanticCore::estateAfter(Estate *estate)
+{
+ Estate *eFirst = 0, *eTmp = 0;
+ bool useNext = false;
+ for (QPtrListIterator<Estate> it(m_estates); (eTmp = *it) ; ++it)
+ {
+ if (!eFirst)
+ eFirst = eTmp;
+ if (eTmp == estate)
+ useNext = true;
+ else if (useNext)
+ return eTmp;
+ }
+ return eFirst;
+}
+
+QPtrList<EstateGroup> AtlanticCore::estateGroups()
+{
+ return m_estateGroups;
+}
+
+EstateGroup *AtlanticCore::newEstateGroup(int groupId)
+{
+ EstateGroup *estateGroup = new EstateGroup(groupId);
+ m_estateGroups.append(estateGroup);
+ return estateGroup;
+}
+
+EstateGroup *AtlanticCore::findEstateGroup(int groupId)
+{
+ EstateGroup *estateGroup = 0;
+ for (QPtrListIterator<EstateGroup> it(m_estateGroups); (estateGroup = *it) ; ++it)
+ if (estateGroup->id() == groupId)
+ return estateGroup;
+
+ return 0;
+}
+
+QPtrList<Trade> AtlanticCore::trades()
+{
+ return m_trades;
+}
+
+Trade *AtlanticCore::newTrade(int tradeId)
+{
+ Trade *trade = new Trade(tradeId);
+ m_trades.append(trade);
+
+ emit createGUI(trade);
+
+ return trade;
+}
+
+Trade *AtlanticCore::findTrade(int tradeId)
+{
+ Trade *trade = 0;
+ for (QPtrListIterator<Trade> it(m_trades); (trade = *it) ; ++it)
+ if (trade->tradeId() == tradeId)
+ return trade;
+
+ return 0;
+}
+
+void AtlanticCore::removeTrade(Trade *trade)
+{
+ m_trades.remove(trade);
+ emit removeGUI(trade);
+ trade->deleteLater();
+}
+
+QPtrList<Auction> AtlanticCore::auctions()
+{
+ return m_auctions;
+}
+
+Auction *AtlanticCore::newAuction(int auctionId, Estate *estate)
+{
+ Auction *auction = new Auction(auctionId, estate);
+ m_auctions.append(auction);
+ return auction;
+}
+
+void AtlanticCore::delAuction(Auction *auction)
+{
+ m_auctions.remove(auction);
+ delete auction;
+}
+
+ConfigOption *AtlanticCore::newConfigOption(int configId)
+{
+ ConfigOption *configOption = new ConfigOption(configId);
+ m_configOptions.append(configOption);
+
+ emit createGUI(configOption);
+
+ return configOption;
+}
+
+void AtlanticCore::removeConfigOption(ConfigOption *configOption)
+{
+ m_configOptions.remove(configOption);
+ emit removeGUI(configOption);
+ configOption->deleteLater();
+}
+
+ConfigOption *AtlanticCore::findConfigOption(int configId)
+{
+ ConfigOption *configOption = 0;
+ for (QPtrListIterator<ConfigOption> it(m_configOptions); (configOption = *it) ; ++it)
+ if (configOption->id() == configId)
+ return configOption;
+
+ return 0;
+}
+
+void AtlanticCore::printDebug()
+{
+ Player *player = 0;
+ for (QPtrListIterator<Player> it(m_players); (player = *it) ; ++it)
+ if (player == m_playerSelf)
+ std::cout << "PS: " << player->name().latin1() << ", game " << QString::number(player->game() ? player->game()->id() : -1).latin1() << std::endl;
+ else
+ std::cout << " P: " << player->name().latin1() << ", game " << QString::number(player->game() ? player->game()->id() : -1).latin1() << std::endl;
+
+ Game *game = 0;
+ for (QPtrListIterator<Game> it(m_games); (game = *it) ; ++it)
+ std::cout << " G: " << QString::number(game->id()).latin1() << ", master: " << QString::number(game->master() ? game->master()->id() : -1 ).latin1() << std::endl;
+
+ Estate *estate = 0;
+ for (QPtrListIterator<Estate> it(m_estates); (estate = *it) ; ++it)
+ std::cout << " E: " << estate->name().latin1() << std::endl;
+
+ EstateGroup *estateGroup = 0;
+ for (QPtrListIterator<EstateGroup> it(m_estateGroups); (estateGroup = *it) ; ++it)
+ std::cout << "EG: " << estateGroup->name().latin1() << std::endl;
+
+ Auction *auction = 0;
+ for (QPtrListIterator<Auction> it(m_auctions); (auction = *it) ; ++it)
+ std::cout << " A: " << QString::number(auction->auctionId()).latin1() << std::endl;
+
+ Trade *trade = 0;
+ for (QPtrListIterator<Trade> it(m_trades); (trade = *it) ; ++it)
+ std::cout << " T: " << QString::number(trade->tradeId()).latin1() << std::endl;
+
+ ConfigOption *configOption = 0;
+ for (QPtrListIterator<ConfigOption> it(m_configOptions); (configOption = *it) ; ++it)
+ std::cout << "CO:" << QString::number(configOption->id()).latin1() << " " << configOption->name().latin1() << " " << configOption->value().latin1() << std::endl;
+}
+
+#include "atlantic_core.moc"
diff --git a/atlantik/libatlantic/atlantic_core.h b/atlantik/libatlantic/atlantic_core.h
new file mode 100644
index 00000000..bca5b783
--- /dev/null
+++ b/atlantik/libatlantic/atlantic_core.h
@@ -0,0 +1,105 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_CORE_H
+#define LIBATLANTIC_CORE_H
+
+#include <qobject.h>
+#include <qptrlist.h>
+
+#include "libatlantic_export.h"
+
+class Player;
+class ConfigOption;
+class Estate;
+class EstateGroup;
+class Game;
+class Trade;
+class Auction;
+
+class LIBATLANTIC_EXPORT AtlanticCore : public QObject
+{
+Q_OBJECT
+
+public:
+ AtlanticCore(QObject *parent, const char *name);
+
+ void reset(bool deletePermanents = false);
+
+ bool selfIsMaster() const;
+
+ void setPlayerSelf(Player *player);
+ Player *playerSelf();
+
+ QPtrList<Player> players();
+ Player *newPlayer(int playerId, const bool &playerSelf = false);
+ Player *findPlayer(int playerId);
+ void removePlayer(Player *player);
+
+ QPtrList<Game> games();
+ Game *newGame(int gameId, const QString &type = QString::null);
+ Game *findGame(const QString &type); // finds game types
+ Game *findGame(int gameId); // finds actual games
+ Game *gameSelf();
+ void removeGame(Game *game);
+ void emitGames();
+
+ QPtrList<Estate> estates();
+ Estate *newEstate(int estateId);
+ Estate *findEstate(int estateId);
+ Estate *estateAfter(Estate *estate);
+
+ QPtrList<EstateGroup> estateGroups();
+ EstateGroup *newEstateGroup(int groupId);
+ EstateGroup *findEstateGroup(int groupId);
+
+ QPtrList<Trade> trades();
+ Trade *newTrade(int tradeId);
+ Trade *findTrade(int tradeId);
+ void removeTrade(Trade *trade);
+
+ QPtrList<Auction> auctions();
+ Auction *newAuction(int auctionId, Estate *estate);
+ void delAuction(Auction *auction);
+
+ ConfigOption *newConfigOption(int configId);
+ void removeConfigOption(ConfigOption *configOption);
+ ConfigOption *findConfigOption(int configId);
+
+ void printDebug();
+
+signals:
+ void createGUI(Player *player);
+ void removeGUI(Player *player);
+ void createGUI(Game *game);
+ void removeGUI(Game *game);
+ void createGUI(Trade *trade);
+ void removeGUI(Trade *trade);
+ void createGUI(ConfigOption *configOption);
+ void removeGUI(ConfigOption *configOption);
+
+private:
+ Player *m_playerSelf;
+ QPtrList<Player> m_players;
+ QPtrList<Game> m_games;
+ QPtrList<Estate> m_estates;
+ QPtrList<EstateGroup> m_estateGroups;
+ QPtrList<Trade> m_trades;
+ QPtrList<Auction> m_auctions;
+ QPtrList<ConfigOption> m_configOptions;
+};
+
+#endif
diff --git a/atlantik/libatlantic/auction.cpp b/atlantik/libatlantic/auction.cpp
new file mode 100644
index 00000000..70734c4e
--- /dev/null
+++ b/atlantik/libatlantic/auction.cpp
@@ -0,0 +1,56 @@
+// Copyright (c) 2002 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include "auction.h"
+#include "auction.moc"
+#include "player.h"
+#include "estate.h"
+
+Auction::Auction(int auctionId, Estate *estate) : QObject()
+{
+ m_auctionId = auctionId;
+ m_estate = estate;
+ m_status = 0;
+ m_changed = false;
+}
+
+Auction::~Auction()
+{
+ emit completed();
+}
+
+void Auction::setStatus(int status)
+{
+ if (m_status != status)
+ {
+ m_status = status;
+ m_changed = true;
+ }
+}
+
+void Auction::newBid(Player *player, int amount)
+{
+ emit updateBid(player, amount);
+}
+
+void Auction::update(bool force)
+{
+ if (m_changed || force)
+ {
+ emit changed();
+ m_changed = false;
+ }
+}
diff --git a/atlantik/libatlantic/auction.h b/atlantik/libatlantic/auction.h
new file mode 100644
index 00000000..cc44cce5
--- /dev/null
+++ b/atlantik/libatlantic/auction.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2002 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_AUCTION_H
+#define LIBATLANTIC_AUCTION_H
+
+#include <qobject.h>
+
+#include "libatlantic_export.h"
+
+class Player;
+class Estate;
+
+class LIBATLANTIC_EXPORT Auction : public QObject
+{
+Q_OBJECT
+
+public:
+ Auction(int auctionId, Estate *estate);
+ virtual ~Auction();
+
+ int auctionId() { return m_auctionId; }
+ Estate *estate() { return m_estate; }
+
+ void setStatus(int status);
+ int status() { return m_status; }
+
+ void newBid(Player *player, int bid);
+
+ void update(bool force = false);
+
+signals:
+ void changed();
+ void completed();
+ void bid(Auction *auction, int amount);
+ void updateBid(Player *player, int amount);
+
+private:
+ bool m_changed;
+ int m_auctionId, m_status;
+ Estate *m_estate;
+};
+
+#endif
diff --git a/atlantik/libatlantic/configoption.cpp b/atlantik/libatlantic/configoption.cpp
new file mode 100644
index 00000000..00a8eb12
--- /dev/null
+++ b/atlantik/libatlantic/configoption.cpp
@@ -0,0 +1,99 @@
+// Copyright (c) 2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include "configoption.h"
+
+ConfigOption::ConfigOption(int configId) : QObject()
+{
+ m_id = configId;
+ m_name = "";
+ m_description = "";
+ m_edit = false;
+ m_value = "";
+ m_changed = false;
+}
+
+int ConfigOption::id()
+{
+ return m_id;
+}
+
+void ConfigOption::setName(const QString &name)
+{
+ if (m_name != name)
+ {
+ m_name = name;
+ m_changed = true;
+ }
+}
+
+QString ConfigOption::name() const
+{
+ return m_name;
+}
+
+void ConfigOption::setDescription(const QString &description)
+{
+ if (m_description != description)
+ {
+ m_description = description;
+ m_changed = true;
+ }
+}
+
+QString ConfigOption::description() const
+{
+ return m_description;
+}
+
+void ConfigOption::setEdit(bool edit)
+{
+ if (m_edit != edit)
+ {
+ m_edit = edit;
+ m_changed = true;
+ }
+}
+
+bool ConfigOption::edit()
+{
+ return m_edit;
+}
+
+void ConfigOption::setValue(const QString &value)
+{
+ if (m_value != value)
+ {
+ m_value = value;
+ m_changed = true;
+ }
+}
+
+QString ConfigOption::value() const
+{
+ return m_value;
+}
+
+void ConfigOption::update(bool force)
+{
+ if (m_changed || force)
+ {
+ emit changed(this);
+ m_changed = false;
+ }
+}
+
+#include "configoption.moc"
diff --git a/atlantik/libatlantic/configoption.h b/atlantik/libatlantic/configoption.h
new file mode 100644
index 00000000..a29d6b45
--- /dev/null
+++ b/atlantik/libatlantic/configoption.h
@@ -0,0 +1,51 @@
+// Copyright (c) 2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_CONFIGOPTION_H
+#define LIBATLANTIC_CONFIGOPTION_H
+
+#include <qobject.h>
+#include <qstring.h>
+
+#include "libatlantic_export.h"
+
+class LIBATLANTIC_EXPORT ConfigOption : public QObject
+{
+Q_OBJECT
+
+public:
+ ConfigOption(int configId);
+ int id();
+ void setName(const QString &name);
+ QString name() const;
+ void setDescription(const QString &description);
+ QString description() const;
+ void setEdit(bool edit);
+ bool edit();
+ void setValue(const QString &value);
+ QString value() const;
+ void update(bool force = false);
+
+signals:
+ void changed(ConfigOption *configOption);
+
+private:
+ int m_id;
+ bool m_changed, m_edit;
+ QString m_name, m_description, m_value;
+};
+
+#endif
diff --git a/atlantik/libatlantic/estate.cpp b/atlantik/libatlantic/estate.cpp
new file mode 100644
index 00000000..eef69280
--- /dev/null
+++ b/atlantik/libatlantic/estate.cpp
@@ -0,0 +1,163 @@
+// Copyright (c) 2002 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+//#include <kdebug.h>
+
+#include "estate.h"
+#include "estate.moc"
+#include "player.h"
+
+Estate::Estate(int estateId) : QObject()
+{
+ m_id = estateId;
+ m_name = QString::null;
+ m_owner = 0;
+ m_houses = 0;
+ m_price = 0;
+ m_money = 0;
+ m_estateGroup = 0;
+ m_changed = m_canBeOwned = m_canBuyHouses = m_canSellHouses = m_isMortgaged = m_canToggleMortgage = false;
+ m_bgColor = QColor();
+ m_color = QColor();
+}
+
+void Estate::setEstateGroup(EstateGroup *estateGroup)
+{
+ if (m_estateGroup != estateGroup)
+ m_estateGroup = estateGroup;
+}
+
+void Estate::setOwner(Player *player)
+{
+ if (m_owner != player)
+ {
+ m_owner = player;
+ m_changed = true;
+ }
+}
+bool Estate::isOwned() const
+{
+ if (m_owner)
+ return true;
+ else
+ return false;
+}
+
+bool Estate::isOwnedBySelf() const
+{
+ if (m_owner && m_owner->isSelf())
+ return true;
+ else
+ return false;
+}
+
+void Estate::setHouses(unsigned int houses)
+{
+ if (m_houses != houses)
+ m_houses = houses;
+ m_changed = true;
+}
+
+void Estate::setName(QString name)
+{
+ if (m_name != name)
+ {
+ m_name = name;
+ m_changed = true;
+ }
+}
+
+QString Estate::name() const
+{
+ return m_name;
+}
+
+void Estate::setColor(QColor color)
+{
+ if (m_color != color)
+ {
+ m_color = color;
+ m_changed = true;
+ }
+}
+
+void Estate::setBgColor(QColor color)
+{
+ if (m_bgColor != color)
+ {
+ m_bgColor = color;
+ m_changed = true;
+ }
+}
+
+void Estate::setCanBeOwned(const bool canBeOwned)
+{
+ if (m_canBeOwned != canBeOwned)
+ m_canBeOwned = canBeOwned;
+}
+
+void Estate::setCanBuyHouses(const bool canBuyHouses)
+{
+ if (m_canBuyHouses != canBuyHouses)
+ m_canBuyHouses = canBuyHouses;
+}
+
+void Estate::setCanSellHouses(const bool canSellHouses)
+{
+ if (m_canSellHouses != canSellHouses)
+ m_canSellHouses = canSellHouses;
+}
+
+void Estate::setIsMortgaged(const bool isMortgaged)
+{
+ if (m_isMortgaged != isMortgaged)
+ {
+ m_isMortgaged = isMortgaged;
+ m_changed = true;
+ }
+}
+
+void Estate::setCanToggleMortgage(const bool canToggleMortgage)
+{
+ if (m_canToggleMortgage != canToggleMortgage)
+ {
+ m_canToggleMortgage = canToggleMortgage;
+ m_changed = true;
+ }
+}
+
+void Estate::setMoney(int money)
+{
+ if (m_money != money)
+ {
+ m_money = money;
+ m_changed = true;
+ }
+}
+
+int Estate::money()
+{
+ return m_money;
+}
+
+void Estate::update(bool force)
+{
+ if (m_changed || force)
+ {
+ emit changed();
+ m_changed = false;
+ }
+}
diff --git a/atlantik/libatlantic/estate.h b/atlantik/libatlantic/estate.h
new file mode 100644
index 00000000..b6b768a5
--- /dev/null
+++ b/atlantik/libatlantic/estate.h
@@ -0,0 +1,95 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_ESTATE_H
+#define LIBATLANTIC_ESTATE_H
+
+#include <qobject.h>
+#include <qcolor.h>
+
+#include "libatlantic_export.h"
+
+class EstateGroup;
+class Player;
+
+class LIBATLANTIC_EXPORT Estate : public QObject
+{
+Q_OBJECT
+
+public:
+ Estate(int estateId);
+ int id() { return m_id; }
+ void setName(QString name);
+ QString name() const;
+ void setEstateGroup(EstateGroup *estateGroup);
+ EstateGroup *estateGroup() { return m_estateGroup; }
+ void setOwner(Player *player);
+ bool isOwned() const;
+ bool isOwnedBySelf() const;
+ Player *owner() { return m_owner; }
+ void setHouses(unsigned int houses);
+ unsigned int houses() { return m_houses; }
+ void setCanBeOwned(const bool canBeOwned);
+ bool canBeOwned() const { return m_canBeOwned; }
+ void setCanBuyHouses(const bool canBuyHouses);
+ bool canBuyHouses() const { return m_canBuyHouses; }
+ void setCanSellHouses(const bool canSellHouses);
+ bool canSellHouses() const { return m_canSellHouses; }
+ void setHousePrice(const unsigned int housePrice) { m_housePrice = housePrice; }
+ unsigned int housePrice() const { return m_housePrice; }
+ void setHouseSellPrice(const unsigned int houseSellPrice) { m_houseSellPrice = houseSellPrice; }
+ unsigned int houseSellPrice() const { return m_houseSellPrice; }
+ void setIsMortgaged(const bool isMortgaged);
+ bool isMortgaged() const { return m_isMortgaged; }
+ void setCanToggleMortgage(const bool canToggleMortgage);
+ bool canToggleMortgage() const { return m_canToggleMortgage; }
+ void setMortgagePrice(const unsigned int mortgagePrice) { m_mortgagePrice = mortgagePrice; }
+ unsigned int mortgagePrice() const { return m_mortgagePrice; }
+ void setUnmortgagePrice(const unsigned int unmortgagePrice) { m_unmortgagePrice = unmortgagePrice; }
+ unsigned int unmortgagePrice() const { return m_unmortgagePrice; }
+ void setColor(QColor color);
+ QColor color() const { return m_color; }
+ void setBgColor(QColor color);
+ QColor bgColor() const { return m_bgColor; }
+ void setPrice(const unsigned int price) { m_price = price; }
+ unsigned int price() const { return m_price; }
+ void setMoney(int money);
+ int money();
+ void update(bool force = false);
+
+signals:
+ void changed();
+ void estateToggleMortgage(Estate *estate);
+ void estateHouseBuy(Estate *estate);
+ void estateHouseSell(Estate *estate);
+ void newTrade(Player *player);
+ void LMBClicked(Estate *estate);
+
+protected:
+ bool m_changed;
+ int m_id;
+
+private:
+ QString m_name;
+ Player *m_owner;
+ EstateGroup *m_estateGroup;
+ unsigned int m_houses, m_price, m_housePrice, m_houseSellPrice, m_mortgagePrice, m_unmortgagePrice;
+ int m_money;
+ bool m_canBeOwned, m_canBuyHouses, m_canSellHouses, m_isMortgaged, m_canToggleMortgage;
+ QColor m_bgColor, m_color;
+};
+
+#endif
diff --git a/atlantik/libatlantic/estategroup.cpp b/atlantik/libatlantic/estategroup.cpp
new file mode 100644
index 00000000..e0148afc
--- /dev/null
+++ b/atlantik/libatlantic/estategroup.cpp
@@ -0,0 +1,41 @@
+// Copyright (c) 2002 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include "estategroup.h"
+#include "estategroup.moc"
+
+EstateGroup::EstateGroup(const int id) : QObject()
+{
+ m_id = id;
+}
+
+void EstateGroup::setName(const QString name)
+{
+ if (m_name != name)
+ {
+ m_name = name;
+ m_changed = true;
+ }
+}
+
+void EstateGroup::update(bool force)
+{
+ if (m_changed || force)
+ {
+ emit changed();
+ m_changed = false;
+ }
+}
diff --git a/atlantik/libatlantic/estategroup.h b/atlantik/libatlantic/estategroup.h
new file mode 100644
index 00000000..3e08a9ce
--- /dev/null
+++ b/atlantik/libatlantic/estategroup.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_ESTATEGROUP_H
+#define LIBATLANTIC_ESTATEGROUP_H
+
+#include <qobject.h>
+
+#include "libatlantic_export.h"
+
+class LIBATLANTIC_EXPORT EstateGroup : public QObject
+{
+Q_OBJECT
+
+public:
+ EstateGroup(const int id);
+ int id() { return m_id; }
+ void setName(const QString name);
+ QString name() const { return m_name; }
+ void update(bool force = false);
+
+signals:
+ void changed();
+
+private:
+ int m_id;
+ bool m_changed;
+ QString m_name;
+};
+
+#endif
diff --git a/atlantik/libatlantic/game.cpp b/atlantik/libatlantic/game.cpp
new file mode 100644
index 00000000..1f4eb244
--- /dev/null
+++ b/atlantik/libatlantic/game.cpp
@@ -0,0 +1,130 @@
+// Copyright (c) 2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <qstring.h>
+
+#include "game.h"
+
+Game::Game(int gameId) : QObject()
+{
+ m_id = gameId;
+ m_description = QString::null;
+ m_type = QString::null;
+ m_players = 0;
+ m_master = 0;
+
+ m_changed = false;
+}
+
+int Game::id() const
+{
+ return m_id;
+}
+
+void Game::setCanBeJoined(const bool &canBeJoined)
+{
+ if (m_canBeJoined != canBeJoined)
+ {
+ m_canBeJoined = canBeJoined;
+ m_changed = true;
+ }
+}
+
+bool Game::canBeJoined() const
+{
+ return m_canBeJoined;
+}
+
+void Game::setDescription(const QString &description)
+{
+ if (m_description != description)
+ {
+ m_description = description;
+ m_changed = true;
+ }
+}
+
+QString Game::description() const
+{
+ return m_description;
+}
+
+void Game::setName(const QString &name)
+{
+ if (m_name != name)
+ {
+ m_name = name;
+ m_changed = true;
+ }
+}
+
+QString Game::name() const
+{
+ return m_name;
+}
+
+void Game::setType(const QString &type)
+{
+ if (m_type != type)
+ {
+ m_type = type;
+ m_changed = true;
+ }
+}
+
+QString Game::type() const
+{
+ return m_type;
+}
+
+void Game::update(bool force)
+{
+ if (m_changed || force)
+ {
+ emit changed(this);
+ m_changed = false;
+ }
+}
+
+int Game::players()
+{
+ return m_players;
+}
+
+void Game::setPlayers(int players)
+{
+ if (m_players != players)
+ {
+ m_players = players;
+ m_changed = true;
+ }
+}
+
+Player *Game::master()
+{
+ return m_master;
+}
+
+void Game::setMaster(Player *master)
+{
+ if (m_master != master)
+ {
+ m_master = master;
+ m_changed = true;
+ }
+}
+
+#include "game.moc"
diff --git a/atlantik/libatlantic/game.h b/atlantik/libatlantic/game.h
new file mode 100644
index 00000000..8eaa85f6
--- /dev/null
+++ b/atlantik/libatlantic/game.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_GAME_H
+#define LIBATLANTIC_GAME_H
+
+#include <qobject.h>
+
+#include "libatlantic_export.h"
+
+class QString;
+
+class Player;
+
+class LIBATLANTIC_EXPORT Game : public QObject
+{
+Q_OBJECT
+
+public:
+ Game(int gameId);
+
+ int id() const;
+ void setCanBeJoined(const bool &canBeJoined);
+ bool canBeJoined() const;
+ void setDescription(const QString &description);
+ QString description() const;
+ void setName(const QString &name);
+ QString name() const;
+ void setType(const QString &type);
+ QString type() const;
+ int players();
+ void setPlayers(int players);
+ Player *master();
+ void setMaster(Player *master);
+
+ void update(bool force = false);
+
+signals:
+ void changed(Game *game);
+
+private:
+ bool m_changed;
+ bool m_canBeJoined;
+ QString m_description, m_name, m_type;
+ int m_id, m_players;
+ Player *m_master;
+};
+
+#endif
diff --git a/atlantik/libatlantic/libatlantic_export.h b/atlantik/libatlantic/libatlantic_export.h
new file mode 100644
index 00000000..6ea0423a
--- /dev/null
+++ b/atlantik/libatlantic/libatlantic_export.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2004 Dirk Mueller <[email protected]>
+
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_EXPORT_H
+#define LIBATLANTIC_EXPORT_H
+
+#include <kdemacros.h>
+
+#define LIBATLANTIC_EXPORT KDE_EXPORT
+
+#endif
diff --git a/atlantik/libatlantic/player.cpp b/atlantik/libatlantic/player.cpp
new file mode 100644
index 00000000..ab5e9268
--- /dev/null
+++ b/atlantik/libatlantic/player.cpp
@@ -0,0 +1,183 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include "player.h"
+#include "player.moc"
+#include "estate.h"
+
+Player::Player(int playerId) : QObject()
+{
+ m_id = playerId;
+ m_game = 0;
+ m_name = "";
+ m_host = "";
+ m_image = "";
+ m_location = m_destination = 0;
+ m_money = 0;
+ m_changed = m_isSelf = false;
+ m_bankrupt = m_hasDebt = m_hasTurn = m_canRoll = m_canBuy = m_canAuction = m_canUseCard = m_inJail = false;
+}
+
+void Player::setGame(Game *game)
+{
+ if (m_game != game)
+ {
+ m_game = game;
+ m_changed = true;
+ }
+}
+
+Game *Player::game()
+{
+ return m_game;
+}
+
+void Player::setLocation(Estate *location)
+{
+ if (m_location != location)
+ {
+ m_location = location;
+ m_changed = true;
+ }
+}
+
+void Player::setDestination(Estate *destination)
+{
+ if (m_destination != destination)
+ {
+ m_destination = destination;
+ m_changed = true;
+ }
+}
+
+void Player::setBankrupt(bool bankrupt)
+{
+ if (m_bankrupt != bankrupt)
+ {
+ m_bankrupt = bankrupt;
+ m_changed = true;
+ }
+}
+
+void Player::setHasDebt(bool hasDebt)
+{
+ if (m_hasDebt != hasDebt)
+ {
+ m_hasDebt = hasDebt;
+ m_changed = true;
+ }
+}
+
+void Player::setHasTurn(const bool hasTurn)
+{
+ if (m_hasTurn != hasTurn)
+ {
+ m_hasTurn = hasTurn;
+ m_changed = true;
+ if (m_hasTurn && m_isSelf)
+ emit gainedTurn();
+ }
+}
+
+void Player::setCanRoll(bool canRoll)
+{
+ if (m_canRoll != canRoll)
+ {
+ m_canRoll = canRoll;
+ m_changed = true;
+ }
+}
+
+void Player::setCanBuy(bool canBuy)
+{
+ if (m_canBuy != canBuy)
+ {
+ m_canBuy = canBuy;
+ m_changed = true;
+ }
+}
+
+void Player::setCanAuction(bool canAuction)
+{
+ if (m_canAuction != canAuction)
+ {
+ m_canAuction = canAuction;
+ m_changed = true;
+ }
+}
+
+void Player::setCanUseCard(bool canUseCard)
+{
+ if (m_canUseCard != canUseCard)
+ {
+ m_canUseCard = canUseCard;
+ m_changed = true;
+ }
+}
+
+void Player::setInJail(const bool inJail)
+{
+ if (m_inJail != inJail)
+ {
+ m_inJail = inJail;
+ m_changed = true;
+ }
+}
+
+void Player::setName(const QString _n)
+{
+ if (m_name != _n)
+ {
+ m_name = _n;
+ m_changed = true;
+ }
+}
+
+void Player::setHost(const QString &host)
+{
+ if (m_host != host)
+ {
+ m_host = host;
+ m_changed = true;
+ }
+}
+
+void Player::setImage(const QString &image)
+{
+ if (m_image != image)
+ {
+ m_image = image;
+ m_changed = true;
+ }
+}
+
+void Player::setMoney(unsigned int money)
+{
+ if (m_money != money)
+ {
+ m_money = money;
+ m_changed = true;
+ }
+}
+
+void Player::update(bool force)
+{
+ if (m_changed || force)
+ {
+ emit changed(this);
+ m_changed = false;
+ }
+}
diff --git a/atlantik/libatlantic/player.h b/atlantik/libatlantic/player.h
new file mode 100644
index 00000000..571276ef
--- /dev/null
+++ b/atlantik/libatlantic/player.h
@@ -0,0 +1,84 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_PLAYER_H
+#define LIBATLANTIC_PLAYER_H
+
+#include <qobject.h>
+#include <qstring.h>
+
+#include "libatlantic_export.h"
+
+class Estate;
+class Game;
+
+class LIBATLANTIC_EXPORT Player : public QObject
+{
+Q_OBJECT
+
+public:
+ Player(int playerId);
+
+ int id() { return m_id; }
+ void setGame(Game *game);
+ Game *game();
+ void setLocation(Estate *location);
+ Estate *location() { return m_location; }
+ void setDestination(Estate *destination);
+ Estate *destination() { return m_destination; }
+ void setIsSelf(const bool isSelf) { m_isSelf = isSelf; }
+ bool isSelf() const { return m_isSelf; }
+ void setBankrupt(bool bankrupt);
+ bool isBankrupt() { return m_bankrupt; }
+ void setHasDebt(bool hasDebt);
+ bool hasDebt() { return m_hasDebt; }
+ void setHasTurn(const bool hasTurn);
+ bool hasTurn() const { return m_hasTurn; }
+ void setCanRoll(bool canRoll);
+ bool canRoll() const { return m_canRoll; }
+ void setCanBuy(bool canBuy);
+ bool canBuy() const { return m_canBuy; }
+ void setCanAuction(bool canAuction);
+ bool canAuction() const { return m_canAuction; }
+ void setCanUseCard(bool canUseCard);
+ bool canUseCard() const { return m_canUseCard; }
+ void setInJail(const bool inJail);
+ bool inJail() const { return m_inJail; }
+ void setName(const QString _n);
+ QString name() const { return m_name; }
+ void setHost(const QString &host);
+ QString host() const { return m_host; }
+ void setImage(const QString &image);
+ const QString image() const { return m_image; }
+ void setMoney(unsigned int _m);
+ unsigned int money() const { return m_money; }
+ void update(bool force = false);
+
+signals:
+ void changed(Player *player);
+ void gainedTurn();
+
+private:
+ int m_id;
+ bool m_changed, m_isSelf;
+ bool m_bankrupt, m_hasDebt, m_hasTurn, m_canRoll, m_canBuy, m_canAuction, m_canUseCard, m_inJail;
+ unsigned int m_money;
+ QString m_name, m_host, m_image;
+ Game *m_game;
+ Estate *m_location, *m_destination;
+};
+
+#endif
diff --git a/atlantik/libatlantic/trade.cpp b/atlantik/libatlantic/trade.cpp
new file mode 100644
index 00000000..b516dc70
--- /dev/null
+++ b/atlantik/libatlantic/trade.cpp
@@ -0,0 +1,200 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include "trade.h"
+#include "trade.moc"
+#include "player.h"
+#include "estate.h"
+
+Trade::Trade(int tradeId)
+{
+ m_tradeId = tradeId;
+ m_revision = 0;
+ m_changed = m_rejected = false;
+}
+
+void Trade::setRevision(int revision)
+{
+ m_revision = revision;
+}
+
+int Trade::revision() const
+{
+ return m_revision;
+}
+
+void Trade::addPlayer(Player *player)
+{
+ m_playerAcceptMap[player] = false;
+}
+
+void Trade::removePlayer(Player *player)
+{
+ m_playerAcceptMap[player] = false;
+}
+
+unsigned int Trade::count( bool acceptOnly )
+{
+ unsigned int count = 0;
+ for (QMapIterator<Player *, bool> it = m_playerAcceptMap.begin() ; it != m_playerAcceptMap.end() ; ++it)
+ if ( !acceptOnly || it.data() )
+ count++;
+ return count;
+}
+
+void Trade::updateEstate(Estate *estate, Player *to)
+{
+ TradeEstate *t=0;
+
+ for (QPtrListIterator<TradeItem> i(mTradeItems); *i; ++i)
+ {
+ t=dynamic_cast<TradeEstate*>(*i);
+
+ if (!t)
+ continue;
+
+ if (t->estate()==estate)
+ break;
+
+ t=0;
+ }
+ if (t)
+ {
+ if (to)
+ {
+ if (t->to() == to)
+ return;
+ t->setTo(to);
+ }
+ else
+ {
+ mTradeItems.removeRef(t);
+ emit itemRemoved(t);
+ t->deleteLater();
+ }
+ }
+ else if (estate && to)
+ {
+ // new trade
+ t = new TradeEstate(estate, this, to);
+
+ mTradeItems.append(t);
+ emit itemAdded(t);
+ }
+}
+
+void Trade::updateMoney(unsigned int money, Player *from, Player *to)
+{
+ TradeMoney *t=0;
+
+ for (QPtrListIterator<TradeItem> i(mTradeItems); *i; ++i)
+ {
+ t=dynamic_cast<TradeMoney*>(*i);
+
+ if (!t)
+ continue;
+
+ if (t->from() == from && t->to() == to && t->money())
+ break;
+
+ t=0;
+ }
+ if (t)
+ {
+ if (from && to && money)
+ {
+ if (t->money() == money)
+ return;
+ t->setMoney(money);
+ }
+ else
+ {
+ mTradeItems.removeRef(t);
+ emit itemRemoved(t);
+ t->deleteLater();
+ }
+ }
+ else if (from && to && money)
+ {
+ // new trade
+ t = new TradeMoney(money, this, from, to);
+
+ mTradeItems.append(t);
+ emit itemAdded(t);
+ }
+}
+
+void Trade::updateAccept(Player *player, bool accept)
+{
+ if (m_playerAcceptMap[player] != accept)
+ {
+ m_playerAcceptMap[player] = accept;
+ m_changed = true;
+ }
+}
+
+void Trade::reject(Player *player)
+{
+ m_rejected = true;
+ emit rejected(player);
+}
+
+void Trade::update(bool force)
+{
+ if (m_changed || force)
+ {
+ emit changed(this);
+ m_changed = false;
+ }
+}
+
+TradeItem::TradeItem(Trade *trade, Player *from, Player *to) : mFrom(from), mTo(to), mTrade(trade)
+{
+ connect(from, SIGNAL(changed(Player *)), this, SLOT(playerChanged()));
+ connect(to, SIGNAL(changed(Player *)), this, SLOT(playerChanged()));
+}
+
+void TradeItem::playerChanged()
+{
+ emit changed(this);
+}
+
+TradeEstate::TradeEstate(Estate *estate, Trade *trade, Player *to) : TradeItem(trade, estate->owner(), to), mEstate(estate)
+{
+}
+
+QString TradeEstate::text() const
+{
+ return mEstate->name();
+}
+
+TradeMoney::TradeMoney(unsigned int money, Trade *trade, Player *from, Player *to) : TradeItem(trade, from, to), m_money(money)
+{
+}
+
+void TradeMoney::setMoney(unsigned int money)
+{
+ if (m_money != money)
+ {
+ m_money = money;
+ emit changed(this);
+ }
+}
+
+QString TradeMoney::text() const
+{
+ return QString("$%1").arg(m_money);
+}
diff --git a/atlantik/libatlantic/trade.h b/atlantik/libatlantic/trade.h
new file mode 100644
index 00000000..5d8f3c01
--- /dev/null
+++ b/atlantik/libatlantic/trade.h
@@ -0,0 +1,152 @@
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 as published by the Free Software Foundation.
+//
+// This library 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; see the file COPYING.LIB. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#ifndef LIBATLANTIC_TRADE_H
+#define LIBATLANTIC_TRADE_H
+
+#include <qobject.h>
+#include <qstring.h>
+#include <qptrlist.h>
+
+#include "libatlantic_export.h"
+#include "player.h"
+
+class Player;
+class Trade;
+class Estate;
+
+class LIBATLANTIC_EXPORT TradeItem : public QObject
+{
+Q_OBJECT
+
+public:
+ TradeItem(Trade *trade, Player *from, Player *to);
+ virtual ~TradeItem() { }
+
+ Player *from() { return mFrom; }
+ Player *to() { return mTo; }
+ void setTo(Player *p) { mTo=p; }
+ Trade *trade() { return mTrade; }
+
+ /**
+ * how to visualize this
+ **/
+ virtual QString text() const=0;
+
+signals:
+ void changed(TradeItem *);
+
+private slots:
+ void playerChanged();
+
+private:
+ Player *mFrom, *mTo;
+ Trade *mTrade;
+};
+
+class LIBATLANTIC_EXPORT TradeEstate : public TradeItem
+{
+Q_OBJECT
+
+public:
+ TradeEstate(Estate *estate, Trade *trade, Player *to);
+
+ Estate *estate() { return mEstate; }
+
+ virtual QString text() const;
+
+signals:
+ void updateEstate(Trade *trade, Estate *estate, Player *player);
+ void updateMoney(Trade *trade, unsigned int money, Player *from, Player *to);
+
+private:
+ Estate *mEstate;
+};
+
+class LIBATLANTIC_EXPORT TradeMoney : public TradeItem
+{
+Q_OBJECT
+
+public:
+ TradeMoney(unsigned int money, Trade *trade, Player *from, Player *to);
+
+ unsigned int money() const { return m_money; }
+ void setMoney(unsigned int money);
+
+ virtual QString text() const;
+
+signals:
+ void changed(TradeItem *tradeItem);
+
+private:
+ unsigned int m_money;
+};
+
+
+class LIBATLANTIC_EXPORT Trade : public QObject
+{
+Q_OBJECT
+
+public:
+ Trade(int tradeId);
+ int tradeId() { return m_tradeId; }
+
+ void setRevision(int revision);
+ int revision() const;
+
+ void addPlayer(Player *player);
+ void removePlayer(Player *player);
+
+ unsigned int count( bool acceptOnly );
+
+ bool isRejected() { return m_rejected; }
+
+private slots:
+ /**
+ * tell someone that this changed
+ **/
+// void changed(TradeItem *i) { emit itemChanged(i); }
+
+public:
+ void update(bool force = false);
+ void updateEstate(Estate *estate, Player *player);
+ void updateMoney(unsigned int money, Player *from, Player *to);
+ void updateAccept(Player *player, bool accept);
+ void reject(Player *player);
+
+signals:
+ void changed(Trade *);
+ void rejected(Player *player);
+
+ void itemAdded(TradeItem *);
+ void itemRemoved(TradeItem *);
+
+ void updateEstate(Trade *trade, Estate *estate, Player *to);
+ void updateMoney(Trade *trade, unsigned int money, Player *from, Player *to);
+ void reject(Trade *trade);
+ void accept(Trade *trade);
+
+private:
+ bool m_changed, m_rejected;
+ int m_tradeId, m_revision;
+
+ QPtrList<Player> mPlayers;
+ QMap<Player *, bool> m_playerAcceptMap;
+
+ QPtrList<TradeItem> mTradeItems;
+};
+
+#endif