summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/ai/regression/regression.nut23
-rw-r--r--bin/ai/regression/regression.txt41
-rw-r--r--src/script/api/ai/ai_station.hpp.sq1
-rw-r--r--src/script/api/ai_changelog.hpp3
-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.cpp56
-rw-r--r--src/script/api/script_station.hpp26
8 files changed, 122 insertions, 36 deletions
diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut
index 5e8533a2e..72a0c5a97 100644
--- a/bin/ai/regression/regression.nut
+++ b/bin/ai/regression/regression.nut
@@ -1234,10 +1234,6 @@ function Regression::Station()
print(" GetLocation(1000): " + AIStation.GetLocation(1000));
print(" GetStationID(33411): " + AIStation.GetStationID(33411));
print(" GetStationID(34411): " + AIStation.GetStationID(34411));
- print(" GetCargoWaiting(0, 0): " + AIStation.GetCargoWaiting(0, 0));
- print(" GetCargoWaiting(1000, 0): " + AIStation.GetCargoWaiting(1000, 0));
- print(" GetCargoWaiting(0, 1000): " + AIStation.GetCargoWaiting(0, 1000));
-
print(" GetStationID(33411): " + AIStation.GetStationID(33411));
print(" HasRoadType(3, TRAM): " + AIStation.HasRoadType(3, AIRoad.ROADTYPE_TRAM));
print(" HasRoadType(3, ROAD): " + AIStation.HasRoadType(3, AIRoad.ROADTYPE_ROAD));
@@ -1254,6 +1250,25 @@ function Regression::Station()
print(" GetNearestTown(): " + AIStation.GetNearestTown(10000));
print(" GetNearestTown(): " + AIStation.GetNearestTown(3));
+ print("");
+ print("--CargoWaiting--");
+ for (local cargo = 0; cargo <= 1000; cargo += 1000) {
+ for (local station0 = 0; station0 <= 1000; station0 += 1000) {
+ print(" GetCargoWaiting(" + station0 + ", " + cargo + "): " +
+ AIStation.GetCargoWaiting(station0, cargo));
+ for (local station1 = 0; station1 <= 1000; station1 += 1000) {
+ print(" GetCargoWaitingFrom(" + station0 + ", " + station1 + ", " + cargo + "): " +
+ AIStation.GetCargoWaitingFrom(station0, station1, cargo));
+ print(" GetCargoWaitingVia(" + station0 + ", " + station1 + ", " + cargo + "): " +
+ AIStation.GetCargoWaitingFrom(station0, station1, cargo));
+ for (local station2 = 0; station2 <= 1000; station2 += 1000) {
+ print(" GetCargoWaitingFromVia(" + station0 + ", " + station1 + ", " + station2 + ", " + cargo + "): " +
+ AIStation.GetCargoWaitingFromVia(station0, station1, station2, cargo));
+ }
+ }
+ }
+ }
+
local list = AIStationList(AIStation.STATION_BUS_STOP + AIStation.STATION_TRUCK_STOP);
print("");
diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt
index 5eab44103..e6f30d220 100644
--- a/bin/ai/regression/regression.txt
+++ b/bin/ai/regression/regression.txt
@@ -7487,9 +7487,6 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetLocation(1000): -1
GetStationID(33411): 4
GetStationID(34411): 65535
- GetCargoWaiting(0, 0): 0
- GetCargoWaiting(1000, 0): -1
- GetCargoWaiting(0, 1000): -1
GetStationID(33411): 4
HasRoadType(3, TRAM): false
HasRoadType(3, ROAD): false
@@ -7504,6 +7501,44 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetNearestTown(): 65535
GetNearestTown(): 10
+--CargoWaiting--
+ GetCargoWaiting(0, 0): 0
+ GetCargoWaitingFrom(0, 0, 0): 0
+ GetCargoWaitingVia(0, 0, 0): 0
+ GetCargoWaitingFromVia(0, 0, 0, 0): 0
+ GetCargoWaitingFromVia(0, 0, 1000, 0): -1
+ GetCargoWaitingFrom(0, 1000, 0): -1
+ GetCargoWaitingVia(0, 1000, 0): -1
+ GetCargoWaitingFromVia(0, 1000, 0, 0): -1
+ GetCargoWaitingFromVia(0, 1000, 1000, 0): -1
+ GetCargoWaiting(1000, 0): -1
+ GetCargoWaitingFrom(1000, 0, 0): -1
+ GetCargoWaitingVia(1000, 0, 0): -1
+ GetCargoWaitingFromVia(1000, 0, 0, 0): -1
+ GetCargoWaitingFromVia(1000, 0, 1000, 0): -1
+ GetCargoWaitingFrom(1000, 1000, 0): -1
+ GetCargoWaitingVia(1000, 1000, 0): -1
+ GetCargoWaitingFromVia(1000, 1000, 0, 0): -1
+ GetCargoWaitingFromVia(1000, 1000, 1000, 0): -1
+ GetCargoWaiting(0, 1000): -1
+ GetCargoWaitingFrom(0, 0, 1000): -1
+ GetCargoWaitingVia(0, 0, 1000): -1
+ GetCargoWaitingFromVia(0, 0, 0, 1000): -1
+ GetCargoWaitingFromVia(0, 0, 1000, 1000): -1
+ GetCargoWaitingFrom(0, 1000, 1000): -1
+ GetCargoWaitingVia(0, 1000, 1000): -1
+ GetCargoWaitingFromVia(0, 1000, 0, 1000): -1
+ GetCargoWaitingFromVia(0, 1000, 1000, 1000): -1
+ GetCargoWaiting(1000, 1000): -1
+ GetCargoWaitingFrom(1000, 0, 1000): -1
+ GetCargoWaitingVia(1000, 0, 1000): -1
+ GetCargoWaitingFromVia(1000, 0, 0, 1000): -1
+ GetCargoWaitingFromVia(1000, 0, 1000, 1000): -1
+ GetCargoWaitingFrom(1000, 1000, 1000): -1
+ GetCargoWaitingVia(1000, 1000, 1000): -1
+ GetCargoWaitingFromVia(1000, 1000, 0, 1000): -1
+ GetCargoWaitingFromVia(1000, 1000, 1000, 1000): -1
+
--StationList--
Count(): 2
Location ListDump:
diff --git a/src/script/api/ai/ai_station.hpp.sq b/src/script/api/ai/ai_station.hpp.sq
index 8cb80a4de..6f2b6e741 100644
--- a/src/script/api/ai/ai_station.hpp.sq
+++ b/src/script/api/ai/ai_station.hpp.sq
@@ -49,6 +49,7 @@ void SQAIStation_Register(Squirrel *engine)
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFrom, "GetCargoWaitingFrom", 4, ".iii");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingVia, "GetCargoWaitingVia", 4, ".iii");
+ SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFromVia, "GetCargoWaitingFromVia", 5, ".iiii");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::HasCargoRating, "HasCargoRating", 3, ".ii");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoRating, "GetCargoRating", 3, ".ii");
SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCoverageRadius, "GetCoverageRadius", 2, ".i");
diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp
index f54495080..92893c269 100644
--- a/src/script/api/ai_changelog.hpp
+++ b/src/script/api/ai_changelog.hpp
@@ -19,6 +19,9 @@
*
* 1.5.0 is not yet released. The following changes are not set in stone yet.
*
+ * API additions:
+ * \li AIStation::GetCargoWaitingFromVia
+ *
* \b 1.4.0
*
* API additions:
diff --git a/src/script/api/game/game_station.hpp.sq b/src/script/api/game/game_station.hpp.sq
index ddaa4c575..263ad6ba7 100644
--- a/src/script/api/game/game_station.hpp.sq
+++ b/src/script/api/game/game_station.hpp.sq
@@ -50,6 +50,7 @@ void SQGSStation_Register(Squirrel *engine)
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaiting, "GetCargoWaiting", 3, ".ii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFrom, "GetCargoWaitingFrom", 4, ".iii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingVia, "GetCargoWaitingVia", 4, ".iii");
+ SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingFromVia, "GetCargoWaitingFromVia", 5, ".iiii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::HasCargoRating, "HasCargoRating", 3, ".ii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoRating, "GetCargoRating", 3, ".ii");
SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCoverageRadius, "GetCoverageRadius", 2, ".i");
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 632296cd9..a6a80f9b3 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -19,6 +19,9 @@
*
* 1.5.0 is not yet released. The following changes are not set in stone yet.
*
+ * API additions:
+ * \li GSStation::GetCargoWaitingFromVia
+ *
* \b 1.4.0
*
* API additions:
@@ -32,8 +35,8 @@
* \li GSGoal::SetProgress
* \li GSGoal::SetText
* \li GSStation::HasCargoRating
- * \li AIStation::GetCargoWaitingFrom
- * \li AIStation::GetCargoWaitingVia
+ * \li GSStation::GetCargoWaitingFrom
+ * \li GSStation::GetCargoWaitingVia
* \li GSStoryPage
* \li GSStoryPageList
* \li GSStoryPageElementList
diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp
index db0865261..d304f7366 100644
--- a/src/script/api/script_station.cpp
+++ b/src/script/api/script_station.cpp
@@ -39,45 +39,51 @@
return ::GetStationIndex(tile);
}
-/* static */ int32 ScriptStation::GetCargoWaiting(StationID station_id, CargoID cargo_id)
-{
- if (!IsValidStation(station_id)) return -1;
- if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
-
- return ::Station::Get(station_id)->goods[cargo_id].cargo.TotalCount();
-}
-
-/* static */ int32 ScriptStation::GetCargoWaitingFrom(StationID station_id, StationID from_station_id, CargoID cargo_id)
+template<bool Tfrom, bool Tvia>
+/* static */ int32 ScriptStation::CountCargoWaiting(StationID station_id,
+ StationID from_station_id, StationID via_station_id, CargoID cargo_id)
{
if (!IsValidStation(station_id)) return -1;
- if (!IsValidStation(from_station_id) && from_station_id != STATION_INVALID) return -1;
+ if (Tfrom && !IsValidStation(from_station_id) && from_station_id != STATION_INVALID) return -1;
+ if (Tvia && !IsValidStation(via_station_id) && via_station_id != STATION_INVALID) return -1;
if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
+ if (!Tfrom && !Tvia) return cargo_list.TotalCount();
+
uint16 cargo_count = 0;
- for (StationCargoList::ConstIterator it = cargo_list.Packets()->begin(); it != cargo_list.Packets()->end(); it++) {
- CargoPacket *cp = *it;
- if (cp->SourceStation() == from_station_id) cargo_count += cp->Count();
+ std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range = Tvia ?
+ cargo_list.Packets()->equal_range(via_station_id) :
+ std::make_pair(cargo_list.Packets()->begin(), cargo_list.Packets()->end());
+ for (StationCargoList::ConstIterator it = range.first; it != range.second; it++) {
+ const CargoPacket *cp = *it;
+ if (!Tfrom || cp->SourceStation() == from_station_id) cargo_count += cp->Count();
}
return cargo_count;
}
-/* static */ int32 ScriptStation::GetCargoWaitingVia(StationID station_id, StationID via_station_id, CargoID cargo_id)
+/* static */ int32 ScriptStation::GetCargoWaiting(StationID station_id, CargoID cargo_id)
{
- if (!IsValidStation(station_id)) return -1;
- if (!IsValidStation(via_station_id) && via_station_id != STATION_INVALID) return -1;
- if (!ScriptCargo::IsValidCargo(cargo_id)) return -1;
+ return CountCargoWaiting<false, false>(station_id, STATION_INVALID, STATION_INVALID, cargo_id);
+}
- const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
- uint16 cargo_count = 0;
- std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range = cargo_list.Packets()->equal_range(via_station_id);
- for (StationCargoList::ConstIterator it = range.first; it != range.second; it++) {
- CargoPacket *cp = *it;
- cargo_count += cp->Count();
- }
+/* static */ int32 ScriptStation::GetCargoWaitingFrom(StationID station_id,
+ StationID from_station_id, CargoID cargo_id)
+{
+ return CountCargoWaiting<true, false>(station_id, from_station_id, STATION_INVALID, cargo_id);
+}
- return cargo_count;
+/* static */ int32 ScriptStation::GetCargoWaitingVia(StationID station_id,
+ StationID via_station_id, CargoID cargo_id)
+{
+ return CountCargoWaiting<false, true>(station_id, STATION_INVALID, via_station_id, cargo_id);
+}
+
+/* static */ int32 ScriptStation::GetCargoWaitingFromVia(StationID station_id,
+ StationID from_station_id, StationID via_station_id, CargoID cargo_id)
+{
+ return CountCargoWaiting<true, true>(station_id, from_station_id, via_station_id, cargo_id);
}
/* static */ bool ScriptStation::HasCargoRating(StationID station_id, CargoID cargo_id)
diff --git a/src/script/api/script_station.hpp b/src/script/api/script_station.hpp
index 8108b8370..26fc28042 100644
--- a/src/script/api/script_station.hpp
+++ b/src/script/api/script_station.hpp
@@ -89,6 +89,7 @@ public:
/**
* See how much cargo with a specific source station there is waiting on a station.
* @param station_id The station to get the cargo-waiting of.
+ * @param from_station_id The source station of the cargo. Pass STATION_INVALID to get cargo of which the source has been deleted.
* @param cargo_id The cargo to get the cargo-waiting of.
* @pre IsValidStation(station_id).
* @pre IsValidStation(from_station_id) || from_station_id == STATION_INVALID.
@@ -100,18 +101,33 @@ public:
/**
* See how much cargo with a specific via-station there is waiting on a station.
- * @param station_id The station to get the cargo-waiting of, or pass STATION_INVALID to get waiting cargo for "via any station".
+ * @param station_id The station to get the cargo-waiting of.
+ * @param via_station_id The next station the cargo is going to. Pass STATION_INVALID to get waiting cargo for "via any station".
* @param cargo_id The cargo to get the cargo-waiting of.
* @pre IsValidStation(station_id).
* @pre IsValidStation(via_station_id) || via_station_id == STATION_INVALID.
* @pre IsValidCargo(cargo_id).
* @return The amount of units waiting at the station with via_station_id as next hop.
* @note if ScriptCargo.GetCargoDistributionType(cargo_id) == ScriptCargo.DT_MANUAL, then all waiting cargo will have STATION_INVALID as next hop.
-
*/
static int32 GetCargoWaitingVia(StationID station_id, StationID via_station_id, CargoID cargo_id);
/**
+ * See how much cargo with a specific via-station and source station there is waiting on a station.
+ * @param station_id The station to get the cargo-waiting of.
+ * @param from_station_id The source station of the cargo. Pass STATION_INVALID to get cargo of which the source has been deleted.
+ * @param via_station_id The next station the cargo is going to. Pass STATION_INVALID to get waiting cargo for "via any station".
+ * @param cargo_id The cargo to get the cargo-waiting of.
+ * @pre IsValidStation(station_id).
+ * @pre IsValidStation(from_station_id) || from_station_id == STATION_INVALID.
+ * @pre IsValidStation(via_station_id) || via_station_id == STATION_INVALID.
+ * @pre IsValidCargo(cargo_id).
+ * @return The amount of units waiting at the station with from_station_id as source and via_station_id as next hop.
+ * @note if ScriptCargo.GetCargoDistributionType(cargo_id) == ScriptCargo.DT_MANUAL, then all waiting cargo will have STATION_INVALID as next hop.
+ */
+ static int32 GetCargoWaitingFromVia(StationID station_id, StationID from_station_id, StationID via_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.
@@ -226,6 +242,12 @@ public:
* @return True if the state could be toggled.
*/
static bool OpenCloseAirport(StationID station_id);
+
+private:
+ template<bool Tfrom, bool Tvia>
+ static int32 CountCargoWaiting(StationID station_id, StationID from_station_id,
+ StationID via_station_id, CargoID cargo_id);
+
};
DECLARE_ENUM_AS_BIT_SET(ScriptStation::StationType)