Freeciv-3.2
Loading...
Searching...
No Matches
savecompat.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "capability.h"
20#include "log.h"
21
22/* common */
23#include "map.h"
24#include "specialist.h"
25
26/* server */
27#include "aiiface.h"
28#include "setcompat.h"
29#include "settings.h"
30#include "unittools.h"
31
32#include "savecompat.h"
33
35
36static char *special_names[] =
37 {
38 "Irrigation", "Mine", "Pollution", "Hut", "Farmland",
39 "Fallout", NULL
40 };
41
42/*
43 For each savefile format after 2.3.0, compatibility functions are defined
44 which translate secfile structures from previous version to that version;
45 all necessary compat functions are called in order to
46 translate between the file and current version. See sg_load_compat().
47
48 The integer version ID should be increased every time the format is changed.
49 If the change is not backwards compatible, please state the changes in the
50 following list and update the compat functions at the end of this file.
51
52 - what was added / removed
53 - when was it added / removed (date and version)
54 - when can additional capability checks be set to mandatory (version)
55 - which compatibility checks are needed and till when (version)
56
57 freeciv | what | date | id
58 --------+------------------------------------------------+------------+----
59 current | (mapped to current savegame format) | ----/--/-- | 0
60 | first version (svn17538) | 2010/07/05 | -
61 2.3.0 | 2.3.0 release | 2010/11/?? | 3
62 2.4.0 | 2.4.0 release | 201./../.. | 10
63 | * player ai type | |
64 | * delegation | |
65 | * citizens | |
66 | * save player color | |
67 | * "known" info format change | |
68 2.5.0 | 2.5.0 release | 201./../.. | 20
69 2.6.0 | 2.6.0 release | 201./../.. | 30
70 3.0.0 | 3.0.0 release | 201./../.. | 40
71 3.1.0 | 3.1.0 release | 201./../.. | 50
72 3.2.0 | 3.2.0 release (development) | 202./../.. | 60
73 | | |
74*/
75
82static void compat_post_load_030100(struct loaddata *loading,
84
86
92
93/* The struct below contains the information about the savegame versions. It
94 * is identified by the version number (first element), which should be
95 * steadily increasing. It is saved as 'savefile.version'. The support
96 * string (first element of 'name') is not saved in the savegame; it is
97 * saved in settings files (so, once assigned, cannot be changed). The
98 * 'pretty' string (second element of 'name') can be changed if necessary
99 * For changes in the development version, edit the definitions above and
100 * add the needed code to load the old version below. Thus, old
101 * savegames can still be loaded while the main definition
102 * represents the current state of the art. */
103/* While developing freeciv 3.2.0, add the compatibility functions to
104 * - compat_load_030200 to load old savegame. */
105static struct compatibility compat[] = {
106 /* dummy; equal to the current version (last element) */
107 { 0, NULL, NULL },
108 /* version 1 and 2 is not used */
109 /* version 3: first savegame2 format, so no compat functions for translation
110 * from previous format */
111 { 3, NULL, NULL },
112 /* version 4 to 9 are reserved for possible changes in 2.3.x */
113 { 10, compat_load_020400, NULL },
114 /* version 11 to 19 are reserved for possible changes in 2.4.x */
115 { 20, compat_load_020500, NULL },
116 /* version 21 to 29 are reserved for possible changes in 2.5.x */
117 { 30, compat_load_020600, NULL },
118 /* version 31 to 39 are reserved for possible changes in 2.6.x */
119 { 40, compat_load_030000, NULL },
120 /* version 41 to 49 are reserved for possible changes in 3.0.x */
122 /* version 51 to 59 are reserved for possible changes in 3.1.x */
123 { 60, compat_load_030200, NULL },
124 /* Current savefile version is listed above this line; it corresponds to
125 the definitions in this file. */
126};
127
128static const int compat_num = ARRAY_SIZE(compat);
129#define compat_current (compat_num - 1)
130
131/************************************************************************/
139{
140 int i;
141
142 /* Check status and return if not OK (sg_success FALSE). */
143 sg_check_ret();
144
145 loading->version = secfile_lookup_int_default(loading->file, -1,
146 "savefile.version");
147#ifdef FREECIV_DEBUG
148 sg_failure_ret(0 < loading->version, "Invalid savefile format version (%d).",
149 loading->version);
150 if (loading->version > compat[compat_current].version) {
151 /* Debug build can (TRY TO!) load newer versions but ... */
152 log_error("Savegame version newer than this build found (%d > %d). "
153 "Trying to load the game nevertheless ...", loading->version,
155 }
156#else /* FREECIV_DEBUG */
157 sg_failure_ret(0 < loading->version
158 && loading->version <= compat[compat_current].version,
159 "Unknown savefile format version (%d).", loading->version);
160#endif /* FREECIV_DEBUG */
161
162
163 for (i = 0; i < compat_num; i++) {
164 if (loading->version < compat[i].version && compat[i].load != NULL) {
165 log_normal(_("Run compatibility function for version: <%d "
166 "(save file: %d; server: %d)."), compat[i].version,
169 }
170 }
171}
172
173/************************************************************************/
185{
186 int i;
187
188 /* Check status and return if not OK (sg_success FALSE). */
189 sg_check_ret();
190
191 for (i = 0; i < compat_num; i++) {
192 if (loading->version < compat[i].version
193 && compat[i].post_load != NULL) {
194 log_normal(_("Run post load compatibility function for version: <%d "
195 "(save file: %d; server: %d)."), compat[i].version,
198 }
199 }
200}
201
202/************************************************************************/
206{
208}
209
210/************************************************************************/
215char bin2ascii_hex(int value, int halfbyte_wanted)
216{
217 return hex_chars[((value) >> ((halfbyte_wanted) * 4)) & 0xf];
218}
219
220/************************************************************************/
228{
229 const char *pch;
230
231 if (ch == ' ') {
232 /* Sane value. It is unknown if there are savegames out there which
233 * need this fix. Savegame.c doesn't write such savegames
234 * (anymore) since the inclusion into CVS (2000-08-25). */
235 return 0;
236 }
237
239
240 sg_failure_ret_val(NULL != pch && '\0' != ch, 0,
241 "Unknown hex value: '%c' %d", ch, ch);
242 return (pch - hex_chars) << (halfbyte * 4);
243}
244
245static const char num_chars[] =
246 "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+";
247
248/************************************************************************/
251int char2num(char ch)
252{
253 const char *pch;
254
256
258 "Unknown ascii value for num: '%c' %d", ch, ch);
259
260 return pch - num_chars;
261}
262
263/************************************************************************/
267{
268 int i;
269
270 for (i = 0; special_names[i] != NULL; i++) {
271 if (!strcmp(name, special_names[i])) {
272 return i;
273 }
274 }
275
276 return S_LAST;
277}
278
279/************************************************************************/
283{
284 fc_assert(type >= 0 && type < S_LAST);
285
286 return special_names[type];
287}
288
289/************************************************************************/
293{
295
298 }
299
300 return NULL;
301}
302
303/************************************************************************/
306struct extra_type *resource_by_identifier(const char identifier)
307{
309 if (presource->data.resource->id_old_save == identifier) {
310 return presource;
311 }
313
314 return NULL;
315}
316
317/* =======================================================================
318 * Compatibility functions for loading a game.
319 * ======================================================================= */
320
321/************************************************************************/
326{
327 /* Check status and return if not OK (sg_success FALSE). */
328 sg_check_ret();
329
330 log_debug("Upgrading data from savegame to version 2.4.0");
331
332 /* Add the default player AI. */
333 player_slots_iterate(pslot) {
334 int ncities, i, plrno = player_slot_index(pslot);
335
336 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
337 continue;
338 }
339
341 "player%d.ai_type", player_slot_index(pslot));
342
343 /* Create dummy citizens information. We do not know if citizens are
344 * activated due to the fact that this information
345 * (game.info.citizen_nationality) is not available, but adding the
346 * information does no harm. */
348 "player%d.ncities", plrno);
349 if (ncities > 0) {
350 for (i = 0; i < ncities; i++) {
352 "player%d.c%d.size", plrno, i);
353 if (size > 0) {
355 "player%d.c%d.citizen%d", plrno, i, plrno);
356 }
357 }
358 }
359
361
362 /* Player colors are assigned at the end of player loading, as this
363 * needs information not available here. */
364
365 /* Deal with buggy known tiles information from 2.3.0/2.3.1 (and the
366 * workaround in later 2.3.x); see gna bug #19029.
367 * (The structure of this code is odd as it avoids relying on knowledge of
368 * xsize/ysize, which haven't been extracted from the savefile yet.) */
369 {
370 if (has_capability("knownv2",
371 secfile_lookup_str(loading->file, "savefile.options"))) {
372 /* This savefile contains known information in a sane format.
373 * Just move any entries to where 2.4.x+ expect to find them. */
374 struct section *map = secfile_section_by_name(loading->file, "map");
375
376 if (map != NULL) {
378 const char *name = entry_name(pentry);
379
380 if (!fc_strncmp(name, "kvb", 3)) {
381 /* Rename the "kvb..." entry to "k..." */
382 char *name2 = fc_strdup(name), *newname = name2 + 2;
383
384 *newname = 'k';
385 /* Savefile probably contains existing "k" entries, which are bogus
386 * so we trash them. */
387 secfile_entry_delete(loading->file, "map.%s", newname);
389 FC_FREE(name2);
390 }
392 }
393 /* Could remove "knownv2" from savefile.options, but it's doing
394 * no harm there. */
395 } else {
396 /* This savefile only contains known information in the broken
397 * format. Try to recover it to a sane format. */
398 /* MAX_NUM_PLAYER_SLOTS in 2.3.x was 128 */
399 /* MAP_MAX_LINEAR_SIZE in 2.3.x was 512 */
400#define MAXSLOTS_2_3 128
401#define MAXMAPSIZE_2_3 512
402#define LINES_2_3 (MAXSLOTS_2_3 / 32)
403 int xsize = 0, y, l, j, x;
404 unsigned int known_row_old[LINES_2_3 * MAXMAPSIZE_2_3],
406
407 /* Process a map row at a time */
408 for (y = 0; y < MAXMAPSIZE_2_3; y++) {
409 /* Look for broken info to convert */
410 bool found = FALSE;
411
413 for (l = 0; l < LINES_2_3; l++) {
414 for (j = 0; j < 8; j++) {
415 const char *s
417 "map.k%02d_%04d", l * 8 + j, y);
418
419 if (s) {
420 found = TRUE;
421 if (xsize == 0) {
422 xsize = strlen(s);
423 }
424 sg_failure_ret(xsize == strlen(s),
425 "Inconsistent xsize in map.k%02d_%04d",
426 l * 8 + j, y);
427 for (x = 0; x < xsize; x++) {
428 known_row_old[l * xsize + x] |= ascii_hex2bin(s[x], j);
429 }
430 }
431 }
432 }
433 if (found) {
434 /* At least one entry found for this row. Let's hope they were
435 * all there. */
436 /* Attempt to munge into sane format */
437 int p;
438
439 memset(known_row, 0, sizeof(known_row));
440 /* Iterate over possible player slots */
441 for (p = 0; p < MAXSLOTS_2_3; p++) {
442 l = p / 32;
443 for (x = 0; x < xsize; x++) {
444 /* This test causes bit-shifts of >=32 (undefined behavior), but
445 * on common platforms, information happens not to be lost, just
446 * oddly arranged. */
447 if (known_row_old[l * xsize + x] & (1u << (p - l * 8))) {
448 known_row[l * xsize + x] |= (1u << (p - l * 32));
449 }
450 }
451 }
452 /* Save sane format back to memory representation of secfile for
453 * real loading code to pick up */
454 for (l = 0; l < LINES_2_3; l++) {
455 for (j = 0; j < 8; j++) {
456 /* Save info for all slots (not just used ones). It's only
457 * memory, after all. */
458 char row[xsize + 1];
459
460 for (x = 0; x < xsize; x++) {
461 row[x] = bin2ascii_hex(known_row[l * xsize + x], j);
462 }
463 row[xsize] = '\0';
465 "map.k%02d_%04d", l * 8 + j, y);
466 }
467 }
468 }
469 }
470 }
471
472#undef LINES_2_3
473#undef MAXMAPSIZE_2_3
474#undef MAXSLOTS_2_3
475 }
476
477 /* Server setting migration. */
478 {
479 int set_count;
480
481 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
482 int i, new_opt = set_count;
483 bool gamestart_valid
485 "settings.gamestart_valid");
486
487 for (i = 0; i < set_count; i++) {
488 const char *name
489 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
490
491 if (!name) {
492 continue;
493 }
494
495 /* In 2.3.x and prior, saveturns=0 meant no turn-based saves.
496 * This is now controlled by the "autosaves" setting. */
497 if (!fc_strcasecmp("saveturns", name)) {
498 /* XXX: Hardcodes details from GAME_AUTOSAVES_DEFAULT
499 * and settings.c:autosaves_name() (but these defaults reflect
500 * 2.3's behavior). */
501 const char *const nosave = "GAMEOVER|QUITIDLE|INTERRUPT";
502 const char *const save = "TURN|GAMEOVER|QUITIDLE|INTERRUPT";
503 int nturns;
504
506 "settings.set%d.value", i)) {
507 if (nturns == 0) {
508 /* Invent a new "autosaves" setting */
510 "settings.set%d.value", new_opt);
511 /* Pick something valid for saveturns */
513 "settings.set%d.value", i);
514 } else {
516 "settings.set%d.value", new_opt);
517 }
518 } else {
519 log_sg("Setting '%s': %s", name, secfile_error());
520 }
521 if (gamestart_valid) {
523 "settings.set%d.gamestart", i)) {
524 if (nturns == 0) {
525 /* Invent a new "autosaves" setting */
527 "settings.set%d.gamestart", new_opt);
528 /* Pick something valid for saveturns */
530 "settings.set%d.gamestart", i);
531 } else {
533 "settings.set%d.gamestart", new_opt);
534 }
535 } else {
536 log_sg("Setting '%s': %s", name, secfile_error());
537 }
538 }
539 } else if (!fc_strcasecmp("autosaves", name)) {
540 /* Sanity check. This won't trigger on an option we've just
541 * invented, as the loop won't include it. */
542 log_sg("Unexpected \"autosaves\" setting found in pre-2.4 "
543 "savefile. It may have been overridden.");
544 }
545 }
546 }
547 }
548}
549
550/************************************************************************/
553static const char *killcitizen_enum_str(secfile_data_t data, int bit)
554{
555 switch (bit) {
556 case UMT_LAND:
557 return "LAND";
558 case UMT_SEA:
559 return "SEA";
560 case UMT_BOTH:
561 return "BOTH";
562 }
563
564 return NULL;
565}
566
567/************************************************************************/
572{
573 const char *modname[] = { "Road", "Railroad" };
574 const char *old_activities_names[] = {
575 "Idle",
576 "Pollution",
577 "Unused Road",
578 "Mine",
579 "Irrigate",
580 "Mine",
581 "Irrigate",
582 "Fortified",
583 "Fortress",
584 "Sentry",
585 "Unused Railroad",
586 "Pillage",
587 "Goto",
588 "Explore",
589 "Transform",
590 "Unused",
591 "Unused Airbase",
592 "Fortifying",
593 "Fallout",
594 "Unused Patrol",
595 "Base"
596 };
597
598 /* Check status and return if not OK (sg_success FALSE). */
599 sg_check_ret();
600
601 log_debug("Upgrading data from savegame to version 2.5.0");
602
603 secfile_insert_int(loading->file, 2, "savefile.roads_size");
604 secfile_insert_int(loading->file, 0, "savefile.trait_size");
605
607 "savefile.roads_vector");
608
609 secfile_insert_int(loading->file, 19, "savefile.activities_size");
611 "savefile.activities_vector");
612
613 /* Server setting migration. */
614 {
615 int set_count;
616
617 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
618 int i;
619 bool gamestart_valid
621 "settings.gamestart_valid");
622 for (i = 0; i < set_count; i++) {
623 const char *name
624 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
625 if (!name) {
626 continue;
627 }
628 /* In 2.4.x and prior, "killcitizen" listed move types that
629 * killed citizens after successful attack. Now killcitizen
630 * is just boolean and classes affected are defined in ruleset. */
631 if (!fc_strcasecmp("killcitizen", name)) {
632 int value;
633
634 if (secfile_lookup_enum_data(loading->file, &value, TRUE,
636 "settings.set%d.value", i)) {
637 /* Lowest bit of old killcitizen value indicates if
638 * land units should kill citizens. We take that as
639 * new boolean killcitizen value. */
640 if (value & 0x1) {
642 "settings.set%d.value", i);
643 } else {
645 "settings.set%d.value", i);
646 }
647 } else {
648 log_sg("Setting '%s': %s", name, secfile_error());
649 }
650 if (gamestart_valid) {
651 if (secfile_lookup_enum_data(loading->file, &value, TRUE,
653 "settings.set%d.gamestart", i)) {
654 /* Lowest bit of old killcitizen value indicates if
655 * land units should kill citizens. We take that as
656 * new boolean killcitizen value. */
657 if (value & 0x1) {
659 "settings.set%d.gamestart", i);
660 } else {
662 "settings.set%d.gamestart", i);
663 }
664 } else {
665 log_sg("Setting '%s': %s", name, secfile_error());
666 }
667 }
668 }
669 }
670 }
671 }
672}
673
674/************************************************************************/
678{
679 switch (type) {
680 case REVOLEN_FIXED:
681 return "FIXED";
682 case REVOLEN_RANDOM:
683 return "RANDOM";
685 return "QUICKENING";
687 return "RANDQUICK";
688 }
689
690 return "";
691}
692
693/************************************************************************/
698{
699 bool team_pooled_research = GAME_DEFAULT_TEAM_POOLED_RESEARCH;
700 int tsize;
701 int ti;
702 int turn;
703
704 /* Check status and return if not OK (sg_success FALSE). */
705 sg_check_ret();
706
707 log_debug("Upgrading data from savegame to version 2.6.0");
708
709 /* Terrain mapping table - use current ruleset as we have no way to know
710 * any other old values. */
711 ti = 0;
713 char buf[2];
714
715 secfile_insert_str(loading->file, terrain_rule_name(pterr), "savefile.terrident%d.name", ti);
717 buf[1] = '\0';
718 secfile_insert_str(loading->file, buf, "savefile.terrident%d.identifier", ti++);
720
721 /* Server setting migration. */
722 {
723 int set_count;
724
725 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
726 char value_buffer[1024] = "";
727 char gamestart_buffer[1024] = "";
728 int i;
729 int dcost = -1;
730 int dstartcost = -1;
733 bool gamestart_valid
735 "settings.gamestart_valid");
736 int new_set_count;
737
738 for (i = 0; i < set_count; i++) {
739 const char *name
740 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
741 if (!name) {
742 continue;
743 }
744
745 /* In 2.5.x and prior, "spacerace" boolean controlled if
746 * spacerace victory condition was active. */
747 if (!fc_strcasecmp("spacerace", name)) {
748 bool value;
749
750 if (secfile_lookup_bool(loading->file, &value,
751 "settings.set%d.value", i)) {
752 if (value) {
753 if (value_buffer[0] != '\0') {
755 }
756 sz_strlcat(value_buffer, "SPACERACE");
757 }
758 } else {
759 log_sg("Setting '%s': %s", name, secfile_error());
760 }
761 if (secfile_lookup_bool(loading->file, &value,
762 "settings.set%d.gamestart", i)) {
763 if (value) {
764 if (gamestart_buffer[0] != '\0') {
766 }
767 sz_strlcat(gamestart_buffer, "SPACERACE");
768 }
769 } else {
770 log_sg("Setting '%s': %s", name, secfile_error());
771 }
772
773 /* We cannot delete old values from the secfile, or rather cannot
774 * change index of the later settings. Renumbering them is not easy as
775 * we don't know type of each setting we would encounter.
776 * So we keep old setting values and only add new "victories" setting. */
777 } else if (!fc_strcasecmp("alliedvictory", name)) {
778 bool value;
779
780 if (secfile_lookup_bool(loading->file, &value,
781 "settings.set%d.value", i)) {
782 if (value) {
783 if (value_buffer[0] != '\0') {
785 }
786 sz_strlcat(value_buffer, "ALLIED");
787 }
788 } else {
789 log_sg("Setting '%s': %s", name, secfile_error());
790 }
791 if (secfile_lookup_bool(loading->file, &value,
792 "settings.set%d.gamestart", i)) {
793 if (value) {
794 if (gamestart_buffer[0] != '\0') {
796 }
797 sz_strlcat(gamestart_buffer, "ALLIED");
798 }
799 } else {
800 log_sg("Setting '%s': %s", name, secfile_error());
801 }
802 } else if (!fc_strcasecmp("revolen", name)) {
803 int value;
804
805 if (secfile_lookup_int(loading->file, &value,
806 "settings.set%d.value", i)) {
807 /* 0 meant RANDOM 1-5 */
808 if (value == 0) {
811 "settings.set%d.value", i);
812 } else {
814 }
815 } else {
816 log_sg("Setting '%s': %s", name, secfile_error());
817 }
818 if (secfile_lookup_int(loading->file, &value,
819 "settings.set%d.gamestart", i)) {
820 /* 0 meant RANDOM 1-5 */
821 if (value == 0) {
824 "settings.set%d.gamestart", i);
825 } else {
827 }
828 } else {
829 log_sg("Setting '%s': %s", name, secfile_error());
830 }
831 } else if (!fc_strcasecmp("happyborders", name)) {
832 bool value;
833
834 if (secfile_lookup_bool(loading->file, &value,
835 "settings.set%d.value", i)) {
836 secfile_entry_delete(loading->file, "settings.set%d.value", i);
837 if (value) {
838 secfile_insert_str(loading->file, "NATIONAL",
839 "settings.set%d.value", i);
840 } else {
841 secfile_insert_str(loading->file, "DISABLED",
842 "settings.set%d.value", i);
843 }
844 } else {
845 log_sg("Setting '%s': %s", name, secfile_error());
846 }
847 if (secfile_lookup_bool(loading->file, &value,
848 "settings.set%d.gamestart", i)) {
849 secfile_entry_delete(loading->file, "settings.set%d.gamestart", i);
850 if (value) {
851 secfile_insert_str(loading->file, "NATIONAL",
852 "settings.set%d.gamestart", i);
853 } else {
854 secfile_insert_str(loading->file, "DISABLED",
855 "settings.set%d.gamestart", i);
856 }
857 } else {
858 log_sg("Setting '%s': %s", name, secfile_error());
859 }
860 } else if (!fc_strcasecmp("team_pooled_research", name)) {
862 &team_pooled_research,
863 "settings.set%d.value", i),
864 "%s", secfile_error());
865 } else if (!fc_strcasecmp("diplcost", name)) {
866 /* Old 'diplcost' split to 'diplbulbcost' and 'diplgoldcost' */
867 if (secfile_lookup_int(loading->file, &dcost,
868 "settings.set%d.value", i)) {
869 } else {
870 log_sg("Setting '%s': %s", name, secfile_error());
871 }
872
874 "settings.set%d.gamestart", i)) {
875 } else {
876 log_sg("Setting '%s': %s", name, secfile_error());
877 }
878 } else if (!fc_strcasecmp("huts", name)) {
879 /* Scale of 'huts' changed. */
880 int hcount;
881
883 "settings.set%d.value", i)) {
884 } else {
885 log_sg("Setting '%s': %s", name, secfile_error());
886 }
887
888 /* Store old-style absolute value. */
890 }
891 }
892
893 new_set_count = set_count + 2; /* 'victories' and 'revolentype' */
894
895 if (dcost >= 0) {
896 new_set_count += 2;
897 }
898
899 secfile_replace_int(loading->file, new_set_count, "settings.set_count");
900
901 secfile_insert_str(loading->file, "victories", "settings.set%d.name",
902 set_count);
903 secfile_insert_str(loading->file, value_buffer, "settings.set%d.value",
904 set_count);
905 secfile_insert_str(loading->file, "revolentype", "settings.set%d.name",
906 set_count + 1);
907 secfile_insert_str(loading->file, revolentype_str(rlt), "settings.set%d.value",
908 set_count + 1);
909
910 if (dcost >= 0) {
911 secfile_insert_str(loading->file, "diplbulbcost", "settings.set%d.name", set_count + 2);
912 secfile_insert_int(loading->file, dcost, "settings.set%d.value", set_count + 2);
913 secfile_insert_str(loading->file, "diplgoldcost", "settings.set%d.name", set_count + 3);
914 secfile_insert_int(loading->file, dcost, "settings.set%d.value", set_count + 3);
915 }
916
917 if (gamestart_valid) {
918 secfile_insert_str(loading->file, gamestart_buffer, "settings.set%d.gamestart",
919 set_count);
920 secfile_insert_str(loading->file, revolentype_str(gsrlt), "settings.set%d.gamestart",
921 set_count + 1);
922
923 if (dcost >= 0) {
924 secfile_insert_int(loading->file, dstartcost, "settings.set%d.gamestart", set_count + 2);
925 secfile_insert_int(loading->file, dstartcost, "settings.set%d.gamestart", set_count + 3);
926 }
927 }
928 }
929 }
930
931 sg_failure_ret(secfile_lookup_int(loading->file, &tsize, "savefile.trait_size"),
932 "Trait size: %s", secfile_error());
933
934 turn = secfile_lookup_int_default(loading->file, 0, "game.turn");
935
936 player_slots_iterate(pslot) {
937 int plrno = player_slot_index(pslot);
938 bool got_first_city;
939 int old_barb_type;
940 enum barbarian_type new_barb_type;
941 int i;
942 const char *name;
943 int score;
944 int units_num;
945
946 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
947 continue;
948 }
949
950 /* Renamed 'capital' to 'got_first_city'. */
952 "player%d.capital", plrno)) {
954 "player%d.got_first_city", plrno);
955 }
956
957 /* Add 'anonymous' qualifiers for user names */
958 name = secfile_lookup_str_default(loading->file, "", "player%d.username", plrno);
960 "player%d.unassigned_user", plrno);
961
962 name = secfile_lookup_str_default(loading->file, "", "player%d.ranked_username", plrno);
964 "player%d.unassigned_ranked", plrno);
965
966 /* Convert numeric barbarian type to textual */
968 "player%d.ai.is_barbarian", plrno);
971 "player%d.ai.barb_type", plrno);
972
973 /* Pre-2.6 didn't record when a player was created or died, so we have
974 * to assume they lived from the start of the game until last turn */
975 secfile_insert_int(loading->file, turn, "player%d.turns_alive", plrno);
976
977 /* As if there never has been a war. */
978 secfile_insert_int(loading->file, -1, "player%d.last_war", plrno);
979
980 /* Assume people were playing until current reload */
981 secfile_insert_int(loading->file, 0, "player%d.idle_turns", plrno);
982
983 for (i = 0; i < tsize; i++) {
984 int val;
985
986 val = secfile_lookup_int_default(loading->file, -1, "player%d.trait.val%d",
987 plrno, i);
988 if (val != -1) {
989 secfile_insert_int(loading->file, val, "player%d.trait%d.val", plrno, i);
990 }
991
993 "player%d.trait.mod%d", plrno, i),
994 "Trait mod: %s", secfile_error());
995 secfile_insert_int(loading->file, val, "player%d.trait%d.mod", plrno, i);
996 }
997
998 score = secfile_lookup_int_default(loading->file, -1,
999 "player%d.units_built", plrno);
1000 if (score >= 0) {
1001 secfile_insert_int(loading->file, score, "score%d.units_built", plrno);
1002 }
1003
1004 score = secfile_lookup_int_default(loading->file, -1,
1005 "player%d.units_killed", plrno);
1006 if (score >= 0) {
1007 secfile_insert_int(loading->file, score, "score%d.units_killed", plrno);
1008 }
1009
1010 score = secfile_lookup_int_default(loading->file, -1,
1011 "player%d.units_lost", plrno);
1012 if (score >= 0) {
1013 secfile_insert_int(loading->file, score, "score%d.units_lost", plrno);
1014 }
1015
1016 /* Units orders. */
1018 "player%d.nunits",
1019 plrno);
1020
1021 for (i = 0; i < units_num; i++) {
1022 int len;
1023
1025 "player%d.u%d.orders_last_move_safe",
1026 plrno, i)) {
1027 continue;
1028 }
1029
1031 "player%d.u%d.orders_length",
1032 plrno, i);
1033 if (len > 0) {
1034 char orders_str[len + 1];
1035 char *p;
1036
1039 "player%d.u%d.orders_list",
1040 plrno, i));
1041 if ((p = strrchr(orders_str, 'm'))
1042 || (p = strrchr(orders_str, 'M'))) {
1043 *p = 'x'; /* ORDER_MOVE -> ORDER_ACTION_MOVE */
1045 "player%d.u%d.orders_list", plrno, i);
1046 }
1047 }
1048 }
1050
1051 /* Add specialist order - loading time order is ok here, as we will use
1052 * that when we in later part of compatibility conversion use the specialist
1053 * values */
1055 "savefile.specialists_size");
1056 {
1057 const char **modname;
1058 int i = 0;
1059
1061
1065
1067 "savefile.specialists_vector");
1068
1069 free(modname);
1070 }
1071
1072 /* Replace all city specialist count fields with correct names */
1073 player_slots_iterate(pslot) {
1074 int plrno = player_slot_index(pslot);
1075 int ncities;
1076 int i;
1077
1078 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
1079 continue;
1080 }
1081
1082 ncities = secfile_lookup_int_default(loading->file, 0, "player%d.ncities", plrno);
1083
1084 for (i = 0; i < ncities; i++) {
1085 int k = 0;
1086
1088 struct specialist *psp = specialist_by_number(sp);
1089 int count;
1090
1092 "player%d.c%d.n%s",
1094 "specialist error: %s", secfile_error());
1095 secfile_entry_delete(loading->file, "player%d.c%d.n%s",
1097 secfile_insert_int(loading->file, count, "player%d.c%d.nspe%d",
1098 plrno, i, k++);
1100 }
1102
1103 /* Build [research]. */
1104 {
1105 const struct {
1106 const char *name;
1107 enum entry_type type;
1108 } entries[] = {
1109 { "goal_name", ENTRY_STR },
1110 { "techs", ENTRY_INT },
1111 { "futuretech", ENTRY_INT },
1112 { "bulbs_before", ENTRY_INT },
1113 { "saved_name", ENTRY_STR },
1114 { "bulbs", ENTRY_INT },
1115 { "now_name", ENTRY_STR },
1116 { "got_tech", ENTRY_BOOL },
1117 { "done", ENTRY_STR }
1118 };
1119
1121 int count = 0;
1122 int i;
1123
1124 for (i = 0; i < ARRAY_SIZE(researches); i++) {
1125 researches[i] = -1;
1126 }
1127
1128 player_slots_iterate(pslot) {
1129 int plrno = player_slot_index(pslot);
1130 int ival;
1131 bool bval;
1132 const char *sval;
1133 int j;
1134
1135 if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) {
1136 continue;
1137 }
1138
1139 /* Get the research number. */
1140 if (team_pooled_research) {
1142 "player%d.team_no", plrno);
1143 } else {
1144 i = plrno;
1145 }
1146
1148 "Research out of bounds (%d)!", i);
1149
1150 /* Find the index in [research] section. */
1151 if (researches[i] == -1) {
1152 /* This is the first player for this research. */
1153 secfile_insert_int(loading->file, i, "research.r%d.number", count);
1154 researches[i] = count;
1155 count++;
1156 }
1157 i = researches[i];
1158
1159 /* Move entries. */
1160 for (j = 0; j < ARRAY_SIZE(entries); j++) {
1161 switch (entries[j].type) {
1162 case ENTRY_BOOL:
1163 if (secfile_lookup_bool(loading->file, &bval,
1164 "player%d.research.%s",
1165 plrno, entries[j].name)) {
1166 secfile_insert_bool(loading->file, bval, "research.r%d.%s",
1167 i, entries[j].name);
1168 }
1169 break;
1170 case ENTRY_INT:
1171 if (secfile_lookup_int(loading->file, &ival,
1172 "player%d.research.%s",
1173 plrno, entries[j].name)) {
1174 secfile_insert_int(loading->file, ival, "research.r%d.%s",
1175 i, entries[j].name);
1176 }
1177 break;
1178 case ENTRY_STR:
1179 if ((sval = secfile_lookup_str(loading->file,
1180 "player%d.research.%s",
1181 plrno, entries[j].name))) {
1182 secfile_insert_str(loading->file, sval, "research.r%d.%s",
1183 i, entries[j].name);
1184 }
1185 break;
1186 case ENTRY_FLOAT:
1188 "Research related entry marked as float.");
1189 break;
1192 break;
1193 case ENTRY_LONG_COMMENT:
1195 break;
1196 case ENTRY_ILLEGAL:
1198 break;
1199 }
1200 }
1202 secfile_insert_int(loading->file, count, "research.count");
1203 }
1204
1205 /* Add diplstate type order. */
1207 "savefile.diplstate_type_size");
1208 if (DS_LAST > 0) {
1209 const char **modname;
1210 int i;
1211 int j;
1212
1213 i = 0;
1214 modname = fc_calloc(DS_LAST, sizeof(*modname));
1215
1216 for (j = 0; j < DS_LAST; j++) {
1218 }
1219
1221 DS_LAST,
1222 "savefile.diplstate_type_vector");
1223 free(modname);
1224 }
1225
1226 /* Fix save games from Freeciv versions with a bug that made it view
1227 * "Never met" as closer than "Peace" or "Alliance". */
1228 player_slots_iterate(pslot) {
1229 int plrno = player_slot_index(pslot);
1230
1231 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
1232 continue;
1233 }
1234
1236 int i = player_slot_index(pslot2);
1237 char buf[32];
1238 int current;
1239 int closest;
1240
1241 if (NULL == secfile_section_lookup(loading->file, "player%d", i)) {
1242 continue;
1243 }
1244
1245 fc_snprintf(buf, sizeof(buf), "player%d.diplstate%d", plrno, i);
1246
1247 /* Read the current diplomatic state. */
1249 "%s.type",
1250 buf);
1251
1252 /* Read the closest diplomatic state. */
1254 "%s.max_state",
1255 buf);
1256
1257 if (closest == DS_NO_CONTACT
1258 && (current == DS_PEACE
1259 || current == DS_ALLIANCE)) {
1260 const char *name1 = secfile_lookup_str_default(loading->file, "",
1261 "player%d.name", plrno);
1262 const char *name2 = secfile_lookup_str_default(loading->file, "",
1263 "player%d.name", i);
1264 /* The current relationship is closer than what the save game
1265 * claims is the closes relationship ever. */
1266
1267 log_sg(_("The save game is wrong about what the closest"
1268 " relationship %s (player %d) and %s (player %d) have had is."
1269 " Fixing it..."),
1270 name1, plrno, name2, i);
1271
1272 secfile_replace_int(loading->file, current, "%s.max_state", buf);
1273 }
1276}
1277
1278/************************************************************************/
1281static int increase_secfile_turn_int(struct loaddata *loading, const char *key,
1282 int old_def, bool keep_default)
1283{
1284 int value;
1285
1286 value = secfile_lookup_int_default(loading->file, old_def, "%s", key);
1287
1288 if (value != old_def || !keep_default) {
1289 value++;
1290 secfile_replace_int(loading->file, value, "%s", key);
1291 }
1292
1293 return value;
1294}
1295
1296/************************************************************************/
1304{
1305 bool randsaved;
1306 int num_settings;
1307 bool started;
1308 int old_turn;
1309 int event_count;
1310 int i;
1311
1312 /* Check status and return if not OK (sg_success FALSE). */
1313 sg_check_ret();
1314
1315 log_debug("Upgrading data from savegame to version 3.0.0");
1316
1317 /* Rename "random.save" as "random.saved"
1318 * Note that it's not an error if a scenario does not have [random] at all. */
1319 if (secfile_lookup_bool(loading->file, &randsaved, "random.save")) {
1320 secfile_insert_bool(loading->file, randsaved, "random.saved");
1321 }
1322
1323 /* Already started games should have their turn counts increased by 1 */
1324 if (secfile_lookup_bool_default(loading->file, TRUE, "game.save_players")) {
1325 started = TRUE;
1326
1327 old_turn = increase_secfile_turn_int(loading, "game.turn", 0, FALSE) - 1;
1329 increase_secfile_turn_int(loading, "history.turn", -2, TRUE);
1330 } else {
1331 started = FALSE;
1332 }
1333
1334 player_slots_iterate(pslot) {
1335 int plrno = player_slot_index(pslot);
1336 const char *flag_names[1];
1337
1338 if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) {
1339 continue;
1340 }
1341
1342 if (secfile_lookup_bool_default(loading->file, FALSE, "player%d.ai.control",
1343 plrno)) {
1345
1347 "player%d.flags", plrno);
1348 }
1349
1350 if (started) {
1351 int num = secfile_lookup_int_default(loading->file, 0,
1352 "player%d.nunits",
1353 plrno);
1354
1355 for (i = 0; i < num; i++) {
1356 char buf[64];
1357
1358 fc_snprintf(buf, sizeof(buf), "player%d.u%d.born", plrno, i);
1359
1361 }
1362
1363 num = secfile_lookup_int_default(loading->file, 0,
1364 "player%d.ncities", plrno);
1365
1366 for (i = 0; i < num; i++) {
1367 char buf[64];
1368
1369 fc_snprintf(buf, sizeof(buf), "player%d.c%d.turn_founded", plrno, i);
1370
1372 }
1373 }
1375
1376 /* Settings */
1378 "settings.set_count");
1379
1380 /* User meta server message is now a setting. */
1382 "game.meta_usermessage")) {
1383 const char *metamessage;
1384
1386 "game.meta_message");
1387
1388 /* Insert the meta message as a setting */
1389 secfile_insert_str(loading->file, "metamessage",
1390 "settings.set%d.name", num_settings);
1392 "settings.set%d.value", num_settings);
1393 secfile_insert_str(loading->file, "",
1394 "settings.set%d.gamestart", num_settings);
1395 num_settings++;
1396 }
1397
1398 secfile_replace_int(loading->file, num_settings, "settings.set_count");
1399
1400 event_count = secfile_lookup_int_default(loading->file, 0, "event_cache.count");
1401
1402 for (i = 0; i < event_count; i++) {
1403 const char *etype;
1404
1405 etype = secfile_lookup_str(loading->file, "event_cache.events%d.event", i);
1406
1407 if (etype != NULL && !fc_strcasecmp("E_UNIT_WIN", etype)) {
1408 secfile_replace_str(loading->file, "E_UNIT_WIN_DEF",
1409 "event_cache.events%d.event", i);
1410 }
1411 }
1412}
1413
1414/************************************************************************/
1419{
1420 int ssa_size;
1421
1422 if (format_class == SAVEGAME_2) {
1423 /* Handled in savegame2 */
1424 return;
1425 }
1426
1428 "savefile.server_side_agent_size");
1429
1430 if (ssa_size != 0) {
1431 /* Already inserted. */
1432 return;
1433 }
1434
1435 /* Add server side agent order. */
1437 "savefile.server_side_agent_size");
1438 if (SSA_COUNT > 0) {
1439 const char **modname;
1440 int i;
1441 int j;
1442
1443 i = 0;
1444 modname = fc_calloc(SSA_COUNT, sizeof(*modname));
1445
1446 for (j = 0; j < SSA_COUNT; j++) {
1448 }
1449
1451 SSA_COUNT,
1452 "savefile.server_side_agent_list");
1453 free(modname);
1454 }
1455
1456 /* Insert server_side_agent unit field. */
1457 player_slots_iterate(pslot) {
1458 int unit;
1459 int units_num;
1460 int plrno = player_slot_index(pslot);
1461
1462 if (secfile_section_lookup(loading->file, "player%d", plrno)
1463 == NULL) {
1464 continue;
1465 }
1466
1467 /* Number of units the player has. */
1469 "player%d.nunits",
1470 plrno);
1471
1472 for (unit = 0; unit < units_num; unit++) {
1473 bool ai;
1474
1476 "player%d.u%d.server_side_agent",
1477 plrno, unit)
1478 != NULL) {
1479 /* Already updated? */
1480 continue;
1481 }
1482
1484 "player%d.u%d.ai",
1485 plrno, unit);
1486
1487 if (ai) {
1488 /* Autosettler and Autoexplore are separated by
1489 * compat_post_load_030100() when set to SSA_AUTOSETTLER */
1491 "player%d.u%d.server_side_agent",
1492 plrno, unit);
1493 } else {
1495 "player%d.u%d.server_side_agent",
1496 plrno, unit);
1497 }
1498 }
1500}
1501
1502/************************************************************************/
1510{
1511 /* Check status and return if not OK (sg_success FALSE). */
1512 sg_check_ret();
1513
1514 log_debug("Upgrading data from savegame to version 3.1.0");
1515
1516 /* Actions are now stored by number. */
1517 player_slots_iterate(pslot) {
1518 int unit;
1519 int units_num;
1520 int plrno = player_slot_index(pslot);
1521
1522 if (secfile_section_lookup(loading->file, "player%d", plrno)
1523 == NULL) {
1524 continue;
1525 }
1526
1527 /* Number of units the player has. */
1529 "player%d.nunits",
1530 plrno);
1531
1532 for (unit = 0; unit < units_num; unit++) {
1533 const char *action_unitstr;
1534 int order_len;
1535
1537 "player%d.u%d.orders_length",
1538 plrno, unit);
1539
1541 "player%d.u%d.action_list",
1542 plrno, unit))) {
1543 int order_num;
1544
1547 }
1548
1549 for (order_num = 0; order_num < order_len; order_num++) {
1551
1552 if (action_unitstr[order_num] == '?') {
1554 } else {
1556 }
1557
1558 if (order_num == 0) {
1559 /* The start of a vector has no number. */
1561 "player%d.u%d.action_vec",
1562 plrno, unit);
1563 } else {
1565 "player%d.u%d.action_vec,%d",
1566 plrno, unit, order_num);
1567 }
1568 }
1569 }
1570 }
1572
1573 {
1574 int action_count;
1575
1577 "savefile.action_size");
1578
1579 if (action_count > 0) {
1580 const char **modname;
1581 const char **savemod;
1582 int j;
1583 const char *dur_name = "Disband Unit Recover";
1584
1585 modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
1586 "savefile.action_vector");
1587
1589
1590 for (j = 0; j < action_count; j++) {
1591 if (!fc_strcasecmp("Recycle Unit", modname[j])) {
1592 savemod[j] = dur_name;
1593 } else {
1594 savemod[j] = modname[j];
1595 }
1596 }
1597
1599 "savefile.action_vector");
1600
1601 free(savemod);
1602 }
1603 }
1604
1605 /* Server setting migration. */
1606 {
1607 int set_count;
1608
1609 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
1610 int i;
1611 bool gamestart_valid
1613 "settings.gamestart_valid");
1614
1615 /* Only add gamesetdef if gamestart is valid at all */
1616 if (gamestart_valid) {
1617 for (i = 0; i < set_count; i++) {
1618 const char *name
1619 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
1620
1621 if (!name) {
1622 continue;
1623 }
1624
1626 "settings.set%d.gamesetdef", i);
1627 }
1628 }
1629 }
1630 }
1631
1632 /* Explicit server side agent was new in 3.1 */
1634}
1635
1636/************************************************************************/
1640{
1641 int i;
1642
1643 for (i = 0; i < act_unit->orders.length; i++) {
1644 struct unit_order *order = &act_unit->orders.list[i];
1645
1646 if (order->order != ORDER_ACTIVITY) {
1647 continue;
1648 }
1649
1650 switch (order->activity) {
1651 case ACTIVITY_CLEAN:
1652 case ACTIVITY_MINE:
1653 case ACTIVITY_IRRIGATE:
1654 case ACTIVITY_PLANT:
1655 case ACTIVITY_CULTIVATE:
1656 case ACTIVITY_TRANSFORM:
1657 case ACTIVITY_CONVERT:
1659 case ACTIVITY_BASE:
1660 case ACTIVITY_GEN_ROAD:
1661 case ACTIVITY_PILLAGE:
1662 action_iterate(act_id) {
1663 struct action *paction = action_by_number(act_id);
1664
1665 if (action_get_activity(paction) == order->activity) {
1666 order->order = ORDER_PERFORM_ACTION;
1667 order->action = action_number(paction);
1668 order->activity = ACTIVITY_LAST;
1669 break;
1670 }
1672 break;
1673 case ACTIVITY_SENTRY:
1674 /* Not an action */
1675 break;
1676 case ACTIVITY_EXPLORE:
1677 case ACTIVITY_IDLE:
1678 case ACTIVITY_GOTO:
1679 case ACTIVITY_FORTIFIED:
1680 case ACTIVITY_LAST:
1681 log_error("Activity %d is not supposed to appear in unit orders",
1682 order->activity);
1683 break;
1684 }
1685 }
1686}
1687
1688/************************************************************************/
1692{
1693 switch (dir) {
1694 case DIR8_NORTH:
1695 return DIR8_SOUTH;
1696 case DIR8_NORTHEAST:
1697 return DIR8_SOUTHWEST;
1698 case DIR8_EAST:
1699 return DIR8_WEST;
1700 case DIR8_SOUTHEAST:
1701 return DIR8_NORTHWEST;
1702 case DIR8_SOUTH:
1703 return DIR8_NORTH;
1704 case DIR8_SOUTHWEST:
1705 return DIR8_NORTHEAST;
1706 case DIR8_WEST:
1707 return DIR8_EAST;
1708 case DIR8_NORTHWEST:
1709 return DIR8_SOUTHEAST;
1710 }
1711
1712 return DIR8_ORIGIN;
1713}
1714
1715/************************************************************************/
1719{
1720 int i;
1721 struct tile *current_tile;
1722 struct tile *tgt_tile;
1723
1724 if (!unit_has_orders(act_unit)) {
1725 return;
1726 }
1727
1728 /* The order index is for the unit at its current tile. */
1729 current_tile = unit_tile(act_unit);
1730
1731 /* Rewind to the beginning of the orders */
1732 for (i = act_unit->orders.index; i > 0 && current_tile != NULL; i--) {
1733 struct unit_order *prev_order = &act_unit->orders.list[i - 1];
1734
1735 if (!(prev_order->order == ORDER_PERFORM_ACTION
1739 current_tile = mapstep(&(wld.map), current_tile,
1740 dir_opposite(prev_order->dir));
1741 }
1742 }
1743
1744 /* Upgrade to explicit target tile */
1745 for (i = 0; i < act_unit->orders.length && current_tile != NULL; i++) {
1746 struct unit_order *order = &act_unit->orders.list[i];
1747
1748 if (order->order == ORDER_PERFORM_ACTION
1749 && order->target != NO_TARGET) {
1750 /* The target is already specified in the new format. */
1751
1752 /* The index_to_tile() call has no side-effects that we
1753 * would want also in NDEBUG builds. */
1754 fc_assert(index_to_tile(&(wld.map), order->target) != NULL);
1755 return;
1756 }
1757
1758 if (!direction8_is_valid(order->dir)) {
1759 /* The target of the action is on the actor's tile. */
1760 tgt_tile = current_tile;
1761 } else {
1762 /* The target of the action is on a tile next to the actor. */
1763 tgt_tile = mapstep(&(wld.map), current_tile, order->dir);
1764 }
1765
1766 if (order->order == ORDER_PERFORM_ACTION) {
1767 if (tgt_tile != NULL) {
1768 struct action *paction = action_by_number(order->action);
1769
1770 order->target = tgt_tile->index;
1771 /* Leave no traces. */
1772 order->dir = DIR8_ORIGIN;
1773
1775 /* The action moves the unit to the target tile (unless this is the
1776 * final order) */
1779 || i == act_unit->orders.length - 1);
1780 current_tile = tgt_tile;
1781 }
1782 } else {
1783 current_tile = NULL;
1784 }
1785 } else {
1786 current_tile = tgt_tile;
1787 }
1788 }
1789
1790 if (current_tile == NULL) {
1791 log_sg("Illegal orders for %s. Cancelling.", unit_rule_name(act_unit));
1793 }
1794}
1795
1796/************************************************************************/
1800{
1801 players_iterate_alive(pplayer) {
1802 unit_list_iterate(pplayer->units, punit) {
1805 }
1808}
1809
1810/************************************************************************/
1815{
1816 /* Check status and return if not OK (sg_success FALSE). */
1817 sg_check_ret();
1818
1819 /* Action orders were new in 3.0 */
1820 if (format_class == SAVEGAME_3) {
1821 /* Only 3.0 savegames may have "Attack" action orders. */
1822 players_iterate_alive(pplayer) {
1823 unit_list_iterate(pplayer->units, punit) {
1824 int i;
1825
1826 if (!punit->has_orders) {
1827 continue;
1828 }
1829
1831 || punit->orders.list != NULL, continue);
1832
1833 for (i = 0; i < punit->orders.length; i++) {
1834 /* "Attack" was split in "Suicide Attack" and "Attack" in 3.1. */
1840 }
1841
1842 /* Production targeted actions were split from building targeted
1843 * actions in 3.1. The building sub target encoding changed. */
1845 && ((punit->orders.list[i].action
1847 || (punit->orders.list[i].action
1849 punit->orders.list[i].sub_target -= 1;
1850 }
1852 && (punit->orders.list[i].action
1854 && punit->orders.list[i].sub_target == -1) {
1857 }
1859 && (punit->orders.list[i].action
1861 && punit->orders.list[i].sub_target == -1) {
1864 }
1865 }
1868 }
1869
1870 /* Explicit server side agent was new in 3.1 */
1872
1873 /* Some activities should only be ordered in action orders. */
1874 players_iterate_alive(pplayer) {
1875 unit_list_iterate(pplayer->units, punit) {
1879
1880 /* Unit order action target isn't dir anymore */
1881 players_iterate_alive(pplayer) {
1882 unit_list_iterate(pplayer->units, punit) {
1886
1887 /* Backward compatibility: if we had any open-ended orders (pillage)
1888 * in the savegame, assign specific targets now */
1889 players_iterate_alive(pplayer) {
1890 unit_list_iterate(pplayer->units, punit) {
1892 &punit->activity,
1896}
1897
1898/************************************************************************/
1906{
1907 int i;
1908 int count;
1909 int set_count;
1910 bool gamestart_valid = FALSE;
1911
1912 /* Check status and return if not OK (sg_success FALSE). */
1913 sg_check_ret();
1914
1915 log_debug("Upgrading data from savegame to version 3.2.0");
1916
1917 {
1918 const char *str = secfile_lookup_str_default(loading->file, NULL,
1919 "savefile.orig_version");
1920
1921 if (str == NULL) {
1922 /* Make sure CURRENTLY running version does not
1923 * end as orig_version when we resave. */
1924 if (format_class == SAVEGAME_3) {
1925 secfile_insert_str(loading->file, "old savegame3, or older",
1926 "savefile.orig_version");
1927 } else {
1929
1930 secfile_insert_str(loading->file, "savegame2, or older",
1931 "savefile.orig_version");
1932 }
1933 }
1934 }
1935
1936 {
1937 int action_count;
1938
1940 "savefile.action_size");
1941
1942 if (action_count > 0) {
1943 const char **modname;
1944 const char **savemod;
1945 int j;
1946 const char *dur_name = "Transport Deboard";
1947 const char *clean_name = "Clean";
1948
1949 modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
1950 "savefile.action_vector");
1951
1953
1954 for (j = 0; j < action_count; j++) {
1955 if (!fc_strcasecmp("Transport Alight", modname[j])) {
1956 savemod[j] = dur_name;
1957 } else if (!fc_strcasecmp("Clean Pollution", modname[j])
1958 || !fc_strcasecmp("Clean Fallout", modname[j])) {
1959 savemod[j] = clean_name;
1960 } else {
1961 savemod[j] = modname[j];
1962 }
1963 }
1964
1966 "savefile.action_vector");
1967
1968 free(savemod);
1969 }
1970 }
1971
1972 {
1973 int activities_count;
1974
1976 "savefile.activities_size");
1977
1978 if (activities_count > 0) {
1979 const char **modname;
1980 const char **savemod;
1981 int j;
1982 const char *clean_name = "Clean";
1983
1984 modname = secfile_lookup_str_vec(loading->file, &loading->activities.size,
1985 "savefile.activities_vector");
1986
1988
1989 for (j = 0; j < activities_count; j++) {
1990 if (!fc_strcasecmp("Pollution", modname[j])
1991 || !fc_strcasecmp("Fallout", modname[j])) {
1992 savemod[j] = clean_name;
1993 } else {
1994 savemod[j] = modname[j];
1995 }
1996 }
1997
1999 "savefile.activities_vector");
2000
2001 free(savemod);
2002 }
2003 }
2004
2005 /* Server setting migration. */
2006 {
2007 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
2008 int alltemperate_idx = -1, singlepole_idx = -1;
2009 bool count_changed = FALSE;
2010
2013 "settings.gamestart_valid");
2014
2015 for (i = 0; i < set_count; i++) {
2016 const char *old_name
2017 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
2018 const char *name;
2019
2020 if (!old_name) {
2021 continue;
2022 }
2023
2025
2026 if (fc_strcasecmp(old_name, name)) {
2027 /* Setting's name changed */
2028 secfile_replace_str(loading->file, name, "settings.set%d.name", i);
2029 }
2030
2031 if (!gamestart_valid) {
2032 /* Older savegames saved these values even when they were not valid.
2033 * Silence warnings caused by them. */
2034 (void) secfile_entry_lookup(loading->file, "settings.set%d.gamestart", i);
2035 (void) secfile_entry_lookup(loading->file, "settings.set%d.gamesetdef", i);
2036 }
2037
2038 if (!fc_strcasecmp("compresstype", name)) {
2039 const char *val = secfile_lookup_str(loading->file,
2040 "settings.set%d.value", i);
2041 if (!fc_strcasecmp(val, "BZIP2")) {
2042#ifdef FREECIV_HAVE_LIBZSTD
2043 secfile_replace_str(loading->file, "ZSTD",
2044 "settings.set%d.value", i);
2045#elif FREECIV_HAVE_LIBLZMA
2046 secfile_replace_str(loading->file, "XZ",
2047 "settings.set%d.value", i);
2048#elif FREECIV_HAVE_LIBZ
2049 secfile_replace_str(loading->file, "LIBZ",
2050 "settings.set%d.value", i);
2051#else
2052 secfile_replace_str(loading->file, "PLAIN",
2053 "settings.set%d.value", i);
2054#endif
2055 }
2056
2057 if (gamestart_valid) {
2058 val = secfile_lookup_str(loading->file,
2059 "settings.set%d.gamestart", i);
2060 if (!fc_strcasecmp(val, "BZIP2")) {
2061#ifdef FREECIV_HAVE_LIBZSTD
2062 secfile_replace_str(loading->file, "ZSTD",
2063 "settings.set%d.gamestart", i);
2064#elif FREECIV_HAVE_LIBLZMA
2065 secfile_replace_str(loading->file, "XZ",
2066 "settings.set%d.gamestart", i);
2067#elif FREECIV_HAVE_LIBZ
2068 secfile_replace_str(loading->file, "LIBZ",
2069 "settings.set%d.gamestart", i);
2070#else
2071 secfile_replace_str(loading->file, "PLAIN",
2072 "settings.set%d.gamestart", i);
2073#endif
2074 }
2075 }
2076 } else if (!fc_strcasecmp("topology", name)) {
2077 struct setting *pset = setting_by_name(name);
2078 struct sf_cb_data info = { pset, TRUE };
2079 int val;
2080
2081 if (secfile_lookup_enum_data(loading->file, &val, TRUE,
2083 "settings.set%d.value", i)) {
2084 char wrap[100];
2085 char buf[100];
2086
2087 if (val & TF_OLD_WRAPX) {
2088 if (val & TF_OLD_WRAPY) {
2089 fc_strlcpy(wrap, "WrapX|WrapY", sizeof(wrap));
2090 } else {
2091 fc_strlcpy(wrap, "WrapX", sizeof(wrap));
2092 }
2093 } else if (val & TF_OLD_WRAPY) {
2094 fc_strlcpy(wrap, "WrapY", sizeof(wrap));
2095 } else {
2096 fc_strlcpy(wrap, "", sizeof(wrap));
2097 }
2098
2099 if (val & TF_ISO) {
2100 if (val & TF_HEX) {
2101 setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0);
2102 } else {
2103 setting_bitwise_set(pset, "ISO", NULL, NULL, 0);
2104 }
2105 } else if (val & TF_HEX) {
2106 setting_bitwise_set(pset, "HEX", NULL, NULL, 0);
2107 } else {
2109 }
2110
2111 setting_value_name(pset, FALSE, buf, sizeof(buf));
2113 "settings.set%d.value", i);
2114
2116 "wrap", "settings.set%d.name", set_count);
2118 wrap, "settings.set%d.value", set_count);
2119
2120 if (gamestart_valid) {
2121 if (secfile_lookup_enum_data(loading->file, &val, TRUE,
2123 "settings.set%d.gamestart", i)) {
2124 if (val & TF_OLD_WRAPX) {
2125 if (val & TF_OLD_WRAPY) {
2126 fc_strlcpy(wrap, "WrapX|WrapY", sizeof(wrap));
2127 } else {
2128 fc_strlcpy(wrap, "WrapX", sizeof(wrap));
2129 }
2130 } else if (val & TF_OLD_WRAPY) {
2131 fc_strlcpy(wrap, "WrapY", sizeof(wrap));
2132 } else {
2133 fc_strlcpy(wrap, "", sizeof(wrap));
2134 }
2135
2136 if (val & TF_ISO) {
2137 if (val & TF_HEX) {
2138 setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0);
2139 } else {
2140 setting_bitwise_set(pset, "ISO", NULL, NULL, 0);
2141 }
2142 } else if (val & TF_HEX) {
2143 setting_bitwise_set(pset, "HEX", NULL, NULL, 0);
2144 } else {
2146 }
2147
2148 setting_value_name(pset, FALSE, buf, sizeof(buf));
2150 "settings.set%d.gamestart", i);
2151
2153 wrap, "settings.set%d.gamestart", set_count);
2154 }
2155 }
2156
2157 set_count++;
2159 }
2160 } else if (!fc_strcasecmp("alltemperate", name)) {
2162 } else if (!fc_strcasecmp("singlepole", name)) {
2163 singlepole_idx = i;
2164 }
2165 }
2166
2167 if (alltemperate_idx >= 0 || singlepole_idx >= 0) {
2168 int north_latitude, south_latitude;
2169 int north_idx, south_idx;
2171
2172 if (alltemperate_idx < 0
2174 "settings.set%d.value",
2176 /* Infer what would've been the ruleset default */
2178 }
2179
2180 if (singlepole_idx < 0
2182 "settings.set%d.value",
2183 singlepole_idx)) {
2184 /* Infer what would've been the ruleset default */
2186 }
2187
2188 /* Note: hard-coding 1000-based latitudes here; if MAX_LATITUDE ever
2189 * changes, that'll have to be handled in later migrations anyway */
2190 north_latitude = alltemperate ? 500 : 1000;
2191 south_latitude = alltemperate ? 500 : (singlepole ? 0 : -1000);
2192
2193 /* Replace alltemperate with northlatitude, and singlepole with
2194 * southlatitude. If only one of the two was given, add the other
2195 * at the end. */
2198
2199 secfile_replace_str(loading->file, "northlatitude",
2200 "settings.set%d.name", north_idx);
2201 secfile_replace_int(loading->file, north_latitude,
2202 "settings.set%d.value", north_idx);
2203
2204 secfile_replace_str(loading->file, "southlatitude",
2205 "settings.set%d.name", south_idx);
2206 secfile_replace_int(loading->file, south_latitude,
2207 "settings.set%d.value", south_idx);
2208
2209 if (gamestart_valid) {
2210 if (alltemperate_idx < 0
2212 "settings.set%d.gamestart",
2214 alltemperate =
2216 }
2217
2218 if (singlepole_idx < 0
2220 "settings.set%d.gamestart",
2221 singlepole_idx)) {
2223 }
2224
2225 north_latitude = alltemperate ? 500 : 1000;
2226 south_latitude = alltemperate ? 500 : (singlepole ? 0 : -1000);
2227
2228 secfile_replace_int(loading->file, north_latitude,
2229 "settings.set%d.gamestart", north_idx);
2230 secfile_replace_int(loading->file, south_latitude,
2231 "settings.set%d.gamestart", south_idx);
2232 }
2233
2234 if (alltemperate_idx < 0 || singlepole_idx < 0) {
2235 /* only one was given and replaced ~> we added one new entry */
2236 set_count++;
2238 }
2239 }
2240
2241 if (count_changed) {
2243 "settings.set_count");
2244 }
2245 }
2246 }
2247
2248 {
2249 /* Turn old AI level field to a setting. */
2250 const char *level;
2251 enum ai_level lvl;
2252
2253 level = secfile_lookup_str_default(loading->file, NULL, "game.level");
2254 if (level != NULL && !fc_strcasecmp("Handicapped", level)) {
2255 /* Up to freeciv-3.1 Restricted AI level was known as Handicapped */
2257 } else {
2259 }
2260
2261 if (!ai_level_is_valid(lvl)) {
2262 log_sg("Invalid AI level \"%s\". "
2263 "Changed to \"%s\".", level,
2266 }
2267
2268 secfile_insert_str(loading->file, "ailevel", "settings.set%d.name", set_count);
2269 secfile_insert_enum(loading->file, lvl, ai_level, "settings.set%d.value", set_count);
2270
2271 if (gamestart_valid) {
2272 secfile_insert_enum(loading->file, lvl, ai_level, "settings.set%d.gamestart",
2273 set_count);
2274 }
2275
2276 set_count++;
2277 secfile_replace_int(loading->file, set_count, "settings.set_count");
2278 }
2279
2280 if (format_class != SAVEGAME_2) {
2281 /* Replace got_tech[_multi] bools on free_bulbs integers. */
2282 /* Older savegames had a bug that got_tech_multi was not saved. */
2283 count = secfile_lookup_int_default(loading->file, 0, "research.count");
2284 for (i = 0; i < count; i++) {
2285 bool got_tech = FALSE;
2286 int bulbs = 0;
2287 bool got_tech_multi
2289 "research.r%d.got_tech_multi", i);
2290
2292 "research.r%d.got_tech", i)
2293 && secfile_lookup_int(loading->file, &bulbs,
2294 "research.r%d.bulbs", i)) {
2296 got_tech || got_tech_multi ? bulbs : 0,
2297 "research.r%d.free_bulbs", i);
2298 }
2299 }
2300 }
2301
2302 /* Older savegames unnecessarily saved diplstate type order.
2303 * Silence "unused entry" warnings about those. */
2304 {
2306 "savefile.diplstate_type_size");
2307
2308 for (i = 0; i < dscount; i++) {
2310 "savefile.diplstate_type_vector,%d", i);
2311 }
2312 }
2313
2314 /* Add wl_max_length entries for players */
2315 {
2316 player_slots_iterate(pslot) {
2317 int plrno = player_slot_index(pslot);
2318 int ncities;
2319 int cnro;
2320 size_t wlist_max_length = 0;
2321 bool first_city;
2322
2323 if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) {
2324 continue;
2325 }
2326
2328 "player%d.got_first_city",
2329 plrno);
2330 if (first_city) {
2331 const char **flag_names = fc_calloc(PLRF_COUNT, sizeof(char *));
2332 int flagcount = 0;
2333 const char **flags_sg;
2334 size_t nval;
2335
2337
2339 "player%d.flags", plrno);
2340
2341 for (i = 0; i < nval; i++) {
2344
2346 }
2347
2349 "player%d.flags", plrno);
2350
2352 }
2353
2355 "player%d.ncities", plrno);
2356
2357 for (cnro = 0; cnro < ncities; cnro++) {
2359 "player%d.c%d.wl_length",
2360 plrno, cnro);
2361
2363
2364 if (format_class == SAVEGAME_3) {
2366 "player%d.c%d.original",
2367 plrno, cnro) != plrno) {
2369 "player%d.c%d.acquire_t",
2370 plrno, cnro);
2371 } else {
2373 "player%d.c%d.acquire_t",
2374 plrno, cnro);
2375 }
2376
2378 "player%d.c%d.wlcb",
2379 plrno, cnro);
2380 }
2381 }
2382
2384 "player%d.wl_max_length", plrno);
2385
2386 if (format_class == SAVEGAME_3) {
2387 int nunits;
2388 int unro;
2389 size_t olist_max_length = 0;
2390
2392 "player%d.nunits", plrno);
2393
2394 for (unro = 0; unro < nunits; unro++) {
2396 "player%d.u%d.orders_length",
2397 plrno, unro);
2398
2400 }
2401
2403 "player%d.orders_max_length", plrno);
2404
2406 "player%d.routes_max_length", plrno);
2407 }
2408
2410 }
2411}
2412
2413/************************************************************************/
2416enum ai_level ai_level_convert(int old_level)
2417{
2418 switch (old_level) {
2419 case 1:
2420 return AI_LEVEL_AWAY;
2421 case 2:
2422 return AI_LEVEL_NOVICE;
2423 case 3:
2424 return AI_LEVEL_EASY;
2425 case 5:
2426 return AI_LEVEL_NORMAL;
2427 case 7:
2428 return AI_LEVEL_HARD;
2429 case 8:
2430 return AI_LEVEL_CHEATING;
2431 case 10:
2432#ifdef FREECIV_DEBUG
2433 return AI_LEVEL_EXPERIMENTAL;
2434#else /* FREECIV_DEBUG */
2435 return AI_LEVEL_HARD;
2436#endif /* FREECIV_DEBUG */
2437 }
2438
2439 return ai_level_invalid();
2440}
2441
2442/************************************************************************/
2445enum barbarian_type barb_type_convert(int old_type)
2446{
2447 switch (old_type) {
2448 case 0:
2449 return NOT_A_BARBARIAN;
2450 case 1:
2451 return LAND_BARBARIAN;
2452 case 2:
2453 return SEA_BARBARIAN;
2454 }
2455
2456 return barbarian_type_invalid();
2457}
int action_number(const struct action *action)
Definition actions.c:1969
static struct action * action_by_number(action_id act_id)
Definition actions.h:635
#define action_iterate_end
Definition actions.h:465
#define action_get_activity(_pact_)
Definition actions.h:699
#define action_iterate(_act_)
Definition actions.h:461
struct @126::my_agent entries[MAX_AGENTS]
const char * default_ai_type_name(void)
Definition aiiface.c:251
#define str
Definition astring.c:76
bool has_capability(const char *cap, const char *capstr)
Definition capability.c:77
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
struct extra_type_list * extra_type_list_by_cause(enum extra_cause cause)
Definition extras.c:249
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
#define NO_TARGET
Definition fc_types.h:354
#define EC_SPECIAL
Definition fc_types.h:1114
revolen_type
Definition fc_types.h:1282
@ REVOLEN_RANDOM
Definition fc_types.h:1284
@ REVOLEN_RANDQUICK
Definition fc_types.h:1286
@ REVOLEN_FIXED
Definition fc_types.h:1283
@ REVOLEN_QUICKENING
Definition fc_types.h:1285
#define DIR8_ORIGIN
Definition fc_types.h:457
#define _(String)
Definition fcintl.h:67
struct world wld
Definition game.c:63
#define GAME_DEFAULT_REVOLENTYPE
Definition game.h:738
#define GAME_DEFAULT_SCORETURN
Definition game.h:582
#define GAME_DEFAULT_SAVETURNS
Definition game.h:680
#define GAME_DEFAULT_TEAM_POOLED_RESEARCH
Definition game.h:566
#define GAME_HARDCODED_DEFAULT_SKILL_LEVEL
Definition game.h:698
GType type
Definition repodlgs.c:1313
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
#define log_error(message,...)
Definition log.h:103
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:456
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:371
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_strdup(str)
Definition mem.h:43
int len
Definition packhand.c:127
int player_slot_count(void)
Definition player.c:418
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
#define ANON_USER_NAME
Definition player.h:48
#define player_slots_iterate(_pslot)
Definition player.h:523
#define players_iterate_alive_end
Definition player.h:547
#define player_slots_iterate_end
Definition player.h:527
#define players_iterate_alive(_pplayer)
Definition player.h:542
const char * secfile_error(void)
bool secfile_lookup_int(const struct section_file *secfile, int *ival, const char *path,...)
bool secfile_entry_delete(struct section_file *secfile, const char *path,...)
bool entry_set_name(struct entry *pentry, const char *name)
bool secfile_lookup_enum_data(const struct section_file *secfile, int *pvalue, bool bitwise, secfile_enum_name_data_fn_t name_fn, secfile_data_t data, const char *path,...)
const struct entry_list * section_entries(const struct section *psection)
const char ** secfile_lookup_str_vec(const struct section_file *secfile, size_t *dim, const char *path,...)
const char * entry_name(const struct entry *pentry)
struct entry * secfile_entry_lookup(const struct section_file *secfile, const char *path,...)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
struct section * secfile_section_by_name(const struct section_file *secfile, const char *name)
struct section * secfile_section_lookup(const struct section_file *secfile, const char *path,...)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
bool secfile_lookup_bool(const struct section_file *secfile, bool *bval, const char *path,...)
#define secfile_replace_str_vec(secfile, strings, dim, path,...)
#define secfile_insert_int(secfile, value, path,...)
#define secfile_insert_enum(secfile, enumerator, specenum_type, path,...)
entry_type
@ ENTRY_FILEREFERENCE
@ ENTRY_LONG_COMMENT
@ ENTRY_INT
@ ENTRY_FLOAT
@ ENTRY_STR
@ ENTRY_ILLEGAL
@ ENTRY_BOOL
#define secfile_insert_str_vec(secfile, strings, dim, path,...)
#define secfile_replace_int(secfile, value, path,...)
#define entry_list_iterate_end
#define secfile_insert_str(secfile, string, path,...)
#define secfile_insert_bool(secfile, value, path,...)
#define secfile_replace_str(secfile, string, path,...)
#define entry_list_iterate(entlist, pentry)
#define secfile_replace_bool(secfile, value, path,...)
const void * secfile_data_t
static void compat_post_load_030100(struct loaddata *loading, enum sgf_version format_class)
struct extra_type * resource_by_identifier(const char identifier)
Definition savecompat.c:306
int current_compat_ver(void)
Definition savecompat.c:205
static void compat_load_030000(struct loaddata *loading, enum sgf_version format_class)
static const char num_chars[]
Definition savecompat.c:245
bool sg_success
Definition savecompat.c:34
static const char * killcitizen_enum_str(secfile_data_t data, int bit)
Definition savecompat.c:553
enum barbarian_type barb_type_convert(int old_type)
#define LINES_2_3
#define MAXMAPSIZE_2_3
static char * special_names[]
Definition savecompat.c:36
static struct compatibility compat[]
Definition savecompat.c:105
static void compat_load_020400(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:324
static void upgrade_unit_order_targets(struct unit *act_unit)
char bin2ascii_hex(int value, int halfbyte_wanted)
Definition savecompat.c:215
static const int compat_num
Definition savecompat.c:128
static void compat_load_020600(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:696
static enum direction8 dir_opposite(enum direction8 dir)
void(* load_version_func_t)(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:85
int char2num(char ch)
Definition savecompat.c:251
static void upgrade_server_side_agent(struct loaddata *loading)
void sg_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:138
static void unit_order_activity_to_action(struct unit *act_unit)
static char * revolentype_str(enum revolen_type type)
Definition savecompat.c:677
static int increase_secfile_turn_int(struct loaddata *loading, const char *key, int old_def, bool keep_default)
enum ai_level ai_level_convert(int old_level)
#define MAXSLOTS_2_3
int ascii_hex2bin(char ch, int halfbyte)
Definition savecompat.c:227
struct extra_type * special_extra_get(int spe)
Definition savecompat.c:292
static void compat_load_020500(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:570
static void compat_load_030200(struct loaddata *loading, enum sgf_version format_class)
enum tile_special_type special_by_rule_name(const char *name)
Definition savecompat.c:266
void sg_load_post_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:183
const char * special_rule_name(enum tile_special_type type)
Definition savecompat.c:282
static void compat_load_030100(struct loaddata *loading, enum sgf_version format_class)
static void insert_server_side_agent(struct loaddata *loading, enum sgf_version format_class)
#define compat_current
Definition savecompat.c:129
#define sg_check_ret(...)
Definition savecompat.h:150
#define sg_warn(condition, message,...)
Definition savecompat.h:160
tile_special_type
Definition savecompat.h:29
@ S_LAST
Definition savecompat.h:38
#define hex_chars
Definition savecompat.h:205
#define sg_failure_ret_val(condition, _val, message,...)
Definition savecompat.h:184
#define sg_failure_ret(condition, message,...)
Definition savecompat.h:177
#define MAX_TRADE_ROUTES_OLD
Definition savecompat.h:222
sgf_version
Definition savecompat.h:27
@ SAVEGAME_2
Definition savecompat.h:27
@ SAVEGAME_3
Definition savecompat.h:27
#define log_sg
Definition savecompat.h:146
const char * setcompat_S3_2_name_from_S3_1(const char *old_name)
Definition setcompat.c:62
struct setting * setting_by_name(const char *name)
Definition settings.c:3306
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4264
bool setting_bitwise_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4220
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
const char * setting_bitwise_secfile_str(secfile_data_t data, int bit)
Definition settings.c:4062
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MAX(x, y)
Definition shared.h:54
struct specialist * specialist_by_number(const Specialist_type_id id)
Definition specialist.c:100
const char * specialist_rule_name(const struct specialist *sp)
Definition specialist.c:146
Specialist_type_id specialist_count(void)
Definition specialist.c:71
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
int north_latitude
Definition map_types.h:79
int south_latitude
Definition map_types.h:80
struct civ_map::@42::@44 server
int huts_absolute
Definition map_types.h:95
const load_version_func_t post_load
Definition savecompat.c:90
const load_version_func_t load
Definition savecompat.c:89
struct name_translation name
Definition specialist.h:31
Definition tile.h:50
enum unit_activity activity
Definition unit.h:93
enum unit_orders order
Definition unit.h:92
int action
Definition unit.h:99
enum direction8 dir
Definition unit.h:101
int target
Definition unit.h:96
int sub_target
Definition unit.h:97
Definition unit.h:137
int length
Definition unit.h:194
bool has_orders
Definition unit.h:192
struct unit::@80 orders
enum unit_activity activity
Definition unit.h:156
struct extra_type * activity_target
Definition unit.h:163
struct unit_order * list
Definition unit.h:197
enum server_side_agent ssa_controller
Definition unit.h:171
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define sz_strlcat(dest, src)
Definition support.h:196
#define fc_strncmp(_s1_, _s2_, _len_)
Definition support.h:160
int team_slot_count(void)
Definition team.c:112
char terrain_identifier(const struct terrain *pterrain)
Definition terrain.c:126
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
#define terrain_type_iterate(_p)
Definition terrain.h:373
#define terrain_type_iterate_end
Definition terrain.h:379
void free_unit_orders(struct unit *punit)
Definition unit.c:1777
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:367
bool unit_has_orders(const struct unit *punit)
Definition unit.c:210
#define unit_tile(_pu)
Definition unit.h:396
@ ORDER_ACTIVITY
Definition unit.h:40
@ ORDER_PERFORM_ACTION
Definition unit.h:46
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
void unit_assign_specific_activity_target(struct unit *punit, enum unit_activity *activity, struct extra_type **target)
Definition unittools.c:1079
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
bool utype_is_moved_to_tgt_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1249
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1587
bool utype_is_unmoved_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1288