Ok here is the code thats causing the problems...
Attachment:
pathzilla.tar [651 KiB]
Downloaded 53 times
I've managed to narrow down at least one problem. I have commented out some code to emphasize whats going on.
In the main loop in the
Start() function the method
ServiceManager.FindNewServices() is called. In there I have commented out most of everything except the following snippet...
Code:
targets.Filter(function (target, cargo) {
return !target.ProducesCargo(cargo);
}, cargo);
If I also comment out this the error goes away. Note that the Sleep() call that triggers the error is not connected to this code in any way... it just follows it.
targets is an instance of
Map which has the following
Filter() method, which uses
acall.
Code:
function Map::Filter(filterFn, ...) {
// Build an array of arguments for the filter function
local argv = [];
for(local i = 0; i < vargc; i++) {
argv.append(vargv[i]);
}
// Select the keys for items to be removed
local toRemove = [];
foreach(key, item in this.data) {
local args = [this, item];
args.extend(argv);
if(filterFn.acall(args)) {
toRemove.append(key);
}
}
// Remove them
foreach(r in toRemove) {
this.RemoveKey(r);
}
}So the
ProducesCargo() method is called from within an
acall...
Code:
function Target::ProducesCargo(cargo) {
// Pre-condition - Check that the target is still valid
if(!this.IsValid()) return false;
// If the target is a town check each tile in its influence for production
if(this.type == Target.TYPE_TOWN) {
if(AICargo.GetTownEffect(cargo) == AICargo.TE_NONE) return false;
local searchRadius = min(AIMap.DistanceFromEdge(this.tile) - 1, PathZilla.MAX_TOWN_RADIUS);
local offset = AIMap.GetTileIndex(searchRadius, searchRadius);
local tileList = AITileList();
tileList.AddRectangle(this.tile - offset, this.tile + offset);
tileList.Valuate(function(tile, id) {
return AITown.IsWithinTownInfluence(id, tile);
}, this.id);
tileList.KeepValue(1);
tileList.Valuate(function(tile, cargo) {
return AITile.GetCargoProduction(tile, cargo, 1, 1, 0);
}, cargo);
return ListSum(tileList) > 0;
}
// Otherwise check the list of cargos for the appropriate industry type
local indType = AIIndustry.GetIndustryType(this.id);
if(!AIIndustryType.IsValidIndustryType(indType)) return false;
return AIIndustryType.GetProducedCargo(indType).HasItem(cargo);
}However this method doesn't Sleep or have any DoCommands. There are two things about this that confused me.
1) Why in an error thrown when I call Sleep(), when the error seems to be linked to an acall elsewehere?
2) Why is the acall triggering the error?
Is it the code within the acall, or just he use of acall itself? Am I allowed to use acall at all anymore?
I suppose I can get around this with Yexo's thingy, but I prefer to fix the root cause (if possible) or at least understand why this is going wrong.
Thanks very much guys
