//todo: refactor these to a setup object public void SetUpPlayerShip(SectorDef playerShipDef) { this.Write.DebugLine(this.Config.GetSetting <string>("DebugSettingUpPlayership")); //todo: remove this requirement if (this.Regions == null) { throw new GameException(this.Config.GetSetting <string>("RegionsNeedToBeSetup1")); } //todo: if playershipDef.GetFromConfig then grab info from config. else set up with default random numbers. var playerShipName = this.Config.GetSetting <string>("PlayerShip"); var startingSector = new Sector(new LocationDef(playerShipDef.RegionDef, new Coordinate(playerShipDef.Sector.X, playerShipDef.Sector.Y))); this.Playership = new Ship(FactionName.Federation, playerShipName, startingSector, this, this.Game) { Allegiance = Allegiance.GoodGuy, Energy = this.Config.GetSetting <int>("energy") }; this.SetupPlayershipRegion(playerShipDef); this.SetupSubsystems(); this.Playership.Destroyed = false; }
private static void SetupRandomRegionDef(SectorDef sectorDef, Regions Regions) { StartOverQ: if (sectorDef.RegionDef == null) { var randomRegion = Coordinate.GetRandom(); if (Regions.NotFound(randomRegion)) { sectorDef.RegionDef = randomRegion; } else { //we got a duplicate random number. This Region is already set up. goto StartOverQ; //todo: rewrite function to remove goto } } }
public void SetupPlayershipRegion(SectorDef playerShipDef) { if (playerShipDef.RegionDef == null) { playerShipDef.RegionDef = Coordinate.GetRandom(); } if (this.Regions.Count == 0) { throw new ArgumentException(this.Config.GetSetting <string>("RegionsNotSetUp")); } var m = this.Regions.Single(q => q.X == playerShipDef.RegionDef.X && q.Y == playerShipDef.RegionDef.Y); this.Playership.Coordinate = new Coordinate(m.X, m.Y); //this.Playership.GetRegion().Active = true; this.Playership.GetRegion().SetActive(); }
public static void SetupNewSector(SectorDef sectorDef, Sectors newSectors, Regions Regions) { //todo: rewrite this function to get rid of GOTO StartOver: var randomSector = Coordinate.GetRandom(); if (newSectors.NotFound(randomSector)) { Sectors.SetupRandomRegionDef(sectorDef, Regions); var locationDef = new LocationDef(sectorDef.RegionDef, new Coordinate(sectorDef.Sector.X, sectorDef.Sector.Y)); var newSector = new Sector(locationDef); newSector.Item = sectorDef.Item; newSectors.Add(newSector); } else { //Console.WriteLine("Sector already Set up: " + sectorDef.Sector.X + "," + sectorDef.Sector.Y); goto StartOver; } }