Freeciv-3.3: /fast/freeciv/nightly/main/server/savegame/savecompat.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
savecompat.h
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#ifndef FC__SAVECOMPAT_H
14#define FC__SAVECOMPAT_H
15
16/* utility */
17#include "rand.h"
18
19/* server */
20#include "srv_main.h"
21
22struct section_file;
23struct extra_type;
24struct base_type;
25struct road_type;
26
27 enum sgf_version { SAVEGAME_2, SAVEGAME_3 };
28
29 enum tile_special_type {
30 S_IRRIGATION,
31 S_MINE,
32 S_POLLUTION,
33 S_HUT,
34 S_FARMLAND,
35 S_FALLOUT,
36
37 /* internal values not saved */
38 S_LAST,
39
40 S_OLD_FORTRESS,
41 S_OLD_AIRBASE,
42 S_OLD_ROAD,
43 S_OLD_RAILROAD,
44 S_OLD_RIVER
45};
46
47 struct loaddata {
48 struct section_file *file;
49 const char *secfile_options;
50 int version;
51 int full_version;
52
53 struct {
54 const char **order;
55 size_t size;
56 } counter;
57 /* loaded in sg_load_savefile(); needed in sg_load_player() */
58 struct {
59 const char **order;
60 size_t size;
61 } improvement;
62 /* loaded in sg_load_savefile(); needed in sg_load_player() */
63 struct {
64 const char **order;
65 size_t size;
66 } technology;
67 /* loaded in sg_load_savefile(); needed in sg_load_player() */
68 struct {
69 const char **order;
70 size_t size;
71 } activities;
72 /* loaded in sg_load_savefile(); needed in sg_load_player() */
73 struct {
74 const char **order;
75 size_t size;
76 } trait;
77 /* loaded in sg_load_savefile(); needed in sg_load_map(), ... */
78 struct {
79 struct extra_type **order;
80 size_t size;
81 } extra;
82 /* loaded in sg_load_savefile(); needed in sg_load_players_basic() */
83 struct {
84 struct multiplier **order;
85 size_t size;
86 } multiplier;
87 /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
88 * Deprecated in 3.0 (savegame3.c) */
89 struct {
90 enum tile_special_type *order;
91 size_t size;
92 } special;
93 /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
94 * Deprecated in 3.0 (savegame3.c) */
95 struct {
96 struct base_type **order;
97 size_t size;
98 } base;
99 /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
100 * Deprecated in 3.0 (savegame3.c) */
101 struct {
102 struct road_type **order;
103 size_t size;
104 } road;
105 /* loaded in sg_load_savefile(); needed in sg_load_(), ... */
106 struct {
107 struct specialist **order;
108 size_t size;
109 } specialist;
110 /* loaded in sg_load_savefile(); needed in sg_load_player_main(), ... */
111 /* Deprecated in 3.0 (savegame3.c) Still saved up to 3.1. */
112 struct {
113 enum diplstate_type *order;
114 size_t size;
115 } ds_t;
116 /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
117 struct {
118 action_id *order;
119 size_t size;
120 } action;
121 /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
122 struct {
123 enum action_decision *order;
124 size_t size;
125 } act_dec;
126 /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
127 struct {
128 enum server_side_agent *order;
129 size_t size;
130 } ssa;
131 struct {
132 enum city_options *order;
133 size_t size;
134 } coptions;
135
136 /* loaded in sg_load_game(); needed in sg_load_random(), ... */
137 enum server_states server_state;
138
139 /* loaded in sg_load_random(); needed in sg_load_sanitycheck() */
140 RANDOM_STATE rstate;
141
142 /* loaded in sg_load_map_worked(); needed in sg_load_player_cities() */
143 int *worked_tiles;
144};
145
146#define log_sg log_error
147/* Fixing known problems from older savegame formats */
148#define log_sgfix log_normal
149
150#define sg_check_ret(...) \
151 if (!sg_success) { \
152 return; \
153 }
154
155#define sg_check_ret_val(_val) \
156 if (!sg_success) { \
157 return _val; \
158 }
159
160#define sg_warn(condition, message, ...) \
161 if (!(condition)) { \
162 log_sg(message, ## __VA_ARGS__); \
163 }
164
165#define sg_warn_ret(condition, message, ...) \
166 if (!(condition)) { \
167 log_sg(message, ## __VA_ARGS__); \
168 return; \
169 }
170
171#define sg_warn_ret_val(condition, _val, message, ...) \
172 if (!(condition)) { \
173 log_sg(message, ## __VA_ARGS__); \
174 return _val; \
175 }
176
177#define sg_failure_ret(condition, message, ...) \
178 if (!(condition)) { \
179 log_sg(message, ## __VA_ARGS__); \
180 sg_success = FALSE; \
181 sg_check_ret(); \
182 }
183
184#define sg_failure_ret_val(condition, _val, message, ...) \
185 if (!(condition)) { \
186 log_sg(message, ## __VA_ARGS__); \
187 sg_success = FALSE; \
188 sg_check_ret_val(_val); \
189 }
190
191/* Resist urge to write version numbers with leading zero; "030?0?00",
192 * as that makes compiler to consider them octal. */
193#define sg_regr(fixversion, message, ...) \
194 if (loading->full_version >= fixversion) { \
195 log_sg(message, ## __VA_ARGS__); \
196 } else { \
197 log_sgfix(message, ## __VA_ARGS__); \
198 }
199
200void sg_load_compat(struct loaddata *loading, enum sgf_version format_class);
201void sg_load_post_load_compat(struct loaddata *loading,
202 enum sgf_version format_class);
203int current_compat_ver(void);
204
205#define hex_chars "0123456789abcdef"
206
207char bin2ascii_hex(int value, int halfbyte_wanted);
208int ascii_hex2bin(char ch, int halfbyte);
209
210int char2num(char ch);
211
212enum tile_special_type special_by_rule_name(const char *name);
213const char *special_rule_name(enum tile_special_type type);
214struct extra_type *special_extra_get(int spe);
215
216struct extra_type *resource_by_identifier(const char identifier);
217
218enum ai_level ai_level_convert(int old_level);
219enum barbarian_type barb_type_convert(int old_type);
220
221/* Old savegames might have padding up to this amount of trade routes */
222#define MAX_TRADE_ROUTES_OLD 5
223
224#endif /* FC__SAVECOMPAT_H */
incite_cost
char * incite_cost
Definition comments.c:74
action_id
int action_id
Definition fc_types.h:393
type
GType type
Definition repodlgs.c:1313
name
const char * name
Definition inputfile.c:127
rand.h
resource_by_identifier
struct extra_type * resource_by_identifier(const char identifier)
Definition savecompat.c:327
current_compat_ver
int current_compat_ver(void)
Definition savecompat.c:226
tile_special_type
tile_special_type
Definition savecompat.h:29
S_MINE
@ S_MINE
Definition savecompat.h:31
S_OLD_FORTRESS
@ S_OLD_FORTRESS
Definition savecompat.h:40
S_OLD_AIRBASE
@ S_OLD_AIRBASE
Definition savecompat.h:41
S_HUT
@ S_HUT
Definition savecompat.h:33
S_FALLOUT
@ S_FALLOUT
Definition savecompat.h:35
S_POLLUTION
@ S_POLLUTION
Definition savecompat.h:32
S_OLD_RIVER
@ S_OLD_RIVER
Definition savecompat.h:44
S_FARMLAND
@ S_FARMLAND
Definition savecompat.h:34
S_OLD_ROAD
@ S_OLD_ROAD
Definition savecompat.h:42
S_LAST
@ S_LAST
Definition savecompat.h:38
S_IRRIGATION
@ S_IRRIGATION
Definition savecompat.h:30
S_OLD_RAILROAD
@ S_OLD_RAILROAD
Definition savecompat.h:43
barb_type_convert
enum barbarian_type barb_type_convert(int old_type)
Definition savecompat.c:3484
bin2ascii_hex
char bin2ascii_hex(int value, int halfbyte_wanted)
Definition savecompat.c:236
char2num
int char2num(char ch)
Definition savecompat.c:272
sg_load_compat
void sg_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:147
sgf_version
sgf_version
Definition savecompat.h:27
SAVEGAME_2
@ SAVEGAME_2
Definition savecompat.h:27
SAVEGAME_3
@ SAVEGAME_3
Definition savecompat.h:27
ai_level_convert
enum ai_level ai_level_convert(int old_level)
Definition savecompat.c:3455
ascii_hex2bin
int ascii_hex2bin(char ch, int halfbyte)
Definition savecompat.c:248
special_extra_get
struct extra_type * special_extra_get(int spe)
Definition savecompat.c:313
special_by_rule_name
enum tile_special_type special_by_rule_name(const char *name)
Definition savecompat.c:287
sg_load_post_load_compat
void sg_load_post_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:198
special_rule_name
const char * special_rule_name(enum tile_special_type type)
Definition savecompat.c:303
size
size_t size
Definition specvec.h:72
srv_main.h
RANDOM_STATE
Definition rand.h:50
base_type
Definition base.h:41
extra_type
Definition extras.h:88
loaddata
Definition savecompat.h:47
loaddata::secfile_options
const char * secfile_options
Definition savecompat.h:49
loaddata::version
int version
Definition savecompat.h:50
loaddata::order
struct specialist ** order
Definition savecompat.h:107
loaddata::order
enum tile_special_type * order
Definition savecompat.h:90
loaddata::act_dec
struct loaddata::@111 act_dec
loaddata::rstate
RANDOM_STATE rstate
Definition savecompat.h:140
loaddata::road
struct loaddata::@107 road
loaddata::base
struct loaddata::@106 base
loaddata::counter
struct loaddata::@98 counter
loaddata::multiplier
struct loaddata::@104 multiplier
loaddata::order
struct road_type ** order
Definition savecompat.h:102
loaddata::coptions
struct loaddata::@113 coptions
loaddata::full_version
int full_version
Definition savecompat.h:51
loaddata::order
enum city_options * order
Definition savecompat.h:132
loaddata::size
size_t size
Definition savecompat.h:55
loaddata::order
enum action_decision * order
Definition savecompat.h:123
loaddata::ds_t
struct loaddata::@109 ds_t
loaddata::order
struct base_type ** order
Definition savecompat.h:96
loaddata::action
struct loaddata::@110 action
loaddata::ssa
struct loaddata::@112 ssa
loaddata::order
struct extra_type ** order
Definition savecompat.h:79
loaddata::special
struct loaddata::@105 special
loaddata::order
struct multiplier ** order
Definition savecompat.h:84
loaddata::server_state
enum server_states server_state
Definition savecompat.h:137
loaddata::technology
struct loaddata::@100 technology
loaddata::specialist
struct loaddata::@108 specialist
loaddata::order
const char ** order
Definition savecompat.h:54
loaddata::activities
struct loaddata::@101 activities
loaddata::trait
struct loaddata::@102 trait
loaddata::improvement
struct loaddata::@99 improvement
loaddata::worked_tiles
int * worked_tiles
Definition savecompat.h:143
loaddata::order
action_id * order
Definition savecompat.h:118
loaddata::extra
struct loaddata::@103 extra
loaddata::order
enum diplstate_type * order
Definition savecompat.h:113
loaddata::file
struct section_file * file
Definition savecompat.h:48
loaddata::order
enum server_side_agent * order
Definition savecompat.h:128
multiplier
Definition multipliers.h:31
road_type
Definition road.h:71
section_file
Definition section_file.h:36
specialist
Definition specialist.h:29