<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14490 >
On 2/11/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote: > > On 1/18/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote: > > > > I think problem is that worklist length varies between cities. > > Untested patch attached. > > This version saves as many worklist items as longest worklist > contains (previous version saved MAX_LEN_WORKLIST). S2_1 version - ML
diff -Nurd -X.diff_ignore freeciv/client/options.c freeciv/client/options.c --- freeciv/client/options.c 2006-07-17 14:28:41.000000000 +0300 +++ freeciv/client/options.c 2007-02-12 15:32:11.000000000 +0200 @@ -624,6 +624,7 @@ for(i = 0; i < MAX_NUM_WORKLISTS; i++){ if (game.player_ptr->worklists[i].is_valid) { worklist_save(&sf, &(game.player_ptr->worklists[i]), + game.player_ptr->worklists[i].length, "worklists.worklist%d", i); } } diff -Nurd -X.diff_ignore freeciv/common/worklist.c freeciv/common/worklist.c --- freeciv/common/worklist.c 2007-01-19 16:20:14.000000000 +0200 +++ freeciv/common/worklist.c 2007-02-12 15:31:10.000000000 +0200 @@ -272,7 +272,7 @@ path and ... give the prefix to load from, printf-style. ****************************************************************************/ void worklist_save(struct section_file *file, struct worklist *pwl, - const char *path, ...) + int max_length, const char *path, ...) { char path_str[1024]; int i; @@ -299,4 +299,13 @@ secfile_insert_str(file, name, "%s.wl_value%d", path_str, i); } + + assert(max_length <= MAX_LEN_WORKLIST); + + /* We want to keep savegame in tabular format, so each line has to be + * of equal length. Fill table up to maximum worklist size. */ + for (i = pwl->length ; i < max_length; i++) { + secfile_insert_bool(file, false, "%s.wl_is_unit%d", path_str, i); + secfile_insert_str(file, "", "%s.wl_value%d", path_str, i); + } } diff -Nurd -X.diff_ignore freeciv/common/worklist.h freeciv/common/worklist.h --- freeciv/common/worklist.h 2006-07-17 14:28:35.000000000 +0300 +++ freeciv/common/worklist.h 2007-02-12 15:31:10.000000000 +0200 @@ -53,8 +53,8 @@ const char *path, ...) fc__attribute((__format__ (__printf__, 3, 4))); void worklist_save(struct section_file *file, struct worklist *pwl, - const char *path, ...) - fc__attribute((__format__ (__printf__, 3, 4))); + int max_length, const char *path, ...) + fc__attribute((__format__ (__printf__, 4, 5))); /* Iterate over all entries in the worklist. */ #define worklist_iterate(worklist, prod) \ diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c --- freeciv/server/savegame.c 2006-07-17 14:28:07.000000000 +0300 +++ freeciv/server/savegame.c 2007-02-12 15:31:10.000000000 +0200 @@ -2691,6 +2691,7 @@ char invs[A_LAST+1]; struct player_spaceship *ship = &plr->spaceship; struct ai_data *ai = ai_data_get(plr); + int wlist_max_length = 0; secfile_insert_str(file, plr->name, "player%d.name", plrno); secfile_insert_str(file, plr->username, "player%d.username", plrno); @@ -3007,6 +3008,14 @@ unit_list_iterate_end; i = -1; + + /* First determine lenght of longest worklist */ + city_list_iterate(plr->cities, pcity) { + if (pcity->worklist.length > wlist_max_length) { + wlist_max_length = pcity->worklist.length; + } + } city_list_iterate_end; + city_list_iterate(plr->cities, pcity) { int j, x, y; char citymap_buf[CITY_MAP_SIZE * CITY_MAP_SIZE + 1]; @@ -3147,7 +3156,8 @@ secfile_insert_str(file, impr_buf, "player%d.c%d.improvements_new", plrno, i); - worklist_save(file, &pcity->worklist, "player%d.c%d", plrno, i); + worklist_save(file, &pcity->worklist, wlist_max_length, + "player%d.c%d", plrno, i); /* FIXME: remove this when the urgency is properly recalculated. */ secfile_insert_int(file, pcity->ai.urgency,
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev