/** * @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; }
/* you can move some armies to the conquered country */ TEG_STATUS clitok_tropas( char *str) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; int src,dst,cant; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { src = atoi( p.token ); } else goto error; if( parser_call( &p ) && p.hay_otro ) { dst = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { cant = atoi( p.token ); } else goto error; ESTADO_SET(PLAYER_STATUS_TROPAS); gui_tropas( src,dst,cant); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_tropas()"); return TEG_STATUS_ERROR; }
/* Informs that a player has surrender */ TEG_STATUS clitok_surrender( char *str ) { int numjug; PCPLAYER pJ; numjug = atoi( str ); if( player_whois( numjug, &pJ) != TEG_STATUS_SUCCESS) { /* no lo tengo en la base */ textmsg( M_IMP,_("Player %d abandoned the game"), numjug ); return TEG_STATUS_SUCCESS; } textmsg( M_IMP,_("Player %s(%s) abandoned the game"), pJ->name, _(g_colores[pJ->color]) ); if( pJ->numjug == WHOAMI() ) { ESTADO_SET(PLAYER_STATUS_GAMEOVER); gui_sensi(); } out_countries(); gui_surrender(numjug); return TEG_STATUS_SUCCESS; }
/* the game have just started */ TEG_STATUS clitok_start(char *str) { CPLAYER j; PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ '/', '/', '/' }; int i; if( strlen(str)==0 ) goto error; p.igualador = &igualador; p.separador = &separador; p.data = str; player_flush(); do { if( (i=parser_call( &p )) ) { if( aux_status( &j, p.token ) != TEG_STATUS_SUCCESS ) goto error; player_ins( &j ); } } while( i && p.hay_otro); ESTADO_SET(PLAYER_STATUS_START); out_countries(); gui_start(); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_start()"); return TEG_STATUS_ERROR; }
/* it's someone turn */ TEG_STATUS clitok_turno( char *str) { int numjug; PCPLAYER pJ; PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && !p.hay_otro ) { numjug = atoi( p.token ); } else goto error; if( player_whois( numjug, &pJ) != TEG_STATUS_SUCCESS) goto error; g_game.whos_turn = numjug; attack_unshow(); out_countries(); if( numjug == g_game.numjug ) { ESTADO_SET(PLAYER_STATUS_ATAQUE); /* cosas a hacer cuando yo comienzo un nuevo turno */ reagrupe_bigreset(); attack_init(); textmsg(M_INF,_("It's your turn to attack!!")); } else { /* No es mi turno, entonces yo tengo que estar en idle */ textmsg(M_IMP,_("Player %s(%s) has the turn to attack!"), pJ->name, _(g_colores[pJ->color]) ); ESTADO_SET(PLAYER_STATUS_IDLE); } gui_turn( pJ ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_turno()"); return TEG_STATUS_ERROR; }
/* I reconnected to the server */ TEG_STATUS clitok_reconnect( char *str) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { strncpy( g_game.myname, p.token, sizeof(g_game.myname)-1); g_game.myname[sizeof(g_game.myname)-1]=0; } else goto error; if( parser_call( &p ) && p.hay_otro ) { g_game.numjug = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { g_game.mycolor = atoi( p.token ); } else goto error; ESTADO_SET(PLAYER_STATUS_IDLE); textmsg( M_IMP,_("Successful reconnection. I'm player number:%d"),g_game.numjug ); { /* insert myself in the list of players */ CPLAYER j; PCPLAYER pJ; if( player_whois( g_game.numjug, &pJ ) != TEG_STATUS_SUCCESS ) { memset(&j,0,sizeof(j)); j.color = g_game.mycolor; j.numjug = g_game.numjug; strncpy(j.name,g_game.myname,sizeof(j.name)-1); j.name[sizeof(j.name)-1]=0; player_ins(&j); } } out_status(); out_countries(); out_enum_cards(); out_get_typeofgame(); out_new_round(); gui_reconnected(); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_reconnect()"); return TEG_STATUS_ERROR; }
TEG_STATUS fichasc_restore_from_error() { ESTADO_SET( PLAYER_STATUS_FICHASC ); fichas_reset(); aux_draw_all_countries(); gui_sensi(); return TEG_STATUS_SUCCESS; }
/* someone is placing the continents armies */ TEG_STATUS clitok_fichasc( char *str) { int numjug; int cant,tot_cant; unsigned long conts; PCPLAYER j; PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { numjug = atoi( p.token ); } else goto error; if( parser_call( &p ) && p.hay_otro ) { conts = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { cant = atoi( p.token ); } else goto error; if( player_whois( numjug, &j) != TEG_STATUS_SUCCESS) goto error; attack_unshow(); g_game.whos_turn = numjug; gui_sensi(); tot_cant = cont_tot( conts ) + cant; out_countries(); if( numjug == g_game.numjug ) { ESTADO_SET(PLAYER_STATUS_FICHASC); fichas_init( tot_cant, conts ); gui_fichas(cant,conts); } else { textmsg(M_INF,_("Player %s(%s) is placing %d armies"), j->name, _(g_colores[j->color]), cant); } return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_fichasc()"); return TEG_STATUS_ERROR; }
/* a new player enters the game */ TEG_STATUS clitok_newplayer( char *str) { char name[PLAYERNAME_MAX_LEN]; int color,numjug; PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; CPLAYER j; PCPLAYER pJ; if( strlen(str)==0 ) goto error; p.igualador = &igualador; p.separador = &separador; p.data = str; if( parser_call( &p ) && p.hay_otro ) { strncpy( name, p.token, sizeof(name)-1 ); name[sizeof(name)-1]=0; } else goto error; if( parser_call( &p ) && p.hay_otro ) { numjug = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { color = atoi( p.token ); } else goto error; if( player_whois( numjug, &pJ ) != TEG_STATUS_SUCCESS ) { memset(&j,0,sizeof(j)); j.color = color; j.numjug = numjug; strncpy(j.name,name,sizeof(j.name)-1); j.name[sizeof(j.name)-1]=0; player_ins(&j); } else pJ->color = color; if( numjug == WHOAMI() ) { g_game.mycolor = color; ESTADO_SET( PLAYER_STATUS_HABILITADO ); textmsg( M_IMP,_("My color is: %s"),_(g_colores[color]) ); } else { textmsg(M_IMP,_("Player[%d] '%s' is connected with color %s"),numjug,name,_(g_colores[color])); } gui_habilitado( numjug ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_newplayer()"); 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; }
/* who am i, and available colors */ TEG_STATUS clitok_playerid( char *str) { char c[TEG_MAX_PLAYERS]; PARSER p; int i; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { strncpy( g_game.myname, p.token, sizeof(g_game.myname)-1); g_game.myname[sizeof(g_game.myname)-1]=0; } else goto error; if( parser_call( &p ) && p.hay_otro ) { g_game.numjug = atoi( p.token ); } else goto error; for(i=0;i<TEG_MAX_PLAYERS-1;i++ ) { if( parser_call( &p ) && p.hay_otro ) { c[i] = atoi( p.token ); } else goto error; } if( parser_call( &p ) && !p.hay_otro ) { c[i] = atoi( p.token ); } else goto error; ESTADO_SET(PLAYER_STATUS_CONNECTED); out_status(); if( g_game.observer ) out_countries(); gui_connected( c ); textmsg( M_IMP,_("I'm player number:%d"),g_game.numjug ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_playerid()"); return TEG_STATUS_ERROR; }
/* a player won the game */ TEG_STATUS clitok_winner( char *str ) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; int numjug; int mission; PCPLAYER pJ; p.igualador = &igualador; p.separador = &separador; p.data = str; if( strlen(str)==0 ) goto error; if( parser_call( &p ) && p.hay_otro ) { numjug = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { mission = atoi( p.token ); } else goto error; if( player_whois( numjug, &pJ) != TEG_STATUS_SUCCESS) goto error; if( mission == -1 ) mission = 0; if( mission < 0 || mission >= missions_cant() ) goto error; textmsg( M_IMP,_("Player %s(%s) is the WINNER"), pJ->name, _(g_colores[pJ->color]) ); gui_winner( pJ->numjug, mission ); ESTADO_SET( PLAYER_STATUS_HABILITADO ); gui_sensi(); game_finalize(); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_winner()"); return TEG_STATUS_ERROR; }
/* 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; }
/* 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; }
/* a player lost the game */ TEG_STATUS clitok_lost( char *str ) { int numjug; PCPLAYER pJ; numjug = atoi( str ); if( player_whois( numjug, &pJ) != TEG_STATUS_SUCCESS) goto error; textmsg( M_IMP,_("Player %s(%s) lost the game\n"), pJ->name, _(g_colores[pJ->color]) ); if( pJ->numjug == WHOAMI() ) ESTADO_SET(PLAYER_STATUS_GAMEOVER); gui_lost( pJ->numjug ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_lost()"); return TEG_STATUS_ERROR; }