示例#1
0
        internal RoadStationInfo EnsureStation(TownNode townNode)
        {
            if (this.stations.ContainsKey(townNode.TownId))
            {
                return(this.stations[townNode.TownId]);
            }

            var place = RoadStationBuilder.FindPlaceForStation(townNode.Location.Tile);

            AIRoad.BuildRoadStation(place.tile, place.entryPoint, AIRoad.ROADVEHTYPE_BUS, AIStation.STATION_NEW);
            AIRoad.BuildRoad(place.tile, place.entryPoint);
            this.stations.Add(townNode.TownId, place);
            return(place);
        }
示例#2
0
        internal RoadStationInfo EnsureDepot(TownNode townNode)
        {
            if (this.depots.ContainsKey(townNode.TownId))
            {
                return(this.depots[townNode.TownId]);
            }

            var place = RoadStationBuilder.FindPlaceForStation(townNode.Location.Tile);

            if (place != null)
            {
                AIRoad.BuildRoadDepot(place.tile, place.entryPoint);
                AIRoad.BuildRoad(place.tile, place.entryPoint);
                this.depots.Add(townNode.TownId, place);
                return(place);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        internal static bool BuildRoad(TileIndex previous, TileIndex from, TileIndex to, TileIndex next, HashSet <TileIndex> forbidden, Action <TileIndex, string> sign = null)
        {
            var path = RoadBuilder.FindPath(from, to, previous, forbidden);

            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)
                    {
                        AILog.Error($"Length is: {path[i].Length}. ([" + AIMap.GetTileX(p) + ", " + AIMap.GetTileY(p) + "] via [" + AIMap.GetTileX(c) + ", " + AIMap.GetTileY(c) + "] to [" + AIMap.GetTileX(n) + ", " + AIMap.GetTileY(n) + "])");
                        continue;
                        //throw new Exception("Should not be Road");
                    }

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

                    //AILog.Info("Build a Road  from [" + AIMap.GetTileX(p) + ", " + AIMap.GetTileY(p) + "] via [" + AIMap.GetTileX(c) + ", " + AIMap.GetTileY(c) + "] to [" + AIMap.GetTileX(n) + ", " + AIMap.GetTileY(n) + "].");
                    good = AIRoad.BuildRoad(p, c);
                    good = AIRoad.BuildRoad(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_ROAD, bridgeTypes.Begin(), c, n);
                    if ((!good) && (sign != null))
                    {
                        sign(p, "s");
                        sign(c, "e");
                    }

                    break;

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

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

            return(true);
        }