/[maitretarot]/game_server/src/state_machine.c
ViewVC logotype

Diff of /game_server/src/state_machine.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by ymettier, Sun Apr 27 16:39:52 2003 UTC revision 1.9 by ymettier, Mon Apr 28 00:25:56 2003 UTC
# Line 25  Line 25 
25  #include "game.h"  #include "game.h"
26  #include "protocol.h"  #include "protocol.h"
27    
28    void
29    send_waiting_for_player (player_t * player)
30    {
31      game_t *g = player->game;
32      int i;
33      for (i = 0; i < g->players->len; i++)
34        {
35          int sock_id = g_array_index (g->players, int, i);
36          player_t *p =
37            g_tree_lookup (config->sock_id, GINT_TO_POINTER (sock_id));
38          g_assert (p != NULL);
39          if (p != player)
40            protocol_send (sock_id, PROTOCOL_SAY_WAITING_PLAYER, player->name);
41        }
42    }
43    
44  gboolean  gboolean
45  game_state_machine_cb (gpointer a, gpointer b, gpointer c)  game_state_machine_cb (gpointer a, gpointer b, gpointer c)
46  {  {
# Line 49  game_state_machine_cb (gpointer a, gpoin Line 65  game_state_machine_cb (gpointer a, gpoin
65      }      }
66    else if (g->state == GAME_STATE_START_GAME)    else if (g->state == GAME_STATE_START_GAME)
67      {      {
68          player_t *p;
69        game_start (g);        game_start (g);
70        for (i = 0; i < g->players->len; i++)        for (i = 0; i < g->players->len; i++)
71          {          {
72            int sock_id = g_array_index (g->players, int, i);            int sock_id = g_array_index (g->players, int, i);
73            player_t *p =            p = g_tree_lookup (config->sock_id, GINT_TO_POINTER (sock_id));
             g_tree_lookup (config->sock_id, GINT_TO_POINTER (sock_id));  
74            g_assert (p != NULL);            g_assert (p != NULL);
75  send_message_SAY_resume (sock_id, g);            send_message_SAY_resume (sock_id, g);
76             send_message_SAY_cards_in_hand (sock_id,g, i);            send_message_SAY_cards_in_hand (sock_id, g, i);
77              g->rules->bids[i] = LIBMT_BID_UNDEF;
78          }          }
79          g->turn = g->game_turn;
80        g->state = GAME_STATE_ASKING_BIDS;        g->state = GAME_STATE_ASKING_BIDS;
81      }      }
82    else if (g->state == GAME_STATE_ASKING_BIDS)    else if (g->state == GAME_STATE_ASKING_BIDS)
83      {      {
84        /* check who is supposed say his bid        int sock_id = g_array_index (g->players, int, g->turn);
85         * and update players' state        player_t *p =
86         */          g_tree_lookup (config->sock_id, GINT_TO_POINTER (sock_id));
87      }        g_assert (p != NULL);
88          if (p->state != PLAYER_STATE_ASKING_BID)
89            {
90              int turn = g->turn;
91              for (i = 0; i < g->nb_players_max; i++)
92                {
93                  int s1;
94                  player_t *p1;
95                  turn++;
96                  if (turn >= g->nb_players_max)
97                    turn = 0;
98    
99                  s1 = g_array_index (g->players, int, turn);
100                  p1 = g_tree_lookup (config->sock_id, GINT_TO_POINTER (s1));
101                  g_assert (p1 != NULL);
102                  if ((g->rules->bids[turn] == LIBMT_BID_UNDEF)
103                      ||
104                      ((LIBMT_BID_CMP (g->rules->bids[turn], LIBMT_BID_PASSE)
105                        && LIBMT_BID_CMP (g->rules->bids[turn], g->rules->bid))))
106                    {
107                      p1->state = PLAYER_STATE_ASKING_BID;
108                      p1->state_change_date = 0;
109                      g->turn = turn;
110                      send_waiting_for_player (p1);
111                      break;
112    
113                    }
114                }
115              if (i == g->nb_players_max)
116                {
117                  for (i = 0; i < g->players->len; i++)
118                    {
119                      int s1;
120                      player_t *p1;
121                      s1 = g_array_index (g->players, int, i);
122                      p1 = g_tree_lookup (config->sock_id, GINT_TO_POINTER (s1));
123                      g_assert (p1 != NULL);
124                      send_ask_bids (s1, p1, 1);
125                    }
126                  g->state = GAME_STATE_ASKING_ANNOUNCES;
127                }
128    
129            }
130        }
131      else if (g->state == GAME_STATE_ASKING_ANNOUNCES)
132        {
133                /* Check if the bids != PASSE.
134                 * If yes, go on
135                 * Otherwise, stop here and play again
136                 */
137        }
138    return (FALSE);    return (FALSE);
139  }  }
140    
# Line 84  player_state_machine_cb (gpointer k, gpo Line 151  player_state_machine_cb (gpointer k, gpo
151        switch (p->state)        switch (p->state)
152          {          {
153          case PLAYER_STATE_ASK_NICK:          case PLAYER_STATE_ASK_NICK:
154            protocol_send(sock_id,PROTOCOL_ASK_NICK);            protocol_send (sock_id, PROTOCOL_ASK_NICK);
155            break;            break;
156          case PLAYER_STATE_ASK_GAME:          case PLAYER_STATE_ASK_GAME:
157            protocol_send(sock_id,PROTOCOL_ASK_GAME);            protocol_send (sock_id, PROTOCOL_ASK_GAME);
158            break;            break;
159          case PLAYER_STATE_WAIT_FOR_PLAYERS:          case PLAYER_STATE_WAIT_FOR_PLAYERS:
160            protocol_send(sock_id,PROTOCOL_INFO,"Waiting for the other players");            protocol_send (sock_id, PROTOCOL_INFO,
161                             "Waiting for the other players");
162            break;            break;
163          case PLAYER_STATE_START_GAME:          case PLAYER_STATE_START_GAME:
164            protocol_send(sock_id,PROTOCOL_INFO,"Starting the game");            protocol_send (sock_id, PROTOCOL_INFO, "Starting the game");
165              break;
166            case PLAYER_STATE_ASKING_BID:
167              send_ask_bids (sock_id, p, 0);
168            break;            break;
169          case PLAYER_STATE_UNDEF:          case PLAYER_STATE_UNDEF:
170            protocol_send (sock_id,PROTOCOL_WARNING,  "Undefined state");            protocol_send (sock_id, PROTOCOL_WARNING, "Undefined state");
171            break;            break;
172          default:          default:
173            g_error ("This should not have been executed");            g_error ("This should not have been executed");

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26