src/strings_func.h
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10197 fa185196aef1
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     1
/* $Id$ */
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     2
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     3
/** @file strings_func.h Functions related to OTTD's strings. */
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     4
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     5
#ifndef STRINGS_FUNC_H
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     6
#define STRINGS_FUNC_H
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     7
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     8
#include "strings_type.h"
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
     9
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    10
char *InlineString(char *buf, StringID string);
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    11
char *GetString(char *buffr, StringID string, const char *last);
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8330
diff changeset
    12
const char *GetStringPtr(StringID string);
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    13
10197
fa185196aef1 (svn r14410) -Codechange: one can't inject a negative number of parameters, so enforce this by using a uint.
rubidium
parents: 9648
diff changeset
    14
void InjectDParam(uint amount);
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    15
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    16
static inline void SetDParamX(uint64 *s, uint n, uint64 v)
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    17
{
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    18
	s[n] = v;
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    19
}
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    20
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    21
static inline void SetDParam(uint n, uint64 v)
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    22
{
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    23
	extern uint64 _decode_parameters[20];
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    24
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    25
	assert(n < lengthof(_decode_parameters));
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    26
	_decode_parameters[n] = v;
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    27
}
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    28
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    29
void SetDParamStr(uint n, const char *str);
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    30
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    31
static inline uint64 GetDParamX(const uint64 *s, uint n)
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    32
{
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    33
	return s[n];
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    34
}
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    35
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    36
static inline uint64 GetDParam(uint n)
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    37
{
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    38
	extern uint64 _decode_parameters[20];
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    39
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    40
	assert(n < lengthof(_decode_parameters));
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    41
	return _decode_parameters[n];
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    42
}
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    43
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    44
static inline void CopyInDParam(int offs, const uint64 *src, int num)
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    45
{
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    46
	extern uint64 _decode_parameters[20];
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    47
	memcpy(_decode_parameters + offs, src, sizeof(uint64) * (num));
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    48
}
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    49
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    50
static inline void CopyOutDParam(uint64 *dst, int offs, int num)
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    51
{
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    52
	extern uint64 _decode_parameters[20];
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    53
	memcpy(dst, _decode_parameters + offs, sizeof(uint64) * (num));
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    54
}
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    55
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    56
extern DynamicLanguages _dynlang; // defined in strings.cpp
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    57
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    58
bool ReadLanguagePack(int index);
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    59
void InitializeLanguagePacks();
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    60
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    61
int CDECL StringIDSorter(const void *a, const void *b);
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    62
8321
96c331ee5ac3 (svn r11886) -Add: sort the strings in languages dropdown
glx
parents: 8114
diff changeset
    63
/** Key comparison function for std::map */
96c331ee5ac3 (svn r11886) -Add: sort the strings in languages dropdown
glx
parents: 8114
diff changeset
    64
struct StringIDCompare
96c331ee5ac3 (svn r11886) -Add: sort the strings in languages dropdown
glx
parents: 8114
diff changeset
    65
{
8330
55c297af752e (svn r11896) -Fix (r11886): a missing const broke compilation with MSVC
glx
parents: 8321
diff changeset
    66
	bool operator()(StringID s1, StringID s2) const { return StringIDSorter(&s1, &s2) < 0; }
8321
96c331ee5ac3 (svn r11886) -Add: sort the strings in languages dropdown
glx
parents: 8114
diff changeset
    67
};
96c331ee5ac3 (svn r11886) -Add: sort the strings in languages dropdown
glx
parents: 8114
diff changeset
    68
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    69
void CheckForMissingGlyphsInLoadedLanguagePack();
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    70
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8445
diff changeset
    71
StringID RemapOldStringID(StringID s);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8445
diff changeset
    72
char *CopyFromOldName(StringID id);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8445
diff changeset
    73
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
diff changeset
    74
#endif /* STRINGS_TYPE_H */