Exemplo n.º 1
0
        public FinalConnector(NetInfo centerNodeNetInfo, EdgeIntersections2 edgeIntersections, Ellipse ellipse, bool insertControllingVertices)
        {
            intersections      = edgeIntersections?.Intersections ?? new List <RoundaboutNode>();
            actionGroupTMPE    = edgeIntersections?.ActionGroupTMPE ?? new ActionGroup("Set up TMPE");
            actionGroupRoads   = edgeIntersections?.ActionGroupRoads ?? new ActionGroup("Build roundabout");
            wrappersDictionary = edgeIntersections?.networkDictionary ?? new WrappersDictionary();

            this.ellipse = ellipse;
            pleasenoinfiniterecursion = 0;
            this.centerNodeNetInfo    = centerNodeNetInfo;
            leftHandTraffic           = Singleton <SimulationManager> .instance.m_metaData.m_invertTraffic ==
                                        SimulationMetaData.MetaBool.True;

            // We ensure that the segments are not too long. For circles only (with ellipses it would be more difficult)
            m_maxAngDistance = Math.Min(Math.PI * 25 / ellipse.RadiusMain, Math.PI / 2 + 0.1d);

            bool isCircle = ellipse.IsCircle();

            if (!isCircle && insertControllingVertices)
            {
                /* See doc in the method below */
                InsertIntermediateNodes();
            }

            /* If the list of edge nodes is empty, we add one default intersection. */
            if (isCircle && intersections.Count == 0)
            {
                Vector3 defaultIntersection = new Vector3(ellipse.RadiusMain, 0, 0) + ellipse.Center;
                //ushort newNodeId = NetAccess.CreateNode(centerNodeNetInfo, defaultIntersection);

                WrappedNode newNodeW = new WrappedNode();
                newNodeW.Position = defaultIntersection;
                newNodeW.NetInfo  = centerNodeNetInfo;
                RoundaboutNode raNode = new RoundaboutNode(newNodeW);
                raNode.Create(actionGroupRoads);
                intersections.Add(raNode);
            }

            int count = intersections.Count;

            foreach (RoundaboutNode item in intersections)
            {
                item.angle = Ellipse.VectorsAngle(item.wrappedNode.Position - ellipse.Center);
            }

            /* We sort the nodes according to their angles */
            intersections.Sort();

            /* Goes over all the nodes and conntets each of them to the angulary closest neighbour. (In a given direction) */

            for (int i = 0; i < count; i++)
            {
                RoundaboutNode prevNode = intersections[i];
                if (isCircle)
                {
                    prevNode = CheckAngularDistance(intersections[i], intersections[(i + 1) % count]);
                }
                ConnectNodes(intersections[(i + 1) % count], prevNode);
            }

            // Charge player
            var chargePlayerAction = new ChargePlayerAction(actionGroupRoads.DoCost(), centerNodeNetInfo.m_class);

            if (!chargePlayerAction.CheckMoney())
            {
                throw new PlayerException("Not enough money!");
            }

            actionGroupRoads.Actions.Add(chargePlayerAction);

            // Create
            ModThreading.PushAction(actionGroupRoads, actionGroupTMPE);
        }
 public void Build()
 {
     ModThreading.PushAction(actionGroupRoads, actionGroupTMPE);
 }