Пример #1
0
        //todo: refactor these functions with LRS
        //todo: hand LRS a List<LRSResult>(); and then it can build its little grid.
        //or rather.. LongRangeScan subsystem comes up with the numbers, then hands it to the Print

        //todo: refactor this with GetLRSFullData.  Pay attention to OutOfBounds
        public IEnumerable <IRSResult> GetIRSFullData(Location shipLocation, Game game)
        {
            var scanData = new List <IRSResult>();

            //todo:  //bool currentlyInNebula = shipLocation.Sector.Type == RegionType.Nebulae;

            for (var sectorX = shipLocation.Sector.X - 1;
                 sectorX <= shipLocation.Sector.X + 1;
                 sectorX++)
            {
                for (var sectorY = shipLocation.Sector.Y - 1;
                     sectorY <= shipLocation.Sector.Y + 1;
                     sectorY++)
                {
                    var outOfBounds = Region.OutOfBounds(shipLocation.Sector);

                    var currentResult = new IRSResult();

                    //todo: breaks here when regionX or regionY is 8
                    currentResult.Coordinate = new Coordinate(sectorX, sectorY, false);

                    currentResult            = this.GetSectorInfo(shipLocation.Region, new Coordinate(sectorX, sectorY, false), outOfBounds, game);
                    currentResult.MyLocation = shipLocation.Region.X == sectorX &&
                                               shipLocation.Region.Y == sectorY;

                    scanData.Add(currentResult);
                }
            }
            return(scanData);
        }
Пример #2
0
        public IRSResult GetSectorInfo(Region currentRegion, ICoordinate sector, bool outOfBounds, Game game)
        {
            var currentResult = new IRSResult();

            if (!outOfBounds)
            {
                currentResult = this.GetSectorData(currentRegion, sector, game);
            }
            else
            {
                currentResult.GalacticBarrier = true;
                //todo: set region to Galactic barrier?
            }

            return(currentResult);
        }
Пример #3
0
        public IRSResult Execute(Location locationToScan)
        {
            var sectorResult = new IRSResult();

            sectorResult.Coordinate = locationToScan.Sector.GetCoordinate();

            //todo: support sector level nebulae
            //if (sectorToScan.Type != RegionType.Nebulae)
            //{
            //todo: these 2 concepts need to be combined
            sectorResult.Item       = locationToScan.Sector.Item;
            sectorResult.Object     = locationToScan.Sector.Object;
            sectorResult.RegionName = locationToScan.Region.Name;
            //}

            locationToScan.Sector.Scanned = true;

            return(sectorResult);
        }
Пример #4
0
        ///// <summary>
        ///// Used by CRS
        ///// </summary>
        ///// <param name="shipLocation"></param>
        ///// <returns></returns>
        //public List<string> RunIRSScan(Location shipLocation)
        //{
        //    var tlrsResults = shipLocation.Region.GetIRSFullData(shipLocation, this.Game);
        //    var renderedData = this.Game.Write.RenderIRSData(tlrsResults, this.Game);

        //    return renderedData.ToList();
        //}

        /// <summary>
        /// SectorToScan
        /// </summary>
        /// <param name="locationToScan"></param>
        /// <returns></returns>
        public IRSResult Scan(Location locationToScan)
        {
            if (this.Damaged())
            {
                return(null);
            }

            //todo: refactor this with region.GetIRSFullData() inner loop

            var outOfBounds = this.Game.Map.OutOfBounds(locationToScan.Region);

            ////todo: breaks here when regionX or regionY is 8

            //todo: perform scan on location passed

            var shipRegion = this.ShipConnectedTo.GetRegion();

            //locationToScan.Region is divined to the new one when crossing barrier
            IRSResult divinedResult = shipRegion.GetSectorInfo(locationToScan.Region, locationToScan.Sector, outOfBounds, this.Game);

            return(divinedResult);
        }
