コード例 #1
0
        public static void DeserializeData(byte[] data)
        {
            var nm    = Singleton <NetManager> .instance;
            var nodes = nm.m_nodes;

            int i = 0;

            foreach (var hasLights in data.Select(Convert.ToBoolean))
            {
                var node = nodes.m_buffer[i];
                if (hasLights)
                {
                    //this if is utterly unnecessary...
                    if (!CitiesHelper.HasTrafficLights(node.m_flags))
                    {
                        node.m_flags |= NetNode.Flags.TrafficLights;
                    }
                }
                else //(!hasLights)
                {
                    //"
                    if (CitiesHelper.HasTrafficLights(node.m_flags))
                    {
                        node.m_flags &= ~NetNode.Flags.TrafficLights;
                    }
                }

                nodes.m_buffer[i] = node;

                i++;
            }
        }
コード例 #2
0
 public static IEnumerable <byte> SerializeData()
 {
     return(Singleton <NetManager> .instance.m_nodes.m_buffer
            .Select(n => CitiesHelper.HasTrafficLights(n.m_flags))
            .Select(Convert.ToByte));
 }
コード例 #3
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++;
                }
            }
        }