summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtle Hellvik Havsø <atle@havso.net>2010-11-21 16:31:10 +0100
committerAtle Hellvik Havsø <atle@havso.net>2010-11-21 16:31:10 +0100
commitb9942d8af0400f943b9b5bd67faf417a932750f5 (patch)
tree46d4a8c42120079f7db62036b63a26608966cfb5
parent09def96d8546284367b08e90795752d1934d35eb (diff)
Server sends the players id in the game together with the GameStart message.
Signed-off-by: Atle Hellvik Havsø <atle@havso.net>
-rw-r--r--common/message.cpp2
-rw-r--r--common/message.h1
-rw-r--r--server/game.cpp52
-rw-r--r--server/player.cpp1
4 files changed, 28 insertions, 28 deletions
diff --git a/common/message.cpp b/common/message.cpp
index b69ddef..4f7bad3 100644
--- a/common/message.cpp
+++ b/common/message.cpp
@@ -116,10 +116,12 @@ Message::GameStart::GameStart() : BoostBase(Types::GameStart) {
void Message::GameStart::serialize(boost::archive::text_oarchive& ar) {
ar & players;
+ ar & player_id;
}
void Message::GameStart::deserialize(boost::archive::text_iarchive& ar) {
ar & players;
+ ar & player_id;
}
Message::Ready::Ready() : NullBase(Types::Ready) {
diff --git a/common/message.h b/common/message.h
index 447d12d..584a850 100644
--- a/common/message.h
+++ b/common/message.h
@@ -114,6 +114,7 @@ namespace Message {
GameStart();
std::vector<std::string> players;
+ int player_id;
virtual void serialize(boost::archive::text_oarchive& ar);
virtual void deserialize(boost::archive::text_iarchive& ar);
diff --git a/server/game.cpp b/server/game.cpp
index cdfaf4f..72183bf 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -35,13 +35,10 @@ void Game::handle_ready() {
void Game::round_start() {
players[0]->round_start();
- players[0]->id = 0;
players[1]->round_start();
- players[1]->id = 1;
players[2]->round_start();
- players[2]->id = 2;
players[3]->round_start();
- players[3]->id = 3;
+
// Sett opp runden sin state
//game_state = make_shared<State>();
@@ -68,14 +65,8 @@ void Game::round_start() {
}
void Game::round_update() {
-
-
-
- if ( draw_phase ) {
-
-
-
+ if ( draw_phase ) {
if ( current_player == 3) {
current_player = 0;
} else {
@@ -106,13 +97,12 @@ void Game::round_update() {
num_player_actions++;
} else { // Run if we're in the discard phase
-
- // TODO
- // Add code for calculation of possible chi, pon, kan and ron.
- }
-
-
+ // TODO
+ // Add code for calculation of possible chi, pon, kan and ron.
+ }
+
+
// Send RoundState, inkl. liste av mulige actions.
for(int i = 0; i <= 3; i++) {
if ( i != current_player ) {
@@ -148,7 +138,6 @@ void Game::handle_action(Action action) {
#endif
-
switch ( action.type ) {
case Action::Pass: {
@@ -156,8 +145,10 @@ void Game::handle_action(Action action) {
} break;
case Action::Discard: {
- game_state.players[current_player].pond.push_back(game_state.players[current_player].hand[action.target]);
- game_state.players[current_player].hand.erase(game_state.players[current_player].hand.begin() + action.target);
+ Tile discarded_tile = game_state.players[action.player].hand[action.target];
+ game_state.players[action.player].pond.push_back(discarded_tile);
+ game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + action.target);
+
} break;
case Action::Riichi: {
@@ -195,18 +186,18 @@ void Game::handle_action(Action action) {
default:
break;
}
-
-
+
+
num_player_actions--;
-
+
+
+ if(num_player_actions == 0) {
+ round_update();
+ }
+
// Sjekk action, sjekk om endelig action er avgjort
// Oppdater state
// Evt. round_end()
- if (num_player_actions == 0) {
- // TODO
- // Add code for when someone has done a chi, pon, ron and kan.
- round_update();
- }
}
void Game::round_end() {
@@ -221,6 +212,11 @@ void Game::start() {
<< players[2]->nick() << " and "
<< players[3]->nick() << "." << std::endl;
+ players[0]->id = 0;
+ players[1]->id = 1;
+ players[2]->id = 2;
+ players[3]->id = 3;
+
waiting_players = 4;
players[0]->game_start(boost::bind(&Game::handle_ready, shared_from_this()), players);
diff --git a/server/player.cpp b/server/player.cpp
index 437d78d..6e1a7d3 100644
--- a/server/player.cpp
+++ b/server/player.cpp
@@ -72,6 +72,7 @@ void Player::game_start(boost::function<void ()> callback, std::vector<Player::p
for(std::vector<Player::p>::iterator i = players.begin(); i != players.end(); i++) {
msg->players.push_back((*i)->nick());
}
+ msg->player_id = id;
connection->send(msg);