1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-01-27 14:09:24 +01:00

Success counter. Minor fixes.

This commit is contained in:
gyboth 2005-04-24 10:17:20 +00:00
parent a62634bfde
commit f924bb977e
10 changed files with 147 additions and 42 deletions

View File

@ -105,8 +105,6 @@ cup_load_choose_teams(Cup *cup)
GArray *leagues = NULL;
GPtrArray *sids = NULL;
free_teams_array(&cup->teams, TRUE);
for(i=0;i<cup->choose_teams->len;i++)
{
choose_team = &g_array_index(cup->choose_teams, CupChooseTeam, i);
@ -524,9 +522,9 @@ cup_compare_success_tables(const Team *tm1, const Team *tm2, const Cup *cup, gin
{
for(i=0;i<cupround->tables->len;i++)
for(j=0;j<g_array_index(cupround->tables, Table, i).elements->len;j++)
if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm1)
if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team_id == tm1->id)
elem1 = &g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j);
else if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm2)
else if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team_id == tm2->id)
elem2 = &g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j);
return_value = table_element_compare_func(elem1, elem2, GINT_TO_POINTER(cup->id));

View File

@ -57,11 +57,21 @@ fixture_write_league_fixtures(League *league)
void
fixture_write_cup_fixtures(Cup *cup)
{
gint i, j;
GPtrArray *teams = NULL;
g_array_free(cup->fixtures, TRUE);
cup->fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture));
for(i=0;i<cup->rounds->len;i++)
{
for(j=0;j<g_array_index(cup->rounds, CupRound, i).tables->len;j++)
free_table(&g_array_index(g_array_index(cup->rounds, CupRound, i).tables, Table, j));
g_array_free(g_array_index(cup->rounds, CupRound, i).tables, TRUE);
g_array_index(cup->rounds, CupRound, i).tables = g_array_new(FALSE, FALSE, sizeof(Table));
}
if(cup->type == CUP_TYPE_INTERNATIONAL)
teams = cup_get_team_pointers(cup);
else
@ -298,12 +308,6 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
main_exit_program(EXIT_FIXTURE_WRITE_ERROR, NULL);
}
for(i=0;i<cupround->tables->len;i++)
free_table(&g_array_index(cupround->tables, Table, i));
g_array_free(cupround->tables, TRUE);
cupround->tables = g_array_new(FALSE, FALSE, sizeof(Table));
for(i=0;i<number_of_groups;i++)
{
new_table.name = g_string_new(cup->name->str);
@ -386,8 +390,11 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, GPtrArray *teams)
}
if(len % 2 != 0)
main_exit_program(EXIT_FIXTURE_WRITE_ERROR,
"fixture_write_round_robin: round robin for an odd number of teams is not supported.\n");
{
g_warning("fixture_write_round_robin: round robin for an odd number of teams (%d) is not supported (cup %s).\n",
len, league_cup_get_name_string(clid));
main_exit_program(EXIT_FIXTURE_WRITE_ERROR, "");
}
/* first half of fixtures */
for(i=0;i<len - 1;i++)

View File

@ -872,7 +872,8 @@ void
game_post_match(Fixture *fix)
{
gint i;
User *user = NULL;
GPtrArray *teams = NULL;
Cup *cup = NULL;
if(query_fixture_has_tables(fix))
table_update(fix);
@ -886,24 +887,30 @@ game_post_match(Fixture *fix)
team_update_post_match(fix->teams[i], fix->clid);
}
if(fix->clid < ID_CUP_START || fixture_user_team_involved(fix) == -1)
if(fix->clid < ID_CUP_START ||
(fix->clid >= ID_PROM_CUP_START && fix->clid < ID_SUPERCUP_START))
return;
user = &usr(fixture_user_team_involved(fix));
cup = cup_from_clid(fix->clid);
if(fix->round == cup_from_clid(fix->clid)->rounds->len - 1 &&
fix == &g_array_index((league_cup_get_fixtures(fix->clid)), Fixture,
(league_cup_get_fixtures(fix->clid))->len - 1))
if(fix->round == cup->rounds->len - 1 &&
fix == &g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1))
{
if((Team*)fixture_winner_of(fix, FALSE) == user->tm)
user_history_add(user, USER_HISTORY_WIN_FINAL, user->team_id, fix->clid, fix->round,
fix->teams[fix->teams[0] != user->tm]->name->str);
else
user_history_add(user, USER_HISTORY_LOSE_FINAL, user->team_id, fix->clid, fix->round,
fix->teams[fix->teams[0] != user->tm]->name->str);
teams = cup_get_teams_sorted(cup);
if(team_is_user((Team*)g_ptr_array_index(teams, 0)) != -1)
user_history_add(&usr(team_is_user((Team*)g_ptr_array_index(teams, 0))),
USER_HISTORY_WIN_FINAL, ((Team*)g_ptr_array_index(teams, 0))->id,
fix->clid, fix->round,((Team*)g_ptr_array_index(teams, 1))->name->str);
else if(team_is_user((Team*)g_ptr_array_index(teams, 1)) != -1)
user_history_add(&usr(team_is_user((Team*)g_ptr_array_index(teams, 1))),
USER_HISTORY_LOSE_FINAL, ((Team*)g_ptr_array_index(teams, 1))->id,
fix->clid, fix->round,((Team*)g_ptr_array_index(teams, 0))->name->str);
g_ptr_array_free(teams, TRUE);
}
else
user_history_add(user, USER_HISTORY_REACH_CUP_ROUND, user->team_id,
else if(fixture_user_team_involved(fix) != -1)
user_history_add(&usr(fixture_user_team_involved(fix)), USER_HISTORY_REACH_CUP_ROUND,
usr(fixture_user_team_involved(fix)).team_id,
fix->clid, fix->round, "");
}

