mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: turn a constant variable into a real constant.
This commit is contained in:
parent
d17226910d
commit
4ce941bbc2
|
@ -17,6 +17,7 @@
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
#include "settings_internal.h"
|
#include "settings_internal.h"
|
||||||
#include "newgrf_townname.h"
|
#include "newgrf_townname.h"
|
||||||
|
#include "townname_type.h"
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
#include "window_func.h"
|
#include "window_func.h"
|
||||||
#include "string_func.h"
|
#include "string_func.h"
|
||||||
|
@ -73,7 +74,6 @@ static const StringID _font_zoom_dropdown[] = {
|
||||||
INVALID_STRING_ID,
|
INVALID_STRING_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Number of original town names.
|
|
||||||
static StringID *_grf_names = nullptr; ///< Pointer to town names defined by NewGRFs.
|
static StringID *_grf_names = nullptr; ///< Pointer to town names defined by NewGRFs.
|
||||||
static int _nb_grf_names = 0; ///< Number of town names defined by NewGRFs.
|
static int _nb_grf_names = 0; ///< Number of town names defined by NewGRFs.
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ void InitGRFTownGeneratorNames()
|
||||||
*/
|
*/
|
||||||
static inline StringID TownName(int town_name)
|
static inline StringID TownName(int town_name)
|
||||||
{
|
{
|
||||||
if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
|
if (town_name < BUILTIN_TOWNNAME_GENERATOR_COUNT) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
|
||||||
town_name -= _nb_orig_names;
|
town_name -= BUILTIN_TOWNNAME_GENERATOR_COUNT;
|
||||||
if (town_name < _nb_grf_names) return _grf_names[town_name];
|
if (town_name < _nb_grf_names) return _grf_names[town_name];
|
||||||
return STR_UNDEFINED;
|
return STR_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ struct GameOptionsWindow : Window {
|
||||||
|
|
||||||
/* Add and sort newgrf townnames generators */
|
/* Add and sort newgrf townnames generators */
|
||||||
for (int i = 0; i < _nb_grf_names; i++) {
|
for (int i = 0; i < _nb_grf_names; i++) {
|
||||||
int result = _nb_orig_names + i;
|
int result = BUILTIN_TOWNNAME_GENERATOR_COUNT + i;
|
||||||
list.emplace_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
|
list.emplace_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
|
||||||
}
|
}
|
||||||
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
|
std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
|
||||||
|
@ -258,7 +258,7 @@ struct GameOptionsWindow : Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add and sort original townnames generators */
|
/* Add and sort original townnames generators */
|
||||||
for (int i = 0; i < _nb_orig_names; i++) {
|
for (int i = 0; i < BUILTIN_TOWNNAME_GENERATOR_COUNT; i++) {
|
||||||
list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
|
list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
|
||||||
}
|
}
|
||||||
std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
|
std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
|
||||||
|
|
|
@ -1841,15 +1841,10 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
|
||||||
t->exclusive_counter = 0;
|
t->exclusive_counter = 0;
|
||||||
t->statues = 0;
|
t->statues = 0;
|
||||||
|
|
||||||
extern int _nb_orig_names;
|
{
|
||||||
if (_settings_game.game_creation.town_name < _nb_orig_names) {
|
TownNameParams tnp(_settings_game.game_creation.town_name);
|
||||||
/* Original town name */
|
t->townnamegrfid = tnp.grfid;
|
||||||
t->townnamegrfid = 0;
|
t->townnametype = tnp.type;
|
||||||
t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
|
|
||||||
} else {
|
|
||||||
/* Newgrf town name */
|
|
||||||
t->townnamegrfid = GetGRFTownNameId(_settings_game.game_creation.town_name - _nb_orig_names);
|
|
||||||
t->townnametype = GetGRFTownNameType(_settings_game.game_creation.town_name - _nb_orig_names);
|
|
||||||
}
|
}
|
||||||
t->townnameparts = townnameparts;
|
t->townnameparts = townnameparts;
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,14 @@
|
||||||
|
|
||||||
#include "newgrf_townname.h"
|
#include "newgrf_townname.h"
|
||||||
#include "town_type.h"
|
#include "town_type.h"
|
||||||
|
#include "string_type.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
typedef std::set<std::string> TownNames;
|
typedef std::set<std::string> TownNames;
|
||||||
|
|
||||||
|
static constexpr uint BUILTIN_TOWNNAME_GENERATOR_COUNT = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Number of built-in town name generators.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Struct holding parameters used to generate town name.
|
* Struct holding parameters used to generate town name.
|
||||||
* Speeds things up a bit because these values are computed only once per name generation.
|
* Speeds things up a bit because these values are computed only once per name generation.
|
||||||
|
@ -34,10 +37,9 @@ struct TownNameParams {
|
||||||
*/
|
*/
|
||||||
TownNameParams(byte town_name)
|
TownNameParams(byte town_name)
|
||||||
{
|
{
|
||||||
extern int _nb_orig_names;
|
bool grf = town_name >= BUILTIN_TOWNNAME_GENERATOR_COUNT;
|
||||||
bool grf = town_name >= _nb_orig_names;
|
this->grfid = grf ? GetGRFTownNameId(town_name - BUILTIN_TOWNNAME_GENERATOR_COUNT) : 0;
|
||||||
this->grfid = grf ? GetGRFTownNameId(town_name - _nb_orig_names) : 0;
|
this->type = grf ? GetGRFTownNameType(town_name - BUILTIN_TOWNNAME_GENERATOR_COUNT) : SPECSTR_TOWNNAME_START + town_name;
|
||||||
this->type = grf ? GetGRFTownNameType(town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + town_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TownNameParams(const Town *t);
|
TownNameParams(const Town *t);
|
||||||
|
|
Loading…
Reference in New Issue