From 81815ef0c1bf00e907f8be5131dc96e7dfd0dc02 Mon Sep 17 00:00:00 2001 From: pk910 Date: Mon, 12 Nov 2012 15:43:16 +0100 Subject: [PATCH] fixed game_uno +2/+4 timeout handling --- src/modules/NeonFun.mod/game_uno.c | 54 ++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/modules/NeonFun.mod/game_uno.c b/src/modules/NeonFun.mod/game_uno.c index 99827c9..2e67eda 100644 --- a/src/modules/NeonFun.mod/game_uno.c +++ b/src/modules/NeonFun.mod/game_uno.c @@ -329,7 +329,7 @@ TIMEQ_CALLBACK(uno_game_wait_timeout) { uno_show_top_card(game); game->active_player = game->player; //active player uno_reply(game, NULL, "NF_UNO_USER_HURRY_UP", game->active_player->chanuser->user->nick); - game->timer = timeq_add(30, module_id, uno_player_timeout, game); + game->timer = timeq_add(40, module_id, uno_player_timeout, game); } TIMEQ_CALLBACK(uno_player_timeout) { @@ -338,22 +338,42 @@ TIMEQ_CALLBACK(uno_player_timeout) { //player timeout (take another card) struct uno_player *player = game->active_player, *next_player = uno_get_next_player(game); //add a card to the players deck - if(!game->deck->count) - game->deck = uno_shuffle_deck(); - struct uno_card *card = uno_get_card(game->deck); - if(!card) { - uno_reply(game, NULL, "NF_UNO_ERROR", 2); - uno_free_game(game); - return; + int ccount; + if(game->take_cards_pending) { + //count cards to take + struct uno_card *card; + ccount = 0; + for(card = game->top_card; card; card = card->prev) { + if(card->card == UNO_CARD_ADD_2) + ccount += 2; + else if(card->card == UNO_CARD_ADD_4) + ccount += 4; + } + } else + ccount = 1; + int i; + for(i = 0; i < ccount; i++) { + if(!game->deck->count) + game->deck = uno_shuffle_deck(); + struct uno_card *card = uno_get_card(game->deck); + if(!card) { + uno_reply(game, NULL, "NF_UNO_ERROR", 2); + uno_free_game(game); + return; + } + card->next = player->cards; + if(player->cards) + player->cards->prev = card; + player->cards = card; + player->count++; } - card->next = player->cards; - if(player->cards) - player->cards->prev = card; - player->cards = card; - player->count++; player->timeout = 1; game->active_player = next_player; - uno_reply(game, NULL, "NF_UNO_USER_TOOK_CARD", player->chanuser->user->nick); + if(game->take_cards_pending) { + game->take_cards_pending = 0; + uno_reply(game, NULL, "NF_UNO_USER_TOOK_CARDS", player->chanuser->user->nick, ccount); + } else + uno_reply(game, NULL, "NF_UNO_USER_TOOK_CARD", player->chanuser->user->nick); struct uno_player *cplayer; for(cplayer = game->player; cplayer; cplayer = cplayer->next) { if(!cplayer->timeout) @@ -368,7 +388,7 @@ TIMEQ_CALLBACK(uno_player_timeout) { uno_show_top_card(game); uno_reply(game, NULL, "NF_UNO_USER_HURRY_UP", game->active_player->chanuser->user->nick); uno_show_player_cards(game, game->active_player); - game->timer = timeq_add(30, module_id, uno_player_timeout, game); + game->timer = timeq_add(40, module_id, uno_player_timeout, game); } void uno_action_take_card(struct uno_game *game, struct uno_player *player) { @@ -415,7 +435,7 @@ void uno_action_take_card(struct uno_game *game, struct uno_player *player) { uno_show_top_card(game); uno_reply(game, NULL, "NF_UNO_USER_HURRY_UP", game->active_player->chanuser->user->nick); uno_show_player_cards(game, game->active_player); - game->timer = timeq_add(30, module_id, uno_player_timeout, game); + game->timer = timeq_add(40, module_id, uno_player_timeout, game); } @@ -619,7 +639,7 @@ void uno_play_card(struct uno_game *game, struct uno_player *player, struct uno_ } uno_reply(game, NULL, "NF_UNO_USER_HURRY_UP", game->active_player->chanuser->user->nick); uno_show_player_cards(game, game->active_player); - game->timer = timeq_add(30, module_id, uno_player_timeout, game); + game->timer = timeq_add(40, module_id, uno_player_timeout, game); } void uno_event_part(struct ChanUser *chanuser) { -- 2.20.1