#include "file.h" #include "misc.h" #include "player.h" #include "team.h" #include "xml.h" #include "xml_loadsave_teams.h" enum { TAG_TEAMS = TAG_START_TEAMS, TAG_TEAM, TAG_TEAM_STRUCTURE, TAG_TEAM_STYLE, TAG_TEAM_BOOST, TAG_TEAM_CLID, TAG_TEAM_STADIUM, TAG_TEAM_STADIUM_CAPACITY, TAG_TEAM_STADIUM_AVERAGE_ATTENDANCE, TAG_TEAM_STADIUM_POSSIBLE_ATTENDANCE, TAG_TEAM_STADIUM_GAMES, TAG_TEAM_STADIUM_SAFETY, TAG_TEAM_PLAYER, TAG_TEAM_PLAYER_NAME, TAG_TEAM_PLAYER_POS, TAG_TEAM_PLAYER_CPOS, TAG_TEAM_PLAYER_HEALTH, TAG_TEAM_PLAYER_RECOVERY, TAG_TEAM_PLAYER_ID, TAG_TEAM_PLAYER_VALUE, TAG_TEAM_PLAYER_WAGE, TAG_TEAM_PLAYER_OFFERS, TAG_TEAM_PLAYER_SKILL, TAG_TEAM_PLAYER_CSKILL, TAG_TEAM_PLAYER_TALENT, TAG_TEAM_PLAYER_ETAL, TAG_TEAM_PLAYER_FITNESS, TAG_TEAM_PLAYER_LSU, TAG_TEAM_PLAYER_AGE, TAG_TEAM_PLAYER_PEAK_AGE, TAG_TEAM_PLAYER_CONTRACT, TAG_TEAM_PLAYER_PARTICIPATION, TAG_TEAM_PLAYER_GAMES_GOAL, TAG_TEAM_PLAYER_GAMES_GOAL_CLID, TAG_TEAM_PLAYER_GAMES_GOAL_GAMES, TAG_TEAM_PLAYER_GAMES_GOAL_GOALS, TAG_TEAM_PLAYER_GAMES_GOAL_SHOTS, TAG_TEAM_PLAYER_CARD, TAG_TEAM_PLAYER_CARD_CLID, TAG_TEAM_PLAYER_CARD_YELLOW, TAG_TEAM_PLAYER_CARD_RED, TAG_END }; gint state, etalidx; GArray *teams_array; Team new_team; Player new_player; PlayerGamesGoals new_games_goals; PlayerCard new_card; void xml_loadsave_teams_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_TEAMS;ilen;i++) for(j=0;jlen;j++) g_array_index(g_array_index(teams, Team, i).players, Player, j).team = &g_array_index(teams, Team, i); } void xml_loadsave_teams_write(const gchar *filename, const GArray *teams) { gint i; FILE *fil = NULL; file_my_fopen(filename, "w", &fil, TRUE); fprintf(fil, "<_%d>\n", TAG_TEAMS); for(i=0;ilen;i++) xml_loadsave_teams_write_team(fil, &g_array_index(teams, Team, i)); fprintf(fil, "\n", TAG_TEAMS); fclose(fil); } void xml_loadsave_teams_write_team(FILE *fil, const Team* team) { gint i; fprintf(fil, "<_%d>\n", TAG_TEAM); xml_write_g_string(fil, team->name, TAG_NAME, I1); xml_write_g_string(fil, team->symbol, TAG_SYMBOL, I1); xml_write_int(fil, team->clid, TAG_TEAM_CLID, I1); xml_write_int(fil, team->id, TAG_TEAM_ID, I1); xml_write_int(fil, team->structure, TAG_TEAM_STRUCTURE, I1); xml_write_int(fil, team->style, TAG_TEAM_STYLE, I1); xml_write_int(fil, team->boost, TAG_TEAM_BOOST, I1); fprintf(fil, "%s<_%d>\n", I1, TAG_TEAM_STADIUM); xml_write_int(fil, team->stadium.capacity, TAG_TEAM_STADIUM_CAPACITY, I2); xml_write_int(fil, team->stadium.average_attendance, TAG_TEAM_STADIUM_AVERAGE_ATTENDANCE, I2); xml_write_int(fil, team->stadium.possible_attendance, TAG_TEAM_STADIUM_POSSIBLE_ATTENDANCE, I2); xml_write_int(fil, team->stadium.games, TAG_TEAM_STADIUM_GAMES, I2); xml_write_float(fil, team->stadium.safety, TAG_TEAM_STADIUM_SAFETY, I2); fprintf(fil, "%s\n", I1, TAG_TEAM_STADIUM); for(i=0;iplayers->len;i++) xml_loadsave_teams_write_player(fil, &g_array_index(team->players, Player, i)); fprintf(fil, "\n", TAG_TEAM); } void xml_loadsave_teams_write_player(FILE *fil, const Player *pl) { gint i; fprintf(fil, "%s<_%d>\n", I1, TAG_TEAM_PLAYER); xml_write_g_string(fil, pl->name, TAG_TEAM_PLAYER_NAME, I2); xml_write_int(fil, pl->pos, TAG_TEAM_PLAYER_POS, I2); xml_write_int(fil, pl->cpos, TAG_TEAM_PLAYER_CPOS, I2); xml_write_int(fil, pl->health, TAG_TEAM_PLAYER_HEALTH, I2); xml_write_int(fil, pl->recovery, TAG_TEAM_PLAYER_RECOVERY, I2); xml_write_int(fil, pl->id, TAG_TEAM_PLAYER_ID, I2); xml_write_int(fil, pl->value, TAG_TEAM_PLAYER_VALUE, I2); xml_write_int(fil, pl->wage, TAG_TEAM_PLAYER_WAGE, I2); xml_write_int(fil, pl->offers, TAG_TEAM_PLAYER_OFFERS, I2); xml_write_int(fil, pl->participation, TAG_TEAM_PLAYER_PARTICIPATION, I2); xml_write_float(fil, pl->skill, TAG_TEAM_PLAYER_SKILL, I2); xml_write_float(fil, pl->cskill, TAG_TEAM_PLAYER_CSKILL, I2); xml_write_float(fil, pl->talent, TAG_TEAM_PLAYER_TALENT, I2); xml_write_float(fil, pl->fitness, TAG_TEAM_PLAYER_FITNESS, I2); xml_write_float(fil, pl->lsu, TAG_TEAM_PLAYER_LSU, I2); xml_write_float(fil, pl->age, TAG_TEAM_PLAYER_AGE, I2); xml_write_float(fil, pl->peak_age, TAG_TEAM_PLAYER_PEAK_AGE, I2); xml_write_float(fil, pl->contract, TAG_TEAM_PLAYER_CONTRACT, I2); for(i=0;i<4;i++) xml_write_float(fil, pl->etal[i], TAG_TEAM_PLAYER_ETAL, I3); for(i=0;igames_goals->len;i++) { fprintf(fil, "%s<_%d>\n", I2, TAG_TEAM_PLAYER_GAMES_GOAL); xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).clid, TAG_TEAM_PLAYER_GAMES_GOAL_CLID, I3); xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).games, TAG_TEAM_PLAYER_GAMES_GOAL_GAMES, I3); xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).goals, TAG_TEAM_PLAYER_GAMES_GOAL_GOALS, I3); xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).shots, TAG_TEAM_PLAYER_GAMES_GOAL_SHOTS, I3); fprintf(fil, "%s\n", I2, TAG_TEAM_PLAYER_GAMES_GOAL); } for(i=0;icards->len;i++) { fprintf(fil, "%s<_%d>\n", I2, TAG_TEAM_PLAYER_CARD); xml_write_int(fil, g_array_index(pl->cards, PlayerCard, i).clid, TAG_TEAM_PLAYER_CARD_CLID, I3); xml_write_int(fil, g_array_index(pl->cards, PlayerCard, i).yellow, TAG_TEAM_PLAYER_CARD_YELLOW, I3); xml_write_int(fil, g_array_index(pl->cards, PlayerCard, i).red, TAG_TEAM_PLAYER_CARD_RED, I3); fprintf(fil, "%s\n", I2, TAG_TEAM_PLAYER_CARD); } fprintf(fil, "%s\n", I1, TAG_TEAM_PLAYER); }