/// <summary> /// Initializes a new instance of the World. /// </summary> /// <param name="worldSize">Size of World (measured by rows and columns).</param> public World(WorldSize worldSize, IWorldGenerator worldGenerator) { this.worldGenerator = worldGenerator; this.Size = worldSize; NextGeneration(); }
public void NextWorld_ReturnsWorldWithLife_On_WorldWithLifeOnEdges() { var worldSize = new WorldSize(width: 3, height: 3, depth: 3); var locationOfLiveCells = new Coordinate[] { new Coordinate(0, 0, 0), new Coordinate(1, 1, 1), new Coordinate(2, 2, 2), }; var worldWithLifeOnEdges = new World(worldSize, locationOfLiveCells); Array.ForEach(locationOfLiveCells, l => Assert.IsType <LivingCell>(GetCell(worldWithLifeOnEdges, l))); var worldAllLocationsAlive = worldWithLifeOnEdges.NextWorld(); Array.ForEach(worldAllLocationsAlive.Locations.ToArray(), l => Assert.IsType <LivingCell>(GetCell(worldAllLocationsAlive, l.Coordinate))); var emptyWorld = worldAllLocationsAlive.NextWorld(); Array.ForEach(emptyWorld.Locations.ToArray(), l => Assert.IsType <DeadCell>(GetCell(emptyWorld, l.Coordinate))); }
/// <summary> /// Generates grid of first generation. /// </summary> public WorldGenerationResult RandomGeneration(WorldSize worldSize) { if (worldSize.Rows < 1 || worldSize.Columns < 1) // worldSize size is invalid { throw new ArgumentOutOfRangeException("World Size has incorrect value", nameof(worldSize)); } var firstGeneration = new CellStatus[worldSize.Rows, worldSize.Columns]; int aliveCells = 0; // Randomly initialize grid for (var row = 0; row < worldSize.Rows; row++) { for (var column = 0; column < worldSize.Columns; column++) { firstGeneration[row, column] = (CellStatus)RandomNumberGenerator.GetInt32(0, 2); var cell = firstGeneration[row, column]; if (cell == CellStatus.Alive) { aliveCells++; } } } return(new WorldGenerationResult { AliveCells = aliveCells, IsGenerationAlive = aliveCells > 0, Generation = firstGeneration }); }
private void OnWorldSizeValueChanged(Entity entity) { RadioButton selectedOption = (RadioButton)entity; string value = selectedOption.TextParagraph.Text.ToLower(); switch (value) { case "small": newWorldSize = WorldSize.TINY; break; case "medium": newWorldSize = WorldSize.MEDIUM; break; case "large": newWorldSize = WorldSize.LARGE; break; default: newWorldSize = WorldSize.SMALL; break; } }
public void PopulateWorld_ThrowsArgumentException_At_LocationOutOfBounds(int outOfBoundsX, int outOfBoundsY, int outOfBoundsZ) { var outOfBounds = new Coordinate(outOfBoundsX, outOfBoundsY, outOfBoundsZ); var worldSize = new WorldSize(3, 3, 3); Assert.Throws <InvalidLocation>(() => new World(worldSize: worldSize, livingCoords: new Coordinate[] { outOfBounds })); }
//////////////// public override void Initialize() { WorldSize size = WorldHelpers.GetSize(); switch (size) { default: case WorldSize.SubSmall: this.MaxAmbushes = AmbushesMod.Config.TinyWorldInitialAmbushes; break; case WorldSize.Small: this.MaxAmbushes = AmbushesMod.Config.SmallWorldInitialAmbushes; break; case WorldSize.Medium: this.MaxAmbushes = AmbushesMod.Config.MediumWorldInitialAmbushes; break; case WorldSize.Large: this.MaxAmbushes = AmbushesMod.Config.LargeWorldInitialAmbushes; break; case WorldSize.SuperLarge: this.MaxAmbushes = AmbushesMod.Config.HugeWorldInitialAmbushes; break; } this.AmbushMngr = new AmbushManager(size); }
public void WorldSize_GoodSize(int goodWidth, int goodHeight, int goodDepth) { var worldSize = new WorldSize(goodWidth, goodHeight, goodDepth); Assert.Equal(goodWidth, worldSize.Width); Assert.Equal(goodHeight, worldSize.Height); Assert.Equal(goodDepth, worldSize.Depth); }
/// <summary> /// Overloaded constructor for the PaperWorld class that uses custom World Size. /// </summary> /// <param name="name">Name of this world.</param> /// <param name="width">Width of this world in tiles.</param> /// <param name="height">Height of this world in tiles.</param> public PaperWorld(string name, int width, int height) { this.name = name; worldSize = WorldSize.Custom; this.width = width; this.height = height; layers = new List <PaperWorldLayer>(); }
public World(WorldSize s, WorldType t, Season se, AxisTilt at) { size = s; type = t; season = se; tilt = at; origin = Vector3.zero; }
public void RenderWorld_Returns_2DEmpty_World() { var expectedOutput = "...\n...\n...\n"; var worldSize = new WorldSize(width: 3, height: 3); var emptyWorld = new World(worldSize: worldSize); var actualOutput = WorldRenderer.RenderWorld(emptyWorld); Assert.Equal(expectedOutput, actualOutput); }
public void RenderWorld_Returns_2DWorld_With_Life() { var expectedOutput = ".*.\n*..\n..*\n"; var worldSize = new WorldSize(width: 3, height: 3); var liveLocations = new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 0), new Coordinate(2, 2) }; var worldWithLife = new World(worldSize: worldSize, livingCoords: liveLocations); var actualOutput = WorldRenderer.RenderWorld(worldWithLife); Assert.Equal(expectedOutput, actualOutput); }
public void RenderWorld_Returns_3DEmpty_World() { var expectedWorld = "..|..|..|..\n..|..|..|..\n"; var worldSize = new WorldSize(width: 2, height: 2, depth: 4); var empty3DWorld = new World(worldSize: worldSize); var actualWorld = WorldRenderer.RenderWorld(empty3DWorld); Assert.Equal(expectedWorld, actualWorld); }
public void IsStagnant_ReturnsFalse_With_ProgressingWorld() { var worldSize = new WorldSize(3, 3); var locationOfLiveCells = new Coordinate[] { new Coordinate(0, 0), }; var progressingWorld = new World(worldSize: worldSize, livingCoords: locationOfLiveCells); Assert.False(progressingWorld.IsStagnant()); }
public void SetSize(WorldSize sz) { var mpsz = MapSizes.First(s => s.WorldSize == sz); SizeX = mpsz.SizeX; SizeZ = mpsz.SizeY; HumanSettlements = mpsz.HumanSettlements; PointOfInterests = mpsz.PointOfInterests; VillagesToGenerate = mpsz.VillagesToGenerate; }
public static string CreateNormalWorld(string name, WorldSize size, bool save) { int x; int y; switch (size) { case WorldSize.Small: x = 4200; y = 1200; break; case WorldSize.Medium: x = 6400; y = 1800; break; case WorldSize.Large: x = 8400; y = 2400; break; default: x = 0; y = 0; break; } subworldLibrary = ModLoader.GetMod("SubworldLibrary"); if (subworldLibrary != null) { object result = subworldLibrary.Call( "Register", /*Mod mod*/ ModContent.GetInstance <Multiverse>(), /*string name*/ name, /*int width*/ x, /*int height*/ y, /*List<GenPass> tasks*/ NormalGenPassList(), /*the following ones are optional, I've included three here (technically two but since order matters, had to pass null for the unload argument) * /*Action load*/(Action)LoadNormalWorld, /*Action unload*/ null, /*ModWorld modWorld*/ null, /*bool saveSubworld*/ save ); if (result != null && result is string id) { return(id); } } return(string.Empty); }
/// <summary> /// Creates new game. /// </summary> private void CreateGame() { int worldsCount = gamePresenter.RequestCountOfWorlds(); WorldSize worldSize = gamePresenter.RequestWorldSize(MinWorldSize, MaxWorldSize); worlds = CreateWorlds(worldsCount, worldSize); RequestDisplayWorlds(); gamePresenter.PauseRequested += Pause; StartGameTimer(); }
public void RandomGeneration_IncorrectInput_ShouldThrowArgumentException(int rows, int columns) { // Arrange WorldGenerator worldGenerator = new WorldGenerator(); WorldSize worldSize = new WorldSize { Rows = rows, Columns = columns }; // Act and Assert Assert.Throws <ArgumentOutOfRangeException>(() => worldGenerator.RandomGeneration(worldSize)); }
/// <summary> /// Starts a new server session. /// </summary> /// <param name="worldSize"></param> /// <param name="age"></param> /// <param name="climate"></param> /// <param name="landmass"></param> /// <param name="temperature"></param> /// <param name="waterCoverage"></param> /// <param name="barbarianAggressiveness"></param> /// <param name="difficulty"></param> /// <param name="rules"></param> public void StartServer(WorldSize worldSize, Age age, Temperature temperature, Climate climate, Landmass landmass, WaterCoverage waterCoverage, BarbarianAggressiveness barbarianAggressiveness, Difficulty difficulty, Rules rules) { OnServerStarting(); this.rules = rules; OnStatusChanged(new StatusChangedEventArgs(ServerResources.CreatingMap, 5)); GridBuilder builder = new GridBuilder(); this.grid = builder.Build(worldSize, age, temperature, climate, landmass, waterCoverage, this.ruleset); OnStatusChanged(new StatusChangedEventArgs(ServerResources.AddingVillages, 10)); AddVillages(worldSize); this.year = -4000; OnServerStarted(); }
public void NextWorld_ReturnsStagnantWorld_On_StagnantWorld() { var worldSize = new WorldSize(5, 5); var locationOfLiveCells = new Coordinate[] { new Coordinate(0, 0), new Coordinate(0, 1), new Coordinate(1, 0), new Coordinate(1, 1), }; var stagnantWorld = new World(worldSize: worldSize, livingCoords: locationOfLiveCells); Assert.Equal(stagnantWorld, stagnantWorld.NextWorld()); }
//////////////// public AmbushManager(WorldSize size) { var dungeonWalls = new HashSet <int>(TileWallHelpers.UnsafeDungeonWallTypes); dungeonWalls.Add(WallID.LihzahrdBrickUnsafe); this.ViableAmbushTilePattern = new TilePattern(new TilePatternBuilder { HasSolidProperties = false, IsPlatform = false, IsActuated = false, MaximumBrightness = 0.25f, CustomCheck = (x, y) => !dungeonWalls.Contains(Main.tile[x, y].wall) }); }
/// <summary> /// Creates list of worlds. /// </summary> /// <param name="worldsCount">Count of worlds to create</param> /// <param name="worldSize">World size</param> /// <returns></returns> private List <World> CreateWorlds(int worldsCount, WorldSize worldSize) { var worldGenerator = new WorldGenerator(); var newWorlds = new List <World>(); for (int i = 1; i <= worldsCount; i++) { var world = new World(worldSize, worldGenerator); newWorlds.Add(world); } return(newWorlds); }
/// <summary> /// Overloaded constructor for the PaperWorld class that uses a pre-defined World Size. /// </summary> /// <param name="name">Name of this world.</param> public PaperWorld(string name, WorldSize worldSize) { this.name = name; this.worldSize = worldSize; if (GetWorldSize == WorldSize.Custom) { MeasureWorld(WorldSize.Small); } else { MeasureWorld(GetWorldSize); } layers = new List <PaperWorldLayer>(); }
public IEnumerable <Property> ToProperties() { // Add simple fields. var properties = new List <Property> { new Property(nameof(WorldSize), WorldSize.ToString(), comment: "The width and height of the game world."), new Property(nameof(MsPerFrame), MsPerFrame.ToString(), comment: "The number of milliseconds to spend per frame. FPS = 1000 / MsPerFrame."), new Property(nameof(FramesPerShot), FramesPerShot.ToString(), comment: "The number of frames to pause between each firing of a projectile."), new Property(nameof(RespawnRate), RespawnRate.ToString(), comment: "How many frames before a dead ship respawns."), new Property(nameof(ShipHitpoints), ShipHitpoints.ToString(), comment: "How many hitpoints ships should start with."), new Property(nameof(ProjectileSpeed), ProjectileSpeed.ToString(CultureInfo.InvariantCulture), comment: "How many units per frame that projectiles travel."), new Property(nameof(ShipEngineStrength), ShipEngineStrength.ToString(CultureInfo.InvariantCulture), comment: "How many units per frame that ships accellerate when thrusting."), new Property(nameof(ShipTurningRate), ShipTurningRate.ToString(CultureInfo.InvariantCulture), comment: "The degrees that a ship can rotate per frame."), new Property(nameof(ShipCollisionRadius), ShipCollisionRadius.ToString(CultureInfo.InvariantCulture), comment: "How close a projectile must get to collide with a ship."), new Property(nameof(StarCollisionRadius), StarCollisionRadius.ToString(CultureInfo.InvariantCulture), comment: "How close a projectile or ship must get to collide with a star."), new Property(nameof(ExplosiveGameMode), ExplosiveGameMode.ToString(), comment: "Set to true to enable the explosive game mode, where a large number of projectiles are spawned each time a sihp dies.") }; // Add all stars. foreach (var star in Stars) { properties.Add(new Property( nameof(Star), attributes: new Dictionary <string, string> { ["x"] = star.Location.GetX().ToString(CultureInfo.InvariantCulture), ["y"] = star.Location.GetY().ToString(CultureInfo.InvariantCulture), ["mass"] = star.Mass.ToString(CultureInfo.InvariantCulture) }, comment: "The location and mass of a star." )); } return(properties); }
private void Start() { if (WorldInfo.useWorldInfo) { seed = WorldInfo.worldSeed; worldSize = WorldInfo.worldSize; } if (seed == 0) { seed = RandomString(8).GetHashCode(); } Generator.worldSeed = seed; Generation(); }
/// <summary> /// Generates a map with the specified parameters. /// </summary> /// <param name="worldSize"></param> /// <param name="worldAge"></param> /// <param name="worldTemperature"></param> /// <param name="worldClimate"></param> /// <param name="worldLandmass"></param> /// <param name="worldWaterCoverage"></param> /// <param name="ruleset"></param> /// <returns></returns> public Grid Build(WorldSize worldSize, Age worldAge, Temperature worldTemperature, Climate worldClimate, Landmass worldLandmass, WaterCoverage worldWaterCoverage, Ruleset ruleset) { Size size = GetDimensions(worldSize); this.grid = BuildGrid(size); this.ruleset = ruleset; List <Point> seeds = GetLandSeeds(grid, worldLandmass); GrowLandSeeds(seeds, worldWaterCoverage); GenerateHeightMap(worldAge); GenerateTemperatureMap(worldTemperature); GenerateClimateMap(worldClimate); AddTerrain(); AddRivers(); AddLakes(); AddResources(); return(grid); }
public WorldGen(WorldSize size) { switch (size) { case WorldSize.Small: width = 75; height = 50; exclusion = 12; seedCount = 90; xyamount = 3; percentDraw = .3; townCount = 5; townSpacing = 15; waterSpacing = 6; break; case WorldSize.Medium: width = 125; height = 90; exclusion = 18; seedCount = 250; xyamount = 5; percentDraw = .3; townCount = 6; townSpacing = 15; waterSpacing = 5; break; case WorldSize.Large: width = 175; height = 90; exclusion = 18; seedCount = 340; xyamount = 7; percentDraw = .3; break; } }
public PlanetSettings GeneratePlanet() { WorldSize worldSize = Database.WorldDatabase.World.sizes[Utils.RandomInt(random, 0, Database.WorldDatabase.World.sizes.Length)]; int oreSamples = Database.WorldDatabase.World.oreSamples[Utils.RandomInt(random, 0, Database.WorldDatabase.World.oreSamples.Length)]; double heightBoost = Database.WorldDatabase.World.heightBoost[Utils.RandomInt(random, 0, Database.WorldDatabase.World.heightBoost.Length)]; List <string> ores = new List <string>(); for (int i = 0; i < oreSamples; i++) { ores.Add(Database.WorldDatabase.World.ores[Utils.RandomInt(random, 0, Database.WorldDatabase.World.ores.Length)]); } float oreLengthBoost = Database.WorldDatabase.World.oreLengthBoost[Utils.RandomInt(random, 0, Database.WorldDatabase.World.oreLengthBoost.Length)]; float caveLengthBoost = Database.WorldDatabase.World.caveLengthBoost[Utils.RandomInt(random, 0, Database.WorldDatabase.World.caveLengthBoost.Length)]; string biome = Database.WorldDatabase.World.biomes[Utils.RandomInt(random, 0, Database.WorldDatabase.World.biomes.Length)]; string surfaceTile = Database.BiomeDatabase.BiomeDictionary[biome].surfaceTile; string middleTile = Database.BiomeDatabase.BiomeDictionary[biome].middleTile; string undergroundTile = Database.BiomeDatabase.BiomeDictionary[biome].undergroundTile; string[] features = Database.BiomeDatabase.BiomeDictionary[biome].features; PlanetSettings settings = new PlanetSettings { worldSize = worldSize, heightBoost = heightBoost, ores = ores.ToArray(), oreLengthBoost = oreLengthBoost, caveLengthBoost = caveLengthBoost, biome = biome, surfaceTile = surfaceTile, middleTile = middleTile, undergroundTile = undergroundTile, features = features }; Debug.Log("GENERALMANAGER:GENERATEPLANET():PLANETSETTINGS:"); settings.DebugPrint(); return(settings); }
public void RenderWorld_Returns_3DWorld_With_Life() { var expectedWorld = "*..|...|...\n...|.*.|.*.\n*..|..*|..*\n"; var worldSize = new WorldSize(width: 3, height: 3, depth: 3); var liveLocations = new Coordinate[] { new Coordinate(0, 0, 0), new Coordinate(2, 0, 0), new Coordinate(1, 1, 1), new Coordinate(2, 2, 1), new Coordinate(1, 1, 2), new Coordinate(2, 2, 2), }; var worldWithLife = new World(worldSize: worldSize, livingCoords: liveLocations); var actualWorld = WorldRenderer.RenderWorld(worldWithLife); Assert.Equal(expectedWorld, actualWorld); }
/// <summary> /// Sets tile width & height of the world based on world size. /// </summary> private void MeasureWorld(WorldSize worldSize) { switch (worldSize) { case WorldSize.Small: // Small width = Global.SM_World_Width; height = Global.SM_World_Height; break; case WorldSize.Medium: // Medium width = Global.MED_World_Width; height = Global.MED_World_Height; break; case WorldSize.Large: // Large width = Global.LG_World_Width; height = Global.LG_World_Height; break; } }
/// Adds the villages to the grid. private void AddVillages(WorldSize worldSize) { int numVillages = 0; GridCell nextVillageCell; Village nextVillage; switch (worldSize) { case WorldSize.Tiny: numVillages = 10; break; case WorldSize.Small: numVillages = 20; break; case WorldSize.Standard: numVillages = 30; break; case WorldSize.Large: numVillages = 40; break; case WorldSize.Huge: numVillages = 50; break; } for (int i = 1; i <= numVillages; i++) { do { nextVillageCell = this.grid.FindRandomDryCell(); } while(nextVillageCell.Village != null); //FIXME: get village names from Xml. nextVillage = new Village("Sioux"); nextVillageCell.Village = nextVillage; } }