Ejemplo n.º 1
0
        public static RandomRoadPrefix GetRoadPrefix(RandomRoadPrefix checkingPrefix, bool alwaysPick = false, int forcePick = -1)
        {
            RandomRoadPrefix returnPrefix = null;

            if (Instance().m_roadPrefixes != null && Instance().m_roadPrefixes.Length > 0)
            {
                List<RandomRoadPrefix> validPrefixes = new List<RandomRoadPrefix>();

                foreach (RandomRoadPrefix prefix in Instance().m_roadPrefixes)
                {
                    if (ValidRoadPrefix(prefix, checkingPrefix))
                    {
                        validPrefixes.Add(prefix);
                    }
                }

                if (validPrefixes.Count > 0)
                {
                    bool assignAPrefix = true;

                    if (!Instance().m_alwaysAssignPrefixes)
                    {
                        assignAPrefix = UnityEngine.Random.Range(0f, 1f) < 0.5f;
                    }

                    if (assignAPrefix || alwaysPick)
                    {
                        int prefixToPick = (int)Math.Round(UnityEngine.Random.Range(0f, validPrefixes.Count - 1));
                        prefixToPick = forcePick != -1 ? forcePick : prefixToPick;

                        returnPrefix = validPrefixes[prefixToPick];
                    }
                }
            }

            return returnPrefix;
        }
Ejemplo n.º 2
0
        private static bool ValidRoadPrefix(RandomRoadPrefix prefixToCheck, RandomRoadPrefix checkingPrefix)
        {
            bool valid = true;

            if (prefixToCheck.MinimumLanes > 0 && checkingPrefix.MinimumLanes <= prefixToCheck.MinimumLanes)
            {
                valid = false;
            }

            if (prefixToCheck.MaximumLanes > 0 && checkingPrefix.MaximumLanes > prefixToCheck.MaximumLanes)
            {
                valid = false;
            }

            if (prefixToCheck.NameHasToContain != null && prefixToCheck.NameHasToContain != "" && !checkingPrefix.NameHasToContain.Contains(prefixToCheck.NameHasToContain.ToLower()))
            {
                valid = false;
            }

            return valid;
        }
Ejemplo n.º 3
0
        public static string GenerateRandomRoadName(ushort netSegmentId)
        {
            string returnRoadName = null;

            if (netSegmentId != 0)
            {
                NetManager netManager = Singleton<NetManager>.instance;
                NetSegment netSegment = netManager.m_segments.m_buffer[(int)netSegmentId];
                NetSegment.Flags segmentFlags = netSegment.m_flags;

                if (segmentFlags.IsFlagSet(NetSegment.Flags.Created))
                {
                    int forwardLanes = 0, backwardLanes = 0, totalLanes = 0;
                    string roadName = netSegment.Info.name.ToLower();
                    RandomRoadPrefix selectedPrefix = null;
                    RandomRoadName selectedRoadName = null;
                    RandomRoadPostfix selectedPostfix = null;

                    netSegment.CountLanes(netSegmentId, NetInfo.LaneType.Vehicle | NetInfo.LaneType.PublicTransport | NetInfo.LaneType.TransportVehicle, VehicleInfo.VehicleType.All, ref forwardLanes, ref backwardLanes);
                    totalLanes = forwardLanes + backwardLanes;

                    Debug.Log(roadName);
                    Debug.Log(forwardLanes.ToString());
                    Debug.Log(backwardLanes.ToString());

                    RandomRoadPrefix checkingPrefix = new RandomRoadPrefix()
                    {
                        NameHasToContain = roadName,
                        MinimumLanes = totalLanes,
                        MaximumLanes = totalLanes
                    };

                    RandomRoadName checkingName = new RandomRoadName()
                    {
                        NameHasToContain = roadName,
                        MinimumLanes = totalLanes,
                        MaximumLanes = totalLanes
                    };

                    RandomRoadPostfix checkingPostfix = new RandomRoadPostfix()
                    {
                        NameHasToContain = roadName,
                        MinimumLanes = totalLanes,
                        MaximumLanes = totalLanes
                    };

                    selectedRoadName = RandomNameUtility.GetRoadName(checkingName);

                    if (selectedRoadName != null)
                    {
                        bool lowercaseInitial = false;
                        returnRoadName = "";

                        if (!selectedRoadName.NoPrefix)
                        {
                            selectedPrefix = RandomNameUtility.GetRoadPrefix(checkingPrefix, selectedRoadName.ForcePrefix);
                        }

                        if (!selectedRoadName.NoPostfix)
                        {
                            selectedPostfix = RandomNameUtility.GetRoadPostfix(checkingPostfix, selectedRoadName.ForcePostfix);
                        }

                        if(selectedPrefix != null)
                        {
                            returnRoadName += selectedPrefix.Name;
                            returnRoadName += selectedPrefix.SpaceBetweenName ? " " : "";
                            lowercaseInitial = selectedPrefix.LowercaseInitialOnName;
                        }

                        returnRoadName += lowercaseInitial ? selectedRoadName.Name.ToLower() : selectedRoadName.Name; //TODO: There might be an instance where we actually only want the initial to be lowercase. Needs improvement

                        if (selectedPostfix != null)
                        {
                            returnRoadName += selectedPostfix.SpaceBetweenName ? " " : "";
                            returnRoadName += selectedPostfix.Name;
                        }

                        returnRoadName = TranslateRoadName(netSegmentId, returnRoadName);
                    }
                }
            }

            return returnRoadName;
        }