-
-
Save SamuXarick/c635c30588208fd67ea1eb618d9520fd to your computer and use it in GitHub Desktop.
number of wagons in the wagon chain mismatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local cargo = Utils.getCargoId(m_cargoClass); | |
/* Check if we have money first to buy entire parts */ | |
local cost = AIAccounting(); | |
AITestMode() && AIVehicle.BuildVehicleWithRefit(depot, this.m_engineWagonPair[0], cargo); | |
local num_wagons = this.m_engineWagonPair[2]; | |
while (num_wagons > 0) { | |
AITestMode() && AIVehicle.BuildVehicleWithRefit(depot, this.m_engineWagonPair[1], cargo); | |
num_wagons--; | |
} | |
if (Utils.HasMoney(cost.GetCosts())) { | |
new_vehicle = TestBuildVehicleWithRefit().TryBuild(depot, this.m_engineWagonPair[0], cargo); | |
if (AIVehicle.IsValidVehicle(new_vehicle)) { | |
local num_tries = this.m_engineWagonPair[2]; | |
local wagon_chain = AIVehicle.VEHICLE_INVALID; | |
local num_wagons = 0; | |
while (num_tries > 0) { | |
local wagon = TestBuildVehicleWithRefit().TryBuild(depot, this.m_engineWagonPair[1], cargo); | |
if (AIVehicle.IsValidVehicle(wagon) || AIVehicle.IsValidVehicle(wagon_chain)) { | |
// AILog.Info("wagon or wagon_chain is valid"); | |
if (!AIVehicle.IsValidVehicle(wagon_chain)) wagon_chain = wagon; | |
num_wagons = AIVehicle.GetNumWagons(wagon_chain); | |
num_tries--; | |
} else { | |
break; | |
} | |
} | |
if (num_wagons < this.m_engineWagonPair[2]) { | |
if (AIVehicle.IsValidVehicle(wagon_chain)) { | |
if (!AIVehicle.SellWagonChain(wagon_chain, 0)) { | |
// AILog.Info("Failed to sell wagon chain. Reason: missing wagons"); | |
} else { | |
// AILog.Info("Sold wagon chain. Reason: missing wagons"); | |
} | |
} | |
if (!AIVehicle.SellVehicle(new_vehicle)) { | |
// AILog.Info("Failed to sell train. Reason: missing wagons"); | |
} else { | |
new_vehicle = AIVehicle.VEHICLE_INVALID; | |
// AILog.Info("Sold train. Reason: missing wagons"); | |
} | |
} else { | |
// AILog.Info("new_vehicle = " + AIVehicle.IsValidVehicle(new_vehicle) + "; wagon_chain = " + AIVehicle.IsValidVehicle(wagon_chain)); | |
if (!AIVehicle.MoveWagonChain(wagon_chain, 0, new_vehicle, 0)) { | |
// AILog.Info("Failed to move wagon chain"); | |
if (!AIVehicle.SellWagonChain(wagon_chain, 0)) { | |
// AILog.Info("Failed to sell wagon chain. Reason: failed to move wagons"); | |
} else { | |
// AILog.Info("Sold wagon chain. Reason: failed to move wagons"); | |
} | |
if (!AIVehicle.SellVehicle(new_vehicle)) { | |
// AILog.Info("Failed to sell train. Reason: failed to move wagons"); | |
} else { | |
new_vehicle = AIVehicle.VEHICLE_INVALID; | |
// AILog.Info("Sold train. Reason: failed to move wagons"); | |
} | |
} else { | |
// AILog.Info("Wagon chain moved successfully"); | |
// AILog.Info("new_vehicle = " + AIVehicle.IsValidVehicle(new_vehicle) + "; wagon_chain = " + AIVehicle.IsValidVehicle(wagon_chain)); | |
// AILog.Info("number of wagons in new_vehicle = " + AIVehicle.GetNumWagons(new_vehicle)); | |
} | |
} | |
} | |
} |
Author
SamuXarick
commented
Mar 15, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment