コード例 #1
0
        public override void Update(Ship ship)
        {
            OrderComplete = true;

            // Atack any targets in this sector
            var targets = _game.AllUnits.Where(_ => _.Active && _.IsVisibleToTeam(ship.Team - 1) && _.SectorId == ship.SectorId && _.Alliance != ship.Alliance && _targetTypes.Contains(_.Type)).ToList();

            if (targets.Count() > 0)
            {
                var target = StrategyGame.RandomItem(targets);
                ship.OrderShip(new InterceptOrder(_game, target, ship.SectorId, true));
            }
            else
            {
                // Otherwise, continue the hunt in another sector!
                var visibleSectors = _game.Map.Sectors.Where(_ => _.IsVisibleToTeam(ship.Team - 1)).ToList();
                if (visibleSectors.Count < 2)
                {
                    return;
                }

                var randomSectorId = StrategyGame.RandomItem(visibleSectors).Id;

                ship.OrderShip(new NavigateOrder(_game, ship, randomSectorId), true);
                ship.OrderShip(new HuntControlOrder(_game, _targetTypes), true);
            }
        }
コード例 #2
0
        private void TryToInvestInResources(List <TechItem> consCanBuild, List <int> ourSectors)
        {
            var cons = consCanBuild.Where(_ => _.Name.Contains("Miner") || _.Name.Contains("Resource")).ToList();

            if (cons.Count == 0)
            {
                return;
            }

            var numResourceRocks = _game.ResourceAsteroids.Count(_ => _.Active && _.IsVisibleToTeam(_t) && ourSectors.Contains(_.SectorId));

            if (numResourceRocks == 0)
            {
                return;
            }

            var con = StrategyGame.RandomItem(cons);

            // Build something!
            var remaining = con.Cost - con.AmountInvested;

            if (remaining <= 0)
            {
                return;
            }

            var invested = _game.SpendCredits(Team, remaining);

            con.AmountInvested += invested;
        }
コード例 #3
0
        public override void Update(Ship ship)
        {
            if (_target != null && _target.Active && _target.SectorId == ship.SectorId)
            {
                OrderPosition = _target.CenterPoint;
                OrderSectorId = _target.SectorId;
            }
            else if (_changeTarget)
            {
                var targets = _game.AllUnits.Where(_ => _.Active && _.SectorId == ship.SectorId && _.Alliance == _target.Alliance && _.Type == _target.Type).ToList();
                if (targets.Count == 0)
                {
                    OrderComplete = true;
                    return;
                }

                _target = StrategyGame.RandomItem(targets);
            }
            else
            {
                OrderComplete = true;
                return;
            }

            base.Update(ship);

            if (OrderComplete && ship.Type == EShipType.Lifepod)
            {
                ship.Dock(null);
            }
            else if (OrderComplete && _target != null && _target.Active && _target.SectorId == ship.SectorId)
            {
                OrderComplete = false;
            }
        }
コード例 #4
0
        public override void Update(Ship ship)
        {
            OrderComplete = true;

            var visibleSectors = _game.Map.Sectors.Where(_ => _.IsVisibleToTeam(ship.Team - 1)).ToList();

            if (visibleSectors.Count < 2)
            {
                return;
            }

            // If we have stopped, keep scouting
            var randomSectorId = StrategyGame.RandomItem(visibleSectors).Id;

            ship.OrderShip(new NavigateOrder(_game, ship, randomSectorId), true);
            ship.OrderShip(new MoveOrder(_game, randomSectorId, StrategyGame.ScreenCenter, PointF.Empty), true);
            ship.OrderShip(new ScoutControlOrder(_game), true);
        }
