예제 #1
0
    void addStationInformation(int i)
    {
        StationNode sNode = pointsOnRoute[i].GetComponent <StationNode>();

        sNode.trainlines.Add(routeName);
        sNode.setImage();
    }
예제 #2
0
 // switch currently selected node to the neighbor in the given direction. if the direction isnt out
 // of grid bounds and if port is used with a bridge coming out, then we move out in the direction
 // by one or two node (depending on its a double bridge or not) and select that node
 public void SelectNeighborNode(Direction dir)
 {
     if (selectedNode.selectedHub.IsPortUsed(dir))
     {
         HorizontalBuildingType bridgeType = selectedNode.selectedHub.GetPortConnectorType(dir);
         int bridgeLen;
         if (bridgeType == HorizontalBuildingType.LargeBridge || bridgeType == HorizontalBuildingType.SmallBridge)
         {
             bridgeLen = 1;
         }
         else if (bridgeType == HorizontalBuildingType.LargeBridgeDouble || bridgeType == HorizontalBuildingType.SmallBridgeDouble)
         {
             bridgeLen = 2;
         }
         else
         {
             return; // port does not connect to bridge type, must be turret or something else
         }
         int x = currentStation.first + DirectionEastWest(dir) * bridgeLen;
         int y = currentStation.second + DirectionNorthSouth(dir) * bridgeLen;
         if (!IsIndexInGridBounds(x) || !IsIndexInGridBounds(y))
         {
             return; // no node exists in this direction because it's out of bounds
         }
         currentStation.first  = x;
         currentStation.second = y;
         prevSelectedNode      = selectedNode;
         lastDirChange         = dir;
         SetSelectedNode();
     }
 }
예제 #3
0
    //public StationBuilding()
    //{
    //    type = BuildingType.MainConnector;
    //    portsUsed = new List<Tuple<Direction, StationBuilding>>();
    //}

    //public StationBuilding(BuildingType type, Vector3 pos)
    //{
    //    this.type = type;
    //    this.pos = pos;
    //    portsUsed = new List<Tuple<Direction, StationBuilding>>();
    //}

    public StationBuilding(BuildingType type, Vector pos, StationNode parent)
    {
        this.type  = type;
        this.pos   = pos;
        portsUsed  = new List <PortBuilding>();
        parentNode = parent;
    }
예제 #4
0
    //public StationBuilding()
    //{
    //    type = BuildingType.MainConnector;
    //    portsUsed = new List<Tuple<Direction, StationBuilding>>();
    //}

    //public StationBuilding(BuildingType type, Vector3 pos)
    //{
    //    this.type = type;
    //    this.pos = pos;
    //    portsUsed = new List<Tuple<Direction, StationBuilding>>();
    //}

    public StationBuilding(BuildingType btype, Vector3 pos, StationNode parent)
    {
        this.type    = btype;
        this.pos     = pos;
        portsUsed    = new List <PortBuilding>();
        parentNode   = parent;
        buildingMesh = null;
        InitializeFunctional(btype);
    }
예제 #5
0
    // move camera up and at more of an angle to player or if it exists, the spacestation's selected node
    void SwitchCamToBuildMode()
    {
        mainCam.isBuildMode = true;
        StationNode currNode = ((SpaceStation)GameObject.FindGameObjectWithTag("SpaceStation").GetComponent <SpaceStation>()).selectedNode;

        if (currNode != null)
        {
            mainCam.SetPositionOffsetFromPoint(currNode.selectedHub.pos, new Vector3(70f, 70f, 70f));
            mainCam.SetLookAtPos(currNode.selectedHub.pos);
        }
    }
예제 #6
0
    void pickFinishPoint(int count)
    {
        StationNode sNode = allOtherNodes[count].GetComponent <StationNode>();

        if (!sNode.startingNode)
        {
            endPoint = sNode.gameObject;
        }
        else
        {
            pickFinishPoint(count - 1);
        }
    }
