I just saw your change to the code - honestly I tried the same thing.
if ( possibleTarget.ActiveOutflows[MetalFlowPurpose.SelfConstruction] )
{
#region Tracing
if ( tracing ) traceBuffer.Add( ":" ).Add( "Skipping because this structure is under construction" );
#endregion
return DelReturn.Continue;
}
The problem I ran into is that if you put your construction into hold fire mode, your ships will stop constructing it and will instead start healing it because X.ActiveOutflows[MetalFlowPurpose.SelfConstruction] is now false/null. I just tested it again and it indeed occurs, this could be bad if you had some larger construction like a fortress hogging your metal while being constructed - your metal flows would still be tied up because a bunch of engineers will repair it instead of doing other things.
This is my solution, but I assume it's very ugly:
if ( possibleTarget.ComputeDisabledReason(ArcenRejectionReason.EntityIsInHoldFireMode) == ArcenRejectionReason.EntityIsSelfBuilding)
{
return DelReturn.Continue;
}
I have no idea how to check for a specific disabled reason, I assume that each unit has an array of bool for all of the possible reasons. This way works in the simplest case of either SelfBuilding or HoldFire, but might fail if for instance the construction got hit with a paralyzer shot.