summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/script/api/ai/ai_station.hpp.sq1
-rw-r--r--src/script/api/ai_changelog.hpp7
-rw-r--r--src/script/api/game/game_station.hpp.sq1
-rw-r--r--src/script/api/game_changelog.hpp7
-rw-r--r--src/script/api/script_station.cpp11
-rw-r--r--src/script/api/script_station.hpp11
6 files changed, 36 insertions, 2 deletions
diff --git a/src/script/api/ai/ai_station.hpp.sq b/src/script/api/ai/ai_station.hpp.sq
index 620f378b9..60e7a9cce 100644
--- a/src/script/api/ai/ai_station.hpp.sq
+++ b/src/script/api/ai/ai_station.hpp.sq
@@ -47,6 +47,7 @@ void SQAIStation_Register(Squirrel *engine)
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::IsValidStation, "IsValidStation", 2, ".i");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetStationID, "GetStationID", 2, ".i");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
+ SQAIStation.DefSQStaticMethod(engine, &ScriptStation::HasCargoRating, "HasCargoRating", 3, ".ii");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoRating, "GetCargoRating", 3, ".ii");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCoverageRadius, "GetCoverageRadius", 2, ".i");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetStationCoverageRadius, "GetStationCoverageRadius", 2, ".i");
diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp
index a01692982..6f1741c1c 100644
--- a/src/script/api/ai_changelog.hpp
+++ b/src/script/api/ai_changelog.hpp
@@ -19,6 +19,13 @@
*
* 1.4.0 is not yet released. The following changes are not set in stone yet.
*
+ * API additions:
+ * \li AIStation::HasRating
+ *
+ * Other changes:
+ * \li AIStation::GetRating does return -1 for cargo-station combinations that
+ * do not have a rating yet instead of returning 69.
+ *
* \b 1.3.0
*
* API additions:
diff --git a/src/script/api/game/game_station.hpp.sq b/src/script/api/game/game_station.hpp.sq
index 9e95d32bf..24f80f7d6 100644
--- a/src/script/api/game/game_station.hpp.sq
+++ b/src/script/api/game/game_station.hpp.sq
@@ -48,6 +48,7 @@ void SQGSStation_Register(Squirrel *engine)
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetOwner, "GetOwner", 2, ".i");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetStationID, "GetStationID", 2, ".i");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
+ SQGSStation.DefSQStaticMethod(engine, &ScriptStation::HasCargoRating, "HasCargoRating", 3, ".ii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoRating, "GetCargoRating", 3, ".ii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCoverageRadius, "GetCoverageRadius", 2, ".i");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetStationCoverageRadius, "GetStationCoverageRadius", 2, ".i");
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 02478302c..4fed0a13a 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -19,6 +19,13 @@
*
* 1.4.0 is not yet released. The following changes are not set in stone yet.
*
+ * API additions:
+ * \li AIStation::HasRating
+ *
+ * Other changes:
+ * \li AIStation::GetRating does return -1 for cargo-station combinations that
+ * do not have a rating yet instead of returning 69.
+ *
* \b 1.3.0
*
* API additions:
diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp
index 423c5545a..a7b8459fc 100644
--- a/src/script/api/script_station.cpp
+++ b/src/script/api/script_station.cpp
@@ -44,10 +44,17 @@
return ::Station::Get(station_id)->goods[cargo_id].cargo.Count();
}
+/* static */ bool ScriptStation::HasCargoRating(StationID station_id, CargoID cargo_id)
+{
+ if (!IsValidStation(station_id)) return false;
+ if (!ScriptCargo::IsValidCargo(cargo_id)) return false;
+
+ return ::Station::Get(station_id)->goods[cargo_id].HasRating();
+}
+
/* static */ int32 ScriptStation::GetCargoRating(StationID station_id, CargoID cargo_id)
{
- if (!IsValidStation(station_id)) return -1;
- if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
+ if (!ScriptStation::HasCargoRating(station_id, cargo_id)) return -1;
return ::ToPercent8(::Station::Get(station_id)->goods[cargo_id].rating);
}
diff --git a/src/script/api/script_station.hpp b/src/script/api/script_station.hpp
index bb5d22c1b..7614b516c 100644
--- a/src/script/api/script_station.hpp
+++ b/src/script/api/script_station.hpp
@@ -87,11 +87,22 @@ public:
static int32 GetCargoWaiting(StationID station_id, CargoID cargo_id);
/**
+ * Check whether the given cargo at the given station a rating.
+ * @param station_id The station to get the cargo-rating state of.
+ * @param cargo_id The cargo to get the cargo-rating state of.
+ * @pre IsValidStation(station_id).
+ * @pre IsValidCargo(cargo_id).
+ * @return True if the cargo has a rating, otherwise false.
+ */
+ static bool HasCargoRating(StationID station_id, CargoID cargo_id);
+
+ /**
* See how high the rating is of a cargo on a station.
* @param station_id The station to get the cargo-rating of.
* @param cargo_id The cargo to get the cargo-rating of.
* @pre IsValidStation(station_id).
* @pre IsValidCargo(cargo_id).
+ * @pre HasCargoRating(station_id, cargo_id).
* @return The rating in percent of the cargo on the station.
*/
static int32 GetCargoRating(StationID station_id, CargoID cargo_id);