Exemplo n.º 1
0
        //todo: move to Game() object
        private void TakeAttackDamageOrRepair(IMap map, int lastRegionY, int lastRegionX)
        {
            var thisShip = this.ShipConnectedTo.GetLocation();

            var currentRegion = Regions.Get(map, thisShip.Region);

            var hostiles             = currentRegion.GetHostiles();
            var baddiesHangingAround = hostiles.Count > 0;

            var hostileFedsInRegion = hostiles.Any(h => h.Faction == FactionName.Federation);
            //todo: Cheap.  Use a property for this.

            var stillInSameRegion = lastRegionX == thisShip.Region.X && lastRegionY == thisShip.Region.Y;

            if ((baddiesHangingAround && stillInSameRegion) ||
                hostileFedsInRegion ||
                (this.Game.PlayerNowEnemyToFederation && currentRegion.GetStarbaseCount() > 0))
            {
                this.Game.ALLHostilesAttack(this.Game.Map);
            }
            else
            {
                this.ShipConnectedTo.Subsystems.PartialRepair();
            }
        }
Exemplo n.º 2
0
        private void CheckStarsInRegion()
        {
            this.Game.Map = new Map(new SetupOptions
            {
                AddNebulae = false,
                Initialize = true,
                AddStars   = false,
                SectorDefs = new SectorDefs
                {
                    new SectorDef(
                        new LocationDef(new Coordinate(0, 0), new Coordinate(0, 4)),
                        SectorItem.Star),
                    new SectorDef(
                        new LocationDef(new Coordinate(0, 0), new Coordinate(0, 5)),
                        SectorItem.Star),
                }
            }, this.Game.Write, this.Game.Config);

            _setup.TestLongRangeScan = new LongRangeScan(this.Game.Map.Playership, this.Game);

            Region Region    = Regions.Get(this.Game.Map, new Coordinate(0, 0));
            int    starCount = Region.GetStarCount();

            Assert.AreEqual(2, starCount);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Updates the region.
 /// </summary>
 /// <param name="regionId">The region id.</param>
 /// <param name="playername">The player name.</param>
 /// <param name="nbrOfArmies">The number of armies.</param>
 public void UpdateRegion(int regionId, String playername, int nbrOfArmies)
 {
     Regions
     .Get(regionId)
     .Update(
         player: Configuration.Current.GetPlayerByName(playername),
         nbrOfArmies: nbrOfArmies);
 }
        public void Region_Constellations_ReturnsNonEmptySequence()
        {
            var r = Regions.Get(10000064).Value;

            var cs = r.Constellations().ToList();

            cs.Should().NotHaveCount(0);
        }
Exemplo n.º 5
0
        private void CheckRegionsAfterMovement(bool checkForGalacticBarrierHit)
        {
            var playershipRegion = this.Game.Map.Playership.GetRegion();
            var activeRegion     = this.Game.Map.Regions.GetActive();

            Assert.AreEqual(64, this.Game.Map.Regions.Count); //I'd certainly hope that this hasnt changed..
            Assert.IsFalse(_testMovement.BlockedByObstacle, "Blocked by Obstacle");

            if (checkForGalacticBarrierHit)
            {
                Assert.IsFalse(_testMovement.BlockedByGalacticBarrier, "Blocked by Galactic Barrier");
            }

            //ensure there is still only 1 of original Region (used to address a bug early on)
            Assert.IsInstanceOf <Region>(playershipRegion);

            //ship is in active sector
            var found = Sector.Get(activeRegion.Sectors,
                                   this.Game.Map.Playership.Sector.X,
                                   this.Game.Map.Playership.Sector.Y);

            Assert.IsInstanceOf <Sector>(found);

            //starting location is empty
            var startingRegionT = Regions.Get(this.Game.Map, _startingRegion);

            Assert.AreEqual(SectorItem.Empty, Sector.Get(startingRegionT.Sectors, _startingSectorX, _startingSectorY).Item);

            //We moved from our original Region, right?
            Assert.AreNotEqual(startingRegionT.X.ToString() + startingRegionT.Y, activeRegion.X +
                               activeRegion.Y.ToString(), "Starting Region");

            //Friendly was set in new location
            //Playership current sector has the ship set in it
            Assert.AreEqual(SectorItem.PlayerShip, Sector.Get(playershipRegion.Sectors,
                                                              this.Game.Map.Playership.Sector.X, this.Game.Map.Playership.Sector.Y).Item);

            //is ship in expected location in new Region?
            ////indirectly..
            var found2 = (playershipRegion.Sectors.Where(s => s.Item == SectorItem.PlayerShip)).Count();

            Assert.AreEqual(1, found2, "expected to find 1 friendly, not " + found2 + ".   ");

            //directly
            //Verifying Sector. Look up sector by playership's coordinates. see if a friendly is there.
            Assert.AreEqual(SectorItem.PlayerShip, playershipRegion.Sectors.Single(s => s.X == this.Game.Map.Playership.Sector.X &&
                                                                                   s.Y == this.Game.Map.Playership.Sector.Y).Item);

            //Check Ship Region against active. (this really just tests the GetActive() function - this should be a separate test as well)
            Assert.AreEqual(this.Game.Map.Playership.Coordinate.X, activeRegion.X, "this.Game.Map.Playership.Region.X");
            Assert.AreEqual(this.Game.Map.Playership.Coordinate.Y, activeRegion.Y, "this.Game.Map.Playership.Region.Y");
        }
Exemplo n.º 6
0
        public void Shoot(double direction)
        {
            if (this.Count < 1)
            {
                this.Game.Write.Line("Cannot fire.  Torpedo Room reports no Torpedoes to fire.");
                return;
            }

            this.Game.ALLHostilesAttack(this.Game.Map);

            var angle = Utility.Utility.ComputeAngle(direction);

            Location torpedoStartingLocation = this.ShipConnectedTo.GetLocation();
            Region   Region = Regions.Get(this.Game.Map, torpedoStartingLocation.Region);

            //var currentLocation = new VectorCoordinate(torpedoStartingLocation.Sector);
            //var torpedoVector = new VectorCoordinate(Math.Cos(angle)/20, Math.Sin(angle)/20);

            this.Game.Write.Line("Photon torpedo fired...");
            this.Count--;

            //TODO: WRITE SOME TORPEDO TESTS!

            //todo: add in a constructor to turn off coordinate bounds checking for this object only
            //either that, or come up with a null location so that the first WHILE will work
            var lastPosition = new Coordinate(-1, -1, false);

            var newLocation = new Location();

            newLocation.Region = Region;
            newLocation.Sector = new Sector();

            ////todo: condense WHILE to be a function of Coordinate
            ////todo: eliminate the twice rounding of torpedo location, as the same value is evaluated twice
            ////todo: the rounding can happen once in a variable, and then referred to twice (see note below)
            //while (Torpedoes.IsInRegion(currentLocation))
            //{
            //    //Increment to next Sector
            //    if (this.HitSomething(currentLocation, lastPosition, newLocation))
            //    {
            //        this.Game.Write.OutputConditionAndWarnings(this.ShipConnectedTo, this.Game.Config.GetSetting<int>("ShieldsDownLevel"));
            //        return;
            //    }

            //    //Keep going.. because we haven't hit anything yet

            //    //todo: How about storing a *rounded* XY that is referred to by the While, and the new SectorToCheck
            //    currentLocation.IncrementBy(torpedoVector);
            //}

            this.Game.Write.Line("Photon torpedo failed to hit anything.");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets the region neighbors.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="neighbors">The neighbors.</param>
        public void SetRegionNeighbors(int id, String[] neighbors)
        {
            var currentRegion = Regions.Get(id);

            var neighbourRegions = neighbors
                                   .Select(neighbour => Regions.Get(neighbour))
                                   .ToList();

            currentRegion
            .Neighbours
            .AddRange(neighbourRegions);

            /*
             * Neighbors are only given in one direction.
             * E.g.: A has neighbour B, but the game won't tell us B has neighbour A.
             *
             * We have to define that relation explicitly
             * */
            neighbourRegions
            .ForEach(
                neighbourRegion => neighbourRegion.Neighbours.Add(currentRegion));
        }
Exemplo n.º 8
0
        public void RenderSectors(SectorScanType scanType, ISubsystem subsystem)
        {
            var    location          = subsystem.ShipConnectedTo.GetLocation();
            Region Region            = Regions.Get(subsystem.Game.Map, location.Region);
            var    shieldsAutoRaised = Shields.For(subsystem.ShipConnectedTo).AutoRaiseShieldsIfNeeded(Region);
            var    printSector       = (new Render(this, subsystem.Game.Config));

            int    totalHostiles           = subsystem.Game.Map.Regions.GetHostileCount();
            var    isNebula                = (Region.Type == RegionType.Nebulae);
            string RegionDisplayName       = Region.Name;
            var    sectorScanStringBuilder = new StringBuilder();

            if (isNebula)
            {
                RegionDisplayName += " Nebula"; //todo: resource out.
            }

            this.Line("");

            switch (scanType)
            {
            case SectorScanType.CombinedRange:
                printSector.CreateCRSViewScreen(Region, subsystem.Game.Map, location, totalHostiles, RegionDisplayName, isNebula, sectorScanStringBuilder);
                break;

            case SectorScanType.ShortRange:
                printSector.CreateSRSViewScreen(Region, subsystem.Game.Map, location, totalHostiles, RegionDisplayName, isNebula, sectorScanStringBuilder);
                break;

            default:
                throw new NotImplementedException();
            }

            printSector.OutputScanWarnings(Region, subsystem.Game.Map, shieldsAutoRaised);

            Region.ClearSectorsWithItem(SectorItem.Debug); //Clears any debug Markers that might have been set
            Region.Scanned = true;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Marks the starting regions.
        /// </summary>
        /// <param name="regions">The regions.</param>
        public void MarkStartingRegions(String[] regions)
        {
            // Reset all marked starting regions
            Regions
            .ForEach(
                region =>
            {
                if (region.RegionStatus == RegionStatus.PossibleStartingRegion)
                {
                    region.RegionStatus = RegionStatus.Initialized;
                }
            });

            regions
            .ToList()
            .ForEach(
                regionId =>
            {
                Regions
                .Get(regionId)
                .RegionStatus = RegionStatus.PossibleStartingRegion;
            }
                );
        }
Exemplo n.º 10
0
        private Region TravelThroughRegions(int distance, int direction, IShip playership)
        {
            // 4   5   6
            //   \ ↑ /
            //3 ← <*> → 7
            //   / ↓ \
            // 2   1   8

            //todo: get rid of this double-stuff. I'm only doing this so that IsGalacticBarrier can be used by both Region and Sector Navigation.
            int currentQX = playership.GetRegion().X;
            int currentQY = playership.GetRegion().Y;

            for (int i = 0; i < distance; i++)
            {
                switch (direction)
                {
                case 3:
                    currentQX--;     //left
                    break;

                case 4:
                    currentQX--;     //left
                    currentQY--;     //up
                    break;

                case 5:
                    currentQY--;     //up
                    break;

                case 6:
                    currentQX++;     //right
                    currentQY--;     //up
                    break;

                case 7:
                    currentQX++;     //right
                    break;

                case 8:
                    currentQX++;     //right
                    currentQY++;     //down
                    break;

                case 1:
                    currentQY++;     //down
                    break;

                case 2:
                    currentQX--;     //left
                    currentQY++;     //down
                    break;
                }

                //todo: check if Region is nebula or out of bounds

                var barrierHit = this.IsGalacticBarrier(ref currentQX, ref currentQY);  //XY will be set to safe value in here
                if (barrierHit)
                {
                    break;
                }
                else
                {
                    bool nebulaEncountered = Regions.IsNebula(ShipConnectedTo.Map, new Coordinate(Convert.ToInt32(currentQX), Convert.ToInt32(currentQY)));
                    if (nebulaEncountered)
                    {
                        this.Game.Write.Line("Nebula Encountered. Navigation stopped to manually recalibrate warp coil");
                        break;
                    }
                }
            }

            return(Regions.Get(ShipConnectedTo.Map, new Coordinate(Convert.ToInt32(currentQX), Convert.ToInt32(currentQY))));

            //todo: once we have found Region..
            //is target location blocked?
            //if true, then output that expected location was blocked, and ship's computers have picked a new spot

            //while loop
            //   pick a random sector
            //   check it for obstacle
            //if good then jump out of loop
        }
Exemplo n.º 11
0
 /// <summary>
 /// Gets the region.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns></returns>
 public Region GetRegion(int id)
 {
     return(Regions.Get(id));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Defines a region as wasteland
 /// </summary>
 /// <param name="regionId">The region identifier.</param>
 public void SetWasteland(int regionId)
 {
     Regions
     .Get(regionId)
     .IsWasteland = true;
 }