Freeciv-3.3
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 "plrhand.h"
29#include "setcompat.h"
30#include "settings.h"
31#include "unittools.h"
32
33#include "savecompat.h"
34
36
37static char *special_names[] =
38 {
39 "Irrigation", "Mine", "Pollution", "Hut", "Farmland",
40 "Fallout", NULL
41 };
42
43/*
44 For each savefile format after 2.3.0, compatibility functions are defined
45 which translate secfile structures from previous version to that version;
46 all necessary compat functions are called in order to
47 translate between the file and current version. See sg_load_compat().
48
49 The integer version ID should be increased every time the format is changed.
50 If the change is not backwards compatible, please state the changes in the
51 following list and update the compat functions at the end of this file.
52
53 - what was added / removed
54 - when was it added / removed (date and version)
55 - when can additional capability checks be set to mandatory (version)
56 - which compatibility checks are needed and till when (version)
57
58 freeciv | what | date | id
59 --------+------------------------------------------------+------------+----
60 current | (mapped to current savegame format) | ----/--/-- | 0
61 | first version (svn17538) | 2010/07/05 | -
62 2.3.0 | 2.3.0 release | 2010/11/?? | 3
63 2.4.0 | 2.4.0 release | 201./../.. | 10
64 | * player ai type | |
65 | * delegation | |
66 | * citizens | |
67 | * save player color | |
68 | * "known" info format change | |
69 2.5.0 | 2.5.0 release | 201./../.. | 20
70 2.6.0 | 2.6.0 release | 201./../.. | 30
71 3.0.0 | 3.0.0 release | 201./../.. | 40
72 3.1.0 | 3.1.0 release | 201./../.. | 50
73 3.2.0 | 3.2.0 release | 202./../.. | 60
74 3.3.0 | 3.3.0 release (development) | 202./../.. | 70
75 | | |
76*/
77
85static void compat_post_load_030100(struct loaddata *loading,
87static void compat_post_load_030300(struct loaddata *loading,
89
91
97
98/* The struct below contains the information about the savegame versions. It
99 * is identified by the version number (first element), which should be
100 * steadily increasing. It is saved as 'savefile.version'. The support
101 * string (first element of 'name') is not saved in the savegame; it is
102 * saved in settings files (so, once assigned, cannot be changed). The
103 * 'pretty' string (second element of 'name') can be changed if necessary
104 * For changes in the development version, edit the definitions above and
105 * add the needed code to load the old version below. Thus, old
106 * savegames can still be loaded while the main definition
107 * represents the current state of the art. */
108/* While developing freeciv 3.3.0, add the compatibility functions to
109 * - compat_load_030300 to load old savegame. */
110static struct compatibility compat[] = {
111 /* dummy; equal to the current version (last element) */
112 { 0, NULL, NULL },
113 /* version 1 and 2 is not used */
114 /* version 3: first savegame2 format, so no compat functions for translation
115 * from previous format */
116 { 3, NULL, NULL },
117 /* version 4 to 9 are reserved for possible changes in 2.3.x */
118 { 10, compat_load_020400, NULL },
119 /* version 11 to 19 are reserved for possible changes in 2.4.x */
120 { 20, compat_load_020500, NULL },
121 /* version 21 to 29 are reserved for possible changes in 2.5.x */
122 { 30, compat_load_020600, NULL },
123 /* version 31 to 39 are reserved for possible changes in 2.6.x */
124 { 40, compat_load_030000, NULL },
125 /* version 41 to 49 are reserved for possible changes in 3.0.x */
127 /* version 51 to 59 are reserved for possible changes in 3.1.x */
128 { 60, compat_load_030200, NULL },
129 /* version 61 to 69 are reserved for possible changes in 3.2.x */
131 /* Current savefile version is listed above this line; it corresponds to
132 the definitions in this file. */
133};
134
135static const int compat_num = ARRAY_SIZE(compat);
136#define compat_current (compat_num - 1)
137
138/************************************************************************/
146{
147 int i;
148
149 /* Check status and return if not OK (sg_success FALSE). */
150 sg_check_ret();
151
152 loading->version = secfile_lookup_int_default(loading->file, -1,
153 "savefile.version");
154#ifdef FREECIV_DEBUG
155 sg_failure_ret(0 < loading->version, "Invalid savefile format version (%d).",
156 loading->version);
157 if (loading->version > compat[compat_current].version) {
158 /* Debug build can (TRY TO!) load newer versions but ... */
159 log_error("Savegame version newer than this build found (%d > %d). "
160 "Trying to load the game nevertheless ...", loading->version,
162 }
163#else /* FREECIV_DEBUG */
164 sg_failure_ret(0 < loading->version
165 && loading->version <= compat[compat_current].version,
166 "Unknown savefile format version (%d).", loading->version);
167#endif /* FREECIV_DEBUG */
168
169
170 for (i = 0; i < compat_num; i++) {
171 if (loading->version < compat[i].version && compat[i].load != NULL) {
172 log_normal(_("Run compatibility function for version: <%d "
173 "(save file: %d; server: %d)."), compat[i].version,
176 }
177 }
178}
179
180/************************************************************************/
192{
193 int i;
194
195 /* Check status and return if not OK (sg_success FALSE). */
196 sg_check_ret();
197
198 for (i = 0; i < compat_num; i++) {
199 if (loading->version < compat[i].version
200 && compat[i].post_load != NULL) {
201 log_normal(_("Run post load compatibility function for version: <%d "
202 "(save file: %d; server: %d)."), compat[i].version,
205 }
206 }
207}
208
209/************************************************************************/
213{
215}
216
217/************************************************************************/
222char bin2ascii_hex(int value, int halfbyte_wanted)
223{
224 return hex_chars[((value) >> ((halfbyte_wanted) * 4)) & 0xf];
225}
226
227/************************************************************************/
235{
236 const char *pch;
237
238 if (ch == ' ') {
239 /* Sane value. It is unknown if there are savegames out there which
240 * need this fix. Savegame.c doesn't write such savegames
241 * (anymore) since the inclusion into CVS (2000-08-25). */
242 return 0;
243 }
244
246
247 sg_failure_ret_val(NULL != pch && '\0' != ch, 0,
248 "Unknown hex value: '%c' %d", ch, ch);
249 return (pch - hex_chars) << (halfbyte * 4);
250}
251
252static const char num_chars[] =
253 "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+";
254
255/************************************************************************/
258int char2num(char ch)
259{
260 const char *pch;
261
263
265 "Unknown ascii value for num: '%c' %d", ch, ch);
266
267 return pch - num_chars;
268}
269
270/************************************************************************/
274{
275 int i;
276
277 for (i = 0; special_names[i] != NULL; i++) {
278 if (!strcmp(name, special_names[i])) {
279 return i;
280 }
281 }
282
283 return S_LAST;
284}
285
286/************************************************************************/
290{
291 fc_assert(type >= 0 && type < S_LAST);
292
293 return special_names[type];
294}
295
296/************************************************************************/
300{
302
305 }
306
307 return NULL;
308}
309
310/************************************************************************/
313struct extra_type *resource_by_identifier(const char identifier)
314{
316 if (presource->data.resource->id_old_save == identifier) {
317 return presource;
318 }
320
321 return NULL;
322}
323
324/* =======================================================================
325 * Compatibility functions for loading a game.
326 * ======================================================================= */
327
328/************************************************************************/
333{
334 /* Check status and return if not OK (sg_success FALSE). */
335 sg_check_ret();
336
337 log_debug("Upgrading data from savegame to version 2.4.0");
338
339 /* Add the default player AI. */
340 player_slots_iterate(pslot) {
341 int ncities, i, plrno = player_slot_index(pslot);
342
343 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
344 continue;
345 }
346
348 "player%d.ai_type", player_slot_index(pslot));
349
350 /* Create dummy citizens information. We do not know if citizens are
351 * activated due to the fact that this information
352 * (game.info.citizen_nationality) is not available, but adding the
353 * information does no harm. */
355 "player%d.ncities", plrno);
356 if (ncities > 0) {
357 for (i = 0; i < ncities; i++) {
359 "player%d.c%d.size", plrno, i);
360 if (size > 0) {
362 "player%d.c%d.citizen%d", plrno, i, plrno);
363 }
364 }
365 }
366
368
369 /* Player colors are assigned at the end of player loading, as this
370 * needs information not available here. */
371
372 /* Deal with buggy known tiles information from 2.3.0/2.3.1 (and the
373 * workaround in later 2.3.x); see gna bug #19029.
374 * (The structure of this code is odd as it avoids relying on knowledge of
375 * xsize/ysize, which haven't been extracted from the savefile yet.) */
376 {
377 if (has_capability("knownv2",
378 secfile_lookup_str(loading->file, "savefile.options"))) {
379 /* This savefile contains known information in a sane format.
380 * Just move any entries to where 2.4.x+ expect to find them. */
381 struct section *map = secfile_section_by_name(loading->file, "map");
382
383 if (map != NULL) {
385 const char *name = entry_name(pentry);
386
387 if (!fc_strncmp(name, "kvb", 3)) {
388 /* Rename the "kvb..." entry to "k..." */
389 char *name2 = fc_strdup(name), *newname = name2 + 2;
390
391 *newname = 'k';
392 /* Savefile probably contains existing "k" entries, which are bogus
393 * so we trash them. */
394 secfile_entry_delete(loading->file, "map.%s", newname);
396 FC_FREE(name2);
397 }
399 }
400 /* Could remove "knownv2" from savefile.options, but it's doing
401 * no harm there. */
402 } else {
403 /* This savefile only contains known information in the broken
404 * format. Try to recover it to a sane format. */
405 /* MAX_NUM_PLAYER_SLOTS in 2.3.x was 128 */
406 /* MAP_MAX_LINEAR_SIZE in 2.3.x was 512 */
407#define MAXSLOTS_2_3 128
408#define MAXMAPSIZE_2_3 512
409#define LINES_2_3 (MAXSLOTS_2_3 / 32)
410 int xsize = 0, y, l, j, x;
411 unsigned int known_row_old[LINES_2_3 * MAXMAPSIZE_2_3],
413
414 /* Process a map row at a time */
415 for (y = 0; y < MAXMAPSIZE_2_3; y++) {
416 /* Look for broken info to convert */
417 bool found = FALSE;
418
420 for (l = 0; l < LINES_2_3; l++) {
421 for (j = 0; j < 8; j++) {
422 const char *s
424 "map.k%02d_%04d", l * 8 + j, y);
425
426 if (s) {
427 found = TRUE;
428 if (xsize == 0) {
429 xsize = strlen(s);
430 }
431 sg_failure_ret(xsize == strlen(s),
432 "Inconsistent xsize in map.k%02d_%04d",
433 l * 8 + j, y);
434 for (x = 0; x < xsize; x++) {
435 known_row_old[l * xsize + x] |= ascii_hex2bin(s[x], j);
436 }
437 }
438 }
439 }
440 if (found) {
441 /* At least one entry found for this row. Let's hope they were
442 * all there. */
443 /* Attempt to munge into sane format */
444 int p;
445
446 memset(known_row, 0, sizeof(known_row));
447 /* Iterate over possible player slots */
448 for (p = 0; p < MAXSLOTS_2_3; p++) {
449 l = p / 32;
450 for (x = 0; x < xsize; x++) {
451 /* This test causes bit-shifts of >=32 (undefined behavior), but
452 * on common platforms, information happens not to be lost, just
453 * oddly arranged. */
454 if (known_row_old[l * xsize + x] & (1u << (p - l * 8))) {
455 known_row[l * xsize + x] |= (1u << (p - l * 32));
456 }
457 }
458 }
459 /* Save sane format back to memory representation of secfile for
460 * real loading code to pick up */
461 for (l = 0; l < LINES_2_3; l++) {
462 for (j = 0; j < 8; j++) {
463 /* Save info for all slots (not just used ones). It's only
464 * memory, after all. */
465 char row[xsize + 1];
466
467 for (x = 0; x < xsize; x++) {
468 row[x] = bin2ascii_hex(known_row[l * xsize + x], j);
469 }
470 row[xsize] = '\0';
472 "map.k%02d_%04d", l * 8 + j, y);
473 }
474 }
475 }
476 }
477 }
478
479#undef LINES_2_3
480#undef MAXMAPSIZE_2_3
481#undef MAXSLOTS_2_3
482 }
483
484 /* Server setting migration. */
485 {
486 int set_count;
487
488 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
489 int i, new_opt = set_count;
490 bool gamestart_valid
492 "settings.gamestart_valid");
493
494 for (i = 0; i < set_count; i++) {
495 const char *name
496 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
497
498 if (!name) {
499 continue;
500 }
501
502 /* In 2.3.x and prior, saveturns=0 meant no turn-based saves.
503 * This is now controlled by the "autosaves" setting. */
504 if (!fc_strcasecmp("saveturns", name)) {
505 /* XXX: Hardcodes details from GAME_AUTOSAVES_DEFAULT
506 * and settings.c:autosaves_name() (but these defaults reflect
507 * 2.3's behavior). */
508 const char *const nosave = "GAMEOVER|QUITIDLE|INTERRUPT";
509 const char *const save = "TURN|GAMEOVER|QUITIDLE|INTERRUPT";
510 int nturns;
511
513 "settings.set%d.value", i)) {
514 if (nturns == 0) {
515 /* Invent a new "autosaves" setting */
517 "settings.set%d.value", new_opt);
518 /* Pick something valid for saveturns */
520 "settings.set%d.value", i);
521 } else {
523 "settings.set%d.value", new_opt);
524 }
525 } else {
526 log_sg("Setting '%s': %s", name, secfile_error());
527 }
528 if (gamestart_valid) {
530 "settings.set%d.gamestart", i)) {
531 if (nturns == 0) {
532 /* Invent a new "autosaves" setting */
534 "settings.set%d.gamestart", new_opt);
535 /* Pick something valid for saveturns */
537 "settings.set%d.gamestart", i);
538 } else {
540 "settings.set%d.gamestart", new_opt);
541 }
542 } else {
543 log_sg("Setting '%s': %s", name, secfile_error());
544 }
545 }
546 } else if (!fc_strcasecmp("autosaves", name)) {
547 /* Sanity check. This won't trigger on an option we've just
548 * invented, as the loop won't include it. */
549 log_sg("Unexpected \"autosaves\" setting found in pre-2.4 "
550 "savefile. It may have been overridden.");
551 }
552 }
553 }
554 }
555}
556
557/************************************************************************/
560static const char *killcitizen_enum_str(secfile_data_t data, int bit)
561{
562 switch (bit) {
563 case UMT_LAND:
564 return "LAND";
565 case UMT_SEA:
566 return "SEA";
567 case UMT_BOTH:
568 return "BOTH";
569 }
570
571 return NULL;
572}
573
574/************************************************************************/
579{
580 const char *modname[] = { "Road", "Railroad" };
581 const char *old_activities_names[] = {
582 "Idle",
583 "Pollution",
584 "Unused Road",
585 "Mine",
586 "Irrigate",
587 "Mine",
588 "Irrigate",
589 "Fortified",
590 "Fortress",
591 "Sentry",
592 "Unused Railroad",
593 "Pillage",
594 "Goto",
595 "Explore",
596 "Transform",
597 "Unused",
598 "Unused Airbase",
599 "Fortifying",
600 "Fallout",
601 "Unused Patrol",
602 "Base"
603 };
604
605 /* Check status and return if not OK (sg_success FALSE). */
606 sg_check_ret();
607
608 log_debug("Upgrading data from savegame to version 2.5.0");
609
610 secfile_insert_int(loading->file, 2, "savefile.roads_size");
611 secfile_insert_int(loading->file, 0, "savefile.trait_size");
612
614 "savefile.roads_vector");
615
616 secfile_insert_int(loading->file, 19, "savefile.activities_size");
618 "savefile.activities_vector");
619
620 /* Server setting migration. */
621 {
622 int set_count;
623
624 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
625 int i;
626 bool gamestart_valid
628 "settings.gamestart_valid");
629 for (i = 0; i < set_count; i++) {
630 const char *name
631 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
632 if (!name) {
633 continue;
634 }
635 /* In 2.4.x and prior, "killcitizen" listed move types that
636 * killed citizens after successful attack. Now killcitizen
637 * is just boolean and classes affected are defined in ruleset. */
638 if (!fc_strcasecmp("killcitizen", name)) {
639 int value;
640
641 if (secfile_lookup_enum_data(loading->file, &value, TRUE,
643 "settings.set%d.value", i)) {
644 /* Lowest bit of old killcitizen value indicates if
645 * land units should kill citizens. We take that as
646 * new boolean killcitizen value. */
647 if (value & 0x1) {
649 "settings.set%d.value", i);
650 } else {
652 "settings.set%d.value", i);
653 }
654 } else {
655 log_sg("Setting '%s': %s", name, secfile_error());
656 }
657 if (gamestart_valid) {
658 if (secfile_lookup_enum_data(loading->file, &value, TRUE,
660 "settings.set%d.gamestart", i)) {
661 /* Lowest bit of old killcitizen value indicates if
662 * land units should kill citizens. We take that as
663 * new boolean killcitizen value. */
664 if (value & 0x1) {
666 "settings.set%d.gamestart", i);
667 } else {
669 "settings.set%d.gamestart", i);
670 }
671 } else {
672 log_sg("Setting '%s': %s", name, secfile_error());
673 }
674 }
675 }
676 }
677 }
678 }
679}
680
681/************************************************************************/
685{
686 switch (type) {
687 case REVOLEN_FIXED:
688 return "FIXED";
689 case REVOLEN_RANDOM:
690 return "RANDOM";
692 return "QUICKENING";
694 return "RANDQUICK";
695 }
696
697 return "";
698}
699
700/************************************************************************/
705{
706 bool team_pooled_research = GAME_DEFAULT_TEAM_POOLED_RESEARCH;
707 int tsize;
708 int ti;
709 int turn;
710
711 /* Check status and return if not OK (sg_success FALSE). */
712 sg_check_ret();
713
714 log_debug("Upgrading data from savegame to version 2.6.0");
715
716 /* Terrain mapping table - use current ruleset as we have no way to know
717 * any other old values. */
718 ti = 0;
720 char buf[2];
721
722 secfile_insert_str(loading->file, terrain_rule_name(pterr), "savefile.terrident%d.name", ti);
724 buf[1] = '\0';
725 secfile_insert_str(loading->file, buf, "savefile.terrident%d.identifier", ti++);
727
728 /* Server setting migration. */
729 {
730 int set_count;
731
732 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
733 char value_buffer[1024] = "";
734 char gamestart_buffer[1024] = "";
735 int i;
736 int dcost = -1;
737 int dstartcost = -1;
740 bool gamestart_valid
742 "settings.gamestart_valid");
743 int new_set_count;
744
745 for (i = 0; i < set_count; i++) {
746 const char *name
747 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
748 if (!name) {
749 continue;
750 }
751
752 /* In 2.5.x and prior, "spacerace" boolean controlled if
753 * spacerace victory condition was active. */
754 if (!fc_strcasecmp("spacerace", name)) {
755 bool value;
756
757 if (secfile_lookup_bool(loading->file, &value,
758 "settings.set%d.value", i)) {
759 if (value) {
760 if (value_buffer[0] != '\0') {
762 }
763 sz_strlcat(value_buffer, "SPACERACE");
764 }
765 } else {
766 log_sg("Setting '%s': %s", name, secfile_error());
767 }
768 if (secfile_lookup_bool(loading->file, &value,
769 "settings.set%d.gamestart", i)) {
770 if (value) {
771 if (gamestart_buffer[0] != '\0') {
773 }
774 sz_strlcat(gamestart_buffer, "SPACERACE");
775 }
776 } else {
777 log_sg("Setting '%s': %s", name, secfile_error());
778 }
779
780 /* We cannot delete old values from the secfile, or rather cannot
781 * change index of the later settings. Renumbering them is not easy as
782 * we don't know type of each setting we would encounter.
783 * So we keep old setting values and only add new "victories" setting. */
784 } else if (!fc_strcasecmp("alliedvictory", name)) {
785 bool value;
786
787 if (secfile_lookup_bool(loading->file, &value,
788 "settings.set%d.value", i)) {
789 if (value) {
790 if (value_buffer[0] != '\0') {
792 }
793 sz_strlcat(value_buffer, "ALLIED");
794 }
795 } else {
796 log_sg("Setting '%s': %s", name, secfile_error());
797 }
798 if (secfile_lookup_bool(loading->file, &value,
799 "settings.set%d.gamestart", i)) {
800 if (value) {
801 if (gamestart_buffer[0] != '\0') {
803 }
804 sz_strlcat(gamestart_buffer, "ALLIED");
805 }
806 } else {
807 log_sg("Setting '%s': %s", name, secfile_error());
808 }
809 } else if (!fc_strcasecmp("revolen", name)) {
810 int value;
811
812 if (secfile_lookup_int(loading->file, &value,
813 "settings.set%d.value", i)) {
814 /* 0 meant RANDOM 1-5 */
815 if (value == 0) {
818 "settings.set%d.value", i);
819 } else {
821 }
822 } else {
823 log_sg("Setting '%s': %s", name, secfile_error());
824 }
825 if (secfile_lookup_int(loading->file, &value,
826 "settings.set%d.gamestart", i)) {
827 /* 0 meant RANDOM 1-5 */
828 if (value == 0) {
831 "settings.set%d.gamestart", i);
832 } else {
834 }
835 } else {
836 log_sg("Setting '%s': %s", name, secfile_error());
837 }
838 } else if (!fc_strcasecmp("happyborders", name)) {
839 bool value;
840
841 if (secfile_lookup_bool(loading->file, &value,
842 "settings.set%d.value", i)) {
843 secfile_entry_delete(loading->file, "settings.set%d.value", i);
844 if (value) {
845 secfile_insert_str(loading->file, "NATIONAL",
846 "settings.set%d.value", i);
847 } else {
848 secfile_insert_str(loading->file, "DISABLED",
849 "settings.set%d.value", i);
850 }
851 } else {
852 log_sg("Setting '%s': %s", name, secfile_error());
853 }
854 if (secfile_lookup_bool(loading->file, &value,
855 "settings.set%d.gamestart", i)) {
856 secfile_entry_delete(loading->file, "settings.set%d.gamestart", i);
857 if (value) {
858 secfile_insert_str(loading->file, "NATIONAL",
859 "settings.set%d.gamestart", i);
860 } else {
861 secfile_insert_str(loading->file, "DISABLED",
862 "settings.set%d.gamestart", i);
863 }
864 } else {
865 log_sg("Setting '%s': %s", name, secfile_error());
866 }
867 } else if (!fc_strcasecmp("team_pooled_research", name)) {
869 &team_pooled_research,
870 "settings.set%d.value", i),
871 "%s", secfile_error());
872 } else if (!fc_strcasecmp("diplcost", name)) {
873 /* Old 'diplcost' split to 'diplbulbcost' and 'diplgoldcost' */
874 if (secfile_lookup_int(loading->file, &dcost,
875 "settings.set%d.value", i)) {
876 } else {
877 log_sg("Setting '%s': %s", name, secfile_error());
878 }
879
881 "settings.set%d.gamestart", i)) {
882 } else {
883 log_sg("Setting '%s': %s", name, secfile_error());
884 }
885 } else if (!fc_strcasecmp("huts", name)) {
886 /* Scale of 'huts' changed. */
887 int hcount;
888
890 "settings.set%d.value", i)) {
891 } else {
892 log_sg("Setting '%s': %s", name, secfile_error());
893 }
894
895 /* Store old-style absolute value. */
897 }
898 }
899
900 new_set_count = set_count + 2; /* 'victories' and 'revolentype' */
901
902 if (dcost >= 0) {
903 new_set_count += 2;
904 }
905
906 secfile_replace_int(loading->file, new_set_count, "settings.set_count");
907
908 secfile_insert_str(loading->file, "victories", "settings.set%d.name",
909 set_count);
910 secfile_insert_str(loading->file, value_buffer, "settings.set%d.value",
911 set_count);
912 secfile_insert_str(loading->file, "revolentype", "settings.set%d.name",
913 set_count + 1);
914 secfile_insert_str(loading->file, revolentype_str(rlt), "settings.set%d.value",
915 set_count + 1);
916
917 if (dcost >= 0) {
918 secfile_insert_str(loading->file, "diplbulbcost", "settings.set%d.name", set_count + 2);
919 secfile_insert_int(loading->file, dcost, "settings.set%d.value", set_count + 2);
920 secfile_insert_str(loading->file, "diplgoldcost", "settings.set%d.name", set_count + 3);
921 secfile_insert_int(loading->file, dcost, "settings.set%d.value", set_count + 3);
922 }
923
924 if (gamestart_valid) {
925 secfile_insert_str(loading->file, gamestart_buffer, "settings.set%d.gamestart",
926 set_count);
927 secfile_insert_str(loading->file, revolentype_str(gsrlt), "settings.set%d.gamestart",
928 set_count + 1);
929
930 if (dcost >= 0) {
931 secfile_insert_int(loading->file, dstartcost, "settings.set%d.gamestart", set_count + 2);
932 secfile_insert_int(loading->file, dstartcost, "settings.set%d.gamestart", set_count + 3);
933 }
934 }
935 }
936 }
937
938 sg_failure_ret(secfile_lookup_int(loading->file, &tsize, "savefile.trait_size"),
939 "Trait size: %s", secfile_error());
940
941 turn = secfile_lookup_int_default(loading->file, 0, "game.turn");
942
943 player_slots_iterate(pslot) {
944 int plrno = player_slot_index(pslot);
945 bool got_first_city;
946 int old_barb_type;
947 enum barbarian_type new_barb_type;
948 int i;
949 const char *name;
950 int score;
951 int units_num;
952
953 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
954 continue;
955 }
956
957 /* Renamed 'capital' to 'got_first_city'. */
959 "player%d.capital", plrno)) {
961 "player%d.got_first_city", plrno);
962 }
963
964 /* Add 'anonymous' qualifiers for user names */
965 name = secfile_lookup_str_default(loading->file, "", "player%d.username", plrno);
967 "player%d.unassigned_user", plrno);
968
969 name = secfile_lookup_str_default(loading->file, "", "player%d.ranked_username", plrno);
971 "player%d.unassigned_ranked", plrno);
972
973 /* Convert numeric barbarian type to textual */
975 "player%d.ai.is_barbarian", plrno);
978 "player%d.ai.barb_type", plrno);
979
980 /* Pre-2.6 didn't record when a player was created or died, so we have
981 * to assume they lived from the start of the game until last turn */
982 secfile_insert_int(loading->file, turn, "player%d.turns_alive", plrno);
983
984 /* As if there never has been a war. */
985 secfile_insert_int(loading->file, -1, "player%d.last_war", plrno);
986
987 /* Assume people were playing until current reload */
988 secfile_insert_int(loading->file, 0, "player%d.idle_turns", plrno);
989
990 for (i = 0; i < tsize; i++) {
991 int val;
992
993 val = secfile_lookup_int_default(loading->file, -1, "player%d.trait.val%d",
994 plrno, i);
995 if (val != -1) {
996 secfile_insert_int(loading->file, val, "player%d.trait%d.val", plrno, i);
997 }
998
1000 "player%d.trait.mod%d", plrno, i),
1001 "Trait mod: %s", secfile_error());
1002 secfile_insert_int(loading->file, val, "player%d.trait%d.mod", plrno, i);
1003 }
1004
1005 score = secfile_lookup_int_default(loading->file, -1,
1006 "player%d.units_built", plrno);
1007 if (score >= 0) {
1008 secfile_insert_int(loading->file, score, "score%d.units_built", plrno);
1009 }
1010
1011 score = secfile_lookup_int_default(loading->file, -1,
1012 "player%d.units_killed", plrno);
1013 if (score >= 0) {
1014 secfile_insert_int(loading->file, score, "score%d.units_killed", plrno);
1015 }
1016
1017 score = secfile_lookup_int_default(loading->file, -1,
1018 "player%d.units_lost", plrno);
1019 if (score >= 0) {
1020 secfile_insert_int(loading->file, score, "score%d.units_lost", plrno);
1021 }
1022
1023 /* Units orders. */
1025 "player%d.nunits",
1026 plrno);
1027
1028 for (i = 0; i < units_num; i++) {
1029 int len;
1030
1032 "player%d.u%d.orders_last_move_safe",
1033 plrno, i)) {
1034 continue;
1035 }
1036
1038 "player%d.u%d.orders_length",
1039 plrno, i);
1040 if (len > 0) {
1041 char orders_str[len + 1];
1042 char *p;
1043
1046 "player%d.u%d.orders_list",
1047 plrno, i));
1048 if ((p = strrchr(orders_str, 'm'))
1049 || (p = strrchr(orders_str, 'M'))) {
1050 *p = 'x'; /* ORDER_MOVE -> ORDER_ACTION_MOVE */
1052 "player%d.u%d.orders_list", plrno, i);
1053 }
1054 }
1055 }
1057
1058 /* Add specialist order - loading time order is ok here, as we will use
1059 * that when we in later part of compatibility conversion use the specialist
1060 * values */
1062 "savefile.specialists_size");
1063 {
1064 const char **modname;
1065 int i = 0;
1066
1068
1072
1074 "savefile.specialists_vector");
1075
1076 free(modname);
1077 }
1078
1079 /* Replace all city specialist count fields with correct names */
1080 player_slots_iterate(pslot) {
1081 int plrno = player_slot_index(pslot);
1082 int ncities;
1083 int i;
1084
1085 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
1086 continue;
1087 }
1088
1089 ncities = secfile_lookup_int_default(loading->file, 0, "player%d.ncities", plrno);
1090
1091 for (i = 0; i < ncities; i++) {
1092 int k = 0;
1093
1095 struct specialist *psp = specialist_by_number(sp);
1096 int count;
1097
1099 "player%d.c%d.n%s",
1101 "specialist error: %s", secfile_error());
1102 secfile_entry_delete(loading->file, "player%d.c%d.n%s",
1104 secfile_insert_int(loading->file, count, "player%d.c%d.nspe%d",
1105 plrno, i, k++);
1107 }
1109
1110 /* Build [research]. */
1111 {
1112 const struct {
1113 const char *name;
1114 enum entry_type type;
1115 } entries[] = {
1116 { "goal_name", ENTRY_STR },
1117 { "techs", ENTRY_INT },
1118 { "futuretech", ENTRY_INT },
1119 { "bulbs_before", ENTRY_INT },
1120 { "saved_name", ENTRY_STR },
1121 { "bulbs", ENTRY_INT },
1122 { "now_name", ENTRY_STR },
1123 { "got_tech", ENTRY_BOOL },
1124 { "done", ENTRY_STR }
1125 };
1126
1128 int count = 0;
1129 int i;
1130
1131 for (i = 0; i < ARRAY_SIZE(researches); i++) {
1132 researches[i] = -1;
1133 }
1134
1135 player_slots_iterate(pslot) {
1136 int plrno = player_slot_index(pslot);
1137 int ival;
1138 bool bval;
1139 const char *sval;
1140 int j;
1141
1142 if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) {
1143 continue;
1144 }
1145
1146 /* Get the research number. */
1147 if (team_pooled_research) {
1149 "player%d.team_no", plrno);
1150 } else {
1151 i = plrno;
1152 }
1153
1155 "Research out of bounds (%d)!", i);
1156
1157 /* Find the index in [research] section. */
1158 if (researches[i] == -1) {
1159 /* This is the first player for this research. */
1160 secfile_insert_int(loading->file, i, "research.r%d.number", count);
1161 researches[i] = count;
1162 count++;
1163 }
1164 i = researches[i];
1165
1166 /* Move entries. */
1167 for (j = 0; j < ARRAY_SIZE(entries); j++) {
1168 switch (entries[j].type) {
1169 case ENTRY_BOOL:
1170 if (secfile_lookup_bool(loading->file, &bval,
1171 "player%d.research.%s",
1172 plrno, entries[j].name)) {
1173 secfile_insert_bool(loading->file, bval, "research.r%d.%s",
1174 i, entries[j].name);
1175 }
1176 break;
1177 case ENTRY_INT:
1178 if (secfile_lookup_int(loading->file, &ival,
1179 "player%d.research.%s",
1180 plrno, entries[j].name)) {
1181 secfile_insert_int(loading->file, ival, "research.r%d.%s",
1182 i, entries[j].name);
1183 }
1184 break;
1185 case ENTRY_STR:
1186 if ((sval = secfile_lookup_str(loading->file,
1187 "player%d.research.%s",
1188 plrno, entries[j].name))) {
1189 secfile_insert_str(loading->file, sval, "research.r%d.%s",
1190 i, entries[j].name);
1191 }
1192 break;
1193 case ENTRY_FLOAT:
1195 "Research related entry marked as float.");
1196 break;
1199 break;
1200 case ENTRY_LONG_COMMENT:
1202 break;
1203 case ENTRY_ILLEGAL:
1205 break;
1206 }
1207 }
1209 secfile_insert_int(loading->file, count, "research.count");
1210 }
1211
1212 /* Add diplstate type order. */
1214 "savefile.diplstate_type_size");
1215 if (DS_LAST > 0) {
1216 const char **modname;
1217 int i;
1218 int j;
1219
1220 i = 0;
1221 modname = fc_calloc(DS_LAST, sizeof(*modname));
1222
1223 for (j = 0; j < DS_LAST; j++) {
1225 }
1226
1228 DS_LAST,
1229 "savefile.diplstate_type_vector");
1230 free(modname);
1231 }
1232
1233 /* Fix save games from Freeciv versions with a bug that made it view
1234 * "Never met" as closer than "Peace" or "Alliance". */
1235 player_slots_iterate(pslot) {
1236 int plrno = player_slot_index(pslot);
1237
1238 if (NULL == secfile_section_lookup(loading->file, "player%d", plrno)) {
1239 continue;
1240 }
1241
1243 int i = player_slot_index(pslot2);
1244 char buf[32];
1245 int current;
1246 int closest;
1247
1248 if (NULL == secfile_section_lookup(loading->file, "player%d", i)) {
1249 continue;
1250 }
1251
1252 fc_snprintf(buf, sizeof(buf), "player%d.diplstate%d", plrno, i);
1253
1254 /* Read the current diplomatic state. */
1256 "%s.type",
1257 buf);
1258
1259 /* Read the closest diplomatic state. */
1261 "%s.max_state",
1262 buf);
1263
1264 if (closest == DS_NO_CONTACT
1265 && (current == DS_PEACE
1266 || current == DS_ALLIANCE)) {
1267 const char *name1 = secfile_lookup_str_default(loading->file, "",
1268 "player%d.name", plrno);
1269 const char *name2 = secfile_lookup_str_default(loading->file, "",
1270 "player%d.name", i);
1271 /* The current relationship is closer than what the save game
1272 * claims is the closes relationship ever. */
1273
1274 log_sg(_("The save game is wrong about what the closest"
1275 " relationship %s (player %d) and %s (player %d) have had is."
1276 " Fixing it..."),
1277 name1, plrno, name2, i);
1278
1279 secfile_replace_int(loading->file, current, "%s.max_state", buf);
1280 }
1283}
1284
1285/************************************************************************/
1288static int increase_secfile_turn_int(struct loaddata *loading, const char *key,
1289 int old_def, bool keep_default)
1290{
1291 int value;
1292
1293 value = secfile_lookup_int_default(loading->file, old_def, "%s", key);
1294
1295 if (value != old_def || !keep_default) {
1296 value++;
1297 secfile_replace_int(loading->file, value, "%s", key);
1298 }
1299
1300 return value;
1301}
1302
1303/************************************************************************/
1311{
1312 bool randsaved;
1313 int num_settings;
1314 bool started;
1315 int old_turn;
1316 int event_count;
1317 int i;
1318
1319 /* Check status and return if not OK (sg_success FALSE). */
1320 sg_check_ret();
1321
1322 log_debug("Upgrading data from savegame to version 3.0.0");
1323
1324 /* Rename "random.save" as "random.saved"
1325 * Note that it's not an error if a scenario does not have [random] at all. */
1326 if (secfile_lookup_bool(loading->file, &randsaved, "random.save")) {
1327 secfile_insert_bool(loading->file, randsaved, "random.saved");
1328 }
1329
1330 /* Already started games should have their turn counts increased by 1 */
1331 if (secfile_lookup_bool_default(loading->file, TRUE, "game.save_players")) {
1332 started = TRUE;
1333
1334 old_turn = increase_secfile_turn_int(loading, "game.turn", 0, FALSE) - 1;
1336 increase_secfile_turn_int(loading, "history.turn", -2, TRUE);
1337 } else {
1338 started = FALSE;
1339 }
1340
1341 player_slots_iterate(pslot) {
1342 int plrno = player_slot_index(pslot);
1343 const char *flag_names[1];
1344
1345 if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) {
1346 continue;
1347 }
1348
1349 if (secfile_lookup_bool_default(loading->file, FALSE, "player%d.ai.control",
1350 plrno)) {
1352
1354 "player%d.flags", plrno);
1355 }
1356
1357 if (started) {
1358 int num = secfile_lookup_int_default(loading->file, 0,
1359 "player%d.nunits",
1360 plrno);
1361
1362 for (i = 0; i < num; i++) {
1363 char buf[64];
1364
1365 fc_snprintf(buf, sizeof(buf), "player%d.u%d.born", plrno, i);
1366
1368 }
1369
1370 num = secfile_lookup_int_default(loading->file, 0,
1371 "player%d.ncities", plrno);
1372
1373 for (i = 0; i < num; i++) {
1374 char buf[64];
1375
1376 fc_snprintf(buf, sizeof(buf), "player%d.c%d.turn_founded", plrno, i);
1377
1379 }
1380 }
1382
1383 /* Settings */
1385 "settings.set_count");
1386
1387 /* User meta server message is now a setting. */
1389 "game.meta_usermessage")) {
1390 const char *metamessage;
1391
1393 "game.meta_message");
1394
1395 /* Insert the meta message as a setting */
1396 secfile_insert_str(loading->file, "metamessage",
1397 "settings.set%d.name", num_settings);
1399 "settings.set%d.value", num_settings);
1400 secfile_insert_str(loading->file, "",
1401 "settings.set%d.gamestart", num_settings);
1402 num_settings++;
1403 }
1404
1405 secfile_replace_int(loading->file, num_settings, "settings.set_count");
1406
1407 event_count = secfile_lookup_int_default(loading->file, 0, "event_cache.count");
1408
1409 for (i = 0; i < event_count; i++) {
1410 const char *etype;
1411
1412 etype = secfile_lookup_str(loading->file, "event_cache.events%d.event", i);
1413
1414 if (etype != NULL && !fc_strcasecmp("E_UNIT_WIN", etype)) {
1415 secfile_replace_str(loading->file, "E_UNIT_WIN_DEF",
1416 "event_cache.events%d.event", i);
1417 }
1418 }
1419}
1420
1421/************************************************************************/
1426{
1427 int ssa_size;
1428
1429 if (format_class == SAVEGAME_2) {
1430 /* Handled in savegame2 */
1431 return;
1432 }
1433
1435 "savefile.server_side_agent_size");
1436
1437 if (ssa_size != 0) {
1438 /* Already inserted. */
1439 return;
1440 }
1441
1442 /* Add server side agent order. */
1444 "savefile.server_side_agent_size");
1445 if (SSA_COUNT > 0) {
1446 const char **modname;
1447 int i;
1448 int j;
1449
1450 i = 0;
1451 modname = fc_calloc(SSA_COUNT, sizeof(*modname));
1452
1453 for (j = 0; j < SSA_COUNT; j++) {
1455 }
1456
1458 SSA_COUNT,
1459 "savefile.server_side_agent_list");
1460 free(modname);
1461 }
1462
1463 /* Insert server_side_agent unit field. */
1464 player_slots_iterate(pslot) {
1465 int unit;
1466 int units_num;
1467 int plrno = player_slot_index(pslot);
1468
1469 if (secfile_section_lookup(loading->file, "player%d", plrno)
1470 == NULL) {
1471 continue;
1472 }
1473
1474 /* Number of units the player has. */
1476 "player%d.nunits",
1477 plrno);
1478
1479 for (unit = 0; unit < units_num; unit++) {
1480 bool ai;
1481
1483 "player%d.u%d.server_side_agent",
1484 plrno, unit)
1485 != NULL) {
1486 /* Already updated? */
1487 continue;
1488 }
1489
1491 "player%d.u%d.ai",
1492 plrno, unit);
1493
1494 if (ai) {
1495 /* Autoworker and Autoexplore are separated by
1496 * compat_post_load_030100() when set to SSA_AUTOWORKER */
1498 "player%d.u%d.server_side_agent",
1499 plrno, unit);
1500 } else {
1502 "player%d.u%d.server_side_agent",
1503 plrno, unit);
1504 }
1505 }
1507}
1508
1509/************************************************************************/
1517{
1518 /* Check status and return if not OK (sg_success FALSE). */
1519 sg_check_ret();
1520
1521 log_debug("Upgrading data from savegame to version 3.1.0");
1522
1523 /* Actions are now stored by number. */
1524 player_slots_iterate(pslot) {
1525 int unit;
1526 int units_num;
1527 int plrno = player_slot_index(pslot);
1528
1529 if (secfile_section_lookup(loading->file, "player%d", plrno)
1530 == NULL) {
1531 continue;
1532 }
1533
1534 /* Number of units the player has. */
1536 "player%d.nunits",
1537 plrno);
1538
1539 for (unit = 0; unit < units_num; unit++) {
1540 const char *action_unitstr;
1541 int order_len;
1542
1544 "player%d.u%d.orders_length",
1545 plrno, unit);
1546
1548 "player%d.u%d.action_list",
1549 plrno, unit))) {
1550 int order_num;
1551
1554 }
1555
1556 for (order_num = 0; order_num < order_len; order_num++) {
1558
1559 if (action_unitstr[order_num] == '?') {
1561 } else {
1563 }
1564
1565 if (order_num == 0) {
1566 /* The start of a vector has no number. */
1568 "player%d.u%d.action_vec",
1569 plrno, unit);
1570 } else {
1572 "player%d.u%d.action_vec,%d",
1573 plrno, unit, order_num);
1574 }
1575 }
1576 }
1577 }
1579
1580 {
1581 int action_count;
1582
1584 "savefile.action_size");
1585
1586 if (action_count > 0) {
1587 const char **modname;
1588 const char **savemod;
1589 int j;
1590 const char *dur_name = "Disband Unit Recover";
1591
1592 modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
1593 "savefile.action_vector");
1594
1596
1597 for (j = 0; j < action_count; j++) {
1598 if (!fc_strcasecmp("Recycle Unit", modname[j])) {
1599 savemod[j] = dur_name;
1600 } else {
1601 savemod[j] = modname[j];
1602 }
1603 }
1604
1606 "savefile.action_vector");
1607
1608 free(savemod);
1609 }
1610 }
1611
1612 /* Server setting migration. */
1613 {
1614 int set_count;
1615
1616 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
1617 int i;
1618 bool gamestart_valid
1620 "settings.gamestart_valid");
1621
1622 /* Only add gamesetdef if gamestart is valid at all */
1623 if (gamestart_valid) {
1624 for (i = 0; i < set_count; i++) {
1625 const char *name
1626 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
1627
1628 if (!name) {
1629 continue;
1630 }
1631
1633 "settings.set%d.gamesetdef", i);
1634 }
1635 }
1636 }
1637 }
1638
1639 /* Explicit server side agent was new in 3.1 */
1641}
1642
1643/************************************************************************/
1647{
1648 int i;
1649
1650 for (i = 0; i < act_unit->orders.length; i++) {
1651 struct unit_order *order = &act_unit->orders.list[i];
1652
1653 if (order->order != ORDER_ACTIVITY) {
1654 continue;
1655 }
1656
1657 switch (order->activity) {
1658 case ACTIVITY_CLEAN:
1659 case ACTIVITY_MINE:
1660 case ACTIVITY_IRRIGATE:
1661 case ACTIVITY_PLANT:
1662 case ACTIVITY_CULTIVATE:
1663 case ACTIVITY_TRANSFORM:
1664 case ACTIVITY_CONVERT:
1666 case ACTIVITY_BASE:
1667 case ACTIVITY_GEN_ROAD:
1668 case ACTIVITY_PILLAGE:
1669 action_iterate(act_id) {
1670 struct action *paction = action_by_number(act_id);
1671
1672 if (action_get_activity(paction) == order->activity) {
1673 order->order = ORDER_PERFORM_ACTION;
1674 order->action = action_number(paction);
1675 order->activity = ACTIVITY_LAST;
1676 break;
1677 }
1679 break;
1680 case ACTIVITY_SENTRY:
1681 /* Not an action */
1682 break;
1683 case ACTIVITY_EXPLORE:
1684 case ACTIVITY_IDLE:
1685 case ACTIVITY_GOTO:
1686 case ACTIVITY_FORTIFIED:
1687 case ACTIVITY_LAST:
1688 log_error("Activity %d is not supposed to appear in unit orders",
1689 order->activity);
1690 break;
1691 }
1692 }
1693}
1694
1695/************************************************************************/
1699{
1700 switch (dir) {
1701 case DIR8_NORTH:
1702 return DIR8_SOUTH;
1703 case DIR8_NORTHEAST:
1704 return DIR8_SOUTHWEST;
1705 case DIR8_EAST:
1706 return DIR8_WEST;
1707 case DIR8_SOUTHEAST:
1708 return DIR8_NORTHWEST;
1709 case DIR8_SOUTH:
1710 return DIR8_NORTH;
1711 case DIR8_SOUTHWEST:
1712 return DIR8_NORTHEAST;
1713 case DIR8_WEST:
1714 return DIR8_EAST;
1715 case DIR8_NORTHWEST:
1716 return DIR8_SOUTHEAST;
1717 }
1718
1719 return DIR8_ORIGIN;
1720}
1721
1722/************************************************************************/
1726{
1727 int i;
1728 struct tile *current_tile;
1729 struct tile *tgt_tile;
1730
1731 if (!unit_has_orders(act_unit)) {
1732 return;
1733 }
1734
1735 /* The order index is for the unit at its current tile. */
1736 current_tile = unit_tile(act_unit);
1737
1738 /* Rewind to the beginning of the orders */
1739 for (i = act_unit->orders.index; i > 0 && current_tile != NULL; i--) {
1740 struct unit_order *prev_order = &act_unit->orders.list[i - 1];
1741
1742 if (!(prev_order->order == ORDER_PERFORM_ACTION
1746 current_tile = mapstep(&(wld.map), current_tile,
1747 dir_opposite(prev_order->dir));
1748 }
1749 }
1750
1751 /* Upgrade to explicit target tile */
1752 for (i = 0; i < act_unit->orders.length && current_tile != NULL; i++) {
1753 struct unit_order *order = &act_unit->orders.list[i];
1754
1755 if (order->order == ORDER_PERFORM_ACTION
1756 && order->target != NO_TARGET) {
1757 /* The target is already specified in the new format. */
1758
1759 /* The index_to_tile() call has no side-effects that we
1760 * would want also in NDEBUG builds. */
1761 fc_assert(index_to_tile(&(wld.map), order->target) != NULL);
1762 return;
1763 }
1764
1765 if (!direction8_is_valid(order->dir)) {
1766 /* The target of the action is on the actor's tile. */
1767 tgt_tile = current_tile;
1768 } else {
1769 /* The target of the action is on a tile next to the actor. */
1770 tgt_tile = mapstep(&(wld.map), current_tile, order->dir);
1771 }
1772
1773 if (order->order == ORDER_PERFORM_ACTION) {
1774 if (tgt_tile != NULL) {
1775 struct action *paction = action_by_number(order->action);
1776
1777 order->target = tgt_tile->index;
1778 /* Leave no traces. */
1779 order->dir = DIR8_ORIGIN;
1780
1782 /* The action moves the unit to the target tile (unless this is the
1783 * final order) */
1786 || i == act_unit->orders.length - 1);
1787 current_tile = tgt_tile;
1788 }
1789 } else {
1790 current_tile = NULL;
1791 }
1792 } else {
1793 current_tile = tgt_tile;
1794 }
1795 }
1796
1797 if (current_tile == NULL) {
1798 log_sg("Illegal orders for %s. Cancelling.", unit_rule_name(act_unit));
1800 }
1801}
1802
1803/************************************************************************/
1807{
1808 players_iterate_alive(pplayer) {
1809 unit_list_iterate(pplayer->units, punit) {
1812 }
1815}
1816
1817/************************************************************************/
1822{
1823 /* Check status and return if not OK (sg_success FALSE). */
1824 sg_check_ret();
1825
1826 /* Action orders were new in 3.0 */
1827 if (format_class == SAVEGAME_3) {
1828 /* Only 3.0 savegames may have "Attack" action orders. */
1829 players_iterate_alive(pplayer) {
1830 unit_list_iterate(pplayer->units, punit) {
1831 int i;
1832
1833 if (!punit->has_orders) {
1834 continue;
1835 }
1836
1838 || punit->orders.list != NULL, continue);
1839
1840 for (i = 0; i < punit->orders.length; i++) {
1841 /* "Attack" was split in "Suicide Attack" and "Attack" in 3.1. */
1847 }
1848
1849 /* Production targeted actions were split from building targeted
1850 * actions in 3.1. The building sub target encoding changed. */
1852 && ((punit->orders.list[i].action
1854 || (punit->orders.list[i].action
1856 punit->orders.list[i].sub_target -= 1;
1857 }
1859 && (punit->orders.list[i].action
1861 && punit->orders.list[i].sub_target == -1) {
1864 }
1866 && (punit->orders.list[i].action
1868 && punit->orders.list[i].sub_target == -1) {
1871 }
1872 }
1875 }
1876
1877 /* Explicit server side agent was new in 3.1 */
1879
1880 /* Some activities should only be ordered in action orders. */
1881 players_iterate_alive(pplayer) {
1882 unit_list_iterate(pplayer->units, punit) {
1886
1887 /* Unit order action target isn't dir anymore */
1888 players_iterate_alive(pplayer) {
1889 unit_list_iterate(pplayer->units, punit) {
1893
1894 /* Backward compatibility: if we had any open-ended orders (pillage)
1895 * in the savegame, assign specific targets now */
1896 players_iterate_alive(pplayer) {
1897 unit_list_iterate(pplayer->units, punit) {
1899 &punit->activity,
1900 punit->action,
1904}
1905
1906/************************************************************************/
1914{
1915 int i;
1916 int count;
1917 int set_count;
1918 bool gamestart_valid = FALSE;
1919
1920 /* Check status and return if not OK (sg_success FALSE). */
1921 sg_check_ret();
1922
1923 log_debug("Upgrading data from savegame to version 3.2.0");
1924
1925 {
1926 const char *str = secfile_lookup_str_default(loading->file, NULL,
1927 "savefile.orig_version");
1928
1929 if (str == NULL) {
1930 /* Make sure CURRENTLY running version does not
1931 * end as orig_version when we resave. */
1932 if (format_class == SAVEGAME_3) {
1933 secfile_insert_str(loading->file, "old savegame3, or older",
1934 "savefile.orig_version");
1935 } else {
1937
1938 secfile_insert_str(loading->file, "savegame2, or older",
1939 "savefile.orig_version");
1940 }
1941 }
1942 }
1943
1944 {
1945 int action_count;
1946
1948 "savefile.action_size");
1949
1950 if (action_count > 0) {
1951 const char **modname;
1952 const char **savemod;
1953 int j;
1954 const char *dur_name = "Transport Deboard";
1955 const char *clean_name = "Clean";
1956
1957 modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
1958 "savefile.action_vector");
1959
1961
1962 for (j = 0; j < action_count; j++) {
1963 if (!fc_strcasecmp("Transport Alight", modname[j])) {
1964 savemod[j] = dur_name;
1965 } else if (!fc_strcasecmp("Clean Pollution", modname[j])
1966 || !fc_strcasecmp("Clean Fallout", modname[j])) {
1967 savemod[j] = clean_name;
1968 } else {
1969 savemod[j] = modname[j];
1970 }
1971 }
1972
1974 "savefile.action_vector");
1975
1976 free(savemod);
1977 }
1978 }
1979
1980 {
1981 int activities_count;
1982
1984 "savefile.activities_size");
1985
1986 if (activities_count > 0) {
1987 const char **modname;
1988 const char **savemod;
1989 int j;
1990 const char *clean_name = "Clean";
1991
1992 modname = secfile_lookup_str_vec(loading->file, &loading->activities.size,
1993 "savefile.activities_vector");
1994
1996
1997 for (j = 0; j < activities_count; j++) {
1998 if (!fc_strcasecmp("Pollution", modname[j])
1999 || !fc_strcasecmp("Fallout", modname[j])) {
2000 savemod[j] = clean_name;
2001 } else {
2002 savemod[j] = modname[j];
2003 }
2004 }
2005
2007 "savefile.activities_vector");
2008
2009 free(savemod);
2010 }
2011 }
2012
2013 /* Server setting migration. */
2014 {
2015 if (secfile_lookup_int(loading->file, &set_count, "settings.set_count")) {
2016 int alltemperate_idx = -1, singlepole_idx = -1;
2017 bool count_changed = FALSE;
2018
2021 "settings.gamestart_valid");
2022
2023 for (i = 0; i < set_count; i++) {
2024 const char *old_name
2025 = secfile_lookup_str(loading->file, "settings.set%d.name", i);
2026 const char *name;
2027
2028 if (!old_name) {
2029 continue;
2030 }
2031
2033
2034 if (fc_strcasecmp(old_name, name)) {
2035 /* Setting's name changed */
2036 secfile_replace_str(loading->file, name, "settings.set%d.name", i);
2037 }
2038
2039 if (!gamestart_valid) {
2040 /* Older savegames saved these values even when they were not valid.
2041 * Silence warnings caused by them. */
2042 secfile_entry_ignore(loading->file, "settings.set%d.gamestart", i);
2043 secfile_entry_ignore(loading->file, "settings.set%d.gamesetdef", i);
2044 }
2045
2046 if (!fc_strcasecmp("compresstype", name)) {
2047 const char *val = secfile_lookup_str(loading->file,
2048 "settings.set%d.value", i);
2049 if (!fc_strcasecmp(val, "BZIP2")) {
2050#ifdef FREECIV_HAVE_LIBZSTD
2051 secfile_replace_str(loading->file, "ZSTD",
2052 "settings.set%d.value", i);
2053#elif FREECIV_HAVE_LIBLZMA
2054 secfile_replace_str(loading->file, "XZ",
2055 "settings.set%d.value", i);
2056#elif FREECIV_HAVE_LIBZ
2057 secfile_replace_str(loading->file, "LIBZ",
2058 "settings.set%d.value", i);
2059#else
2060 secfile_replace_str(loading->file, "PLAIN",
2061 "settings.set%d.value", i);
2062#endif
2063 }
2064
2065 if (gamestart_valid) {
2066 val = secfile_lookup_str(loading->file,
2067 "settings.set%d.gamestart", i);
2068 if (!fc_strcasecmp(val, "BZIP2")) {
2069#ifdef FREECIV_HAVE_LIBZSTD
2070 secfile_replace_str(loading->file, "ZSTD",
2071 "settings.set%d.gamestart", i);
2072#elif FREECIV_HAVE_LIBLZMA
2073 secfile_replace_str(loading->file, "XZ",
2074 "settings.set%d.gamestart", i);
2075#elif FREECIV_HAVE_LIBZ
2076 secfile_replace_str(loading->file, "LIBZ",
2077 "settings.set%d.gamestart", i);
2078#else
2079 secfile_replace_str(loading->file, "PLAIN",
2080 "settings.set%d.gamestart", i);
2081#endif
2082 }
2083 }
2084 } else if (!fc_strcasecmp("topology", name)) {
2085 struct setting *pset = setting_by_name(name);
2086 struct sf_cb_data info = { pset, TRUE };
2087 int val;
2088
2089 if (secfile_lookup_enum_data(loading->file, &val, TRUE,
2091 "settings.set%d.value", i)) {
2092 char wrap[100];
2093 char buf[100];
2094
2095 if (val & TF_OLD_WRAPX) {
2096 if (val & TF_OLD_WRAPY) {
2097 fc_strlcpy(wrap, "WrapX|WrapY", sizeof(wrap));
2098 } else {
2099 fc_strlcpy(wrap, "WrapX", sizeof(wrap));
2100 }
2101 } else if (val & TF_OLD_WRAPY) {
2102 fc_strlcpy(wrap, "WrapY", sizeof(wrap));
2103 } else {
2104 fc_strlcpy(wrap, "", sizeof(wrap));
2105 }
2106
2107 if (val & TF_ISO) {
2108 if (val & TF_HEX) {
2109 setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0);
2110 } else {
2111 setting_bitwise_set(pset, "ISO", NULL, NULL, 0);
2112 }
2113 } else if (val & TF_HEX) {
2114 setting_bitwise_set(pset, "HEX", NULL, NULL, 0);
2115 } else {
2117 }
2118
2119 setting_value_name(pset, FALSE, buf, sizeof(buf));
2121 "settings.set%d.value", i);
2122
2124 "wrap", "settings.set%d.name", set_count);
2126 wrap, "settings.set%d.value", set_count);
2127
2128 if (gamestart_valid) {
2129 if (secfile_lookup_enum_data(loading->file, &val, TRUE,
2131 "settings.set%d.gamestart", i)) {
2132 if (val & TF_OLD_WRAPX) {
2133 if (val & TF_OLD_WRAPY) {
2134 fc_strlcpy(wrap, "WrapX|WrapY", sizeof(wrap));
2135 } else {
2136 fc_strlcpy(wrap, "WrapX", sizeof(wrap));
2137 }
2138 } else if (val & TF_OLD_WRAPY) {
2139 fc_strlcpy(wrap, "WrapY", sizeof(wrap));
2140 } else {
2141 fc_strlcpy(wrap, "", sizeof(wrap));
2142 }
2143
2144 if (val & TF_ISO) {
2145 if (val & TF_HEX) {
2146 setting_bitwise_set(pset, "ISO|HEX", NULL, NULL, 0);
2147 } else {
2148 setting_bitwise_set(pset, "ISO", NULL, NULL, 0);
2149 }
2150 } else if (val & TF_HEX) {
2151 setting_bitwise_set(pset, "HEX", NULL, NULL, 0);
2152 } else {
2154 }
2155
2156 setting_value_name(pset, FALSE, buf, sizeof(buf));
2158 "settings.set%d.gamestart", i);
2159
2161 wrap, "settings.set%d.gamestart", set_count);
2162 }
2163 }
2164
2165 set_count++;
2167 }
2168 } else if (!fc_strcasecmp("alltemperate", name)) {
2170 } else if (!fc_strcasecmp("singlepole", name)) {
2171 singlepole_idx = i;
2172 }
2173 }
2174
2175 if (alltemperate_idx >= 0 || singlepole_idx >= 0) {
2176 int north_latitude, south_latitude;
2177 int north_idx, south_idx;
2179
2180 if (alltemperate_idx < 0
2182 "settings.set%d.value",
2184 /* Infer what would've been the ruleset default */
2186 }
2187
2188 if (singlepole_idx < 0
2190 "settings.set%d.value",
2191 singlepole_idx)) {
2192 /* Infer what would've been the ruleset default */
2194 }
2195
2196 /* Note: hard-coding 1000-based latitudes here; if MAX_LATITUDE ever
2197 * changes, that'll have to be handled in later migrations anyway */
2198 north_latitude = alltemperate ? 500 : 1000;
2199 south_latitude = alltemperate ? 500 : (singlepole ? 0 : -1000);
2200
2201 /* Replace alltemperate with northlatitude, and singlepole with
2202 * southlatitude. If only one of the two was given, add the other
2203 * at the end. */
2206
2207 secfile_replace_str(loading->file, "northlatitude",
2208 "settings.set%d.name", north_idx);
2209 secfile_replace_int(loading->file, north_latitude,
2210 "settings.set%d.value", north_idx);
2211
2212 secfile_replace_str(loading->file, "southlatitude",
2213 "settings.set%d.name", south_idx);
2214 secfile_replace_int(loading->file, south_latitude,
2215 "settings.set%d.value", south_idx);
2216
2217 if (gamestart_valid) {
2218 if (alltemperate_idx < 0
2220 "settings.set%d.gamestart",
2222 alltemperate =
2224 }
2225
2226 if (singlepole_idx < 0
2228 "settings.set%d.gamestart",
2229 singlepole_idx)) {
2231 }
2232
2233 north_latitude = alltemperate ? 500 : 1000;
2234 south_latitude = alltemperate ? 500 : (singlepole ? 0 : -1000);
2235
2236 secfile_replace_int(loading->file, north_latitude,
2237 "settings.set%d.gamestart", north_idx);
2238 secfile_replace_int(loading->file, south_latitude,
2239 "settings.set%d.gamestart", south_idx);
2240 }
2241
2242 if (alltemperate_idx < 0 || singlepole_idx < 0) {
2243 /* only one was given and replaced ~> we added one new entry */
2244 set_count++;
2246 }
2247 }
2248
2249 if (count_changed) {
2251 "settings.set_count");
2252 }
2253 }
2254 }
2255
2256 {
2257 /* Turn old AI level field to a setting. */
2258 const char *level;
2259 enum ai_level lvl;
2260
2261 level = secfile_lookup_str_default(loading->file, NULL, "game.level");
2262 if (level != NULL && !fc_strcasecmp("Handicapped", level)) {
2263 /* Up to freeciv-3.1 Restricted AI level was known as Handicapped */
2265 } else {
2267 }
2268
2269 if (!ai_level_is_valid(lvl)) {
2270 log_sg("Invalid AI level \"%s\". "
2271 "Changed to \"%s\".", level,
2274 }
2275
2276 secfile_insert_str(loading->file, "ailevel", "settings.set%d.name", set_count);
2277 secfile_insert_enum(loading->file, lvl, ai_level, "settings.set%d.value", set_count);
2278
2279 if (gamestart_valid) {
2280 secfile_insert_enum(loading->file, lvl, ai_level, "settings.set%d.gamestart",
2281 set_count);
2282 }
2283
2284 set_count++;
2285 secfile_replace_int(loading->file, set_count, "settings.set_count");
2286 }
2287
2288 if (format_class != SAVEGAME_2) {
2289 /* Replace got_tech[_multi] bools on free_bulbs integers. */
2290 /* Older savegames had a bug that got_tech_multi was not saved. */
2291 count = secfile_lookup_int_default(loading->file, 0, "research.count");
2292 for (i = 0; i < count; i++) {
2293 bool got_tech = FALSE;
2294 int bulbs = 0;
2295 bool got_tech_multi
2297 "research.r%d.got_tech_multi", i);
2298
2300 "research.r%d.got_tech", i)
2301 && secfile_lookup_int(loading->file, &bulbs,
2302 "research.r%d.bulbs", i)) {
2304 got_tech || got_tech_multi ? bulbs : 0,
2305 "research.r%d.free_bulbs", i);
2306 }
2307 }
2308 }
2309
2310 /* Older savegames unnecessarily saved diplstate type order.
2311 * Silence "unused entry" warnings about those. */
2312 {
2314 "savefile.diplstate_type_size");
2315
2316 for (i = 0; i < dscount; i++) {
2318 "savefile.diplstate_type_vector,%d", i);
2319 }
2320 }
2321
2322 /* Add wl_max_length entries for players */
2323 {
2324 player_slots_iterate(pslot) {
2325 int plrno = player_slot_index(pslot);
2326 int ncities;
2327 int cnro;
2328 size_t wlist_max_length = 0;
2329 bool first_city;
2330
2331 if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) {
2332 continue;
2333 }
2334
2336 "player%d.got_first_city",
2337 plrno);
2338 if (first_city) {
2339 const char **flag_names = fc_calloc(PLRF_COUNT, sizeof(char *));
2340 int flagcount = 0;
2341 const char **flags_sg;
2342 size_t nval;
2343
2345
2347 "player%d.flags", plrno);
2348
2349 for (i = 0; i < nval; i++) {
2352
2354 }
2355
2357 "player%d.flags", plrno);
2358
2360 }
2361
2363 "player%d.ncities", plrno);
2364
2365 for (cnro = 0; cnro < ncities; cnro++) {
2367 "player%d.c%d.wl_length",
2368 plrno, cnro);
2369
2371
2372 if (format_class == SAVEGAME_3) {
2374 "player%d.c%d.original",
2375 plrno, cnro) != plrno) {
2377 "player%d.c%d.acquire_t",
2378 plrno, cnro);
2379 } else {
2381 "player%d.c%d.acquire_t",
2382 plrno, cnro);
2383 }
2384
2386 "player%d.c%d.wlcb",
2387 plrno, cnro);
2388 }
2389 }
2390
2392 "player%d.wl_max_length", plrno);
2393
2394 if (format_class == SAVEGAME_3) {
2395 int nunits;
2396 int unro;
2397 size_t olist_max_length = 0;
2398
2400 "player%d.nunits", plrno);
2401
2402 for (unro = 0; unro < nunits; unro++) {
2404 "player%d.u%d.orders_length",
2405 plrno, unro);
2406
2408 }
2409
2411 "player%d.orders_max_length", plrno);
2412
2414 "player%d.routes_max_length", plrno);
2415 }
2416
2418 }
2419}
2420
2421/************************************************************************/
2429{
2430 /* Check status and return if not OK (sg_success != TRUE). */
2431 sg_check_ret();
2432
2433 log_debug("Upgrading data from savegame to version 3.3.0");
2434
2435 /* World Peace has never started in the old savegame. */
2436 game.info.turn = secfile_lookup_int_default(loading->file, 0, "game.turn");
2437
2438 if (format_class != SAVEGAME_2) {
2439 secfile_insert_int(loading->file, game.info.turn, "game.world_peace_start");
2440
2441 secfile_insert_bool(loading->file, FALSE, "map.altitude");
2442 }
2443
2444 /* Last turn change time as a float, not integer multiplied by 100 */
2445 {
2446 float tct = secfile_lookup_int_default(loading->file, 0,
2447 "game.last_turn_change_time") / 100.0;
2448
2449 secfile_replace_float(loading->file, tct, "game.last_turn_change_time");
2450 }
2451
2452 {
2453 int ssa_count;
2454
2456 "savefile.server_side_agent_size");
2457 if (ssa_count > 0) {
2458 const char **modname;
2459 const char **savemod;
2460 int j;
2461 const char *aw_name = "AutoWorker";
2462
2463 modname = secfile_lookup_str_vec(loading->file, &loading->ssa.size,
2464 "savefile.server_side_agent_list");
2465
2466 savemod = fc_calloc(ssa_count, sizeof(*savemod));
2467
2468 for (j = 0; j < ssa_count; j++) {
2469 if (!fc_strcasecmp("Autosettlers", modname[j])) {
2470 savemod[j] = aw_name;
2471 } else {
2472 savemod[j] = modname[j];
2473 }
2474 }
2475
2477 "savefile.server_side_agent_list");
2478
2479 free(savemod);
2480 }
2481 }
2482
2483 {
2484 int action_count;
2485
2487 "savefile.action_size");
2488
2489 if (action_count > 0) {
2490 const char **modname;
2491 const char **savemod;
2492 int j;
2493 const char *cc1_name = "Conquer City Shrink";
2494 const char *cc2_name = "Conquer City Shrink 2";
2495 const char *cc3_name = "Conquer City Shrink 3";
2496 const char *cc4_name = "Conquer City Shrink 4";
2497
2498 modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
2499 "savefile.action_vector");
2500
2502
2503 for (j = 0; j < action_count; j++) {
2504 if (!fc_strcasecmp("Conquer City", modname[j])) {
2505 savemod[j] = cc1_name;
2506 } else if (!fc_strcasecmp("Conquer City 2", modname[j])) {
2507 savemod[j] = cc2_name;
2508 } else if (!fc_strcasecmp("Conquer City 3", modname[j])) {
2509 savemod[j] = cc3_name;
2510 } else if (!fc_strcasecmp("Conquer City 4", modname[j])) {
2511 savemod[j] = cc4_name;
2512 } else {
2513 savemod[j] = modname[j];
2514 }
2515 }
2516
2518 "savefile.action_vector");
2519
2520 free(savemod);
2521 }
2522 }
2523
2524 /* Add actions for unit activities */
2525 if (format_class == SAVEGAME_3) {
2526 loading->activities.size
2528 "savefile.activities_size");
2529 if (loading->activities.size) {
2530 loading->activities.order
2531 = secfile_lookup_str_vec(loading->file, &loading->activities.size,
2532 "savefile.activities_vector");
2533 sg_failure_ret(loading->activities.size != 0,
2534 "Failed to load activity order: %s",
2535 secfile_error());
2536 }
2537
2538 loading->action.size = secfile_lookup_int_default(loading->file, 0,
2539 "savefile.action_size");
2540
2541 sg_failure_ret(loading->action.size > 0,
2542 "Failed to load action order: %s",
2543 secfile_error());
2544
2545 if (loading->action.size) {
2546 const char **modname;
2547 int j;
2548
2549 modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
2550 "savefile.action_vector");
2551
2552 loading->action.order = fc_calloc(loading->action.size,
2553 sizeof(*loading->action.order));
2554
2555 for (j = 0; j < loading->action.size; j++) {
2557
2558 if (real_action != nullptr) {
2559 loading->action.order[j] = real_action->id;
2560 } else {
2561 log_sg("Unknown action \'%s\'", modname[j]);
2562 loading->action.order[j] = ACTION_NONE;
2563 }
2564 }
2565
2566 free(modname);
2567 }
2568
2569 player_slots_iterate(pslot) {
2570 int plrno = player_slot_index(pslot);
2571 int nunits;
2572 int unro;
2573
2574 if (secfile_section_lookup(loading->file, "player%d", plrno) == nullptr) {
2575 continue;
2576 }
2577
2579 "player%d.nunits", plrno);
2580
2581 for (unro = 0; unro < nunits; unro++) {
2582 int ei;
2583 int i;
2584 enum unit_activity activity;
2585 enum gen_action act;
2586
2588 "player%d.u%d.activity", plrno, unro);
2589
2590 if (ei >= 0 && ei < loading->activities.size) {
2591 bool found = FALSE;
2592
2593 activity = unit_activity_by_name(loading->activities.order[ei],
2595
2596 act = activity_default_action(activity);
2597
2598 for (i = 0; i < loading->action.size; i++) {
2599 if (act == loading->action.order[i]) {
2600 secfile_insert_int(loading->file, i, "player%d.u%d.action",
2601 plrno, unro);
2602 found = TRUE;
2603 break;
2604 }
2605 }
2606
2607 if (!found) {
2608 secfile_insert_int(loading->file, -1, "player%d.u%d.action",
2609 plrno, unro);
2610 }
2611 }
2612 }
2614 }
2615
2616 /* Researches */
2617 {
2618 int count = secfile_lookup_int_default(loading->file, 0, "research.count");
2619 int i;
2620
2621 for (i = 0; i < count; i++) {
2622 /* It's ok for old savegames to have these entries. */
2623 secfile_entry_ignore(loading->file, "research.r%d.techs", i);
2624 }
2625 }
2626
2627 player_slots_iterate(pslot) {
2628 int plrno = player_slot_index(pslot);
2629 int ncities;
2630 int cnro;
2631
2632 if (secfile_section_lookup(loading->file, "player%d", plrno) == nullptr) {
2633 continue;
2634 }
2635
2637 "player%d.dc_total", plrno);
2638
2639 for (cnro = 0; cnro < ncities; cnro++) {
2640 secfile_insert_int(loading->file, -1, "player%d.c%d.original",
2641 plrno, cnro);
2642 }
2644}
2645
2646/************************************************************************/
2651{
2652 /* Check status and return if not OK (sg_success FALSE). */
2653 sg_check_ret();
2654
2655 /* Capital information was not saved in older savegames,
2656 * so we have no capital setup at all at the moment.
2657 * Best we can do is to do recalculation now. It might be
2658 * a bit off compared to the situation before the game was saved,
2659 * but definitely better than not setting capitals at all. */
2660 players_iterate_alive(pplayer) {
2661 update_capital(pplayer);
2663}
2664
2665/************************************************************************/
2668enum ai_level ai_level_convert(int old_level)
2669{
2670 switch (old_level) {
2671 case 1:
2672 return AI_LEVEL_AWAY;
2673 case 2:
2674 return AI_LEVEL_NOVICE;
2675 case 3:
2676 return AI_LEVEL_EASY;
2677 case 5:
2678 return AI_LEVEL_NORMAL;
2679 case 7:
2680 return AI_LEVEL_HARD;
2681 case 8:
2682 return AI_LEVEL_CHEATING;
2683 case 10:
2684#ifdef FREECIV_DEBUG
2685 return AI_LEVEL_EXPERIMENTAL;
2686#else /* FREECIV_DEBUG */
2687 return AI_LEVEL_HARD;
2688#endif /* FREECIV_DEBUG */
2689 }
2690
2691 return ai_level_invalid();
2692}
2693
2694/************************************************************************/
2697enum barbarian_type barb_type_convert(int old_type)
2698{
2699 switch (old_type) {
2700 case 0:
2701 return NOT_A_BARBARIAN;
2702 case 1:
2703 return LAND_BARBARIAN;
2704 case 2:
2705 return SEA_BARBARIAN;
2706 }
2707
2708 return barbarian_type_invalid();
2709}
struct action * action_by_rule_name(const char *name)
Definition actions.c:1079
int action_number(const struct action *action)
Definition actions.c:1208
static struct action * action_by_number(action_id act_id)
Definition actions.h:400
#define action_iterate_end
Definition actions.h:218
#define action_get_activity(_pact_)
Definition actions.h:464
#define action_iterate(_act_)
Definition actions.h:214
#define ACTION_NONE
Definition actions.h:59
struct @130::my_agent entries[MAX_AGENTS]
const char * default_ai_type_name(void)
Definition aiiface.c:249
#define str
Definition astring.c:76
bool has_capability(const char *cap, const char *capstr)
Definition capability.c:79
char * incite_cost
Definition comments.c:76
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:214
#define EC_SPECIAL
Definition fc_types.h:821
revolen_type
Definition fc_types.h:990
@ REVOLEN_RANDOM
Definition fc_types.h:992
@ REVOLEN_RANDQUICK
Definition fc_types.h:994
@ REVOLEN_FIXED
Definition fc_types.h:991
@ REVOLEN_QUICKENING
Definition fc_types.h:993
#define DIR8_ORIGIN
Definition fc_types.h:315
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:61
struct world wld
Definition game.c:62
#define GAME_DEFAULT_REVOLENTYPE
Definition game.h:743
#define GAME_DEFAULT_SCORETURN
Definition game.h:587
#define GAME_DEFAULT_SAVETURNS
Definition game.h:685
#define GAME_DEFAULT_TEAM_POOLED_RESEARCH
Definition game.h:571
#define GAME_HARDCODED_DEFAULT_SKILL_LEVEL
Definition game.h:703
GType type
Definition repodlgs.c:1313
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_normal(message,...)
Definition log.h:108
#define log_error(message,...)
Definition log.h:104
struct tile * index_to_tile(const struct civ_map *imap, int mindex)
Definition map.c:471
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:384
#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:528
#define players_iterate_alive_end
Definition player.h:552
#define player_slots_iterate_end
Definition player.h:532
#define players_iterate_alive(_pplayer)
Definition player.h:547
void update_capital(struct player *pplayer)
Definition plrhand.c:732
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)
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_entry_ignore(_sfile_, _fmt_,...)
#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_float(secfile, value, path,...)
#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:313
int current_compat_ver(void)
Definition savecompat.c:212
static void compat_load_030000(struct loaddata *loading, enum sgf_version format_class)
static const char num_chars[]
Definition savecompat.c:252
bool sg_success
Definition savecompat.c:35
static const char * killcitizen_enum_str(secfile_data_t data, int bit)
Definition savecompat.c:560
enum barbarian_type barb_type_convert(int old_type)
#define LINES_2_3
#define MAXMAPSIZE_2_3
static char * special_names[]
Definition savecompat.c:37
static struct compatibility compat[]
Definition savecompat.c:110
static void compat_load_020400(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:331
static void upgrade_unit_order_targets(struct unit *act_unit)
static void compat_load_030300(struct loaddata *loading, enum sgf_version format_class)
char bin2ascii_hex(int value, int halfbyte_wanted)
Definition savecompat.c:222
static const int compat_num
Definition savecompat.c:135
static void compat_load_020600(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:703
static enum direction8 dir_opposite(enum direction8 dir)
void(* load_version_func_t)(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:90
int char2num(char ch)
Definition savecompat.c:258
static void upgrade_server_side_agent(struct loaddata *loading)
void sg_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:145
static void unit_order_activity_to_action(struct unit *act_unit)
static char * revolentype_str(enum revolen_type type)
Definition savecompat.c:684
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:234
struct extra_type * special_extra_get(int spe)
Definition savecompat.c:299
static void compat_load_020500(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:577
static void compat_load_030200(struct loaddata *loading, enum sgf_version format_class)
static void compat_post_load_030300(struct loaddata *loading, enum sgf_version format_class)
enum tile_special_type special_by_rule_name(const char *name)
Definition savecompat.c:273
void sg_load_post_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:190
const char * special_rule_name(enum tile_special_type type)
Definition savecompat.c:289
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:136
#define sg_check_ret(...)
Definition savecompat.h:148
#define sg_warn(condition, message,...)
Definition savecompat.h:158
tile_special_type
Definition savecompat.h:29
@ S_LAST
Definition savecompat.h:38
#define hex_chars
Definition savecompat.h:203
#define sg_failure_ret_val(condition, _val, message,...)
Definition savecompat.h:182
#define sg_failure_ret(condition, message,...)
Definition savecompat.h:175
#define MAX_TRADE_ROUTES_OLD
Definition savecompat.h:220
sgf_version
Definition savecompat.h:27
@ SAVEGAME_2
Definition savecompat.h:27
@ SAVEGAME_3
Definition savecompat.h:27
#define log_sg
Definition savecompat.h:144
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:3309
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4267
bool setting_bitwise_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:4223
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:4065
#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
struct packet_game_info info
Definition game.h:89
int north_latitude
Definition map_types.h:80
int south_latitude
Definition map_types.h:81
struct civ_map::@44::@46 server
int huts_absolute
Definition map_types.h:108
const load_version_func_t post_load
Definition savecompat.c:95
const load_version_func_t load
Definition savecompat.c:94
struct name_translation name
Definition specialist.h:31
Definition tile.h:50
enum unit_activity activity
Definition unit.h:94
enum unit_orders order
Definition unit.h:93
int action
Definition unit.h:101
enum direction8 dir
Definition unit.h:103
int target
Definition unit.h:97
int sub_target
Definition unit.h:98
Definition unit.h:139
int length
Definition unit.h:197
bool has_orders
Definition unit.h:195
enum unit_activity activity
Definition unit.h:158
enum gen_action action
Definition unit.h:159
struct unit::@83 orders
struct extra_type * activity_target
Definition unit.h:166
struct unit_order * list
Definition unit.h:200
enum server_side_agent ssa_controller
Definition unit.h:174
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
#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:125
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:246
#define terrain_type_iterate(_p)
Definition terrain.h:267
#define terrain_type_iterate_end
Definition terrain.h:273
void free_unit_orders(struct unit *punit)
Definition unit.c:1832
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:401
enum gen_action activity_default_action(enum unit_activity act)
Definition unit.c:2956
bool unit_has_orders(const struct unit *punit)
Definition unit.c:220
#define unit_tile(_pu)
Definition unit.h:406
@ ORDER_ACTIVITY
Definition unit.h:41
@ ORDER_PERFORM_ACTION
Definition unit.h:47
#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, enum gen_action action, struct extra_type **target)
Definition unittools.c:1083
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:1253
const char * unit_rule_name(const struct unit *punit)
Definition unittype.c:1591
bool utype_is_unmoved_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1292