예제 #1
0
        /// <summary>
        /// Gets a direction of tile2 related to tile1.
        /// </summary>
        /// <param name="tile1"></param>
        /// <param name="tile2"></param>
        /// <returns></returns>
        public static Direction GetDirection(TileIndex tile1, TileIndex tile2)
        {
            if ((tile1 == tile2) || !(AIMap.IsValidTile(tile1) && AIMap.IsValidTile(tile2)))
            {
                return(Direction.None);
            }

            int x1 = AIMap.GetTileX(tile1);
            int x2 = AIMap.GetTileX(tile2);
            int y1 = AIMap.GetTileY(tile1);
            int y2 = AIMap.GetTileY(tile2);

            if (y1 == y2)
            {
                // /
                return(x1 < x2 ? Direction.SouthWest : Direction.NorthEast);
            }
            else if (x1 == x2)
            {
                // \
                return(y1 < y2 ? Direction.SouthEast : Direction.NorthWest);
            }

            return(Direction.None);
        }
예제 #2
0
        private static bool IsClear(TileIndex topCorner, int width, int height)
        {
            if (!AITile.IsBuildableRectangle(topCorner, width, height))
            {
                return(false);
            }

            var xx = AIMap.GetTileX(topCorner);
            var yy = AIMap.GetTileY(topCorner);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var testTile = topCorner + AIMap.GetTileIndex(x, y);
                    if (!AIMap.IsValidTile(testTile))
                    {
                        return(false);
                    }

                    var slope = AITile.GetSlope(testTile);
                    if (slope != AITile.SLOPE_FLAT)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #3
0
        private void BuildSign(TileIndex tile, string text)
        {
            AILog.Info("Sign (" + AIMap.GetTileX(tile) + ", " + AIMap.GetTileY(tile) + "): " + text);
            var signId = AISign.BuildSign(tile, "" + text);

            this.signs.AddItem(signId, 0);
        }
예제 #4
0
        internal static bool BuildRail(TileIndex previous, TileIndex from, TileIndex to, TileIndex next, HashSet <TileIndex> forbidden, int railCount = 1, Action <TileIndex, string> sign = null)
        {
            var path = RailBuilder.FindPath(from, to, previous, forbidden, sign);

            if (path == null)
            {
                return(false);
            }

            for (var i = 0; i < path.Count - 1; i++)
            {
                var p  = i == 0 ? next : path[i - 1].Tile;
                var c  = path[i].Tile;
                var n  = i == path.Count - 1 ? previous : path[i + 1].Tile;
                var nt = i == 0 ? BuildType.Basic : path[i - 1].Type;
                //sign(c, "[" + AIMap.GetTileX(c) + ", " + AIMap.GetTileY(c) + "] " + path[i].type);
                bool good = false;
                switch (path[i].Type)
                {
                case BuildType.Basic:
                    if (path[i].Length > 1)
                    {
                        throw new Exception("Should not be rail");
                    }

                    if (nt != BuildType.Basic)
                    {
                        continue;
                    }

                    //AILog.Info("Build a rail  from [" + AIMap.GetTileX(p) + ", " + AIMap.GetTileY(p) + "] via [" + AIMap.GetTileX(c) + ", " + AIMap.GetTileY(c) + "] to [" + AIMap.GetTileX(n) + ", " + AIMap.GetTileY(n) + "].");
                    good = AIRail.BuildRail(p, c, n);
                    break;

                case BuildType.Bridge:
                    var bridgeTypes = new AIBridgeList_Length(path[i].Length);
                    //AILog.Info("Build a bridge " + bridgeTypes.Begin() + " from [" + AIMap.GetTileX(c) + ", " + AIMap.GetTileY(c) + "] to [" + AIMap.GetTileX(n) + ", " + AIMap.GetTileY(n) + "].");
                    good = AIBridge.BuildBridge(AIVehicle.VT_RAIL, bridgeTypes.Begin(), c, n);
                    if (!good)
                    {
                        sign(p, "s");
                        sign(c, "e");
                    }

                    break;

                case BuildType.Tunnel:
                    throw new Exception("Tunnels not supported");
                }

                if (!good)
                {
                    AILog.Error("Failed to build on [" + AIMap.GetTileX(c) + ", " + AIMap.GetTileY(c) + "]. Reason: " + AIError.GetLastErrorString());
                }
            }

            return(true);
        }
예제 #5
0
        private static RailStationInfo FindPlaceForStation(TileIndex tile, int platformLength, int platformCount)
        {
            var xx = AIMap.GetTileX(tile);
            var yy = AIMap.GetTileY(tile);

            for (var step = 1; step < 15; step++)
            {
                for (var i = 0; i < step * 2; i++)
                {
                    var x     = xx - step;
                    var y     = yy + Helper.Alternate(i);
                    var tile2 = AIMap.GetTileIndex(x, y);
                    var test  = RailStationBuilder.TestPlaceForStation(tile2, platformLength, platformCount);
                    if (test != null)
                    {
                        return(test);
                    }

                    x     = xx - Helper.Alternate(i);
                    y     = yy + step;
                    tile2 = AIMap.GetTileIndex(x, y);
                    test  = RailStationBuilder.TestPlaceForStation(tile2, platformLength, platformCount);
                    if (test != null)
                    {
                        return(test);
                    }

                    x     = xx + step;
                    y     = yy + Helper.Alternate(i);
                    tile2 = AIMap.GetTileIndex(x, y);
                    test  = RailStationBuilder.TestPlaceForStation(tile2, platformLength, platformCount);
                    if (test != null)
                    {
                        return(test);
                    }

                    x     = xx + Helper.Alternate(i);
                    y     = yy - step;
                    tile2 = AIMap.GetTileIndex(x, y);
                    test  = RailStationBuilder.TestPlaceForStation(tile2, platformLength, platformCount);
                    if (test != null)
                    {
                        return(test);
                    }
                }
            }

            return(null);
        }
예제 #6
0
 public static string FormatTile(TileIndex tile)
 {
     return("[" + AIMap.GetTileX(tile) + ", " + AIMap.GetTileY(tile) + "]");
 }
예제 #7
0
        private static void BuildIntersection(TileIndex tile1, TileIndex tile2, TileIndex tile3, TileIndex tile4 = null)
        {
            var tile1x = AIMap.GetTileX(tile1);
            var tile1y = AIMap.GetTileY(tile1);
            var tile2x = AIMap.GetTileX(tile2);
            var tile2y = AIMap.GetTileY(tile2);
            var tile3x = AIMap.GetTileX(tile3);
            var tile3y = AIMap.GetTileY(tile3);

            var x = (int)((tile1x + tile2x + tile3x) / 3.0 + 0.5);
            var y = (int)((tile1y + tile2y + tile3y) / 3.0 + 0.5);

            var center = AIMap.GetTileIndex(x, y);

            var nwTile = AIMap.GetTileIndex(x, y - 1);
            var neTile = AIMap.GetTileIndex(x - 1, y);
            var swTile = AIMap.GetTileIndex(x + 1, y);
            var seTile = AIMap.GetTileIndex(x, y + 1);

            if (tile4 != null)
            {
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NE_SW); // /
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_SE); // \
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_NE); // - (upper)
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_SW_SE); // - (lower)
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_SW); // | left
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NE_SE); // | right
                return;
            }

            if ((tile1 != nwTile) && (tile2 != nwTile) && (tile3 != nwTile))
            {
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NE_SW); // /
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_SW_SE); // - (lower)
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NE_SE); // | right
                return;
            }

            if ((tile1 != neTile) && (tile2 != neTile) && (tile3 != neTile))
            {
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_SE); // \
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_SW_SE); // - (lower)
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_SW); // | left
                return;
            }

            if ((tile1 != swTile) && (tile2 != swTile) && (tile3 != swTile))
            {
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_SE); // \
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_NE); // - (upper)
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NE_SE); // | right
                return;
            }

            if ((tile1 != seTile) && (tile2 != seTile) && (tile3 != seTile))
            {
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NE_SW); // /
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_NE); // - (upper)
                AIRail.BuildRailTrack(center, AIRail.RAILTRACK_NW_SW); // | left
                return;
            }
        }
예제 #8
0
파일: Point.cs 프로젝트: ttv86/CsNut
 public Point(TileIndex tile)
 {
     this.Tile = tile;
     this.X    = AIMap.GetTileX(tile);
     this.Y    = AIMap.GetTileY(tile);
 }