Update of /home/kde/kdegames/atlantik/libatlantic In directory office:/tmp/cvs-serv10286/libatlantic Modified Files: Tag: atlantik_3_3_branch atlantic_core.cpp atlantic_core.h game.cpp game.h player.cpp player.h Log Message: more gameupdate changes, game master is now a server-wide property Index: atlantic_core.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantic/atlantic_core.cpp,v retrieving revision 1.27.2.1 retrieving revision 1.27.2.2 diff -u -d -r1.27.2.1 -r1.27.2.2 --- atlantic_core.cpp 15 Nov 2003 22:09:06 -0000 1.27.2.1 +++ atlantic_core.cpp 17 Nov 2003 02:50:42 -0000 1.27.2.2 @@ -79,6 +79,11 @@ } } +bool AtlanticCore::selfIsMaster() const +{ + return (m_playerSelf && m_playerSelf->game() && m_playerSelf->game()->master() == m_playerSelf); +} + void AtlanticCore::setPlayerSelf(Player *player) { m_playerSelf = player; @@ -145,16 +150,34 @@ return game; } -Game *AtlanticCore::findGame(int gameId, const QString &type) +Game *AtlanticCore::findGame(const QString &type) { Game *game = 0; for (QPtrListIterator it(m_games); (game = *it) ; ++it) - if (game->id() == gameId && (type.isNull() || type == game->type()) ) + 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 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); @@ -283,13 +306,13 @@ Player *player = 0; for (QPtrListIterator it(m_players); (player = *it) ; ++it) if (player == m_playerSelf) - std::cout << "PS: " << player->name().latin1() << ", game " << QString::number(player->gameId()).latin1() << std::endl; + 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->gameId()).latin1() << std::endl; + std::cout << " P: " << player->name().latin1() << ", game " << QString::number(player->game() ? player->game()->id() : -1).latin1() << std::endl; Game *game = 0; for (QPtrListIterator it(m_games); (game = *it) ; ++it) - std::cout << " G: " << QString::number(game->id()).latin1() << std::endl; + 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 it(m_estates); (estate = *it) ; ++it) Index: atlantic_core.h =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantic/atlantic_core.h,v retrieving revision 1.22.2.1 retrieving revision 1.22.2.2 diff -u -d -r1.22.2.1 -r1.22.2.2 --- atlantic_core.h 15 Nov 2003 22:09:06 -0000 1.22.2.1 +++ atlantic_core.h 17 Nov 2003 02:50:42 -0000 1.22.2.2 @@ -36,6 +36,8 @@ void reset(bool deletePlayers = false); + bool selfIsMaster() const; + void setPlayerSelf(Player *player); Player *playerSelf(); @@ -46,7 +48,9 @@ QPtrList games(); Game *newGame(int gameId, const QString &type = QString::null); - Game *findGame(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(); Index: game.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantic/Attic/game.cpp,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- game.cpp 15 Nov 2003 22:09:06 -0000 1.1.2.1 +++ game.cpp 17 Nov 2003 02:50:42 -0000 1.1.2.2 @@ -24,6 +24,7 @@ m_description = QString::null; m_type = QString::null; m_players = 0; + m_master = 0; m_changed = false; } @@ -108,6 +109,20 @@ 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; } } Index: game.h =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantic/Attic/game.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- game.h 15 Nov 2003 22:09:06 -0000 1.1.2.1 +++ game.h 17 Nov 2003 02:50:42 -0000 1.1.2.2 @@ -21,6 +21,8 @@ class QString; +class Player; + class Game : public QObject { Q_OBJECT @@ -39,6 +41,8 @@ QString type() const; int players(); void setPlayers(int players); + Player *master(); + void setMaster(Player *master); void update(bool force = false); @@ -50,6 +54,7 @@ bool m_canBeJoined; QString m_description, m_name, m_type; int m_id, m_players; + Player *m_master; }; #endif Index: player.cpp =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantic/player.cpp,v retrieving revision 1.21 retrieving revision 1.21.2.1 diff -u -d -r1.21 -r1.21.2.1 --- player.cpp 16 Jul 2003 21:53:16 -0000 1.21 +++ player.cpp 17 Nov 2003 02:50:42 -0000 1.21.2.1 @@ -21,25 +21,30 @@ Player::Player(int playerId) : QObject() { m_id = playerId; - m_gameId = -1; + m_game = 0; m_name = ""; m_host = ""; m_image = ""; m_location = m_destination = 0; m_money = 0; m_changed = m_isSelf = false; - m_master = m_bankrupt = m_hasDebt = m_hasTurn = m_canRoll = m_canBuy = m_canAuction = m_canUseCard = m_inJail = false; + m_bankrupt = m_hasDebt = m_hasTurn = m_canRoll = m_canBuy = m_canAuction = m_canUseCard = m_inJail = false; } -void Player::setGame(int gameId) +void Player::setGame(Game *game) { - if (m_gameId != gameId) + if (m_game != game) { - m_gameId = gameId; + m_game = game; m_changed = true; } } +Game *Player::game() +{ + return m_game; +} + void Player::setLocation(Estate *location) { if (m_location != location) @@ -54,15 +59,6 @@ if (m_destination != destination) { m_destination = destination; - m_changed = true; - } -} - -void Player::setMaster(bool master) -{ - if (m_master != master) - { - m_master = master; m_changed = true; } } Index: player.h =================================================================== RCS file: /home/kde/kdegames/atlantik/libatlantic/player.h,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -u -d -r1.18 -r1.18.2.1 --- player.h 16 Jul 2003 21:53:16 -0000 1.18 +++ player.h 17 Nov 2003 02:50:42 -0000 1.18.2.1 @@ -21,6 +21,7 @@ #include class Estate; +class Game; class Player : public QObject { @@ -30,16 +31,14 @@ Player(int playerId); int id() { return m_id; } - void setGame(int gameId); - int gameId() { return m_gameId; } + void setGame(Game *game); + Game *game(); void setLocation(Estate *estate); Estate *location() { return m_location; } void setDestination(Estate *estate); Estate *destination() { return m_destination; } void setIsSelf(const bool isSelf) { m_isSelf = isSelf; } bool isSelf() const { return m_isSelf; } - void setMaster(bool master); - bool master() { return m_master; } void setBankrupt(bool bankrupt); bool isBankrupt() { return m_bankrupt; } void setHasDebt(bool hasDebt); @@ -71,11 +70,12 @@ void gainedTurn(); private: - int m_id, m_gameId; + int m_id; bool m_changed, m_isSelf; - bool m_master, m_bankrupt, m_hasDebt, m_hasTurn, m_canRoll, m_canBuy, m_canAuction, m_canUseCard, m_inJail; + 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; }; _______________________________________________ atlantik-cvs mailing list atlantik-cvs@kde.org https://mail.kde.org/mailman/listinfo/atlantik-cvs