コード例 #5
0
        public static void ProcessOrder(StrategyGame game, QuickChatItem cmd, MapSector sector, Ship.ShipEventHandler f_ShipEvent)
        {
            // TODO: Test!
            return;

            if (cmd == null || game == null || cmd.OrderAction == string.Empty)
            {
                return;
            }

            var order      = cmd.OrderAction;
            var team       = 1;
            var t          = team - 1;
            var alliance   = game.GameSettings.TeamAlliance[t];
            var pilotCount = game.DockedPilots[t];

            if (order.StartsWith("Attack"))
            {
                // All friendly combat ships in sector
                var ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.CanAttackShips()).ToList();
                if (ships.Count == 0)
                {
                    return;
                }

                if (order.EndsWith("Base"))
                {
                    var targetBases = game.AllBases.Where(_ => _.Active && _.SectorId != sector.Id && _.Alliance != alliance).ToList();
                    if (targetBases.Count == 0)
                    {
                        return;
                    }

                    var targetBase = StrategyGame.RandomItem(targetBases);
                    ships.ForEach(_ => _.OrderShip(new SurroundOrder(game, sector.Id, targetBase, PointF.Empty)));
                    return;
                }

                // if type in sector, attack it (rnd)
                var targetTypes = GetOrderTypes(order);
                var targets     = game.AllUnits.Where(_ => _.Active && _.IsVisibleToTeam(t) && _.Alliance != alliance && _.SectorId == sector.Id && targetTypes.Contains(_.Type)).ToList();

                var  append = false;
                Ship target = null;

                // if type spotted, navigate to it (rnd)
                if (targets.Count == 0)
                {
                    targets = game.AllUnits.Where(_ => _.Active && _.IsVisibleToTeam(t) && _.Alliance != alliance && targetTypes.Contains(_.Type)).ToList();
                    if (targets.Count == 0)
                    {
                        return;
                    }

                    append = true;
                    target = StrategyGame.RandomItem(targets);
                    ships.ForEach(_ => _.OrderShip(new NavigateOrder(game, _, target.SectorId)));
                }
                if (target == null)
                {
                    target = StrategyGame.RandomItem(targets);
                }

                ships.ForEach(_ => _.OrderShip(new InterceptOrder(game, target, sector.Id, true), append));
            }
            else if (order.StartsWith("Defend"))
            {
                // All friendly combat ships in sector
                var ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.Type != EShipType.Lifepod && _.CanAttackShips()).ToList();
                if (ships.Count == 0)
                {
                    return;
                }

                if (order.EndsWith("Base"))
                {
                    var targetBases = game.AllBases.Where(_ => _.Active && _.SectorId != sector.Id && _.Alliance == alliance).ToList();
                    if (targetBases.Count == 0)
                    {
                        return;
                    }

                    var targetBase = StrategyGame.RandomItem(targetBases);
                    ships.ForEach(_ => _.OrderShip(new SurroundOrder(game, sector.Id, targetBase, PointF.Empty)));
                    return;
                }

                // if type in sector, defend it (rnd)
                var targetTypes = GetOrderTypes(order);
                var targets     = game.AllUnits.Where(_ => _.Active && _.Alliance == alliance && _.SectorId == sector.Id && targetTypes.Contains(_.Type)).ToList();

                if (targets.Count == 0)
                {
                    return;
                }
                var target = StrategyGame.RandomItem(targets);
                ships.ForEach(_ => _.OrderShip(new InterceptOrder(game, target, sector.Id, true)));
            }
            else if (order.StartsWith("Launch"))
            {
                if (pilotCount == 0)
                {
                    return;
                }

                // Get a base in sector (rnd)
                var  bases      = game.AllBases.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.CanLaunchShips()).ToList();
                Base launchBase = null;
                if (bases.Count == 0)
                {
                    // Get a base close to this sector (rnd)
                    launchBase = game.ClosestSectorWithBase(team, sector.Id);
                }
                else
                {
                    launchBase = StrategyGame.RandomItem(bases);
                }
                if (launchBase == null)
                {
                    return;
                }

                // Launch this ship type
                var types = GetOrderTypes(order);
                do
                {
                    var s = LaunchShipType(game, types, launchBase, f_ShipEvent);
                    if (s == null)
                    {
                        break;
                    }
                } while (game.DockedPilots[t] > pilotCount / 2);
            }
            else if (order.StartsWith("Hunt"))
            {
                // Get a base in sector (rnd)
                var  bases      = game.AllBases.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.CanLaunchShips()).ToList();
                Base launchBase = null;

                if (bases.Count == 0)
                {
                    // Get a base close to this sector (rnd)
                    launchBase = game.ClosestSectorWithBase(team, sector.Id);
                }
                else
                {
                    launchBase = StrategyGame.RandomItem(bases);
                }

                var targetTypes = GetOrderTypes(order);
                var targets     = game.AllUnits.Where(_ => _.Active && _.IsVisibleToTeam(team) && _.Alliance != alliance && targetTypes.Contains(_.Type)).ToList();
                var target      = StrategyGame.RandomItem(targets);

                // Launch fighter ship type
                var types = GetOrderTypes("Fighter");
                var ships = new List <CombatShip>();
                do
                {
                    var s = LaunchShipType(game, types, launchBase, f_ShipEvent);
                    if (s == null)
                    {
                        break;
                    }
                    ships.Add(s);
                } while (game.DockedPilots[t] > pilotCount / 2);

                // If type spotted, navigate & attack it (rnd)
                if (target != null)
                {
                    if (launchBase.SectorId != target.SectorId)
                    {
                        ships.ForEach(_ => _.OrderShip(new NavigateOrder(game, _, target.SectorId), true));
                    }

                    ships.ForEach(_ => _.OrderShip(new InterceptOrder(game, target, _.SectorId, true), true));
                }
                else
                {
                    // Otherwise patrol randomly until spotted
                    ships.ForEach(_ => _.OrderShip(new HuntControlOrder(game, targetTypes), true));
                }
            }
            else if (order == "Scout")
            {
                // Launch up to 3 scouts to patrol randomly
                var bases = game.AllBases.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.CanLaunchShips()).ToList();
                if (bases.Count == 0)
                {
                    return;
                }
                var launchBase = StrategyGame.RandomItem(bases);

                var types = GetOrderTypes("Scout");
                var ships = new List <CombatShip>();
                do
                {
                    var s = LaunchShipType(game, types, launchBase, f_ShipEvent);
                    if (s == null)
                    {
                        break;
                    }
                    ships.Add(s);
                } while (game.DockedPilots[t] > 0 && ships.Count < 3);

                ships.ForEach(_ => _.OrderShip(new ScoutControlOrder(game), true));
            }
            else if (order == "Dock")
            {
                // All friendly combat ships in sector
                var ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.Type != EShipType.Lifepod && _.CanAttackShips()).ToList();
                if (ships.Count == 0)
                {
                    return;
                }

                // Dock order
                ships.ForEach(_ => _.OrderShip(new DockOrder(game, _)));
            }
            else if (order == "Pause")
            {
                // All friendly combat ships in sector
                var ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.Type != EShipType.Lifepod && _.CanAttackShips()).ToList();
                if (ships.Count == 0)
                {
                    return;
                }

                // Pause order
            }
            else if (order == "Resume")
            {
                // All friendly combat ships in sector
                var ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.Type != EShipType.Lifepod && _.CanAttackShips()).ToList();
                if (ships.Count == 0)
                {
                    return;
                }

                // Unpause order
            }
        }
