public override void Parse(string line, TranspilerContext context) { var data = GetData(line); var resources = data["resourcelist"].Value .ReplaceIfNullOrEmpty("wood and food and gold") .Replace("all", "wood and food and gold and stone") .Split(" and "); var threshold = data["threshold"].Value.ReplaceIfNullOrEmpty("300"); var interval = data["time"].Value.ReplaceIfNullOrEmpty("60"); var rules = new List <Defrule>(); var timer = context.CreateTimer(); rules.Add(new Defrule(new[] { "true" }, new[] { $"enable-timer {timer} {interval}", "disable-self" })); (var escrowRules, var goalToResourceMap) = CreateNonEscrowedResourceGoals(context, resources); rules.AddRange(escrowRules); foreach (var rule in GetBalanceRules(8, int.Parse(threshold), goalToResourceMap, goalToResourceMap.Keys)) { rule.Conditions.Add(new Condition($"timer-triggered {timer}")); rules.Add(rule); } rules.Add(new Defrule(new[] { $"timer-triggered {timer}" }, new[] { $"disable-timer {timer}", $"enable-timer {timer} {interval}" })); context.AddToScript(context.ApplyStacks(rules)); context.FreeVolatileGoals(goalToResourceMap.Keys); }
public override void Parse(string line, TranspilerContext context) { var data = GetData(line); var amount = data["amount"].Value; var resourceList = data["resourcelist"].Value .ReplaceIfNullOrEmpty("wood and food and gold and stone") .Split(" and "); var rules = new List <Defrule>(); (var escrowRules, var goalToResourceMap) = CreateNonEscrowedResourceGoals(context, resourceList); foreach (var(resourceGoal, resource) in goalToResourceMap) { if (resource == "gold") { continue; } rules.Add(new Defrule( new[] { $"up-compare-goal {resourceGoal} c:> {amount}", $"can-sell-commodity {resource}" }, new[] { $"sell-commodity {resource}" })); } if (resourceList.Contains("gold")) { var goldGoal = goalToResourceMap.First(x => x.Value == "gold").Key; foreach (var rule in rules) { rule.Conditions.Add(new Condition($"up-compare-goal {goldGoal} c:< {amount}")); } foreach (var(resourceGoal, resource) in goalToResourceMap) { if (resource == "gold") { continue; } rules.Add(new Defrule( new[] { $"up-compare-goal {resourceGoal} c:< {amount}", $"up-compare-goal {goldGoal} c:> {amount}", $"can-buy-commodity {resource}" }, new[] { $"buy-commodity {resource}" })); } } rules.InsertRange(0, escrowRules); context.AddToScript(context.ApplyStacks(rules)); context.FreeVolatileGoals(goalToResourceMap.Keys); }
public override void Parse(string line, TranspilerContext context) { var data = GetData(line); var civilianTotal = data["villamount"].Value; var tradeAmount = data["tradeamount"].Value; var useEscrow = data["useescrow"].Success; var rules = new List <Defrule>(); var villagerTargetGoal = context.CreateVolatileGoal(); var currentVillagersGoal = context.CreateVolatileGoal(); var currentPopulationGoal = context.CreateVolatileGoal(); var populationRemainingGoal = context.CreateVolatileGoal(); rules.Add(new Defrule( new[] { "true", }, new[] { $"up-get-fact unit-type-count-total villager {currentVillagersGoal}", $"set-goal {villagerTargetGoal} {civilianTotal}", })); rules.Add(new Defrule( new[] { "players-building-type-count any-ally market >= 1", }, new[] { $"up-modify-goal {villagerTargetGoal} c:- {tradeAmount}", })); rules.Add(new Defrule( new[] { "can-train villager", $"up-compare-goal {currentVillagersGoal} g:< {villagerTargetGoal}", }, new[] { "train villager", })); rules.Add(new Defrule( new[] { "players-building-type-count any-ally market >= 1", "can-build market", "building-type-count-total market < 2", }, new[] { "build market", })); if (useEscrow) { rules.Add(new Defrule( new[] { "players-building-type-count any-ally market >= 1", "can-research-with-escrow ri-caravan", }, new[] { "release-escrow food", "release-escrow gold", "research ri-caravan", })); } else { rules.Add(new Defrule( new[] { "players-building-type-count any-ally market >= 1", "can-research ri-caravan", }, new[] { "research ri-caravan", })); } rules.Add(new Defrule( new[] { "players-building-type-count any-ally market >= 1", $"unit-type-count {Game.DeadTradeCartId} == 0", $"unit-type-count {Game.DeadLoadedTradeCartId} == 0", "can-train trade-cart", $"unit-type-count-total trade-cart < {tradeAmount}", }, new[] { "train trade-cart", })); rules.Add(new Defrule( new[] { "true", }, new[] { $"up-get-fact population 0 {currentPopulationGoal}", $"up-get-fact population-cap 0 {populationRemainingGoal}", $"up-modify-goal {populationRemainingGoal} g:- {currentPopulationGoal}", })); rules.Add(new Defrule( new[] { $"up-compare-goal {populationRemainingGoal} c:< 10", $"civilian-population >= {civilianTotal}", }, new[] { "delete-unit villager", })); context.AddToScript(context.ApplyStacks(rules)); context.FreeVolatileGoals(new[] { villagerTargetGoal, currentVillagersGoal, currentPopulationGoal, populationRemainingGoal }); }