示例#1
0
        /// <summary>
        /// Добавляет новую дорогу в город, а также автоматически проверяет её пересечение
        /// с другими дорогами и границами города. Если пересечение найдется, то на это место будет
        /// добавлена новая постройка. Но если в городе уже существует постройка на найденных координатах пересечения,
        /// то новая добавлена не будет.
        /// Помимо этого, добавляет в список «соседей» уже существующих построек новую.
        /// </summary>
        /// <param name="newRoad">Новая дорогая для добавления.</param>
        public void AddRoad(Road newRoad)
        {
            foreach (Road existedRoad in Roads)
            {
                if (existedRoad.TryGetIntersectPoint(newRoad, out var intersectPoint))
                {
                    Institution newInstitution;
                    if (Institutions.Contains(intersectPoint))
                    {
                        newInstitution = Institutions[intersectPoint];
                    }
                    else
                    {
                        newInstitution = _insitutionBuilder.Build(existedRoad, newRoad,
                                                                  intersectPoint);
                        Institutions.Add(newInstitution);
                    }

                    UpdateNeighbours(existedRoad, newInstitution, intersectPoint);
                    UpdateNeighbours(newRoad, newInstitution, intersectPoint);
                }
            }

            Roads.Add(newRoad);
        }
示例#2
0
 /// <summary> Adds road element to terrain. </summary>
 /// <param name="roadElement">Road element</param>
 public void AddRoad(RoadElement roadElement)
 {
     lock (Roads)
     {
         Roads.Add(roadElement);
     }
 }
示例#3
0
        public void Read(Stream input, Endian endian = Endian.Little)
        {
            RoadGraphRoadToJunctionEdgeMappingCount = input.ReadValueU16(endian);
            RoadGraphEdgeCount = input.ReadValueU16(endian);

            for (int i = 0; i < RoadGraphEdgeCount; i++)
            {
                RoadGraphEdges.Add(new Tuple <ushort, ushort>(input.ReadValueU16(endian), input.ReadValueU16(endian)));
            }

            ushort roadCount = input.ReadValueU16(endian);

            for (int i = 0; i < roadCount; i++)
            {
                var road = new RoadDefinitionDe();
                road.Read(input, endian);
                Roads.Add(road);
            }

            for (int i = 0; i < RoadGraphEdgeCount; i++)
            {
                var costMapping = new CostMapEntryDe();
                costMapping.Read(input, endian);
                CostMap.Add(costMapping);
            }

            byte magic0 = input.ReadValueU8();
            byte magic1 = input.ReadValueU8();
            byte magic2 = input.ReadValueU8();
            byte magic3 = input.ReadValueU8();

            if (magic0 != 0x11 && magic1 != 0x11 && magic2 != 0x11 && magic3 != 0)
            {
                throw new IOException($"Unexpected magic values ({magic0}, {magic1}, {magic2}, {magic3})");
            }

            ushort splineCount = input.ReadValueU16(endian);

            for (int i = 0; i < splineCount; i++)
            {
                var spline = new RoadSplineDe();
                spline.Read(input, endian);
                Splines.Add(spline);
            }

            for (int i = 0; i < roadCount * 2; i++)
            {
                RoadToCrossroadMapping.Add(input.ReadValueU16(endian));
            }

            ushort crossroadCount = input.ReadValueU16(endian);

            for (int i = 0; i < crossroadCount; i++)
            {
                var crossroad = new CrossroadDe();
                crossroad.Read(input, endian);
                Crossroads.Add(crossroad);
            }
        }
示例#4
0
文件: Map.cs 项目: ryancheung/WinWar
        public void PlaceRoad(int x, int y)
        {
            Construct road = new Construct(ConstructType.Road);

            road.X      = (byte)x;
            road.Y      = (byte)y;
            road.Config = ConstructConfig.EndPieceBottom;

            Roads.Add(road);

            // TODO: Only check adjacent roads
            DetermineConstructConfigForAllConstructs();
        }
示例#5
0
文件: Road.cs 项目: Fraham/TrafficApp
 private static void ProcessReader(XmlReader reader)
 {
     if (reader.Read())
     {
         switch (reader.Name)
         {
         case "Name":
             if (reader.Read())
             {
                 Roads.Add(DecodeName(reader.Value.Trim()));
             }
             break;
         }
     }
 }
