Freeciv-3.1: /fast/freeciv/nightly/S3_1/server/savegame/savecompat.h Source File

Freeciv-3.1

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 /* loaded in sg_load_savefile(); needed in sg_load_player() */
54 struct {
55 const char **order;
56 size_t size;
57 } improvement;
58 /* loaded in sg_load_savefile(); needed in sg_load_player() */
59 struct {
60 const char **order;
61 size_t size;
62 } technology;
63 /* loaded in sg_load_savefile(); needed in sg_load_player() */
64 struct {
65 const char **order;
66 size_t size;
67 } activities;
68 /* loaded in sg_load_savefile(); needed in sg_load_player() */
69 struct {
70 const char **order;
71 size_t size;
72 } trait;
73 /* loaded in sg_load_savefile(); needed in sg_load_map(), ... */
74 struct {
75 struct extra_type **order;
76 size_t size;
77 } extra;
78 /* loaded in sg_load_savefile(); needed in sg_load_players_basic() */
79 struct {
80 struct multiplier **order;
81 size_t size;
82 } multiplier;
83 /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
84 * Deprecated in 3.0 (savegame3.c) */
85 struct {
86 enum tile_special_type *order;
87 size_t size;
88 } special;
89 /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
90 * Deprecated in 3.0 (savegame3.c) */
91 struct {
92 struct base_type **order;
93 size_t size;
94 } base;
95 /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
96 * Deprecated in 3.0 (savegame3.c) */
97 struct {
98 struct road_type **order;
99 size_t size;
100 } road;
101 /* loaded in sg_load_savefile(); needed in sg_load_(), ... */
102 struct {
103 struct specialist **order;
104 size_t size;
105 } specialist;
106 /* loaded in sg_load_savefile(); needed in sg_load_player_main(), ... */
107 struct {
108 enum diplstate_type *order;
109 size_t size;
110 } ds_t;
111 /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
112 struct {
113 action_id *order;
114 size_t size;
115 } action;
116 /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
117 struct {
118 enum action_decision *order;
119 size_t size;
120 } act_dec;
121 /* loaded in sg_load_savefile(); needed in sg_load_player_unit(), ... */
122 struct {
123 enum server_side_agent *order;
124 size_t size;
125 } ssa;
126
127 /* loaded in sg_load_game(); needed in sg_load_random(), ... */
128 enum server_states server_state;
129
130 /* loaded in sg_load_random(); needed in sg_load_sanitycheck() */
131 RANDOM_STATE rstate;
132
133 /* loaded in sg_load_map_worked(); needed in sg_load_player_cities() */
134 int *worked_tiles;
135};
136
137#define log_sg log_error
138/* Fixing known problems from older savegame formats */
139#define log_sgfix log_normal
140
141#define sg_check_ret(...) \
142 if (!sg_success) { \
143 return; \
144 }
145
146#define sg_check_ret_val(_val) \
147 if (!sg_success) { \
148 return _val; \
149 }
150
151#define sg_warn(condition, message, ...) \
152 if (!(condition)) { \
153 log_sg(message, ## __VA_ARGS__); \
154 }
155
156#define sg_warn_ret(condition, message, ...) \
157 if (!(condition)) { \
158 log_sg(message, ## __VA_ARGS__); \
159 return; \
160 }
161
162#define sg_warn_ret_val(condition, _val, message, ...) \
163 if (!(condition)) { \
164 log_sg(message, ## __VA_ARGS__); \
165 return _val; \
166 }
167
168#define sg_failure_ret(condition, message, ...) \
169 if (!(condition)) { \
170 log_sg(message, ## __VA_ARGS__); \
171 sg_success = FALSE; \
172 sg_check_ret(); \
173 }
174
175#define sg_failure_ret_val(condition, _val, message, ...) \
176 if (!(condition)) { \
177 log_sg(message, ## __VA_ARGS__); \
178 sg_success = FALSE; \
179 sg_check_ret_val(_val); \
180 }
181
182/* Resist urge to write version numbers with leading zero; "030?0?00",
183 * as that makes compiler to consider them octal. */
184#define sg_regr(fixversion, message, ...) \
185 if (loading->full_version >= fixversion) { \
186 log_sg(message, ## __VA_ARGS__); \
187 } else { \
188 log_sgfix(message, ## __VA_ARGS__); \
189 }
190
191void sg_load_compat(struct loaddata *loading, enum sgf_version format_class);
192void sg_load_post_load_compat(struct loaddata *loading,
193 enum sgf_version format_class);
194int current_compat_ver(void);
195
196#define hex_chars "0123456789abcdef"
197
198char bin2ascii_hex(int value, int halfbyte_wanted);
199int ascii_hex2bin(char ch, int halfbyte);
200
201int char2num(char ch);
202
203enum tile_special_type special_by_rule_name(const char *name);
204const char *special_rule_name(enum tile_special_type type);
205struct extra_type *special_extra_get(int spe);
206
207struct extra_type *resource_by_identifier(const char identifier);
208
209enum ai_level ai_level_convert(int old_level);
210enum barbarian_type barb_type_convert(int old_type);
211
212void set_unit_activity_base(struct unit *punit, Base_type_id base);
213void set_unit_activity_road(struct unit *punit, Road_type_id road);
214
215#endif /* FC__SAVECOMPAT_H */
road
static void road(QVariant data1, QVariant data2)
Definition dialogs.cpp:2818
base
static void base(QVariant data1, QVariant data2)
Definition dialogs.cpp:2839
punit
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
Road_type_id
int Road_type_id
Definition fc_types.h:354
action_id
int action_id
Definition fc_types.h:359
Base_type_id
int Base_type_id
Definition fc_types.h:353
type
GType type
Definition repodlgs.c:1312
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:300
current_compat_ver
int current_compat_ver(void)
Definition savecompat.c:199
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:1912
set_unit_activity_road
void set_unit_activity_road(struct unit *punit, Road_type_id road)
Definition savecompat.c:1939
bin2ascii_hex
char bin2ascii_hex(int value, int halfbyte_wanted)
Definition savecompat.c:209
char2num
int char2num(char ch)
Definition savecompat.c:245
sg_load_compat
void sg_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:132
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:1883
set_unit_activity_base
void set_unit_activity_base(struct unit *punit, Base_type_id base)
Definition savecompat.c:1929
ascii_hex2bin
int ascii_hex2bin(char ch, int halfbyte)
Definition savecompat.c:221
special_extra_get
struct extra_type * special_extra_get(int spe)
Definition savecompat.c:286
special_by_rule_name
enum tile_special_type special_by_rule_name(const char *name)
Definition savecompat.c:260
sg_load_post_load_compat
void sg_load_post_load_compat(struct loaddata *loading, enum sgf_version format_class)
Definition savecompat.c:177
special_rule_name
const char * special_rule_name(enum tile_special_type type)
Definition savecompat.c:276
size
size_t size
Definition specvec.h:72
srv_main.h
RANDOM_STATE
Definition rand.h:28
base_type
Definition base.h:41
extra_type
Definition extras.h:85
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:103
loaddata::order
enum tile_special_type * order
Definition savecompat.h:86
loaddata::act_dec
struct loaddata::@111 act_dec
loaddata::rstate
RANDOM_STATE rstate
Definition savecompat.h:131
loaddata::road
struct loaddata::@107 road
loaddata::base
struct loaddata::@106 base
loaddata::multiplier
struct loaddata::@104 multiplier
loaddata::order
struct road_type ** order
Definition savecompat.h:98
loaddata::full_version
int full_version
Definition savecompat.h:51
loaddata::size
size_t size
Definition savecompat.h:56
loaddata::order
enum action_decision * order
Definition savecompat.h:118
loaddata::ds_t
struct loaddata::@109 ds_t
loaddata::order
struct base_type ** order
Definition savecompat.h:92
loaddata::action
struct loaddata::@110 action
loaddata::ssa
struct loaddata::@112 ssa
loaddata::order
struct extra_type ** order
Definition savecompat.h:75
loaddata::special
struct loaddata::@105 special
loaddata::order
struct multiplier ** order
Definition savecompat.h:80
loaddata::server_state
enum server_states server_state
Definition savecompat.h:128
loaddata::technology
struct loaddata::@100 technology
loaddata::specialist
struct loaddata::@108 specialist
loaddata::order
const char ** order
Definition savecompat.h:55
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:134
loaddata::order
action_id * order
Definition savecompat.h:113
loaddata::extra
struct loaddata::@103 extra
loaddata::order
enum diplstate_type * order
Definition savecompat.h:108
loaddata::file
struct section_file * file
Definition savecompat.h:48
loaddata::order
enum server_side_agent * order
Definition savecompat.h:123
multiplier
Definition multipliers.h:31
road_type
Definition road.h:75
section_file
Definition section_file.h:36
specialist
Definition specialist.h:29
unit
Definition unit.h:138