AI.JobGiver.WorkRoot doesn't always return optimal work location?

Started by pawnstorm, May 19, 2014, 06:43:10 AM

Previous topic - Next topic

pawnstorm

In AI.JobGiver.WorkRoot.TryGiveTerminalJob(Pawn pawn), there's this piece of code according to ILSpy:

IntVec3 position = pawn.Position;
float num2 = 99999f;
foreach (IntVec3 current2 in giver.PotentialWorkLocs)
{
if ((current2 - position).LengthHorizontalSquared < num2 && giver.StartingJobOn(pawn, current2) != null)
{
targetPack = current2;
workGiver = giver;
}
}


Shouldn't it instead be something like this, so that it will always return the closest work location?

IntVec3 position = pawn.Position;
float num2 = 99999f;
foreach (IntVec3 current2 in giver.PotentialWorkLocs)
{
float num3 = (current2 - position).LengthHorizontalSquared;
if (num3 < num2 && giver.StartingJobOn(pawn, current2) != null)
{
targetPack = current2;
workGiver = giver;
num2 = num3;
}
}


Edit: Also, not relevant to alpha 3 since there are no workgivers that it applies to, but if one workgiver class can have both PotentialWorkThings aswell as PotentialWorkLocs, maybe if it finds a work thing before it starts checking for work locations, num2 should initially be set to "(thing.Position - pawn.Position).LengthHorizontalSquared" instead of 99999f.