public VariantAI(StrategyGame game, int team, Color teamColour, Ship.ShipEventHandler shipHandler) : base(game, team, teamColour, shipHandler) { _scouting = new ScoutingMission(game, this, _shipHandler); _minerOffense = new MinerOffenseMission(game, this, shipHandler); _mining = new MinerMission(game, this, shipHandler); _building = new BuilderMission(game, this, shipHandler); _baseOffense = new BombingMission(game, this, shipHandler); _minerDefense = new MinerDefenseMission(game, this, shipHandler); _baseDefense = new BaseDefenseMission(game, this, shipHandler); if (StrategyGame.RandomChance(0.5f)) { _initTech = EInitialTargetTech.ChooseInSector; } else { _initTech = (StrategyGame.RandomChance(0.75f)) ? EInitialTargetTech.Starbase : EInitialTargetTech.Shipyard; } _focusBuildOrder = StrategyGame.RandomChance(0.95f); // Play test a specific focus: //_initTech = EInitialTargetTech.Shipyard; //_focusBuildOrder = true; _initTechName = Enum.GetName(typeof(EInitialTargetTech), _initTech); }
private void TryToInvestInBases(List <TechItem> consCanBuild, List <int> ourSectors) { if (ourSectors.Count >= _game.Map.Sectors.Count - 1) { return; } var found = false; var loopCount = 0; var techCons = consCanBuild.Where(_ => _.Name.Contains("Expansion") || _.Name.Contains("Supremacy") || _.Name.Contains("Tactical") || _.Name.Contains("Shipyard")).ToList(); var baseCons = consCanBuild.Where(_ => _.Name.Contains("Outpost") || _.Name.Contains("Starbase")).ToList(); if (techCons.Count == 0 && baseCons.Count == 0) { return; } // Build an Outpost/Starbase/Techbase/Shipyard while (!found && loopCount < 10) { loopCount++; TechItem con = null; if (!_flagBuiltTech && techCons.Count > 0) { con = techCons[StrategyGame.Random.Next(techCons.Count)]; } else { if (StrategyGame.RandomChance(0.5f) && baseCons.Count > 0) { con = baseCons[0]; } else if (techCons.Count > 0) { con = techCons[0]; } } if (con == null) { continue; } var remaining = con.Cost - con.AmountInvested; if (remaining <= 0) { continue; } var invested = _game.SpendCredits(Team, remaining); con.AmountInvested += invested; found = true; } }
public override bool AddMorePilots() { if (_launchBase == null || _targetBase == null || !_launchBase.Active || !_targetBase.Active || _targetBase.Alliance == AI.Alliance || _launchBase.Team != AI.Team) { CheckForNewTarget(); } if (_launchBase == null || _targetBase == null) { return(false); } // Send any cap ships for support var capships = _game.AllUnits.Where(_ => _.Active && _.Team == AI.Team && Ship.IsCapitalShip(_.Type) && _.CurrentOrder == null).ToList(); IncludedShips.AddRange(capships); Ship ship; var t = AI.Team - 1; ship = _game.Ships.CreateBomberShip(AI.Team, AI.TeamColour, _launchBase.SectorId); if (ship == null) { if (StrategyGame.RandomChance(0.3f)) { ship = _game.Ships.CreateCombatShip(AI.Team, AI.TeamColour, _launchBase.SectorId); } else { ship = _game.Ships.CreateCombatShip(Keys.S, AI.Team, AI.TeamColour, _launchBase.SectorId); } } if (ship == null) { return(false); } if (!_game.LaunchShip(ship)) { return(false); } ship.CenterX = _launchBase.CenterX; ship.CenterY = _launchBase.CenterY; var pos = _launchBase.GetNextBuildPosition(); ship.ShipEvent += _shipHandler; ship.OrderShip(new MoveOrder(_game, _launchBase.SectorId, pos, Point.Empty)); IncludedShips.Add(ship); return(true); }
public virtual void ReducePilots(float chance) { var dockedShips = new List <Ship>(); foreach (var s in IncludedShips) { if (StrategyGame.RandomChance(chance)) { s.OrderShip(new DockOrder(_game, s)); LogOrder(); dockedShips.Add(s); } } if (dockedShips.Count > 0) { IncludedShips.RemoveAll(dockedShips.Contains); } }
public override bool AddMorePilots() { if (_shipsToProtect.Count == 0) { return(false); } var s = _shipsToProtect[StrategyGame.Random.Next(_shipsToProtect.Count)]; var launchBase = _game.ClosestSectorWithBase(AI.Team, s.SectorId); if (launchBase == null) { return(false); } Ship ship = null; // launch scouts and our best pilotable combat ships if (StrategyGame.RandomChance(0.5f)) { ship = _game.Ships.CreateCombatShip(Keys.S, AI.Team, AI.TeamColour, launchBase.SectorId); } else { ship = _game.Ships.CreateCombatShip(AI.Team, AI.TeamColour, launchBase.SectorId); } if (ship == null) { return(false); } ship.CenterX = launchBase.CenterX; ship.CenterY = launchBase.CenterY; var pos = launchBase.GetNextBuildPosition(); ship.ShipEvent += _shipHandler; ship.OrderShip(new MoveOrder(_game, launchBase.SectorId, pos, Point.Empty)); IncludedShips.Add(ship); _game.LaunchShip(ship); return(true); }
public override bool RequireMorePilots() { return(StrategyGame.RandomChance(0.75f)); }