function WrightAI::GetEngineOptimalRealFakeDist(engine_id, days_in_transit)
{
/* Assuming going in axis, it is the same as distancemanhattan */
local realfakedist = (AIEngine.GetMaxSpeed(engine_id) * 2 * 74 * days_in_transit / 256) / 16;
return realfakedist;
}
function WrightAI::GetEngineOptimalDaysInTransit(engine_id, cargo, days_int, valuator = false)
{
local distance = WrightAI.GetEngineOptimalRealFakeDist(engine_id, 1000);
local running_cost = AIEngine.GetRunningCost(engine_id);
local capacity = AIEngine.GetCapacity(engine_id);
local days_in_transit = 0;
local best_income = -100000000;
local best_distance = 0;
local breakdowns = AIGameSettings.GetValue("vehicle_breakdowns");
for (local days = days_int * 3; days <= (breakdowns ? 130 / breakdowns : 185); days++) {
local income = capacity * AICargo.GetCargoIncome(cargo, distance * days / 1000, days) - running_cost * days / 365;
// local income_per_year = capacity * AICargo.GetCargoIncome(cargo, distance * days / 1000, days) * 365 / days - running_cost;
if (income > 1000 && income > best_income) {
// if (income_per_year > 10000 && income_per_year > best_income) {
best_income = income;
// best_income = income_per_year;
best_distance = distance * days / 1000;
days_in_transit = days;
}
}
// AILog.Info("days_in_transit = " + days_in_transit + " ; best_distance = " + best_distance + " ; best_income = " + best_income + " ; fakedist = " + GetEngineOptimalRealFakeDist(engine_id, days_in_transit));
// AILog.Info("engine = " + AIEngine.GetName(engine_id) + " ; max speed = " + AIEngine.GetMaxSpeed(engine_id) + " ; capacity = " + capacity + " ; running cost = " + running_cost);
if (valuator) {
return best_income;
} else {
return [days_in_transit, best_income, best_distance];
}
}