예제 #1
0
    /// <summary>
    /// Moves along the build chain skipping units until it finds the matching unit.
    /// If it is the target unit, returns build actions for it, if no, pass the rest of the chain to each child and returns merged actions.
    /// </summary>
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(SkipTillUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                for (var i = 0; i < buildChain.Length; i++)
                {
                    var unitInfo = buildChain[i];

                    var isPatternMatches = UnitPattern.Matches(unitInfo);
                    if (isPatternMatches)
                    {
                        Log.WriteLine(LogLevel.Verbose, LogConst.Matched, true);
                        hasActions = GetOwnOrChildrenBuildActions(buildChain.GetTail(i), inputWeight, out actionBag);
                        return(hasActions);
                    }
                }

                Log.WriteLine(LogLevel.Trace, LogConst.Matched, false);
            }

        actionBag = null;
        return(false);
    }
예제 #2
0
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, that's the point
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(SkipAllUnits)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Weight = {Weight.ToHoconString()}");
                var targetUnit = buildChain.GetTail(buildChain.Length - 1);

                var decreaseWeight = (buildChain.Length - 1) * Weight;
                hasActions = GetChildrenActions(targetUnit, inputWeight + decreaseWeight, out actionBag);
                return(hasActions);
            }
    }
예제 #3
0
    protected bool GetOwnOrChildrenBuildActions(BuildChain buildChain, int inputWeight, out WeightedBuildActionBag?actionBag)
    {
        var result = false;

        actionBag = null;

        if (buildChain.Length > 1)
        { // pass the rest of the chain to children and return their actions
            result = GetChildrenActions(buildChain.GetTail(1), inputWeight, out actionBag);
        }
        else
        { // this patterns matches the target unit, return actions for it
            result = GetOwnBuildActions(inputWeight, out actionBag);
            actionBag.WriteToLog(LogLevel.Verbose, "Actions: ");
        }

        return(result);
    }
예제 #4
0
    public override bool GatherBuildActions(BuildChain buildChain, out WeightedBuildActionBag?actionBag, int inputWeight)
    {
        var hasActions = false;

        // ReSharper disable once AccessToModifiedClosure - yes, I need it to be captured
        using (Log.ConditionalMode(LogLevel.Verbose, () => hasActions))
            using (Log.NamedBlock(LogLevel.Verbose, nameof(SkipWhileUnit)))
            {
                Log.WriteLine(LogLevel.Verbose, () => $"Pattern = {UnitPattern.ToHoconString()}, Weight = {Weight.ToHoconString()}");

                var i = 0;
                for (; i < buildChain.Length - 1; i++) // target unit is not the subject of skipping
                {
                    if (!UnitPattern.Matches(buildChain[i]))
                    {
                        break;
                    }
                }

                hasActions = GetChildrenActions(buildChain.GetTail(i), inputWeight, out actionBag);
                return(hasActions);
            }
    }