mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use GetString() with local parameters in script functions. (#13585)
parent
fd4adc55e3
commit
154896ce55
|
@ -31,8 +31,7 @@
|
|||
{
|
||||
if (!IsValidBaseStation(station_id)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, station_id);
|
||||
return GetString(::Station::IsValidID(station_id) ? STR_STATION_NAME : STR_WAYPOINT_NAME);
|
||||
return ::StrMakeValid(::GetString(::Station::IsValidID(station_id) ? STR_STATION_NAME : STR_WAYPOINT_NAME, station_id));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptBaseStation::SetName(StationID station_id, Text *name)
|
||||
|
|
|
@ -134,7 +134,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
|
|||
EnforcePrecondition(std::nullopt, vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_WATER);
|
||||
if (!IsValidBridge(bridge_type)) return std::nullopt;
|
||||
|
||||
return GetString(vehicle_type == ScriptVehicle::VT_WATER ? STR_LAI_BRIDGE_DESCRIPTION_AQUEDUCT : ::GetBridgeSpec(bridge_type)->transport_name[vehicle_type]);
|
||||
return ::StrMakeValid(::GetString(vehicle_type == ScriptVehicle::VT_WATER ? STR_LAI_BRIDGE_DESCRIPTION_AQUEDUCT : ::GetBridgeSpec(bridge_type)->transport_name[vehicle_type]));
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptBridge::GetMaxSpeed(BridgeType bridge_type)
|
||||
|
|
|
@ -32,8 +32,7 @@
|
|||
{
|
||||
if (!IsValidCargo(cargo_type)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, 1ULL << cargo_type);
|
||||
return GetString(STR_JUST_CARGO_LIST);
|
||||
return ::StrMakeValid(::GetString(STR_JUST_CARGO_LIST, 1ULL << cargo_type));
|
||||
}
|
||||
|
||||
/* static */ std::optional<std::string> ScriptCargo::GetCargoLabel(CargoType cargo_type)
|
||||
|
|
|
@ -77,8 +77,7 @@
|
|||
company = ResolveCompanyID(company);
|
||||
if (company == ScriptCompany::COMPANY_INVALID) return std::nullopt;
|
||||
|
||||
::SetDParam(0, ScriptCompany::FromScriptCompanyID(company));
|
||||
return GetString(STR_COMPANY_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_COMPANY_NAME, ScriptCompany::FromScriptCompanyID(company)));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompany::SetPresidentName(Text *name)
|
||||
|
@ -99,8 +98,7 @@
|
|||
company = ResolveCompanyID(company);
|
||||
if (company == ScriptCompany::COMPANY_INVALID) return std::nullopt;
|
||||
|
||||
::SetDParam(0, ScriptCompany::FromScriptCompanyID(company));
|
||||
return GetString(STR_PRESIDENT_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_PRESIDENT_NAME, ScriptCompany::FromScriptCompanyID(company)));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptCompany::SetPresidentGender(Gender gender)
|
||||
|
|
|
@ -46,8 +46,7 @@
|
|||
{
|
||||
if (!IsValidEngine(engine_id)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, engine_id);
|
||||
return GetString(STR_ENGINE_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_ENGINE_NAME, engine_id));
|
||||
}
|
||||
|
||||
/* static */ CargoType ScriptEngine::GetCargoType(EngineID engine_id)
|
||||
|
|
|
@ -33,8 +33,7 @@ std::optional<std::string> ScriptEventEnginePreview::GetName()
|
|||
{
|
||||
if (!this->IsEngineValid()) return std::nullopt;
|
||||
|
||||
::SetDParam(0, this->engine);
|
||||
return GetString(STR_ENGINE_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_ENGINE_NAME, this->engine));
|
||||
}
|
||||
|
||||
CargoType ScriptEventEnginePreview::GetCargoType()
|
||||
|
|
|
@ -72,8 +72,7 @@
|
|||
{
|
||||
if (!IsValidGroup(group_id)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, group_id);
|
||||
return GetString(STR_GROUP_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_GROUP_NAME, group_id));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGroup::SetParent(GroupID group_id, GroupID parent_group_id)
|
||||
|
|
|
@ -45,8 +45,7 @@
|
|||
{
|
||||
if (!IsValidIndustry(industry_id)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, industry_id);
|
||||
return GetString(STR_INDUSTRY_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_INDUSTRY_NAME, industry_id));
|
||||
}
|
||||
|
||||
/* static */ ScriptDate::Date ScriptIndustry::GetConstructionDate(IndustryID industry_id)
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
{
|
||||
if (!IsValidIndustryType(industry_type)) return std::nullopt;
|
||||
|
||||
return GetString(::GetIndustrySpec(industry_type)->name);
|
||||
return ::StrMakeValid(::GetString(::GetIndustrySpec(industry_type)->name));
|
||||
}
|
||||
|
||||
/* static */ ScriptList *ScriptIndustryType::GetProducedCargo(IndustryType industry_type)
|
||||
|
|
|
@ -249,11 +249,6 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
|||
return GetStorage()->log_data;
|
||||
}
|
||||
|
||||
/* static */ std::string ScriptObject::GetString(StringID string)
|
||||
{
|
||||
return ::StrMakeValid(::GetString(string));
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetCallbackVariable(int index, int value)
|
||||
{
|
||||
if (static_cast<size_t>(index) >= GetStorage()->callback_value.size()) GetStorage()->callback_value.resize(index + 1);
|
||||
|
|
|
@ -320,11 +320,6 @@ protected:
|
|||
*/
|
||||
static ScriptLogTypes::LogData &GetLogData();
|
||||
|
||||
/**
|
||||
* Get an allocated string with all control codes stripped off.
|
||||
*/
|
||||
static std::string GetString(StringID string);
|
||||
|
||||
private:
|
||||
/* Helper functions for DoCommand. */
|
||||
static std::tuple<bool, bool, bool, bool> DoCommandPrep();
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "script_error.hpp"
|
||||
#include "script_map.hpp"
|
||||
#include "../../object_cmd.h"
|
||||
#include "../../strings_func.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
|
@ -27,7 +28,7 @@
|
|||
{
|
||||
EnforcePrecondition(std::nullopt, IsValidObjectType(object_type));
|
||||
|
||||
return GetString(ObjectSpec::Get(object_type)->name);
|
||||
return ::StrMakeValid(::GetString(ObjectSpec::Get(object_type)->name));
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptObjectType::GetViews(ObjectType object_type)
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
{
|
||||
if (!IsRailTypeAvailable(rail_type)) return std::nullopt;
|
||||
|
||||
return GetString(GetRailTypeInfo((::RailType)rail_type)->strings.menu_text);
|
||||
return ::StrMakeValid(::GetString(GetRailTypeInfo((::RailType)rail_type)->strings.menu_text));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptRail::IsRailTile(TileIndex tile)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "../../landscape_cmd.h"
|
||||
#include "../../road_cmd.h"
|
||||
#include "../../station_cmd.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "../../newgrf_roadstop.h"
|
||||
#include "../../script/squirrel_helper_type.hpp"
|
||||
|
||||
|
@ -29,7 +30,7 @@
|
|||
{
|
||||
if (!IsRoadTypeAvailable(road_type)) return std::nullopt;
|
||||
|
||||
return GetString(GetRoadTypeInfo((::RoadType)road_type)->strings.name);
|
||||
return ::StrMakeValid(::GetString(GetRoadTypeInfo((::RoadType)road_type)->strings.name));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptRoad::IsRoadTile(TileIndex tile)
|
||||
|
|
|
@ -51,8 +51,7 @@
|
|||
{
|
||||
if (!IsValidSign(sign_id)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, sign_id);
|
||||
return GetString(STR_SIGN_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_SIGN_NAME, sign_id));
|
||||
}
|
||||
|
||||
/* static */ TileIndex ScriptSign::GetLocation(SignID sign_id)
|
||||
|
|
|
@ -298,6 +298,5 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
|
|||
|
||||
const std::string Text::GetDecodedText()
|
||||
{
|
||||
::SetDParamStr(0, this->GetEncodedText());
|
||||
return ::GetString(STR_JUST_RAW_STRING);
|
||||
return ::GetString(STR_JUST_RAW_STRING, this->GetEncodedText());
|
||||
}
|
||||
|
|
|
@ -36,8 +36,7 @@
|
|||
{
|
||||
if (!IsValidTown(town_id)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, town_id);
|
||||
return GetString(STR_TOWN_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_TOWN_NAME, town_id));
|
||||
}
|
||||
|
||||
/* static */ bool ScriptTown::SetName(TownID town_id, Text *name)
|
||||
|
|
|
@ -303,8 +303,7 @@
|
|||
{
|
||||
if (!IsPrimaryVehicle(vehicle_id)) return std::nullopt;
|
||||
|
||||
::SetDParam(0, vehicle_id);
|
||||
return GetString(STR_VEHICLE_NAME);
|
||||
return ::StrMakeValid(::GetString(STR_VEHICLE_NAME, vehicle_id));
|
||||
}
|
||||
|
||||
/* static */ SQInteger ScriptVehicle::GetAge(VehicleID vehicle_id)
|
||||
|
|
Loading…
Reference in New Issue