diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/game.cpp | 67 | ||||
-rw-r--r-- | server/game.h | 10 |
2 files changed, 57 insertions, 20 deletions
diff --git a/server/game.cpp b/server/game.cpp index 6b0b275..5827565 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -192,7 +192,7 @@ void Game::handle_action_draw(Action action) { case Action::Tsumo: { players[current_player].declare_tsumo(); - round_end(); + round_end(Tsumo); } break; case Action::Riichi: { @@ -283,7 +283,7 @@ void Game::handle_action_discard(Action action, int player) { // Check if the wall has run out. if(wall.remaining() <= 14) { - round_end(); + round_end(Draw); break; } @@ -313,7 +313,7 @@ void Game::handle_action_discard(Action action, int player) { case Action::Ron: { players[preceding_action_owner].declare_ron(players[current_player].claim()); - round_end(); + round_end(Ron); } break; // Will never occur on discard: @@ -325,25 +325,56 @@ void Game::handle_action_discard(Action action, int player) { } } -void Game::round_end() { +void Game::round_end(Endcondition end) { Message::RoundEnd::p msg = make_shared<Message::RoundEnd>(); - // Did anybody win? - for(int i = 0; i < 4; i++) { - if(players[current_player + i].won) { - Player& player = players[current_player + i]; - - msg->hand = player.hand; - - msg->yakus = player.won_han; - - msg->total_han = player.won_value.han(); - msg->total_fu = player.won_value.fu_rounded(); - msg->won = player.won_value.ron_east(); - + switch(end) { + case Draw: + msg->total_han = msg->total_fu = msg->won = 0; + break; + + case Tsumo: { + Player& player = players[current_player]; + + msg->hand = player.hand; + + msg->yakus = player.won_han; + + msg->total_han = player.won_value.han(); + msg->total_fu = player.won_value.fu_rounded(); + + if(current_player == round_num) { + msg->won = 3 * player.won_value.tsumo_east(); + } else { + msg->won = player.won_value.tsumo_east() + 2 * player.won_value.tsumo(); + } + } break; + + case Ron: + for(int i = 0; i < 4; i++) { + if(players[current_player + i].won) { + Player& player = players[current_player + i]; + + msg->hand = player.hand; + + msg->yakus = player.won_han; + + msg->total_han = player.won_value.han(); + msg->total_fu = player.won_value.fu_rounded(); + + if(current_player + i == round_num) { + msg->won = player.won_value.ron_east(); + } else { + msg->won = player.won_value.ron(); + } + + // TODO: Support multiple wins. + break; + } + } break; - } } + round_num++; if(!round_num) { diff --git a/server/game.h b/server/game.h index 0c47917..9d795a4 100644 --- a/server/game.h +++ b/server/game.h @@ -59,8 +59,14 @@ class Game : public boost::enable_shared_from_this<Game> { //! Handle actions after discard. void handle_action_discard(Action action, int player); - //! End the game. - void round_end(); + enum Endcondition { + Draw, + Tsumo, + Ron + }; + + //! End the round. + void round_end(Endcondition end); }; #endif |