summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/game.cpp10
-rw-r--r--server/player.cpp12
-rw-r--r--server/player.h4
3 files changed, 14 insertions, 12 deletions
diff --git a/server/game.cpp b/server/game.cpp
index d13235b..4d102a7 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -67,26 +67,26 @@ void Game::round_update() {
// Only implemented discard so far, so only current player that needs to be able to do a action.
int smart = 0;
for(Actions::iterator it = gamestate.possible_actions.begin(); it != gamestate.possible_actions.end(); ++it) {
- smart = smart | (1 << it->player);
+ //smart = smart | (1 << it->player);
}
int num_player_actions = 0;
if(smart & 1) {
num_player_actions++;
- players[0]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ players[0]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1), gamestate.possible_actions);
}
if(smart & 2) {
num_player_actions++;
- players[1]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ players[1]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1), gamestate.possible_actions);
}
if(smart & 4) {
num_player_actions++;
- players[2]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ players[2]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1), gamestate.possible_actions);
}
if(smart & 8) {
num_player_actions++;
- players[3]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ players[3]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1), gamestate.possible_actions);
}
if(num_player_actions == 0) {
diff --git a/server/player.cpp b/server/player.cpp
index b1d8467..d8baaf8 100644
--- a/server/player.cpp
+++ b/server/player.cpp
@@ -49,16 +49,18 @@ void Player::handle_ready(Message::p msg, boost::function<void ()> ready_callbac
ready_callback();
}
-void Player::handle_action(Message::p msg, boost::function<void (Action)> action_callback) {
+void Player::handle_action(Message::p msg, boost::function<void (Action)> action_callback, Actions possible_actions) {
if(msg->type != Message::Types::RoundAction) {
return;
}
Message::RoundAction::p action_msg = dynamic_pointer_cast<Message::RoundAction>(msg);
- //action_msg->action.player = id;
- if(action_callback != 0) {
+ // Check if the action is valid.
+ if(possible_actions.contains(action_msg->action)) {
action_callback(action_msg->action);
+ } else {
+ action_callback(possible_actions[0]);
}
}
@@ -91,8 +93,8 @@ void Player::round_end() {
connection->send(make_shared<Message::RoundEnd>());
}
-void Player::get_action(boost::function<void (Action)> callback) {
- connection->recv(boost::bind(&Player::handle_action, shared_from_this(), _1, callback));
+void Player::get_action(boost::function<void (Action)> callback, Actions expected_actions) {
+ connection->recv(boost::bind(&Player::handle_action, shared_from_this(), _1, callback, expected_actions));
}
void Player::kill_action() {
diff --git a/server/player.h b/server/player.h
index d0dc73b..25eddd3 100644
--- a/server/player.h
+++ b/server/player.h
@@ -34,7 +34,7 @@ class Player : public boost::enable_shared_from_this<Player> {
void handle_ready(Message::p msg, boost::function<void ()> ready_callback);
//! Handle Action-message.
- void handle_action(Message::p msg, boost::function<void (Action)> action_callback);
+ void handle_action(Message::p msg, boost::function<void (Action)> action_callback, Actions expected_actions);
public:
//! The ID of the player
@@ -56,7 +56,7 @@ class Player : public boost::enable_shared_from_this<Player> {
void round_end();
//! Get action.
- void get_action(boost::function<void (Action)> callback);
+ void get_action(boost::function<void (Action)> callback, Actions expected_actions);
void kill_action();
};