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

Diff of /game_server/src/game.c

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

revision 1.10 by ymettier, Sat Sep 6 15:09:07 2003 UTC revision 1.11 by ymettier, Sat Sep 6 18:21:22 2003 UTC
# Line 78  send_message_SAY_cards_in_hand (int sock Line 78  send_message_SAY_cards_in_hand (int sock
78    n = 0;    n = 0;
79    for (i = 0; i < 78; i++)    for (i = 0; i < 78; i++)
80      {      {
81        if (g->rules->card_status[i] == player_id)        if (RULES (g->rules)->card_status[i] == player_id)
82          deck[n++] = g->rules->card_value[i];          deck[n++] = RULES (g->rules)->card_value[i];
83      }      }
84    a = g_malloc (sizeof (char *) * (n + 2));    a = g_malloc (sizeof (char *) * (n + 2));
85    a[0] = g_strdup_printf ("%d", n);    a[0] = g_strdup_printf ("%d", n);
# Line 103  send_ask_bids (int sock_id, player_t * p Line 103  send_ask_bids (int sock_id, player_t * p
103    msg[0] = g_strdup_printf ("%d", g->nb_players_max);    msg[0] = g_strdup_printf ("%d", g->nb_players_max);
104    for (i = 0; i < g->nb_players_max; i++)    for (i = 0; i < g->nb_players_max; i++)
105      {      {
106        switch (g->rules->bids[i])        switch (RULES (g->rules)->bids[i])
107          {          {
108          case LIBMT_BID_UNDEF:          case LIBMT_BID_UNDEF:
109            msg[i + 1] = g_strdup ("?");            msg[i + 1] = g_strdup ("?");
# Line 134  send_ask_bids (int sock_id, player_t * p Line 134  send_ask_bids (int sock_id, player_t * p
134  }  }
135    
136  void  void
137    send_ask_card (int sock_id, player_t * p, int is_resume)
138    {
139      game_t *g = p->game;
140      char **a;
141      int i;
142      a = g_malloc (sizeof (char *) * (g->nb_players_max + 2));
143      a[0] = g_strdup_printf ("%d", g->nb_players_max);
144      for (i = 0; i < g->nb_players_max; i++)
145        a[i + 1] =
146          g_strdup_printf ("%d",
147                           RULES (g->rules)->card_value[RULES (g->rules)->
148                                                        board[i]]);
149      a[g->nb_players_max + 1] = NULL;
150    
151      protocol_send_array (sock_id, PROTOCOL_ASK_CARDS_ON_BOARD, a);
152      for (i = 0; a[i]; i++)
153        g_free (a[i]);
154      g_free (a);
155    }
156    
157    void
158  shuffle (rules_t * r)  shuffle (rules_t * r)
159  {  {
160    gint shuffle;    gint shuffle;
# Line 196  dill (rules_t * r, int nb_players) Line 217  dill (rules_t * r, int nb_players)
217  void  void
218  tarot_game_start (game_t * game)  tarot_game_start (game_t * game)
219  {  {
220    game->rules = g_malloc (sizeof (rules_t));    RULES (game->rules) = g_malloc (sizeof (rules_t));
221    game->rules->bid = LIBMT_BID_UNDEF;    RULES (game->rules)->bid = LIBMT_BID_UNDEF;
222    game->rules->preneur = -1;    RULES (game->rules)->preneur = -1;
223    
224  /* Shuffle the cards */  /* Shuffle the cards */
225    shuffle (game->rules);    shuffle (game->rules);
# Line 249  send_info_chien (int sock_id, player_t * Line 270  send_info_chien (int sock_id, player_t *
270    msg = g_malloc (sizeof (char *) * (nb_cards_in_chien + 2));    msg = g_malloc (sizeof (char *) * (nb_cards_in_chien + 2));
271    msg[0] = g_strdup_printf ("%d", nb_cards_in_chien);    msg[0] = g_strdup_printf ("%d", nb_cards_in_chien);
272    for (i = 0; i < nb_cards_in_chien; i++)    for (i = 0; i < nb_cards_in_chien; i++)
273      g_strdup_printf ("%d", g->rules->chien[i]);      g_strdup_printf ("%d", RULES (g->rules)->chien[i]);
274    msg[nb_cards_in_chien + 1] = NULL;    msg[nb_cards_in_chien + 1] = NULL;
275    protocol_send_array (sock_id, PROTOCOL_INFO_CHIEN, msg);    protocol_send_array (sock_id, PROTOCOL_INFO_CHIEN, msg);
276    for (i = 0; msg[i]; i++)    for (i = 0; msg[i]; i++)
# Line 287  read_chien (char **aline, game_t * game) Line 308  read_chien (char **aline, game_t * game)
308        if (!aline[i + 2])        if (!aline[i + 2])
309          return (READ_CHIEN_TOO_FEW_ARGUMENTS);          return (READ_CHIEN_TOO_FEW_ARGUMENTS);
310        chien[i] = atoi (aline[i + 2]);        chien[i] = atoi (aline[i + 2]);
311        if (game->rules->card_status[chien[i]] != game->rules->preneur)        if (RULES (game->rules)->card_status[chien[i]] !=
312              RULES (game->rules)->preneur)
313          return (READ_CHIEN_WRONG_CHIEN);          return (READ_CHIEN_WRONG_CHIEN);
314      }      }
315    for (i = 0; i < nb; i++)    for (i = 0; i < nb; i++)
316      {      {
317        game->rules->card_status[chien[i]] = 10 + game->rules->preneur;        RULES (game->rules)->card_status[chien[i]] =
318            10 + RULES (game->rules)->preneur;
319      }      }
320    
321    return (READ_CHIEN_OK);    return (READ_CHIEN_OK);

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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