@@ -71,19 +71,56 @@ static void hoover_card(window_t *win, intermission_t *inter)
7171 }
7272}
7373
74- static void restart_game_as_new_game (wolf_t * wolf )
74+ static int get_card_player_count (wolf_t * wolf )
75+ {
76+ int count = wolf -> lobby .nb_connected ;
77+
78+ if (count < wolf -> nb_others )
79+ count = wolf -> nb_others ;
80+ if (wolf -> net .player_id != MAX_PLAYERS &&
81+ count < (int )wolf -> net .player_id + 1 )
82+ count = (int )wolf -> net .player_id + 1 ;
83+ if (count < 1 )
84+ count = 1 ;
85+ if (count > MAX_PLAYERS )
86+ count = MAX_PLAYERS ;
87+ return count ;
88+ }
89+
90+ static sfBool are_cards_ready (wolf_t * wolf )
91+ {
92+ int count = get_card_player_count (wolf );
93+
94+ for (int i = 0 ; i < count ; i ++ ) {
95+ if (!wolf -> card_ready [i ])
96+ return sfFalse ;
97+ }
98+ return sfTrue ;
99+ }
100+
101+ static void start_next_round (wolf_t * wolf )
75102{
76- wolf -> score = 0 ;
77- wolf -> stage = 0 ;
78103 reset_game_run (wolf );
79104 if (network_is_host (wolf ))
80- notify_game_reset (wolf );
105+ notify_next_round (wolf );
81106 wolf -> game -> state = STAGE ;
82107 sfMouse_setPositionRenderWindow ((sfVector2i ){wolf -> window_data -> width / 2 ,
83108 wolf -> window_data -> height / 2 }, wolf -> window_data -> window );
84109 sfRenderWindow_setMouseCursorVisible (wolf -> window_data -> window , sfFalse );
85110}
86111
112+ static void mark_cards_done (wolf_t * wolf )
113+ {
114+ if (!wolf -> connected || wolf -> net .player_id == MAX_PLAYERS ) {
115+ start_next_round (wolf );
116+ return ;
117+ }
118+ wolf -> card_ready [wolf -> net .player_id ] = 1 ;
119+ notify_card_ready (wolf );
120+ if (network_is_host (wolf ) && are_cards_ready (wolf ))
121+ start_next_round (wolf );
122+ }
123+
87124static void handle_card_round_end (wolf_t * wolf , window_t * win ,
88125 intermission_t * inter )
89126{
@@ -94,9 +131,7 @@ static void handle_card_round_end(wolf_t *wolf, window_t *win,
94131 sfClock_restart (inter -> clock );
95132 return ;
96133 }
97- if (wolf -> connected && !network_is_host (wolf ))
98- return ;
99- restart_game_as_new_game (wolf );
134+ mark_cards_done (wolf );
100135}
101136
102137static void click_card (wolf_t * wolf , window_t * win , intermission_t * inter )
@@ -138,9 +173,7 @@ static void select_card_by_key(wolf_t *wolf, intermission_t *inter,
138173 sfClock_restart (inter -> clock );
139174 return ;
140175 }
141- if (wolf -> connected && !network_is_host (wolf ))
142- return ;
143- restart_game_as_new_game (wolf );
176+ mark_cards_done (wolf );
144177}
145178
146179void card_action (wolf_t * wolf , player_t * player , sfEvent event )
0 commit comments