예제 #7
0
    public void OnBridgeBuildButton(HorizontalBuildingType bridgeType)
    {
        if (bridgeType == HorizontalBuildingType.LargeBridgeDouble || bridgeType == HorizontalBuildingType.SmallBridgeDouble)
        {
            if (GetNodeInSelectedDir() == null)
            {
                stationGrid[currentStation.first + DirectionEastWest(selectedDir), currentStation.second + DirectionNorthSouth(selectedDir)] = new StationNode();
            }
            GetNodeInSelectedDir().IsBridgeCovered = true;
            TurretSlot slot1 = new TurretSlot();
            TurretSlot slot2 = new TurretSlot();
            selectedNode.BuildBridgeOnSelectedHub(selectedDir, bridgeType, ref slot1, ref slot2);
            turretSlots.Add(slot1); turretSlots.Add(slot2);
            bool        isValidNode    = true;;
            StationNode connectingNode = GetNodeInDirection(selectedDir, 2, ref isValidNode);
            if (isValidNode && connectingNode == null) // node was in bounds and has not been constructed
            {
                connectingNode = new StationNode();
            }
        }
        if (bridgeType == HorizontalBuildingType.LargeBridge || bridgeType == HorizontalBuildingType.SmallBridge)
        {
            TurretSlot slot1 = new TurretSlot();
            TurretSlot slot2 = new TurretSlot();
            if (GetNodeInSelectedDir() == null)
            {
                stationGrid[currentStation.first + DirectionEastWest(selectedDir), currentStation.second + DirectionNorthSouth(selectedDir)] = new StationNode();
            }
            selectedNode.BuildBridgeOnSelectedHub(selectedDir, bridgeType, ref slot1, ref slot2);
            turretSlots.Add(slot1); turretSlots.Add(slot2);
        }


        // note that any hubs we add, besides the first, will ned to check adjacent grid squares to see if they are covered by a bridge
        // or if they are also a hub with the adjacent port used - in both cases it means the new hubs port will need to be set to used upon creation
    }
예제 #8
0
        public OperationResult <bool> LoadESTW(ESTW Estw)
        {
            try
            {
                var Result = new OperationResult <bool>();
                Estw.Stations.Clear();
                Estw.Blocks.Clear();
                Estw.IsLoaded = false;

                var PathResult = SettingsBLL.GetPath(Estw.Id);
                ValidateResult(PathResult);

                if (PathResult.Result.IsNullOrWhiteSpace())
                {
                    Result.Succeeded = true;
                    return(Result);
                }

                using (var xmlStream = __GetEstwXmlStream(Estw))
                {
                    if (xmlStream == null)
                    {
                        Result.Message   = "ESTW-Projektierung nicht gefunden";
                        Result.Succeeded = false;
                        return(Result);
                    }

                    var xml = new XmlDocument();
                    xml.Load(xmlStream);
                    var EstwNode = xml.DocumentElement;

                    if (EstwNode == null)
                    {
                        Result.Message   = "Ungültiges ESTW";
                        Result.Succeeded = false;
                        return(Result);
                    }

                    var Stations = EstwNode.SelectNodes("station");
                    Result.Result = true;

                    foreach (XmlNode StationNode in Stations)
                    {
                        Station Station = null;

                        try
                        {
                            Station = __GetStation(StationNode, Estw);
                            if (Station == null)
                            {
                                continue;
                            }

                            var Tracks = StationNode.SelectNodes("track");

                            foreach (XmlNode TrackNode in Tracks)
                            {
                                var Track = __GetTrack(TrackNode, Station);
                                if (Track == null)
                                {
                                    continue;
                                }

                                foreach (XmlNode ChildTrackNode in TrackNode.SelectNodes("track"))
                                {
                                    __GetTrack(ChildTrackNode, Station, Track);
                                }
                            }

                            foreach (XmlNode TrackNode in Tracks)
                            {
                                var TrackName = TrackNode.Attributes["name"];
                                if (TrackName == null)
                                {
                                    continue;
                                }

                                var Track = Station.Tracks.FirstOrDefault(t => t.Name == TrackName.InnerText);
                                if (Track == null)
                                {
                                    continue;
                                }

                                __GetAlternatives(TrackNode, Track);

                                foreach (XmlNode ChildTrackNode in TrackNode.SelectNodes("track"))
                                {
                                    var ChildTrackName = ChildTrackNode.Attributes["name"];
                                    if (ChildTrackName == null)
                                    {
                                        continue;
                                    }

                                    var ChildTrack = Station.Tracks.FirstOrDefault(t => t.Name == ChildTrackName.InnerText);
                                    if (ChildTrack == null)
                                    {
                                        continue;
                                    }

                                    __GetAlternatives(ChildTrackNode, ChildTrack);
                                }
                            }

                            __GetSchedule(Station, PathResult.Result);
                            __ResolveDuplicates(Station.Schedules);
                            __GetLocalOrders(Station, PathResult.Result);
                            Result.Succeeded = true;
                        }
                        catch (Exception ex)
                        {
                            if (Station != null)
                            {
                                Estw.Stations.Remove(Station);
                            }

                            Result.Message = ex.Message;
                            Result.Result  = false;
                        }
                    }
                }

                Estw.IsLoaded = true;
                return(Result);
            }
            catch (Exception ex)
            {
                return(new OperationResult <bool> {
                    Message = ex.Message
                });
            }
        }
