summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-01-09 15:15:14 +0100
committerGitHub <noreply@github.com>2021-01-09 15:15:14 +0100
commit218f40eea2227dddb2e3475f4f89d08ffd5c9c6f (patch)
tree444fda7b347d1d1651efa2a36251e2867cb3708f /src/script
parent3dbdb1c7e3d5b7561d87d2cf891809324064bc1c (diff)
downloadopenttd-218f40eea2227dddb2e3475f4f89d08ffd5c9c6f.tar.xz
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.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/ai_changelog.hpp1
-rw-r--r--src/script/api/game_changelog.hpp1
-rw-r--r--src/script/api/script_cargo.cpp10
-rw-r--r--src/script/api/script_cargo.hpp8
4 files changed, 20 insertions, 0 deletions
diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp
index a579bb27b..5d5d5c26f 100644
--- a/src/script/api/ai_changelog.hpp
+++ b/src/script/api/ai_changelog.hpp
@@ -18,6 +18,7 @@
* This version is not yet released. The following changes are not set in stone yet.
*
* API additions:
+ * \li AICargo::GetName
* \li AIPriorityQueue
*
* \b 1.10.0
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 1f43cdea1..cbb862f1c 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -18,6 +18,7 @@
* This version is not yet released. The following changes are not set in stone yet.
*
* API additions:
+ * \li GSCargo::GetName
* \li GSEventStoryPageButtonClick
* \li GSEventStoryPageTileSelect
* \li GSEventStoryPageVehicleSelect
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;
diff --git a/src/script/api/script_cargo.hpp b/src/script/api/script_cargo.hpp
index 9ecd4cbfb..1bfd8c553 100644
--- a/src/script/api/script_cargo.hpp
+++ b/src/script/api/script_cargo.hpp
@@ -85,6 +85,14 @@ public:
static bool IsValidTownEffect(TownEffect towneffect_type);
/**
+ * Get the name of the cargo type.
+ * @param cargo_type The cargo type to get the name of.
+ * @pre IsValidCargo(cargo_type).
+ * @return The name of the cargo type.
+ */
+ static char *GetName(CargoID cargo_type);
+
+ /**
* Gets the string representation of the cargo label.
* @param cargo_type The cargo to get the string representation of.
* @pre ScriptCargo::IsValidCargo(cargo_type).