summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-12-13 14:05:10 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-12-13 14:05:10 +0100
commit4920ca952d7b818c7d2f5953a4676bf0ff7513e8 (patch)
tree564a1cb563dd78c043adf100252c29f9207ba6ec
parentd432140a22c45841d43eaf7e4b9352fe24f5062f (diff)
Added endcondition argument to Game::round_end().
-rw-r--r--server/game.cpp67
-rw-r--r--server/game.h10
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