예제 #9
0
        public OperationResult <bool> LoadESTW(ESTW Estw)
        {
            try
            {
                var Result = new OperationResult <bool>();

                if (Estw.IsLoaded)
                {
                    Result.Succeeded = true;
                    return(Result);
                }

                var PathResult = SettingsBLL.GetPath(Estw.Id);
                ValidateResult(PathResult);

                using (var xmlStream = __GetEstwXmlStream(Estw))
                {
                    if (xmlStream == null)
                    {
                        Result.Message   = "ESTW-Projektierung nicht gefunden";
                        Result.Succeeded = false;
                        return(Result);
                    }

                    var xml = new XmlDocument();
                    xml.Load(xmlStream);
                    var EstwNode = xml.DocumentElement;

                    if (EstwNode == null)
                    {
                        Result.Message   = "Ungültiges ESTW";
                        Result.Succeeded = false;
                        return(Result);
                    }

                    var Stations = EstwNode.SelectNodes("station");
                    Result.Result = true;

                    foreach (XmlNode StationNode in Stations)
                    {
                        var Station = __GetStation(StationNode, Estw);

                        if (Station == null)
                        {
                            continue;
                        }

                        var Tracks = StationNode.SelectNodes("track");

                        foreach (XmlNode TrackNode in Tracks)
                        {
                            var Track = __GetTrack(TrackNode, Station);
                            if (Track == null)
                            {
                                continue;
                            }

                            foreach (XmlNode ChildTrackNode in TrackNode.SelectNodes("track"))
                            {
                                __GetTrack(ChildTrackNode, Station, Track);
                            }
                        }

                        foreach (XmlNode TrackNode in Tracks)
                        {
                            var TrackName = TrackNode.Attributes["name"];
                            if (TrackName == null)
                            {
                                continue;
                            }

                            var Track = Station.Tracks.FirstOrDefault(t => t.Name == TrackName.InnerText);
                            if (Track == null)
                            {
                                continue;
                            }

                            __GetAlternatives(TrackNode, Track);

                            foreach (XmlNode ChildTrackNode in TrackNode.SelectNodes("track"))
                            {
                                var ChildTrackName = ChildTrackNode.Attributes["name"];
                                if (ChildTrackName == null)
                                {
                                    continue;
                                }

                                var ChildTrack = Station.Tracks.FirstOrDefault(t => t.Name == ChildTrackName.InnerText);
                                if (ChildTrack == null)
                                {
                                    continue;
                                }

                                __GetAlternatives(ChildTrackNode, ChildTrack);
                            }
                        }

                        if (PathResult.Result.IsNotNullOrWhiteSpace())
                        {
                            __GetSchedule(Station, PathResult.Result);
                            __ResolveDuplicates(Station.Schedules);
                            __DetectTwinSchedules(Station.Schedules);
                            __GetLocalOrders(Station, PathResult.Result);
                        }
                    }
                }

                if (PathResult.Result.IsNotNullOrWhiteSpace())
                {
                    __LoadTrainCompositions(Estw, PathResult.Result);
                    __LoadTrainRelations(Estw, PathResult.Result);
                }

                Estw.SchedulesLoaded = PathResult.Result.IsNotNullOrWhiteSpace();
                Estw.IsLoaded        = true;
                Result.Result        = true;
                Result.Succeeded     = true;
                return(Result);
            }
            catch (Exception ex)
            {
                Estw.Stations.Clear();
                Estw.Blocks.Clear();
                Estw.IsLoaded = false;

                foreach (var train in Estw.Area.Trains.Values)
                {
                    var schedulesToDelete = train.Schedules.Where(s => s.Station.ESTW.Id == Estw.Id).ToList();
                    schedulesToDelete.ForEach(train.RemoveSchedule);
                }

                return(new OperationResult <bool> {
                    Message = ex.ToString()
                });
            }
        }
