Loading

Paste #pjzwj6cj6

  1. function WrightAI::GetEngineOptimalDaysInTransit(engine_id, cargo, days_int, valuator = false)
  2. {
  3.     local distance = WrightAI.GetEngineOptimalRealFakeDist(engine_id, 1000);
  4.     local running_cost = AIEngine.GetRunningCost(engine_id);
  5.     local capacity = AIEngine.GetCapacity(engine_id);
  6.    
  7.     local days_in_transit = 0;
  8.     local best_income = -100000000;
  9.     local best_distance = 0;
  10.     local breakdowns = AIGameSettings.GetValue("vehicle_breakdowns");
  11.         for (local days = days_int * 3; days <= (breakdowns ? 130 / breakdowns : 185); days++) {
  12.             local income = capacity * AICargo.GetCargoIncome(cargo, distance * days / 1000, days) - running_cost * days / 365;
  13. //          local income_per_year = capacity * AICargo.GetCargoIncome(cargo, distance * days / 1000, days) * 365 / days - running_cost;
  14.             if (income > 1000 && income > best_income) {
  15. //          if (income_per_year > 10000 && income_per_year > best_income) {
  16.                 best_income = income;
  17. //              best_income = income_per_year;
  18.                 best_distance = distance * days / 1000;
  19.                 days_in_transit = days;
  20.             }
  21.         }
  22. //  AILog.Info("days_in_transit = " + days_in_transit + " ; best_distance = " + best_distance + " ; best_income = " + best_income + " ; fakedist = " + GetEngineOptimalRealFakeDist(engine_id, days_in_transit));
  23. //  AILog.Info("engine = " + AIEngine.GetName(engine_id) + " ; max speed = " + AIEngine.GetMaxSpeed(engine_id) + " ; capacity = " + capacity + " ; running cost = " + running_cost);
  24.     if (valuator) {
  25.         return best_income;
  26.     } else {
  27.         return [days_in_transit, best_income, best_distance];
  28.     }
  29. }

Comments