fixed game_uno +2/+4 timeout handling
authorpk910 <philipp@zoelle1.de>
Mon, 12 Nov 2012 14:43:16 +0000 (15:43 +0100)
committerpk910 <philipp@zoelle1.de>
Mon, 12 Nov 2012 14:43:16 +0000 (15:43 +0100)
src/modules/NeonFun.mod/game_uno.c

index 99827c989039b1aef7141843ad62c720f407eb97..2e67edaa2b871febaf38b52300f1cfc4c8cd137a 100644 (file)
@@ -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) {