summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/ai/ai_cargo.hpp.sq57
-rw-r--r--src/script/api/ai/ai_station.hpp.sq2
-rw-r--r--src/script/api/ai_changelog.hpp3
-rw-r--r--src/script/api/game/game_cargo.hpp.sq57
-rw-r--r--src/script/api/game/game_station.hpp.sq2
-rw-r--r--src/script/api/game_changelog.hpp3
-rw-r--r--src/script/api/script_cargo.cpp7
-rw-r--r--src/script/api/script_cargo.hpp18
-rw-r--r--src/script/api/script_station.cpp34
-rw-r--r--src/script/api/script_station.hpp25
-rw-r--r--src/script/api/template/template_cargo.hpp.sq2
11 files changed, 158 insertions, 52 deletions
diff --git a/src/script/api/ai/ai_cargo.hpp.sq b/src/script/api/ai/ai_cargo.hpp.sq
index c65872126..6478d44b8 100644
--- a/src/script/api/ai/ai_cargo.hpp.sq
+++ b/src/script/api/ai/ai_cargo.hpp.sq
@@ -21,32 +21,37 @@ void SQAICargo_Register(Squirrel *engine)
SQAICargo.PreRegister(engine);
SQAICargo.AddConstructor<void (ScriptCargo::*)(), 1>(engine, "x");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_PASSENGERS, "CC_PASSENGERS");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_MAIL, "CC_MAIL");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_EXPRESS, "CC_EXPRESS");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_ARMOURED, "CC_ARMOURED");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_BULK, "CC_BULK");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_PIECE_GOODS, "CC_PIECE_GOODS");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_LIQUID, "CC_LIQUID");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_REFRIGERATED, "CC_REFRIGERATED");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_HAZARDOUS, "CC_HAZARDOUS");
- SQAICargo.DefSQConst(engine, ScriptCargo::CC_COVERED, "CC_COVERED");
- SQAICargo.DefSQConst(engine, ScriptCargo::TE_NONE, "TE_NONE");
- SQAICargo.DefSQConst(engine, ScriptCargo::TE_PASSENGERS, "TE_PASSENGERS");
- SQAICargo.DefSQConst(engine, ScriptCargo::TE_MAIL, "TE_MAIL");
- SQAICargo.DefSQConst(engine, ScriptCargo::TE_GOODS, "TE_GOODS");
- SQAICargo.DefSQConst(engine, ScriptCargo::TE_WATER, "TE_WATER");
- SQAICargo.DefSQConst(engine, ScriptCargo::TE_FOOD, "TE_FOOD");
- SQAICargo.DefSQConst(engine, ScriptCargo::CT_AUTO_REFIT, "CT_AUTO_REFIT");
- SQAICargo.DefSQConst(engine, ScriptCargo::CT_NO_REFIT, "CT_NO_REFIT");
-
- SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidCargo, "IsValidCargo", 2, ".i");
- SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidTownEffect, "IsValidTownEffect", 2, ".i");
- SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoLabel, "GetCargoLabel", 2, ".i");
- SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::IsFreight, "IsFreight", 2, ".i");
- SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::HasCargoClass, "HasCargoClass", 3, ".ii");
- SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::GetTownEffect, "GetTownEffect", 2, ".i");
- SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoIncome, "GetCargoIncome", 4, ".iii");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_PASSENGERS, "CC_PASSENGERS");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_MAIL, "CC_MAIL");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_EXPRESS, "CC_EXPRESS");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_ARMOURED, "CC_ARMOURED");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_BULK, "CC_BULK");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_PIECE_GOODS, "CC_PIECE_GOODS");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_LIQUID, "CC_LIQUID");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_REFRIGERATED, "CC_REFRIGERATED");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_HAZARDOUS, "CC_HAZARDOUS");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CC_COVERED, "CC_COVERED");
+ SQAICargo.DefSQConst(engine, ScriptCargo::TE_NONE, "TE_NONE");
+ SQAICargo.DefSQConst(engine, ScriptCargo::TE_PASSENGERS, "TE_PASSENGERS");
+ SQAICargo.DefSQConst(engine, ScriptCargo::TE_MAIL, "TE_MAIL");
+ SQAICargo.DefSQConst(engine, ScriptCargo::TE_GOODS, "TE_GOODS");
+ SQAICargo.DefSQConst(engine, ScriptCargo::TE_WATER, "TE_WATER");
+ SQAICargo.DefSQConst(engine, ScriptCargo::TE_FOOD, "TE_FOOD");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CT_AUTO_REFIT, "CT_AUTO_REFIT");
+ SQAICargo.DefSQConst(engine, ScriptCargo::CT_NO_REFIT, "CT_NO_REFIT");
+ SQAICargo.DefSQConst(engine, ScriptCargo::DT_MANUAL, "DT_MANUAL");
+ SQAICargo.DefSQConst(engine, ScriptCargo::DT_ASYMMETRIC, "DT_ASYMMETRIC");
+ SQAICargo.DefSQConst(engine, ScriptCargo::DT_SYMMETRIC, "DT_SYMMETRIC");
+ SQAICargo.DefSQConst(engine, ScriptCargo::INVALID_DISTRIBUTION_TYPE, "INVALID_DISTRIBUTION_TYPE");
+
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidCargo, "IsValidCargo", 2, ".i");
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidTownEffect, "IsValidTownEffect", 2, ".i");
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoLabel, "GetCargoLabel", 2, ".i");
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::IsFreight, "IsFreight", 2, ".i");
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::HasCargoClass, "HasCargoClass", 3, ".ii");
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::GetTownEffect, "GetTownEffect", 2, ".i");
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoIncome, "GetCargoIncome", 4, ".iii");
+ SQAICargo.DefSQStaticMethod(engine, &ScriptCargo::GetDistributionType, "GetDistributionType", 2, ".i");
SQAICargo.PostRegister(engine);
}
diff --git a/src/script/api/ai/ai_station.hpp.sq b/src/script/api/ai/ai_station.hpp.sq
index 60e7a9cce..8cb80a4de 100644
--- a/src/script/api/ai/ai_station.hpp.sq
+++ b/src/script/api/ai/ai_station.hpp.sq
@@ -47,6 +47,8 @@ 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::GetCargoWaitingFrom, "GetCargoWaitingFrom", 4, ".iii");
+ SQAIStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingVia, "GetCargoWaitingVia", 4, ".iii");
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 5c9baa616..e73857dbf 100644
--- a/src/script/api/ai_changelog.hpp
+++ b/src/script/api/ai_changelog.hpp
@@ -20,9 +20,12 @@
* 1.4.0 is not yet released. The following changes are not set in stone yet.
*
* API additions:
+ * \li AICargo::GetDistributionType
* \li AIDate::DATE_INVALID
* \li AIDate::IsValidDate
* \li AIStation::HasCargoRating
+ * \li AIStation::GetCargoWaitingFrom
+ * \li AIStation::GetCargoWaitingVia
* \li AITile::GetTerrainType
* \li AITown::FoundTown
* \li AITown::GetFundBuildingsDuration
diff --git a/src/script/api/game/game_cargo.hpp.sq b/src/script/api/game/game_cargo.hpp.sq
index 188c732a8..515d5ff28 100644
--- a/src/script/api/game/game_cargo.hpp.sq
+++ b/src/script/api/game/game_cargo.hpp.sq
@@ -21,32 +21,37 @@ void SQGSCargo_Register(Squirrel *engine)
SQGSCargo.PreRegister(engine);
SQGSCargo.AddConstructor<void (ScriptCargo::*)(), 1>(engine, "x");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_PASSENGERS, "CC_PASSENGERS");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_MAIL, "CC_MAIL");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_EXPRESS, "CC_EXPRESS");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_ARMOURED, "CC_ARMOURED");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_BULK, "CC_BULK");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_PIECE_GOODS, "CC_PIECE_GOODS");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_LIQUID, "CC_LIQUID");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_REFRIGERATED, "CC_REFRIGERATED");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_HAZARDOUS, "CC_HAZARDOUS");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CC_COVERED, "CC_COVERED");
- SQGSCargo.DefSQConst(engine, ScriptCargo::TE_NONE, "TE_NONE");
- SQGSCargo.DefSQConst(engine, ScriptCargo::TE_PASSENGERS, "TE_PASSENGERS");
- SQGSCargo.DefSQConst(engine, ScriptCargo::TE_MAIL, "TE_MAIL");
- SQGSCargo.DefSQConst(engine, ScriptCargo::TE_GOODS, "TE_GOODS");
- SQGSCargo.DefSQConst(engine, ScriptCargo::TE_WATER, "TE_WATER");
- SQGSCargo.DefSQConst(engine, ScriptCargo::TE_FOOD, "TE_FOOD");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CT_AUTO_REFIT, "CT_AUTO_REFIT");
- SQGSCargo.DefSQConst(engine, ScriptCargo::CT_NO_REFIT, "CT_NO_REFIT");
-
- SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidCargo, "IsValidCargo", 2, ".i");
- SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidTownEffect, "IsValidTownEffect", 2, ".i");
- SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoLabel, "GetCargoLabel", 2, ".i");
- SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::IsFreight, "IsFreight", 2, ".i");
- SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::HasCargoClass, "HasCargoClass", 3, ".ii");
- SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::GetTownEffect, "GetTownEffect", 2, ".i");
- SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoIncome, "GetCargoIncome", 4, ".iii");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_PASSENGERS, "CC_PASSENGERS");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_MAIL, "CC_MAIL");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_EXPRESS, "CC_EXPRESS");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_ARMOURED, "CC_ARMOURED");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_BULK, "CC_BULK");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_PIECE_GOODS, "CC_PIECE_GOODS");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_LIQUID, "CC_LIQUID");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_REFRIGERATED, "CC_REFRIGERATED");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_HAZARDOUS, "CC_HAZARDOUS");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CC_COVERED, "CC_COVERED");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::TE_NONE, "TE_NONE");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::TE_PASSENGERS, "TE_PASSENGERS");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::TE_MAIL, "TE_MAIL");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::TE_GOODS, "TE_GOODS");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::TE_WATER, "TE_WATER");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::TE_FOOD, "TE_FOOD");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CT_AUTO_REFIT, "CT_AUTO_REFIT");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::CT_NO_REFIT, "CT_NO_REFIT");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::DT_MANUAL, "DT_MANUAL");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::DT_ASYMMETRIC, "DT_ASYMMETRIC");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::DT_SYMMETRIC, "DT_SYMMETRIC");
+ SQGSCargo.DefSQConst(engine, ScriptCargo::INVALID_DISTRIBUTION_TYPE, "INVALID_DISTRIBUTION_TYPE");
+
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidCargo, "IsValidCargo", 2, ".i");
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::IsValidTownEffect, "IsValidTownEffect", 2, ".i");
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoLabel, "GetCargoLabel", 2, ".i");
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::IsFreight, "IsFreight", 2, ".i");
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::HasCargoClass, "HasCargoClass", 3, ".ii");
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::GetTownEffect, "GetTownEffect", 2, ".i");
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::GetCargoIncome, "GetCargoIncome", 4, ".iii");
+ SQGSCargo.DefSQStaticMethod(engine, &ScriptCargo::GetDistributionType, "GetDistributionType", 2, ".i");
SQGSCargo.PostRegister(engine);
}
diff --git a/src/script/api/game/game_station.hpp.sq b/src/script/api/game/game_station.hpp.sq
index 24f80f7d6..ddaa4c575 100644
--- a/src/script/api/game/game_station.hpp.sq
+++ b/src/script/api/game/game_station.hpp.sq
@@ -48,6 +48,8 @@ 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::GetCargoWaitingFrom, "GetCargoWaitingFrom", 4, ".iii");
+ SQGSStation.DefSQStaticMethod(engine, &ScriptStation::GetCargoWaitingVia, "GetCargoWaitingVia", 4, ".iii");
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 4ce320514..f6064a1bd 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -20,6 +20,7 @@
* 1.4.0 is not yet released. The following changes are not set in stone yet.
*
* API additions:
+ * \li AICargo::GetDistributionType
* \li GSCompany::ChangeBankBalance
* \li GSDate::DATE_INVALID
* \li GSDate::IsValidDate
@@ -29,6 +30,8 @@
* \li GSGoal::SetProgress
* \li GSGoal::SetText
* \li GSStation::HasCargoRating
+ * \li AIStation::GetCargoWaitingFrom
+ * \li AIStation::GetCargoWaitingVia
* \li GSStoryPage
* \li GSStoryPageList
* \li GSStoryPageElementList
diff --git a/src/script/api/script_cargo.cpp b/src/script/api/script_cargo.cpp
index e8268b6bb..b2459af4e 100644
--- a/src/script/api/script_cargo.cpp
+++ b/src/script/api/script_cargo.cpp
@@ -13,6 +13,7 @@
#include "script_cargo.hpp"
#include "../../economy_func.h"
#include "../../core/bitmath_func.hpp"
+#include "../../settings_type.h"
/* static */ bool ScriptCargo::IsValidCargo(CargoID cargo_type)
{
@@ -64,3 +65,9 @@
if (!IsValidCargo(cargo_type)) return -1;
return ::GetTransportedGoodsIncome(1, distance, Clamp(days_in_transit * 2 / 5, 0, 255), cargo_type);
}
+
+/* static */ ScriptCargo::DistributionType ScriptCargo::GetDistributionType(CargoID cargo_type)
+{
+ if (!ScriptCargo::IsValidCargo(cargo_type)) return INVALID_DISTRIBUTION_TYPE;
+ return (ScriptCargo::DistributionType)_settings_game.linkgraph.GetDistributionType(cargo_type);
+} \ No newline at end of file
diff --git a/src/script/api/script_cargo.hpp b/src/script/api/script_cargo.hpp
index f4e430362..9d409e191 100644
--- a/src/script/api/script_cargo.hpp
+++ b/src/script/api/script_cargo.hpp
@@ -14,6 +14,7 @@
#include "script_object.hpp"
#include "../../cargotype.h"
+#include "../../linkgraph/linkgraph_type.h"
/**
* Class that handles all cargo related functions.
@@ -61,6 +62,16 @@ public:
};
/**
+ * Type of cargo distribution.
+ */
+ enum DistributionType {
+ DT_MANUAL = ::DT_MANUAL, ///< Manual distribution.
+ DT_ASYMMETRIC = ::DT_ASYMMETRIC, ///< Asymmetric distribution. Usually cargo will only travel in one direction.
+ DT_SYMMETRIC = ::DT_SYMMETRIC, ///< Symmetric distribution. The same amount of cargo travels in each direction between each pair of nodes.
+ INVALID_DISTRIBUTION_TYPE = 0xFFFF, ///< Invalid distribution type.
+ };
+
+ /**
* Checks whether the given cargo type is valid.
* @param cargo_type The cargo to check.
* @return True if and only if the cargo type is valid.
@@ -121,6 +132,13 @@ public:
* @return The amount of money that would be earned by this trip.
*/
static Money GetCargoIncome(CargoID cargo_type, uint32 distance, uint32 days_in_transit);
+
+ /**
+ * Get the cargo distribution type for a cargo.
+ * @param cargo_type The cargo to check on.
+ * @return The cargo distribution type for the given cargo.
+ */
+ static DistributionType GetDistributionType(CargoID cargo_type);
};
#endif /* SCRIPT_CARGO_HPP */
diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp
index bcf5e08ce..506c800d9 100644
--- a/src/script/api/script_station.cpp
+++ b/src/script/api/script_station.cpp
@@ -13,6 +13,7 @@
#include "script_station.hpp"
#include "script_map.hpp"
#include "script_town.hpp"
+#include "script_cargo.hpp"
#include "../../station_base.h"
#include "../../roadstop_base.h"
#include "../../town.h"
@@ -44,6 +45,39 @@
return ::Station::Get(station_id)->goods[cargo_id].cargo.TotalCount();
}
+/* static */ int32 ScriptStation::GetCargoWaitingFrom(StationID station_id, StationID from_station_id, CargoID cargo_id)
+{
+ if (!IsValidStation(station_id)) return -1;
+ if (!IsValidStation(from_station_id) && from_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;
+ 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();
+ }
+
+ return cargo_count;
+}
+
+/* static */ int32 ScriptStation::GetCargoWaitingVia(StationID station_id, StationID via_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;
+
+ 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();
+ }
+
+ return cargo_count;
+}
+
/* static */ bool ScriptStation::HasCargoRating(StationID station_id, CargoID cargo_id)
{
if (!IsValidStation(station_id)) return false;
diff --git a/src/script/api/script_station.hpp b/src/script/api/script_station.hpp
index 7614b516c..8108b8370 100644
--- a/src/script/api/script_station.hpp
+++ b/src/script/api/script_station.hpp
@@ -87,6 +87,31 @@ public:
static int32 GetCargoWaiting(StationID station_id, CargoID cargo_id);
/**
+ * 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 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 IsValidCargo(cargo_id).
+ * @return The amount of units waiting at the station originating from from_station_id.
+ * @note source station means, the station where cargo was first loaded.
+ */
+ static int32 GetCargoWaitingFrom(StationID station_id, StationID from_station_id, CargoID cargo_id);
+
+ /**
+ * 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 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);
+
+ /**
* 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.
diff --git a/src/script/api/template/template_cargo.hpp.sq b/src/script/api/template/template_cargo.hpp.sq
index 0a80aa705..b57e5c05a 100644
--- a/src/script/api/template/template_cargo.hpp.sq
+++ b/src/script/api/template/template_cargo.hpp.sq
@@ -19,6 +19,8 @@ namespace SQConvert {
template <> inline int Return<ScriptCargo::TownEffect>(HSQUIRRELVM vm, ScriptCargo::TownEffect res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptCargo::SpecialCargoID GetParam(ForceType<ScriptCargo::SpecialCargoID>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptCargo::SpecialCargoID)tmp; }
template <> inline int Return<ScriptCargo::SpecialCargoID>(HSQUIRRELVM vm, ScriptCargo::SpecialCargoID res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> inline ScriptCargo::DistributionType GetParam(ForceType<ScriptCargo::DistributionType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptCargo::DistributionType)tmp; }
+ template <> inline int Return<ScriptCargo::DistributionType>(HSQUIRRELVM vm, ScriptCargo::DistributionType res) { sq_pushinteger(vm, (int32)res); return 1; }
/* Allow ScriptCargo to be used as Squirrel parameter */
template <> inline ScriptCargo *GetParam(ForceType<ScriptCargo *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptCargo *)instance; }