Example #1
0
/* 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;
}
Example #2
0
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;
}
Example #3
0
/* returns the quantity of border contries that a country has */
int countries_cantlimitrofes( int p )
{
	int i;
	int cant=0;

	if(p < 0 || p >= COUNTRIES_CANT )
		return -1;

	for(i=0; i < COUNTRIES_CANT; i++ ) {
		if(  countries_eslimitrofe( p, i ) )
			cant++;
	}

	return cant;
}
Example #4
0
/* A player is attacking from src to dst */
STATIC TEG_STATUS token_attack( int fd, char *str )
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int src,dst,src_lost,dst_lost;
	char d_src[3],d_dst[3];
	PSPLAYER pJ_src, pJ_dst;
	int conq = 0;
	int tropas = 0;
	char buffer[4096];

	PLAY_DEBUG("token_attack()\n");

	if( strlen(str)==0)
		goto error;

	if( !SPLAYER_ATAQUE_P(fd,&pJ_src)) {
		if( SPLAYER_TROPAS_P(fd,&pJ_src)) {
			pJ_src->estado=PLAYER_STATUS_ATAQUE;
			pJ_src->country_src = pJ_src->country_dst = -1;
		} else goto error;
	}

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	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( src >= COUNTRIES_CANT || src < 0 || dst >= COUNTRIES_CANT || dst < 0) {
		goto error;
	}

	if( pJ_src->numjug != g_countries[src].numjug || pJ_src->numjug == g_countries[dst].numjug )  {
		goto error;
	}

	if( g_countries[src].ejercitos < 2 || !countries_eslimitrofe( src, dst) ) {
		goto error;
	}

	if( player_whois( g_countries[dst].numjug, &pJ_dst ) != TEG_STATUS_SUCCESS ){
		goto error;
	}

	if( pactos_attack( src, dst ) != TEG_STATUS_SUCCESS )
		goto error;

	/* aviso a todos que hay un attack */
	if( ! g_game.fog_of_war )
		netall_printf( "%s=%d,%d\n",TOKEN_ATAQUE,src,dst );
	else {
		fow_2_netall_printf( src, dst, "%s=%s,%s\n",TOKEN_ATAQUE,"%d","%d" );
	}

	/* so far, attack... */
	aux_token_attack( g_countries[src].ejercitos, g_countries[dst].ejercitos, &src_lost, &dst_lost, d_src, d_dst );

	g_countries[src].ejercitos -= src_lost;
	g_countries[dst].ejercitos -= dst_lost;
	pJ_src->tot_armies -= src_lost;
	pJ_dst->tot_armies -= dst_lost;

	/* updated statistics */
	pJ_src->player_stats.armies_killed += dst_lost;
	pJ_dst->player_stats.armies_killed += src_lost;
	pJ_dst->player_stats.armies_lost += dst_lost;
	pJ_src->player_stats.armies_lost += src_lost;

	/* conquisto el country | country was conquered */
	if( g_countries[dst].ejercitos == 0) {
		PLIST_ENTRY l;

		conq = 1;

		pJ_src->turno_conq++;
		pJ_src->tot_countries++;

		
		g_countries[dst].numjug = pJ_src->numjug;

		g_countries[dst].ejercitos++;		/* se pasa automaticamente */
		g_countries[src].ejercitos--;		/* un ejercito */

		tropas = g_countries[src].ejercitos - 1;	/* cantidad que se pueden pasar */
		if( tropas > 2 )			/* En verdad son 3, pero ya se le paso 1 */
			tropas =2;

		pJ_src->estado = PLAYER_STATUS_TROPAS;
		pJ_src->country_src = src;
		pJ_src->country_dst = dst;
	
		pJ_dst->tot_countries--;

		l= RemoveHeadList( g_countries[dst].next.Blink );
		InsertTailList( &pJ_src->countries, l);

		/* updated statistics */
		pJ_src->player_stats.countries_won ++;
		pJ_dst->player_stats.countries_lost ++;
	}

	/* update the scores */
	stats_score( &pJ_src->player_stats );
	stats_score( &pJ_dst->player_stats );

	/* tell everybody the result of the attack */

	memset( buffer, 0, sizeof(buffer) );

	if( ! g_game.fog_of_war ) {
		netall_printf( "%s=%d,%d,%d,%d,%d,%d,%d,%d\n", TOKEN_DADOS,
			src,d_src[0],d_src[1],d_src[2], dst,d_dst[0],d_dst[1],d_dst[2] );
	} else {
		fow_2_netall_printf( src, dst, "%s=%s,%d,%d,%d,%s,%d,%d,%d\n"
			, TOKEN_DADOS
			, "%d",d_src[0],d_src[1],d_src[2]
			, "%d",d_dst[0],d_dst[1],d_dst[2] );
	}

	if( ! g_game.fog_of_war ) {
		netall_printf( "%s=%d,%d,%d;%s=%d,%d,%d\n",
			TOKEN_COUNTRY, src, g_countries[src].numjug, g_countries[src].ejercitos,
			TOKEN_COUNTRY, dst, g_countries[dst].numjug, g_countries[dst].ejercitos
			);
	} else {
		fow_netall_printf( src, "%s=%d,%d,%d\n", TOKEN_COUNTRY,
				src, g_countries[src].numjug, g_countries[src].ejercitos );

		fow_netall_printf( dst, "%s=%d,%d,%d\n", TOKEN_COUNTRY,
				dst, g_countries[dst].numjug, g_countries[dst].ejercitos );
	}

	if( conq == 1 ) {

		/* Did 'dst' player lose the game ? */
		if( player_is_lost( pJ_dst ) ) {
			con_text_out(M_INF,_("Player %s(%d) lost the game\n"),pJ_dst->name,pJ_dst->numjug);
			netall_printf( "%s=%d\n",TOKEN_LOST, pJ_dst->numjug );
			player_poner_perdio(pJ_dst);
		}

		/* Did 'src' player win the game ? */
		if( mission_chequear( pJ_src ) == TEG_STATUS_GAMEOVER || game_is_finished() ) {
#ifdef WITH_GGZ
			ggz_server_gameover(pJ_src->fd);
#endif
			con_text_out(M_INF,_("Player %s(%d) is the winner! Game Over\n"),pJ_src->name,pJ_src->numjug);
			pJ_src->estado = PLAYER_STATUS_GAMEOVER;
			game_end( pJ_src );
			return TEG_STATUS_SUCCESS;
		}

		net_printf(fd,"%s=%d,%d,%d\n", TOKEN_TROPAS, src,dst,tropas);


		/* in FOW show the boundaries countries */
		if( g_game.fog_of_war ) {
			char buffer[2048];

			memset( buffer, 0, sizeof(buffer) );
			if( fow_fill_with_boundaries( dst, buffer, sizeof(buffer) ) == TEG_STATUS_SUCCESS )
				net_printf( fd, "%s\n", buffer );
		}
	}

	return TEG_STATUS_SUCCESS;
