Freeciv21
Develop your civilization from humble roots to a global empire
savecompat.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2021 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 // utility
16 #include "rand.h"
17 
18 // server
19 #include "srv_main.h"
20 
21 struct section_file;
22 struct extra_type;
23 struct base_type;
24 struct road_type;
25 
27 
35 
36  // internal values not saved
41 };
42 
43 struct loaddata {
44  struct section_file *file;
45  const char *secfile_options;
46  int version;
47 
48  // loaded in sg_load_savefile(); needed in sg_load_player()
49  struct {
50  const char **order;
51  size_t size;
53  // loaded in sg_load_savefile(); needed in sg_load_player()
54  struct {
55  const char **order;
56  size_t size;
58  // loaded in sg_load_savefile(); needed in sg_load_player()
59  struct {
60  const char **order;
61  size_t size;
63  // loaded in sg_load_savefile(); needed in sg_load_player()
64  struct {
65  const char **order;
66  size_t size;
67  } trait;
68  // loaded in sg_load_savefile(); needed in sg_load_map(), ...
69  struct {
70  struct extra_type **order;
71  size_t size;
72  } extra;
73  // loaded in sg_load_savefile(); needed in sg_load_players_basic()
74  struct {
75  struct multiplier **order;
76  size_t size;
78  /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
79  * Deprecated in 3.0 (savegame3.c) */
80  struct {
82  size_t size;
84  /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
85  * Deprecated in 3.0 (savegame3.c) */
86  struct {
87  struct base_type **order;
88  size_t size;
89  } base;
90  /* loaded in sg_load_savefile(); needed in sg_load_map(), ...
91  * Deprecated in 3.0 (savegame3.c) */
92  struct {
93  struct road_type **order;
94  size_t size;
95  } road;
96  // loaded in sg_load_savefile(); needed in sg_load_(), ...
97  struct {
98  struct specialist **order;
99  size_t size;
101  // loaded in sg_load_savefile(); needed in sg_load_player_main(), ...
102  struct {
103  enum diplstate_type *order;
104  size_t size;
105  } ds_t;
106  // loaded in sg_load_savefile(); needed in sg_load_player_unit(), ...
107  struct {
109  size_t size;
111  // loaded in sg_load_savefile(); needed in sg_load_player_unit(), ...
112  struct {
113  enum action_decision *order;
114  size_t size;
116  // loaded in sg_load_savefile(); needed in sg_load_player_unit(), ...
117  struct {
118  enum server_side_agent *order;
119  size_t size;
120  } ssa;
121 
122  // loaded in sg_load_game(); needed in sg_load_random(), ...
123  enum server_states server_state;
124 
125  // loaded in sg_load_random(); needed in sg_load_sanitycheck()
126  std::mt19937 rstate;
127 
128  // loaded in sg_load_map_worked(); needed in sg_load_player_cities()
130 };
131 
132 #define log_sg qCritical
133 
134 #define sg_check_ret(...) \
135  if (!sg_success) { \
136  return; \
137  }
138 #define sg_check_ret_val(_val) \
139  if (!sg_success) { \
140  return _val; \
141  }
142 
143 #define sg_warn(condition, message, ...) \
144  if (!(condition)) { \
145  log_sg(message, ##__VA_ARGS__); \
146  }
147 #define sg_warn_ret(condition, message, ...) \
148  if (!(condition)) { \
149  log_sg(message, ##__VA_ARGS__); \
150  return; \
151  }
152 #define sg_warn_ret_val(condition, _val, message, ...) \
153  if (!(condition)) { \
154  log_sg(message, ##__VA_ARGS__); \
155  return _val; \
156  }
157 
158 #define sg_failure_ret(condition, message, ...) \
159  if (!(condition)) { \
160  sg_success = false; \
161  log_sg(message, ##__VA_ARGS__); \
162  sg_check_ret(); \
163  }
164 #define sg_failure_ret_val(condition, _val, message, ...) \
165  if (!(condition)) { \
166  sg_success = false; \
167  log_sg(message, ##__VA_ARGS__); \
168  sg_check_ret_val(_val); \
169  }
170 
171 void sg_load_compat(struct loaddata *loading, enum sgf_version format_class);
172 void sg_load_post_load_compat(struct loaddata *loading,
173  enum sgf_version format_class);
174 int current_compat_ver();
175 
176 #define hex_chars "0123456789abcdef"
177 
178 char bin2ascii_hex(int value, int halfbyte_wanted);
179 int ascii_hex2bin(char ch, int halfbyte);
180 
181 int char2num(char ch);
182 
184 const char *special_rule_name(enum tile_special_type type);
185 struct extra_type *special_extra_get(int spe);
186 
187 struct extra_type *resource_by_identifier(const char identifier);
188 
189 enum ai_level ai_level_convert(int old_level);
190 enum barbarian_type barb_type_convert(int old_type);
191 
192 void set_unit_activity_base(struct unit *punit, Base_type_id base);
193 void set_unit_activity_road(struct unit *punit, Road_type_id road);
194 
195 #define ORDER_OLD_BUILD_CITY (-1)
196 #define ORDER_OLD_DISBAND (-2)
197 #define ORDER_OLD_BUILD_WONDER (-3)
198 #define ORDER_OLD_TRADE_ROUTE (-4)
199 #define ORDER_OLD_HOMECITY (-5)
200 int sg_order_to_action(int order, struct unit *act_unit,
201  struct tile *tgt_tile);
static void road(QVariant data1, QVariant data2)
Action "Build Road" for choice dialog.
Definition: dialogs.cpp:2374
static void base(QVariant data1, QVariant data2)
Action "Build Base" for choice dialog.
Definition: dialogs.cpp:2393
int Road_type_id
Definition: fc_types.h:301
int action_id
Definition: fc_types.h:306
int Base_type_id
Definition: fc_types.h:300
const char * name
Definition: inputfile.cpp:118
struct extra_type * resource_by_identifier(const char identifier)
Return the resource type matching the identifier, or nullptr when none matches.
Definition: savecompat.cpp:321
int sg_order_to_action(int order, struct unit *act_unit, struct tile *tgt_tile)
Returns the action id corresponding to the specified order id.
const char * special_rule_name(enum tile_special_type type)
Return the untranslated name of the given special.
Definition: savecompat.cpp:295
tile_special_type
Definition: savecompat.h:28
@ S_MINE
Definition: savecompat.h:30
@ S_HUT
Definition: savecompat.h:32
@ S_FALLOUT
Definition: savecompat.h:34
@ S_POLLUTION
Definition: savecompat.h:31
@ S_OLD_RIVER
Definition: savecompat.h:40
@ S_FARMLAND
Definition: savecompat.h:33
@ S_OLD_ROAD
Definition: savecompat.h:38
@ S_LAST
Definition: savecompat.h:37
@ S_IRRIGATION
Definition: savecompat.h:29
@ S_OLD_RAILROAD
Definition: savecompat.h:39
enum barbarian_type barb_type_convert(int old_type)
Convert old barbarian type value to barbarian_type.
void set_unit_activity_road(struct unit *punit, Road_type_id road)
Assign a new road building task to unit.
struct extra_type * special_extra_get(int spe)
Get extra of the given special.
Definition: savecompat.cpp:305
char bin2ascii_hex(int value, int halfbyte_wanted)
This returns an ascii hex value of the given half-byte of the binary integer.
Definition: savecompat.cpp:227
int char2num(char ch)
Converts single character into numerical value.
Definition: savecompat.cpp:264
void sg_load_compat(struct loaddata *loading, enum sgf_version format_class)
Compatibility functions for loaded game.
Definition: savecompat.cpp:140
sgf_version
Definition: savecompat.h:26
@ SAVEGAME_2
Definition: savecompat.h:26
@ SAVEGAME_3
Definition: savecompat.h:26
enum ai_level ai_level_convert(int old_level)
Translate savegame secfile data from earlier development version format to current one.
void set_unit_activity_base(struct unit *punit, Base_type_id base)
Assign a new base building task to unit.
int ascii_hex2bin(char ch, int halfbyte)
This returns a binary integer value of the ascii hex char, offset by the given number of half-bytes.
Definition: savecompat.cpp:239
enum tile_special_type special_by_rule_name(const char *name)
Return the special with the given name, or S_LAST.
Definition: savecompat.cpp:279
void sg_load_post_load_compat(struct loaddata *loading, enum sgf_version format_class)
Compatibility functions for loaded game that needs game state.
Definition: savecompat.cpp:191
int current_compat_ver()
Return current compatibility version.
Definition: savecompat.cpp:220
Definition: base.h:43
struct loaddata::@96 trait
const char * secfile_options
Definition: savecompat.h:45
int version
Definition: savecompat.h:46
struct specialist ** order
Definition: savecompat.h:98
struct loaddata::@98 multiplier
struct loaddata::@97 extra
enum tile_special_type * order
Definition: savecompat.h:81
struct road_type ** order
Definition: savecompat.h:93
size_t size
Definition: savecompat.h:51
enum action_decision * order
Definition: savecompat.h:113
struct loaddata::@105 act_dec
struct loaddata::@103 ds_t
struct base_type ** order
Definition: savecompat.h:87
struct extra_type ** order
Definition: savecompat.h:70
struct loaddata::@93 improvement
struct loaddata::@106 ssa
struct multiplier ** order
Definition: savecompat.h:75
enum server_states server_state
Definition: savecompat.h:123
struct loaddata::@94 technology
struct loaddata::@104 action
const char ** order
Definition: savecompat.h:50
std::mt19937 rstate
Definition: savecompat.h:126
struct loaddata::@101 road
struct loaddata::@99 special
struct loaddata::@100 base
struct loaddata::@95 activities
int * worked_tiles
Definition: savecompat.h:129
action_id * order
Definition: savecompat.h:108
struct loaddata::@102 specialist
enum diplstate_type * order
Definition: savecompat.h:103
struct section_file * file
Definition: savecompat.h:44
enum server_side_agent * order
Definition: savecompat.h:118
Definition: road.h:54
Definition: tile.h:42
Definition: unit.h:134