summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-12-03 10:33:05 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-12-03 10:33:05 +0100
commit34e376a4908f8f2235d28314c4f779bbd1d09389 (patch)
tree4af1ebbf313d6a10bcde77d87a0cd4a3c30ad37e /server
parent391b6e2ad7541100191c2f2d4dd9ea5163de8f19 (diff)
Use PlayerState and GameState in Message::RoundState.
Diffstat (limited to 'server')
-rw-r--r--server/client.cpp6
-rw-r--r--server/client.h8
-rw-r--r--server/game.cpp16
-rw-r--r--server/game.h7
-rw-r--r--server/player.cpp14
5 files changed, 31 insertions, 20 deletions
diff --git a/server/client.cpp b/server/client.cpp
index 1fbef6d..0d0b0ba 100644
--- a/server/client.cpp
+++ b/server/client.cpp
@@ -104,8 +104,8 @@ void Client::round_start() {
connection->send(make_shared<Message::RoundStart>());
}
-void Client::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p) {
- connection->send(make_shared<Message::RoundState>(pl_d, pl_r, pl_u, pl_l, d, a, p));
+void Client::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) {
+ connection->send(make_shared<Message::RoundState>(pl_d, pl_r, pl_u, pl_l, g, a));
}
void Client::round_end(boost::function<void ()> callback) {
@@ -133,7 +133,7 @@ void ClientDumb::round_start() {
}
-void ClientDumb::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p) {
+void ClientDumb::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) {
}
diff --git a/server/client.h b/server/client.h
index add78f0..3455056 100644
--- a/server/client.h
+++ b/server/client.h
@@ -25,10 +25,8 @@ class ClientBase {
//! Notify client of a round start.
virtual void round_start() = 0;
- typedef Message::RoundState::Player PlayerState;
-
//! Send round state.
- virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p) = 0;
+ virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) = 0;
//! Send round end.
virtual void round_end(boost::function<void ()> callback) = 0;
@@ -83,7 +81,7 @@ class Client : public ClientBase, public boost::enable_shared_from_this<Client>
virtual void round_start();
//! Send round state.
- virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p);
+ virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a);
//! Send round end.
virtual void round_end(boost::function<void ()> callback);
@@ -102,7 +100,7 @@ class ClientDumb : public ClientBase {
virtual void round_start();
- virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p);
+ virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a);
virtual void round_end(boost::function<void ()> callback);
diff --git a/server/game.cpp b/server/game.cpp
index 628a966..b0739cb 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -116,7 +116,7 @@ void Game::round_update_draw() {
// Construct and send state to each client.
PlayerNum player = 0;
do {
- Player::State state[4];
+ PlayerState state[4];
state[0] = players[player].get_state();
state[1] = players[player + 1].get_state_filtered();
@@ -128,7 +128,11 @@ void Game::round_update_draw() {
a = possible_actions;
}
- players[player].client->round_state(state[0], state[1], state[2], state[3], dora, a, current_player - player);
+ GameState gstate;
+ gstate.dora = dora;
+ gstate.current_player = current_player - player;
+
+ players[player].client->round_state(state[0], state[1], state[2], state[3], gstate, a);
} while(++player);
// Await action from client.
@@ -143,7 +147,7 @@ void Game::round_update_discard() {
// Construct and send state to each client.
PlayerNum player = 0;
do {
- Player::State state[4];
+ PlayerState state[4];
state[0] = players[player].get_state();
state[1] = players[player + 1].get_state_filtered();
@@ -157,7 +161,11 @@ void Game::round_update_discard() {
}
}
- players[player].client->round_state(state[0], state[1], state[2], state[3], dora, a, current_player - player);
+ GameState gstate;
+ gstate.dora = dora;
+ gstate.current_player = current_player - player;
+
+ players[player].client->round_state(state[0], state[1], state[2], state[3], gstate, a);
} while(++player);
preceding_action = Action::Pass;
diff --git a/server/game.h b/server/game.h
index 1de6c73..b0ec4a2 100644
--- a/server/game.h
+++ b/server/game.h
@@ -9,6 +9,7 @@
#include "wall.h"
#include "client.h"
#include "../common/action.h"
+#include "../common/state.h"
#include "../common/cyclicint.h"
class Game : public boost::enable_shared_from_this<Game> {
@@ -34,13 +35,11 @@ class Game : public boost::enable_shared_from_this<Game> {
//! Prepare for a new round.
void round_start();
- typedef Client::PlayerState State;
-
//! Get a state snapshot.
- State get_state();
+ PlayerState get_state();
//! Get a state snapshot, with concealed tiles filtered.
- State get_state_filtered();
+ PlayerState get_state_filtered();
//! Get possible actions after a draw.
Actions get_actions_draw();
diff --git a/server/player.cpp b/server/player.cpp
index 554084d..6673937 100644
--- a/server/player.cpp
+++ b/server/player.cpp
@@ -13,13 +13,19 @@ void Game::Player::round_start() {
client->round_start();
}
-Game::Player::State Game::Player::get_state() {
- State state = {hand, open, pond};
+PlayerState Game::Player::get_state() {
+ Tilegroups h = open;
+ h.insert(h.begin(), hand);
+
+ PlayerState state = {h, pond};
return state;
}
-Game::Player::State Game::Player::get_state_filtered() {
- State state = {hand, open, pond};
+PlayerState Game::Player::get_state_filtered() {
+ Tilegroups h = open;
+ h.insert(h.begin(), hand);
+
+ PlayerState state = {h, pond};
return state;
}