diff options
-rw-r--r-- | bin/ai/regression/regression.txt | 4 | ||||
-rw-r--r-- | src/script/api/ai/ai_station.hpp.sq | 1 | ||||
-rw-r--r-- | src/script/api/ai_changelog.hpp | 7 | ||||
-rw-r--r-- | src/script/api/game/game_station.hpp.sq | 1 | ||||
-rw-r--r-- | src/script/api/game_changelog.hpp | 7 | ||||
-rw-r--r-- | src/script/api/script_station.cpp | 11 | ||||
-rw-r--r-- | src/script/api/script_station.hpp | 11 |
7 files changed, 38 insertions, 4 deletions
diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index 8fa6a8b27..9ca055ea5 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -9118,8 +9118,8 @@ ERROR: IsEnd() is invalid as Begin() is never called 5 => 0 4 => 0 CargoRating(1) ListDump: - 5 => 69 - 4 => 69 + 5 => -1 + 4 => -1 DistanceManhattanToTile(30000) ListDump: 5 => 106 4 => 96 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); |