示例#6
0
        void objope()
        {
            if (MarksAvaiInitCount > MarksAvaiInitMax)
            {
                if (ClearPoint.X != -1)   //オブジェクト削除
                {
                    int id = GetNearistRoad(ClearPoint, false)[0];
                    for (int i = 0; i < Roads.Count; i++)
                    {
                        if (Roads[i].GetObjectID() == id)
                        {
                            Roads.Remove(Roads[i]);
                            break;
                        }
                    }
                }

                foreach (int i in RoadMarkersNumber)   // 道を追加
                {
                    if (RoadMarkersAvailable[i])
                    {
                        List <int> l = GetNearistRoad(RoadMarkers[i], true);
                        if (l.Count != 0)   //Roadが一つ以上ある場合。
                        //-1、つまり、近くにオブジェクトがない場合はコネクトのidはなしでOK!
                        {
                            foreach (BaseRoadClass o in Roads)
                            {
                                if (l.Contains(o.GetObjectID()))
                                {
                                    o.Add(Roads.Count);
                                }
                            }
                            Roads.Add(new BaseRoadClass(Roads.Count, RoadMarkers[i], "Road", l));
                        }
                        RoadMarkersAvailable[i] = false;
                    }
                }

                foreach (KeyValuePair <int, Point> kv in BuildPoint) //建物追加
                {
                    Builds.Add(new BaseBuildClass(Builds.Count, kv.Value, "Build"));
                    BuildPoint = new Dictionary <int, Point>();
                }

                MarksAvaiInitCount = 0;
            }
        }
示例#7
0
    public override void PerformCommand()
    {
        base.PerformCommand();
        GameObject currentRoad = GetRoadFromAngle(transform.rotation.eulerAngles.y);

        GetComponent <GoCommand>().Roads.Remove(currentRoad);
        if (Roads.Contains(currentRoad))
        {
            return;
        }
        Roads.Add(currentRoad);

        if (GetComponent <GoCommand> ())
        {
            GetComponent <GoCommand> ().ResetCommand();
        }
        this.TransformCommand();
    }
示例#8
0
        private void OnAdd()
        {
            if (Validate())
            {
                Road nr = new Road(Int32.Parse(this.Id), this.Label, this.Type);

                // If we manage to delete the added road from deleted roads, that means that now we want to display data in report for the added element
                if (RoadsObs.Instance.DeletedRoads.Contains(nr))
                {
                    Roads.Add(nr);
                    RoadsObs.Instance.DeletedRoads.Remove(nr);
                    addWindow.Close();
                    serializer.SerializeObject <ObservableCollection <Road> >(Roads, "roads.xml");
                }
                else
                {
                    Roads.Add(nr);
                    addWindow.Close();
                    serializer.SerializeObject <ObservableCollection <Road> >(Roads, "roads.xml");
                }
            }
        }
示例#9
0
文件: Road.cs 项目: Fraham/TrafficApp
        public static Road NewRoad(string roadName)
        {
            Road road;

            if (roadName.StartsWith("M"))
            {
                road = new Motorway(roadName);
            }
            else if (roadName.StartsWith("A"))
            {
                road = new ARoad(roadName);
            }
            else
            {
                road = new Road(roadName);
            }

            Roads.Add(road);
            Save();

            return(road);
        }
    private bool Build <T> (T building, Vector2 Location)
    {
        var existingZone     = Zones.FirstOrDefault(a => a.Position == Location);
        var existingBuilding = Buildings.FirstOrDefault(a => a.Position == Location);
        var existingRoad     = Roads.FirstOrDefault(a => a.Position == Location);

        if (existingZone != null || existingBuilding != null)
        {
            if (existingZone != null)
            {
                DeleteObject(existingZone);
            }
            else if (existingBuilding != null)
            {
                DeleteObject(existingBuilding);
            }
            else if (existingRoad != null)
            {
                DeleteObject(existingRoad);
            }
        }

        if (building is PoliceStation)
        {
            Node z1 = building as Node;
            AddChild(z1);
            var _z = z1 as PoliceStation;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Police;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is UtilityStation)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as UtilityStation;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Util;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is FireStation)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as FireStation;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Fire;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is Park)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as Park;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Park;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is Road)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as Road;
            _z.Position = Location;
            _z.ID       = (Roads.Count() < 1) ? 1 : Roads.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Roads.Add(_z);
        }
        return(true);
    }
示例#11
0
 public void AddRoad(HexEdge edge, Road road)
 {
     Roads.Add(edge, road);
 }
 /// <summary>
 /// Add road to the world
 /// </summary>
 public void AddRoad(Road road) => Roads.Add(road);