From d4e406b161376f8f7d195fbc5851c5d6751a01af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atle=20Hellvik=20Havs=C3=B8?= Date: Mon, 13 Dec 2010 18:17:21 +0100 Subject: Tried to fix the RoundEnd dialog... --- server/game.cpp | 140 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 73 insertions(+), 67 deletions(-) diff --git a/server/game.cpp b/server/game.cpp index 501aa57..e9b1369 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -326,88 +326,94 @@ void Game::handle_action_discard(Action action, int player) { } void Game::round_end(Endcondition end) { - Message::RoundEnd::p msg = make_shared(); - for(int i = 0; i < 4; i++) { - msg->score[current_player + i].won = 0; - msg->score[current_player + i].score = players[current_player + i].get_state().score; + + round_num++; + + if(!round_num) { + round_wind++; } - 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(); - msg->score[current_player].won = msg->won; - for(int i = 1; i < 4; i++) { - msg->score[current_player + i]. won = -(msg->won / 3); - } - } else { - msg->won = player.won_value.tsumo_east() + 2 * player.won_value.tsumo(); - for(int i = 0; i < 4; i++) { - if(i == current_player) { - msg->score[i].won = msg->won; - } else if (i == round_num){ - msg->score[i].won = -(player.won_value.tsumo_east()); - } else { - msg->score[i].won = -(player.won_value.tsumo()); - } - } - } - } break; + Message::RoundEnd::p msg[4] = make_shared(); + + for(CyclicInt<4> count_player = 0; count_player < 4; count_player++) { + msg[count_player]->total_han = msg[count_player]->total_fu = msg[count_player]->won = msg[count_player]->score[count_player].won = 0; + for(int i = 0; i < 4; i++) { + msg[count_player]->score[count_player + i].score = players[count_player + i].get_state().score; + } - case Ron: - for(int i = 0; i < 4; i++) { - if(players[current_player + i].won) { - Player& player = players[current_player + i]; + 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[count_player]->hand = player.hand; - msg->yakus = player.won_han; + msg[count_player]->yakus = player.won_han; - msg->total_han = player.won_value.han(); - msg->total_fu = player.won_value.fu_rounded(); + msg[count_player]->total_han = player.won_value.han(); + msg[count_player]->total_fu = player.won_value.fu_rounded(); - if(current_player + i == round_num) { - msg->won = player.won_value.ron_east(); + if(current_player == round_num) { + msg[count_player]->won = 3 * player.won_value.tsumo_east(); + + for(int y = 0; y < 4; y++) { + msg[count_player]->score[current_player + y].won = -(msg[count_player]->won / 3); + } + msg[count_player]->score[count_player + current_player ].won = msg[count_player]->won; + } else { - msg->won = player.won_value.ron(); + msg[count_player]->won = player.won_value.tsumo_east() + 2 * player.won_value.tsumo(); + + for(int y = 0; y < 4; y++) { + if(count_player + y == current_player) { + msg[count_player]->score[y].won = msg[count_player]->won; + } else if (count_player + y == round_num){ + msg[count_player]->score[y].won = -(player.won_value.tsumo_east()); + } else { + msg[count_player]->score[y].won = -(player.won_value.tsumo()); + } + } } - // TODO: Support multiple wins. - break; + } break; + + case Ron: + for(int i = 0; i < 4; i++) { + if(players[current_player + i].won) { + Player& player = players[current_player + i]; + + msg[count_player]->hand = player.hand; + + msg[count_player]->yakus = player.won_han; + + msg[count_player]->total_han = player.won_value.han(); + msg[count_player]->total_fu = player.won_value.fu_rounded(); + + if(current_player + i == round_num) { + msg[count_player]->won = player.won_value.ron_east(); + } else { + msg[count_player]->won = player.won_value.ron(); + } + + // TODO: Support multiple wins. + break; + } } - } - break; - } + break; + } //Send med score - - - round_num++; - - if(!round_num) { - round_wind++; + msg[count_player]->game_end = false; + if(count_player == 3) break; } - - msg->game_end = false; awaiting_players = 4; - - players[0].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this())); - players[1].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this())); - players[2].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this())); - players[3].client->round_end(msg, boost::bind(&Game::handle_ready, shared_from_this())); + players[0].client->round_end(msg[0], boost::bind(&Game::handle_ready, shared_from_this())); + players[1].client->round_end(msg[1], boost::bind(&Game::handle_ready, shared_from_this())); + players[2].client->round_end(msg[2], boost::bind(&Game::handle_ready, shared_from_this())); + players[3].client->round_end(msg[3], boost::bind(&Game::handle_ready, shared_from_this())); // Ferdig? game_end() -- cgit v1.2.3