mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-31 11:23:21 +00:00
(svn r25150) -Fix [FS#5514]: [Script] The was no way to differentiate between a cargo-station combination with or without rating, so introduce [AI|GS]Station::HasRating and let GetRating return -1 when there is no rating
This commit is contained in:
parent
b2292122b6
commit
7a3d549f2f
@ -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
|
||||
|
@ -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");
|
||||
|
@ -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:
|
||||
|
@ -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");
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -86,12 +86,23 @@ 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);
|
||||
|
Loading…
Reference in New Issue
Block a user