/* the mouse is over a country */ TEG_STATUS attack_enter( PCOUNTRY p ) { if( attack_check() != TEG_STATUS_SUCCESS ) { return TEG_STATUS_UNEXPECTED; } if( country_origen == -1 ) { if(p->numjug == WHOAMI()) { if( p->ejercitos >1 ) { if( !(p->selected & COUNTRY_SELECT_ATTACK_ENTER)) { p->selected |= COUNTRY_SELECT_ATTACK_ENTER; gui_country_select(p->id); } } } } else if( country_destino == -1 ) { if(p->numjug != WHOAMI() ) { if( countries_eslimitrofe(country_origen, p->id) ) { if( !(p->selected & COUNTRY_SELECT_ATTACK_ENTER)) { p->selected |= COUNTRY_SELECT_ATTACK_ENTER; gui_country_select(p->id); } } } } return TEG_STATUS_SUCCESS; }
TEG_STATUS attack_click( PCOUNTRY p ) { if( attack_check() != TEG_STATUS_SUCCESS ) { textmsg(M_ERR,_("Error, It's not the time to attack")); return TEG_STATUS_UNEXPECTED; } if( country_origen == -1 ) { if(p->numjug == WHOAMI()) { if( p->ejercitos >1 ) { p->selected &= ~COUNTRY_SELECT_ATTACK_ENTER; p->selected |= COUNTRY_SELECT_ATTACK; gui_country_select(p->id); country_origen = p->id; textmsg(M_INF,_("Source country: '%s'. Now select the destination country"),countries_get_name(p->id)); } else { textmsg(M_ERR,_("Error, '%s' must have at least 2 armies"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } } else { textmsg(M_ERR,_("Error, '%s' isn't one of your countries"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } } else if( country_destino == -1 ) { if( country_origen == p->id ) { textmsg(M_INF,_("Source country is the same as the destination. Resetting the attack...")); attack_reset(); return TEG_STATUS_SUCCESS; } if(p->numjug != WHOAMI() ) { if( countries_eslimitrofe(country_origen, p->id) ) { p->selected &= ~COUNTRY_SELECT_ATTACK_ENTER; p->selected |= COUNTRY_SELECT_ATTACK; gui_country_select(p->id); country_destino = p->id; textmsg(M_INF,_("Destination country: '%s'. Attacking..."),countries_get_name(p->id)); attack_out(); } else { textmsg(M_ERR,_("Error, '%s' isn't frontier with '%s'"),countries_get_name(p->id),countries_get_name(country_origen)); attack_reset(); return TEG_STATUS_UNEXPECTED; } } else { textmsg(M_ERR,_("Error, you can't attack your own countries ('%s')"),countries_get_name(p->id)); attack_reset(); return TEG_STATUS_UNEXPECTED; } } else { attack_reset(); textmsg(M_ERR,_("Error, unexpected error in attack_click(). Report this bug!")); return TEG_STATUS_UNEXPECTED; } return TEG_STATUS_SUCCESS; }
/** * @fn char *ai_fetch_a_name() * Devuelve el name de un player al azar */ char *ai_fetch_a_name() { int i=0; PCPLAYER pJ; PLIST_ENTRY l = g_list_player.Flink; int n; if( g_game.playeres < 2 ) { return NULL; } n = RANDOM_MAX(0, g_game.playeres -1 ); while( !IsListEmpty( &g_list_player ) && (l != &g_list_player) ) { if( (i++) == n ) { pJ = (PCPLAYER) l; if( pJ->numjug == WHOAMI() ) n++; else return pJ->name; } l = LIST_NEXT(l); } return NULL; }
/* a players lost the connection of just quit the game */ TEG_STATUS clitok_exit( 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 exit the game"), numjug ); return TEG_STATUS_SUCCESS; } textmsg( M_IMP,_("Player %s(%s) exit the game"), pJ->name, _(g_colores[pJ->color]) ); /* dont delete the player, I need the status */ /* player_del( pJ ); */ if( WHOAMI() == numjug ) { /* por alguna razon el server quiere que abandone el game */ teg_disconnect(); } return TEG_STATUS_SUCCESS; }
/* 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; }
TEST(LoggerTest, Logging) { int num = 0; NBLA_LOG_TRACE("TRACE LOG {}", num++); NBLA_LOG_DEBUG("DEBUG LOG {}", num++); NBLA_LOG_INFO("INFO LOG {}", num++); NBLA_LOG_WARN("WARN LOG {}", num++); NBLA_LOG_ERROR("ERROR LOG {}", num++); NBLA_LOG_CRITICAL("CRITICAL LOG {}", num++); WHOAMI("%d\n", num++); ; }
/* 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; }
/* src is attacking dst */ TEG_STATUS clitok_attack( char *str) { int src,dst; PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; PCPLAYER pJsrc, pJdst; 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; /* countries are allowed to be -1 (unknown in fog of war) */ if( src<-1 || src>=COUNTRIES_CANT || dst<-1 || dst>=COUNTRIES_CANT ) goto error; pJsrc = NULL; if( src >=0 ) player_whois( g_countries[src].numjug, &pJsrc ); pJdst = NULL; if( dst >=0 ) player_whois( g_countries[dst].numjug, &pJdst ); if( src >= 0 && g_countries[src].numjug == WHOAMI() ) { attack_reset(); } else { attack_show( src, dst ); } if( pJsrc && pJdst ) textmsg(M_INF,_("%s(%s) is attacking %s(%s)"), countries_get_name(src), _(g_colores[pJsrc->color]) ,countries_get_name(dst), _(g_colores[pJdst->color]) ); else textmsg(M_INF,_("%s is attacking %s"),countries_get_name(src), countries_get_name(dst) ); return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_attack()"); return TEG_STATUS_ERROR; }
TEG_STATUS fichas_leave( PCOUNTRY p ) { if( fichas_check() != TEG_STATUS_SUCCESS ) { return TEG_STATUS_ERROR; } if( p->numjug == WHOAMI() ) { p->selected &= ~COUNTRY_SELECT_FICHAS_IN; p->selected &= ~COUNTRY_SELECT_FICHAS_OUT; gui_country_select( p->id ); } return TEG_STATUS_SUCCESS; }
/* 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 sub_fichas( PCOUNTRY p ) * llamada desde la 'gui' y recuerda los countries que se fueron agregando * @params p country que se esta agregando */ TEG_STATUS fichas_sub( PCOUNTRY p ) { if( fichas_check() != TEG_STATUS_SUCCESS ) { textmsg(M_ERR,_("Error, you cant sub armies now")); return TEG_STATUS_UNEXPECTED; } if(p->numjug == WHOAMI() ) { if( aFichas[p->id] ) { fichas_tot--; p->ejercitos--; aFichas[p->id]--; aConts[p->continente]--; fichas_enter( p ); return TEG_STATUS_SUCCESS; } else return TEG_STATUS_UNEXPECTED; } else { textmsg(M_ERR,_("Error, '%s' isnt one of your countries"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } }
/** * @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; } }
TEG_STATUS fichas_enter( PCOUNTRY p ) { if( fichas_check() != TEG_STATUS_SUCCESS ) { return TEG_STATUS_ERROR; } if( p->numjug == WHOAMI() ) { if( fichas_tot >= wanted_tot ) { if(!( p->selected & COUNTRY_SELECT_FICHAS_OUT )) { p->selected &= ~COUNTRY_SELECT_FICHAS_IN; p->selected |= COUNTRY_SELECT_FICHAS_OUT; gui_country_select( p->id ); } } else { if(!( p->selected & COUNTRY_SELECT_FICHAS_IN )) { p->selected &= ~COUNTRY_SELECT_FICHAS_OUT; p->selected |= COUNTRY_SELECT_FICHAS_IN; gui_country_select( p->id ); } } } return TEG_STATUS_SUCCESS; }
/** * @fn TEG_STATUS add_fichas( PCOUNTRY p ) * llamada desde la 'gui' y recuerda los countries que se fueron agregando * @params p country que se esta agregando */ TEG_STATUS fichas_add( PCOUNTRY p ) { if( fichas_check() != TEG_STATUS_SUCCESS ) { textmsg(M_ERR,_("Error, you cant add armies now")); return TEG_STATUS_UNEXPECTED; } if(p->numjug == WHOAMI() ) { if( fichas_tot < wanted_tot ) { fichas_tot++; p->ejercitos++; aFichas[p->id]++; aConts[p->continente]++; return TEG_STATUS_SUCCESS; } else { textmsg(M_ERR,_("Error, you cant put more than %d armies"),wanted_tot); fichas_enter( p ); return TEG_STATUS_ERROR; } } else { textmsg(M_ERR,_("Error, '%s' isnt one of your countries"),countries_get_name(p->id)); return TEG_STATUS_UNEXPECTED; } }
/* 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; }
/* someone has exchanged cards for armies. maybe its me */ TEG_STATUS clitok_exchange(char *str) { PARSER p; DELIM igualador={ ':', ':', ':' }; DELIM separador={ ',', ',', ',' }; int p1,p2,p3; int numjug,cant; PCPLAYER pJ; if( strlen(str)==0 ) goto error; p.igualador = &igualador; p.separador = &separador; p.data = str; if( parser_call( &p ) && p.hay_otro ) { numjug = atoi( p.token ); } else goto error; if( parser_call( &p ) && p.hay_otro ) { cant = atoi( p.token ); } else goto error; if( parser_call( &p ) && p.hay_otro ) { p1 = atoi( p.token ); } else goto error; if( parser_call( &p ) && p.hay_otro ) { p2 = atoi( p.token ); } else goto error; if( parser_call( &p ) && !p.hay_otro ) { p3 = atoi( p.token ); } else goto error; if( player_whois( numjug, &pJ) != TEG_STATUS_SUCCESS) goto error; if( numjug == WHOAMI() ) { PLIST_ENTRY pL = g_game.tarjetas_list.Flink; while( !IsListEmpty( &g_game.tarjetas_list ) && (pL != &g_game.tarjetas_list )) { PCOUNTRY pP; PTARJETA pT = (PTARJETA) pL; pP = (PCOUNTRY ) COUNTRY_FROM_TARJETA( pT ); if( pP->id == p1 || pP->id == p2 || pP->id == p3 ) { PLIST_ENTRY l; g_countries[ pP->id ].tarjeta.numjug = -1; l = RemoveHeadList( pL->Blink ); g_game.tarjetas_cant--; } pL = LIST_NEXT( pL ); } fichas_add_wanted( cant ); textmsg( M_IMP,_("Exchanged approved. Now you can place %d more armies!"),cant); gui_canje(cant,p1,p2,p3); } else { textmsg(M_IMP,_("Player %s(%s) exchanged 3 cards for %d armies"), pJ->name, _(g_colores[pJ->color]), cant); } return TEG_STATUS_SUCCESS; error: textmsg(M_ERR,"Error in clitok_tarjeta()"); return TEG_STATUS_ERROR; }