diff options
author | zuu <zuu@openttd.org> | 2013-09-19 18:48:05 +0000 |
---|---|---|
committer | zuu <zuu@openttd.org> | 2013-09-19 18:48:05 +0000 |
commit | 67ab3108d6b4ca9676871cabdae3ed187d51393d (patch) | |
tree | bed3b9842803eb94ce1280431ab58fd6aca33a95 /src/script/api/script_town.cpp | |
parent | 953aa839b9954b3098ffc5932ab6bd0910b8ae46 (diff) | |
download | openttd-67ab3108d6b4ca9676871cabdae3ed187d51393d.tar.xz |
(svn r25785) -Feature: [Script] Allow AIs and GS to found towns. Allow GS to rename towns
Diffstat (limited to 'src/script/api/script_town.cpp')
-rw-r--r-- | src/script/api/script_town.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index b64adab1a..3b9a4b7b6 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -14,6 +14,7 @@ #include "script_map.hpp" #include "script_error.hpp" #include "../../town.h" +#include "../../townname_func.h" #include "../../string_func.h" #include "../../strings_func.h" #include "../../station_base.h" @@ -38,6 +39,21 @@ return GetString(STR_TOWN_NAME); } +/* static */ bool ScriptTown::SetName(TownID town_id, Text *name) +{ + CCountedPtr<Text> counter(name); + + const char *text = NULL; + if (name != NULL) { + const char *text = name->GetDecodedText(); + EnforcePreconditionEncodedText(false, text); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + } + EnforcePrecondition(false, IsValidTown(town_id)); + + return ScriptObject::DoCommand(0, town_id, 0, CMD_RENAME_TOWN, text); +} + /* static */ bool ScriptTown::SetText(TownID town_id, Text *text) { CCountedPtr<Text> counter(text); @@ -238,6 +254,33 @@ return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, houses, CMD_EXPAND_TOWN); } +/* static */ bool ScriptTown::FoundTown(TileIndex tile, TownSize size, bool city, RoadLayout layout, Text *name) +{ + CCountedPtr<Text> counter(name); + + EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY || _settings_game.economy.found_town != TF_FORBIDDEN); + EnforcePrecondition(false, ::IsValidTile(tile)); + EnforcePrecondition(false, size == TOWN_SIZE_SMALL || size == TOWN_SIZE_MEDIUM || size == TOWN_SIZE_LARGE) + EnforcePrecondition(false, size != TOWN_SIZE_LARGE || ScriptObject::GetCompany() == OWNER_DEITY); + if (ScriptObject::GetCompany() == OWNER_DEITY || _settings_game.economy.found_town == TF_CUSTOM_LAYOUT) { + EnforcePrecondition(false, layout == ROAD_LAYOUT_ORIGINAL || layout == ROAD_LAYOUT_BETTER_ROADS || layout == ROAD_LAYOUT_2x2 || layout == ROAD_LAYOUT_3x3); + } else { + /* The layout parameter is ignored for AIs when custom layouts is disabled. */ + layout = (RoadLayout) (byte)_settings_game.economy.town_layout; + } + + const char *text = NULL; + if (name != NULL) { + text = name->GetDecodedText(); + EnforcePreconditionEncodedText(false, text); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + } + uint32 townnameparts; + GenerateTownName(&townnameparts); + + return ScriptObject::DoCommand(tile, size | (city ? 1 << 2 : 0) | layout << 3, townnameparts, CMD_FOUND_TOWN, text); +} + /* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id) { if (!IsValidTown(town_id)) return TOWN_RATING_INVALID; |