public void GlobalSetup() { var map = new Generator(MapSize, MapSize) .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps())) .Context.GetFirst <IGridView <bool> >("WallFloor"); var goalView = new ArrayView <GoalState>(map.Width, map.Height); goalView.ApplyOverlay(pos => map[pos] ? GoalState.Clear : GoalState.Obstacle); goalView[map.Bounds().Center] = GoalState.Goal; // Create the goal maps used as the desires. They all use the same goals and weights, which in general is not // realistic, but will provide a mathematically solid test base nonetheless. var maps = new List <GoalMap>(); for (int i = 0; i < NumGoalMaps; i++) { var desireMap = new GoalMap(goalView, DistanceCalc); maps.Add(desireMap); } // Create overall weighted goal map _desireMap = new WeightedGoalMap(maps); // Pre-calculate the point we'll access _threeQuarters = new Point(map.Width, map.Height) * 0.75; }
public void GlobalSetup() { var map = new Generator(MapSize, MapSize) .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps())) .Context.GetFirst <IGridView <bool> >("WallFloor"); var goalsBase = new LambdaTranslationGridView <bool, GoalState>(map, val => val ? GoalState.Clear : GoalState.Obstacle); var singleGoalView = new ArrayView <GoalState>(map.Width, map.Height); singleGoalView.ApplyOverlay(goalsBase); singleGoalView[map.Bounds().Center] = GoalState.Goal; _singleGoalMap = new GoalMap(singleGoalView, DistanceCalc); _singleFleeMap = new FleeMap(_singleGoalMap); var dualGoalView = new ArrayView <GoalState>(map.Width, map.Height); dualGoalView.ApplyOverlay(goalsBase); foreach (var rect in dualGoalView.Bounds().BisectVertically()) { dualGoalView[rect.Center] = GoalState.Goal; } _dualGoalMap = new GoalMap(dualGoalView, DistanceCalc); _dualFleeMap = new FleeMap(_dualGoalMap); }
private static RogueLikeMap GenerateMap() { // Generate a rectangular map for the sake of testing with GoRogue's map generation system. var generator = new Generator(MapWidth, MapHeight) .ConfigAndGenerateSafe(gen => { gen.AddSteps(DefaultAlgorithms.RectangleMapSteps()); }); var generatedMap = generator.Context.GetFirst <ISettableGridView <bool> >("WallFloor"); // Create a RogueLikeMap structure, specifying the appropriate viewport size for the default renderer RogueLikeMap map = new RogueLikeMap(MapWidth, MapHeight, new DefaultRendererParams((Width, Height)), 4, Distance.Manhattan); // Add a component that will implement a character "memory" system, where tiles will be dimmed when they aren't seen by the player, // and remain visible exactly as they were when the player last saw them regardless of changes to their actual appearance, // until the player sees them again. map.AllComponents.Add(new DimmingMemoryFieldOfViewHandler(0.6f)); // Translate the GoRogue map generation context's information on the map to appropriate RogueLikeCells. We must use MemoryAwareRogueLikeCells // because we are using the integration library's "memory-based" fov visibility system. foreach (var location in map.Positions()) { bool walkable = generatedMap[location]; int glyph = walkable ? '.' : '#'; map.SetTerrain(new MemoryAwareRogueLikeCell(location, Color.White, Color.Black, glyph, 0, walkable, walkable)); } return(map); }
public void ApplyTerrainOverlayTranslation() { var grMap = new Generator(10, 10) .AddSteps(DefaultAlgorithms.RectangleMapSteps()) .Generate() .Context.GetFirstOrDefault <ISettableGridView <bool> >(); TestUtils.NotNull(grMap); // Create map and apply overlay with a translation function var map = new Map(grMap.Width, grMap.Height, 1, Distance.Chebyshev); map.ApplyTerrainOverlay(grMap, (pos, b) => b ? new GameObject(pos, 0) : new GameObject(pos, 0, false, false)); foreach (var pos in grMap.Positions()) { var terrain = map.GetTerrainAt(pos); TestUtils.NotNull(terrain); Assert.Equal(grMap[pos], terrain.IsWalkable); } }
private void CreateSenseMap() { // Create sense map of rectangular area var wallFloor = new Generator(MapSize, MapSize) .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps())) .Context.GetFirst <IGridView <bool> >("WallFloor"); var resMap = new ArrayView <double>(wallFloor.Width, wallFloor.Height); resMap.ApplyOverlay(pos => wallFloor[pos] ? 0.0 : 1.0); _senseMap = new SenseMap(resMap); }
public void ApplyTerrainOverlayPositions() { var grMap = new Generator(10, 10) .AddSteps(DefaultAlgorithms.RectangleMapSteps()) .Generate() .Context.GetFirstOrDefault <ISettableGridView <bool> >(); TestUtils.NotNull(grMap); // Create map and apply overlay with a translation function var map = new Map(grMap.Width, grMap.Height, 1, Distance.Chebyshev); map.ApplyTerrainOverlay(grMap, (pos, b) => b ? new GameObject(pos, 0) : new GameObject(pos, 0, true, false)); // Assert all objects are at right position to start with foreach (var pos in grMap.Positions()) { var terrain = map.GetTerrainAt(pos); TestUtils.NotNull(terrain); Assert.Equal(pos, terrain.Position); } // Rearrange positions by mirror-imaging in X/Y var terrainMap2 = new ArrayView <IGameObject>(map.Width, map.Height); foreach (var(x, y) in map.Positions()) { var terrain = map.GetTerrainAt(x, y); TestUtils.NotNull(terrain); terrainMap2[map.Width - 1 - x, map.Height - 1 - y] = terrain; } // Apply overlay, hopefully adapting positions properly map.ApplyTerrainOverlay(terrainMap2); foreach (var pos in grMap.Positions()) { var terrain = map.GetTerrainAt(pos); TestUtils.NotNull(terrain); Assert.Equal(pos, terrain.Position); } }
public void GlobalSetup() { // Center FOV in middle of open map _center = (MapWidth / 2, MapHeight / 2); // Generate rectangular map var gen = new Generator(MapWidth, MapHeight); gen.ConfigAndGenerateSafe(g => g.AddSteps(DefaultAlgorithms.RectangleMapSteps())); // Extract wall-floor map which we can use as transparency view var transparencyView = gen.Context.GetFirst <IGridView <bool> >("WallFloor"); // Create FOV structure to use _fov = new RecursiveShadowcastingFOV(transparencyView); }
public void GlobalSetup() { var map = new Generator(PathDistance + 5, PathDistance + 5) .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps())) .Context.GetFirst <IGridView <bool> >("WallFloor"); // A couple points exactly PathDistance apart. We keep the paths on the same y-line so that they are // PathDistance apart regardless of the DistanceCalc. // Path performance checks will independently path both from p1 to p2 and from p2 to p1, in order to // account for one direction likely being faster (first direction checked in the neighbors loop) _p1 = (1, 5); _p2 = (PathDistance + 1, 5); // An AStar instance to use for pathing _aStar = new GoRogue.Pathing.AStar(map, DistanceCalc); // Equivalent FastAStar instance _fastAStar = new FastAStar(map, DistanceCalc); }
public void GlobalSetup() { // Use GoRogue map generation to generate terrain data var wallFloor = new Generator(Size, Size) .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps())) .Context.GetFirst <IGridView <bool> >("WallFloor"); // Create real map and apply terrain _map = new Map(Size, Size, NumEntityLayers, Distance.Chebyshev); _map.ApplyTerrainOverlay(wallFloor, (pos, val) => new GameObject(pos, 0, val, val)); // Spawn correct number of entities float spawnRegion = (float)Size - 2; // Range (1, width - 1) float increment = spawnRegion / NumEntitySpawnLocations; int spawns = 0; for (float i = increment; i < Size - 1; i += increment) { int val = (int)i; var position = new Point(val, val); for (int j = 0; j < NumEntitiesPerLocation; j++) { var entity = new GameObject(position, j % NumEntityLayers + 1, j != 0); _map.AddEntity(entity); } // Record two positions (with and without entities) we can test against _positionWithEntities = position; _positionWithoutEntities = position - 1; // Sanity check spawns++; } if (spawns != NumEntitySpawnLocations) { throw new Exception($"Incorrect number of entity spawn locations. Got: {spawns}, but wanted: {NumEntitySpawnLocations}"); } // Record center for caching purposes _center = _map.Bounds().Center; }
public static MyGameMap GenerateDungeonMap(int width, int height) { // Generate a rectangular map for the sake of testing with GoRogue's map generation system. // // CUSTOMIZATION: Use a different set steps in AddSteps to generate a different type of map. var generator = new Generator(width, height) .ConfigAndGenerateSafe(gen => { gen.AddSteps(DefaultAlgorithms.RectangleMapSteps()); }); var generatedMap = generator.Context.GetFirst <ISettableGridView <bool> >("WallFloor"); // Create actual integration library map. var map = new MyGameMap(generator.Context.Width, generator.Context.Height, null); // Add a component that will implement a character "memory" system, where tiles will be dimmed when they aren't seen by the player, // and remain visible exactly as they were when the player last saw them regardless of changes to their actual appearance, // until the player sees them again. // // CUSTOMIZATION: If you want to handle FOV visibility differently, you can create an instance of one of the // other classes in the FieldOfView namespace, or create your own by inheriting from FieldOfViewHandlerBase map.AllComponents.Add(new DimmingMemoryFieldOfViewHandler(0.6f)); // Translate GoRogue's terrain data into actual integration library objects. Our terrain must be of type // MemoryAwareRogueLikeCells because we are using the integration library's "memory-based" fov visibility // system. map.ApplyTerrainOverlay(generatedMap, (pos, val) => val ? MapObjectFactory.Floor(pos) : MapObjectFactory.Wall(pos)); // Generate 10 enemies, placing them in random walkable locations for demo purposes. for (int i = 0; i < 10; i++) { var enemy = MapObjectFactory.Enemy(); enemy.Position = map.WalkabilityView.RandomPosition(true); map.AddEntity(enemy); } return(map); }
public void ApplyTerrainOverlay() { var grMap = new Generator(10, 10) .AddSteps(DefaultAlgorithms.RectangleMapSteps()) .Generate() .Context.GetFirstOrDefault <ISettableGridView <bool> >(); TestUtils.NotNull(grMap); // Normally, in this situation, you would just use the ApplyTerrainOverlay function overload that takes // a translation function, instead of creating tempMap and translationMap. But we want to test the other // overload so we do it this way only for testing var translationMap = new LambdaTranslationGridView <bool, IGameObject>(grMap, (pos, val) => val ? new GameObject(pos, 0) : new GameObject(pos, 0, true, false)); // Create map var map = new Map(grMap.Width, grMap.Height, 1, Distance.Chebyshev); // Create temporary map to record what values are supposed to be var tempMap = new ArrayView <IGameObject>(grMap.Width, grMap.Height); tempMap.ApplyOverlay(translationMap); // Apply overlay map.ApplyTerrainOverlay(tempMap); // Verify tiles match Assert.Equal(grMap.Width, map.Width); Assert.Equal(grMap.Height, map.Height); foreach (var pos in map.Positions()) { Assert.Equal(tempMap[pos], map.GetTerrainAt(pos)); } }
private static RogueLikeMap GenerateMap() { // Generate a rectangular map for the sake of testing. var generator = new Generator(MapWidth, MapHeight) .ConfigAndGenerateSafe(gen => { gen.AddSteps(DefaultAlgorithms.RectangleMapSteps()); }); var generatedMap = generator.Context.GetFirst <ISettableGridView <bool> >("WallFloor"); RogueLikeMap map = new RogueLikeMap(MapWidth, MapHeight, new DefaultRendererParams((Width, Height)), 4, Distance.Manhattan); map.AllComponents.Add(new DimmingMemoryFieldOfViewHandler(0.6f)); foreach (var location in map.Positions()) { bool walkable = generatedMap[location]; int glyph = walkable ? '.' : '#'; map.SetTerrain(new MemoryAwareRogueLikeCell(location, Color.White, Color.Black, glyph, 0, walkable, walkable)); } return(map); }