public Squad(IBot bot, SquadManagerBotModule squadManager, SquadType type, Actor target) { Bot = bot; SquadManager = squadManager; World = bot.Player.PlayerActor.World; Random = World.LocalRandom; Type = type; Target = Target.FromActor(target); FuzzyStateMachine = new StateMachine(); switch (type) { case SquadType.Assault: case SquadType.Rush: FuzzyStateMachine.ChangeState(this, new GroundUnitsIdleState(), true); break; case SquadType.Air: FuzzyStateMachine.ChangeState(this, new AirIdleState(), true); break; case SquadType.Protection: FuzzyStateMachine.ChangeState(this, new UnitsForProtectionIdleState(), true); break; case SquadType.Naval: FuzzyStateMachine.ChangeState(this, new NavyUnitsIdleState(), true); break; } }
public static Squad Deserialize(IBot bot, SquadManagerBotModule squadManager, MiniYaml yaml) { var type = SquadType.Rush; Actor targetActor = null; var typeNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Type"); if (typeNode != null) { type = FieldLoader.GetValue <SquadType>("Type", typeNode.Value.Value); } var targetNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Target"); if (targetNode != null) { targetActor = squadManager.World.GetActorById(FieldLoader.GetValue <uint>("ActiveUnits", targetNode.Value.Value)); } var squad = new Squad(bot, squadManager, type, targetActor); var unitsNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Units"); if (unitsNode != null) { squad.Units.AddRange(FieldLoader.GetValue <uint[]>("Units", unitsNode.Value.Value) .Select(a => squadManager.World.GetActorById(a))); } return(squad); }
void INotifyCreated.Created(Actor self) { ai = self.Owner.PlayerActor.TraitsImplementing <SquadManagerBotModule>().FirstOrDefault(Exts.IsTraitEnabled); }
public Squad(IBot bot, SquadManagerBotModule squadManager, SquadType type) : this(bot, squadManager, type, null) { }
void IBotTick.BotTick(IBot bot) { if (--scanForBitsTicks > 0) { return; } scanForBitsTicks = Info.ScanInterval; var bits = world.ActorsHavingTrait <ColonyBit>().ToList(); if (!bits.Any()) { return; } if (Info.CheckTargetsForVisibility) { bits.RemoveAll(c => !c.CanBeViewedByPlayer(player)); } var units = world.ActorsHavingTrait <Mobile>().Where(a => a.Owner == player && a.IsIdle && (Info.IncludedUnitTypes.Contains(a.Info.Name) || (!Info.IncludedUnitTypes.Any() && !Info.ExcludedUnitTypes.Contains(a.Info.Name)))).ToList(); if (!units.Any()) { return; } foreach (var bit in bits) { var bitCollector = units.ClosestTo(bit); if (bitCollector == null) { continue; } if ((bit.Location - bitCollector.Location).Length > maxProximity) { continue; } units.Remove(bitCollector); if (squadManagerBotModule == null) { squadManagerBotModule = bot.Player.PlayerActor.TraitsImplementing <SquadManagerBotModule>().FirstEnabledTraitOrDefault(); } if (squadManagerBotModule != null) { // You got ONE job! var squad = squadManagerBotModule.Squads.FirstOrDefault(s => s.Units.Contains(bitCollector)); if (squad != null) { squad.Units.Remove(bitCollector); } } var target = Target.FromCell(world, bit.Location); AIUtils.BotDebug("AI: Ordering unit {0} to {1} for colony bit pick up.".F(bitCollector, target)); bot.QueueOrder(new Order("Stop", bitCollector, false)); bot.QueueOrder(new Order("Move", bitCollector, target, false)); } }