View File

@ -118,7 +118,7 @@ main (gint argc, gchar *argv[])
stat0 = STATUS_TEAM_SELECTION;
/*d*/
on_button_add_player_clicked(NULL, NULL);
/* on_button_add_player_clicked(NULL, NULL); */
gtk_main ();

View File

@ -77,13 +77,6 @@ start_new_season(void)
usr(i).tm = team_of_id(usr(i).team_id);
}
for(i=0;i<ligs->len;i++)
{
if(season > 1)
league_season_start(&lig(i));
fixture_write_league_fixtures(&lig(i));
}
start_load_cup_teams();
for(i=acps->len - 1;i >= 0;i--)
@ -93,6 +86,14 @@ start_new_season(void)
else
fixture_write_cup_fixtures(&cp(i));
}
for(i=0;i<ligs->len;i++)
{
if(season > 1)
league_season_start(&lig(i));
fixture_write_league_fixtures(&lig(i));
}
}
/** Fill some global variables with default values at the
@ -137,6 +138,16 @@ start_load_cup_teams(void)
for(i=0;i<cps->len;i++)
if(cp(i).type == CUP_TYPE_INTERNATIONAL)
{
free_teams_array(&cp(i).teams, TRUE);
g_ptr_array_free(cp(i).user_teams, TRUE);
cp(i).user_teams = g_ptr_array_new();
}
for(i=0;i<cps->len;i++)
if(cp(i).type == CUP_TYPE_INTERNATIONAL)
{
printf("nam %s \n ", cp(i).name->str);
cup_load_choose_teams(&cp(i));
cup_load_choose_team_user(&cp(i));
}
@ -349,6 +360,9 @@ start_week(void)
(*start_func)();
start_func++;
}
/*d*/
printf("succ %d \n ", usr(0).counters[COUNT_USER_SUCCESS]);
}
/** Age increase etc. of players.

View File

@ -126,7 +126,7 @@ table_element_compare_func(gconstpointer a,
GArray *fixtures;
const Fixture *fix[2] = {NULL, NULL};
if(element1->team == element2->team)
if(element1->team_id == element2->team_id)
return 0;
clid = GPOINTER_TO_INT(clid_pointer);
@ -166,11 +166,11 @@ table_element_compare_func(gconstpointer a,
g_array_index(fixtures, Fixture, i).week_number <= week &&
g_array_index(fixtures, Fixture, i).week_round_number <= week_round)
{
if(g_array_index(fixtures, Fixture, i).teams[0] == element1->team &&
g_array_index(fixtures, Fixture, i).teams[1] == element2->team)
if(g_array_index(fixtures, Fixture, i).team_ids[0] == element1->team_id &&
g_array_index(fixtures, Fixture, i).team_ids[1] == element2->team_id)
fix[0] = &g_array_index(fixtures, Fixture, i);
else if(g_array_index(fixtures, Fixture, i).teams[1] == element1->team &&
g_array_index(fixtures, Fixture, i).teams[0] == element2->team)
else if(g_array_index(fixtures, Fixture, i).team_ids[1] == element1->team_id &&
g_array_index(fixtures, Fixture, i).team_ids[0] == element2->team_id)
fix[1] = &g_array_index(fixtures, Fixture, i);
}
}

View File

@ -266,7 +266,7 @@ query_is_in_international_cups(const Team *tm)
if(tm == g_ptr_array_index(cp(i).user_teams, j))
return TRUE;
}
return FALSE;
}
@ -475,7 +475,7 @@ team_get_cup_rank(const Team *tm, const CupRound *cupround)
for(i=0;i<cupround->tables->len;i++)
{
for(j=0;j<g_array_index(cupround->tables, Table, i).elements->len;j++)
if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm)
if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team_id == tm->id)
return j + 1;
}

View File

@ -223,6 +223,12 @@ user_from_team(const Team *tm)
void
user_weekly_update_counters(User *user)
{
gint rank = team_get_league_rank(user->tm);
gint teamslen = (league_cup_get_teams(user->tm->clid))->len;
gint rank_bounds[2] = {(gint)rint(const_float("float_user_success_table_bound_upper") *
(gfloat)teamslen),
(gint)rint(const_float("float_user_success_table_bound_lower") *
(gfloat)teamslen)};
gint *cnts = user->counters;
gint increase_capacity;
gfloat increase_safety;
@ -252,6 +258,18 @@ user_weekly_update_counters(User *user)
cnts[COUNT_USER_STADIUM_SAFETY] =
MAX(cnts[COUNT_USER_STADIUM_SAFETY] - (gint)rint(increase_safety * 100), 0);
}
if(rank < rank_bounds[0])
user->counters[COUNT_USER_SUCCESS] += (rank_bounds[0] - rank);
else if(rank > rank_bounds[1])
user->counters[COUNT_USER_SUCCESS] -= (rank - rank_bounds[1]);
else
{
if(user->counters[COUNT_USER_SUCCESS] > 0)
user->counters[COUNT_USER_SUCCESS] -= const_int("int_user_success_mediocre_rank_change");
else
user->counters[COUNT_USER_SUCCESS] += const_int("int_user_success_mediocre_rank_change");
}
}
/** Return a default new user event. */
@ -526,6 +544,46 @@ user_history_add(User *user, gint type, gint team_id,
}
}
if(type == USER_HISTORY_WIN_FINAL)
{
if(cup_from_clid(value1)->type == CUP_TYPE_INTERNATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_international_winner");
else if(cup_from_clid(value1)->type == CUP_TYPE_NATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_national_winner");
}
else if(type == USER_HISTORY_LOSE_FINAL)
{
if(cup_from_clid(value1)->type == CUP_TYPE_INTERNATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_international_final");
else if(cup_from_clid(value1)->type == CUP_TYPE_NATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_national_final");
}
else if(type == USER_HISTORY_REACH_CUP_ROUND)
{
if(value2 == cup_from_clid(value1)->rounds->len - 2)
{
if(cup_from_clid(value1)->type == CUP_TYPE_INTERNATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_international_semis");
else if(cup_from_clid(value1)->type == CUP_TYPE_NATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_national_semis");
}
else if(value2 == cup_from_clid(value1)->rounds->len - 3)
{
if(cup_from_clid(value1)->type == CUP_TYPE_INTERNATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_international_quarter");
else if(cup_from_clid(value1)->type == CUP_TYPE_NATIONAL)
user->counters[COUNT_USER_SUCCESS] +=
const_int("int_user_success_national_quarter");
}
}
his->season = season;
his->week = week;

View File

@ -21,7 +21,7 @@ int_opt_player_precision 0
int_opt_live_game_player_list_refresh 48
# whether some debugging info's shown (in the console)
int_opt_debug 0
int_opt_debug 60
string_opt_player_names_file player_names.xml
string_opt_constants_file bygfoot_constants

View File

@ -193,6 +193,27 @@ float_player_max_skill 990000
int_initial_money_lower 80
int_initial_money_upper 110
# below and above which percentages of ranks
# in the league table the user's success counter
# gets incremented or decremented
float_user_success_table_bound_upper 3000
float_user_success_table_bound_lower 7000
# how many points the user loses or gains (so that
# his success counter converges to 0) if the team
# rank is between the above bounds
int_user_success_mediocre_rank_change 2
# success points for reaching some cup rounds
int_user_success_international_winner 80
int_user_success_international_final 70
int_user_success_international_semis 60
int_user_success_international_quarter 40
int_user_success_national_winner 70
int_user_success_national_final 60
int_user_success_national_semis 50
int_user_success_national_quarter 30
# how often a user may overdraw his bank account
int_finance_overdraw_limit 3
# how many weeks until he's got to be positive