Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/release-linux.yml # .github/workflows/release-macos.yml # src/industry_cmd.cpp # src/industry_cmd.h # src/network/core/http_curl.cpp # src/network/core/tcp_http.cpp # src/network/core/tcp_http.h # src/network/network_content.h # src/script/api/script_goal.cpp # src/script/api/script_industry.cpp # src/script/api/script_league.cpp # src/script/api/script_story_page.cpp # src/script/api/script_town.cpp # src/train.h # src/train_cmd.cpp
This commit is contained in:
@@ -19,6 +19,10 @@
|
||||
*
|
||||
* API additions:
|
||||
* \li AITown::ROAD_LAYOUT_RANDOM
|
||||
* \li AIVehicle::IsPrimaryVehicle
|
||||
*
|
||||
* API removals:
|
||||
* \li AIError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
|
||||
*
|
||||
* \b 13.0
|
||||
*
|
||||
|
@@ -19,6 +19,10 @@
|
||||
*
|
||||
* API additions:
|
||||
* \li GSTown::ROAD_LAYOUT_RANDOM
|
||||
* \li GSVehicle::IsPrimaryVehicle
|
||||
*
|
||||
* API removals:
|
||||
* \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
|
||||
*
|
||||
* \b 13.0
|
||||
*
|
||||
|
@@ -38,7 +38,7 @@
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidBaseStation(station_id));
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const char *text = name->GetDecodedText();
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
@@ -44,7 +44,7 @@
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const char *text = name->GetDecodedText();
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const char *text = name->GetDecodedText();
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
@@ -42,11 +42,7 @@
|
||||
* @param string The string that is checked.
|
||||
*/
|
||||
#define EnforcePreconditionEncodedText(returnval, string) \
|
||||
if ((string) == nullptr) { \
|
||||
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_TOO_MANY_PARAMETERS); \
|
||||
return returnval; \
|
||||
} \
|
||||
if (StrEmpty(string)) { \
|
||||
if (string.empty()) { \
|
||||
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_FAILED); \
|
||||
return returnval; \
|
||||
}
|
||||
@@ -94,8 +90,6 @@ public:
|
||||
ERR_PRECONDITION_FAILED, // []
|
||||
/** A string supplied was too long */
|
||||
ERR_PRECONDITION_STRING_TOO_LONG, // []
|
||||
/** A string had too many parameters */
|
||||
ERR_PRECONDITION_TOO_MANY_PARAMETERS, // []
|
||||
/** The company you use is invalid */
|
||||
ERR_PRECONDITION_INVALID_COMPANY, // []
|
||||
/** An error returned by a NewGRF. No possibility to get the exact error in an script readable format */
|
||||
|
@@ -33,7 +33,7 @@
|
||||
|
||||
EnforcePrecondition(GOAL_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
EnforcePrecondition(GOAL_INVALID, goal != nullptr);
|
||||
const char *text = goal->GetEncodedText();
|
||||
const std::string &text = goal->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(GOAL_INVALID, text);
|
||||
EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
|
||||
|
||||
@@ -70,9 +70,10 @@
|
||||
EnforcePrecondition(false, IsValidGoal(goal_id));
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
EnforcePrecondition(false, goal != nullptr);
|
||||
EnforcePrecondition(false, !StrEmpty(goal->GetEncodedText()));
|
||||
const std::string &text = goal->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
|
||||
return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_TEXT, goal->GetEncodedText());
|
||||
return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_TEXT, text);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGoal::SetProgress(GoalID goal_id, Text *progress)
|
||||
@@ -82,12 +83,7 @@
|
||||
EnforcePrecondition(false, IsValidGoal(goal_id));
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
|
||||
/* Ensure null as used for empty string. */
|
||||
if (progress != nullptr && StrEmpty(progress->GetEncodedText())) {
|
||||
progress = nullptr;
|
||||
}
|
||||
|
||||
return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_PROGRESS, progress != nullptr ? progress->GetEncodedText() : nullptr);
|
||||
return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_PROGRESS, progress != nullptr ? progress->GetEncodedText().c_str() : "");
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGoal::SetCompleted(GoalID goal_id, bool completed)
|
||||
@@ -113,7 +109,7 @@
|
||||
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
EnforcePrecondition(false, question != nullptr);
|
||||
const char *text = question->GetEncodedText();
|
||||
const std::string &text = question->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
uint min_buttons = (type == QT_QUESTION ? 1 : 0);
|
||||
EnforcePrecondition(false, CountBits(buttons) >= min_buttons && CountBits(buttons) <= 3);
|
||||
|
@@ -54,7 +54,7 @@
|
||||
|
||||
EnforcePrecondition(false, IsValidGroup(group_id));
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const char *text = name->GetDecodedText();
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
/* static */ bool ScriptGroup::MoveVehicle(GroupID group_id, VehicleID vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT);
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, group_id, vehicle_id, CMD_ADD_VEHICLE_GROUP);
|
||||
}
|
||||
|
@@ -147,7 +147,7 @@ public:
|
||||
* @param group_id The group to move the vehicle to.
|
||||
* @param vehicle_id The vehicle to move to the group.
|
||||
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @return True if and only if the vehicle was successfully moved to the group.
|
||||
* @note A vehicle can be in only one group at the same time. To remove it from
|
||||
* a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the
|
||||
|
@@ -52,14 +52,9 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
const char *encoded_text = nullptr;
|
||||
if (text != nullptr) {
|
||||
encoded_text = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded_text);
|
||||
}
|
||||
EnforcePrecondition(false, IsValidIndustry(industry_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, industry_id, static_cast<uint32>(IndustryAction::SetText), CMD_INDUSTRY_CTRL, encoded_text);
|
||||
return ScriptObject::DoCommand(0, industry_id, 0, CMD_INDUSTRY_SET_TEXT, text != nullptr ? text->GetEncodedText().c_str() : "");
|
||||
}
|
||||
|
||||
/* static */ ScriptIndustry::CargoAcceptState ScriptIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
|
||||
@@ -257,7 +252,7 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
|
||||
if (ScriptObject::GetCompany() != OWNER_DEITY) return false;
|
||||
if (!IsValidIndustry(industry_id)) return false;
|
||||
|
||||
return ScriptObject::DoCommand(0, industry_id, 0 | ((control_flags & ::INDCTL_MASK) << 8), CMD_INDUSTRY_CTRL);
|
||||
return ScriptObject::DoCommand(0, industry_id, (::IndustryControlFlags)control_flags & ::INDCTL_MASK, CMD_INDUSTRY_SET_FLAGS);
|
||||
}
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveSupplier(IndustryID industry_id)
|
||||
@@ -276,7 +271,7 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
|
||||
|
||||
auto company = ScriptCompany::ResolveCompanyID(company_id);
|
||||
::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company);
|
||||
return ScriptObject::DoCommand(0, industry_id, 1 | (((uint8)owner) << 16), CMD_INDUSTRY_CTRL);
|
||||
return ScriptObject::DoCommand(0, industry_id, (1 << 8) | ((uint8)owner), CMD_INDUSTRY_SET_EXCLUSIVITY);
|
||||
}
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveConsumer(IndustryID industry_id)
|
||||
@@ -295,5 +290,5 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
|
||||
|
||||
auto company = ScriptCompany::ResolveCompanyID(company_id);
|
||||
::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company);
|
||||
return ScriptObject::DoCommand(0, industry_id, 2 | (((uint8)owner) << 16), CMD_INDUSTRY_CTRL);
|
||||
return ScriptObject::DoCommand(0, industry_id, ((uint8)owner), CMD_INDUSTRY_SET_EXCLUSIVITY);
|
||||
}
|
||||
|
@@ -84,7 +84,7 @@ public:
|
||||
/**
|
||||
* Set the custom text of an industry, shown in the GUI.
|
||||
* @param industry_id The industry to set the custom text of.
|
||||
* @param text The text to set it to (can be either a raw string, or a ScriptText object). If null is passed, the text will be removed.
|
||||
* @param text The text to set it to (can be either a raw string, or a ScriptText object). If null, or an empty string, is passed, the text will be removed.
|
||||
* @pre IsValidIndustry(industry_id).
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
|
@@ -218,20 +218,27 @@ public:
|
||||
* store the current configuration of Scripts. Required.
|
||||
* - description A single line describing the setting. Required.
|
||||
* - min_value The minimum value of this setting. Required for integer
|
||||
* settings and not allowed for boolean settings.
|
||||
* settings and not allowed for boolean settings. The value will be
|
||||
* clamped in the range [MIN(int32), MAX(int32)] (inclusive).
|
||||
* - max_value The maximum value of this setting. Required for integer
|
||||
* settings and not allowed for boolean settings.
|
||||
* settings and not allowed for boolean settings. The value will be
|
||||
* clamped in the range [MIN(int32), MAX(int32)] (inclusive).
|
||||
* - easy_value The default value if the easy difficulty level
|
||||
* is selected. Required.
|
||||
* is selected. Required. The value will be clamped in the range
|
||||
* [MIN(int32), MAX(int32)] (inclusive).
|
||||
* - medium_value The default value if the medium difficulty level
|
||||
* is selected. Required.
|
||||
* is selected. Required. The value will be clamped in the range
|
||||
* [MIN(int32), MAX(int32)] (inclusive).
|
||||
* - hard_value The default value if the hard difficulty level
|
||||
* is selected. Required.
|
||||
* is selected. Required. The value will be clamped in the range
|
||||
* [MIN(int32), MAX(int32)] (inclusive).
|
||||
* - custom_value The default value if the custom difficulty level
|
||||
* is selected. Required.
|
||||
* is selected. Required. The value will be clamped in the range
|
||||
* [MIN(int32), MAX(int32)] (inclusive).
|
||||
* - random_deviation If this property has a nonzero value, then the
|
||||
* actual value of the setting in game will be randomized in the range
|
||||
* [user_configured_value - random_deviation, user_configured_value + random_deviation] (inclusive).
|
||||
* random_deviation sign is ignored and the value is clamped in the range [0, MAX(int32)] (inclusive).
|
||||
* Not allowed if the CONFIG_RANDOM flag is set, otherwise optional.
|
||||
* - step_size The increase/decrease of the value every time the user
|
||||
* clicks one of the up/down arrow buttons. Optional, default is 1.
|
||||
@@ -247,13 +254,16 @@ public:
|
||||
* user will see the corresponding name.
|
||||
* @param setting_name The name of the setting.
|
||||
* @param value_names A table that maps values to names. The first
|
||||
* character of every identifier is ignored and the rest should
|
||||
* character of every identifier is ignored, the second character
|
||||
* could be '_' to indicate the value is negative, and the rest should
|
||||
* be an integer of the value you define a name for. The value
|
||||
* is a short description of that value.
|
||||
* To define labels for a setting named "competition_level" you could
|
||||
* for example call it like this:
|
||||
* AddLabels("competition_level", {_0 = "no competition", _1 = "some competition",
|
||||
* _2 = "a lot of competition"});
|
||||
* Another example, for a setting with a negative value:
|
||||
* AddLabels("amount", {__1 = "less than one", _0 = "none", _1 = "more than one"});
|
||||
*
|
||||
* @note This is a function provided by OpenTTD, you don't have to
|
||||
* include it in your Script but should just call it from GetSettings.
|
||||
|
@@ -33,13 +33,13 @@
|
||||
|
||||
EnforcePrecondition(LEAGUE_TABLE_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
EnforcePrecondition(LEAGUE_TABLE_INVALID, title != nullptr);
|
||||
const char *encoded_title = title->GetEncodedText();
|
||||
std::string encoded_title = title->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(LEAGUE_TABLE_INVALID, encoded_title);
|
||||
|
||||
LeagueTableCmdData data;
|
||||
data.title = encoded_title;
|
||||
data.header = header->GetEncodedText();
|
||||
data.footer = footer->GetEncodedText();
|
||||
data.title = std::move(encoded_title);
|
||||
if (header != nullptr) data.header = header->GetEncodedText();
|
||||
if (footer != nullptr) data.footer = footer->GetEncodedText();
|
||||
|
||||
if (!ScriptObject::DoCommandEx(0, 0, 0, 0, CMD_CREATE_LEAGUE_TABLE, nullptr, &data, &ScriptInstance::DoCommandReturnLeagueTableID)) return LEAGUE_TABLE_INVALID;
|
||||
|
||||
@@ -66,12 +66,11 @@
|
||||
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
|
||||
|
||||
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, text != nullptr);
|
||||
const char *encoded_text_ptr = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(LEAGUE_TABLE_ELEMENT_INVALID, encoded_text_ptr);
|
||||
std::string encoded_text = encoded_text_ptr; // save into string so GetEncodedText can reuse the internal buffer
|
||||
const std::string &encoded_text = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(LEAGUE_TABLE_ELEMENT_INVALID, encoded_text);
|
||||
|
||||
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, score != nullptr);
|
||||
const char *encoded_score = score->GetEncodedText();
|
||||
const std::string &encoded_score = score->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(LEAGUE_TABLE_ELEMENT_INVALID, encoded_score);
|
||||
|
||||
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, IsValidLink(Link((::LinkType)link_type, link_target)));
|
||||
@@ -98,7 +97,7 @@
|
||||
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
|
||||
|
||||
EnforcePrecondition(false, text != nullptr);
|
||||
const char *encoded_text = text->GetEncodedText();
|
||||
const std::string &encoded_text = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded_text);
|
||||
|
||||
EnforcePrecondition(false, IsValidLink(Link((::LinkType)link_type, link_target)));
|
||||
@@ -114,7 +113,7 @@
|
||||
EnforcePrecondition(false, IsValidLeagueTableElement(element));
|
||||
|
||||
EnforcePrecondition(false, score != nullptr);
|
||||
const char *encoded_score = score->GetEncodedText();
|
||||
const std::string &encoded_score = score->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded_score);
|
||||
|
||||
return ScriptObject::DoCommandEx(0, element, 0, rating, CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE, encoded_score);
|
||||
|
@@ -24,7 +24,7 @@
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
EnforcePrecondition(false, text != nullptr);
|
||||
const char *encoded = text->GetEncodedText();
|
||||
const std::string &encoded = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded);
|
||||
EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL);
|
||||
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
|
||||
|
@@ -86,9 +86,19 @@ protected:
|
||||
*/
|
||||
static bool DoCommandEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint cmd, const char *text = nullptr, const CommandAuxiliaryBase *aux_data = nullptr, Script_SuspendCallbackProc *callback = nullptr);
|
||||
|
||||
static bool DoCommandEx(TileIndex tile, uint32 p1, uint32 p2, uint64 p3, uint cmd, const std::string &text, const CommandAuxiliaryBase *aux_data = nullptr, Script_SuspendCallbackProc *callback = nullptr)
|
||||
{
|
||||
return ScriptObject::DoCommandEx(tile, p1, p2, p3, cmd, text.c_str(), aux_data, callback);
|
||||
}
|
||||
|
||||
static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = nullptr, Script_SuspendCallbackProc *callback = nullptr)
|
||||
{
|
||||
return ScriptObject::DoCommandEx(tile, p1, p2, 0, cmd, text, 0, callback);
|
||||
return ScriptObject::DoCommandEx(tile, p1, p2, 0, cmd, text, nullptr, callback);
|
||||
}
|
||||
|
||||
static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const std::string &text, Script_SuspendCallbackProc *callback = nullptr)
|
||||
{
|
||||
return ScriptObject::DoCommandEx(tile, p1, p2, 0, cmd, text.c_str(), nullptr, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -49,7 +49,7 @@ static OrderType GetOrderTypeByTile(TileIndex t)
|
||||
|
||||
/* static */ bool ScriptOrder::IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position)
|
||||
{
|
||||
return ScriptVehicle::IsValidVehicle(vehicle_id) && order_position >= 0 && (order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders() || order_position == ORDER_CURRENT);
|
||||
return ScriptVehicle::IsPrimaryVehicle(vehicle_id) && order_position >= 0 && (order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders() || order_position == ORDER_CURRENT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +162,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id)
|
||||
{
|
||||
if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return false;
|
||||
if (!ScriptVehicle::IsPrimaryVehicle(vehicle_id)) return false;
|
||||
if (GetOrderCount(vehicle_id) == 0) return false;
|
||||
|
||||
const Order *order = &::Vehicle::Get(vehicle_id)->current_order;
|
||||
@@ -172,7 +172,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ ScriptOrder::OrderPosition ScriptOrder::ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position)
|
||||
{
|
||||
if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return ORDER_INVALID;
|
||||
if (!ScriptVehicle::IsPrimaryVehicle(vehicle_id)) return ORDER_INVALID;
|
||||
|
||||
int num_manual_orders = ::Vehicle::Get(vehicle_id)->GetNumManualOrders();
|
||||
if (num_manual_orders == 0) return ORDER_INVALID;
|
||||
@@ -240,7 +240,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ int32 ScriptOrder::GetOrderCount(VehicleID vehicle_id)
|
||||
{
|
||||
return ScriptVehicle::IsValidVehicle(vehicle_id) ? ::Vehicle::Get(vehicle_id)->GetNumManualOrders() : -1;
|
||||
return ScriptVehicle::IsPrimaryVehicle(vehicle_id) ? ::Vehicle::Get(vehicle_id)->GetNumManualOrders() : -1;
|
||||
}
|
||||
|
||||
/* static */ TileIndex ScriptOrder::GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position)
|
||||
@@ -450,7 +450,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
|
||||
|
||||
return InsertOrder(vehicle_id, (ScriptOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumManualOrders(), destination, order_flags);
|
||||
@@ -458,7 +458,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
|
||||
/* static */ bool ScriptOrder::AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to));
|
||||
|
||||
return InsertConditionalOrder(vehicle_id, (ScriptOrder::OrderPosition)::Vehicle::Get(vehicle_id)->GetNumManualOrders(), jump_to);
|
||||
@@ -469,7 +469,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
/* IsValidVehicleOrder is not good enough because it does not allow appending. */
|
||||
if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
|
||||
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders());
|
||||
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
|
||||
|
||||
@@ -522,7 +522,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||
/* IsValidVehicleOrder is not good enough because it does not allow appending. */
|
||||
if (order_position == ORDER_CURRENT) order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
|
||||
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, order_position >= 0 && order_position <= ::Vehicle::Get(vehicle_id)->GetNumManualOrders());
|
||||
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
|
||||
|
||||
@@ -653,23 +653,23 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
|
||||
|
||||
/* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, vehicle_id | CO_COPY << 30, main_vehicle_id, CMD_CLONE_ORDER);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(main_vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, CMD_CLONE_ORDER);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, vehicle_id | CO_UNSHARE << 30, 0, CMD_CLONE_ORDER);
|
||||
}
|
||||
|
@@ -142,7 +142,7 @@ public:
|
||||
* Checks whether the given order id is valid for the given vehicle.
|
||||
* @param vehicle_id The vehicle to check the order index for.
|
||||
* @param order_position The order index to check.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @return True if and only if the order_position is valid for the given vehicle.
|
||||
*/
|
||||
static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
|
||||
@@ -207,7 +207,7 @@ public:
|
||||
/**
|
||||
* Checks whether the current order is part of the orderlist.
|
||||
* @param vehicle_id The vehicle to check.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @return True if and only if the current order is part of the order list.
|
||||
* @note If the order is a non-'non-stop' order, and the vehicle is currently
|
||||
* (un)loading at a station that is not the final destination, this function
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
* given index does not exist it will return ORDER_INVALID.
|
||||
* @param vehicle_id The vehicle to check the order index for.
|
||||
* @param order_position The order index to resolve.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @return The resolved order index.
|
||||
*/
|
||||
static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
|
||||
@@ -246,7 +246,7 @@ public:
|
||||
/**
|
||||
* Returns the number of orders for the given vehicle.
|
||||
* @param vehicle_id The vehicle to get the order count of.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @return The number of orders for the given vehicle or a negative
|
||||
* value when the vehicle does not exist.
|
||||
*/
|
||||
@@ -432,7 +432,7 @@ public:
|
||||
* @param vehicle_id The vehicle to append the order to.
|
||||
* @param destination The destination of the order.
|
||||
* @param order_flags The flags given to the order.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre AreOrderFlagsValid(destination, order_flags).
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
@@ -446,7 +446,7 @@ public:
|
||||
* Appends a conditional order to the end of the vehicle's order list.
|
||||
* @param vehicle_id The vehicle to append the order to.
|
||||
* @param jump_to The OrderPosition to jump to if the condition is true.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
@@ -461,6 +461,7 @@ public:
|
||||
* @param order_position The order to place the new order before.
|
||||
* @param destination The destination of the order.
|
||||
* @param order_flags The flags given to the order.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id)
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre AreOrderFlagsValid(destination, order_flags).
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
@@ -476,6 +477,7 @@ public:
|
||||
* @param vehicle_id The vehicle to add the order to.
|
||||
* @param order_position The order to place the new order before.
|
||||
* @param jump_to The OrderPosition to jump to if the condition is true.
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
||||
* @pre IsValidVehicleOrder(vehicle_id, jump_to).
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
@@ -550,8 +552,8 @@ public:
|
||||
* are going to be the orders of the changed vehicle.
|
||||
* @param vehicle_id The vehicle to copy the orders to.
|
||||
* @param main_vehicle_id The vehicle to copy the orders from.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsValidVehicle(main_vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_TOO_MANY
|
||||
* @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
|
||||
@@ -565,8 +567,8 @@ public:
|
||||
* vehicle are going to be the orders of the changed vehicle.
|
||||
* @param vehicle_id The vehicle to add to the shared order list.
|
||||
* @param main_vehicle_id The vehicle to share the orders with.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsValidVehicle(main_vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(main_vehicle_id).
|
||||
* @exception ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY
|
||||
* @exception ScriptOrder::ERR_ORDER_AIRCRAFT_NOT_ENOUGH_RANGE
|
||||
* @return True if and only if the sharing succeeded.
|
||||
@@ -578,7 +580,7 @@ public:
|
||||
* Removes the given vehicle from a shared orders list.
|
||||
* After unsharing orders, the orders list of the vehicle is empty.
|
||||
* @param vehicle_id The vehicle to remove from the shared order list.
|
||||
* @pre ScriptVehicle::IsValidVehicle(vehicle_id).
|
||||
* @pre ScriptVehicle::IsPrimaryVehicle(vehicle_id).
|
||||
* @return True if and only if the unsharing succeeded.
|
||||
* @api -game
|
||||
*/
|
||||
|
@@ -37,7 +37,7 @@
|
||||
|
||||
EnforcePrecondition(false, IsValidSign(sign_id));
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const char *text = name->GetDecodedText();
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
|
||||
EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location));
|
||||
EnforcePrecondition(INVALID_SIGN, name != nullptr);
|
||||
const char *text = name->GetDecodedText();
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(INVALID_SIGN, text);
|
||||
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
|
@@ -25,7 +25,7 @@ ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
|
||||
|
||||
ScriptStationList_Vehicle::ScriptStationList_Vehicle(VehicleID vehicle_id)
|
||||
{
|
||||
if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return;
|
||||
if (!ScriptVehicle::IsPrimaryVehicle(vehicle_id)) return;
|
||||
|
||||
Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
|
||||
|
@@ -51,7 +51,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
c,
|
||||
0,
|
||||
CMD_CREATE_STORY_PAGE,
|
||||
title != nullptr? title->GetEncodedText() : nullptr,
|
||||
title != nullptr ? title->GetEncodedText().c_str() : "",
|
||||
&ScriptInstance::DoCommandReturnStoryPageID)) return STORY_PAGE_INVALID;
|
||||
|
||||
/* In case of test-mode, we return StoryPageID 0 */
|
||||
@@ -66,7 +66,12 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
|
||||
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, IsValidStoryPage(story_page_id));
|
||||
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, !StoryPageElementTypeRequiresText(btype) || (text != nullptr && !StrEmpty(text->GetEncodedText())));
|
||||
std::string encoded_text;
|
||||
if (StoryPageElementTypeRequiresText(btype)) {
|
||||
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, text != nullptr);
|
||||
encoded_text = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(STORY_PAGE_ELEMENT_INVALID, encoded_text);
|
||||
}
|
||||
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_LOCATION || ::IsValidTile(reference));
|
||||
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || ScriptGoal::IsValidGoal((ScriptGoal::GoalID)reference));
|
||||
EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
|
||||
@@ -93,7 +98,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
story_page_id + (type << 16),
|
||||
refid,
|
||||
CMD_CREATE_STORY_PAGE_ELEMENT,
|
||||
StoryPageElementTypeRequiresText(btype) ? text->GetEncodedText() : nullptr,
|
||||
encoded_text,
|
||||
&ScriptInstance::DoCommandReturnStoryPageElementID)) return STORY_PAGE_ELEMENT_INVALID;
|
||||
|
||||
/* In case of test-mode, we return StoryPageElementID 0 */
|
||||
@@ -111,7 +116,12 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
StoryPage *p = StoryPage::Get(pe->page);
|
||||
::StoryPageElementType type = pe->type;
|
||||
|
||||
EnforcePrecondition(false, !StoryPageElementTypeRequiresText(type) || (text != nullptr && !StrEmpty(text->GetEncodedText())));
|
||||
std::string encoded_text;
|
||||
if (StoryPageElementTypeRequiresText(type)) {
|
||||
EnforcePrecondition(false, text != nullptr);
|
||||
encoded_text = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded_text);
|
||||
}
|
||||
EnforcePrecondition(false, type != ::SPET_LOCATION || ::IsValidTile(reference));
|
||||
EnforcePrecondition(false, type != ::SPET_GOAL || ScriptGoal::IsValidGoal((ScriptGoal::GoalID)reference));
|
||||
EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY));
|
||||
@@ -138,7 +148,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
story_page_element_id,
|
||||
refid,
|
||||
CMD_UPDATE_STORY_PAGE_ELEMENT,
|
||||
StoryPageElementTypeRequiresText(type) ? text->GetEncodedText() : nullptr);
|
||||
encoded_text);
|
||||
}
|
||||
|
||||
/* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id)
|
||||
@@ -162,7 +172,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
|
||||
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
|
||||
|
||||
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != nullptr? title->GetEncodedText() : nullptr);
|
||||
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != nullptr ? title->GetEncodedText().c_str() : "");
|
||||
}
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptStoryPage::GetCompany(StoryPageID story_page_id)
|
||||
|
@@ -11,21 +11,17 @@
|
||||
#include "../../string_func.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "script_text.hpp"
|
||||
#include "../script_fatalerror.hpp"
|
||||
#include "../../table/control_codes.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
RawText::RawText(const char *text) : text(stredup(text))
|
||||
RawText::RawText(const char *text) : text(text)
|
||||
{
|
||||
}
|
||||
|
||||
RawText::~RawText()
|
||||
{
|
||||
free(this->text);
|
||||
}
|
||||
|
||||
|
||||
ScriptText::ScriptText(HSQUIRRELVM vm) :
|
||||
string(STR_NULL), params(), parami(), paramt(), paramc(0)
|
||||
@@ -176,12 +172,13 @@ SQInteger ScriptText::_set(HSQUIRRELVM vm)
|
||||
return this->_SetParam(k, vm);
|
||||
}
|
||||
|
||||
const char *ScriptText::GetEncodedText()
|
||||
const std::string ScriptText::GetEncodedText()
|
||||
{
|
||||
static char buf[1024];
|
||||
int param_count = 0;
|
||||
this->_GetEncodedText(buf, lastof(buf), param_count);
|
||||
return (param_count > SCRIPT_TEXT_MAX_PARAMETERS) ? nullptr : buf;
|
||||
if (param_count > SCRIPT_TEXT_MAX_PARAMETERS) throw Script_FatalError("A string had too many parameters");
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
||||
@@ -206,10 +203,9 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count)
|
||||
return p;
|
||||
}
|
||||
|
||||
const char *Text::GetDecodedText()
|
||||
const std::string Text::GetDecodedText()
|
||||
{
|
||||
const char *encoded_text = this->GetEncodedText();
|
||||
if (encoded_text == nullptr) return nullptr;
|
||||
const std::string &encoded_text = this->GetEncodedText();
|
||||
|
||||
static char buf[1024];
|
||||
::SetDParamStr(0, encoded_text);
|
||||
|
@@ -21,17 +21,17 @@ class Text : public ScriptObject {
|
||||
public:
|
||||
/**
|
||||
* Convert a ScriptText to a normal string.
|
||||
* @return A string (in a static buffer), or nullptr.
|
||||
* @return A string.
|
||||
* @api -all
|
||||
*/
|
||||
virtual const char *GetEncodedText() = 0;
|
||||
virtual const std::string GetEncodedText() = 0;
|
||||
|
||||
/**
|
||||
* Convert a #ScriptText into a decoded normal string.
|
||||
* @return A string (in a static buffer), or nullptr.
|
||||
* @return A string.
|
||||
* @api -all
|
||||
*/
|
||||
const char *GetDecodedText();
|
||||
const std::string GetDecodedText();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -41,11 +41,10 @@ public:
|
||||
class RawText : public Text {
|
||||
public:
|
||||
RawText(const char *text);
|
||||
~RawText();
|
||||
|
||||
const char *GetEncodedText() override { return this->text; }
|
||||
const std::string GetEncodedText() override { return this->text; }
|
||||
private:
|
||||
const char *text;
|
||||
const std::string text;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -125,7 +124,7 @@ public:
|
||||
/**
|
||||
* @api -all
|
||||
*/
|
||||
virtual const char *GetEncodedText();
|
||||
virtual const std::string GetEncodedText();
|
||||
|
||||
private:
|
||||
StringID string;
|
||||
|
@@ -44,13 +44,12 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
const char *text = nullptr;
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
std::string text;
|
||||
if (name != nullptr) {
|
||||
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);
|
||||
}
|
||||
@@ -59,14 +58,9 @@
|
||||
{
|
||||
CCountedPtr<Text> counter(text);
|
||||
|
||||
const char *encoded_text = nullptr;
|
||||
if (text != nullptr) {
|
||||
encoded_text = text->GetEncodedText();
|
||||
EnforcePreconditionEncodedText(false, encoded_text);
|
||||
}
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, encoded_text);
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, text != nullptr ? text->GetEncodedText().c_str() : "");
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptTown::GetPopulation(TownID town_id)
|
||||
@@ -296,10 +290,9 @@
|
||||
layout = (RoadLayout) (byte)_settings_game.economy.town_layout;
|
||||
}
|
||||
|
||||
const char *text = nullptr;
|
||||
std::string text;
|
||||
if (name != nullptr) {
|
||||
text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
}
|
||||
uint32 townnameparts;
|
||||
@@ -309,7 +302,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
return ScriptObject::DoCommand(tile, size | (city ? 1 << 2 : 0) | layout << 3, townnameparts, CMD_FOUND_TOWN, text);
|
||||
return ScriptObject::DoCommand(tile, size | (city ? 1 << 2 : 0) | layout << 3, townnameparts, CMD_FOUND_TOWN, text.c_str());
|
||||
}
|
||||
|
||||
/* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id)
|
||||
|
@@ -147,7 +147,7 @@ public:
|
||||
/**
|
||||
* Rename a town.
|
||||
* @param town_id The town to rename
|
||||
* @param name The new name of the town. If null is passed, the town name will be reset to the default name.
|
||||
* @param name The new name of the town. If null, or an empty string, is passed, the town name will be reset to the default name.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
@@ -157,7 +157,7 @@ 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 (can be either a raw string, or a ScriptText object). If null is passed, the text will be removed.
|
||||
* @param text The text to set it to (can be either a raw string, or a ScriptText object). If null, or an empty string, is passed, the text will be removed.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
@@ -401,7 +401,7 @@ public:
|
||||
* @param size The town size of the new town.
|
||||
* @param city True if the new town should be a city.
|
||||
* @param layout The town layout of the new town.
|
||||
* @param name The name of the new town. Pass null to use a random town name.
|
||||
* @param name The name of the new town. Pass null, or an empty string, to use a random town name.
|
||||
* @game @pre no company mode in scope || ScriptSettings.GetValue("economy.found_town") != 0.
|
||||
* @ai @pre ScriptSettings.GetValue("economy.found_town") != 0.
|
||||
* @game @pre no company mode in scope || size != TOWN_SIZE_LARGE.
|
||||
|
@@ -31,6 +31,13 @@
|
||||
return v != nullptr && (v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptVehicle::IsPrimaryVehicle(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return false;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->IsPrimaryVehicle();
|
||||
}
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptVehicle::GetOwner(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return ScriptCompany::COMPANY_INVALID;
|
||||
@@ -101,7 +108,7 @@
|
||||
/* static */ VehicleID ScriptVehicle::CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
if (!ScriptObject::DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE, nullptr, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
|
||||
|
||||
@@ -190,7 +197,7 @@
|
||||
/* static */ bool ScriptVehicle::SendVehicleToDepot(VehicleID vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, vehicle_id, 0, GetCmdSendToDepot(::Vehicle::Get(vehicle_id)));
|
||||
}
|
||||
@@ -198,7 +205,7 @@
|
||||
/* static */ bool ScriptVehicle::SendVehicleToDepotForServicing(VehicleID vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, vehicle_id | DEPOT_SERVICE, 0, GetCmdSendToDepot(::Vehicle::Get(vehicle_id)));
|
||||
}
|
||||
@@ -218,7 +225,7 @@
|
||||
/* static */ bool ScriptVehicle::StartStopVehicle(VehicleID vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
|
||||
|
||||
return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_VEHICLE);
|
||||
}
|
||||
@@ -226,7 +233,7 @@
|
||||
/* static */ bool ScriptVehicle::ReverseVehicle(VehicleID vehicle_id)
|
||||
{
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_ROAD || ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN);
|
||||
|
||||
switch (::Vehicle::Get(vehicle_id)->type) {
|
||||
@@ -241,9 +248,9 @@
|
||||
CCountedPtr<Text> counter(name);
|
||||
|
||||
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
|
||||
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, IsPrimaryVehicle(vehicle_id));
|
||||
EnforcePrecondition(false, name != nullptr);
|
||||
const char *text = name->GetDecodedText();
|
||||
const std::string &text = name->GetDecodedText();
|
||||
EnforcePreconditionEncodedText(false, text);
|
||||
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
|
||||
|
||||
@@ -285,14 +292,14 @@
|
||||
|
||||
/* static */ int32 ScriptVehicle::GetUnitNumber(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->unitnumber;
|
||||
}
|
||||
|
||||
/* static */ char *ScriptVehicle::GetName(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return nullptr;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return nullptr;
|
||||
|
||||
::SetDParam(0, vehicle_id);
|
||||
return GetString(STR_VEHICLE_NAME);
|
||||
@@ -319,21 +326,21 @@
|
||||
|
||||
/* static */ int32 ScriptVehicle::GetMaxAge(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->max_age;
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptVehicle::GetAgeLeft(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age;
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
const ::Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
return (v->vehstatus & (::VS_STOPPED | ::VS_CRASHED)) == 0 ? v->GetDisplaySpeed() : 0; // km-ish/h
|
||||
@@ -356,21 +363,21 @@
|
||||
|
||||
/* static */ Money ScriptVehicle::GetRunningCost(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->GetRunningCost() >> 8;
|
||||
}
|
||||
|
||||
/* static */ Money ScriptVehicle::GetProfitThisYear(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->GetDisplayProfitThisYear();
|
||||
}
|
||||
|
||||
/* static */ Money ScriptVehicle::GetProfitLastYear(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->GetDisplayProfitLastYear();
|
||||
}
|
||||
@@ -431,7 +438,7 @@
|
||||
|
||||
/* static */ GroupID ScriptVehicle::GetGroupID(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return ScriptGroup::GROUP_INVALID;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return ScriptGroup::GROUP_INVALID;
|
||||
|
||||
return ::Vehicle::Get(vehicle_id)->group_id;
|
||||
}
|
||||
@@ -451,7 +458,7 @@
|
||||
|
||||
/* static */ bool ScriptVehicle::HasSharedOrders(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return false;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return false;
|
||||
|
||||
Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
return v->orders != nullptr && v->orders->GetNumVehicles() > 1;
|
||||
@@ -459,7 +466,7 @@
|
||||
|
||||
/* static */ int ScriptVehicle::GetReliability(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return -1;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return -1;
|
||||
|
||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
return ::ToPercent16(v->reliability);
|
||||
@@ -467,7 +474,7 @@
|
||||
|
||||
/* static */ uint ScriptVehicle::GetMaximumOrderDistance(VehicleID vehicle_id)
|
||||
{
|
||||
if (!IsValidVehicle(vehicle_id)) return 0;
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return 0;
|
||||
|
||||
const ::Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
switch (v->type) {
|
||||
|
@@ -97,9 +97,20 @@ public:
|
||||
* Checks whether the given vehicle is valid and owned by you.
|
||||
* @param vehicle_id The vehicle to check.
|
||||
* @return True if and only if the vehicle is valid.
|
||||
* @note Also returns true when the leading part of the vehicle is a wagon.
|
||||
* Use IsPrimaryVehicle() to check for a valid vehicle with a leading engine.
|
||||
*/
|
||||
static bool IsValidVehicle(VehicleID vehicle_id);
|
||||
|
||||
/**
|
||||
* Checks whether this is a primary vehicle.
|
||||
* @param vehicle_id The vehicle to check.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @return True if the vehicle is a primary vehicle.
|
||||
* @note Returns false when the leading part of the vehicle is a wagon.
|
||||
*/
|
||||
static bool IsPrimaryVehicle(VehicleID vehicle_id);
|
||||
|
||||
/**
|
||||
* Get the number of wagons a vehicle has.
|
||||
* @param vehicle_id The vehicle to get the number of wagons from.
|
||||
@@ -112,7 +123,7 @@ public:
|
||||
* Set the name of a vehicle.
|
||||
* @param vehicle_id The vehicle to set the name for.
|
||||
* @param name The name for the vehicle (can be either a raw string, or a ScriptText object).
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @pre name != null && len(name) != 0.
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
|
||||
@@ -123,7 +134,7 @@ public:
|
||||
/**
|
||||
* Get the name of a vehicle.
|
||||
* @param vehicle_id The vehicle to get the name of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The name the vehicle has.
|
||||
*/
|
||||
static char *GetName(VehicleID vehicle_id);
|
||||
@@ -166,7 +177,7 @@ public:
|
||||
/**
|
||||
* Get the unitnumber of a vehicle.
|
||||
* @param vehicle_id The vehicle to get the unitnumber of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The unitnumber the vehicle has.
|
||||
*/
|
||||
static int32 GetUnitNumber(VehicleID vehicle_id);
|
||||
@@ -194,7 +205,7 @@ public:
|
||||
/**
|
||||
* Get the maximum age of a vehicle.
|
||||
* @param vehicle_id The vehicle to get the age of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The maximum age the vehicle has.
|
||||
* @note The age is in days.
|
||||
*/
|
||||
@@ -203,7 +214,7 @@ public:
|
||||
/**
|
||||
* Get the age a vehicle has left (maximum - current).
|
||||
* @param vehicle_id The vehicle to get the age of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The age the vehicle has left.
|
||||
* @note The age is in days.
|
||||
*/
|
||||
@@ -212,7 +223,7 @@ public:
|
||||
/**
|
||||
* Get the current speed of a vehicle.
|
||||
* @param vehicle_id The vehicle to get the speed of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The current speed of the vehicle.
|
||||
* @note The speed is in OpenTTD's internal speed unit.
|
||||
* This is mph / 1.6, which is roughly km/h.
|
||||
@@ -231,7 +242,7 @@ public:
|
||||
/**
|
||||
* Get the running cost of this vehicle.
|
||||
* @param vehicle_id The vehicle to get the running cost of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The running cost of the vehicle per year.
|
||||
* @note Cost is per year; divide by 365 to get per day.
|
||||
* @note This is not equal to ScriptEngine::GetRunningCost for Trains, because
|
||||
@@ -242,7 +253,7 @@ public:
|
||||
/**
|
||||
* Get the current profit of a vehicle.
|
||||
* @param vehicle_id The vehicle to get the profit of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The current profit the vehicle has.
|
||||
*/
|
||||
static Money GetProfitThisYear(VehicleID vehicle_id);
|
||||
@@ -250,7 +261,7 @@ public:
|
||||
/**
|
||||
* Get the profit of last year of a vehicle.
|
||||
* @param vehicle_id The vehicle to get the profit of.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The profit the vehicle had last year.
|
||||
*/
|
||||
static Money GetProfitLastYear(VehicleID vehicle_id);
|
||||
@@ -363,7 +374,7 @@ public:
|
||||
* @param vehicle_id The vehicle to use as example for the new vehicle.
|
||||
* @param share_orders Should the orders be copied or shared?
|
||||
* @pre The tile 'depot' has a depot on it, allowing 'vehicle_id'-type vehicles.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_TOO_MANY
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED
|
||||
@@ -481,7 +492,7 @@ public:
|
||||
* Sends the given vehicle to a depot. If the vehicle has already been
|
||||
* sent to a depot it continues with its normal orders instead.
|
||||
* @param vehicle_id The vehicle to send to a depot.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
|
||||
* @return True if the current order was changed.
|
||||
@@ -492,7 +503,7 @@ public:
|
||||
* Sends the given vehicle to a depot for servicing. If the vehicle has
|
||||
* already been sent to a depot it continues with its normal orders instead.
|
||||
* @param vehicle_id The vehicle to send to a depot for servicing.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_CANNOT_SEND_TO_DEPOT
|
||||
* @return True if the current order was changed.
|
||||
@@ -502,7 +513,7 @@ public:
|
||||
/**
|
||||
* Starts or stops the given vehicle depending on the current state.
|
||||
* @param vehicle_id The vehicle to start/stop.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @exception ScriptVehicle::ERR_VEHICLE_CANNOT_START_STOP
|
||||
* @exception (For aircraft only): ScriptVehicle::ERR_VEHICLE_IN_FLIGHT
|
||||
@@ -514,7 +525,7 @@ public:
|
||||
/**
|
||||
* Turn the given vehicle so it'll drive the other way.
|
||||
* @param vehicle_id The vehicle to turn.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @pre GetVehicleType(vehicle_id) == VT_ROAD || GetVehicleType(vehicle_id) == VT_RAIL.
|
||||
* @game @pre Valid ScriptCompanyMode active in scope.
|
||||
* @return True if and only if the vehicle has started to turn.
|
||||
@@ -555,6 +566,7 @@ public:
|
||||
/**
|
||||
* Get the group of a given vehicle.
|
||||
* @param vehicle_id The vehicle to get the group from.
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The group of the given vehicle.
|
||||
*/
|
||||
static GroupID GetGroupID(VehicleID vehicle_id);
|
||||
@@ -571,7 +583,7 @@ public:
|
||||
/**
|
||||
* Check if the vehicle has shared orders.
|
||||
* @param vehicle_id The vehicle to check.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return True if the vehicle has shared orders.
|
||||
*/
|
||||
static bool HasSharedOrders(VehicleID vehicle_id);
|
||||
@@ -579,7 +591,7 @@ public:
|
||||
/**
|
||||
* Get the current reliability of a vehicle.
|
||||
* @param vehicle_id The vehicle to check.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The current reliability (0-100%).
|
||||
*/
|
||||
static int GetReliability(VehicleID vehicle_id);
|
||||
@@ -590,7 +602,7 @@ public:
|
||||
* map distances, you may use the result of this function to compare it
|
||||
* with the result of ScriptOrder::GetOrderDistance.
|
||||
* @param vehicle_id The vehicle to get the distance for.
|
||||
* @pre IsValidVehicle(vehicle_id).
|
||||
* @pre IsPrimaryVehicle(vehicle_id).
|
||||
* @return The maximum distance between two orders for this vehicle
|
||||
* or 0 if the distance is unlimited.
|
||||
* @note The unit of the order distances is unspecified and should
|
||||
|
@@ -91,7 +91,7 @@ ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile)
|
||||
|
||||
ScriptVehicleList_SharedOrders::ScriptVehicleList_SharedOrders(VehicleID vehicle_id)
|
||||
{
|
||||
if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return;
|
||||
if (!ScriptVehicle::IsPrimaryVehicle(vehicle_id)) return;
|
||||
|
||||
for (const Vehicle *v = Vehicle::Get(vehicle_id)->FirstShared(); v != nullptr; v = v->NextShared()) {
|
||||
this->AddItem(v->index);
|
||||
|
@@ -25,7 +25,7 @@ ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_typ
|
||||
|
||||
ScriptWaypointList_Vehicle::ScriptWaypointList_Vehicle(VehicleID vehicle_id)
|
||||
{
|
||||
if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return;
|
||||
if (!ScriptVehicle::IsPrimaryVehicle(vehicle_id)) return;
|
||||
|
||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
|
||||
|
Reference in New Issue
Block a user