mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r26557) -Fix: clean up, test (somewhat), and complete the API for waiting cargo
This commit is contained in:
parent
d2357ec435
commit
bb269661d4
|
@ -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("");
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -39,45 +39,51 @@
|
|||
return ::GetStationIndex(tile);
|
||||
}
|
||||
|
||||
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 (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;
|
||||
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::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();
|
||||
return CountCargoWaiting<false, false>(station_id, STATION_INVALID, STATION_INVALID, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoWaitingFrom(StationID station_id, StationID from_station_id, CargoID cargo_id)
|
||||
/* 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;
|
||||
return CountCargoWaiting<true, false>(station_id, from_station_id, STATION_INVALID, cargo_id);
|
||||
}
|
||||
|
||||
/* static */ int32 ScriptStation::GetCargoWaitingVia(StationID station_id, StationID via_station_id, CargoID cargo_id)
|
||||
/* 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;
|
||||
return CountCargoWaiting<false, true>(station_id, STATION_INVALID, via_station_id, 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();
|
||||
}
|
||||
|
||||
return cargo_count;
|
||||
/* 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)
|
||||
|
|
|
@ -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,17 +101,32 @@ 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.
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue