1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-01-31 16:04:48 +01:00

League stats done.

This commit is contained in:
gyboth 2005-04-30 13:57:58 +00:00
parent 681c112236
commit fdcba17f18
10 changed files with 302 additions and 8 deletions

View File

@ -52,6 +52,7 @@ bygfoot_SOURCES = \
xml_loadsave_cup.c cup.h file.h misc.h table.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \ xml_loadsave_cup.c cup.h file.h misc.h table.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \
xml_loadsave_fixtures.c file.h fixture.h misc.h team.h xml.h xml_loadsave_fixtures.h \ xml_loadsave_fixtures.c file.h fixture.h misc.h team.h xml.h xml_loadsave_fixtures.h \
xml_loadsave_league.c file.h league.h misc.h xml.h xml_loadsave_fixtures.h xml_loadsave_league.h xml_loadsave_table.h xml_loadsave_teams.h \ xml_loadsave_league.c file.h league.h misc.h xml.h xml_loadsave_fixtures.h xml_loadsave_league.h xml_loadsave_table.h xml_loadsave_teams.h \
xml_loadsave_league_stat.c file.h misc.h stat.h team.h xml_loadsave_league_stat.h xml.h \
xml_loadsave_live_game.c cup.h file.h fixture.h league.h live_game.h misc.h variables.h xml.h xml_loadsave_live_game.h \ xml_loadsave_live_game.c cup.h file.h fixture.h league.h live_game.h misc.h variables.h xml.h xml_loadsave_live_game.h \
xml_loadsave_table.c file.h misc.h team.h xml.h xml_loadsave_table.h \ xml_loadsave_table.c file.h misc.h team.h xml.h xml_loadsave_table.h \
xml_loadsave_teams.c file.h misc.h player.h team.h xml.h xml_loadsave_teams.h \ xml_loadsave_teams.c file.h misc.h player.h team.h xml.h xml_loadsave_teams.h \

View File

@ -45,11 +45,7 @@ league_new(gboolean new_id)
new.first_week = new.week_gap = 1; new.first_week = new.week_gap = 1;
new.yellow_red = 1000; new.yellow_red = 1000;
new.stats.clid = new.id; new.stats = stat_league_new(new.id);
new.stats.teams_off = g_array_new(FALSE, FALSE, sizeof(Stat));
new.stats.teams_def = g_array_new(FALSE, FALSE, sizeof(Stat));
new.stats.player_scorers = g_array_new(FALSE, FALSE, sizeof(Stat));
new.stats.player_goalies = g_array_new(FALSE, FALSE, sizeof(Stat));
return new; return new;
} }

View File

