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.
pull/217/head
Patric Stout 3 years ago committed by GitHub
parent 3dbdb1c7e3
commit 218f40eea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -332,7 +332,8 @@ function Regression::Cargo()
for (local i = -1; i < 15; i++) { for (local i = -1; i < 15; i++) {
print(" Cargo " + i); print(" Cargo " + i);
print(" IsValidCargo(): " + AICargo.IsValidCargo(i)); print(" IsValidCargo(): " + AICargo.IsValidCargo(i));
print(" GetCargoLabel(): '" + AICargo.GetCargoLabel(i)+ "'"); print(" GetName(): '" + AICargo.GetName(i) + "'");
print(" GetCargoLabel(): '" + AICargo.GetCargoLabel(i) + "'");
print(" IsFreight(): " + AICargo.IsFreight(i)); print(" IsFreight(): " + AICargo.IsFreight(i));
print(" HasCargoClass(): " + AICargo.HasCargoClass(i, AICargo.CC_PASSENGERS)); print(" HasCargoClass(): " + AICargo.HasCargoClass(i, AICargo.CC_PASSENGERS));
print(" GetTownEffect(): " + AICargo.GetTownEffect(i)); print(" GetTownEffect(): " + AICargo.GetTownEffect(i));

@ -1109,6 +1109,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
--AICargo-- --AICargo--
Cargo -1 Cargo -1
IsValidCargo(): false IsValidCargo(): false
GetName(): '(null : 0x00000000)'
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false IsFreight(): false
HasCargoClass(): false HasCargoClass(): false
@ -1120,6 +1121,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 0 Cargo 0
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Passengers'
GetCargoLabel(): 'PASS' GetCargoLabel(): 'PASS'
IsFreight(): false IsFreight(): false
HasCargoClass(): true HasCargoClass(): true
@ -1131,6 +1133,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 0 GetRoadVehicleTypeForCargo(): 0
Cargo 1 Cargo 1
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Coal'
GetCargoLabel(): 'COAL' GetCargoLabel(): 'COAL'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1142,6 +1145,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 2 Cargo 2
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Mail'
GetCargoLabel(): 'MAIL' GetCargoLabel(): 'MAIL'
IsFreight(): false IsFreight(): false
HasCargoClass(): false HasCargoClass(): false
@ -1153,6 +1157,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 3 Cargo 3
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Oil'
GetCargoLabel(): 'OIL_' GetCargoLabel(): 'OIL_'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1164,6 +1169,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 4 Cargo 4
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Livestock'
GetCargoLabel(): 'LVST' GetCargoLabel(): 'LVST'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1175,6 +1181,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 5 Cargo 5
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Goods'
GetCargoLabel(): 'GOOD' GetCargoLabel(): 'GOOD'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1186,6 +1193,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 6 Cargo 6
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Grain'
GetCargoLabel(): 'GRAI' GetCargoLabel(): 'GRAI'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1197,6 +1205,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 7 Cargo 7
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Wood'
GetCargoLabel(): 'WOOD' GetCargoLabel(): 'WOOD'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1208,6 +1217,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 8 Cargo 8
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Iron Ore'
GetCargoLabel(): 'IORE' GetCargoLabel(): 'IORE'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1219,6 +1229,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 9 Cargo 9
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Steel'
GetCargoLabel(): 'STEL' GetCargoLabel(): 'STEL'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1230,6 +1241,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 10 Cargo 10
IsValidCargo(): true IsValidCargo(): true
GetName(): 'Valuables'
GetCargoLabel(): 'VALU' GetCargoLabel(): 'VALU'
IsFreight(): true IsFreight(): true
HasCargoClass(): false HasCargoClass(): false
@ -1241,6 +1253,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 11 Cargo 11
IsValidCargo(): false IsValidCargo(): false
GetName(): '(null : 0x00000000)'
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false IsFreight(): false
HasCargoClass(): false HasCargoClass(): false
@ -1252,6 +1265,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 12 Cargo 12
IsValidCargo(): false IsValidCargo(): false
GetName(): '(null : 0x00000000)'
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false IsFreight(): false
HasCargoClass(): false HasCargoClass(): false
@ -1263,6 +1277,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 13 Cargo 13
IsValidCargo(): false IsValidCargo(): false
GetName(): '(null : 0x00000000)'
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false IsFreight(): false
HasCargoClass(): false HasCargoClass(): false
@ -1274,6 +1289,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetRoadVehicleTypeForCargo(): 1 GetRoadVehicleTypeForCargo(): 1
Cargo 14 Cargo 14
IsValidCargo(): false IsValidCargo(): false
GetName(): '(null : 0x00000000)'
GetCargoLabel(): '(null : 0x00000000)' GetCargoLabel(): '(null : 0x00000000)'
IsFreight(): false IsFreight(): false
HasCargoClass(): false HasCargoClass(): false

@ -18,6 +18,7 @@
* This version is not yet released. The following changes are not set in stone yet. * This version is not yet released. The following changes are not set in stone yet.
* *
* API additions: * API additions:
* \li AICargo::GetName
* \li AIPriorityQueue * \li AIPriorityQueue
* *
* \b 1.10.0 * \b 1.10.0

@ -18,6 +18,7 @@
* This version is not yet released. The following changes are not set in stone yet. * This version is not yet released. The following changes are not set in stone yet.
* *
* API additions: * API additions:
* \li GSCargo::GetName
* \li GSEventStoryPageButtonClick * \li GSEventStoryPageButtonClick
* \li GSEventStoryPageTileSelect * \li GSEventStoryPageTileSelect
* \li GSEventStoryPageVehicleSelect * \li GSEventStoryPageVehicleSelect

@ -11,7 +11,9 @@
#include "script_cargo.hpp" #include "script_cargo.hpp"
#include "../../economy_func.h" #include "../../economy_func.h"
#include "../../core/bitmath_func.hpp" #include "../../core/bitmath_func.hpp"
#include "../../strings_func.h"
#include "../../settings_type.h" #include "../../settings_type.h"
#include "table/strings.h"
#include "../../safeguards.h" #include "../../safeguards.h"
@ -25,6 +27,14 @@
return (towneffect_type >= (TownEffect)TE_BEGIN && towneffect_type < (TownEffect)TE_END); 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) /* static */ char *ScriptCargo::GetCargoLabel(CargoID cargo_type)
{ {
if (!IsValidCargo(cargo_type)) return nullptr; if (!IsValidCargo(cargo_type)) return nullptr;

@ -84,6 +84,14 @@ public:
*/ */
static bool IsValidTownEffect(TownEffect towneffect_type); 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. * Gets the string representation of the cargo label.
* @param cargo_type The cargo to get the string representation of. * @param cargo_type The cargo to get the string representation of.

Loading…
Cancel
Save