mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
(svn r19180) -Add/Fix: (partial) support for genders for cargos, industries, vehicles, stations, ...; partial because you can't set a gender for a custom string.
This commit is contained in:
parent
44f2ef179d
commit
2a65f9e4d0
@ -12,6 +12,7 @@
|
|||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
#include "../core/alloc_func.hpp"
|
#include "../core/alloc_func.hpp"
|
||||||
#include "../core/endian_func.hpp"
|
#include "../core/endian_func.hpp"
|
||||||
|
#include "../core/math_func.hpp"
|
||||||
#include "../string_func.h"
|
#include "../string_func.h"
|
||||||
#include "../strings_type.h"
|
#include "../strings_type.h"
|
||||||
#include "strgen.h"
|
#include "strgen.h"
|
||||||
@ -407,7 +408,10 @@ static void EmitGender(char *buf, int value)
|
|||||||
if (words[nw] == NULL) break;
|
if (words[nw] == NULL) break;
|
||||||
}
|
}
|
||||||
if (nw != _numgenders) error("Bad # of arguments for gender command");
|
if (nw != _numgenders) error("Bad # of arguments for gender command");
|
||||||
|
|
||||||
|
assert(IsInsideBS(cmd->value, SCC_CONTROL_START, UINT8_MAX));
|
||||||
PutUtf8(SCC_GENDER_LIST);
|
PutUtf8(SCC_GENDER_LIST);
|
||||||
|
PutByte(cmd->value - SCC_CONTROL_START);
|
||||||
PutByte(TranslateArgumentIdx(argidx, offset));
|
PutByte(TranslateArgumentIdx(argidx, offset));
|
||||||
EmitWordList(words, nw);
|
EmitWordList(words, nw);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ static char **_langpack_offs;
|
|||||||
static LanguagePack *_langpack;
|
static LanguagePack *_langpack;
|
||||||
static uint _langtab_num[32]; // Offset into langpack offs
|
static uint _langtab_num[32]; // Offset into langpack offs
|
||||||
static uint _langtab_start[32]; // Offset into langpack offs
|
static uint _langtab_start[32]; // Offset into langpack offs
|
||||||
|
static bool _keep_gender_data = false; ///< Should we retain the gender data in the current string?
|
||||||
|
|
||||||
|
|
||||||
/** Read an int64 from the argv array. */
|
/** Read an int64 from the argv array. */
|
||||||
@ -718,20 +719,31 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case SCC_GENDER_LIST: { // {G 0 Der Die Das}
|
case SCC_GENDER_LIST: { // {G 0 Der Die Das}
|
||||||
const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
|
/* First read the meta data from the language file. */
|
||||||
int gender = 0;
|
WChar fmt = SCC_CONTROL_START + (byte)*str++;
|
||||||
if (s != NULL) {
|
byte offset = (byte)*str++;
|
||||||
WChar c = Utf8Consume(&s);
|
|
||||||
/* Switch case is always put before genders, so remove those bits */
|
|
||||||
if (c == SCC_SWITCH_CASE) {
|
|
||||||
/* Skip to the last (i.e. default) case */
|
|
||||||
for (uint num = (byte)*s++; num != 0; num--) s += 3 + (s[1] << 8) + s[2];
|
|
||||||
|
|
||||||
c = Utf8Consume(&s);
|
/* Now we need to figure out what text to resolve, i.e.
|
||||||
}
|
* what do we need to draw? So get the actual raw string
|
||||||
/* Does this string have a gender, if so, set it */
|
* first using the control code to get said string. */
|
||||||
if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
|
char input[4 + 1];
|
||||||
}
|
char *p = input + Utf8Encode(input, fmt);
|
||||||
|
*p = '\0';
|
||||||
|
|
||||||
|
/* Now do the string formatting. */
|
||||||
|
char buf[256];
|
||||||
|
bool old_kgd = _keep_gender_data;
|
||||||
|
_keep_gender_data = true;
|
||||||
|
p = FormatString(buf, input, argv_orig + offset, 0, lastof(buf));
|
||||||
|
_keep_gender_data = old_kgd;
|
||||||
|
*p = '\0';
|
||||||
|
|
||||||
|
/* And determine the string. */
|
||||||
|
int gender = 0;
|
||||||
|
const char *s = buf;
|
||||||
|
WChar c = Utf8Consume(&s);
|
||||||
|
/* Does this string have a gender, if so, set it */
|
||||||
|
if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
|
||||||
str = ParseStringChoice(str, gender, &buff, last);
|
str = ParseStringChoice(str, gender, &buff, last);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -802,7 +814,12 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
|
|||||||
/* This sets up the gender for the string.
|
/* This sets up the gender for the string.
|
||||||
* We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. */
|
* We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. */
|
||||||
case SCC_GENDER_INDEX: // {GENDER 0}
|
case SCC_GENDER_INDEX: // {GENDER 0}
|
||||||
str++;
|
if (_keep_gender_data) {
|
||||||
|
buff += Utf8Encode(buff, SCC_GENDER_INDEX);
|
||||||
|
*buff++ = *str++;
|
||||||
|
} else {
|
||||||
|
str++;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCC_STRING: {// {STRING}
|
case SCC_STRING: {// {STRING}
|
||||||
|
Loading…
Reference in New Issue
Block a user