namespace ReactorMaintenance.Simulation; public sealed record JunctionFlow { public GridPosition Position { get; init; } = new(0, 0); public PropState Prop { get; init; } = new(); public ECarrierType Carrier { get; init; } public IReadOnlyList Branches { get; init; } = Array.Empty(); public GridPosition? IncomingBranch { get; init; } public IReadOnlyList OutgoingBranches { get; init; } = Array.Empty(); public IReadOnlyList Errors { get; init; } = Array.Empty(); public bool IsValid => Errors.Count == 0; public float WeightFor(GridPosition outgoingBranch) { var index = IndexOfOutgoingBranch(outgoingBranch); if (index < 0) return 0; var weights = Balancing.Current.JunctionWeights(OutgoingBranches.Count, Prop.JunctionMode); return index < weights.Length ? weights[index] : 0; } private int IndexOfOutgoingBranch(GridPosition outgoingBranch) { for (var i = 0; i < OutgoingBranches.Count; i++) { if (OutgoingBranches[i] == outgoingBranch) return i; } return -1; } }