From 102f811d0277afefe5c90762c0c4cc11ab69713c Mon Sep 17 00:00:00 2001 From: truebrain Date: Mon, 19 Dec 2011 21:06:06 +0000 Subject: (svn r23636) -Add: introduce ScriptText in parameters where it can be used --- src/script/api/ai/ai_text.hpp.sq | 31 +++++++++++++++++++++++++++++++ src/script/api/game/game_company.hpp.sq | 2 ++ src/script/api/script_basestation.cpp | 12 ++++++++---- src/script/api/script_basestation.hpp | 8 ++++---- src/script/api/script_company.cpp | 22 +++++++++++++++------- src/script/api/script_company.hpp | 16 +++++++--------- src/script/api/script_goal.cpp | 9 ++++++--- src/script/api/script_goal.hpp | 6 +++--- src/script/api/script_group.cpp | 12 ++++++++---- src/script/api/script_group.hpp | 7 +++---- src/script/api/script_news.cpp | 9 ++++++--- src/script/api/script_news.hpp | 5 +++-- src/script/api/script_sign.cpp | 18 +++++++++++++----- src/script/api/script_sign.hpp | 14 ++++++-------- src/script/api/script_text.hpp | 2 +- src/script/api/script_town.cpp | 8 ++++++-- src/script/api/script_town.hpp | 5 +++-- src/script/api/script_vehicle.cpp | 12 ++++++++---- src/script/api/script_vehicle.hpp | 7 +++---- 19 files changed, 136 insertions(+), 69 deletions(-) create mode 100644 src/script/api/ai/ai_text.hpp.sq (limited to 'src/script/api') diff --git a/src/script/api/ai/ai_text.hpp.sq b/src/script/api/ai/ai_text.hpp.sq new file mode 100644 index 000000000..e1d8e96c6 --- /dev/null +++ b/src/script/api/ai/ai_text.hpp.sq @@ -0,0 +1,31 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_text.hpp" +#include "../template/template_text.hpp.sq" + + +template <> const char *GetClassName() { return "AIText"; } + +void SQAIText_Register(Squirrel *engine) +{ + DefSQClass SQAIText("AIText"); + SQAIText.PreRegister(engine); + SQAIText.AddConstructor(engine, "xi"); + + SQAIText.DefSQConst(engine, ScriptText::SCRIPT_TEXT_MAX_PARAMETERS, "SCRIPT_TEXT_MAX_PARAMETERS"); + + SQAIText.DefSQAdvancedMethod(engine, &ScriptText::_set, "_set"); + SQAIText.DefSQAdvancedMethod(engine, &ScriptText::SetParam, "SetParam"); + SQAIText.DefSQAdvancedMethod(engine, &ScriptText::AddParam, "AddParam"); + + SQAIText.PostRegister(engine); +} diff --git a/src/script/api/game/game_company.hpp.sq b/src/script/api/game/game_company.hpp.sq index e90b1a8a4..98c6d4476 100644 --- a/src/script/api/game/game_company.hpp.sq +++ b/src/script/api/game/game_company.hpp.sq @@ -32,7 +32,9 @@ void SQGSCompany_Register(Squirrel *engine) SQGSCompany.DefSQConst(engine, ScriptCompany::GENDER_INVALID, "GENDER_INVALID"); SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::ResolveCompanyID, "ResolveCompanyID", 2, ".i"); + SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::SetName, "SetName", 2, ".."); SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetName, "GetName", 2, ".i"); + SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::SetPresidentName, "SetPresidentName", 2, ".."); SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetPresidentName, "GetPresidentName", 2, ".i"); SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::GetPresidentGender, "GetPresidentGender", 2, ".i"); SQGSCompany.DefSQStaticMethod(engine, &ScriptCompany::SetLoanAmount, "SetLoanAmount", 2, ".i"); diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index 84c41abce..ff4de1cff 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -34,14 +34,18 @@ return name; } -/* static */ bool ScriptBaseStation::SetName(StationID station_id, const char *name) +/* static */ bool ScriptBaseStation::SetName(StationID station_id, Text *name) { + CCountedPtr counter(name); + EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidBaseStation(station_id)); - EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePrecondition(false, name != NULL); + const char *text = name->GetEncodedText(); + EnforcePrecondition(false, !::StrEmpty(text)); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return ScriptObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, name); + return ScriptObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, text); } /* static */ TileIndex ScriptBaseStation::GetLocation(StationID station_id) diff --git a/src/script/api/script_basestation.hpp b/src/script/api/script_basestation.hpp index 7007985ae..02ad4b716 100644 --- a/src/script/api/script_basestation.hpp +++ b/src/script/api/script_basestation.hpp @@ -13,6 +13,7 @@ #define SCRIPT_BASESTATION_HPP #include "script_error.hpp" +#include "script_text.hpp" /** * Base class for stations and waypoints. @@ -49,15 +50,14 @@ public: /** * Set the name this basestation. * @param station_id The basestation to set the name of. - * @param name The new name of the station. + * @param name The new name of the station (can be either a raw string, or a ScriptText object). * @pre IsValidBaseStation(station_id). - * @pre 'name' must have at least one character. - * @pre 'name' must have at most 30 characters. + * @pre name != NULL && len(name) != 0. * @game @pre Valid ScriptCompanyMode active in scope. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. */ - static bool SetName(StationID station_id, const char *name); + static bool SetName(StationID station_id, Text *name); /** * Get the current location of a basestation. diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index efc2848a5..d4bc5d3e7 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -39,12 +39,16 @@ return ResolveCompanyID(company) == ResolveCompanyID(COMPANY_SELF); } -/* static */ bool ScriptCompany::SetName(const char *name) +/* static */ bool ScriptCompany::SetName(Text *name) { - EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + CCountedPtr counter(name); - return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, name); + EnforcePrecondition(false, name != NULL); + const char *text = name->GetEncodedText(); + EnforcePrecondition(false, !::StrEmpty(text)); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + + return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, text); } /* static */ char *ScriptCompany::GetName(ScriptCompany::CompanyID company) @@ -60,11 +64,15 @@ return company_name; } -/* static */ bool ScriptCompany::SetPresidentName(const char *name) +/* static */ bool ScriptCompany::SetPresidentName(Text *name) { - EnforcePrecondition(false, !::StrEmpty(name)); + CCountedPtr counter(name); + + EnforcePrecondition(false, name != NULL); + const char *text = name->GetEncodedText(); + EnforcePrecondition(false, !::StrEmpty(text)); - return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_PRESIDENT, name); + return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_PRESIDENT, text); } /* static */ char *ScriptCompany::GetPresidentName(ScriptCompany::CompanyID company) diff --git a/src/script/api/script_company.hpp b/src/script/api/script_company.hpp index de15b7ab2..04c3a5abc 100644 --- a/src/script/api/script_company.hpp +++ b/src/script/api/script_company.hpp @@ -13,6 +13,7 @@ #define SCRIPT_COMPANY_HPP #include "script_object.hpp" +#include "script_text.hpp" /** * Class that handles all company related functions. @@ -64,14 +65,12 @@ public: /** * Set the name of your company. - * @param name The new name of the company. - * @pre 'name' must have at least one character. - * @pre 'name' must have at most 30 characters. + * @param name The new name of the company (can be either a raw string, or a ScriptText object). + * @pre name != NULL && len(name) != 0. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. - * @api -game */ - static bool SetName(const char *name); + static bool SetName(Text *name); /** * Get the name of the given company. @@ -83,13 +82,12 @@ public: /** * Set the name of your president. - * @param name The new name of the president. - * @pre 'name' must have at least one character. + * @param name The new name of the president (can be either a raw string, or a ScriptText object). + * @pre name != NULL && len(name) != 0. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. - * @api -game */ - static bool SetPresidentName(const char *name); + static bool SetPresidentName(Text *name); /** * Get the name of the president of the given company. diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 85aaeedb6..e005ceda0 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -28,16 +28,19 @@ return ::Goal::IsValidID(goal_id); } -/* static */ ScriptGoal::GoalID ScriptGoal::New(ScriptCompany::CompanyID company, const char *goal, GoalType type, uint32 destination) +/* static */ ScriptGoal::GoalID ScriptGoal::New(ScriptCompany::CompanyID company, Text *goal, GoalType type, uint32 destination) { - EnforcePrecondition(GOAL_INVALID, !StrEmpty(goal)); + CCountedPtr counter(goal); + + EnforcePrecondition(GOAL_INVALID, goal != NULL); + EnforcePrecondition(GOAL_INVALID, !StrEmpty(goal->GetEncodedText())); EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID); EnforcePrecondition(GOAL_INVALID, (type == GT_NONE && destination == 0) || (type == GT_TILE && ScriptMap::IsValidTile(destination)) || (type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) || (type == GT_TOWN && ScriptTown::IsValidTown(destination)) || (type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID)); uint8 c = company; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; - if (!ScriptObject::DoCommand(0, type | (c << 8), destination, CMD_CREATE_GOAL, goal, &ScriptInstance::DoCommandReturnGoalID)) return GOAL_INVALID; + if (!ScriptObject::DoCommand(0, type | (c << 8), destination, CMD_CREATE_GOAL, goal->GetEncodedText(), &ScriptInstance::DoCommandReturnGoalID)) return GOAL_INVALID; /* In case of test-mode, we return GoalID 0 */ return (ScriptGoal::GoalID)0; diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index ac7d8f449..2fad1e843 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -52,14 +52,14 @@ public: /** * Create a new goal. * @param company The company to create the goal for, or ScriptCompany::COMPANY_INVALID for all. - * @param goal The goal to add to the GUI. + * @param goal The goal to add to the GUI (can be either a raw string, or a ScriptText object). * @param type The type of the goal. * @param destination The destination of the #type type. * @return The new GoalID, or GOAL_INVALID if it failed. - * @pre goal != NULL. + * @pre goal != NULL && len(goal) != 0. * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID. */ - static GoalID New(ScriptCompany::CompanyID company, const char *goal, GoalType type, uint32 destination); + static GoalID New(ScriptCompany::CompanyID company, Text *goal, GoalType type, uint32 destination); /** * Remove a goal from the list. diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index 4f9ce8a2a..63c022e90 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -49,13 +49,17 @@ return (ScriptVehicle::VehicleType)((::VehicleType)::Group::Get(group_id)->vehicle_type); } -/* static */ bool ScriptGroup::SetName(GroupID group_id, const char *name) +/* static */ bool ScriptGroup::SetName(GroupID group_id, Text *name) { + CCountedPtr counter(name); + EnforcePrecondition(false, IsValidGroup(group_id)); - EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePrecondition(false, name != NULL); + const char *text = name->GetEncodedText(); + EnforcePrecondition(false, !::StrEmpty(text)); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return ScriptObject::DoCommand(0, group_id, 0, CMD_RENAME_GROUP, name); + return ScriptObject::DoCommand(0, group_id, 0, CMD_RENAME_GROUP, text); } /* static */ char *ScriptGroup::GetName(GroupID group_id) diff --git a/src/script/api/script_group.hpp b/src/script/api/script_group.hpp index 1a549bf53..e1cd7cf4e 100644 --- a/src/script/api/script_group.hpp +++ b/src/script/api/script_group.hpp @@ -68,14 +68,13 @@ public: /** * Set the name of a group. * @param group_id The group to set the name for. - * @param name The name for the group. + * @param name The name for the group (can be either a raw string, or a ScriptText object). * @pre IsValidGroup(group_id). - * @pre 'name' must have at least one character. - * @pre 'name' must have at most 30 characters. + * @pre name != NULL && len(name) != 0 * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ - static bool SetName(GroupID group_id, const char *name); + static bool SetName(GroupID group_id, Text *name); /** * Get the name of a group. diff --git a/src/script/api/script_news.cpp b/src/script/api/script_news.cpp index 36ebf9204..d2c5e9343 100644 --- a/src/script/api/script_news.cpp +++ b/src/script/api/script_news.cpp @@ -18,14 +18,17 @@ #include "../../string_func.h" #include "table/strings.h" -/* static */ bool ScriptNews::Create(NewsType type, const char *text, ScriptCompany::CompanyID company) +/* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company) { - EnforcePrecondition(false, !StrEmpty(text)); + CCountedPtr counter(text); + + EnforcePrecondition(false, text != NULL); + EnforcePrecondition(false, !StrEmpty(text->GetEncodedText())); EnforcePrecondition(false, type >= NT_ARRIVAL_COMPANY && type <= NT_GENERAL); EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID); uint8 c = company; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; - return ScriptObject::DoCommand(0, type | (NR_NONE << 8) | (c << 16), 0, CMD_CUSTOM_NEWS_ITEM, text); + return ScriptObject::DoCommand(0, type | (NR_NONE << 8) | (c << 16), 0, CMD_CUSTOM_NEWS_ITEM, text->GetEncodedText()); } diff --git a/src/script/api/script_news.hpp b/src/script/api/script_news.hpp index 51780befc..8edd80df6 100644 --- a/src/script/api/script_news.hpp +++ b/src/script/api/script_news.hpp @@ -13,6 +13,7 @@ #define SCRIPT_NEWS_HPP #include "script_company.hpp" +#include "script_text.hpp" #include "../../news_type.h" /** @@ -49,13 +50,13 @@ public: /** * Create a news messages for a company. * @param type The type of the news. - * @param text The text message to show. + * @param text The text message to show (can be either a raw string, or a ScriptText object). * @param company The company, or COMPANY_INVALID for all companies. * @return True if the action succeeded. * @pre text != NULL. * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID. */ - static bool Create(NewsType type, const char *text, ScriptCompany::CompanyID company); + static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company); }; #endif /* SCRIPT_NEWS_HPP */ diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp index b5b8dacbc..352bb185e 100644 --- a/src/script/api/script_sign.cpp +++ b/src/script/api/script_sign.cpp @@ -33,13 +33,17 @@ return static_cast((int)::Sign::Get(sign_id)->owner); } -/* static */ bool ScriptSign::SetName(SignID sign_id, const char *name) +/* static */ bool ScriptSign::SetName(SignID sign_id, Text *name) { + CCountedPtr counter(name); + EnforcePrecondition(false, IsValidSign(sign_id)); - EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePrecondition(false, name != NULL); + const char *text = name->GetEncodedText(); + EnforcePrecondition(false, !::StrEmpty(text)); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, name); + return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, text); } /* static */ char *ScriptSign::GetName(SignID sign_id) @@ -69,9 +73,13 @@ return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, ""); } -/* static */ SignID ScriptSign::BuildSign(TileIndex location, const char *text) +/* static */ SignID ScriptSign::BuildSign(TileIndex location, Text *name) { + CCountedPtr counter(name); + EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); + EnforcePrecondition(INVALID_SIGN, name != NULL); + const char *text = name->GetEncodedText(); EnforcePrecondition(INVALID_SIGN, !::StrEmpty(text)); EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); diff --git a/src/script/api/script_sign.hpp b/src/script/api/script_sign.hpp index 9aacc409c..e5c2164da 100644 --- a/src/script/api/script_sign.hpp +++ b/src/script/api/script_sign.hpp @@ -43,14 +43,13 @@ public: /** * Set the name of a sign. * @param sign_id The sign to set the name for. - * @param name The name for the sign. + * @param name The name for the sign (can be either a raw string, or a ScriptText object). * @pre IsValidSign(sign_id). - * @pre 'name' must have at least one character. - * @pre 'name' must have at most 30 characters. + * @pre name != NULL && len(name) != 0. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ - static bool SetName(SignID sign_id, const char *name); + static bool SetName(SignID sign_id, Text *name); /** * Get the name of the sign. @@ -80,16 +79,15 @@ public: /** * Builds a sign on the map. * @param location The place to build the sign. - * @param text The text to place on the sign. + * @param name The text to place on the sign (can be either a raw string, or a ScriptText object). * @pre ScriptMap::IsValidTile(location). - * @pre 'text' must have at least one character. - * @pre 'text' must have at most 30 characters. + * @pre name != NULL && len(name) != 0. * @exception ScriptSign::ERR_SIGN_TOO_MANY_SIGNS * @return The SignID of the build sign (use IsValidSign() to check for validity). * In test-mode it returns 0 if successful, or any other value to indicate * failure. */ - static SignID BuildSign(TileIndex location, const char *text); + static SignID BuildSign(TileIndex location, Text *name); /** * Removes a sign from the map. diff --git a/src/script/api/script_text.hpp b/src/script/api/script_text.hpp index 9f994e1f3..27bcca485 100644 --- a/src/script/api/script_text.hpp +++ b/src/script/api/script_text.hpp @@ -62,7 +62,7 @@ private: * local text = ScriptText(ScriptText.STR_NEWS); text.AddParam(1); * This will set the {COMPANY} to the name of Company 1. * - * @api game + * @api ai game */ class ScriptText : public Text , public ZeroedMemoryAllocator { public: diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index e1c0c0a85..c04115c8f 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -43,10 +43,14 @@ return town_name; } -/* static */ bool ScriptTown::SetText(TownID town_id, const char *text) +/* static */ bool ScriptTown::SetText(TownID town_id, Text *text) { + CCountedPtr counter(text); + + EnforcePrecondition(false, text != NULL); EnforcePrecondition(false, IsValidTown(town_id)); - return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, text); + + return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, text->GetEncodedText()); } /* static */ int32 ScriptTown::GetPopulation(TownID town_id) diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp index 1138d3336..749bf807e 100644 --- a/src/script/api/script_town.hpp +++ b/src/script/api/script_town.hpp @@ -14,6 +14,7 @@ #include "script_cargo.hpp" #include "script_company.hpp" +#include "script_text.hpp" #include "../../town_type.h" /** @@ -129,12 +130,12 @@ public: /** * Set the custom text of a town, shown in the GUI. * @param town_id The town to set the custom text of. - * @param text The text to set it to. + * @param text The text to set it to (can be either a raw string, or a ScriptText object). * @pre IsValidTown(town_id). * @return True if the action succeeded. * @api -ai */ - static bool SetText(TownID town_id, const char *text); + static bool SetText(TownID town_id, Text *text); /** * Gets the number of inhabitants in the town. diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index 9a73e564e..13ccce518 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -212,14 +212,18 @@ } } -/* static */ bool ScriptVehicle::SetName(VehicleID vehicle_id, const char *name) +/* static */ bool ScriptVehicle::SetName(VehicleID vehicle_id, Text *name) { + CCountedPtr counter(name); + EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidVehicle(vehicle_id)); - EnforcePrecondition(false, !::StrEmpty(name)); - EnforcePreconditionCustomError(false, ::Utf8StringLength(name) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePrecondition(false, name != NULL); + const char *text = name->GetEncodedText(); + EnforcePrecondition(false, !::StrEmpty(text)); + EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_RENAME_VEHICLE, name); + return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_RENAME_VEHICLE, text); } /* static */ TileIndex ScriptVehicle::GetLocation(VehicleID vehicle_id) diff --git a/src/script/api/script_vehicle.hpp b/src/script/api/script_vehicle.hpp index 9a6723cb9..da36a542c 100644 --- a/src/script/api/script_vehicle.hpp +++ b/src/script/api/script_vehicle.hpp @@ -113,15 +113,14 @@ public: /** * Set the name of a vehicle. * @param vehicle_id The vehicle to set the name for. - * @param name The name for the vehicle. + * @param name The name for the vehicle (can be either a raw string, or a ScriptText object). * @pre IsValidVehicle(vehicle_id). - * @pre 'name' must have at least one character. - * @pre 'name' must have at most 30 characters. + * @pre name != NULL && len(name) != 0. * @game @pre Valid ScriptCompanyMode active in scope. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ - static bool SetName(VehicleID vehicle_id, const char *name); + static bool SetName(VehicleID vehicle_id, Text *name); /** * Get the name of a vehicle. -- cgit v1.2.3-70-g09d2