Freeciv21
Develop your civilization from humble roots to a global empire
savecompat.h File Reference
#include "rand.h"
#include "srv_main.h"
+ Include dependency graph for savecompat.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  loaddata
 

Macros

#define log_sg   qCritical
 
#define sg_check_ret(...)
 
#define sg_check_ret_val(_val)
 
#define sg_warn(condition, message, ...)
 
#define sg_warn_ret(condition, message, ...)
 
#define sg_warn_ret_val(condition, _val, message, ...)
 
#define sg_failure_ret(condition, message, ...)
 
#define sg_failure_ret_val(condition, _val, message, ...)
 
#define hex_chars   "0123456789abcdef"
 
#define ORDER_OLD_BUILD_CITY   (-1)
 
#define ORDER_OLD_DISBAND   (-2)
 
#define ORDER_OLD_BUILD_WONDER   (-3)
 
#define ORDER_OLD_TRADE_ROUTE   (-4)
 
#define ORDER_OLD_HOMECITY   (-5)
 

Enumerations

enum  sgf_version { SAVEGAME_2 , SAVEGAME_3 }
 
enum  tile_special_type {
  S_IRRIGATION , S_MINE , S_POLLUTION , S_HUT ,
  S_FARMLAND , S_FALLOUT , S_LAST , S_OLD_ROAD ,
  S_OLD_RAILROAD , S_OLD_RIVER
}
 

Functions

void sg_load_compat (struct loaddata *loading, enum sgf_version format_class)
 Compatibility functions for loaded game. More...
 
void sg_load_post_load_compat (struct loaddata *loading, enum sgf_version format_class)
 Compatibility functions for loaded game that needs game state. More...
 
int current_compat_ver ()
 Return current compatibility version. More...
 
char bin2ascii_hex (int value, int halfbyte_wanted)
 This returns an ascii hex value of the given half-byte of the binary integer. More...
 
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. More...
 
int char2num (char ch)
 Converts single character into numerical value. More...
 
enum tile_special_type special_by_rule_name (const char *name)
 Return the special with the given name, or S_LAST. More...
 
const char * special_rule_name (enum tile_special_type type)
 Return the untranslated name of the given special. More...
 
struct extra_typespecial_extra_get (int spe)
 Get extra of the given special. More...
 
struct extra_typeresource_by_identifier (const char identifier)
 Return the resource type matching the identifier, or nullptr when none matches. More...
 
enum ai_level ai_level_convert (int old_level)
 Translate savegame secfile data from earlier development version format to current one. More...
 
enum barbarian_type barb_type_convert (int old_type)
 Convert old barbarian type value to barbarian_type. More...
 
void set_unit_activity_base (struct unit *punit, Base_type_id base)
 Assign a new base building task to unit. More...
 
void set_unit_activity_road (struct unit *punit, Road_type_id road)
 Assign a new road building task to unit. More...
 
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. More...
 

Macro Definition Documentation

◆ hex_chars

#define hex_chars   "0123456789abcdef"

Definition at line 176 of file savecompat.h.

◆ log_sg

#define log_sg   qCritical

Definition at line 132 of file savecompat.h.

◆ ORDER_OLD_BUILD_CITY

#define ORDER_OLD_BUILD_CITY   (-1)

Definition at line 195 of file savecompat.h.

◆ ORDER_OLD_BUILD_WONDER

#define ORDER_OLD_BUILD_WONDER   (-3)

Definition at line 197 of file savecompat.h.

◆ ORDER_OLD_DISBAND

#define ORDER_OLD_DISBAND   (-2)

Definition at line 196 of file savecompat.h.

◆ ORDER_OLD_HOMECITY

#define ORDER_OLD_HOMECITY   (-5)

Definition at line 199 of file savecompat.h.

◆ ORDER_OLD_TRADE_ROUTE

#define ORDER_OLD_TRADE_ROUTE   (-4)

Definition at line 198 of file savecompat.h.

◆ sg_check_ret

#define sg_check_ret (   ...)
Value:
if (!sg_success) { \
return; \
}
bool sg_success
Definition: savecompat.cpp:30

Definition at line 134 of file savecompat.h.

◆ sg_check_ret_val

#define sg_check_ret_val (   _val)
Value:
if (!sg_success) { \
return _val; \
}

Definition at line 138 of file savecompat.h.

◆ sg_failure_ret

