📄 controller.c
字号:
/* if that came from a dangerous discard, tell the other players */ if ( game_flag(the_game,GFDangerousDiscard) ) { CMsgDangerousDiscardMsg ddm; ddm.type = CMsgDangerousDiscard; ddm.id = the_game->players[the_game->supplier]->id; ddm.discard = the_game->serial; ddm.nochoice = game_flag(the_game,GFNoChoice); send_all(the_game,&ddm); } /* do scoring if we've finished */ if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); return; } } /* end of case PMsgPung */ case PMsgPair: { PlayerP p; int id; seats seat; CMsgErrorMsg em; CMsgPlayerPairsMsg ppm; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; ppm.type = CMsgPlayerPairs; ppm.id = id; ppm.tile = the_game->tile; if ( handle_cmsg(the_game,&ppm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } check_min_time(1); send_all(the_game,&ppm); send_infotiles(p); /* if that came from a dangerous discard, tell the other players */ if ( game_flag(the_game,GFDangerousDiscard) ) { CMsgDangerousDiscardMsg ddm; ddm.type = CMsgDangerousDiscard; ddm.id = the_game->players[the_game->supplier]->id; ddm.discard = the_game->serial; ddm.nochoice = game_flag(the_game,GFNoChoice); send_all(the_game,&ddm); } /* do scoring if we've finished */ if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); return; } /* end of case PMsgPair */ case PMsgSpecialSet: { PlayerP p; int id; seats seat; CMsgErrorMsg em; CMsgPlayerSpecialSetMsg pssm; char tiles[100]; int i; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pssm.type = CMsgPlayerSpecialSet; pssm.id = id; pssm.tile = the_game->tile; tiles[0] = '\000'; for ( i = 0; i < p->num_concealed; i++ ) { if ( i > 0 ) strcat(tiles," "); strcat(tiles,tile_code(p->concealed[i])); } pssm.tiles = tiles; if ( handle_cmsg(the_game,&pssm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } send_all(the_game,&pssm); send_infotiles(p); /* do scoring if we've finished */ if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); return; } /* end of case PMsgSpecialSet */ case PMsgFormClosedPair: { PMsgFormClosedPairMsg *m = (PMsgFormClosedPairMsg *) pmp; CMsgPlayerFormsClosedPairMsg pfcpm; PlayerP p; int id; seats seat; CMsgErrorMsg em; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pfcpm.type = CMsgPlayerFormsClosedPair; pfcpm.id = id; pfcpm.tile = m->tile; if ( handle_cmsg(the_game,&pfcpm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } check_min_time(1); send_all(the_game,&pfcpm); send_infotiles(p); /* do scoring if we've finished */ if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); return; } /* end of case PMsgFormClosedPair */ case PMsgFormClosedSpecialSet: { PlayerP p; int id; seats seat; CMsgErrorMsg em; CMsgPlayerFormsClosedSpecialSetMsg pfcssm; char tiles[100]; int i; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pfcssm.type = CMsgPlayerFormsClosedSpecialSet; pfcssm.id = id; tiles[0] = '\000'; for ( i = 0; i < p->num_concealed; i++ ) { if ( i > 0 ) strcat(tiles," "); strcat(tiles,tile_code(p->concealed[i])); } pfcssm.tiles = tiles; if ( handle_cmsg(the_game,&pfcssm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } check_min_time(1); send_all(the_game,&pfcssm); send_infotiles(p); /* do scoring if we've finished */ if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); return; } /* end of case PMsgFormClosedSpecialSet */ case PMsgFormClosedPung: { PMsgFormClosedPungMsg *m = (PMsgFormClosedPungMsg *) pmp; CMsgPlayerFormsClosedPungMsg pfcpm; PlayerP p; int id; seats seat; CMsgErrorMsg em; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pfcpm.type = CMsgPlayerFormsClosedPung; pfcpm.id = id; pfcpm.tile = m->tile; if ( handle_cmsg(the_game,&pfcpm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } check_min_time(1); send_all(the_game,&pfcpm); send_infotiles(p); /* do scoring if we've finished */ if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); return; } /* end of case PMsgFormClosedPung */ case PMsgFormClosedChow: { PMsgFormClosedChowMsg *m = (PMsgFormClosedChowMsg *) pmp; CMsgPlayerFormsClosedChowMsg pfccm; PlayerP p; int id; seats seat; CMsgErrorMsg em; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pfccm.type = CMsgPlayerFormsClosedChow; pfccm.id = id; pfccm.tile = m->tile; if ( handle_cmsg(the_game,&pfccm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } check_min_time(1); send_all(the_game,&pfccm); send_infotiles(p); /* do scoring if we've finished */ if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); return; } /* end of case PMsgFormClosedChow */ case PMsgKong: { PMsgKongMsg *m = (PMsgKongMsg *) pmp; PlayerP p; int id; seats seat; CMsgPlayerClaimsKongMsg pckm; CMsgErrorMsg em; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pckm.type = CMsgPlayerClaimsKong; pckm.id = id; pckm.discard = m->discard; if ( handle_cmsg(the_game,&pckm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } send_all(the_game,&pckm); /* if all claims received, process */ check_claims(the_game); return; } /* end of case PMsgKong */ case PMsgChow: { PMsgChowMsg *m = (PMsgChowMsg *) pmp; PlayerP p; int id; seats seat; CMsgPlayerClaimsChowMsg pccm; CMsgErrorMsg em; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pccm.type = CMsgPlayerClaimsChow; pccm.id = id; pccm.discard = m->discard; pccm.cpos = m->cpos; if ( the_game->state == Discarded ) { /* special case: if chowpending is set, then this claim should be to specify the previously unspecified position after we've told the player that its claim has succeeded. So implement the chow and announce */ if ( the_game->chowpending ) { CMsgPlayerChowsMsg pcm; pcm.type = CMsgPlayerChows; pcm.id = id; pcm.tile = the_game->tile; pcm.cpos = m->cpos; if ( handle_cmsg(the_game,&pcm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } check_min_time(1); send_all(the_game,&pcm); return; } if ( handle_cmsg(the_game,&pccm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } send_all(the_game,&pccm); /* if all claims received, process */ check_claims(the_game); return; } else { /* This had better be mahjonging */ CMsgPlayerChowsMsg pcm; pcm.type = CMsgPlayerChows; pcm.id = id; pcm.tile = the_game->tile; pcm.cpos = m->cpos; if ( handle_cmsg(the_game,&pcm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } /* if any pos, just tell the player */ if ( m->cpos == AnyPos ) { send_id(id,&pcm); } else { check_min_time(1); send_all(the_game,&pcm); send_infotiles(p); /* if that came from a dangerous discard, tell the other players */ if ( game_flag(the_game,GFDangerousDiscard) ) { CMsgDangerousDiscardMsg ddm; ddm.type = CMsgDangerousDiscard; ddm.id = the_game->players[the_game->supplier]->id; ddm.discard = the_game->serial; ddm.nochoice = game_flag(the_game,GFNoChoice); send_all(the_game,&ddm); } if ( pflag(p,HandDeclared) ) score_hand(the_game,seat); } return; } } /* end of case PMsgChow */ case PMsgDeclareWashOut: { PlayerP p; int id; seats seat; CMsgErrorMsg em; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; /* at present, we don't have any rules allowing a player to declare a washout */ em.error = "Can't declare a Wash-Out"; send_id(id,&em); return; } /* end of case PMsgDeclareWashOut */ case PMsgMahJong: { PMsgMahJongMsg *m = (PMsgMahJongMsg *) pmp; PlayerP p; int id; seats seat; CMsgPlayerClaimsMahJongMsg pcmjm; CMsgPlayerMahJongsMsg pmjm; CMsgErrorMsg em; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ em.type = CMsgError ; em.seqno = connections[cnx].seqno; em.error = NULL; pcmjm.type = CMsgPlayerClaimsMahJong; pcmjm.id = id; pmjm.type = CMsgPlayerMahJongs; pmjm.id = id; if ( the_game->state == Discarded || ((the_game->state == Discarding || the_game->state == DeclaringSpecials) && the_game->konging ) ) { pcmjm.discard = m->discard; if ( handle_cmsg(the_game,&pcmjm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } send_all(the_game,&pcmjm); /* if all claims received, process */ check_claims(the_game); return; } else { /* this should be discarding */ pmjm.tile = the_game->tile; /* that's the tile drawn */ if ( handle_cmsg(the_game,&pmjm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } send_all(the_game,&pmjm); /* the players will now start declaring their hands */ return; } } /* end of case PMsgMahJong */ case PMsgDeclareClosedKong: { PMsgDeclareClosedKongMsg *m = (PMsgDeclareClosedKongMsg *) pmp; PlayerP p; int id; seats seat; CMsgErrorMsg em; CMsgPlayerDeclaresClosedKongMsg pdckm; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id); /* fill in basic fields of possible replies */ pdckm.id = id; em.type = CMsgError ; em.seqno = connections[cnx].seqno; pdckm.type = CMsgPlayerDeclaresClosedKong; em.error = NULL; pdckm.tile = m->tile; pdckm.discard = the_game->serial+1; if ( handle_cmsg(the_game,&pdckm) < 0 ) { em.error = the_game->cmsg_err; send_id(id,&em); return; } check_min_time(1); send_all(the_game,&pdckm); send_infotiles(p); /* now we need to wait for people to try to rob the kong */ timeout = 1000*timeout_time; return; } /* end of case PMsgDeclareClosedKong */ case PMsgAddToPung: { PMsgAddToPungMsg *m = (PMsgAddToPungMsg *) pmp; PlayerP p; int id; seats seat; CMsgErrorMsg em; CMsgPlayerAddsToPungMsg patpm; id = cnx_to_id(cnx); p = id_to_player(id); seat = id_to_seat(id);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -