/// <summary> /// Used to get an idea of the area immediately surrounding the ship /// This was created primarily to determine if a sector surrounding the ship is in another Region for navigation purposes /// This function is called when the ship is set in place on the map. /// /// Called at: /// - The end of Map Initialization /// - End of Navigation /// - When destroyed Ships are cleaned up /// </summary> /// <returns></returns> public void UpdateDivinedSectors() { //Scan happens like this, in number order: //036 //036 //147 //1X7 <-- X is you //258 //258 //Immediate Range Scan //Busted //↑|↑|→ //+|-|+ //E|P|→ //+|+|+ //E|E|→ //-|-|- //Longhand //[3,6] E [3,7] S [3,→] FreeHold //[4,6] E [4,7] P [4,→] FreeHold //[5,6] E [5,7] E [5,→] FreeHold //← ↑ → ↓ //Portal to other Galaxy - ⇄ //⇶ //http://en.wikipedia.org/wiki/Template:Unicode_chart_Arrows var myLocation = this.GetLocation(); this.Sector.Neighbors = new List <DivinedSectorItem>(); int row = 0; for (var sectorL = myLocation.Sector.Y - 1; sectorL <= myLocation.Sector.Y + 1; sectorL++) { if (sectorL >= -1 && sectorL <= 8) { for (var sectorT = myLocation.Sector.X - 1; sectorT <= myLocation.Sector.X + 1; sectorT++) { var currentResult = new DivinedSectorItem(); currentResult.MyLocation = myLocation.Sector.X == sectorT && myLocation.Sector.Y == sectorL; currentResult.Location = new Location(); if (sectorT >= -1 && sectorT <= 8) { Sectors sectorsToQuery = myLocation.Region.Sectors; currentResult.Location.Sector = sectorsToQuery.GetNoError(new Coordinate(sectorT, sectorL, false)); bool nullSector = currentResult.Location.Sector == null; if (nullSector) { var currentRegion = myLocation.Region; //todo: debug: fix this. if (sectorT == 8 || sectorT == -1) { //todo: error here when game starts out. is ship spawning in negative sector space? //todo: if so, a solution could be to run GetDivinedSector() on currentLocation to fix. int i; } var boundsChecking = false; var sectorToExamine = new Sector(new LocationDef(currentRegion, new Coordinate(sectorT, sectorL, boundsChecking)), boundsChecking); var locationToExamine = new Location(currentRegion, sectorToExamine); //todo: this could be currentRegion.GetDivinedSector() Location neighborSectorLocation = myLocation.Region.DivineSectorOnMap(locationToExamine, this.Map); if (neighborSectorLocation.Region.Type != RegionType.GalacticBarrier) { //todo: are we moving the Ship? what's going on? //currentResult.Location.Region = neighborSectorLocation.Region; //sectorsToQuery = currentResult.Location.Region.Sectors; //this.Map.Write.SingleLine(currentResult.Location.Region.Name); ////Do we really need this second assignment? //currentResult.Location.Sector = sectorsToQuery.GetNoError(new Coordinate(lookedUpLocation.Sector.X, lookedUpLocation.Sector.Y, false)); } } } row++; } } row++; } }