Author: sveinung Date: Tue Oct 27 16:44:05 2015 New Revision: 30230 URL: http://svn.gna.org/viewcvs/freeciv?rev=30230&view=rev Log: savegame3: store diplstate_type by name
rather than by number. See patch #6478 Modified: trunk/server/savecompat.c trunk/server/savegame3.c Modified: trunk/server/savecompat.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=30230&r1=30229&r2=30230&view=diff ============================================================================== --- trunk/server/savecompat.c (original) +++ trunk/server/savecompat.c Tue Oct 27 16:44:05 2015 @@ -1112,6 +1112,7 @@ bool randsaved; int plrno; int nplayers; + size_t diplstate_type_size; /* Check status and return if not OK (sg_success != TRUE). */ sg_check_ret(); @@ -1142,6 +1143,54 @@ secfile_insert_bool(loading->file, (!strcmp(name, ANON_USER_NAME)), "player%d.unassigned_ranked", plrno); } + } + + /* Diplomatic state type by name. */ + diplstate_type_size + = secfile_lookup_int_default(loading->file, 0, + "savefile.diplstate_type_size"); + + if (diplstate_type_size) { + const char **ds_t_name; + + /* Read the names of the diplomatic states. */ + ds_t_name = secfile_lookup_str_vec(loading->file, + &diplstate_type_size, + "savefile.diplstate_type_vector"); + + for (plrno = 0; plrno < nplayers; plrno++) { + int i; + + for (i = 0; i < nplayers; i++) { + char buf[32]; + + fc_snprintf(buf, sizeof(buf), "player%d.diplstate%d", plrno, i); + + if (!secfile_entry_lookup(loading->file, "%s.current", buf)) { + /* The current diplomatic state was called type when it was + * stored as a number. */ + int current = secfile_lookup_int_default(loading->file, DS_WAR, + "%s.type", + buf); + + secfile_insert_str(loading->file, ds_t_name[current], + "%s.current", buf); + } + + if (!secfile_entry_lookup(loading->file, "%s.closest", buf)) { + /* The closest diplomatic state was called type when it was + * stored as a number. */ + int closest = secfile_lookup_int_default(loading->file, DS_WAR, + "%s.max_state", + buf); + + secfile_insert_str(loading->file, ds_t_name[closest], + "%s.closest", buf); + } + } + } + + free(ds_t_name); } /* Units orders. */ Modified: trunk/server/savegame3.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=30230&r1=30229&r2=30230&view=diff ============================================================================== --- trunk/server/savegame3.c (original) +++ trunk/server/savegame3.c Tue Oct 27 16:44:05 2015 @@ -623,8 +623,6 @@ loading->multiplier.size = -1; loading->specialist.order = NULL; loading->specialist.size = -1; - loading->ds_t.order = NULL; - loading->ds_t.size = -1; loading->server_state = S_S_INITIAL; loading->rstate = fc_rand_state(); @@ -660,10 +658,6 @@ if (loading->specialist.order != NULL) { free(loading->specialist.order); - } - - if (loading->ds_t.order != NULL) { - free(loading->ds_t.order); } if (loading->worked_tiles != NULL) { @@ -1490,33 +1484,6 @@ loading->specialist.order[j] = NULL; } } - - /* Load diplomatic state type order. */ - loading->ds_t.size - = secfile_lookup_int_default(loading->file, 0, - "savefile.diplstate_type_size"); - - sg_failure_ret(loading->ds_t.size > 0, - "Failed to load diplomatic state type order: %s", - secfile_error()); - - if (loading->ds_t.size) { - const char **modname; - int j; - - modname = secfile_lookup_str_vec(loading->file, &loading->ds_t.size, - "savefile.diplstate_type_vector"); - - loading->ds_t.order = fc_calloc(loading->ds_t.size, - sizeof(*loading->ds_t.order)); - - for (j = 0; j < loading->ds_t.size; j++) { - loading->ds_t.order[j] = diplstate_type_by_name(modname[j], - fc_strcasecmp); - } - - free(modname); - } } /**************************************************************************** @@ -3624,37 +3591,18 @@ BV_CLR_ALL(plr->real_embassy); players_iterate(pplayer) { char buf[32]; - int unconverted; struct player_diplstate *ds = player_diplstate_get(plr, pplayer); i = player_index(pplayer); /* load diplomatic status */ fc_snprintf(buf, sizeof(buf), "player%d.diplstate%d", plrno, i); - unconverted = - secfile_lookup_int_default(loading->file, -1, "%s.type", buf); - if (unconverted >= 0 && unconverted < loading->ds_t.size) { - /* Look up what state the unconverted number represents. */ - ds->type = loading->ds_t.order[unconverted]; - } else { - log_sg("No valid diplomatic state type between players %d and %d", - plrno, i); - - ds->type = DS_WAR; - } - - unconverted = - secfile_lookup_int_default(loading->file, -1, "%s.max_state", buf); - if (unconverted >= 0 && unconverted < loading->ds_t.size) { - /* Look up what state the unconverted number represents. */ - ds->max_state = loading->ds_t.order[unconverted]; - } else { - log_sg("No valid diplomatic max_state between players %d and %d", - plrno, i); - - ds->max_state = DS_WAR; - } - + ds->type = + secfile_lookup_enum_default(loading->file, DS_WAR, + diplstate_type, "%s.current", buf); + ds->max_state = + secfile_lookup_enum_default(loading->file, DS_WAR, + diplstate_type, "%s.closest", buf); ds->first_contact_turn = secfile_lookup_int_default(loading->file, 0, "%s.first_contact_turn", buf); @@ -4018,10 +3966,10 @@ /* save diplomatic state */ fc_snprintf(buf, sizeof(buf), "player%d.diplstate%d", plrno, i); - secfile_insert_int(saving->file, ds->type, - "%s.type", buf); - secfile_insert_int(saving->file, ds->max_state, - "%s.max_state", buf); + secfile_insert_enum(saving->file, ds->type, + diplstate_type, "%s.current", buf); + secfile_insert_enum(saving->file, ds->max_state, + diplstate_type, "%s.closest", buf); secfile_insert_int(saving->file, ds->first_contact_turn, "%s.first_contact_turn", buf); secfile_insert_int(saving->file, ds->turns_left, _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits