mirror of https://github.com/OpenTTD/OpenTTD
Codechange: pass the randomizer directly to the town name generation
parent
b3b8c3fd2d
commit
3373128233
|
@ -301,7 +301,7 @@
|
|||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
}
|
||||
uint32 townnameparts;
|
||||
if (!GenerateTownName(&townnameparts)) {
|
||||
if (!GenerateTownName(_interactive_random, &townnameparts)) {
|
||||
ScriptObject::SetLastError(ScriptError::ERR_NAME_IS_NOT_UNIQUE);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2245,7 +2245,7 @@ bool GenerateTowns(TownLayout layout)
|
|||
bool city = (_settings_game.economy.larger_towns != 0 && Chance16(1, _settings_game.economy.larger_towns));
|
||||
IncreaseGeneratingWorldProgress(GWP_TOWN);
|
||||
/* Get a unique name for the town. */
|
||||
if (!GenerateTownName(&townnameparts, &town_names)) continue;
|
||||
if (!GenerateTownName(_random, &townnameparts, &town_names)) continue;
|
||||
/* try 20 times to create a random-sized town for the first loop. */
|
||||
if (CreateRandomTown(20, townnameparts, TSZ_RANDOM, city, layout) != nullptr) current_number++; // If creation was successful, raise a flag.
|
||||
} while (--total);
|
||||
|
@ -2259,7 +2259,7 @@ bool GenerateTowns(TownLayout layout)
|
|||
|
||||
/* If current_number is still zero at this point, it means that not a single town has been created.
|
||||
* So give it a last try, but now more aggressive */
|
||||
if (GenerateTownName(&townnameparts) &&
|
||||
if (GenerateTownName(_random, &townnameparts) &&
|
||||
CreateRandomTown(10000, townnameparts, TSZ_RANDOM, _settings_game.economy.larger_towns != 0, layout) != nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1146,7 +1146,7 @@ public:
|
|||
|
||||
void RandomTownName()
|
||||
{
|
||||
this->townnamevalid = GenerateTownName(&this->townnameparts);
|
||||
this->townnamevalid = GenerateTownName(_interactive_random, &this->townnameparts);
|
||||
|
||||
if (!this->townnamevalid) {
|
||||
this->townname_editbox.text.DeleteAll();
|
||||
|
|
|
@ -112,11 +112,12 @@ bool VerifyTownName(uint32 r, const TownNameParams *par, TownNames *town_names)
|
|||
|
||||
/**
|
||||
* Generates valid town name.
|
||||
* @param randomizer the source of random data for generating the name
|
||||
* @param townnameparts if a name is generated, it's stored there
|
||||
* @param town_names if a name is generated, check its uniqueness with the set
|
||||
* @return true iff a name was generated
|
||||
*/
|
||||
bool GenerateTownName(uint32 *townnameparts, TownNames *town_names)
|
||||
bool GenerateTownName(Randomizer &randomizer, uint32 *townnameparts, TownNames *town_names)
|
||||
{
|
||||
TownNameParams par(_settings_game.game_creation.town_name);
|
||||
|
||||
|
@ -130,7 +131,7 @@ bool GenerateTownName(uint32 *townnameparts, TownNames *town_names)
|
|||
* the other towns may take considerable amount of time (10000 is
|
||||
* too much). */
|
||||
for (int i = 1000; i != 0; i--) {
|
||||
uint32 r = _generating_world ? Random() : InteractiveRandom();
|
||||
uint32 r = randomizer.Next();
|
||||
if (!VerifyTownName(r, &par, town_names)) continue;
|
||||
|
||||
*townnameparts = r;
|
||||
|
|
|
@ -10,12 +10,13 @@
|
|||
#ifndef TOWNNAME_FUNC_H
|
||||
#define TOWNNAME_FUNC_H
|
||||
|
||||
#include "core/random_func.hpp"
|
||||
#include "townname_type.h"
|
||||
|
||||
char *GenerateTownNameString(char *buf, const char *last, size_t lang, uint32 seed);
|
||||
char *GetTownName(char *buff, const TownNameParams *par, uint32 townnameparts, const char *last);
|
||||
char *GetTownName(char *buff, const Town *t, const char *last);
|
||||
bool VerifyTownName(uint32 r, const TownNameParams *par, TownNames *town_names = nullptr);
|
||||
bool GenerateTownName(uint32 *townnameparts, TownNames *town_names = nullptr);
|
||||
bool GenerateTownName(Randomizer &randomizer, uint32 *townnameparts, TownNames *town_names = nullptr);
|
||||
|
||||
#endif /* TOWNNAME_FUNC_H */
|
||||
|
|
|
@ -308,6 +308,7 @@ void PlaceTreesRandomly()
|
|||
*/
|
||||
uint PlaceTreeGroupAroundTile(TileIndex tile, TreeType treetype, uint radius, uint count, bool set_zone)
|
||||
{
|
||||
assert(_game_mode == GM_EDITOR); // Due to InteractiveRandom being used in this function
|
||||
assert(treetype < TREE_TOYLAND + TREE_COUNT_TOYLAND);
|
||||
const bool allow_desert = treetype == TREE_CACTUS;
|
||||
uint planted = 0;
|
||||
|
|
Loading…
Reference in New Issue