Changeset - r24803:d9506734523b
[Not reviewed]
master
0 3 0
frosch - 4 years ago 2021-01-12 21:11:12
frosch@openttd.org
Codechange: turn a constant variable into a real constant.
3 files changed with 15 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -14,12 +14,13 @@
 
#include "textbuf_gui.h"
 
#include "command_func.h"
 
#include "network/network.h"
 
#include "town.h"
 
#include "settings_internal.h"
 
#include "newgrf_townname.h"
 
#include "townname_type.h"
 
#include "strings_func.h"
 
#include "window_func.h"
 
#include "string_func.h"
 
#include "widgets/dropdown_type.h"
 
#include "widgets/dropdown_func.h"
 
#include "highscore.h"
 
@@ -70,13 +71,12 @@ static const StringID _font_zoom_dropdow
 
	STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL,
 
	STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM,
 
	STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM,
 
	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 int _nb_grf_names = 0;       ///< Number of town names defined by NewGRFs.
 

	
 
static Dimension _circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
 

	
 
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd);
 
@@ -94,14 +94,14 @@ void InitGRFTownGeneratorNames()
 
 * Get a town name.
 
 * @param town_name Number of the wanted town name.
 
 * @return Name of the town as string ID.
 
 */
 
static inline StringID TownName(int town_name)
 
{
 
	if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
 
	town_name -= _nb_orig_names;
 
	if (town_name < BUILTIN_TOWNNAME_GENERATOR_COUNT) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
 
	town_name -= BUILTIN_TOWNNAME_GENERATOR_COUNT;
 
	if (town_name < _nb_grf_names) return _grf_names[town_name];
 
	return STR_UNDEFINED;
 
}
 

	
 
/**
 
 * Get index of the current screen resolution.
 
@@ -242,26 +242,26 @@ struct GameOptionsWindow : Window {
 
				*selected_index = this->opt->game_creation.town_name;
 

	
 
				int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
 

	
 
				/* Add and sort newgrf townnames generators */
 
				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));
 
				}
 
				std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
 

	
 
				size_t newgrf_size = list.size();
 
				/* Insert newgrf_names at the top of the list */
 
				if (newgrf_size > 0) {
 
					list.emplace_back(new DropDownListItem(-1, false)); // separator line
 
					newgrf_size++;
 
				}
 

	
 
				/* 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));
 
				}
 
				std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
 
				break;
 
			}
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -1838,21 +1838,16 @@ static void DoCreateTown(Town *t, TileIn
 

	
 
	t->have_ratings = 0;
 
	t->exclusivity = INVALID_COMPANY;
 
	t->exclusive_counter = 0;
 
	t->statues = 0;
 

	
 
	extern int _nb_orig_names;
 
	if (_settings_game.game_creation.town_name < _nb_orig_names) {
 
		/* Original town name */
 
		t->townnamegrfid = 0;
 
		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);
 
	{
 
		TownNameParams tnp(_settings_game.game_creation.town_name);
 
		t->townnamegrfid = tnp.grfid;
 
		t->townnametype = tnp.type;
 
	}
 
	t->townnameparts = townnameparts;
 

	
 
	t->UpdateVirtCoord();
 
	InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD);
 

	
src/townname_type.h
Show inline comments
 
@@ -12,17 +12,20 @@
 

	
 
#ifndef TOWNNAME_TYPE_H
 
#define TOWNNAME_TYPE_H
 

	
 
#include "newgrf_townname.h"
 
#include "town_type.h"
 
#include "string_type.h"
 
#include <set>
 
#include <string>
 

	
 
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.
 
 * Speeds things up a bit because these values are computed only once per name generation.
 
 */
 
struct TownNameParams {
 
	uint32 grfid; ///< newgrf ID (0 if not used)
 
@@ -31,16 +34,15 @@ struct TownNameParams {
 
	/**
 
	 * Initializes this struct from language ID
 
	 * @param town_name town name 'language' ID
 
	 */
 
	TownNameParams(byte town_name)
 
	{
 
		extern int _nb_orig_names;
 
		bool grf = town_name >= _nb_orig_names;
 
		this->grfid = grf ? GetGRFTownNameId(town_name - _nb_orig_names) : 0;
 
		this->type = grf ? GetGRFTownNameType(town_name - _nb_orig_names) : SPECSTR_TOWNNAME_START + town_name;
 
		bool grf = town_name >= BUILTIN_TOWNNAME_GENERATOR_COUNT;
 
		this->grfid = grf ? GetGRFTownNameId(town_name - BUILTIN_TOWNNAME_GENERATOR_COUNT) : 0;
 
		this->type = grf ? GetGRFTownNameType(town_name - BUILTIN_TOWNNAME_GENERATOR_COUNT) : SPECSTR_TOWNNAME_START + town_name;
 
	}
 

	
 
	TownNameParams(const Town *t);
 
};
 

	
 
#endif /* TOWNNAME_TYPE_H */
0 comments (0 inline, 0 general)