Exemplo n.º 1
0
        }                   //Here to make the compiler fine with the DelayChange that doesn't call the above constructor

        public override string ToString()
        {
            return(shape.name + "." + mode.ToString() + " : " + timeLeft + "/" + totalTime);
        }
Exemplo n.º 2
0
        public static void Change(ushort nodeId, ref NetNode node, ChangeMode mode, ref ChangedStatistics stats)
        {
            stats.Action = mode.ToString();

            if (node.m_flags == NetNode.Flags.None)
            {
                return;
            }
            stats.NumberOfNodesNotNone++;
            if (!Node.IsValidIntersection(nodeId, ref node))
            {
                return;
            }
            if (!Node.IsInsideBuildableArea(nodeId, ref node))
            {
                return;
            }

            var ai = node.Info.GetAI() as RoadBaseAI;

            if (ai == null)
            {
                return;
            }

            stats.NumberOfIntersections++;

            var wantLights = ai.WantTrafficLights();
            var hasLights  = CitiesHelper.HasTrafficLights(node.m_flags);
            var isCustom   = CitiesHelper.IsCustomTrafficLights(node.m_flags);

            bool shouldHasLights;

            switch (mode)
            {
            case ChangeMode.Remove:
                shouldHasLights = false;
                break;

            case ChangeMode.Add:
                shouldHasLights = true;
                break;

            case ChangeMode.Reset:
                shouldHasLights = wantLights;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
            }
            bool shouldBeCustom = mode != ChangeMode.Reset;


            if (wantLights)
            {
                stats.NumberOfWantLights++;
            }
            else
            {
                stats.NumberOfWantNoLights++;
            }
            if (hasLights)
            {
                stats.NumberOfHadLights++;
            }
            else
            {
                stats.NumberOfHadNoLights++;
            }
            if (isCustom)
            {
                stats.NumberOfWasCustom++;
            }
            else
            {
                stats.NumberOfWasNotCustom++;
            }

            if (shouldHasLights)
            {
                stats.NumberOfHasLights++;
            }
            else
            {
                stats.NumberOfHasLights++;
            }
            if (shouldBeCustom)
            {
                stats.NumberOfIsCustom++;
            }
            else
            {
                stats.NumberOfIsNotCustom++;
            }

            // test if should change
            if (hasLights == shouldHasLights && isCustom == shouldBeCustom)
            {
                return;
            }
            stats.NumberOfChanges++;

            if (hasLights != shouldHasLights)
            {
                if (shouldHasLights)
                {
                    node.m_flags |= NetNode.Flags.TrafficLights;
                    stats.NumberOfAddedLights++;
                }
                else
                {
                    node.m_flags &= ~NetNode.Flags.TrafficLights;
                    stats.NumberOfRemovedLights++;
                }
            }

            if (isCustom != shouldBeCustom)
            {
                if (shouldBeCustom)
                {
                    node.m_flags |= NetNode.Flags.CustomTrafficLights;
                    stats.NumberOfAddedCustoms++;
                }
                else
                {
                    node.m_flags &= ~NetNode.Flags.CustomTrafficLights;
                    stats.NumberOfRemovedCustoms++;
                }
            }
        }