public void ForXTest() { int width = 33; int height = 80; BasicMap map = new BasicMap(width, height, 1, Distance.EUCLIDEAN); List <Coord> pointsSet = new List <Coord>(); int counter = 0; map.ForX((x) => { double y = 14.75 * Math.Sin(x / 30.0) + width / 2; Coord fx = new Coord(x, (int)y); pointsSet.Add(fx); map.SetTerrain(_factory.Generic(fx, counter)); counter++; }); counter = 0; for (int x = 0; x < width; x++) { double y = 14.75 * Math.Sin(x / 30.0) + width / 2; Coord fx = new Coord(x, (int)y); BasicTerrain terrain = map.GetTerrain <BasicTerrain>(fx); Assert.NotNull(terrain); Assert.AreEqual(counter, terrain.Glyph); counter++; } }
public void Reload(BasicMap m, GameContentDataBase gcdb) { buildingCompleteRender = new RenderTarget2D(Game1.graphics.GraphicsDevice, boundingZone.Height * 3, boundingZone.Height); buildingRender = new RenderTarget2D(Game1.graphics.GraphicsDevice, boundingZone.Width, boundingZone.Height); int layer = 0; //location.Y *= -1; foreach (var item in buildingTilesPositions) { buildingTiles.Add(new List <BasicTile>()); foreach (var position in item) { // var chunk = m.testChunk[layer].Find(kv => kv.Key.Contains(position * 64 + location)); var chunk = m.Chunks.Find(c => c.region.Contains(position * 64 + location)); BasicTile tempTIle = chunk.returnLayer(layer).Find(tile => tile.positionGrid == position + location / 64); tempTIle.Reload(gcdb); tempTIle = tempTIle.BClone(); tempTIle.positionGrid = position; tempTIle.BReload(); buildingTiles[layer].Add(tempTIle); } layer++; } }
public void RotateDiscreetTest() { BasicMap rotated = _map.RotateDiscreet(90); //Top left corner becomes top right corner Coord a = new Coord(0, 0); Coord b = new Coord(_map.Width - 1, 0); BasicTerrain t1 = rotated.GetTerrain <BasicTerrain>(a); BasicTerrain t2 = _map.GetTerrain <BasicTerrain>(b); Assert.AreEqual(t1.Glyph, t2.Glyph, "Top left corner wasn't moved to the top right corner."); //top right corner becomes bottom right corner a = b; b = new Coord(_map.Width - 1, _map.Height - 1); t1 = rotated.GetTerrain <BasicTerrain>(a); t2 = _map.GetTerrain <BasicTerrain>(b); Assert.AreEqual(t1.Glyph, t2.Glyph, "Top right quadrant didn't move to the bottom right quadrant."); //bottom right corner become bottom left corner a = b; b = new Coord(0, _map.Height - 1); t1 = rotated.GetTerrain <BasicTerrain>(a); t2 = _map.GetTerrain <BasicTerrain>(b); Assert.AreEqual(t1.Glyph, t2.Glyph, "Bottom right Quadrant didn't move to the bottom left."); //bottom left corner becomes top left corner a = b; b = new Coord(0, 0); t1 = rotated.GetTerrain <BasicTerrain>(a); t2 = _map.GetTerrain <BasicTerrain>(b); Assert.AreEqual(t1.Glyph, t2.Glyph, "Bottom left quadrant didn't move to the top left."); }
private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { if (fileName == "") { DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { fileName = saveFileDialog.FileName; BasicMap map = Processor.CurrentMap; using (FileStream fileStream = File.Create(fileName)) { using (BinaryWriter writer = new BinaryWriter(fileStream)) { map.Save(writer); } } } RefreshTitle(); } else { BasicMap map = Processor.CurrentMap; using (FileStream fileStream = File.Create(fileName)) { using (BinaryWriter writer = new BinaryWriter(fileStream)) { map.Save(writer); } } } }
public void AddDoesntOverWriteTest() { BasicMap newMap = new BasicMap(8, 8, 1, Distance.MANHATTAN); for (int i = 0; i < 8; i++) { newMap.SetTerrain(_factory.Generic(new Coord(i, i), '#')); } newMap.Add(_map); for (int i = 0; i < _map.Width; i++) { for (int j = 0; j < _map.Height; j++) { BasicTerrain t1 = _map.GetTerrain <BasicTerrain>(new Coord(i, j)); BasicTerrain t2 = newMap.GetTerrain <BasicTerrain>(new Coord(i, j)); if (i == j) { Assert.AreEqual('#', t2.Glyph); } else { Assert.AreEqual(t1.Glyph, t2.Glyph); } } } }
static public bool TryCalculatePath(NPC npc, NPCMoveToCommand NPCtc, BasicMap parentMap, BasicTile start, BasicTile end) { BasicMap mapToCheckIn; if (NPCtc.mapID == 0) { mapToCheckIn = parentMap; } else { mapToCheckIn = parentMap.subMaps.Find(m => m.identifier == NPCtc.mapID); } var chunks = MapChunk.returnChunkRadius(mapToCheckIn, start.mapPosition.Location.ToVector2(), 2); if (chunks.Count != 0) { List <BasicTile> tiles = new List <BasicTile>(); foreach (var chunk in chunks) { tiles.AddRange(mapToCheckIn.possibleTilesWithController(chunk.region, mapToCheckIn)); } tiles = tiles.Distinct().ToList(); var test = PathFinder.NewPathSearch(start, end, tiles); if (test != null && test.Count != 0) { return(true); } } return(false); }
public static bool IsClearOfObstructions(this BasicMap m, Coord origin, int width) { for (int i = origin.X; i < origin.X + width; i++) { for (int j = origin.Y; j < origin.Y + width; j++) { Coord c = new Coord(i, j); if (m.Contains(c)) { BasicTerrain t = m.GetTerrain <BasicTerrain>(c); if (t != null) { if (!t.IsWalkable) { return(false); } else if (Equals(_factory.Pavement(c), _factory.Copy(t, c))) //todo: fix this shit { return(false); } } } } } return(true); }
public void GetNPCLogicReady(BasicMap bm) { npcCommands.ForEach(c => c.parentObject = this); mapPlacedID = bm.identifier; //baseCharacter.fromMap = bm; //baseCharacter.currentMapToDisplayOn = bm; }
public SetTile(BasicMap map, Loc2D loc) { this.loc = loc; this.tile = new Tile(map.MapArray[loc.X, loc.Y]); groundLayers = new List <TileAnim>(); for (int i = 0; i < map.GroundLayers.Count; i++) { groundLayers.Add(map.GroundLayers[i].Tiles[loc.X, loc.Y]); } propBackLayers = new List <TileAnim>(); for (int i = 0; i < map.PropBackLayers.Count; i++) { propBackLayers.Add(map.PropBackLayers[i].Tiles[loc.X, loc.Y]); } propFrontLayers = new List <TileAnim>(); for (int i = 0; i < map.PropFrontLayers.Count; i++) { propFrontLayers.Add(map.PropFrontLayers[i].Tiles[loc.X, loc.Y]); } fringeLayers = new List <TileAnim>(); for (int i = 0; i < map.FringeLayers.Count; i++) { fringeLayers.Add(map.FringeLayers[i].Tiles[loc.X, loc.Y]); } }
public double HeightForPrefab(double lat, double lon, BasicMap _map) { //get tile ID //Debug.Log("lat: " + lat + ", long: " + lon); var tileIDUnwrapped = TileCover.CoordinateToTileId(new Mapbox.Utils.Vector2d(lat, lon), 15); // Debug.Log(tileIDUnwrapped); //get tile UnityTile tile = _map._mapVisualizer.GetUnityTileFromUnwrappedTileId(tileIDUnwrapped); //lat lon to meters because the tiles rect is also in meters Vector2d v2d = Conversions.LatLonToMeters(new Mapbox.Utils.Vector2d(lat, lon)); //get the origin of the tile in meters Vector2d v2dcenter = tile.Rect.Center - new Mapbox.Utils.Vector2d(tile.Rect.Size.x / 2, tile.Rect.Size.y / 2); //offset between the tile origin and the lat lon point Vector2d diff = v2d - v2dcenter; //maping the diffetences to (0-1) float Dx = (float)(diff.x / tile.Rect.Size.x); float Dy = (float)(diff.y / tile.Rect.Size.y); //height in unity units var h = tile.QueryHeightData(Dx, Dy); //lat lon to unity units Vector3 location = Conversions.GeoToWorldPosition(lat, lon, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz(); //replace y in position location = new Vector3(location.x, h, location.z); //Debug.Log("our height is: " + h); return(h); }
public void Reset() { this.curMapIndex = 0; foreach (BasicMap map in this.activeMaps) { Destroy(map.gameObject); } foreach (BasicMap map in this.nextMapsToAdd) { Destroy(map.gameObject); } this.activeMaps.Clear(); this.nextMapsToAdd.Clear(); this.GenerateMapsFromIndex(false); BasicMap nextMap = this.nextMapsToAdd.Dequeue(); nextMap.transform.position = Vector3.zero; nextMap.gameObject.SetActive(true); this.activeMaps.Add(nextMap); this.curMapIndex = 0; this.SetTopBarFromMaps(); GameManager.Instance.gameController.topBar.SetLevelIconHighlight(curMapIndex); this.moveMap = true; }
public void ForYTest() { int width = 33; int height = 80; BasicMap map = new BasicMap(width, height, 1, Distance.EUCLIDEAN); List <Coord> pointsSet = new List <Coord>(); int counter = 0; map.ForY((y) => { double x = 14.75 * Math.Sin(y / 30.0) + width / 2; Coord fy = new Coord((int)x, y); pointsSet.Add(fy); map.SetTerrain(_factory.Generic(fy, counter)); counter++; }); counter = 0; for (int y = 0; y < height; y++) { double x = 14.75 * Math.Sin(y / 30.0) + width / 2; BasicTerrain terrain = map.GetTerrain <BasicTerrain>(new Coord((int)x, y)); Assert.NotNull(terrain); Assert.AreEqual(counter, terrain.Glyph); counter++; } }
public static bool ForY(this BasicMap m, Action <int> f) { for (int i = 0; i < m.Height; i++) { f(i); } return(true); }
public static bool ForX(this BasicMap m, Action <int> f) { for (int i = 0; i < m.Width; i++) { f(i); } return(true); }
public static Vector3 WayPointToUnityVector3D2(AnvilWayPoint waypoint) { BasicMap _map = GameObject.Find("Map").GetComponent <BasicMap>(); Vector2d outputV2 = Conversions.GeoToWorldPosition(waypoint.latitude, waypoint.longitude, _map.CenterMercator, _map.WorldRelativeScale); Vector3 outputV3 = new Vector3((float)outputV2.x, 0, (float)outputV2.y); return(outputV3); }
public static List <Building> Generate(BasicMap bm) { var test = AnyBuildingTilesLeft(bm, new List <BasicTile>()); bool bHasBuildingTile = test.Key; if (!test.Key) { return(new List <Building>()); } List <Building> final = new List <Building>(); List <BasicTile> allBuildingTiles = FindBuildingTiles(bm); List <List <BasicTile> > groupedTiles = new List <List <BasicTile> >(); if (allBuildingTiles.Count > 1) { groupedTiles = GroupProximityTiles(allBuildingTiles); } else { groupedTiles.Add(new List <BasicTile>()); groupedTiles[0].Add(allBuildingTiles[0]); } int index = 0; foreach (var group in groupedTiles) { final.Add(new Building()); float firstX = group.Min(t => t.positionGrid.X); float firstY = group.Min(t => t.positionGrid.Y); Vector2 firstPos = new Vector2(firstX, firstY); final[index].location = firstPos * 64; var temp = group.OrderBy(t => t.tileLayer).Select(tile => tile.tileLayer).Distinct(); int layer = 0; foreach (var item in temp) { final[index].buildingTiles.Add(new List <BasicTile>()); foreach (var t in group.FindAll(tile => tile.tileLayer == item)) { BasicTile tempTIle = t.BClone(); tempTIle.positionGrid -= firstPos; final[index].buildingTiles[layer].Add(tempTIle); } layer++; } index++; } final.ForEach(b => b.Generate()); return(final); }
public static ScrollingConsole CreateRenderer( this BasicMap map, int x, int y, int w, int h, Font font = null) { return(map.CreateRenderer( new Microsoft.Xna.Framework.Rectangle(x, y, w, h), font ?? SadConsole.Global.FontDefault )); }
public void ReplaceMapGroup(BasicMap parentMap, String gNameBefore, String gNameAfter) { foreach (var submap in parentMap.subMaps) { if (submap.mapGroup.Equals(gNameBefore, StringComparison.OrdinalIgnoreCase)) { submap.mapGroup = gNameAfter; } } }
// Update is called once per frame void Update() { if (this.moveMap) { for (int i = 0; i < this.activeMaps.Count; i++) { BasicMap map = this.activeMaps[i]; map.PerformUpdate(); } } }
public static IEnumerable <BasicTerrain> GetCreatures(this BasicMap m) { foreach (ISpatialTuple <IGameObject> e in m.Entities) { IGameObject entity = e.Item; if (entity.GetType() == typeof(BasicTerrain) && entity.GetComponent <ActorComponent>() != null) { yield return((BasicTerrain)entity); } } }
internal MapSaveInfo(BasicMap bm) { bInitialized = true; if (GameProcessor.parentMap == bm) { bIsParentMap = true; } mapID = bm.identifier; }
public static BasicMap CropToContent(this BasicMap m) { int minX = m.Width; int maxX = 0; int minY = m.Height; int maxY = 0; for (int x = 0; x < m.Width; x++) { for (int y = 0; y < m.Height; y++) { if (m.GetTerrain <BasicTerrain>(new Coord(x, y)) != null) { if (minX > x) { minX = x; } if (minY > y) { minY = y; } if (maxX < x) { maxX = x; } if (maxY < y) { maxY = y; } } } } int dx = Math.Abs(maxX - minX + 1); int dy = Math.Abs(maxY - minY + 1); Coord offset = new Coord(-minX, -minY); BasicMap map = new BasicMap(dx, dy, EnumUtils.EnumLength <MapLayer>(), Distance.EUCLIDEAN); map.ForXForY((point) => { if (m.Contains(point - offset)) { BasicTerrain terrain = m.GetTerrain <BasicTerrain>(point - offset); if (terrain != null) { map.SetTerrain(_factory.Copy(terrain, point)); } } }); return(map); }
public static bool ForXForY(this BasicMap m, Action <Coord> f) {//makes it hard to debug, so I don't really recommend using this one any more. for (int i = 0; i < m.Width; i++) { for (int j = 0; j < m.Height; j++) { Coord point = new Coord(i, j); f(point); } } return(true); }
public void Setup() { _map = new BasicMap(8, 8, 2, Distance.MANHATTAN); for (int i = 0; i < _map.Width; i++) { for (int j = 0; j < _map.Height; j++) { Coord c = new Coord(i, j); _map.SetTerrain(_factory.Generic(c, i + j)); } } }
private void RegenerateMaps() { GameManager.Instance.gameState.SetLevel(GameManager.Instance.gameState.floorNumber + 1); this.GenerateMapsFromIndex(false); BasicMap nextMap = this.nextMapsToAdd.Dequeue(); nextMap.PositionRelativeTo(this.activeMaps[this.activeMaps.Count - 1].transform.position); nextMap.gameObject.SetActive(true); this.activeMaps.Add(nextMap); this.curMapIndex = 0; this.SetTopBarFromMaps(); GameManager.Instance.gameController.topBar.SetLevelIconHighlight(curMapIndex); }
public void SubsectionTest() { Coord start = new Coord(4, 3); Coord stop = new Coord(6, 7); BasicMap miniMap = _map.Subsection(start, stop); for (int i = 0; i < miniMap.Width; i++) { for (int j = 0; j < miniMap.Height; j++) { Assert.AreEqual(miniMap.GetTerrain <BasicTerrain>(i, j).Glyph, _map.GetTerrain <BasicTerrain>(start.X + i, start.Y + j).Glyph); } } }
private void OnLoadNextMap(BasicMap map) { if (this.nextMapsToAdd.Count == 0) { return; } //randMapIndex = 1; BasicMap newMap = this.nextMapsToAdd.Dequeue(); newMap.PositionRelativeTo(map.transform.position); newMap.gameObject.SetActive(true); this.activeMaps.Add(newMap); }
public void RemoveMapGroup(BasicMap parentMap, String gName) { if (!gName.Equals("None", StringComparison.OrdinalIgnoreCase)) { foreach (var submap in parentMap.subMaps) { if (submap.mapGroup.Equals(gName, StringComparison.OrdinalIgnoreCase)) { submap.mapGroup = "None"; } } gameMapGroups.RemoveAll(name => name.Equals(gName, StringComparison.OrdinalIgnoreCase)); } }
public void AddToLocationTest() { BasicMap largeMap = new BasicMap(18, 18, 1, Distance.MANHATTAN); largeMap.Add(_map, new Coord(_map.Width, _map.Height)); for (int i = 0; i < _map.Width; i++) { for (int j = 0; j < _map.Height; j++) { BasicTerrain t1 = _map.GetTerrain <BasicTerrain>(new Coord(i, j)); BasicTerrain t2 = largeMap.GetTerrain <BasicTerrain>(new Coord(i + _map.Width, j + _map.Height)); Assert.AreEqual(t1.Glyph, t2.Glyph); } } }
public static BasicMap Rotate(this BasicMap m, Coord origin, int radius, int degrees) { BasicMap rotated = new BasicMap(m.Width, m.Height, 1, Distance.EUCLIDEAN); //only rotating the bottom right corner, and not even rotating it correctly if (degrees % 90 == 0) { //this rotates more than just the circle - bug, deal with it later rotated.Add(m.RotateDiscreet(degrees)); } else { BasicMap map = m.RotateDiscreet(360); while (degrees > 45) { degrees -= 90; //rotates more than just this circle - bug - deal with it later map = m.RotateDiscreet(90); } while (degrees <= -45) { degrees += 90; //rotates more than just the circle - bug, fix later map = m.RotateDiscreet(270); } double radians = Calculate.DegreesToRadians(degrees); for (int x = -radius; x < radius; x++) { for (int y = -radius; y < radius; y++) { if (radius > Math.Sqrt(x * x + y * y)) { int xPrime = (int)(x * Math.Cos(radians) - y * Math.Sin(radians)); int yPrime = (int)(x * Math.Sin(radians) + y * Math.Cos(radians)); Coord source = new Coord(x, y) + origin; Coord target = new Coord(xPrime, yPrime) + origin; BasicTerrain terrain = map.GetTerrain <BasicTerrain>(source); if (terrain != null && rotated.Contains(target)) { rotated.SetTerrain(_factory.Copy(terrain, target)); } } } } } return(rotated); }