private bool DoTileFillConditions(Vector3 worldPosition, Vector2Int tileCoords, TileFlag condition, string entityID, bool logBuildError = false) { if (condition.HasFlag(TileFlag.Free)) { if (!IsTileFree(tileCoords)) { if (logBuildError) { UIMessagesLogger.Instance.LogError("Can't on non-empty tile."); } return(false); } } if (condition.HasFlag(TileFlag.Visible)) { Assert.IsNotNull(FOWManager.Instance, "FOWManager missing"); Vector3 tileWorldPosition = CoordsToWorld(tileCoords); Debug.DrawRay(tileWorldPosition, Vector3.up * 3f, Color.magenta, 1f); if (!IsTileVisible(tileWorldPosition)) { if (logBuildError) { UIMessagesLogger.Instance.LogError("Can't on non-visible tile."); } return(false); } } if (condition.HasFlag(TileFlag.TerrainFlat)) { if (!IsTileFlat(tileCoords)) { if (logBuildError) { UIMessagesLogger.Instance.LogError("You must build on flat terrain."); } return(false); } } if (!string.IsNullOrEmpty(entityID)) { if (GetTile(tileCoords) != null && !DoTileContainsEntityOfID(tileCoords, entityID)) { if (logBuildError) { UIMessagesLogger.Instance.LogError(string.Format("Can't build on {0} building.", GetTileID(tileCoords))); } return(false); } } return(true); }
private static TileFlag[] GetFilters(TileFlag filter) { if (filter == TileFlag.None) { return(_EmptyFilters); } return(_AllFilters.Where(f => f != TileFlag.None && filter.HasFlag(f)).ToArray()); }
// -------------------------------------------------------------- #region PUBLIC FUNCTIONS // -------------------------------------------------------------- /// <summary> /// Create a string with all the active flags /// </summary> public string GetAllFlags() { // initialize the flags list string flags = ""; // create the string with all the flags names foreach (Enum value in Enum.GetValues(m_flags2.GetType())) { if (m_flags2.HasFlag(value) && (TileFlag)value != TileFlag.None) { flags += (flags == string.Empty ? value.ToString() : ", " + value.ToString()); } } return(flags); }
private static TileFlag[] GetFilters(TileFlag filter) { if (filter == TileFlag.None) { return(_EmptyFilters); } List <TileFlag> list = new List <TileFlag>(); for (var index = 0; index < _AllFilters.Length; index++) { var f = _AllFilters[index]; if (f != TileFlag.None && filter.HasFlag(f)) { list.Add(f); } } return(list.ToArray()); }
private IEnumerable <Point3D> Compute(Rectangle3D area) { // Check all corners to skip large bodies of water. for (var index = 0; index < Filters.Length; index++) { var filter = Filters[index]; if (Equals(filter, TileFlag.Wet)) { LandTile land1 = Facet.Tiles.GetLandTile(area.Start.X, area.Start.Y); // TL LandTile land2 = Facet.Tiles.GetLandTile(area.End.X, area.Start.Y); // TR LandTile land3 = Facet.Tiles.GetLandTile(area.Start.X, area.End.Y); // BL LandTile land4 = Facet.Tiles.GetLandTile(area.End.X, area.End.Y); // BR bool ignore1 = land1.Ignored || TileData.LandTable[land1.ID].Flags.HasFlag(TileFlag.Wet); bool ignore2 = land2.Ignored || TileData.LandTable[land2.ID].Flags.HasFlag(TileFlag.Wet); bool ignore3 = land3.Ignored || TileData.LandTable[land3.ID].Flags.HasFlag(TileFlag.Wet); bool ignore4 = land4.Ignored || TileData.LandTable[land4.ID].Flags.HasFlag(TileFlag.Wet); if (ignore1 && ignore2 && ignore3 && ignore4) { yield break; } break; } } Point3D p = Point3D.Zero; for (p.X = area.Start.X; p.X <= area.End.X; p.X++) { for (p.Y = area.Start.Y; p.Y <= area.End.Y; p.Y++) { LandTile land = Facet.Tiles.GetLandTile(p.X, p.Y); p.Z = land.Z; if (Contains(p)) { continue; } if (!CanSpawn(p.X, p.Y, p.Z)) { continue; } if (Filters.Length > 0) { if (land.Ignored) { continue; } TileFlag flags = TileData.LandTable[land.ID].Flags; bool any1 = false; for (var index = 0; index < Filters.Length; index++) { var f = Filters[index]; if (flags.HasFlag(f)) { any1 = true; break; } } if (any1) { continue; } bool valid = true; var tiles = Facet.Tiles.GetStaticTiles(p.X, p.Y); for (var index = 0; index < tiles.Length; index++) { StaticTile tile = tiles[index]; flags = TileData.ItemTable[tile.ID].Flags; bool any2 = false; for (var i = 0; i < Filters.Length; i++) { var f = Filters[i]; if (flags.HasFlag(f)) { any2 = true; break; } } if (any2) { valid = false; break; } } if (!valid) { continue; } } if (Validator != null && !Validator(Facet, p.X, p.Y, p.Z)) { continue; } yield return(p); } } }
private void Compute(Rectangle3D area) { // Check all corners to skip large bodies of water. if (Filters.Contains(TileFlag.Wet)) { LandTile land1 = Facet.Tiles.GetLandTile(area.Start.X, area.Start.Y); // TL LandTile land2 = Facet.Tiles.GetLandTile(area.End.X, area.Start.Y); // TR LandTile land3 = Facet.Tiles.GetLandTile(area.Start.X, area.End.Y); // BL LandTile land4 = Facet.Tiles.GetLandTile(area.End.X, area.End.Y); // BR if ((land1.Ignored || TileData.LandTable[land1.ID].Flags.HasFlag(TileFlag.Wet)) && (land2.Ignored || TileData.LandTable[land2.ID].Flags.HasFlag(TileFlag.Wet)) && (land3.Ignored || TileData.LandTable[land3.ID].Flags.HasFlag(TileFlag.Wet)) && (land4.Ignored || TileData.LandTable[land4.ID].Flags.HasFlag(TileFlag.Wet))) { return; } } int x, y, z, h; for (x = area.Start.X; x < area.End.X; x++) { for (y = area.Start.Y; y < area.End.Y; y++) { h = GetHashCode(x, y); if (_Points.ContainsKey(h)) { continue; } z = Facet.Tiles.GetLandTile(x, y).Z;//.GetAverageZ(x, y); if (!CanSpawn(x, y, z)) { continue; } if (Filters.Length > 0) { LandTile land = Facet.Tiles.GetLandTile(x, y); if (land.Ignored) { continue; } TileFlag flags = TileData.LandTable[land.ID].Flags; if (Filters.Any(f => flags.HasFlag(f))) { continue; } bool valid = true; foreach (StaticTile tile in Facet.Tiles.GetStaticTiles(x, y)) { flags = TileData.ItemTable[tile.ID].Flags; if (Filters.Any(f => flags.HasFlag(f))) { valid = false; break; } } if (!valid) { continue; } } if (Validator != null && !Validator(Facet, x, y, z)) { continue; } lock (_Points) { _Points[h] = new Point3D(x, y, z); } } } }