I've tried to write a small function that calculates the number of busses needed for a bus route. For simplicity reasons, my calculations assume that the AI bus station is the only one in both the source and the destination towns.
The math is based on the following (take from our wiki):
And base on this (also taken from our wiki):During each cycle of 2.5 days for each cargo type of the delivering industry a maximum of 2 stations can get cargo assigned. If there are more than 2 possible stations with the same maximum rating value for the current cargo type then it depends on internal ordering of the stations which ones get the cargo.
If there's only one possible station then the delivered amount is: produced_amount * station_rating_in_percent, rounded up to the next integer value.
For some reason, the amount of busses calculated by the function is way too high.The game has many rules to make vehicles move fairly realistically. A vehicle travelling at 100 mph (160kph) will cross 5.6 tiles per day.
This means that for vehicle speed purposes, a tile is 429 miles (686km) on a side!
The function:
Code: Select all
//from,to - town IDs.
function RonitAI::GetBusCount(from, to, busID)
{
local fromProduction = AITown.GetMaxProduction(from, passenger_cargo_id);
local toProduction = AITown.GetMaxProduction(to, passenger_cargo_id);
AILog.Info("From production: " + fromProduction);
AILog.Info("To Production: " + toProduction);
local fromPerDay = fromProduction * 0.6 / 2.5;
local toPerDay = toProduction * 0.6 / 2.5;
AILog.Info("fromPerDay: " + fromPerDay);
AILog.Info("ToPerDay: " + toPerDay);
local maxPerDay = fromPerDay;
if (toPerDay > maxPerDay)
maxPerDay = toPerDay;
AILog.Info("MaxPerDay: " + maxPerDay);
local engine = AIVehicle.GetEngineType(busID);
local capacity = AIEngine.GetCapacity(engine);
local speed = AIEngine.GetMaxSpeed(engine);
AILog.Info("BusCapacity: " + capacity);
AILog.Info("BusSpeed: " + speed);
local distance = AITile.GetDistanceManhattanToTile(AITown.GetLocation(from), AITown.GetLocation(to)) * 686;
AILog.Info("Manhattan Distance: " + distance/686);
AILog.Info("Distance in kiometers: " + distance);
local travelDays = (distance / speed )/ 24;
AILog.Info("TravelDays: " + travelDays);
local actualProduct = 2 * travelDays * maxPerDay;
AILog.Info("ActualProduct: " + actualProduct);
local busses = actualProduct / capacity;
AILog.Info("busses: " + busses);
if (busses % 1 != 0)
{
busses ++;
AILog.Info("Increment busses.");
}
AILog.Info("Busses: " + busses);
return busses;
}
Code: Select all
From production: 244
To Production: 165
fromPerDay: 58.56
ToPerDay: 39.6
MaxPerDay: 58.56
BusCapacity: 31
BusSpeed: 56
Manhattan Distance: 36
Distance in kiometers: 24696
TravelDays: 18
ActualProduct: 2108.16
busses: 68.0052
Increment busses.
Busses: 69.0052
BTW, does squirrel support Ceil() and Floor() functions (or RoundUp() and RoundDown())?
Thanks,
SummerBulb