#define sg_failure_ret (   condition,
  message,
  ... 
)
Value:
if (!(condition)) { \
sg_success = false; \
log_sg(message, ##__VA_ARGS__); \
sg_check_ret(); \
}

Definition at line 158 of file savecompat.h.

◆ sg_failure_ret_val

#define sg_failure_ret_val (   condition,
  _val,
  message,
  ... 
)
Value:
if (!(condition)) { \
sg_success = false; \
log_sg(message, ##__VA_ARGS__); \
sg_check_ret_val(_val); \
}

Definition at line 164 of file savecompat.h.

◆ sg_warn

#define sg_warn (   condition,
  message,
  ... 
)
Value:
if (!(condition)) { \
log_sg(message, ##__VA_ARGS__); \
}

Definition at line 143 of file savecompat.h.

◆ sg_warn_ret

#define sg_warn_ret (   condition,
  message,
  ... 
)
Value:
if (!(condition)) { \
log_sg(message, ##__VA_ARGS__); \
return; \
}

Definition at line 147 of file savecompat.h.

◆ sg_warn_ret_val

#define sg_warn_ret_val (   condition,
  _val,
  message,
  ... 
)
Value:
if (!(condition)) { \
log_sg(message, ##__VA_ARGS__); \
return _val; \
}

Definition at line 152 of file savecompat.h.

Enumeration Type Documentation

◆ sgf_version

Enumerator
SAVEGAME_2 
SAVEGAME_3 

Definition at line 26 of file savecompat.h.

◆ tile_special_type

Enumerator
S_IRRIGATION 
S_MINE 
S_POLLUTION 
S_HUT 
S_FARMLAND 
S_FALLOUT 
S_LAST 
S_OLD_ROAD 
S_OLD_RAILROAD 
S_OLD_RIVER 

Definition at line 28 of file savecompat.h.

Function Documentation

◆ ai_level_convert()

enum ai_level ai_level_convert ( int  old_level)

Translate savegame secfile data from earlier development version format to current one.

Convert old ai level value to ai_level

Definition at line 1739 of file savecompat.cpp.

Referenced by sg_load_game(), and sg_load_player_main().

◆ ascii_hex2bin()

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.

See bin2ascii_hex(). example: ascii_hex2bin('a', 2) == 0xa00 This is only used in loading games, and it requires some error checking so it's done as a function.

Definition at line 239 of file savecompat.cpp.

Referenced by compat_load_020400(), sg_load_map_known(), and sg_load_player_vision().

◆ barb_type_convert()

enum barbarian_type barb_type_convert ( int  old_type)

Convert old barbarian type value to barbarian_type.

Definition at line 1739 of file savecompat.cpp.

Referenced by compat_load_020600().

◆ bin2ascii_hex()

char bin2ascii_hex ( int  value,
int  halfbyte_wanted 
)

This returns an ascii hex value of the given half-byte of the binary integer.

See ascii_hex2bin(). example: bin2ascii_hex(0xa00, 2) == 'a'

Definition at line 227 of file savecompat.cpp.

Referenced by compat_load_020400(), sg_save_map_known(), and sg_save_player_vision().

◆ char2num()

int char2num ( char  ch)

Converts single character into numerical value.

This is not hex conversion.

Definition at line 264 of file savecompat.cpp.

Referenced by compat_load_030100(), and sg_load_player_unit().

◆ current_compat_ver()

int current_compat_ver ( )

Return current compatibility version.

Definition at line 220 of file savecompat.cpp.

Referenced by sg_save_savefile().

◆ resource_by_identifier()

struct extra_type* resource_by_identifier ( const char  identifier)

Return the resource type matching the identifier, or nullptr when none matches.

Definition at line 321 of file savecompat.cpp.

Referenced by char2resource().

◆ set_unit_activity_base()

void set_unit_activity_base ( struct unit punit,
Base_type_id  base 
)

Assign a new base building task to unit.

Definition at line 2276 of file savecompat.cpp.

Referenced by sg_load_player_unit().

◆ set_unit_activity_road()

void set_unit_activity_road ( struct unit punit,
Road_type_id  road 
)

Assign a new road building task to unit.

Definition at line 2285 of file savecompat.cpp.

Referenced by sg_load_player_unit().

◆ sg_load_compat()

void sg_load_compat ( struct loaddata loading,
enum sgf_version  format_class 
)

Compatibility functions for loaded game.

This function is called at the beginning of loading a savegame. The data in loading->file should be change such, that the current loading functions can be executed without errors.

Definition at line 140 of file savecompat.cpp.

Referenced by savegame2_load(), and savegame3_load().

◆ sg_load_post_load_compat()

void sg_load_post_load_compat ( struct loaddata loading,
enum sgf_version  format_class 
)

Compatibility functions for loaded game that needs game state.

Some compatibility needs access to game state not available in sg_load_compat(). Do those here.

This function is called after a savegame has loaded the game state. The data should be changed in the game state since the game already is done loading. Prefer using sg_load_compat() when possible.

Definition at line 191 of file savecompat.cpp.

Referenced by savegame2_load(), and savegame3_load().

◆ sg_order_to_action()

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.

If no corresponding action is found ACTION_NONE is returned.

Relevant tile content information must be loaded before this function is called. Tile content information is relevant if it determines what action an old order result in. Example: a 2.6 ORDER_BUILD_CITY would result in Join City inside a domestic city and in Found City on a tile without a city. That makes domestic cities relevant tile content information.

Intended to be used while loading unit orders from pre Freeciv 3.0.0 save games (savegame and savegame2). Should be deleted with savegame2.

Temporarily used to provide development version internal save game compatibility for what will become Freeciv21. This use should cease before Freeciv21 3.0.0 is released.

Should never be called from savegame3 after the 3.0 development version internal save game compatibility is removed.

Definition at line 2311 of file savecompat.cpp.

Referenced by sg_load_player_unit().

◆ special_by_rule_name()

enum tile_special_type special_by_rule_name ( const char *  name)

Return the special with the given name, or S_LAST.

Definition at line 264 of file savecompat.cpp.

Referenced by sg_load_savefile().

◆ special_extra_get()

struct extra_type* special_extra_get ( int  spe)

Get extra of the given special.

Definition at line 305 of file savecompat.cpp.

Referenced by sg_load_player_unit().

◆ special_rule_name()

const char* special_rule_name ( enum tile_special_type  type)

Return the untranslated name of the given special.

Definition at line 295 of file savecompat.cpp.

Referenced by sg_special_set().