Loading

Paste #pex5dlqpr

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

Version history

Revision # Author Created at
pjzwj6cj6 Anonymous 05 Sep 2018, 18:14:52 UTC Diff

Comments