public CityEvent GetEventForBuilding(ref Building thisBuilding, List <CityEventXml> xmlEvents)
        {
            CityEvent _buildingEvent = null;
            List <CityEventXmlContainer> _validEvents       = new List <CityEventXmlContainer>();
            SimulationManager            _simulationManager = Singleton <SimulationManager> .instance;

            foreach (CityEventXml xmlEvent in xmlEvents)
            {
                foreach (CityEventXmlContainer containedEvent in xmlEvent._containedEvents)
                {
                    if (containedEvent._eventBuildingClassName == thisBuilding.Info.name && containedEvent._supportsRandomEvents)
                    {
                        _validEvents.Add(containedEvent);
                    }
                }
            }

            if (_validEvents.Count > 0)
            {
                CityEventXmlContainer pickedEvent = _validEvents[_simulationManager.m_randomizer.Int32((uint)_validEvents.Count)];

                if (pickedEvent != null)
                {
                    _buildingEvent = new XmlEvent(pickedEvent);
                }
            }
            else
            {
                CimTools.CimToolsHandler.CimToolBase.DetailedLogger.Log("Couldn't find any events for " + thisBuilding.Info.name);
            }

            return(_buildingEvent);
        }
Esempio n. 2
0
        private void LoadEvents()
        {
            PrintMonuments();

            string modPath = CimTools.CimToolsHandler.CimToolBase.Path.GetModPath();

            if (modPath != null && modPath != "" && Directory.Exists(modPath))
            {
                DirectoryInfo parentPath      = Directory.GetParent(modPath);
                string        searchDirectory = parentPath.FullName;

                string[] allModDirectories = Directory.GetDirectories(searchDirectory);

                foreach (string modDirectory in allModDirectories)
                {
                    if (Directory.Exists(modDirectory))
                    {
                        string rushHourDirectory = modDirectory + System.IO.Path.DirectorySeparatorChar + "RushHour Events";

                        if (Directory.Exists(rushHourDirectory))
                        {
                            string[] eventFiles = Directory.GetFiles(rushHourDirectory, "*.xml");

                            foreach (string foundEventFile in eventFiles)
                            {
                                if (File.Exists(foundEventFile))
                                {
                                    try
                                    {
                                        XmlSerializer eventDeserialiser = new XmlSerializer(typeof(CityEventXml));
                                        TextReader    eventReader       = new StreamReader(foundEventFile);

                                        CityEventXml loadedXmlEvent = eventDeserialiser.Deserialize(eventReader) as CityEventXml;

                                        if (loadedXmlEvent != null)
                                        {
                                            m_xmlEvents.Add(loadedXmlEvent);

                                            if (ExperimentsToggle.AllowForcedXMLEvents)
                                            {
                                                foreach (CityEventXmlContainer individualEvent in loadedXmlEvent._containedEvents)
                                                {
                                                    if (individualEvent._force)
                                                    {
                                                        m_forcedEvent = individualEvent;
                                                        LoggingWrapper.Log("Forcing event " + individualEvent._name);
                                                    }
                                                }
                                            }

                                            LoggingWrapper.Log("Successfully found and loaded " + foundEventFile);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        LoggingWrapper.LogError(ex.Message + "\n" + ex.StackTrace);
                                    }
                                }
                            }
                        }
                        else
                        {
                            LoggingWrapper.Log("No events directory in " + rushHourDirectory);
                        }
                    }
                    else
                    {
                        LoggingWrapper.LogWarning("Directory " + modDirectory + " doesn't exist.");
                    }
                }
            }
            else
            {
                LoggingWrapper.LogWarning("Could not find mod path at " + modPath ?? "null");
            }
        }
Esempio n. 3
0
        public void CreateEvents()
        {
            SimulationManager _simulationManager = Singleton <SimulationManager> .instance;
            BuildingManager   _buildingManager   = Singleton <BuildingManager> .instance;

            PrintMonuments();

            if (m_forcedEvent != null)
            {
                m_nextEvents.Clear();
            }

            FastList <ushort> allBuildings = CityEventBuildings.instance.GetPotentialEventBuildings();

            if (allBuildings.m_size > 0)
            {
                if (m_forcedEvent != null)
                {
                    for (int index = 0; index < allBuildings.m_size; ++index)
                    {
                        ushort   buildingId = allBuildings[index];
                        Building monument   = _buildingManager.m_buildings.m_buffer[buildingId];

                        if (monument.Info.name == m_forcedEvent._eventBuildingClassName)
                        {
                            CityEvent xmlEvent = new XmlEvent(m_forcedEvent);
                            xmlEvent.SetUp(ref buildingId);
                            xmlEvent.m_eventData.m_eventStartTime  = CITY_TIME.AddHours(4d);
                            xmlEvent.m_eventData.m_eventFinishTime = xmlEvent.m_eventData.m_eventStartTime.AddHours(xmlEvent.GetEventLength());

                            AddEvent(xmlEvent);

                            LoggingWrapper.Log("Forced event created at " + monument.Info.name + " for " + xmlEvent.m_eventData.m_eventStartTime.ToShortTimeString() + ". Current date: " + CITY_TIME.ToShortTimeString());
                        }
                        else
                        {
                            LoggingWrapper.Log(monument.Info.name + " != " + m_forcedEvent._eventBuildingClassName);
                        }
                    }
                }
                else
                {
                    for (int count = 0; count < 10; ++count)
                    {
                        ushort randomMonumentId = allBuildings.m_buffer[_simulationManager.m_randomizer.UInt32((uint)allBuildings.m_size)];

                        if (randomMonumentId < _buildingManager.m_buildings.m_size)
                        {
                            Building  monument   = _buildingManager.m_buildings.m_buffer[randomMonumentId];
                            CityEvent foundEvent = CityEventBuildings.instance.GetEventForBuilding(ref monument);

                            if (foundEvent != null && (monument.m_flags & Building.Flags.Active) != Building.Flags.None)
                            {
                                foundEvent.SetUp(ref randomMonumentId);
                                AddEvent(foundEvent);
                                break;
                            }
                            else
                            {
                                Debug.Log("No event scheduled just yet. Checking again soon.");
                            }
                        }
                    }
                }
            }

            m_forcedEvent = null;

            if (!ExperimentsToggle.ForceEventToHappen)
            {
                m_nextEventCheck = CITY_TIME.AddHours(3);
            }
        }