コード例 #6
0
        public static void ProcessOrder(StrategyGame game, QuickChatItem cmd, MapSector sector, Ship.ShipEventHandler f_ShipEvent)
        {
            if (cmd == null || game == null || cmd.OrderAction == string.Empty) return;

            var targetSectorId = sector.Id;
            var launchSectorId = sector.Id;

            var team = 1;
            var t = 0;
            var alliance = game.GameSettings.TeamAlliance[t];
            var pilotCount = game.DockedPilots[t];
            var order = cmd.OrderAction;
            List<Ship> ships;

            if (order == "Scout")
            {
                var idealNumOfShips = 3;
                var orderTypes = GetOrderTypes(order);

                // Prefer ships already in sector
                ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == launchSectorId && orderTypes.Contains(_.Type)).Take(idealNumOfShips).ToList();

                if (ships.Count < idealNumOfShips && pilotCount > 0)
                {
                    // Launch more scouts if needed
                    var launchBase = game.ClosestSectorWithBase(team, sector.Id);
                    if (launchBase != null)
                    {
                        ships.AddRange(LaunchShips(game, idealNumOfShips - ships.Count, orderTypes, launchBase, f_ShipEvent));
                    }
                }
                if (ships.Count == 0) return;

                ships.ForEach(_ => _.OrderShip(new ScoutControlOrder(game), true));
            }
            else if (order == "Dock")
            {
                // All our combat ships in this sector should dock immediately
                ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.Type != EShipType.Lifepod && _.CanAttackShips() && !Ship.IsCapitalShip(_.Type)).ToList();
                if (ships.Count == 0) return;

                ships.ForEach(_ => _.OrderShip(new DockOrder(game, _)));
            }
            else if (order == "Pause")
            {
                // Interrupt the current order for all our combat ships in this sector
                ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.Type != EShipType.Lifepod && _.CanAttackShips()).ToList();
                if (ships.Count == 0) return;

                ships.ForEach(_ => _.InsertOrder(new PauseControlOrder(game)));
            }
            else if (order == "Resume")
            {
                // Resume the order queue for all our combat ships in this sector
                ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == sector.Id && _.Type != EShipType.Lifepod && _.CanAttackShips()).ToList();
                if (ships.Count == 0) return;

                ships.ForEach(_ => _.InsertOrder(new ResumeControlOrder(game)));
            }
            else if (order.StartsWith("Launch"))
            {
                if (pilotCount < 2) return;
                var orderTypes = GetOrderTypes(order);
                var idealNumOfShips = pilotCount / 2;

                var launchBase = game.ClosestSectorWithBase(team, sector.Id);
                if (launchBase == null) return;
                launchSectorId = launchBase.SectorId;

                ships = LaunchShips(game, idealNumOfShips, orderTypes, launchBase, f_ShipEvent);
                if (ships.Count == 0) return;

                if (sector.Id != launchSectorId)
                {
                    ships.ForEach(_ => _.OrderShip(new NavigateOrder(game, _, sector.Id)));
                    ships.ForEach(_ => _.OrderShip(new MoveOrder(game, launchBase.SectorId, StrategyGame.ScreenCenter, Point.Empty), true));
                }
            }
            else if (order.StartsWith("Defend") || order.StartsWith("Attack") || order.StartsWith("Hunt"))
            {
                var idealNumOfScouts = 2;
                var idealNumOfShips = game.TotalPilots[t] / 2;
                var shipTypes = GetOrderTypes("Fighter");
                var targetTypes = GetOrderTypes(order);

                Base targetBase = null;
                Ship targetShip = null;

                var defend = order.StartsWith("Defend");
                var hunt = order.StartsWith("Hunt");

                if (order.EndsWith("Base"))
                {
                    idealNumOfScouts = 0;

                    // Only bases in this sector
                    var targetBases = game.AllBases.Where(_ => _.Active && _.IsVisibleToTeam(t) && (_.Alliance != alliance || defend) && _.SectorId == sector.Id).ToList();                    
                    if (targetBase == null) return;
                    targetSectorId = targetBase.SectorId;
                }
                else
                { 
                    // Prefer targest in this sector
                    var targetShips = game.AllUnits.Where(_ => _.Active && _.IsVisibleToTeam(t) && (_.Alliance != alliance || defend) && _.SectorId == sector.Id && targetTypes.Contains(_.Type)).ToList();
                    if (targetShips.Count == 0)
                    {
                        targetShips = game.AllUnits.Where(_ => _.Active && _.IsVisibleToTeam(t) && (_.Alliance != alliance || defend) && targetTypes.Contains(_.Type)).ToList();
                    }

                    targetShip = StrategyGame.RandomItem(targetShips);

                    // Abort if we have no targets and we are not hunting
                    if (targetShip == null && !hunt) return;

                    targetSectorId = targetShip != null ? targetShip.SectorId : sector.Id;
                }

                var launchBase = game.ClosestSectorWithBase(team, targetSectorId);
                if (launchBase != null) launchSectorId = launchBase.SectorId;

                // Prefer scouts already in sector
                if (idealNumOfScouts > 0)
                {
                    ships = game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == targetSectorId && _.Type == EShipType.Scout).Take(idealNumOfScouts).ToList();

                    if (ships.Count < idealNumOfScouts && pilotCount > 0)
                    {
                        // Launch more scouts if needed
                        if (launchBase != null)
                        {
                            ships.AddRange(LaunchShips(game, idealNumOfScouts - ships.Count, new[] { EShipType.Scout }, launchBase, f_ShipEvent));
                        }
                    }
                }
                else
                {
                    ships = new List<Ship>();
                }

                // Prefer fighters already in sector
                ships.AddRange(game.AllUnits.Where(_ => _.Active && _.Team == team && _.SectorId == targetSectorId && shipTypes.Contains(_.Type)).Take(idealNumOfShips).ToList());
                if (ships.Count < idealNumOfShips && pilotCount > 0)
                {
                    // Launch more fighters if needed
                    if (launchBase != null)
                    {
                        ships.AddRange(LaunchShips(game, idealNumOfShips - ships.Count, shipTypes, launchBase, f_ShipEvent));
                    }
                }
                if (ships.Count == 0) return;

                // Get to the target's sector, if needed
                ships.ForEach(_ => _.OrderShip(new NavigateOrder(game, _, targetSectorId)));

                if (targetBase != null)
                {
                    ships.ForEach(_ => _.OrderShip(new SurroundOrder(game, targetSectorId, targetBase), true));
                }
                else if (targetShip != null)
                {
                    ships.ForEach(_ => _.OrderShip(new InterceptOrder(game, targetShip, targetSectorId), true));
                }
                else if (hunt)
                { 
                    // Otherwise, patrol randomly to hunt for the target type
                    ships.ForEach(_ => _.OrderShip(new HuntControlOrder(game, targetTypes)));
                }
            }
        }
