Fix: Don't set goals for cargo that's not available at the map. Closes #7368
This commit is contained in:
18
main.nut
18
main.nut
@@ -61,6 +61,17 @@ function BusyBeeClass::FindSources(cargo_id)
|
|||||||
num_sources += 1;
|
num_sources += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Dump sources for a cargo.
|
||||||
|
// GSLog.Info("Sources for " + GSCargo.GetCargoLabel(cargo.cid));
|
||||||
|
// foreach (_, src in sources) {
|
||||||
|
// if ("ind" in src) {
|
||||||
|
// GSLog.Info("Industry " + GSIndustry.GetName(src.ind) + " produces " + src.prod);
|
||||||
|
// } else {
|
||||||
|
// GSLog.Info("Town " + GSTown.GetName(src.town) + " produces " + src.prod);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// GSLog.Info("");
|
||||||
|
|
||||||
return sources;
|
return sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +131,10 @@ function BusyBeeClass::GetDistanceScore(desired, actual)
|
|||||||
function BusyBeeClass::FindChallenge(cargo_id, distance, cid)
|
function BusyBeeClass::FindChallenge(cargo_id, distance, cid)
|
||||||
{
|
{
|
||||||
local prods = this.FindSources(cargo_id);
|
local prods = this.FindSources(cargo_id);
|
||||||
|
if (prods.len() == 0) return null;
|
||||||
local accepts = this.FindDestinations(cargo_id, cid);
|
local accepts = this.FindDestinations(cargo_id, cid);
|
||||||
|
if (accepts.len() == 0) return null;
|
||||||
|
|
||||||
local cdata = this.companies[cid];
|
local cdata = this.companies[cid];
|
||||||
|
|
||||||
local best_score = 0; // Best overall distance.
|
local best_score = 0; // Best overall distance.
|
||||||
@@ -129,7 +143,7 @@ function BusyBeeClass::FindChallenge(cargo_id, distance, cid)
|
|||||||
if (cdata != null && cdata.HasGoal(cargo_id, accept)) continue; // Prevent duplicates.
|
if (cdata != null && cdata.HasGoal(cargo_id, accept)) continue; // Prevent duplicates.
|
||||||
|
|
||||||
local min_prod_distance = distance * 2; // Smallest found distance to the accepting industry.
|
local min_prod_distance = distance * 2; // Smallest found distance to the accepting industry.
|
||||||
local prod_score = GetDistanceScore(distance, min_prod_distance);
|
local prod_score = best_score;
|
||||||
foreach (_, prod in prods) {
|
foreach (_, prod in prods) {
|
||||||
local actual_dist = GSTile.GetDistanceManhattanToTile(accept.loc, prod.loc);
|
local actual_dist = GSTile.GetDistanceManhattanToTile(accept.loc, prod.loc);
|
||||||
if (actual_dist > distance * 2) continue; // Too far away, skip.
|
if (actual_dist > distance * 2) continue; // Too far away, skip.
|
||||||
@@ -326,6 +340,7 @@ function BusyBeeClass::FillMonitors(cmon)
|
|||||||
foreach (ind_id, _ in rmon.ind) {
|
foreach (ind_id, _ in rmon.ind) {
|
||||||
local amount = GSCargoMonitor.GetIndustryDeliveryAmount(comp_id, cargo_id, ind_id, true);
|
local amount = GSCargoMonitor.GetIndustryDeliveryAmount(comp_id, cargo_id, ind_id, true);
|
||||||
rmon.ind[ind_id] = amount;
|
rmon.ind[ind_id] = amount;
|
||||||
|
// Dump received amount of cargo of an industry.
|
||||||
// local text = "Industry " + GSIndustry.GetName(ind_id) + " received " + amount +
|
// local text = "Industry " + GSIndustry.GetName(ind_id) + " received " + amount +
|
||||||
// " units for company " + comp_id +
|
// " units for company " + comp_id +
|
||||||
// ", cargo " + GSCargo.GetCargoLabel(cargo_id);
|
// ", cargo " + GSCargo.GetCargoLabel(cargo_id);
|
||||||
@@ -336,6 +351,7 @@ function BusyBeeClass::FillMonitors(cmon)
|
|||||||
foreach (town_id, _ in rmon.town) {
|
foreach (town_id, _ in rmon.town) {
|
||||||
local amount = GSCargoMonitor.GetTownDeliveryAmount(comp_id, cargo_id, town_id, true);
|
local amount = GSCargoMonitor.GetTownDeliveryAmount(comp_id, cargo_id, town_id, true);
|
||||||
rmon.town[town_id] = amount;
|
rmon.town[town_id] = amount;
|
||||||
|
// Dump received amount of cargo of a town.
|
||||||
// local text = "Town " + GSTown.GetName(town_id) + " received " + amount +
|
// local text = "Town " + GSTown.GetName(town_id) + " received " + amount +
|
||||||
// " units for company " + comp_id +
|
// " units for company " + comp_id +
|
||||||
// ", cargo " + GSCargo.GetCargoLabel(cargo_id);
|
// ", cargo " + GSCargo.GetCargoLabel(cargo_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user