MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FoundTown

Method FoundTown

src/script/api/script_town.cpp:290–318  ·  view source on GitHub ↗

static */

Source from the content-addressed store, hash-verified

288}
289
290/* static */ bool ScriptTown::FoundTown(TileIndex tile, TownSize size, bool city, RoadLayout layout, Text *name)
291{
292 ScriptObjectRef counter(name);
293
294 EnforceDeityOrCompanyModeValid(false);
295 EnforcePrecondition(false, ScriptCompanyMode::IsDeity() || _settings_game.economy.found_town != TF_FORBIDDEN);
296 EnforcePrecondition(false, ::IsValidTile(tile));
297 EnforcePrecondition(false, size == TOWN_SIZE_SMALL || size == TOWN_SIZE_MEDIUM || size == TOWN_SIZE_LARGE)
298 EnforcePrecondition(false, ScriptCompanyMode::IsDeity() || size != TOWN_SIZE_LARGE);
299 if (ScriptCompanyMode::IsDeity() || _settings_game.economy.found_town == TF_CUSTOM_LAYOUT) {
300 EnforcePrecondition(false, layout >= ROAD_LAYOUT_ORIGINAL && layout <= ROAD_LAYOUT_RANDOM);
301 } else {
302 /* The layout parameter is ignored for AIs when custom layouts is disabled. */
303 layout = (RoadLayout) (uint8_t)_settings_game.economy.town_layout;
304 }
305
306 std::string text;
307 if (name != nullptr) {
308 text = name->GetDecodedText();
309 EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
310 }
311 uint32_t townnameparts;
312 if (!GenerateTownName(ScriptObject::GetRandomizer(), &townnameparts)) {
313 ScriptObject::SetLastError(ScriptError::ERR_NAME_IS_NOT_UNIQUE);
314 return false;
315 }
316
317 return ScriptObject::Command<CMD_FOUND_TOWN>::Do(tile, (::TownSize)size, city, (::TownLayout)layout, false, townnameparts, text);
318}
319
320/* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id)
321{

Callers

nothing calls this directly

Calls 4

IsValidTileFunction · 0.85
Utf8StringLengthFunction · 0.85
GenerateTownNameFunction · 0.85
GetDecodedTextMethod · 0.80

Tested by

no test coverage detected