/// <summary> /// The path find. /// </summary> /// <param name="start"> /// The start. /// </param> /// <param name="target"> /// The target. /// </param> /// <returns> /// The <see cref="Path"/>. /// </returns> public Path<MapSquare> PathFind(MapSquare start, MapSquare target) { if (start == null) { throw new ArgumentNullException("start"); } if (target == null) { throw new ArgumentNullException("target"); } var path = AStar.FindPath( start, target, AgentBelief.Neighbours, (m1, m2) => { var p1 = BDPMap.Instance.GetPortalGroupBySquare(m1); var p2 = BDPMap.Instance.GetPortalGroupBySquare(m2); if (p1 != null && p2 != null) { return PGBeliefDistance(p1[0], p2[0]); } return MapSquare.Distance(m1, m2); }, (ms) => MapSquare.Distance(ms, target)); return path; }
public static List<MapSquare> GetLowLevelNeighbours(MapSquare ms) { if (ms == null) { throw new ArgumentNullException("ms"); } var result = new List<MapSquare>(); // Add up. if (BDPMap.Instance.IsFree(ms.Up)) { result.Add(ms.Up); } // Add down. if (BDPMap.Instance.IsFree(ms.Down)) { result.Add(ms.Down); } // Add left. if (BDPMap.Instance.IsFree(ms.Left)) { result.Add(ms.Left); } // Add right. if (BDPMap.Instance.IsFree(ms.Right)) { result.Add(ms.Right); } return result; }
public bool IsFree(MapSquare ms) { if (portalSquares.ContainsKey(ms)) { return portalSquares[ms]; } return Original.IsFree(ms); }
/// <summary> /// MoveTo the given MapSquare. /// </summary> /// <param name="ms"></param> /// <returns></returns> public bool MoveTo(MapSquare ms) { if (!BDPMap.Instance.IsFree(ms)) { return false; } CurrentPosition = ms; return true; }
public bool IsFree(MapSquare ms) { if (BDPMap.Instance.IsPortalSquare(ms)) { var pgs = BDPMap.Instance.GetPortalGroupBySquare(ms); foreach (PortalGroup pg in pgs) { if (portalPassability[pg]) { return true; } } } return BDPMap.Instance.IsFree(ms); }
/// <summary> /// Gets the square valid neighbours. /// </summary> /// <returns>The neighbours.</returns> public List<MapSquare> GetNeighbours(MapSquare ms) { var result = new List<MapSquare>(); // Add up. if (IsFree(ms.Up)) result.Add(ms.Up); // Add down. if (IsFree(ms.Down)) result.Add(ms.Down); // Add left. if (IsFree(ms.Left)) result.Add(ms.Left); // Add right. if (IsFree(ms.Right)) result.Add(ms.Right); return result; }
public static int FindPath(MapSquare start, MapSquare target) { if (start == null) { throw new ArgumentNullException("start"); } if (target == null) { throw new ArgumentNullException("target"); } int counter = 0; var path = AStar.FindPath( start, target, (m1) => { return SimpleHOmniscient.GetNeighbours(m1,target); }, (m1, m2) => { var p1 = BDPMap.Instance.GetPortalGroupBySquare(m1); var p2 = BDPMap.Instance.GetPortalGroupBySquare(m2); if (p1 != null && p2 != null) { return SimpleHOmniscient.PGBeliefDistance(p1[0], p2[0]); } return MapSquare.Distance(m1, m2); }, (ms) => MapSquare.Distance(ms, target)); counter += AStar.ExpandedNodes; if (path == null) return counter; // LOW LEVEL EXPANSION. var pathList = PathfindTester.Path2MapSquareList(path); for (var i=1; i<pathList.Count(); i++) { var area = BDPMap.Instance.GetArea(pathList[i-1]); var lowlevel = AStar.FindPath( pathList[i-1], pathList[i], (ms) => GetLowLevelNeighbours(ms).Where(m => BDPMap.Instance.GetArea(m) == area || m == target).ToList(), MapSquare.Distance, (ms) => MapSquare.Distance(ms, target)); counter += AStar.ExpandedNodes; if (lowlevel == null) return counter; } return counter; }
public void Collision_FloatingPointError_StillWorks() { var hitbox = new CollisionBox(-7.5f, -9f, 15, 21); hitbox.Name = "Test"; hitbox.Environment = true; hitbox.PushAway = true; _position.SetPosition(5f, 115.999992f); _collision.AddBox(hitbox); _collision.Message(new HitBoxMessage(EntityMock.Object, new List<CollisionBox>(), new HashSet<string>() { "Test" }, false)); var layer = new Mock<IScreenLayer>(); layer.SetupGet(l => l.Stage).Returns(Container); var tileset = new Common.Tileset() { TileSize = 16 }; var backTile = new Common.Tile(1, new Common.TileSprite(tileset)); var blankSquare = new MapSquare(layer.Object, backTile, 0, 0, 16); Screen.Setup(s => s.SquareAt(It.IsAny<float>(), It.IsAny<float>())).Returns(blankSquare); var blockTile = new Common.Tile(2, new Common.TileSprite(tileset)); blockTile.Properties = new Common.TileProperties() { Blocking = true }; var blockSquare = new MapSquare(layer.Object, blockTile, 0, 8, 16); Screen.Setup(s => s.SquareAt(It.IsInRange<float>(0, 16, Range.Inclusive), It.IsInRange<float>(128, 144, Range.Inclusive))).Returns(blockSquare); Assert.IsFalse(_collision.BlockBottom); Container.Tick(); Assert.IsTrue(_collision.BlockBottom); Container.Tick(); Assert.IsTrue(_collision.BlockBottom); Container.Tick(); Assert.IsTrue(_collision.BlockBottom); }
public void AddLocation(MapSquare square) { m_squares.Add(square); m_listeners.ForEach(l => l.MovedTo(square)); }
/// <summary> /// Distance between specified ms1 and ms2. /// </summary> /// <param name="ms1"> /// The first MapSquare. /// </param> /// <param name="ms2"> /// The second MapSquare. /// </param> /// <returns> /// The <see cref="double"/>. /// </returns> public static double Distance(MapSquare ms1, MapSquare ms2) { if (ms1 == null) { throw new ArgumentNullException("ms1"); } if (ms2 == null) { throw new ArgumentNullException("ms2"); } return Mathf.Sqrt(Mathf.Pow(ms1.x - ms2.x, 2) + Mathf.Pow(ms1.x - ms2.x, 2)); }
public void AddInitializedSquareToList(MapSquare newlyInitializedSquare) { newActiveSquares.Add(newlyInitializedSquare); }
/// <summary> /// Compute the distance between the specified pg1 and a point. /// </summary> /// <param name="pg1"> /// Pg1. /// </param> /// <param name="ms"> /// The ms. /// </param> /// <returns> /// The <see cref="double"/>. /// </returns> public static double Distance(PortalGroup pg1, MapSquare ms) { double minDist = 0; pg1.NearestPortal(ms, out minDist); return minDist; }
/// <summary> /// The belief revision loop. /// </summary> /// <param name="currentPos"> /// The current pos. /// </param> /// <param name="targetPos"> /// The target pos. /// </param> /// <param name="path"> /// The path. /// </param> /// <returns> /// The <see cref="Path"/>. /// </returns> private Path<MapSquare> BeliefRevisionLoop(MapSquare currentPos, MapSquare targetPos) { #if PATHTESTER_DEBUG_LOG Debug.Log(string.Format("[REVISION] Portal belief revision for {0} to {1}", currentPos, targetPos)); #endif Path<MapSquare> path = null; long currentWindows = Windows; while (currentWindows >= MinWindows && path == null) { Debug.Log (string.Format ("[REVISION] Open portals older than {0}", currentWindows)); agent.ReviewBeliefOlderThan (currentWindows); path = ThePathfinder.PathFind (currentPos, targetPos); currentWindows--; } return path; }
/// <summary> /// The is same area path. /// </summary> /// <param name="currentPos"> /// The current pos. /// </param> /// <param name="targetPos"> /// The target pos. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool IsSameAreaPath(MapSquare currentPos, MapSquare targetPos) { return BDPMap.Instance.GetArea(currentPos) == BDPMap.Instance.GetArea(targetPos) && AvoidSameAreaPath; }
public MapData(TextAsset mapFile, GameObject enemyContainer, GameObject wallContainer, Enemy enemyPrefab, Player player, Material tileSheet) { //enemyPrefab = Resources.Load("Enemy") as GameObject; TmxMap map; /*if (Debug.isDebugBuild) * { * map = new TmxMap(mapFileName); * }*/ //TextAsset mapFile = Resources.Load(mapFileName) as TextAsset; //Debug.Log(mapFile.name); //XDocument doc = XDocument.Parse(mapFile.text); //Debug.Log(doc.Element("map").Attribute("tilewidth")); //_doc.(mapFile.text); //Debug.Log(mapFile.text); map = new TmxMap(mapFile.text); horizontal_tiles = map.Width; vertical_tiles = map.Height; tile_width = map.TileWidth; tile_height = map.TileHeight; tileSetName = map.Tilesets[0].Name; mapTitle = map.Properties["Title"]; tileCount = map.Layers[0].Tiles.Count; tiles = new MapSquare[tileCount];; for (int i = 0; i < tileCount; i++) { tiles[i] = new MapSquare(map.Layers[0].Tiles[i]); } int enemyCount = map.ObjectGroups[0].Objects.Count; //enemies = new Enemy[enemyCount]; for (int i = 0; i < enemyCount; i++) { TmxObjectGroup.TmxObject enemy = map.ObjectGroups[0].Objects[i]; //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); int enemyX = (int)enemy.X / tile_width; int enemyY = (int)enemy.Y / tile_height; Vector3 worldPos = new Vector3(-enemyX, 0.01f, enemyY); //GetRelativePosition(enemyX, enemyY); Enemy enemyObject = (Enemy)GameObject.Instantiate(enemyPrefab, worldPos, enemyPrefab.transform.rotation); enemyObject.transform.parent = enemyContainer.transform; enemyObject.transform.localPosition = worldPos; //enemies[i] = enemyObject; } int startEndCount = map.ObjectGroups[1].Objects.Count; for (int i = 0; i < startEndCount; i++) { TmxObjectGroup.TmxObject startEnd = map.ObjectGroups[1].Objects[i]; //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); int startEndX = (int)startEnd.X / tile_width; int startEndY = (int)startEnd.Y / tile_height; Vector3 worldPos = new Vector3(-startEndX + 0.5f, 1f, startEndY - 1.5f); //Debug.Log(startEnd.Name); if (startEnd.Name == "Start") { player.Spawn(worldPos, tile_width, tile_height); GameObject startObject = (GameObject)GameObject.Instantiate(Resources.Load("SpawnPoint"), worldPos, Quaternion.identity); } else if (startEnd.Name == "End") { GameObject endObjectPrefab = (GameObject)GameObject.Instantiate(Resources.Load("LevelEndTrigger")); endObjectPrefab.transform.position = worldPos; //GameObject endObject = (GameObject)GameObject.Instantiate(endObjectPrefab, worldPos, endObjectPrefab.transform.rotation); //LevelEndTrigger end = endObject.GetComponent<LevelEndTrigger>(); } //Vector3 worldPos = new Vector3(-(enemyX / tile_width), 0.01f, enemyY / tile_height); //GetRelativePosition(enemyX, enemyY); //Enemy enemyObject = (Enemy)GameObject.Instantiate(enemyPrefab, worldPos, enemyPrefab.transform.rotation); //enemyObject.transform.parent = enemyContainer.transform; //enemyObject.transform.localPosition = worldPos; //enemies[i] = enemyObject; } int wallCount = map.ObjectGroups[2].Objects.Count; CreateWall(tileSheet); for (int i = 0; i < wallCount; i++) { TmxObjectGroup.TmxObject wall = map.ObjectGroups[2].Objects[i]; //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); int startEndX = (int)wall.X / tile_width; int startEndY = (int)wall.Y / tile_height; Vector3 worldPos = new Vector3(-startEndX, 0.5f, startEndY); GameObject wallObject = (GameObject)GameObject.Instantiate(wallPref, worldPos, Quaternion.identity); wallObject.transform.parent = wallContainer.transform; wallObject.transform.localPosition = worldPos; //LevelEndTrigger end = endObject.GetComponent<LevelEndTrigger>(); //Vector3 worldPos = new Vector3(-(enemyX / tile_width), 0.01f, enemyY / tile_height); //GetRelativePosition(enemyX, enemyY); //Enemy enemyObject = (Enemy)GameObject.Instantiate(enemyPrefab, worldPos, enemyPrefab.transform.rotation); //enemyObject.transform.parent = enemyContainer.transform; //enemyObject.transform.localPosition = worldPos; //enemies[i] = enemyObject; } if (Application.isPlaying) { GameObject.Destroy(wallPref); } int objectCount = map.ObjectGroups[3].Objects.Count; for (int i = 0; i < objectCount; i++) { TmxObjectGroup.TmxObject genericObject = map.ObjectGroups[3].Objects[i]; //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); int startEndX = (int)genericObject.X / tile_width; int startEndY = (int)genericObject.Y / tile_height; Vector3 worldPos = new Vector3(-startEndX + 0.5f, 0.5f, startEndY - 1.5f); if (genericObject.Type == "mirror") { GameObject mirrorPrefab = (GameObject)GameObject.Instantiate(Resources.Load("mirror")); GameObject mirror = (GameObject)GameObject.Instantiate(mirrorPrefab, worldPos, mirrorPrefab.transform.rotation); //wallObject.transform.parent = wallContainer.transform; //wallObject.transform.localPosition = worldPos; } //LevelEndTrigger end = endObject.GetComponent<LevelEndTrigger>(); //Vector3 worldPos = new Vector3(-(enemyX / tile_width), 0.01f, enemyY / tile_height); //GetRelativePosition(enemyX, enemyY); //Enemy enemyObject = (Enemy)GameObject.Instantiate(enemyPrefab, worldPos, enemyPrefab.transform.rotation); //enemyObject.transform.parent = enemyContainer.transform; //enemyObject.transform.localPosition = worldPos; //enemies[i] = enemyObject; } }
private void UnlockThisMetro(MapSquare currentSquare) { currentSquare.OpenMetroStation(); }
public void ShowExtractionSquare(MapSquare newTargetSquare) { targetSquare = newTargetSquare; state = "moveTowardExtraction"; }
/// <summary> /// The update belief. /// </summary> /// <param name="ms"> /// The ms. /// </param> /// <param name="state"> /// The state. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool UpdateBelief(MapSquare ms, bool state) { return false; }
public void StartBattle(MapSquare currentSquare) { FindObjectOfType <MapSFX>().PlayMapSoundSFX(MapSFX.MapSoundEffect.TransitionToBattle); FindObjectOfType <SceneLoader>().LoadBattleFromMap(currentSquare); }
public int ManhattanDistance(MapSquare to) { return(Math.Abs(to.X - X) + (to.Y - Y)); }
public void SetCurrentSquare(MapSquare newCurrentSquare) { currentSquare = newCurrentSquare; }
/// <summary> /// Manhattans distance between specified ms1 and ms2. /// </summary> /// <returns> /// The manhattan distance between ms1 and ms2. /// </returns> /// <param name="ms1"> /// The first MapSquare. /// </param> /// <param name="ms2"> /// The second MapSquare. /// </param> public static double ManhattanDistance(MapSquare ms1, MapSquare ms2) { if (ms1 == null) { throw new ArgumentNullException("ms1"); } if (ms2 == null) { throw new ArgumentNullException("ms2"); } return Mathf.Abs(ms1.x - ms2.x) + Mathf.Abs(ms1.x - ms2.x); }
/* int wallCount = map.ObjectGroups[2].Objects.Count; * CreateWall(tileSheet); * * for (int i = 0; i < wallCount; i++) * { * TmxObjectGroup.TmxObject wall = map.ObjectGroups[2].Objects[i]; * //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); * int startEndX = (int)wall.X / tile_width; * int startEndY = (int)wall.Y / tile_height; * Vector3 worldPos = new Vector3(-startEndX, 0.5f, startEndY); * * GameObject wallObject = (GameObject)GameObject.Instantiate(wallPref, worldPos, Quaternion.identity); * //wallObject.transform.parent = wallContainer.transform; * wallObject.transform.localPosition = worldPos; * } * if (Application.isPlaying) * { * GameObject.Destroy(wallPref); * }*/ /* * int objectCount = map.ObjectGroups[3].Objects.Count; * * for (int i = 0; i < objectCount; i++) * { * TmxObjectGroup.TmxObject genericObject = map.ObjectGroups[3].Objects[i]; * //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); * int startEndX = (int)genericObject.X / tile_width; * int startEndY = (int)genericObject.Y / tile_height; * Vector3 worldPos = new Vector3(-startEndX + 0.5f, 0.5f, startEndY -1.5f); * * }*/ public void GenerateTiles(TmxLayerList layerList) { int layerCount = layerList.Count; for (int i = 0; i < layerCount; i += 1) { TmxLayer layer = layerList[i]; int tileCount = layer.Tiles.Count; PropertyDict properties = layer.Properties; string tileType = "Ground"; if (properties.ContainsKey("Type")) { tileType = properties["Type"]; } if (tileType == "Ground") { tiles = new MapSquare[layer.Tiles.Count]; } Transform layerContainer = new GameObject(layer.Name).transform; layerContainer.rotation = Quaternion.identity; layerContainer.transform.SetParent(tileContainer); //Debug.Log(tileCount); for (int j = 0; j < tileCount; j += 1) { TmxLayerTile tmxTile = layer.Tiles[j]; int tileSetId = FindTileSetId(tmxTile.Gid); if (tileSetId == -1) { continue; } if (tileType == "Wall") { if (tmxTile.Gid == 0) { continue; } tileMap.AddNode(tmxTile.X, tmxTile.Y, false); int xpos = (int)tmxTile.X; int ypos = (int)tmxTile.Y; Vector3 worldPos = new Vector3(-xpos + 0.5f, 0.5f, ypos - 0.5f); //Debug.Log("[" + tmxTile.X + ", " + tmxTile.Y + "]"); GameObject spawnedTile; if (wallPref == null) { CreateWall(); } spawnedTile = (GameObject)Instantiate(wallPref, worldPos, Quaternion.identity); spawnedTile.name = "Wall_" + tmxTile.Gid; spawnedTile.transform.position = worldPos; spawnedTile.transform.parent = layerContainer; } if (tileType == "Ground") { if (tmxTile.Gid != 0) { tileMap.AddNode(tmxTile.X, tmxTile.Y); } tiles[j] = new MapSquare(tmxTile); } } } }
public MapSquare CreateSquare(int x, int y, IReadOnlyList <MapSquare> squares) { var chanceOfTurn = 0.3; var chanceOfDoubleTurn = 0.05; var chanceOfBlock = 0.1; var turn = Random.Next(100) < chanceOfTurn * 100; var doubleTurn = Random.Next(100) < chanceOfDoubleTurn * 100; var block = Random.Next(100) < chanceOfBlock * 100; MapSquareEdge north = null; MapSquareEdge east = null; MapSquareEdge south = null; MapSquareEdge west = null; // First get what we are connected to and fill in the edge types accordingly. MapSquare e = squares.SingleOrDefault(square => square.X == x + 1 && square.Y == y); if (e != null) { east = new MapSquareEdge(e.WestEdge.EdgeType); } MapSquare w = squares.SingleOrDefault(square => square.X == x - 1 && square.Y == y); if (w != null) { west = new MapSquareEdge(w.EastEdge.EdgeType); } MapSquare n = squares.SingleOrDefault(square => square.X == x && square.Y == y + 1); if (n != null) { north = new MapSquareEdge(n.SouthEdge.EdgeType); } MapSquare s = squares.SingleOrDefault(square => square.X == x && square.Y == y - 1); if (s != null) { south = new MapSquareEdge(s.NorthEdge.EdgeType); } // Now we want to setup any straight lines if (east == null && west != null && west.EdgeType == MapSquareEdgeType.Path) { east = new MapSquareEdge(block ? MapSquareEdgeType.Blocked : MapSquareEdgeType.Path); } else if (west == null && east != null && east.EdgeType == MapSquareEdgeType.Path) { west = new MapSquareEdge(block ? MapSquareEdgeType.Blocked : MapSquareEdgeType.Path); } else if (north == null && south != null && south.EdgeType == MapSquareEdgeType.Path) { north = new MapSquareEdge(block ? MapSquareEdgeType.Blocked : MapSquareEdgeType.Path); } else if (south == null && north != null && north.EdgeType == MapSquareEdgeType.Path) { south = new MapSquareEdge(block ? MapSquareEdgeType.Blocked : MapSquareEdgeType.Path); } // Now fill in the rest if (north == null) { if (turn) { north = new MapSquareEdge(MapSquareEdgeType.Path); turn = doubleTurn; doubleTurn = false; } else { north = new MapSquareEdge(MapSquareEdgeType.Blocked); } } if (south == null) { if (turn) { south = new MapSquareEdge(MapSquareEdgeType.Path); turn = doubleTurn; doubleTurn = false; } else { south = new MapSquareEdge(MapSquareEdgeType.Blocked); } } if (east == null) { if (turn) { east = new MapSquareEdge(MapSquareEdgeType.Path); turn = doubleTurn; doubleTurn = false; } else { east = new MapSquareEdge(MapSquareEdgeType.Blocked); } } if (west == null) { if (turn) { west = new MapSquareEdge(MapSquareEdgeType.Path); turn = doubleTurn; doubleTurn = false; } else { west = new MapSquareEdge(MapSquareEdgeType.Blocked); } } return(new MapSquare(x, y, north, east, south, west)); }
/// <summary> /// The contains old. /// </summary> /// <param name="ms"> /// The ms. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool ContainsOld(MapSquare ms) { return this.Portals.Any(p => p.LinkedSquares.First.Equals(ms) || p.LinkedSquares.Second.Equals(ms)); }
private int SortByDistance(MapSquare square1, MapSquare square2) { return(square1.GetDistanceMeasurement().CompareTo(square2.GetDistanceMeasurement())); }
/// <summary> /// Return the nearest portal to a given 2D point in the current instance. /// </summary> /// <returns> /// The portal. /// </returns> /// <param name="ms"> /// The ms. /// </param> public Portal NearestPortal(MapSquare ms) { double dummy = 0; return NearestPortal(ms, out dummy); }
/// <summary> /// The initialize srd. /// </summary> /// <param name="currentPos"> /// The current pos. /// </param> /// <param name="targetPos"> /// The target pos. /// </param> private void InitializeSRD(MapSquare currentPos, MapSquare targetPos) { var p = ThePathfinder.TheMightyOmniscientAndPerfectPathfinder(currentPos, targetPos); var popo = SimpleHOmniscient.FindPath(currentPos,targetPos); srd = new SingleRunData { StartingPoint = currentPos.ToString(), TargetPoint = targetPos.ToString(), RealPathExists = p!=null , OmniscientEffort = popo}; }
/// <summary> /// Return the nearest portal to a given 2D point in the current instance. /// </summary> /// <returns> /// The portal. /// </returns> /// <param name="ms"> /// The ms. /// </param> /// <param name="minDist"> /// Minimum dist. /// </param> public Portal NearestPassablePortal(MapSquare ms, PortalGroup pg) { Portal min = null; var minDist = Mathf.Infinity; foreach (var p in pg.Portals.Where(IsPassable)) { var newDist = Portal.Distance(p, ms); if (!(newDist < minDist)) { continue; } minDist = newDist; min = p; } return min; }
private bool UpdateAllPortalInArea(MapSquare ms, int depth = 1) { var mapSquareArea = BDPMap.Instance.GetArea(ms); var pgs = BDPMap.Instance.GetPortalGroupByAreas(mapSquareArea); var changed = false; foreach (var pg in pgs.Select(pg => pg.NearestPortal(ms))) { var updateSquareIn = pg[mapSquareArea]; var updateSquareOut = pg[mapSquareArea, reverse: true]; if (updateSquareIn == null) { Debug.Log("ERROR"); break; } bool tmpChange; this.srd.UpdateTicks += MethodProfiler.ProfileMethod( agent.UpdateBelief, updateSquareIn, BDPMap.Instance.IsFree(updateSquareIn), out tmpChange); changed = tmpChange; if (!BDPMap.Instance.IsFree(updateSquareIn)) { continue; } this.srd.UpdateTicks += MethodProfiler.ProfileMethod( agent.UpdateBelief, updateSquareOut, BDPMap.Instance.IsFree(updateSquareOut), out tmpChange); changed = changed || tmpChange; if (depth < UpdateDepth) { tmpChange = UpdateAllPortalInArea(updateSquareOut, depth + 1); changed = changed || tmpChange; } } return changed; }
/// <summary> /// The update belief. /// </summary> /// <param name="ms"> /// The ms. /// </param> /// <param name="state"> /// The state. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool UpdateBelief(MapSquare ms, bool state) { var pgs = BDPMap.Instance.GetPortalGroupBySquare(ms); //TODO: This is an hack. if (pgs == null) return false; // end if (pgs.Count == 0) { Debug.LogWarning("Updating a non portalsquare!"); return false; } var changed = false; foreach (var pg in pgs.Where(pg => this.UpdateBelief(pg, BDPMap.Instance.GetArea(ms), state))) { changed = true; } return changed; }
/* int wallCount = map.ObjectGroups[2].Objects.Count; CreateWall(tileSheet); for (int i = 0; i < wallCount; i++) { TmxObjectGroup.TmxObject wall = map.ObjectGroups[2].Objects[i]; //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); int startEndX = (int)wall.X / tile_width; int startEndY = (int)wall.Y / tile_height; Vector3 worldPos = new Vector3(-startEndX, 0.5f, startEndY); GameObject wallObject = (GameObject)GameObject.Instantiate(wallPref, worldPos, Quaternion.identity); //wallObject.transform.parent = wallContainer.transform; wallObject.transform.localPosition = worldPos; } if (Application.isPlaying) { GameObject.Destroy(wallPref); }*/ /* int objectCount = map.ObjectGroups[3].Objects.Count; for (int i = 0; i < objectCount; i++) { TmxObjectGroup.TmxObject genericObject = map.ObjectGroups[3].Objects[i]; //Debug.Log("object at [" + enemy.X + ", " + enemy.Y + "]"); int startEndX = (int)genericObject.X / tile_width; int startEndY = (int)genericObject.Y / tile_height; Vector3 worldPos = new Vector3(-startEndX + 0.5f, 0.5f, startEndY -1.5f); }*/ public void GenerateTiles(TmxLayerList layerList) { int layerCount = layerList.Count; for (int i = 0; i < layerCount; i += 1) { TmxLayer layer = layerList[i]; int tileCount = layer.Tiles.Count; PropertyDict properties = layer.Properties; string tileType = "Ground"; if (properties.ContainsKey("Type")) { tileType = properties["Type"]; } if (tileType == "Ground") { tiles = new MapSquare[layer.Tiles.Count]; } Transform layerContainer = new GameObject(layer.Name).transform; layerContainer.rotation = Quaternion.identity; layerContainer.transform.SetParent(tileContainer); //Debug.Log(tileCount); for (int j = 0; j < tileCount; j += 1) { TmxLayerTile tmxTile = layer.Tiles[j]; int tileSetId = FindTileSetId(tmxTile.Gid); if (tileSetId == -1) { continue; } if (tileType == "Wall") { if (tmxTile.Gid == 0) { continue; } tileMap.AddNode(tmxTile.X, tmxTile.Y, false); int xpos = (int)tmxTile.X; int ypos = (int)tmxTile.Y; Vector3 worldPos = new Vector3(-xpos + 0.5f, 0.5f, ypos-0.5f); //Debug.Log("[" + tmxTile.X + ", " + tmxTile.Y + "]"); GameObject spawnedTile; if (wallPref == null) { CreateWall(); } spawnedTile = (GameObject)Instantiate(wallPref, worldPos, Quaternion.identity); spawnedTile.name = "Wall_" + tmxTile.Gid; spawnedTile.transform.position = worldPos; spawnedTile.transform.parent = layerContainer; } if (tileType == "Ground") { if (tmxTile.Gid != 0) { tileMap.AddNode(tmxTile.X, tmxTile.Y); } tiles[j] = new MapSquare(tmxTile); } } } }
// ability usages public void UseAbility(MapSquare square, string description, string color, int cost) { switch (description) { // SECURITY CAMERA OPTIONS case "Scout Points of Interest": ScoutPointOfInterest(2, square); break; case "Reduce Security Level": ReduceSecurityLevel(5); break; case "Reveal Points of Interest": ScoutPointOfInterest(3, square); break; case "Scout Enemies": ScoutEnemies(2, square); break; case "Reveal Enemies": ScoutEnemies(3, square); break; case "Despa0wn a Weak Enemy": DespawnAnEnemy(2, 1); break; case "Despawn a Medium Enemy": DespawnAnEnemy(3, 2); break; // COMBAT SERVER OPTIONS case "Accelerate Reaction Time": BuffPlayerDodge(10, square); break; case "Disengage Enemy Shielding": IncreaseEnemyVulnerability(1, square); break; case "Enhance Targetting": BuffPlayerCritChance(15, square); break; case "Overclock Systems": BuffPlayerHandSize(1, square); break; case "Harden Armor": BuffPlayerDefense(1, square); break; case "Install Mod Intereference": DebuffEnemyHandSize(1, square); break; case "Sabotage Enemy Tech": AddToEnemyFizzleChance(15, square); break; // DATABASE OPTIONS case "Erase Database": ReduceSecurityLevel(5); break; case "Upload and Sell Financial Data": int jobDifficulty = FindObjectOfType <MapData>().GetJob().GetJobDifficulty(); GainMoney(Random.Range(50, 101) * (jobDifficulty + 1)); break; case "Install Backdoor": RaiseMoneyMultiplier(10); RaiseGoalMultiplier(10); break; case "Brute Force Passwords": jobDifficulty = FindObjectOfType <MapData>().GetJob().GetJobDifficulty(); GainMoney(Random.Range(1, 51) * (jobDifficulty + 1)); RaiseSecurityLevel(7); break; case "Upload and Sell Personal Data": jobDifficulty = FindObjectOfType <MapData>().GetJob().GetJobDifficulty(); GainMoney(Random.Range(75, 151) * (jobDifficulty + 1)); break; case "Download Buyer List": RaiseGoalMultiplier(20); break; case "Download VIP Buyer List": RaiseGoalMultiplier(40); break; // DEFENSE SYSTEM OPTIONS case "Disable Trap": DisableATrap(square); break; //case "Reduce Security Level": // THIS IS ALREADY PART OF THE ABOVE, AND IT WORKS FOR BOTH // break; case "Detonate EMP": AddToEnemyFizzleChance(15, square); break; case "Turn Turrets on Enemies": DamageEnemies(15, square); break; case "Control Attack Drones": DotEnemies(5, square); break; case "Infect Weapon Systems": DebuffEnemyDamage(1, square); break; case "Despawn a Strong Enemy": DespawnAnEnemy(4, 3); break; // TRANSPORTATION case "Unlock This Metro Station": UnlockThisMetro(square); break; case "Unlock Remote Metro Station": UnlockRemoteMetro(square); break; case "Unlock All Metro Stations": UnlockAllMetroStations(); break; case "Map Ventilation Systems": MapVentilationSystem(square); break; case "Co-Opt Stealth Tech": EngageStealthTech(); break; case "Hinder Enemy Movement": HinderEnemyMovement(5); break; case "Stop Enemy Movement": StopEnemyMovement(1); break; // MEDICAL SERVER case "Gain Health and Energy Regeneration": GainHealthRegeneration(5); GainEnergyRegeneration(5); break; case "Sabotage Medicines": DotEnemies(5, square); break; case "Upload and Sell Medical Research": jobDifficulty = FindObjectOfType <MapData>().GetJob().GetJobDifficulty(); GainMoney(Random.Range(50, 101) * (jobDifficulty + 1)); break; case "Healing Boost": GainHealth(25); break; case "Energy Infusion": GainEnergy(100); break; case "Heal and Gain Energy": GainHealth(25); GainEnergy(50); break; case "Injest Stimulants": BuffPlayerDodge(10, square); BuffPlayerHandSize(1, square); BuffPlayerCritChance(15, square); break; } switch (color) { case red: redPoints -= cost; break; case blue: bluePoints -= cost; break; case green: greenPoints -= cost; break; } }
/// <summary> /// Check if the portal group contains the given MapSquare. /// </summary> /// <param name="ms"> /// Ms. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool Contains(MapSquare ms) { // A square is contained in a portal group if it fall in the 2-square band // that join the first portal of the group with the last portal of the group. float edgeMin; float edgeMax; float mid; if (!Horizontal) { edgeMin = this.First.y; edgeMax = this.Last.y; mid = this.First.x; // Debug.Log(edgeMin + " " + edgeMax + " " + ms); if (ms.y >= edgeMin && ms.y <= edgeMax) { if (ms.x <= mid + 0.51 && ms.x >= mid - 0.51) { return true; } } } else { edgeMin = this.First.x; edgeMax = this.Last.x; mid = this.First.y; if (ms.x >= edgeMin && ms.x <= edgeMax) { if (ms.y <= mid + 0.5 && ms.y >= mid - 0.5) { return true; } } } return false; }
public BitmapTile(MapTile tile, BitmapRect bounds) { _tile = tile; _square = tile.GetActualSquare(); _bounds = bounds; }
/// <summary> /// Return the nearest portal to a given 2D point in the current instance. /// </summary> /// <returns> /// The portal. /// </returns> /// <param name="ms"> /// The ms. /// </param> /// <param name="minDist"> /// Minimum dist. /// </param> public Portal NearestPortal(MapSquare ms, out double minDist) { Portal min = null; minDist = Mathf.Infinity; foreach (var p in portals) { var newDist = Portal.Distance(p, ms); if (!(newDist < minDist)) { continue; } minDist = newDist; min = p; } return min; }
/// <summary> /// The this. /// </summary> /// <param name="ms"> /// The ms. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int this[MapSquare ms] { get { if (LinkedSquares.First == ms) { return this.LinkedAreas.First; } if (LinkedSquares.Second == ms) { return this.LinkedAreas.Second; } return -1; } }
/// <summary> /// The is free. /// </summary> /// <param name="ms"> /// The ms. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool IsFree(MapSquare ms) { if (ms == null) { throw new ArgumentNullException("ms"); } if (!BDPMap.Instance.IsPortalSquare(ms)) { return BDPMap.Instance.IsFree(ms); } var pgs = BDPMap.Instance.GetPortalGroupBySquare(ms); var area = BDPMap.Instance.GetArea(ms); return pgs.All(pg => this.portalGroupState[PortalGroupKey(pg, area)]); }
/// <summary> /// Distance between a portal p1 and a 2D point. /// </summary> /// <param name="p1"> /// A portal. /// </param> /// <param name="ms"> /// A map square. /// </param> /// <returns> /// The <see cref="float"/> distance between portal and square. /// </returns> public static float Distance(Portal p1, MapSquare ms) { if (p1 == null) { throw new ArgumentNullException("p1"); } if (ms == null) { throw new ArgumentNullException("ms"); } return Vector2.Distance(p1.MidPoint, new Vector2(ms.x, ms.y)); }
/// <summary> /// The neighbours. /// </summary> /// <param name="node"> /// The node. /// </param> /// <returns> /// The <see cref="IEnumerable"/>. /// </returns> public IEnumerable<MapSquare> Neighbours(MapSquare node) { return GetNeighbours(node); }
/// <summary> /// Initializes a new instance of the <see cref="Portal"/> class. /// </summary> /// <param name="square1"> /// The first square. /// </param> /// <param name="square2"> /// The second square. /// </param> /// <param name="area1"> /// The area of the first square. /// </param> /// <param name="area2"> /// The area of the second square. /// </param> public Portal(MapSquare square1, MapSquare square2, int area1, int area2) { // TODO: There can be inconsistencies. It is possible to develop a more robust constructor. this.LinkedSquares = new Tuple<MapSquare, MapSquare>(square1, square2); this.LinkedAreas = new Tuple<int, int>(area1, area2); }
/// <summary> /// The get neighbours. /// </summary> /// <param name="ms"> /// The ms. /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> public List<MapSquare> GetNeighbours(MapSquare ms) { var originalMap = BDPMap.Instance; var result = new List<MapSquare>(); var area = originalMap.GetArea(ms); var pgs = originalMap.GetPortalGroupByAreas(area); if (pgs == null) { Debug.LogError("BOOM"); } var candidates = (from pg in pgs where this.IsPassable(pg) select MidPortal(pg)).Select(p => p[area, reverse: true]); result.AddRange(candidates); if (area == originalMap.GetArea(CurrentTarget) && !result.Contains(CurrentTarget)) { result.Add(CurrentTarget); } return result; }
/// <summary> /// The is free. /// </summary> /// <param name="ms"> /// The ms. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool IsFree(MapSquare ms) { if (ms == null) { throw new ArgumentNullException("ms"); } if (ms.x >= this.Width || ms.x < 0 || ms.y >= this.Height || ms.y < 0) { return false; } return this.ElementIs("free", this.rawMap[ms.x, ms.y]); }