private bool IsExcluded(NeighborsPattern variant) { if (this.ExcludesAnyCheck != null) { foreach (var pattern in this.ExcludesAnyCheck) { if ((pattern & variant) == NeighborsPattern.None) { // not excluded pattern found return(false); } } // excluded return(true); } if (this.ExcludesOnlyCheck == NeighborsPattern.None || (this.ExcludesOnlyCheck & variant) == NeighborsPattern.None) { // not excluded return(false); } // excluded return(true); }
public static void SharedCalculateNeighborsPattern( Tile tile, IProtoObjectWall protoWall, out NeighborsPattern sameTypeNeighbors, out NeighborsPattern compatibleTypeNeighbors, bool isConsiderDestroyed, bool isConsiderConstructionSites) { sameTypeNeighbors = NeighborsPattern.None; compatibleTypeNeighbors = NeighborsPattern.None; var eightNeighborTiles = tile.EightNeighborTiles; var tileIndex = -1; foreach (var neighborTile in eightNeighborTiles) { tileIndex++; if (SharedIsSameWallType(protoWall, neighborTile, isConsiderDestroyed)) { sameTypeNeighbors |= NeighborsPatternDirections.NeighborDirectionSameType[tileIndex]; } else if (SharedIsCompatibleWallType(neighborTile, isConsiderDestroyed, isConsiderConstructionSites, isHorizontal: tileIndex == 3 || tileIndex == 4)) { sameTypeNeighbors |= NeighborsPatternDirections.NeighborDirectionSameType[tileIndex]; compatibleTypeNeighbors |= NeighborsPatternDirections.NeighborDirectionSameType[tileIndex]; } } }
/// <summary> /// Cleanup pattern to remove impossible combinations. /// A combinations is considered as impossible if it contains diagonal neighbor without non-diagonal neighbors. /// For example, this combination is impossible: /// + + - /// + + - /// - - + /// Because bottom right direction doesn't have neighbor directions (right and bottom). /// It will be cleaned up to: /// + + - /// + + - /// - - - /// </summary> public static NeighborsPattern CleanupImpossibleCombinations(NeighborsPattern pattern) { if ((pattern & NeighborsPattern.TopLeft) == NeighborsPattern.TopLeft && (pattern & (NeighborsPattern.Left | NeighborsPattern.Top)) == 0) { // remove top left pattern &= ~NeighborsPattern.TopLeft; } if ((pattern & NeighborsPattern.TopRight) == NeighborsPattern.TopRight && (pattern & (NeighborsPattern.Top | NeighborsPattern.Right)) == 0) { // remove top right pattern &= ~NeighborsPattern.TopRight; } if ((pattern & NeighborsPattern.BottomRight) == NeighborsPattern.BottomRight && (pattern & (NeighborsPattern.Bottom | NeighborsPattern.Right)) == 0) { // remove bottom right pattern &= ~NeighborsPattern.BottomRight; } if ((pattern & NeighborsPattern.BottomLeft) == NeighborsPattern.BottomLeft && (pattern & (NeighborsPattern.Bottom | NeighborsPattern.Left)) == 0) { // remove bottom left pattern &= ~NeighborsPattern.BottomLeft; } return(pattern); }
public FloorPatternLayer( string name, FloorSourceChunk sourceChunk, NeighborsPattern requires, NeighborsPattern excludes) : this(name, new[] { sourceChunk }, requires, excludes) { }
public static Chunks?GetChunk(NeighborsPattern neighbors) { if (PatternToChunk.TryGetValue(neighbors, out var result)) { return(result); } return(null); }
public FloorPatternLayer( string name, FloorSourceChunk sourceChunk, NeighborsPattern requires, NeighborsPattern[] excludesAny) { this.Name = name; this.SourceChunks = new[] { sourceChunk }; this.RequiresOnlyCheck = requires; this.ExcludesAnyCheck = excludesAny; }
public FloorPatternLayer( string name, FloorSourceChunk[] sourceChunks, NeighborsPattern requires, NeighborsPattern excludes) { this.Name = name; this.SourceChunks = sourceChunks; this.RequiresOnlyCheck = requires; this.ExcludesOnlyCheck = excludes; }
/// <summary> /// Returns wall chunk from texture atlas position based on wall neighbors pattern. /// </summary> public static WallChunkWithOverlays GetRegion( NeighborsPattern patterns, NeighborsPattern patternNeighbors) { var primary = GetRegion(patterns); var overlay = patternNeighbors == NeighborsPattern.None ? null : GetOverlayRegion(patternNeighbors); return(new WallChunkWithOverlays(primary, overlay)); }
private static WallPattern GetRegion(NeighborsPattern patterns) { foreach (var pattern in WallPatterns.PatternsPrimary) { if (pattern.IsPass(patterns)) { return(pattern); } } throw new Exception("Not found!"); }
private static ITempList <WallPattern> GetOverlayRegion(NeighborsPattern patterns) { var result = Api.Shared.GetTempList <WallPattern>(); foreach (var pattern in WallPatterns.PatternsOverlay) { if (pattern.IsPass(patterns)) { result.Add(pattern); } } return(result); }
public FloorChunkPreset( NeighborsPattern pattern, byte targetColumn, byte targetRow, FloorSourceChunk[] layers, int layersHashCode, IEnumerable <FloorSourceChunk> linkedLayersFromOtherChunk) { this.Pattern = pattern; this.Layers = layers; this.LayersHashCode = layersHashCode; this.LinkedLayersFromOtherChunk = linkedLayersFromOtherChunk; this.TargetColumn = targetColumn; this.TargetRow = targetRow; }
public WallPattern( string name, Vector2Ushort atlasChunk, NeighborsPattern requiresNeighbors, double drawOffsetNormal = 0, double?drawOffsetDestroyed = null, Action <IPhysicsBody> physicsNormal = null, Action <IPhysicsBody> physicsDestroyed = null) { this.Name = name; this.AtlasChunkPosition = atlasChunk; this.RequiresNeighbors = requiresNeighbors; this.DrawOffsetNormal = drawOffsetNormal; this.DrawOffsetDestroyed = drawOffsetDestroyed ?? drawOffsetNormal; this.SetupPhysicsNormal = physicsNormal; this.SetupPhysicsDestroyed = physicsDestroyed ?? physicsNormal; }
public static bool SharedIsDestroyedWallRequired(Tile tile, IProtoObjectWall protoWall) { SharedCalculateNeighborsPattern(tile, protoWall, out var sameTypeNeighbors, out var compatibleTypeNeighbors, isConsiderDestroyed: false, isConsiderConstructionSites: false); // remove corner cases (literally!) const NeighborsPattern cornerCases = ~(NeighborsPattern.TopLeft | NeighborsPattern.TopRight | NeighborsPattern.BottomLeft | NeighborsPattern.BottomRight); sameTypeNeighbors &= cornerCases; compatibleTypeNeighbors &= cornerCases; return(sameTypeNeighbors != NeighborsPattern.None || compatibleTypeNeighbors != NeighborsPattern.None); }
private static FloorChunkPreset GetRegion( NeighborsPattern pattern, IReadOnlyDictionary <NeighborsPattern, FloorChunkPreset> wallChunkTypes) { if (wallChunkTypes.TryGetValue(pattern, out var result)) { // found matching atlas position return(result); } // impossible combination - cleanup it and try again pattern = NeighborsPatternHelper.CleanupImpossibleCombinations(pattern); if (wallChunkTypes.TryGetValue(pattern, out result)) { // found matching atlas position (after cleanup) return(result); } // this should be impossible, but kept here for debugging purposes //Api.Logger.WriteError("Impossible pattern: " + patternSameType); return(null); }
public bool IsPass(NeighborsPattern variant) { if (this.IsExcluded(variant)) { return(false); } if (this.RequiresAnyCheck != null) { foreach (var pattern in this.RequiresAnyCheck) { if ((pattern & variant) == pattern) { // pass return(true); } } // not pass return(false); } return((this.RequiresOnlyCheck & variant) == this.RequiresOnlyCheck); }
/// <summary> /// Returns wall chunk from texture atlas position based on wall neighbors pattern. /// </summary> public static FloorChunkPreset GetRegion(NeighborsPattern pattern) { return(GetRegion(pattern, FloorTextureComposer.FloorChunkPresets)); }
public bool IsPass(NeighborsPattern variant) { return((this.RequiresNeighbors & variant) == this.RequiresNeighbors); }
public WallChunkDescriptionAttribute(NeighborsPattern neighborWallsPattern) { this.NeighborsPattern = neighborWallsPattern; }