@ -937,10 +937,7 @@ live_game_event_duel(void)
const_float("float_live_game_score_team_exponent")); const_float("float_live_game_score_team_exponent"));
if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES) if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES)
{
player_games_goals_set(attacker, match->fix->clid, PLAYER_VALUE_SHOTS, 1, TRUE); player_games_goals_set(attacker, match->fix->clid, PLAYER_VALUE_SHOTS, 1, TRUE);
player_games_goals_set(goalie, match->fix->clid, PLAYER_VALUE_SHOTS, 1, TRUE);
}
if(rndom < scoring_prob) if(rndom < scoring_prob)
{ {
@ -957,6 +954,11 @@ live_game_event_duel(void)
else else
new.event.type = math_gauss_disti(LIVE_GAME_EVENT_POST, LIVE_GAME_EVENT_CROSS_BAR); new.event.type = math_gauss_disti(LIVE_GAME_EVENT_POST, LIVE_GAME_EVENT_CROSS_BAR);
if(new.time != LIVE_GAME_UNIT_TIME_PENALTIES &&
(new.event.type == LIVE_GAME_EVENT_SAVE ||
new.event.type == LIVE_GAME_EVENT_GOAL))
player_games_goals_set(goalie, match->fix->clid, PLAYER_VALUE_SHOTS, 1, TRUE);
g_array_append_val(unis, new); g_array_append_val(unis, new);
live_game_finish_unit(); live_game_finish_unit();

View File

@ -6,6 +6,21 @@
#include "team.h" #include "team.h"
#include "variables.h" #include "variables.h"
/** Return a newly allocated league stat with given clid. */
LeagueStat
stat_league_new(gint clid)
{
LeagueStat new;
new.clid = clid;
new.teams_off = g_array_new(FALSE, FALSE, sizeof(Stat));
new.teams_def = g_array_new(FALSE, FALSE, sizeof(Stat));
new.player_scorers = g_array_new(FALSE, FALSE, sizeof(Stat));
new.player_goalies = g_array_new(FALSE, FALSE, sizeof(Stat));
return new;
}
/** Update the league stats. */ /** Update the league stats. */
void void
stat_update_leagues(void) stat_update_leagues(void)

View File

@ -2,8 +2,12 @@
#define STAT_H #define STAT_H
#include "bygfoot.h" #include "bygfoot.h"
#include "league_struct.h"
#include "stat_struct.h" #include "stat_struct.h"
LeagueStat
stat_league_new(gint clid);
GArray* GArray*
stat_update_league_teams(const GArray *teams, gint compare_type); stat_update_league_teams(const GArray *teams, gint compare_type);

View File

@ -13,6 +13,7 @@
#include "xml_loadsave_cup.h" #include "xml_loadsave_cup.h"
#include "xml_loadsave_fixtures.h" #include "xml_loadsave_fixtures.h"
#include "xml_loadsave_league.h" #include "xml_loadsave_league.h"
#include "xml_loadsave_league_stat.h"
#include "xml_loadsave_live_game.h" #include "xml_loadsave_live_game.h"
#include "xml_loadsave_table.h" #include "xml_loadsave_table.h"
#include "xml_loadsave_teams.h" #include "xml_loadsave_teams.h"
@ -65,6 +66,7 @@ xml_load_leagues(const gchar *dirname, const gchar *basename)
if(!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table.xml") && if(!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_table.xml") &&
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_fixtures.xml") &&
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml") && !g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_teams.xml") &&
!g_str_has_suffix(((GString*)g_ptr_array_index(dir_contents, i))->str, "_stat.xml") &&
!query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_promcup")) !query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str, "_promcup"))
xml_load_league(dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str, xml_load_league(dirname, ((GString*)g_ptr_array_index(dir_contents, i))->str,
dir_contents); dir_contents);
@ -100,6 +102,9 @@ xml_load_league(const gchar *dirname, const gchar *basename, const GPtrArray *di
sprintf(buf, "%s/%s_table.xml", dirname, prefix); sprintf(buf, "%s/%s_table.xml", dirname, prefix);
xml_loadsave_table_read(buf, &lig(ligs->len - 1).table); xml_loadsave_table_read(buf, &lig(ligs->len - 1).table);
sprintf(buf, "%s/%s_stat.xml", dirname, prefix);
xml_loadsave_league_stat_read(buf, &lig(ligs->len - 1).stats);
if(league_has_prom_games((&lig(ligs->len - 1)))) if(league_has_prom_games((&lig(ligs->len - 1))))
{ {
lig(ligs->len - 1).prom_rel.prom_games_cup = cup_new(FALSE); lig(ligs->len - 1).prom_rel.prom_games_cup = cup_new(FALSE);

View File

@ -39,6 +39,7 @@ enum XmlTags
#define TAG_START_USERS 7000 #define TAG_START_USERS 7000
#define TAG_START_LIVE_GAME 8000 #define TAG_START_LIVE_GAME 8000
#define TAG_START_TRANSFERS 9000 #define TAG_START_TRANSFERS 9000
#define TAG_START_LEAGUE_STAT 10000
#define xml_write_string(fil, string, tag, indent) fprintf(fil, "%s<_%d>%s</_%d>\n", indent, tag, string, tag) #define xml_write_string(fil, string, tag, indent) fprintf(fil, "%s<_%d>%s</_%d>\n", indent, tag, string, tag)
#define xml_write_g_string(fil, gstring, tag, indent) xml_write_string(fil, (gstring)->str, tag, indent) #define xml_write_g_string(fil, gstring, tag, indent) xml_write_string(fil, (gstring)->str, tag, indent)

View File

@ -5,6 +5,7 @@
#include "xml_loadsave_cup.h" #include "xml_loadsave_cup.h"
#include "xml_loadsave_fixtures.h" #include "xml_loadsave_fixtures.h"
#include "xml_loadsave_league.h" #include "xml_loadsave_league.h"
#include "xml_loadsave_league_stat.h"
#include "xml_loadsave_table.h" #include "xml_loadsave_table.h"
#include "xml_loadsave_teams.h" #include "xml_loadsave_teams.h"
@ -208,6 +209,9 @@ xml_loadsave_league_write(const gchar *prefix, const League *league)
sprintf(buf, "%s___league_%d_fixtures.xml", prefix, league->id); sprintf(buf, "%s___league_%d_fixtures.xml", prefix, league->id);
xml_loadsave_fixtures_write(buf, league->fixtures); xml_loadsave_fixtures_write(buf, league->fixtures);
sprintf(buf, "%s___league_%d_stat.xml", prefix, league->id);
xml_loadsave_league_stat_write(buf, &league->stats);
sprintf(buf, "%s___league_%d.xml", prefix, league->id); sprintf(buf, "%s___league_%d.xml", prefix, league->id);
file_my_fopen(buf, "w", &fil, TRUE); file_my_fopen(buf, "w", &fil, TRUE);

View File

@ -0,0 +1,232 @@
#include "file.h"
#include "stat.h"
#include "misc.h"
#include "team.h"
#include "xml.h"
#include "xml_loadsave_league_stat.h"
enum
{
TAG_LEAGUE_STAT = TAG_START_LEAGUE_STAT,
TAG_STAT_TEAMS_OFF,
TAG_STAT_TEAMS_DEF,
TAG_STAT_PLAYER_SCORERS,
TAG_STAT_PLAYER_GOALIES,
TAG_STAT,
TAG_STAT_VALUE,
TAG_STAT_VALUE_STRING,
TAG_END
};
gint state, in_state, valueidx;
Stat new_stat;
LeagueStat *lstat;
void
xml_loadsave_league_stat_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error)
{
gint i;
gint tag = xml_get_tag_from_name(element_name);
gboolean valid_tag = FALSE;
for(i=TAG_LEAGUE_STAT;i<TAG_END;i++)
if(tag == i)
{
state = i;
valid_tag = TRUE;
}
for(i=TAG_NAME;i<=TAG_ROUND;i++)
if(tag == i)
{
state = i;
valid_tag = TRUE;
}
if(tag == TAG_STAT)
valueidx = 0;
else if(tag == TAG_STAT_TEAMS_OFF ||
tag == TAG_STAT_TEAMS_DEF ||
tag == TAG_STAT_PLAYER_SCORERS ||
tag == TAG_STAT_PLAYER_GOALIES)
in_state = tag;
if(!valid_tag)
g_warning("xml_loadsave_league_stat_start_element: unknown tag: %s; I'm in state %d\n",
element_name, state);
}
void
xml_loadsave_league_stat_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error)
{
GArray *stat_array = NULL;
gint tag = xml_get_tag_from_name(element_name);
if(tag == TAG_ID ||
tag == TAG_STAT_TEAMS_OFF ||
tag == TAG_STAT_TEAMS_DEF ||
tag == TAG_STAT_PLAYER_SCORERS ||
tag == TAG_STAT_PLAYER_GOALIES)
state = TAG_LEAGUE_STAT;
else if(tag == TAG_STAT)
{
state = in_state;
if(in_state == TAG_STAT_TEAMS_OFF)
stat_array = lstat->teams_off;
else if(in_state == TAG_STAT_TEAMS_DEF)
stat_array = lstat->teams_def;
else if(in_state == TAG_STAT_PLAYER_SCORERS)
stat_array = lstat->player_scorers;
else if(in_state == TAG_STAT_PLAYER_GOALIES)
stat_array = lstat->player_goalies;
else
g_warning("xml_loadsave_league_stat_end_element: unknown in_state %d \n",
in_state);
g_array_append_val(stat_array, new_stat);
}
else if(tag == TAG_STAT_VALUE_STRING ||
tag == TAG_STAT_VALUE ||
tag == TAG_STAT_VALUE_STRING ||
tag == TAG_TEAM_ID)
{
state = TAG_STAT;
if(tag == TAG_STAT_VALUE)
valueidx++;
}
else if(tag != TAG_LEAGUE_STAT)
g_warning("xml_loadsave_league_stat_end_element: unknown tag: %s; I'm in state %d\n",
element_name, state);
}
void
xml_loadsave_league_stat_text (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error)
{
gchar buf[SMALL];
gint int_value = -1;
strncpy(buf, text, text_len);
buf[text_len] = '\0';
int_value = (gint)g_ascii_strtod(buf, NULL);
if(state == TAG_ID)
lstat->clid = int_value;
else if(state == TAG_TEAM_ID)
{
new_stat.team_id = int_value;
new_stat.tm = team_of_id(int_value);
}
else if(state == TAG_STAT_VALUE)
{
if(valueidx == 0)
new_stat.value1 = int_value;
else if(valueidx == 1)
new_stat.value2 = int_value;
else
new_stat.value3 = int_value;
}
else if(state == TAG_STAT_VALUE_STRING)
new_stat.value_string = g_string_new(buf);
}
void
xml_loadsave_league_stat_read(const gchar *filename, LeagueStat *league_stat)
{
GMarkupParser parser = {xml_loadsave_league_stat_start_element,
xml_loadsave_league_stat_end_element,
xml_loadsave_league_stat_text, NULL, NULL};
GMarkupParseContext *context;
gchar *file_contents;
guint length;
GError *error = NULL;
context =
g_markup_parse_context_new(&parser, 0, NULL, NULL);
if(!g_file_get_contents(filename, &file_contents, &length, &error))
{
g_warning("xml_loadsave_league_stat_read: error reading file %s\n", filename);
misc_print_error(&error, TRUE);
}
lstat = league_stat;
if(g_markup_parse_context_parse(context, file_contents, length, &error))
{
g_markup_parse_context_end_parse(context, NULL);
g_markup_parse_context_free(context);
g_free(file_contents);
}
else
{
g_warning("xml_loadsave_league_stat_read: error parsing file %s\n", filename);
misc_print_error(&error, TRUE);
}
}
void
xml_loadsave_league_stat_write(const gchar *filename, const LeagueStat *league_stat)
{
gint i;
FILE *fil = NULL;
file_my_fopen(filename, "w", &fil, TRUE);
fprintf(fil, "<_%d>\n", TAG_LEAGUE_STAT);
xml_write_int(fil, league_stat->clid, TAG_ID, I0);
fprintf(fil, "<_%d>\n", TAG_STAT_TEAMS_OFF);
for(i=0;i<league_stat->teams_off->len;i++)
xml_loadsave_league_stat_write_stat(
fil, &g_array_index(league_stat->teams_off, Stat, i));
fprintf(fil, "</_%d>\n", TAG_STAT_TEAMS_OFF);
fprintf(fil, "<_%d>\n", TAG_STAT_TEAMS_DEF);
for(i=0;i<league_stat->teams_def->len;i++)
xml_loadsave_league_stat_write_stat(
fil, &g_array_index(league_stat->teams_def, Stat, i));
fprintf(fil, "</_%d>\n", TAG_STAT_TEAMS_DEF);
fprintf(fil, "<_%d>\n", TAG_STAT_PLAYER_SCORERS);
for(i=0;i<league_stat->player_scorers->len;i++)
xml_loadsave_league_stat_write_stat(
fil, &g_array_index(league_stat->player_scorers, Stat, i));
fprintf(fil, "</_%d>\n", TAG_STAT_PLAYER_SCORERS);
fprintf(fil, "<_%d>\n", TAG_STAT_PLAYER_GOALIES);
for(i=0;i<league_stat->player_goalies->len;i++)
xml_loadsave_league_stat_write_stat(
fil, &g_array_index(league_stat->player_goalies, Stat, i));
fprintf(fil, "</_%d>\n", TAG_STAT_PLAYER_GOALIES);
fprintf(fil, "</_%d>\n", TAG_LEAGUE_STAT);
fclose(fil);
}
void
xml_loadsave_league_stat_write_stat(FILE *fil, const Stat *stat)
{
fprintf(fil, "%s<_%d>\n", I1, TAG_STAT);
xml_write_int(fil, stat->team_id, TAG_TEAM_ID, I1);
xml_write_int(fil, stat->value1, TAG_STAT_VALUE, I1);
xml_write_int(fil, stat->value2, TAG_STAT_VALUE, I1);
xml_write_int(fil, stat->value3, TAG_STAT_VALUE, I1);
xml_write_g_string(fil, stat->value_string, TAG_STAT_VALUE_STRING, I1);
fprintf(fil, "%s</_%d>\n", I1, TAG_STAT);
}

View File

@ -0,0 +1,34 @@
#ifndef XML_LOADSAVE_LEAGUE_STAT_H
#define XML_LOADSAVE_LEAGUE_STAT_H
#include "bygfoot.h"
#include "stat_struct.h"
void
xml_loadsave_league_stat_write(const gchar *filename, const LeagueStat *league_stat);
void
xml_loadsave_league_stat_write_stat(FILE *fil, const Stat *stat);
void
xml_loadsave_league_stat_start_element (GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer user_data,
GError **error);
void
xml_loadsave_league_stat_end_element (GMarkupParseContext *context,
const gchar *element_name,
gpointer user_data,
GError **error);
void
xml_loadsave_league_stat_text (GMarkupParseContext *context,
const gchar *text,
gsize text_len,
gpointer user_data,
GError **error);
void
xml_loadsave_league_stat_read(const gchar *filename, LeagueStat *league_stat);
#endif