diff --git a/src/xml_loadsave_players.c b/src/xml_loadsave_players.c new file mode 100644 index 00000000..f62b5ecd --- /dev/null +++ b/src/xml_loadsave_players.c @@ -0,0 +1,265 @@ +#include "player.h" +#include "team.h" +#include "xml.h" +#include "xml_loadsave_players.h" + +enum +{ + TAG_PLAYERS = TAG_START_PLAYERS, + TAG_PLAYER, + TAG_PLAYER_NAME, + TAG_PLAYER_POS, + TAG_PLAYER_CPOS, + TAG_PLAYER_HEALTH, + TAG_PLAYER_RECOVERY, + TAG_PLAYER_ID, + TAG_PLAYER_VALUE, + TAG_PLAYER_WAGE, + TAG_PLAYER_OFFERS, + TAG_PLAYER_SKILL, + TAG_PLAYER_CSKILL, + TAG_PLAYER_TALENT, + TAG_PLAYER_ETAL, + TAG_PLAYER_FITNESS, + TAG_PLAYER_LSU, + TAG_PLAYER_AGE, + TAG_PLAYER_PEAK_AGE, + TAG_PLAYER_CONTRACT, + TAG_PLAYER_PARTICIPATION, + TAG_PLAYER_GAMES_GOAL, + TAG_PLAYER_GAMES_GOAL_CLID, + TAG_PLAYER_GAMES_GOAL_GAMES, + TAG_PLAYER_GAMES_GOAL_GOALS, + TAG_PLAYER_GAMES_GOAL_SHOTS, + TAG_PLAYER_CARD, + TAG_PLAYER_CARD_CLID, + TAG_PLAYER_CARD_YELLOW, + TAG_PLAYER_CARD_RED, + TAG_PLAYER_CAREER, + TAG_END +}; + +gint state, etalidx, careeridx; +Player new_player; +PlayerGamesGoals new_games_goals; +PlayerCard new_card; + +void +xml_loadsave_players_start_element(gint tag, Team *tm) +{ + gint i; + gboolean valid_tag = FALSE; + + for(i=TAG_PLAYERS;i\n", I1, TAG_PLAYERS); + + for(i=0;ilen;i++) + xml_loadsave_players_write_player(fil, &g_array_index(players, Player, i)); + + fprintf(fil, "%s\n", I1, TAG_PLAYERS); +} + +void +xml_loadsave_players_write_player(FILE *fil, const Player *pl) +{ + gint i; + + fprintf(fil, "%s<_%d>\n", I1, TAG_PLAYER); + + xml_write_g_string(fil, pl->name, TAG_PLAYER_NAME, I2); + xml_write_int(fil, pl->pos, TAG_PLAYER_POS, I2); + xml_write_int(fil, pl->cpos, TAG_PLAYER_CPOS, I2); + xml_write_int(fil, pl->health, TAG_PLAYER_HEALTH, I2); + xml_write_int(fil, pl->recovery, TAG_PLAYER_RECOVERY, I2); + xml_write_int(fil, pl->id, TAG_PLAYER_ID, I2); + xml_write_int(fil, pl->value, TAG_PLAYER_VALUE, I2); + xml_write_int(fil, pl->wage, TAG_PLAYER_WAGE, I2); + xml_write_int(fil, pl->offers, TAG_PLAYER_OFFERS, I2); + xml_write_int(fil, pl->participation, TAG_PLAYER_PARTICIPATION, I2); + + xml_write_float(fil, pl->skill, TAG_PLAYER_SKILL, I2); + xml_write_float(fil, pl->cskill, TAG_PLAYER_CSKILL, I2); + xml_write_float(fil, pl->talent, TAG_PLAYER_TALENT, I2); + xml_write_float(fil, pl->fitness, TAG_PLAYER_FITNESS, I2); + xml_write_float(fil, pl->lsu, TAG_PLAYER_LSU, I2); + xml_write_float(fil, pl->age, TAG_PLAYER_AGE, I2); + xml_write_float(fil, pl->peak_age, TAG_PLAYER_PEAK_AGE, I2); + xml_write_float(fil, pl->contract, TAG_PLAYER_CONTRACT, I2); + + for(i=0;i<4;i++) + xml_write_float(fil, pl->etal[i], TAG_PLAYER_ETAL, I3); + + for(i=0;icareer[i], TAG_PLAYER_CAREER, I2); + + for(i=0;igames_goals->len;i++) + { + fprintf(fil, "%s<_%d>\n", I2, TAG_PLAYER_GAMES_GOAL); + + xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).clid, + TAG_PLAYER_GAMES_GOAL_CLID, I3); + xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).games, + TAG_PLAYER_GAMES_GOAL_GAMES, I3); + xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).goals, + TAG_PLAYER_GAMES_GOAL_GOALS, I3); + xml_write_int(fil, g_array_index(pl->games_goals, PlayerGamesGoals, i).shots, + TAG_PLAYER_GAMES_GOAL_SHOTS, I3); + + fprintf(fil, "%s\n", I2, TAG_PLAYER_GAMES_GOAL); + } + + for(i=0;icards->len;i++) + { + fprintf(fil, "%s<_%d>\n", I2, TAG_PLAYER_CARD); + + xml_write_int(fil, g_array_index(pl->cards, PlayerCard, i).clid, + TAG_PLAYER_CARD_CLID, I3); + xml_write_int(fil, g_array_index(pl->cards, PlayerCard, i).yellow, + TAG_PLAYER_CARD_YELLOW, I3); + xml_write_int(fil, g_array_index(pl->cards, PlayerCard, i).red, + TAG_PLAYER_CARD_RED, I3); + + fprintf(fil, "%s\n", I2, TAG_PLAYER_CARD); + } + + fprintf(fil, "%s\n", I1, TAG_PLAYER); +} diff --git a/src/xml_loadsave_players.h b/src/xml_loadsave_players.h new file mode 100644 index 00000000..121cea6d --- /dev/null +++ b/src/xml_loadsave_players.h @@ -0,0 +1,23 @@ +#ifndef XML_LOADSAVE_PLAYERS_H +#define XML_LOADSAVE_PLAYERS_H + +#include "bygfoot.h" +#include "team_struct.h" + +void +xml_loadsave_players_text(gchar *text); + +void +xml_loadsave_players_end_element(gint tag, GArray *players); + +void +xml_loadsave_players_start_element(gint tag, Team *tm); + +void +xml_loadsave_players_write_player(FILE *fil, const Player *pl); + +void +xml_loadsave_players_write(FILE *fil, const GArray *players); + +#endif +