コード例 #7
0
        public static SimpleGameMap GenerateMirroredMap(EMapSize size, int numTeams = -1)
        {
            var rnd   = StrategyGame.Random;
            var iSize = (int)size;

            // Lock Large/Small maps to 2/4 teams for less variation
            if (size == EMapSize.Small)
            {
                numTeams = 2;
            }
            if (size == EMapSize.Large)
            {
                numTeams = 4;
            }
            if (numTeams == -1 && size == EMapSize.Normal)
            {
                numTeams = rnd.Next(1, 3) * 2;
            }

            var map = new SimpleGameMap($"{size} Random{numTeams}");

            // 0:hor/1:vert/2:hor&vert
            var mirrorType      = numTeams == 2 ? rnd.Next(3) : 2;
            var mirrorIncrement = mirrorType == 2 ? 4 : 2;

            // Determine num sectors based on size & num teams
            // small: (min = num teams*2, max = num teams*4)
            // normal: (min = num teams*3, max = num teams*5)
            // large: (min = num teams*4, max = num teams*6)
            var minNumSectors = numTeams * (iSize + 2);
            var maxNumSectors = numTeams * (iSize + 4);

            var xDim         = 7;
            var yDim         = 7;
            var nextSectorId = 0;

            // Add sectors in all positions
            for (var x = 0; x < xDim; x++)
            {
                for (var y = 0; y < yDim; y++)
                {
                    var s = new SimpleMapSector(nextSectorId++, new Point(x, y));
                    map.Sectors.Add(s);
                }
            }

            var maxChances = map.Sectors.Count * 3;
            var l          = 0;
            // Loop with a decreasing chance to remove sectors (mirrored)
            var removeChance = 0.97;

            while ((l++ < maxChances || map.Sectors.Count - mirrorIncrement > maxNumSectors) && map.Sectors.Count - mirrorIncrement > minNumSectors)
            {
                var s = StrategyGame.RandomItem(map.Sectors);
                if (rnd.NextDouble() < removeChance)
                {
                    removeChance -= 0.03;
                    map.Sectors.Remove(s);

                    // Horiz mirrored or both
                    if (mirrorType == 0 || mirrorType == 2)
                    {
                        var mX = MirrorDimension(xDim, s.MapPosition.X);
                        var mY = s.MapPosition.Y;

                        var s2 = map.Sectors.FirstOrDefault(_ => _.MapPosition.X == mX && _.MapPosition.Y == mY);
                        if (s2 != null)
                        {
                            map.Sectors.Remove(s2);
                        }
                    }

                    // Vert mirrored or both
                    if (mirrorType == 1 || mirrorType == 2)
                    {
                        var mX = s.MapPosition.X;
                        var mY = MirrorDimension(yDim, s.MapPosition.Y);

                        var s2 = map.Sectors.FirstOrDefault(_ => _.MapPosition.X == mX && _.MapPosition.Y == mY);
                        if (s2 != null)
                        {
                            map.Sectors.Remove(s2);
                        }
                    }

                    // Mirrored for both dimensions
                    if (mirrorType == 2)
                    {
                        var mX = MirrorDimension(xDim, s.MapPosition.X);
                        var mY = MirrorDimension(yDim, s.MapPosition.Y);

                        var s2 = map.Sectors.FirstOrDefault(_ => _.MapPosition.X == mX && _.MapPosition.Y == mY);
                        if (s2 != null)
                        {
                            map.Sectors.Remove(s2);
                        }
                    }
                }
            }

            // Fix SectorIDs after removing, they actually need to be indexes...
            l = 0;
            foreach (var s in map.Sectors)
            {
                s.Id = l++;
            }

            // Triangulate, loop with a small chance to remove an edges if that sector has > 2 connections
            var vertices = new List <Vertex <SimpleMapSector> >();

            foreach (var s in map.Sectors)
            {
                var p = s.MapPosition;
                vertices.Add(new Vertex <SimpleMapSector>(new Vector2(p.X, p.Y), s));
            }

            var delaunay = Delaunay2D <SimpleMapSector> .Triangulate(vertices);

            var mapEdges = new List <Edge <SimpleMapSector> >();

            foreach (var edge in delaunay.Edges)
            {
                if (!map.WormholeExists(edge.U.Item.Id, edge.V.Item.Id))
                {
                    map.WormholeIds.Add(new WormholeId(edge.U.Item.Id, edge.V.Item.Id));
                }
            }

            // Find Starting Positions (mirrored)
            var teamsAdded = 0;

            {
                var startPosMinX = 0;
                var startPosMinY = 0;

                var startPosMaxX = mirrorType == 1 ? xDim : xDim / 2 - 1;
                var startPosMaxY = mirrorType == 0 ? yDim : yDim / 2 - 1;

                var startSectors = map.Sectors
                                   .Where(_ => _.MapPosition.X >= startPosMinX && _.MapPosition.X <= startPosMaxX &&
                                          _.MapPosition.Y >= startPosMinY && _.MapPosition.Y <= startPosMaxY)
                                   .ToList();
                var s = StrategyGame.RandomItem(startSectors);

                // Safety check
                if (s == null)
                {
                    return(GenerateMirroredMap(size));
                }

                s.StartingSectorTeam = ++teamsAdded;

                // Mirrored for both dimensions
                if (mirrorType == 2)
                {
                    var mX = MirrorDimension(xDim, s.MapPosition.X);
                    var mY = MirrorDimension(yDim, s.MapPosition.Y);

                    var s2 = map.Sectors.FirstOrDefault(_ => _.MapPosition.X == mX && _.MapPosition.Y == mY);
                    if (s2 != null)
                    {
                        s2.StartingSectorTeam = ++teamsAdded;
                    }
                }

                // Horiz mirrored or both
                if (mirrorType == 0 || (mirrorType == 2 && numTeams > 2))
                {
                    var mX = MirrorDimension(xDim, s.MapPosition.X);
                    var mY = s.MapPosition.Y;

                    var s2 = map.Sectors.FirstOrDefault(_ => _.MapPosition.X == mX && _.MapPosition.Y == mY);
                    if (s2 != null)
                    {
                        s2.StartingSectorTeam = ++teamsAdded;
                    }
                }

                // Vert mirrored or both
                if (mirrorType == 1 || (mirrorType == 2 && numTeams > 2))
                {
                    var mX = s.MapPosition.X;
                    var mY = MirrorDimension(yDim, s.MapPosition.Y);

                    var s2 = map.Sectors.FirstOrDefault(_ => _.MapPosition.X == mX && _.MapPosition.Y == mY);
                    if (s2 != null)
                    {
                        s2.StartingSectorTeam = ++teamsAdded;
                    }
                }
            }

            // Final Checks
            if (teamsAdded < numTeams || !map.IsValid())
            {
                return(GenerateMirroredMap(size));
            }

            return(map);
        }
