@@ -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<Text> 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;
@@ -52,14 +52,14 @@ class ScriptGoal : public ScriptObject {
/**
* 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.
@@ -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<Text> 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)
@@ -68,14 +68,13 @@ class ScriptGroup : public ScriptObject {
/**
* 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.
@@ -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<Text> 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());
}
@@ -13,6 +13,7 @@
#define SCRIPT_NEWS_HPP

#include "script_company.hpp"
#include "script_text.hpp"
#include "../../news_type.h"

/**
@@ -49,13 +50,13 @@ class ScriptNews : public ScriptObject {
/**
* 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 */
@@ -33,13 +33,17 @@
return static_cast<ScriptCompany::CompanyID>((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<Text> 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<Text> 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);

@@ -43,14 +43,13 @@ class ScriptSign : public ScriptObject {
/**
* 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 @@ class ScriptSign : public ScriptObject {
/**
* 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.
@@ -62,7 +62,7 @@ class RawText : public Text {
* 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:
@@ -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<Text> 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)
@@ -14,6 +14,7 @@

#include "script_cargo.hpp"
#include "script_company.hpp"
#include "script_text.hpp"
#include "../../town_type.h"

/**
@@ -129,12 +130,12 @@ class ScriptTown : public ScriptObject {
/**
* 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.
@@ -212,14 +212,18 @@
}
}

/* static */ bool ScriptVehicle::SetName(VehicleID vehicle_id, const char *name)
/* static */ bool ScriptVehicle::SetName(VehicleID vehicle_id, Text *name)
{
CCountedPtr<Text> 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)
@@ -113,15 +113,14 @@ class ScriptVehicle : public ScriptObject {
/**
* 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.
@@ -1205,7 +1205,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (c == NULL) break;

if (c->name != NULL) {
buff = strecpy(buff, c->name, last);
int64 args_array[] = {(uint64)(size_t)c->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
int64 args_array[] = {c->name_2};
StringParameters tmp_params(args_array);
@@ -1237,7 +1239,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg

const Depot *d = Depot::Get(args->GetInt32());
if (d->name != NULL) {
buff = strecpy(buff, d->name, last);
int64 args_array[] = {(uint64)(size_t)d->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
int64 args_array[] = {d->town->index, d->town_cn + 1};
StringParameters tmp_params(args_array);
@@ -1251,7 +1255,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (e == NULL) break;

if (e->name != NULL && e->IsEnabled()) {
buff = strecpy(buff, e->name, last);
int64 args_array[] = {(uint64)(size_t)e->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
StringParameters tmp_params(NULL, 0, NULL);
buff = GetStringWithArgs(buff, e->info.string_id, &tmp_params, last);
@@ -1264,7 +1270,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (g == NULL) break;

if (g->name != NULL) {
buff = strecpy(buff, g->name, last);
int64 args_array[] = {(uint64)(size_t)g->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
int64 args_array[] = {g->index};
StringParameters tmp_params(args_array);
@@ -1292,7 +1300,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (c == NULL) break;

if (c->president_name != NULL) {
buff = strecpy(buff, c->president_name, last);
int64 args_array[] = {(uint64)(size_t)c->president_name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
int64 args_array[] = {c->president_name_2};
StringParameters tmp_params(args_array);
@@ -1315,7 +1325,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
}

if (st->name != NULL) {
buff = strecpy(buff, st->name, last);
int64 args_array[] = {(uint64)(size_t)st->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
StringID str = st->string_id;
if (st->indtype != IT_INVALID) {
@@ -1342,7 +1354,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (t == NULL) break;

if (t->name != NULL) {
buff = strecpy(buff, t->name, last);
int64 args_array[] = {(uint64)(size_t)t->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
buff = GetTownName(buff, t, last);
}
@@ -1354,7 +1368,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (wp == NULL) break;

if (wp->name != NULL) {
buff = strecpy(buff, wp->name, last);
int64 args_array[] = {(uint64)(size_t)wp->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
int64 args_array[] = {wp->town->index, wp->town_cn + 1};
StringParameters tmp_params(args_array);
@@ -1370,7 +1386,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (v == NULL) break;

if (v->name != NULL) {
buff = strecpy(buff, v->name, last);
int64 args_array[] = {(uint64)(size_t)v->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
int64 args_array[] = {v->unitnumber};
StringParameters tmp_params(args_array);
@@ -1394,7 +1412,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
if (si == NULL) break;

if (si->name != NULL) {
buff = strecpy(buff, si->name, last);
int64 args_array[] = {(uint64)(size_t)si->name};
StringParameters tmp_params(args_array);
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
} else {
StringParameters tmp_params(NULL, 0, NULL);
buff = GetStringWithArgs(buff, STR_DEFAULT_SIGN_NAME, &tmp_params, last);
@@ -405,7 +405,8 @@ struct TownViewWindow : Window {
}

if (this->town->text != NULL) {
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, UINT16_MAX, this->town->text, TC_BLACK);
SetDParamStr(0, this->town->text);
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
}
}