Loading

Revision differences

Old revision #pex5dlqprNew revision #pkj6pnebd
1function WrightAI::GetEngineOptimalRealFakeDist(engine_id, days_in_transit)  1function WrightAI::GetEngineDaysInTransit(engine_id, fakedist)
2{  2{  
3    /* Assuming going in axis, it is the same as distancemanhattan */  3    local days_in_transit = (fakedist * 256 * 16) / (2 * 74 * AIEngine.GetMaxSpeed(engine_id));
4    local realfakedist = (AIEngine.GetMaxSpeed(engine_id) * 2 * 74 * days_in_transit / 256) / 16;  4    return days_in_transit;
5    return realfakedist;    
6}  5}  
7  6  
8function WrightAI::GetEngineOptimalDaysInTransit(engine_id, cargo, days_int, valuator = false)  8function WrightAI::GetEngineRouteIncome(engine_id, cargo, fakedist) {
9{  9    local running_cost = AIEngine.GetRunningCost(engine_id);
10    local distance = WrightAI.GetEngineOptimalRealFakeDist(engine_id, 1000);    
11    local running_cost = AIEngine.GetRunningCost(engine_id);    
12    local capacity = AIEngine.GetCapacity(engine_id);  9    local capacity = AIEngine.GetCapacity(engine_id);  
13     13    local days_in_transit = WrightAI.GetEngineDaysInTransit(engine_id, fakedist);
14    local days_in_transit = 0;  14    local income = capacity * AICargo.GetCargoIncome(cargo, fakedist, days_in_transit) - running_cost * days_in_transit / 365;
15    local best_income = -100000000;  15    return income;
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} 13}