public int GetVisibilityInFOW() { int extRadius = (GetObjectType() == MapObjectType.Obstacle) ? 2 : 0; int mw = MapLogic.Instance.Width; int mh = MapLogic.Instance.Height; int TopFlag = 0; for (int ly = Y - extRadius; ly <= Y + Height + extRadius; ly++) { for (int lx = X - extRadius; lx <= X + Width + extRadius; lx++) { if (lx < 0 || lx >= mw || ly < 0 || ly >= mh) { continue; } MapNodeFlags flags = MapLogic.Instance.Nodes[lx, ly].Flags; if ((flags & MapNodeFlags.Visible) != 0) { return(2); } else if ((flags & MapNodeFlags.Discovered) != 0) { TopFlag = 1; } } } return(TopFlag); }
// returns true if cell is walkable for this unit public bool CheckWalkableForUnit(int x, int y, bool staticOnly) { for (int ly = y; ly < y + Unit.Height; ly++) { for (int lx = x; lx < x + Unit.Width; lx++) { // skip cells currently taken if (MapLogic.Instance.Nodes[lx, ly].Objects.Contains(Unit)) { continue; // if we are already on this cell, skip it as passible } uint tile = MapLogic.Instance.Nodes[lx, ly].Tile; MapNodeFlags flags = MapLogic.Instance.Nodes[lx, ly].Flags; if (Unit.IsWalking && (flags & MapNodeFlags.Unblocked) == 0 && (tile >= 0x1C0 && tile <= 0x2FF)) { return(false); } MapNodeFlags bAir = staticOnly ? MapNodeFlags.BlockedAir : MapNodeFlags.BlockedAir | MapNodeFlags.DynamicAir; MapNodeFlags bGround = staticOnly ? MapNodeFlags.BlockedGround : MapNodeFlags.BlockedGround | MapNodeFlags.DynamicGround; if (Unit.IsFlying && (flags & bAir) != 0) { return(false); } else if (!Unit.IsFlying && (flags & bGround) != 0) { return(false); } } } return(true); }
private bool CheckWalkable(int x, int y) { MapNode node = MapLogic.Instance.Nodes[x, y]; uint tile = node.Tile; MapNodeFlags flags = node.Flags; if ((!flags.HasFlag(MapNodeFlags.Unblocked) && (tile >= 0x1C0 && tile <= 0x2FF)) || // blocked by ground terrain flags.HasFlag(MapNodeFlags.BlockedGround)) // or blocked explicitly { return(false); // not walkable } return(true); // walkable }
public Texture2D GetFOWTexture() { if (GameManager.Instance.IsHeadless) { return(null); } if (MapFOWTex == null) { MapFOWTex = new Texture2D(256, 256, TextureFormat.Alpha8, false); MapFOWTex.filterMode = FilterMode.Bilinear; MapFOWNeedsUpdate = true; } if (MapFOWNeedsUpdate) { Color[] colors = new Color[256 * 256]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { MapNodeFlags flags = Nodes[x, y].Flags; float alpha = 1; if ((flags & MapNodeFlags.Discovered) != 0) { alpha -= 0.5f; } if ((flags & MapNodeFlags.Visible) != 0) { alpha -= 0.5f; } colors[y * 256 + x] = new Color(1, 1, 1, alpha); } } MapFOWTex.SetPixels(colors); MapFOWTex.Apply(false); MapFOWNeedsUpdate = false; MapFOWUpdated = true; } return(MapFOWTex); }
// returns true if cell is walkable for this unit public bool CheckWalkableForUnit(int x, int y, bool staticOnly) { if (x < 8 || x > MapLogic.Instance.Width - 8 || y < 8 || y > MapLogic.Instance.Height - 8) { return(false); } for (int ly = y; ly < y + Unit.Height; ly++) { for (int lx = x; lx < x + Unit.Width; lx++) { MapNode node = MapLogic.Instance.Nodes[lx, ly]; // skip cells currently taken if (node.Objects.Contains(Unit)) { continue; // if we are already on this cell, skip it as passible } uint tile = node.Tile; MapNodeFlags flags = node.Flags; if (Unit.IsWalking && !flags.HasFlag(MapNodeFlags.Unblocked) && flags.HasFlag(MapNodeFlags.BlockedTerrain)) { return(false); } MapNodeFlags bAir = staticOnly ? MapNodeFlags.BlockedAir : MapNodeFlags.BlockedAir | MapNodeFlags.DynamicAir; MapNodeFlags bGround = staticOnly ? MapNodeFlags.BlockedGround : MapNodeFlags.BlockedGround | MapNodeFlags.DynamicGround; if (Unit.IsFlying && (flags & bAir) != 0) { return(false); } else if (!Unit.IsFlying && (flags & bGround) != 0) { return(false); } } } return(true); }