Exemplo n.º 1
0
        public override void Parse(string line, TranspilerContext context)
        {
            context.UsingVolatileGoal(gathererGoal =>
            {
                context.UsingVolatileGoal(farmGoal =>
                {
                    var infoRule = new Defrule(
                        new[]
                    {
                        "true",
                    },
                        new[]
                    {
                        $"up-get-fact unit-type-count villager {gathererGoal}",
                        $"up-modify-goal {gathererGoal} s:* sn-food-gatherer-percentage",
                        $"up-modify-goal {gathererGoal} c:/ 100",
                        $"up-get-fact building-type-count-total farm {farmGoal}",
                    });

                    var buildRule = new Defrule(
                        new[]
                    {
                        $"up-compare-goal {farmGoal} g:< {gathererGoal}",
                        "can-build farm",
                    },
                        new[]
                    {
                        "build farm"
                    });

                    context.AddToScript(context.ApplyStacks(infoRule));
                    context.AddToScript(context.ApplyStacks(buildRule));
                });
            });
        }
Exemplo n.º 2
0
        protected (IEnumerable <Defrule> Rules, Dictionary <int, string> GoalToResourceMap) CreateNonEscrowedResourceGoals(TranspilerContext context, IEnumerable <string> resources)
        {
            var rules             = new List <Defrule>();
            var goalToResourceMap = new Dictionary <int, string>();

            context.UsingVolatileGoal(escrowAmountGoal =>
            {
                foreach (var resource in resources)
                {
                    var nonEscrowedAmountGoal = context.CreateVolatileGoal();

                    rules.Add(new Defrule(
                                  new[]
                    {
                        "true",
                    },
                                  new[]
                    {
                        $"up-get-fact resource-amount {resource} {nonEscrowedAmountGoal}",
                        $"up-get-fact escrow-amount {resource} {escrowAmountGoal}",
                        $"up-modify-goal {nonEscrowedAmountGoal} g:- {escrowAmountGoal}",
                    }));

                    goalToResourceMap[nonEscrowedAmountGoal] = resource;
                }
            });

            return(rules, goalToResourceMap);
        }
Exemplo n.º 3
0
        public override void Parse(string line, TranspilerContext context)
        {
            var data       = GetData(line);
            var findType   = data["findtype"].Value;
            var playerType = data["playertype"].Value;

            var rule = new Defrule();

            if (findType != "winning")
            {
                context.UsingVolatileGoal(goal =>
                {
                    rule.Actions.Add(new Action($"up-find-player {playerType} find-{FindTypes[findType]} {goal}"));
                    rule.Actions.Add(new Action($"up-modify-sn sn-target-player-number g:= {goal}"));
                });
            }
            else
            {
                rule.Actions.Add(new Action("set-strategic-number sn-target-player-number 0"));
            }

            context.AddToScript(context.ApplyStacks(rule));
        }