protected override void Start() { base.Start(); // Utility AI setup // ****** VALUES ****** UAIV_AgentHealth agentHealth = new UAIV_AgentHealth(this, _AgentController._AgentStats.HealthPoints); UAIV_AgentFood agentFood = new UAIV_AgentFood(this, _AgentController._AgentStats.FoodPoints); UAIV_AgentEnergy agentEnergy = new UAIV_AgentEnergy(this, _AgentController._AgentStats.EnergyPoints); UAIV_MinePlaced minePlaced = new UAIV_MinePlaced(this, 1); UAIV_ResourceCount oreCount = new UAIV_ResourceCount(GameCache._Cache.GetData("Ore").tag, this, 1); UAIV_InventorySize inventorySize = new UAIV_InventorySize(this, _AgentController._Inventory._MaxInventorySize); UAIV_SoldierEnemyCount enemySoldierCount = new UAIV_SoldierEnemyCount(this, 3.0f); // ****** SCORERS ****** UtilityScorer scorer_AgentHealth = new UtilityScorer(agentHealth, _HealthCurve); UtilityScorer scorer_AgentFood = new UtilityScorer(agentFood, _FoodCurve); UtilityScorer scorer_AgentEnergy = new UtilityScorer(agentEnergy, _EnergyCurve); UtilityScorer scorer_OreBoolCheck = new UtilityScorer(minePlaced, _MinePlacedCurve); UtilityScorer scorer_OreCount = new UtilityScorer(oreCount, _OreCountCurve); UtilityScorer scorer_InventorySize = new UtilityScorer(inventorySize, _InventorySizeCurve); UtilityScorer scorer_enemySoldierThreatLevel = new UtilityScorer(enemySoldierCount, _EnemySoldierThreatCurve); // ****** ACTIONS ****** RoamAround roamAction_SearchOres = new RoamAround(this, 1.0f); roamAction_SearchOres.AddScorer(scorer_OreCount); roamAction_SearchOres.AddScorer(scorer_OreBoolCheck); MineOre mineOreAction = new MineOre(this, 0.5f); DeliverResources deliverResourceAction = new DeliverResources(GameCache._Cache.GetData("Mine").tag, this, 0.0f); deliverResourceAction.AddScorer(scorer_InventorySize); EatFood eatFoodAction = new EatFood(this, 0.0f); eatFoodAction.AddScorer(scorer_AgentFood); eatFoodAction.SetWeight(2); SleepAndRest sleepRestAction = new SleepAndRest("Mine", this, 0.0f); sleepRestAction.AddScorer(scorer_AgentEnergy); Hide hideAction = new Hide("Headquarters", this, 0.0f); hideAction.AddScorer(scorer_enemySoldierThreatLevel); hideAction.SetWeight(3); // ****** REGISTER ACTIONS ****** _AgentActions.Add(roamAction_SearchOres); _AgentActions.Add(mineOreAction); _AgentActions.Add(deliverResourceAction); _AgentActions.Add(eatFoodAction); _AgentActions.Add(sleepRestAction); _AgentActions.Add(hideAction); }
protected override void Start() { base.Start(); // Utility AI setup // ****** VALUES ****** UAIV_AgentHealth agentHealth = new UAIV_AgentHealth(this, _AgentController._AgentStats.HealthPoints); UAIV_AgentFood agentFood = new UAIV_AgentFood(this, _AgentController._AgentStats.FoodPoints); UAIV_AgentEnergy agentEnergy = new UAIV_AgentEnergy(this, _AgentController._AgentStats.EnergyPoints); UAIV_FarmPlaced farmPlaced = new UAIV_FarmPlaced(this, 1); UAIV_DistanceTo distanceToHQ = new UAIV_DistanceTo(_AgentController._PlayerOwner.GetBuilding_ByTag(GameCache._Cache.GetData("Headquarters").tag), this, 20); UAIV_InventorySize inventorySize = new UAIV_InventorySize(this, _AgentController._Inventory._MaxInventorySize); UAIV_SoldierEnemyCount enemySoldierCount = new UAIV_SoldierEnemyCount(this, 3.0f); // ****** SCORERS ****** UtilityScorer scorer_AgentHealth = new UtilityScorer(agentHealth, _HealthCurve); UtilityScorer scorer_AgentFood = new UtilityScorer(agentFood, _FoodCurve); UtilityScorer scorer_AgentEnergy = new UtilityScorer(agentEnergy, _EnergyCurve); UtilityScorer scorer_FarmBoolCheck = new UtilityScorer(farmPlaced, _FarmPlacedCurve); UtilityScorer scorer_DistanceToHQ = new UtilityScorer(distanceToHQ, _DistanceToHQCurve); UtilityScorer scorer_InventorySize = new UtilityScorer(inventorySize, _InventorySizeCurve); UtilityScorer scorer_enemySoldierThreatLevel = new UtilityScorer(enemySoldierCount, _EnemySoldierThreatCurve); // ****** ACTIONS ****** RoamAround roamAction_SearchFarmSpot = new RoamAround(this, 0.0f); roamAction_SearchFarmSpot.AddScorer(scorer_DistanceToHQ); roamAction_SearchFarmSpot.AddScorer(scorer_FarmBoolCheck); FarmField farmFieldAction = new FarmField(this, 0.5f); DeliverResources deliverResourceAction = new DeliverResources(GameCache._Cache.GetData("Headquarters").tag, this, 0.0f); deliverResourceAction.AddScorer(scorer_InventorySize); EatFood eatFoodAction = new EatFood(this, 0.0f); eatFoodAction.AddScorer(scorer_AgentFood); eatFoodAction.SetWeight(2); SleepAndRest sleepRestAction = new SleepAndRest("Field", this, 0.0f); sleepRestAction.AddScorer(scorer_AgentEnergy); Hide hideAction = new Hide("Headquarters", this, 0.0f); hideAction.AddScorer(scorer_enemySoldierThreatLevel); hideAction.SetWeight(3); // ****** REGISTER ACTIONS ****** _AgentActions.Add(roamAction_SearchFarmSpot); _AgentActions.Add(farmFieldAction); _AgentActions.Add(deliverResourceAction); _AgentActions.Add(eatFoodAction); _AgentActions.Add(sleepRestAction); _AgentActions.Add(hideAction); }
public void OnDock(Actor harv, DeliverResources dockOrder) { if (!preventDock) { dockOrder.QueueChild(new CallFunc(() => dockedHarv = harv, false)); dockOrder.QueueChild(DockSequence(harv, self)); dockOrder.QueueChild(new CallFunc(() => dockedHarv = null, false)); } }
public void OnDock(Actor harv, DeliverResources dockOrder) { if (!preventDock) { harv.QueueActivity(new CallFunc(() => dockedHarv = harv, false)); harv.QueueActivity(DockSequence(harv, self)); harv.QueueActivity(new CallFunc(() => dockedHarv = null, false)); } harv.QueueActivity(new CallFunc(() => harv.Trait <Harvester>().ContinueHarvesting(harv))); }
public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Harvest") { // NOTE: An explicit harvest order allows the harvester to decide which refinery to deliver to. LinkProc(self, OwnerLinkedProc = null); idleSmart = true; self.CancelActivity(); CPos?loc; if (order.TargetLocation != CPos.Zero) { // Find the nearest claimable cell to the order location (useful for group-select harvest): loc = mobile.NearestCell(order.TargetLocation, p => mobile.CanEnterCell(p) && claimLayer.TryClaimCell(self, p), 1, 6); } else { // A bot order gives us a CPos.Zero TargetLocation. loc = self.Location; } var findResources = new FindResources(self); self.QueueActivity(findResources); self.SetTargetLine(Target.FromCell(self.World, loc.Value), Color.Red); foreach (var n in notify) { n.MovingToResources(self, loc.Value, findResources); } LastOrderLocation = loc; // This prevents harvesters returning to an empty patch when the player orders them to a new patch: LastHarvestedCell = LastOrderLocation; } else if (order.OrderString == "Deliver") { // NOTE: An explicit deliver order forces the harvester to always deliver to this refinery. var iao = order.TargetActor.TraitOrDefault <IAcceptResources>(); if (iao == null || !iao.AllowDocking || !IsAcceptableProcType(order.TargetActor)) { return; } if (order.TargetActor != OwnerLinkedProc) { LinkProc(self, OwnerLinkedProc = order.TargetActor); } idleSmart = true; self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green); self.CancelActivity(); var deliver = new DeliverResources(self); self.QueueActivity(deliver); foreach (var n in notify) { n.MovingToRefinery(self, order.TargetLocation, deliver); } } else if (order.OrderString == "Stop" || order.OrderString == "Move") { foreach (var n in notify) { n.MovementCancelled(self); } // Turn off idle smarts to obey the stop/move: idleSmart = false; } }
public void ResolveOrder(Actor self, Order order) { if (order.OrderString == "Harvest") { // NOTE: An explicit harvest order allows the harvester to decide which refinery to deliver to. LinkProc(self, OwnerLinkedProc = null); idleSmart = true; self.CancelActivity(); if (order.TargetLocation != CPos.Zero) { var loc = order.TargetLocation; var territory = self.World.WorldActor.TraitOrDefault <ResourceClaimLayer>(); if (territory != null) { // Find the nearest claimable cell to the order location (useful for group-select harvest): loc = mobile.NearestCell(loc, p => mobile.CanEnterCell(p) && territory.ClaimResource(self, p), 1, 6); } else { // Find the nearest cell to the order location (useful for group-select harvest): var taken = new HashSet <CPos>(); loc = mobile.NearestCell(loc, p => mobile.CanEnterCell(p) && taken.Add(p), 1, 6); } self.QueueActivity(mobile.MoveTo(loc, 0)); self.SetTargetLine(Target.FromCell(self.World, loc), Color.Red); var notify = self.TraitsImplementing <INotifyHarvesterAction>(); var next = new FindResources(self); foreach (var n in notify) { n.MovingToResources(self, loc, next); } LastOrderLocation = loc; } else { // A bot order gives us a CPos.Zero TargetLocation, so find some good resources for him: var loc = FindNextResourceForBot(self); // No more resources? Oh well. if (!loc.HasValue) { return; } self.QueueActivity(mobile.MoveTo(loc.Value, 0)); self.SetTargetLine(Target.FromCell(self.World, loc.Value), Color.Red); LastOrderLocation = loc; } // This prevents harvesters returning to an empty patch when the player orders them to a new patch: LastHarvestedCell = LastOrderLocation; self.QueueActivity(new FindResources(self)); } else if (order.OrderString == "Deliver") { // NOTE: An explicit deliver order forces the harvester to always deliver to this refinery. var iao = order.TargetActor.TraitOrDefault <IAcceptResources>(); if (iao == null || !iao.AllowDocking || !IsAcceptableProcType(order.TargetActor)) { return; } if (order.TargetActor != OwnerLinkedProc) { LinkProc(self, OwnerLinkedProc = order.TargetActor); } if (IsEmpty) { return; } idleSmart = true; self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green); self.CancelActivity(); var next = new DeliverResources(self); self.QueueActivity(next); var notify = self.TraitsImplementing <INotifyHarvesterAction>(); foreach (var n in notify) { n.MovingToRefinery(self, order.TargetLocation, next); } } else if (order.OrderString == "Stop" || order.OrderString == "Move") { var notify = self.TraitsImplementing <INotifyHarvesterAction>(); foreach (var n in notify) { n.MovementCancelled(self); } // Turn off idle smarts to obey the stop/move: idleSmart = false; } }