From 218f40eea2227dddb2e3475f4f89d08ffd5c9c6f Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 9 Jan 2021 15:15:14 +0100 Subject: Add: [Script] ScriptCargo::GetName, to get the human readable name of a cargo (#8544) Of course this translates into AICargo.GetName() for AIs and GSCargo.GetName() for GameScripts. --- src/script/api/script_cargo.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/script/api/script_cargo.cpp') diff --git a/src/script/api/script_cargo.cpp b/src/script/api/script_cargo.cpp index 67cbc1930..6b0a4aa7a 100644 --- a/src/script/api/script_cargo.cpp +++ b/src/script/api/script_cargo.cpp @@ -11,7 +11,9 @@ #include "script_cargo.hpp" #include "../../economy_func.h" #include "../../core/bitmath_func.hpp" +#include "../../strings_func.h" #include "../../settings_type.h" +#include "table/strings.h" #include "../../safeguards.h" @@ -25,6 +27,14 @@ return (towneffect_type >= (TownEffect)TE_BEGIN && towneffect_type < (TownEffect)TE_END); } +/* static */ char *ScriptCargo::GetName(CargoID cargo_type) +{ + if (!IsValidCargo(cargo_type)) return nullptr; + + ::SetDParam(0, 1 << cargo_type); + return GetString(STR_JUST_CARGO_LIST); +} + /* static */ char *ScriptCargo::GetCargoLabel(CargoID cargo_type) { if (!IsValidCargo(cargo_type)) return nullptr; -- cgit v1.2.3-54-g00ecf