OpenTTD Source 20241224-master-gee860a5c8e
strings_sl.cpp File Reference

Code handling saving and loading of strings. More...

#include "../stdafx.h"
#include "../core/alloc_func.hpp"
#include "../string_func.h"
#include "../strings_func.h"
#include "saveload_internal.h"
#include <sstream>
#include "table/strings.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  NAMEChunkHandler
 

Functions

StringID RemapOldStringID (StringID s)
 Remap a string ID from the old format to the new format.
 
std::string CopyFromOldName (StringID id)
 Copy and convert old custom names to UTF-8.
 
void ResetOldNames ()
 Free the memory of the old names array.
 
void InitializeOldNames ()
 Initialize the old names table memory.
 
const ChunkHandlerTable _name_chunk_handlers (name_chunk_handlers)
 

Variables

static const int NUM_OLD_STRINGS = 512
 The number of custom strings stored in old savegames.
 
static const int LEN_OLD_STRINGS = 32
 The number of characters per string.
 
static const int LEN_OLD_STRINGS_TTO = 24
 The number of characters per string in TTO savegames.
 
char * _old_name_array = nullptr
 Location to load the old names to.
 
static const NAMEChunkHandler NAME
 
static const ChunkHandlerRef name_chunk_handlers []
 

Detailed Description

Code handling saving and loading of strings.

Definition in file strings_sl.cpp.

Function Documentation

◆ CopyFromOldName()

std::string CopyFromOldName ( StringID  id)

Copy and convert old custom names to UTF-8.

They were all stored in a 512 by 32 (200 by 24 for TTO) long string array and are now stored with stations, waypoints and other places with names.

Parameters
idthe StringID of the custom name to clone.
Returns
the clones custom name.

Definition at line 61 of file strings_sl.cpp.

References _old_name_array, _savegame_type, GB(), GetStringTab(), IsSavegameVersionBefore(), LEN_OLD_STRINGS, LEN_OLD_STRINGS_TTO, SGT_TTO, SLV_37, and Utf8Encode().

Referenced by AfterLoadGame(), CHKPChunkHandler::FixPointers(), ENGSChunkHandler::Load(), and WriteValue().

◆ InitializeOldNames()

void InitializeOldNames ( )

Initialize the old names table memory.

Definition at line 111 of file strings_sl.cpp.

References _old_name_array, free(), LEN_OLD_STRINGS, and NUM_OLD_STRINGS.

◆ RemapOldStringID()

StringID RemapOldStringID ( StringID  s)

Remap a string ID from the old format to the new format.

Parameters
sStringID that requires remapping
Returns
translated ID

Definition at line 30 of file strings_sl.cpp.

References IsInsideMM().

Referenced by SlSaveLoadConv().

◆ ResetOldNames()

void ResetOldNames ( )

Free the memory of the old names array.

Should be called once the old names have all been converted.

Definition at line 102 of file strings_sl.cpp.

References _old_name_array, and free().

Referenced by AfterLoadGame().

Variable Documentation

◆ _old_name_array

char* _old_name_array = nullptr

Location to load the old names to.

Definition at line 52 of file strings_sl.cpp.

Referenced by CopyFromOldName(), InitializeOldNames(), NAMEChunkHandler::Load(), and ResetOldNames().

◆ LEN_OLD_STRINGS

const int LEN_OLD_STRINGS = 32
static

The number of characters per string.

Definition at line 22 of file strings_sl.cpp.

Referenced by CopyFromOldName(), InitializeOldNames(), and NAMEChunkHandler::Load().

◆ LEN_OLD_STRINGS_TTO

const int LEN_OLD_STRINGS_TTO = 24
static

The number of characters per string in TTO savegames.

Definition at line 23 of file strings_sl.cpp.

Referenced by CopyFromOldName().

◆ NAME

const NAMEChunkHandler NAME
static

Definition at line 135 of file strings_sl.cpp.

◆ name_chunk_handlers

const ChunkHandlerRef name_chunk_handlers[]
static
Initial value:
= {
NAME,
}

Definition at line 136 of file strings_sl.cpp.

◆ NUM_OLD_STRINGS

const int NUM_OLD_STRINGS = 512
static

The number of custom strings stored in old savegames.

Definition at line 21 of file strings_sl.cpp.

Referenced by InitializeOldNames(), and NAMEChunkHandler::Load().