/* Ask for a card after the attack */ STATIC TEG_STATUS token_card( int fd, char *str ) { PSPLAYER pJ; PCOUNTRY pP; PLAY_DEBUG("token_card()\n"); /* Veo si puede sacar una tarjeta... */ if( player_whoisfd( fd, &pJ ) != TEG_STATUS_SUCCESS ) goto error; if( pJ->estado < PLAYER_STATUS_TURNOSTART || pJ->estado >= PLAYER_STATUS_TARJETA) goto error; // player may not have more than TEG_MAX_TARJETAS cards if( pJ->tot_cards >= TEG_MAX_TARJETAS ) goto error; // must have conquered a country to get a card if( pJ->turno_conq < 1 ) goto error; // after the 3rd exchange, the player must have conquered two countries if( pJ->tot_exchanges > 3 && pJ->turno_conq < 2 ) goto error; /* Puede sacar tarjeta */ pJ->tot_cards++; pP = get_random_country( tarjeta_es_libre ); pJ->estado = PLAYER_STATUS_TARJETA; tarjeta_sacar( &pP->tarjeta, pJ->numjug ); /* * Me fijo si el player es due�o del pa�s que dice la tarjeta. Si es as� * le agrego 2 fichas automaticamente como dice el reglamento. * Check if the card that the player gets is for a country that this player * owns. If yes, automatically place two armies according to the rules. */ if( pP->numjug == pJ->numjug ) { pP->ejercitos += 2; pJ->tot_armies += 2; tarjeta_usar( &pP->tarjeta ); if( ! g_game.fog_of_war ) netall_printf( "%s=%d,%d,%d\n", TOKEN_COUNTRY,pP->id,pP->numjug,pP->ejercitos); else fow_netall_printf( pP->id, "%s=%d,%d,%d\n", TOKEN_COUNTRY,pP->id,pP->numjug,pP->ejercitos); } net_printf(fd,"%s=%d,%d\n", TOKEN_TARJETA, pP->id,pP->tarjeta.usada); return TEG_STATUS_SUCCESS; error: net_print(fd,TOKEN_ERROR"="TOKEN_TARJETA"\n"); return TEG_STATUS_ERROR; }
/* Place 2 armies in the card's country. The player must own the country */ STATIC TEG_STATUS token_ejer2( int fd, char *str ) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; int country; PSPLAYER j; PLAY_DEBUG("token_ejer2()\n"); if( strlen(str)==0) goto error; if( player_whoisfd( fd, &j ) != TEG_STATUS_SUCCESS ) goto error; if( j->estado != PLAYER_STATUS_TARJETA ) goto error; p.igualador = &igualador; p.separador = &separador; p.data = str; if( parser_call( &p ) && !p.hay_otro ) { country = atoi( p.token ); } else goto error; if( country >= COUNTRIES_CANT || country < 0 ) { goto error; } if( tarjeta_es_usada( &g_countries[ country ].tarjeta )) goto error; if( g_countries[ country ].numjug == j->numjug && g_countries[ country ].tarjeta.numjug == j->numjug ) { g_countries[ country ].ejercitos += 2; j->tot_armies += 2; tarjeta_usar( &g_countries[ country ].tarjeta ); if( ! g_game.fog_of_war ) netall_printf("%s=%d,%d,%d\n", TOKEN_COUNTRY ,country ,g_countries[ country ].numjug ,g_countries[ country ].ejercitos); else fow_netall_printf( country, "%s=%d,%d,%d\n", TOKEN_COUNTRY ,country ,g_countries[ country ].numjug ,g_countries[ country ].ejercitos); } return TEG_STATUS_SUCCESS; error: net_print(fd,TOKEN_ERROR"="TOKEN_EJER2"\n"); return TEG_STATUS_PARSEERROR; }
/* I'm receiving the card I've requested after finishing my turn */ TEG_STATUS clitok_tarjeta(char *str) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; int country,used; if( strlen(str)==0 ) goto error; p.igualador = &igualador; p.separador = &separador; p.data = str; if( parser_call( &p ) && p.hay_otro ) { country = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { used = atoi( p.token ); } else goto error; if( country < 0 || country >= COUNTRIES_CANT ) goto error; ESTADO_SET(PLAYER_STATUS_TARJETA); InsertTailList( &g_game.tarjetas_list, (PLIST_ENTRY) &g_countries[ country ].tarjeta ); g_game.tarjetas_cant++; if( used ) tarjeta_usar( &g_countries[ country ].tarjeta ); g_countries[ country ].tarjeta.numjug = WHOAMI(); if( used ) { textmsg(M_IMP,_("You received card: '%s' and 2 armies where placed there"), countries_get_name( country ) ); } else { textmsg(M_IMP,_("You received card: '%s'"), countries_get_name( country ) ); } gui_tarjeta( country ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_tarjeta()"); return TEG_STATUS_ERROR; }
/* what cards do I have */ TEG_STATUS clitok_enum_cards( char *str ) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; int country, used; PLIST_ENTRY ltmp; g_game.tarjetas_cant = 0; while( ! IsListEmpty( &g_game.tarjetas_list ) ) ltmp = RemoveHeadList( &g_game.tarjetas_list ); if( ! str || strlen(str) == 0 ) goto ok; p.igualador = &igualador; p.separador = &separador; p.data = str; do { if( parser_call( &p ) ) { country = atoi( p.token ); used = atoi( p.value ); } else goto error; if( country < 0 || country >= COUNTRIES_CANT ) goto error; InsertTailList( &g_game.tarjetas_list, (PLIST_ENTRY) &g_countries[ country ].tarjeta ); g_game.tarjetas_cant++; if( used ) tarjeta_usar( &g_countries[ country ].tarjeta ); g_countries[ country ].tarjeta.numjug = WHOAMI(); } while ( p.hay_otro ); ok: return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_enum_cards()"); return TEG_STATUS_ERROR; }
/** * @fn TEG_STATUS ejer2_out( int country ) * Pone 2 ejercitos por la tarjeta que saco */ TEG_STATUS ejer2_out( int country ) { if( g_countries[ country ].numjug == WHOAMI() ) { if( ESTADO_ES( PLAYER_STATUS_TARJETA ) ) { if( !tarjeta_es_usada( &g_countries[ country ].tarjeta )) { tarjeta_usar( &g_countries[ country ].tarjeta ); last_country = country; net_printf(g_game.fd,TOKEN_EJER2"=%d\n",country); return TEG_STATUS_SUCCESS; } else { textmsg( M_ERR,_("Error, the 2 armies where placed before")); return TEG_STATUS_ERROR; } } else { textmsg( M_ERR,_("Error, it's not the time to put 2 armies.")); return TEG_STATUS_ERROR; } } else { textmsg(M_ERR,_("Error, '%s' isnt one of your countries"),g_countries[country].name); return TEG_STATUS_ERROR; } }