rheirman / WhatTheHack

Mechanoid hacking
16 stars 18 forks source link

Fix issue where errors would be thrown for creating 10 jobs in 10 ticks if a pawn was using a control belt and commanded the mech to move. #23

Closed diddily closed 5 years ago

diddily commented 5 years ago

What is happening is the pawn would be told to follow (via JobDriver_ControlMechanoid_Goto) until it is within radius / 2, at which point it'll stop moving and maintain stature. Then JobGiver_ControlMechanoid_Follow will run, see the mech is moving and the pawn is outside the range of the destination, so it would not early out and immediately would start a new JobDriver_ControlMechanoid_Goto. Since the pawn is still within radius / 2, that job will immediately stop again and this cycle will repeat for a while, throwing an error.

This condition: (!followee.pather.Moving || (float)followee.pather.Destination.Cell.DistanceToSquared(pawn.Position) <= radius * radius) seems unnecessary in practice since you'd have to be within the radius to issue a move command to the controlled mech, so I removed that and it resolves the issue. If the conditional is important, adding a check of pawn distance to mech <= radius / 2 to it also resolves the issue.

rheirman commented 5 years ago

Thanks for helping out. I think you're right! I've accepted the PR.