Beispiel #1
0
        /// <summary>
        /// Checks if the wall in other tile is compatible with this type.
        /// It checks if the wall in other tile has exactly the same type as the wall in this tile.
        /// </summary>
        private static bool SharedIsSameWallType(IProtoObjectWall protoWall, Tile tile, bool isConsiderDestroyed)
        {
            foreach (var o in tile.StaticObjects)
            {
                if (o.IsDestroyed)
                {
                    continue;
                }

                if (o.ProtoWorldObject == protoWall)
                {
                    return(true);
                }

                if (isConsiderDestroyed &&
                    o.ProtoWorldObject is ObjectWallDestroyed &&
                    ReferenceEquals(protoWall, ObjectWallDestroyed.GetPublicState(o).OriginalProtoObjectWall))
                {
                    // destroyed wall of the same type
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        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];
                }
            }
        }
Beispiel #3
0
        public static void ClientSetupBlueprint(IProtoObjectWall protoWall, Tile tile, IClientBlueprint blueprint)
        {
            var textureAtlas = ClientGetTextureAtlas(protoWall);
            var result       = SharedGetAtlasTextureChunkPosition(tile,
                                                                  protoWall,
                                                                  isConsiderDestroyed: false,
                                                                  isConsiderConstructionSites: true);

            blueprint.SpriteRenderer.TextureResource = textureAtlas.Chunk((byte)result.Primary.AtlasChunkPosition.X,
                                                                          (byte)result.Primary.AtlasChunkPosition.Y);
            result.Dispose();
        }
Beispiel #4
0
 private static WallTextureChunkSelector.WallChunkWithOverlays SharedGetAtlasTextureChunkPosition(
     Tile tile,
     IProtoObjectWall protoWall,
     bool isConsiderDestroyed,
     bool isConsiderConstructionSites)
 {
     SharedCalculateNeighborsPattern(tile,
                                     protoWall,
                                     out var sameTypeNeighbors,
                                     out var compatibleTypeNeighbors,
                                     isConsiderDestroyed,
                                     isConsiderConstructionSites);
     return(WallTextureChunkSelector.GetRegion(sameTypeNeighbors, compatibleTypeNeighbors));
 }
Beispiel #5
0
        public static void ServerSpawnDestroyedWall(
            Vector2Ushort tilePosition,
            IProtoObjectWall originalProtoObjectWall)
        {
            if (Server.World
                .GetTile(tilePosition)
                .StaticObjects
                .Any(so => so.ProtoStaticWorldObject is ObjectWallDestroyed))
            {
                //Logger.Error("Already spawned a destroyed wall here: " + tilePosition);
                return;
            }

            var worldObject = Server.World.CreateStaticWorldObject <ObjectWallDestroyed>(tilePosition);

            GetPublicState(worldObject).OriginalProtoObjectWall = originalProtoObjectWall;
            Logger.Important($"Spawning a destroyed wall at: {tilePosition} ({originalProtoObjectWall})");
        }
Beispiel #6
0
        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);
        }