예제 #10
0
    // after a port has been selected, update the bridge buttons to show what bridge types are allowed
    // note this does not change what station node is selected
    public void OnDirectionSelect(Direction dir)
    {
        // one case where a bridge type wouldnt be allowed is where you try to do a long bridge over a node
        // another case is where you do a bridge and instead of connecting to a node on the other side it
        // connects to some other building type
        // so we just need to check for these cases:
        bool        outOfBounds         = false;
        StationNode nodeToTest          = GetStationInDirection(dir, 1, ref outOfBounds); // gets the next node over in the given direction
        float       heightOfSelectedHub = GetCurrentNodesHubHeight();                     // offset height so its at about the center of the hub

        bool canStepByOne = false;                                                        // indicates whether we can build

        // test for non-long bridges
        if (!outOfBounds)
        {
            // if no building at node for this height because the node is empty or node has no building at height
            if (nodeToTest == null || nodeToTest.GetBuildingTypeAtHeight(heightOfSelectedHub) == null)
            {
                canStepByOne = true;
                // okay to build any single size (non-long) bridges
                ((Button)GameObject.FindGameObjectWithTag("btnThinBridge").GetComponent <Button>()).interactable = true;
                ((Button)GameObject.FindGameObjectWithTag("btnBigBridge").GetComponent <Button>()).interactable  = true;
                selectedDir = dir;
            }
            else if (nodeToTest.GetBuildingTypeAtHeight(heightOfSelectedHub).type == BuildingType.MainConnector)
            {
                canStepByOne = true;
                // okay to build thick bridge todog
                ((Button)GameObject.FindGameObjectWithTag("btnBigBridge").GetComponent <Button>()).interactable = true;
                selectedDir = dir;
            }
            else if (nodeToTest.GetBuildingTypeAtHeight(heightOfSelectedHub).type == BuildingType.SmallDisk)
            {
                canStepByOne = true;
                // okay to build thin bridge
                ((Button)GameObject.FindGameObjectWithTag("btnThinBridge").GetComponent <Button>()).interactable = true;
                selectedDir = dir;
            }
        }
        else
        {
            // can't build any bridge because this is off grid range
            UpdateText.GetComponent <Text>().text = "can't build any bridge because this is off grid range  ";
        }

        outOfBounds = false;
        // now test the same for long bridges
        nodeToTest = GetStationInDirection(dir, 2, ref outOfBounds);
        if (!outOfBounds && canStepByOne)
        {
            if (nodeToTest == null || nodeToTest.GetBuildingTypeAtHeight(heightOfSelectedHub) == null)
            {
                // okay to build any long bridge
                ((Button)GameObject.FindGameObjectWithTag("btnBigLongBridge").GetComponent <Button>()).interactable  = true;
                ((Button)GameObject.FindGameObjectWithTag("btnThinLongBridge").GetComponent <Button>()).interactable = true;
            }
            else if (nodeToTest.GetBuildingTypeAtHeight(heightOfSelectedHub).type == BuildingType.MainConnector)
            {
                // okay to build thick longbridge todog
                ((Button)GameObject.FindGameObjectWithTag("btnBigLongBridge").GetComponent <Button>()).interactable = true;
            }
            else if (nodeToTest.GetBuildingTypeAtHeight(heightOfSelectedHub).type == BuildingType.SmallDisk)
            {
                // okay to build thin long bridge
                ((Button)GameObject.FindGameObjectWithTag("btnThinLongBridge").GetComponent <Button>()).interactable = true;
            }
        }
        else
        {
            // can't build any bridge because this is off grid range
            UpdateText.GetComponent <Text>().text = "can't build any long bridge because this is off grid range  ";
        }
    }
예제 #11
0
 // return currently selected node
 private void SetSelectedNode()
 {
     selectedNode = stationGrid[currentStation.first, currentStation.second];
 }