コード例 #8
0
        private void UpdateFocussedBuildOrder()
        {
            // Focus on miners, outpost, random tech, garrison, refinery. Then main tech upgrades and bombers, then other random building and research.
            if (_game.Credits[_t] <= 100)
            {
                return;
            }

            if (_initTech == EInitialTargetTech.ChooseInSector)
            {
                var startingSector = _game.AllBases.First(_ => _.Team == Team && _.Type == EBaseType.Starbase).SectorId;
                var techRocks      = _game.AllAsteroids.Where(_ => _.SectorId == startingSector && _.Active && !(_.Type == EAsteroidType.Generic || _.Type == EAsteroidType.Resource)).ToList();
                var choice         = StrategyGame.RandomItem(techRocks);

                switch (choice.Type)
                {
                case EAsteroidType.Carbon:
                    _initTech = EInitialTargetTech.Supremacy;
                    break;

                case EAsteroidType.Silicon:
                    _initTech = EInitialTargetTech.Tactical;
                    break;

                case EAsteroidType.Uranium:
                    _initTech = EInitialTargetTech.Expansion;
                    break;

                default:
                    _initTech = EInitialTargetTech.Starbase;
                    break;
                }

                _initTechName = Enum.GetName(typeof(EInitialTargetTech), _initTech);
            }

            var ourSectors = (from b in _game.AllBases
                              where b.Active && b.Team == Team && b.CanLaunchShips()
                              select b.SectorId).Distinct().ToList();

            // If we have money, build resources
            if (_game.Credits[_t] > 1000)
            {
                var resourcesToBuild = (from c in _game.TechTree[_t].ResearchableItems(ETechType.Construction)
                                        where c.CanBuild() && c.AmountInvested < c.Cost &&
                                        (c.Name.Contains("Miner") ||
                                         c.Name.Contains("Resource"))
                                        select c).ToList();
                TryToInvestInResources(resourcesToBuild, ourSectors);
            }

            // Expand & Build Randomly our focus tech:
            var basesToBuild = (from c in _game.TechTree[_t].ResearchableItems(ETechType.Construction)
                                where c.CanBuild() && c.AmountInvested < c.Cost &&
                                (c.Name.Contains("Outpost") ||
                                 c.Name.Contains("Starbase") ||
                                 c.Name.Contains(_initTechName))
                                orderby c.Id descending
                                select c).ToList();

            TryToInvestInBases(basesToBuild, ourSectors);

            // Once we have built our tech, research it randomly along with bombers/drones
            if (!_flagBuiltFocusTech)
            {
                return;
            }

            var tech = (from t in _game.TechTree[_t].ResearchableItemsNot(ETechType.Construction)
                        where t.CanBuild() &&
                        (int)t.Type == (int)_initTech &&
                        t.AmountInvested < t.Cost
                        orderby t.Cost - t.AmountInvested, t.Id descending
                        select t).Take(3).ToList();

            var bbr = (from t in _game.TechTree[_t].TechItems
                       where t.Active &&
                       !t.Completed &&
                       (t.Name.Contains("Bomber") || t.Name.Contains("Combat Drones"))
                       select t).FirstOrDefault();

            if (bbr != null)
            {
                tech.Add(bbr);
            }

            InvestInRandomTech(tech);

            // Once we are done with our focus, branch out!
            if (tech.Count() < 2)
            {
                _focusBuildOrder = false;
            }
        }