error:
	net_print(fd,TOKEN_ERROR"="TOKEN_ATAQUE"\n");
	return TEG_STATUS_PARSEERROR;
}
Example #5
0
/* Player is regrouping its armies */
STATIC TEG_STATUS token_regroup( int fd, char *str )
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int src,dst,cant;
	int ejer_disp;
	PSPLAYER pJ;

	PLAY_DEBUG("token_regroup()\n");


	if( strlen(str)==0)
		goto error;

	if( player_whoisfd( fd, &pJ ) != TEG_STATUS_SUCCESS )
		goto error;

	if( pJ->estado < PLAYER_STATUS_TURNOSTART || pJ->estado > PLAYER_STATUS_REAGRUPE)
		goto error;

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;


	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;

	if( src >= COUNTRIES_CANT || src < 0 || dst >= COUNTRIES_CANT || dst < 0 || cant <= 0) {
		goto error;
	}

	if( g_countries[src].numjug != pJ->numjug || g_countries[dst].numjug != pJ->numjug ) {
		goto error;
	}

	if( !countries_eslimitrofe( src, dst ))
		goto error;

	ejer_disp = g_countries[src].ejercitos - g_countries[src].ejer_reagrupe - 1;
	if( cant > ejer_disp )
		goto error;

	pJ->estado = PLAYER_STATUS_REAGRUPE;

	g_countries[dst].ejercitos += cant;
	g_countries[dst].ejer_reagrupe += cant;
	g_countries[src].ejercitos -= cant;

	if( ! g_game.fog_of_war )
	{
		netall_printf("%s=%d,%d,%d;%s=%d,%d,%d\n",
			TOKEN_COUNTRY, src,g_countries[src].numjug,g_countries[src].ejercitos,
			TOKEN_COUNTRY, dst,g_countries[dst].numjug,g_countries[dst].ejercitos );
	} else {
		fow_netall_printf( src, "%s=%d,%d,%d\n",
			TOKEN_COUNTRY, src,g_countries[src].numjug,g_countries[src].ejercitos );
		fow_netall_printf( dst, "%s=%d,%d,%d\n",
			TOKEN_COUNTRY, dst,g_countries[dst].numjug,g_countries[dst].ejercitos );
	}

	return TEG_STATUS_SUCCESS;
error:
	net_print(fd,TOKEN_ERROR"="TOKEN_REAGRUPE"\n");
	return TEG_STATUS_PARSEERROR;
}