/** * @fn TEG_STATUS fichas_out() * Envia las fichas al server. Usada por FICHAS, FICHAS2 y FICHASC */ TEG_STATUS fichas_out() { char buf[2000]; char tmp[100]; int *ptr; int i; int first_time; PLAYER_STATUS e; if( fichas_check() != TEG_STATUS_SUCCESS ) { textmsg( M_ERR,_("Error, its not the time to send armies")); return TEG_STATUS_ERROR; } if( fichas_finish( &ptr ) != TEG_STATUS_SUCCESS ) { fichas_reset(); textmsg( M_ERR,_("Error, put the correct number of armies")); return TEG_STATUS_ERROR; } buf[0]=0; tmp[0]=0; first_time = 1; for(i=0;i<COUNTRIES_CANT;i++) { if( ptr[i]>0 ) { if( first_time ) sprintf(tmp,"%d:%d",i,ptr[i]); else sprintf(tmp,",%d:%d",i,ptr[i]); strcat(buf,tmp); first_time = 0; } } e = ESTADO_GET(); switch(e) { case PLAYER_STATUS_FICHAS: net_printf(g_game.fd,TOKEN_FICHAS"=%s\n",buf); ESTADO_SET( PLAYER_STATUS_POSTFICHAS); break; case PLAYER_STATUS_FICHAS2: net_printf(g_game.fd,TOKEN_FICHAS2"=%s\n",buf); ESTADO_SET( PLAYER_STATUS_POSTFICHAS2); break; case PLAYER_STATUS_FICHASC: net_printf(g_game.fd,TOKEN_FICHASC"=%s\n",buf); ESTADO_SET( PLAYER_STATUS_POSTFICHASC); break; default: textmsg( M_ERR,_("Error, its not the moment to send your armies")); return TEG_STATUS_ERROR; } return TEG_STATUS_SUCCESS; }
/* request a robot */ TEG_STATUS out_robot() { PLAYER_STATUS e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED && e < PLAYER_STATUS_START && g_game.fd > 0 ) { net_printf(g_game.fd,TOKEN_ROBOT"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* ask for scores */ TEG_STATUS out_scores() { PLAYER_STATUS e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED && g_game.fd > 0 ) { net_printf(g_game.fd,TOKEN_SCORES"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/** * @fn static TEG_STATUS fichas_check() * Dice si se esta en condiciones de hacer algo con fichas */ TEG_STATUS fichas_check() { PLAYER_STATUS e; e = ESTADO_GET(); if( e==PLAYER_STATUS_FICHAS || e==PLAYER_STATUS_FICHAS2 || e==PLAYER_STATUS_FICHASC ) return TEG_STATUS_SUCCESS; else return TEG_STATUS_ERROR; }
/* echo client (robots uses this) */ TEG_STATUS out_echo( char *msg ) { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED ) { net_printf(g_game.fd,TOKEN_ECHO"=%s\n",msg); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* tells the server that I surrender */ TEG_STATUS out_surrender() { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_START ) { net_printf(g_game.fd,TOKEN_SURRENDER"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* ask server what do I have to do (robots uses this) */ TEG_STATUS out_loque( void ) { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_CONNECTED ) { net_printf(g_game.fd,TOKEN_LOQUE"\n"); return TEG_STATUS_SUCCESS; } return TEG_STATUS_ERROR; }
/* are the necesary conditions met for the attack ? */ static TEG_STATUS attack_check() { PLAYER_STATUS e; e = ESTADO_GET(); if( e==PLAYER_STATUS_ATAQUE || e==PLAYER_STATUS_TROPAS) { ESTADO_SET(PLAYER_STATUS_ATAQUE); return TEG_STATUS_SUCCESS; } else return TEG_STATUS_ERROR; }
/* request the type of game */ TEG_STATUS out_get_typeofgame() { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_START ) { net_printf(g_game.fd,TOKEN_MODALIDAD"\n"); } else { textmsg( M_ERR,_("Error, the game is not started")); return TEG_STATUS_ERROR; } return TEG_STATUS_SUCCESS; }
/* request the server my secret mission */ TEG_STATUS out_missions() { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_START ) { net_printf(g_game.fd,TOKEN_MISSION"\n"); } else { textmsg( M_ERR,_("Error, the game is not started")); return TEG_STATUS_ERROR; } return TEG_STATUS_SUCCESS; }
/* send the server the armies I'm moving after conquering a country */ TEG_STATUS out_tropas( int src, int dst, int cant) { PLAYER_STATUS e; e = ESTADO_GET(); if(e==PLAYER_STATUS_TROPAS || e==PLAYER_STATUS_ATAQUE) { net_printf(g_game.fd,TOKEN_TROPAS"=%d,%d,%d\n",src,dst,cant); } else { return TEG_STATUS_ERROR; } return TEG_STATUS_SUCCESS; }
/* tells the server that my turn is over */ TEG_STATUS out_endturn() { PLAYER_STATUS e; e = ESTADO_GET(); if( e > PLAYER_STATUS_TURNOSTART && e < PLAYER_STATUS_TURNOEND ) { attack_reset(); reagrupe_reset(); ESTADO_SET( PLAYER_STATUS_IDLE ); net_printf(g_game.fd,TOKEN_TURNO"\n"); } else { textmsg( M_ERR,_("Error, it's not your turn.")); return TEG_STATUS_ERROR; } return TEG_STATUS_SUCCESS; }
/* Sets the Conquer-The-World option on/off, Fog of war on/off */ TEG_STATUS out_set_typeofgame(int conqworld, int fog_of_war, int with_common, int armies1, int armies2) { PLAYER_STATUS e; e = ESTADO_GET(); if( e >= PLAYER_STATUS_START ) { textmsg( M_ERR,_("Error, the game is started so you cant change the type of game")); return TEG_STATUS_ERROR; } else { net_printf(g_game.fd,"%s=%s=%d;%s=%s=%d;%s=%s=%d;%s=%s=%d,%d\n", TOKEN_SET,OPTION_CONQWORLD, conqworld, TOKEN_SET,OPTION_FOG_OF_WAR, fog_of_war, TOKEN_SET,OPTION_CMISSION, with_common, TOKEN_SET,OPTION_ARMIES,armies1,armies2 ); } return TEG_STATUS_SUCCESS; }
/** * @fn TEG_STATUS set_sensitive_tb(void) * 'prende' y 'apaga' los botones segun el estado del game */ TEG_STATUS set_sensitive_tb(void) { PLAYER_STATUS e = ESTADO_GET(); /* CONNECT & START */ if( e == PLAYER_STATUS_DESCONECTADO ) { gtk_widget_set_sensitive( game_menu_uiinfo[ON_CONNECT].widget,TRUE); gtk_widget_set_sensitive( game_menu_uiinfo[ON_DISCONNECT].widget,FALSE); gtk_widget_set_sensitive( actions_menu_uiinfo[ON_START].widget,FALSE); gtk_widget_set_sensitive (SensiData.connect_button, TRUE); gtk_widget_set_sensitive (SensiData.start_button, FALSE); } else if( e == PLAYER_STATUS_HABILITADO ) { gtk_widget_set_sensitive( game_menu_uiinfo[ON_CONNECT].widget,FALSE); gtk_widget_set_sensitive( game_menu_uiinfo[ON_DISCONNECT].widget,TRUE); gtk_widget_set_sensitive( actions_menu_uiinfo[ON_START].widget,TRUE); gtk_widget_set_sensitive (SensiData.connect_button, FALSE); gtk_widget_set_sensitive (SensiData.start_button, TRUE); } else { gtk_widget_set_sensitive( game_menu_uiinfo[ON_CONNECT].widget,FALSE); gtk_widget_set_sensitive( game_menu_uiinfo[ON_DISCONNECT].widget,TRUE); gtk_widget_set_sensitive( actions_menu_uiinfo[ON_START].widget,FALSE); gtk_widget_set_sensitive (SensiData.connect_button, FALSE); gtk_widget_set_sensitive (SensiData.start_button, FALSE); } if( g_game.with_ggz ) { gtk_widget_set_sensitive( game_menu_uiinfo[ON_CONNECT].widget,FALSE); gtk_widget_set_sensitive (SensiData.connect_button, FALSE); } if( g_game.observer ) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_START].widget,FALSE); gtk_widget_set_sensitive (SensiData.start_button, FALSE); } /* STATUS */ if( e == PLAYER_STATUS_DESCONECTADO ) { gtk_widget_set_sensitive( view_menu_uiinfo[ON_STATUS].widget,FALSE); gtk_widget_set_sensitive (SensiData.status_button, FALSE); } else { gtk_widget_set_sensitive( view_menu_uiinfo[ON_STATUS].widget,TRUE); gtk_widget_set_sensitive (SensiData.status_button, TRUE); } /* ATAQUE */ if( e == PLAYER_STATUS_ATAQUE ) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_ATTACK_RE].widget,TRUE); gtk_widget_set_sensitive( actions_menu_uiinfo[ON_ATTACK_RESET].widget,TRUE); } else { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_ATTACK_RE].widget,FALSE); gtk_widget_set_sensitive( actions_menu_uiinfo[ON_ATTACK_RESET].widget,FALSE); } /* ENVIAR FICHAS */ if( e==PLAYER_STATUS_FICHAS || e==PLAYER_STATUS_FICHAS2 || e==PLAYER_STATUS_FICHASC ) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_FICHAS].widget,TRUE); gtk_widget_set_sensitive (SensiData.enviarfichas_button, TRUE); } else { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_FICHAS].widget,FALSE); gtk_widget_set_sensitive (SensiData.enviarfichas_button, FALSE); } /* REAGRUPE */ if( e==PLAYER_STATUS_ATAQUE || e==PLAYER_STATUS_TROPAS ) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_REGROUP].widget,TRUE); gtk_widget_set_sensitive (SensiData.reagrupe_button, TRUE); } else { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_REGROUP].widget,FALSE); gtk_widget_set_sensitive (SensiData.reagrupe_button, FALSE); } /* GET CARD */ if( e==PLAYER_STATUS_ATAQUE || e==PLAYER_STATUS_TROPAS || e==PLAYER_STATUS_REAGRUPE ) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_GETCARD].widget,TRUE); gtk_widget_set_sensitive (SensiData.getcard_button, TRUE); } else { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_GETCARD].widget,FALSE); gtk_widget_set_sensitive (SensiData.getcard_button, FALSE); } /* END TURN */ if( e==PLAYER_STATUS_ATAQUE || e==PLAYER_STATUS_TROPAS || e==PLAYER_STATUS_REAGRUPE || e==PLAYER_STATUS_TARJETA) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_ENDTURN].widget,TRUE); gtk_widget_set_sensitive (SensiData.endturn_button, TRUE); } else { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_ENDTURN].widget,FALSE); gtk_widget_set_sensitive (SensiData.endturn_button, FALSE); } /* UPDATE MAP */ if( e >= PLAYER_STATUS_START || (g_game.observer && e >= PLAYER_STATUS_CONNECTED) ) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_UPDATEMAP].widget,TRUE); } else { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_UPDATEMAP].widget,FALSE); } /* VIEW CARDS, MISSION */ if( e >= PLAYER_STATUS_START ) { gtk_widget_set_sensitive( view_menu_uiinfo[ON_MISSION].widget,TRUE); gtk_widget_set_sensitive( view_menu_uiinfo[ON_CARDS].widget,TRUE); } else { gtk_widget_set_sensitive( view_menu_uiinfo[ON_MISSION].widget,FALSE); gtk_widget_set_sensitive( view_menu_uiinfo[ON_CARDS].widget,FALSE); } /* LAUNCH ROBOT */ if( e >= PLAYER_STATUS_CONNECTED && e < PLAYER_STATUS_START ) { gtk_widget_set_sensitive( game_menu_uiinfo[ON_LAUNCHROBOT].widget,TRUE); } else { gtk_widget_set_sensitive( game_menu_uiinfo[ON_LAUNCHROBOT].widget,FALSE); } /* SURRENDER */ if( e>=PLAYER_STATUS_START ) { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_SURRENDER].widget,TRUE); } else { gtk_widget_set_sensitive( actions_menu_uiinfo[ON_SURRENDER].widget,FALSE); } /* SCORES */ if( e >= PLAYER_STATUS_CONNECTED ) { gtk_widget_set_sensitive( game_menu_uiinfo[ON_SCORES].widget,TRUE); } else { gtk_widget_set_sensitive( game_menu_uiinfo[ON_SCORES].widget,FALSE); } return TEG_STATUS_SUCCESS; }