Пример #5
0
        private IRSResult GetSectorData(Region currentRegion, ICoordinate sector, Game game)
        {
            Sector sectorToScan = this.Sectors.GetNoError(sector);

            Coordinate xx = sectorToScan ?? new Coordinate(sector.X, sector.Y, false);

            ISector sectorToExamine   = new Sector(new LocationDef(currentRegion, xx), false);
            var     locationToExamine = new Location(currentRegion, sectorToExamine);

            Location divinedLocationOnMap = currentRegion.DivineSectorOnMap(locationToExamine, this.Map);

            if (divinedLocationOnMap.Region.Type != RegionType.GalacticBarrier)
            {
                int i;
            }
            else
            {
            }


            IRSResult sectorResult = ImmediateRangeScan.For(game.Map.Playership).Execute(divinedLocationOnMap);

            return(sectorResult);
        }
Пример #6
0
        private void TravelThroughSectors(int distance, int direction, IShip travellingShip)
        {
            // 4   5   6
            //   \ ↑ /
            //3 ← <*> → 7
            //   / ↓ \
            // 2   1   8

            direction = -direction + 8;

            var currentRegion = travellingShip.GetRegion();

            int currentSX = travellingShip.Sector.X;
            int currentSY = travellingShip.Sector.Y;

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

                case 4:
                    currentSX--;     //left
                    currentSY--;     //up
                    break;

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

                case 6:
                    currentSX++;     //right
                    currentSY--;     //up
                    break;

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

                case 0:
                    currentSX++;     //right
                    currentSY++;     //down
                    break;

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

                case 2:
                    currentSX--;     //left
                    currentSY++;     //down
                    break;
                }

                //if on the edge of a Region, newSector will have negative numbers
                var newSectorCandidate = new Sector(new LocationDef(currentRegion.X, currentRegion.Y, Convert.ToInt32(currentSX), Convert.ToInt32(currentSY), false), false);

                var locationToScan = new Location(this.ShipConnectedTo.GetRegion(), newSectorCandidate);

                //run IRS on sector we are moving into
                IRSResult scanResult = ImmediateRangeScan.For(this.ShipConnectedTo).Scan(locationToScan);

                //If newSectorCandidate had negative numbers, then scanResult will have the newly updated region in it

                if (scanResult.GalacticBarrier)
                {
                    this.Game.Write.Line("All Stop. Cannot cross Galactic Barrier.");
                    return;
                }
                else
                {
                    //throw new NotImplementedException(); //how we gonna check for obstacles if scanresult has bad numbers in it?

                    //AdjustSectorToNewRegion may need to be called here

                    bool obstacleEncountered = this.SublightObstacleCheck((Coordinate)travellingShip.Sector, newSectorCandidate, currentRegion.Sectors);
                    if (obstacleEncountered)
                    {
                        this.Game.Write.Line("All Stop.");
                        return;
                    }

                    //bool nebulaEncountered = Sectors.IsNebula(ShipConnectedTo.Map, new Coordinate(Convert.ToInt32(currentSX), Convert.ToInt32(currentSY)));
                    //if (nebulaEncountered)
                    //{
                    //    this.Game.Write.Line("Nebula Encountered. Navigation stopped to manually recalibrate warp coil");
                    //    return;
                    //}
                }

                Location newLocation = locationToScan;
                newLocation.Region = this.Game.Map.Regions.Where(r => r.Name == scanResult.RegionName).Single();

                //todo: finish this.
                var shipRegion = travellingShip.GetRegion();

                if (newLocation.Region != shipRegion)
                {
                    newLocation.Sector = this.AdjustSectorToNewRegion(newLocation, this.Game.Map, shipRegion);
                }

                this.Game.Map.SetPlayershipInLocation(travellingShip, this.Game.Map, newLocation);

                //todo:  this.Game.MoveTimeForward(this.Game.Map, new Coordinate(lastRegionX, lastRegionY), newLocation);
            }
        }