private void CreateEvent() { if (_linkedEvent != null) { FastList <object> optionItems = _incentiveList.rowsData; List <IncentiveOptionItem> optionItemList = new List <IncentiveOptionItem>(); foreach (IncentiveOptionItem optionItemObject in optionItems) { if (optionItemObject != null) { optionItemList.Add(optionItemObject); } } DateTime startTime = new DateTime(CityEventManager.CITY_TIME.Year, CityEventManager.CITY_TIME.Month, CityEventManager.CITY_TIME.Day); startTime = startTime.AddDays(_startDaySlider.value); startTime = startTime.AddHours(_startTimeSlider.value); if (_linkedEvent.CreateUserEvent(Mathf.RoundToInt(_ticketSlider.value), _linkedEvent.m_eventData.m_entryCost, optionItemList, startTime)) { CityEventManager.instance.AddEvent(_linkedEvent); Hide(); } else { UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage(LocalisationStrings.EVENT_CREATIONERRORTITLE, LocalisationStrings.EVENT_CREATIONERRORDESCRIPTION, true); LoggingWrapper.LogError("Couldn't create user event!"); } } }
/// <summary> /// <para>Call [[CimToolsRushHour.CimToolsHandler.CimToolBase.XMLFileOptions.Data.GetValue]], reporting any errors to [[DebugOutputPanel]].</para> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="value"></param> /// <returns>Whether the value was retrieved</returns> private static bool safelyGetValue <T>(string name, ref T value, bool legacy) { bool success = false; if (legacy) { success = CimTools.CimToolsHandler.LegacyCimToolBase.XMLFileOptions.Data.GetValue(name, ref value, "IngameOptions", true) == CimToolsRushHour.Legacy.File.ExportOptionBase.OptionError.NoError; CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.SetOptionValue(name, value); CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.SaveOptions(); } else { success = CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.GetOptionValue(name, ref value); } if (!success) { LoggingWrapper.LogError(string.Format("An error occurred trying to fetch '{0}'.", name)); } else { LoggingWrapper.Log("Option \"" + name + "\" is " + value); } return(success); }
public void SetUp(LabelOptionItem selectedData, ushort buildingID) { _linkedEvent = selectedData.linkedEvent; if (_linkedEvent != null && buildingID != 0 && _ticketSlider != null) { List <CityEventXmlIncentive> incentives = _linkedEvent.GetIncentives(); title = _linkedEvent.GetReadableName(); _ticketSlider.maxValue = _linkedEvent.GetCapacity(); _ticketSlider.minValue = Mathf.Min(_linkedEvent.GetCapacity(), 100); _ticketSlider.value = _ticketSlider.minValue; _incentiveList.rowsData.Clear(); foreach (CityEventXmlIncentive incentive in incentives) { IncentiveOptionItem optionItem = new IncentiveOptionItem() { cost = incentive._cost, description = incentive._description, negativeEffect = incentive._negativeEffect, positiveEffect = incentive._positiveEffect, returnCost = incentive._returnCost, title = incentive._name, ticketCount = _ticketSlider.value }; optionItem.OnOptionItemChanged += OptionItem_OnOptionItemChanged; _incentiveList.rowsData.Add(optionItem); } try { _incentiveList.DisplayAt(0); _incentiveList.selectedIndex = 0; _incentiveList.Show(); } catch { LoggingWrapper.LogError("IncentiveList DisplayAt hit an error. Probably too few items in the list."); } _incentiveList.Refresh(); CalculateTotal(); TranslateInfoString(); PerformLayout(); LoggingWrapper.Log("Event capacity is " + _linkedEvent.GetCapacity().ToString() + "."); LoggingWrapper.Log("Successfully set up the UserEventCreationWindow."); } else { LoggingWrapper.LogError("Linked event was invalid, or the building was 0!"); } relativePosition = Vector3.zero; }
private static void UpdateEventSelection(UIComponent component) { UIFastList list = component as UIFastList; if (list != null) { LabelOptionItem selectedOption = list.selectedItem as LabelOptionItem; if (selectedOption != null && eventCreationWindow != null) { eventCreationWindow.Show(); eventCreationWindow.SetUp(selectedOption, lastInstanceID.Value.Building); eventCreationWindow.relativePosition = list.relativePosition + new Vector3(-(list.width / 2f), list.height); LoggingWrapper.Log("Selected " + list.selectedIndex); } else { LoggingWrapper.LogError("Couldn't find the option that has been selected for an event!"); } } else { LoggingWrapper.LogError("Couldn't find the list that the selection was made on!"); } }
public void AddEvent(CityEvent eventToAdd) { if (eventToAdd != null) { BuildingManager buildingManager = Singleton <BuildingManager> .instance; Building monument = buildingManager.m_buildings.m_buffer[eventToAdd.m_eventData.m_eventBuilding]; if ((monument.m_flags & Building.Flags.Active) != Building.Flags.None && (monument.m_flags & Building.Flags.Created) != Building.Flags.None) { m_nextEvents.Add(eventToAdd); string message = eventToAdd.GetCitizenMessageInitialised(); if (message != "") { MessageManager _messageManager = Singleton <MessageManager> .instance; _messageManager.QueueMessage(new CitizenCustomMessage(_messageManager.GetRandomResidentID(), message)); } LoggingWrapper.Log("Event created at " + monument.Info.name + " for " + eventToAdd.m_eventData.m_eventStartTime.ToShortDateString() + ". Current date: " + CITY_TIME.ToShortDateString()); Debug.Log("Event starting at " + eventToAdd.m_eventData.m_eventStartTime.ToLongTimeString() + ", " + eventToAdd.m_eventData.m_eventStartTime.ToShortDateString()); Debug.Log("Event building is " + monument.Info.name); Debug.Log("Current date: " + CITY_TIME.ToLongTimeString() + ", " + CITY_TIME.ToShortDateString()); } else { LoggingWrapper.LogError("Couldn't create an event, as the building is inactive or not created!"); } } else { LoggingWrapper.LogError("Couldn't create an event, as it was null!"); } }
public override float GetExpectedReturn() { float expectedReturn = 0f; if (m_eventData != null && m_eventData.m_userEvent) { expectedReturn += m_eventData.m_entryCost * m_eventData.m_userTickets; if (m_eventData.m_incentives != null && m_eventIncentives != null) { List <CityEventXmlIncentive> incentiveList = m_eventIncentives.ToList(); foreach (CityEventDataIncentives incentive in m_eventData.m_incentives) { expectedReturn += incentive.itemCount * incentive.returnCost; } } else { LoggingWrapper.LogError("Tried to get the return cost of an event that has no incentives!"); } } return(expectedReturn); }
public void ReturnFinalAmount() { if (m_eventData.m_userEvent) { Building eventBuilding = Singleton <BuildingManager> .instance.m_buildings.m_buffer[m_eventData.m_eventBuilding]; if ((eventBuilding.m_flags & Building.Flags.Created) != Building.Flags.None) { Singleton <EconomyManager> .instance.AddResource(EconomyManager.Resource.RewardAmount, Mathf.RoundToInt(GetActualReturn() * 100f), eventBuilding.Info.m_class); LoggingWrapper.Log("Returning " + GetActualReturn() + " out of " + GetExpectedReturn() + " to the player for the event completion"); } else { LoggingWrapper.LogError("Event building has been destroyed!"); } } }
public void TakeInitialAmount() { if (m_eventData.m_userEvent) { Building eventBuilding = Singleton <BuildingManager> .instance.m_buildings.m_buffer[m_eventData.m_eventBuilding]; if ((eventBuilding.m_flags & Building.Flags.Created) != Building.Flags.None) { Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Construction, Mathf.RoundToInt(GetCost() * 100f), eventBuilding.Info.m_class); LoggingWrapper.Log("Taking " + GetCost() + " from the player to pay for the event"); } else { LoggingWrapper.LogError("Event building has not been created!"); } } }
public override float GetCost() { float finalCost = 0f; if (m_eventData != null && m_eventData.m_userEvent) { finalCost += m_eventCosts._creation; finalCost += m_eventCosts._perHead * m_eventData.m_userTickets; if (m_eventData.m_incentives != null && m_eventIncentives != null) { List <CityEventXmlIncentive> incentiveList = m_eventIncentives.ToList(); foreach (CityEventDataIncentives incentive in m_eventData.m_incentives) { CityEventXmlIncentive foundIncentive = incentiveList.Find(thisIncentive => thisIncentive._name == incentive.name); if (foundIncentive != null) { finalCost += incentive.itemCount * foundIncentive._cost; } else { LoggingWrapper.LogError("Failed to match event data incentive to XML data incentive."); } } } else { LoggingWrapper.LogError("Tried to get the cost of an event that has no incentives!"); } } else { LoggingWrapper.LogError("Tried to get the cost of an event that has no data!"); } return(finalCost); }
public virtual float GetActualReturn() { float actualReturn = 0f; if (m_eventData != null && m_eventData.m_userEvent) { actualReturn += m_eventData.m_entryCost * m_eventData.m_registeredCitizens; if (m_eventData.m_incentives != null) { foreach (CityEventDataIncentives incentive in m_eventData.m_incentives) { actualReturn += incentive.boughtItems * incentive.returnCost; } } else { LoggingWrapper.LogError("Tried to get the return cost of an event that has no incentives!"); } } return(actualReturn - GetCost()); }
private static void loadSettingsFromSaveFile() { CimTools.CimToolsHandler.CimToolBase.NamedLogger.Log("Rush Hour: Safely loading saved data."); bool legacy = false; if (!CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.LoadOptions()) { CimTools.CimToolsHandler.CimToolBase.NamedLogger.Log("Rush Hour: Loading data from legacy XML file."); CimToolsRushHour.Legacy.File.ExportOptionBase.OptionError error = CimTools.CimToolsHandler.LegacyCimToolBase.XMLFileOptions.Load(); legacy = error == CimToolsRushHour.Legacy.File.ExportOptionBase.OptionError.NoError; if (legacy == false) { CimTools.CimToolsHandler.CimToolBase.NamedLogger.LogError("Couldn't load up legacy data. " + error.ToString()); } } else { CimTools.CimToolsHandler.CimToolBase.NamedLogger.Log("Rush Hour: Loading data from normal XML file."); } safelyGetValue("RandomEvents", ref Experiments.ExperimentsToggle.EnableRandomEvents, legacy); safelyGetValue("TeamColourOnBar", ref Experiments.ExperimentsToggle.TeamColourOnBar, false); safelyGetValue("DisableGameEvents", ref Experiments.ExperimentsToggle.DisableIngameEvents, false); safelyGetValue("AvailableInScenarios", ref Experiments.ExperimentsToggle.EnableInScenarios, false); safelyGetValue("ForceRandomEvents", ref Experiments.ExperimentsToggle.ForceEventToHappen, legacy); safelyGetValue("UseImprovedCommercial1", ref Experiments.ExperimentsToggle.ImprovedDemand, legacy); safelyGetValue("UseImprovedResidential", ref Experiments.ExperimentsToggle.ImprovedResidentialDemand, legacy); safelyGetValue("GhostMode", ref Experiments.ExperimentsToggle.GhostMode, legacy); safelyGetValue("Weekends1", ref Experiments.ExperimentsToggle.EnableWeekends, legacy); safelyGetValue("BetterParking", ref Experiments.ExperimentsToggle.ImprovedParkingAI, legacy); safelyGetValue("ParkingSearchRadius", ref Experiments.ExperimentsToggle.ParkingSearchRadius, legacy); safelyGetValue("LunchRush", ref Experiments.ExperimentsToggle.SimulateLunchTimeRushHour, legacy); safelyGetValue("SearchLocally", ref Experiments.ExperimentsToggle.AllowLocalBuildingSearch, false); safelyGetValue("LocalSearchChance", ref Experiments.ExperimentsToggle.LocalBuildingPercentage, false); safelyGetValue("TwentyFourHourClock", ref Experiments.ExperimentsToggle.NormalClock, legacy); safelyGetValue("SlowTimeProgression", ref Experiments.ExperimentsToggle.SlowTimeProgression, legacy); safelyGetValue("SlowTimeProgressionSpeed", ref Experiments.ExperimentsToggle.TimeMultiplier, legacy); safelyGetValue("SlowTimeProgressionSpeedNight", ref Experiments.ExperimentsToggle.TimeMultiplierNight, legacy); safelyGetValue("SunriseHour", ref SimulationManager.SUNRISE_HOUR, legacy); safelyGetValue("SunsetHour", ref SimulationManager.SUNSET_HOUR, legacy); safelyGetValue("DateFormat", ref Experiments.ExperimentsToggle.DateFormat, legacy); safelyGetValue("SchoolStartTime2", ref Chances.m_startSchoolHour, legacy); safelyGetValue("SchoolStartTimeVariance2", ref Chances.m_minSchoolHour, legacy); safelyGetValue("SchoolEndTime2", ref Chances.m_endSchoolHour, legacy); safelyGetValue("SchoolEndTimeVariance2", ref Chances.m_maxSchoolHour, legacy); safelyGetValue("SchoolDurationMinimum2", ref Chances.m_minSchoolDuration, legacy); safelyGetValue("WorkStartTime2", ref Chances.m_startWorkHour, legacy); safelyGetValue("WorkStartTimeVariance2", ref Chances.m_minWorkHour, legacy); safelyGetValue("WorkEndTime2", ref Chances.m_endWorkHour, legacy); safelyGetValue("WorkEndTimeVariance2", ref Chances.m_maxWorkHour, legacy); safelyGetValue("WorkDurationMinimum2", ref Chances.m_minWorkDuration, legacy); safelyGetValue("DebugLog", ref Experiments.ExperimentsToggle.WriteDebugLog, false); safelyGetValue("PrintMonuments", ref Experiments.ExperimentsToggle.PrintAllMonuments, legacy); safelyGetValue("ForceXMLEnabled", ref Experiments.ExperimentsToggle.AllowForcedXMLEvents, legacy); safelyGetValue("FixInactiveBuildings", ref Experiments.ExperimentsToggle.AllowActiveCommercialFix, legacy); string language = "English"; safelyGetValue("Language", ref language, legacy); List <string> validLanguages = CimTools.CimToolsHandler.CimToolBase.Translation.GetLanguageIDsFromName(language); if (validLanguages.Count > 0) { CimTools.CimToolsHandler.CimToolBase.Translation.TranslateTo(validLanguages[0]); if (validLanguages.Count > 1) { LoggingWrapper.LogWarning("Language " + language + " has more than one unique ID associated with it. Picked the first one."); } } else { LoggingWrapper.LogError("Could not switch to language " + language + ", as there are no valid languages with that name!"); } bool loadEventEditor = false; safelyGetValue("EditEvents", ref loadEventEditor, legacy); if (loadEventEditor) { try { string modPath = CimTools.CimToolsHandler.CimToolBase.Path.GetModPath(); if (modPath != null && modPath != "") { Process.Start(modPath + Path.DirectorySeparatorChar + "EventEditor.exe"); CimTools.CimToolsHandler.CimToolBase.ModPanelOptions.SetOptionValue("EditEvents", false); } else { UnityEngine.Debug.LogError("Rush Hour: Couldn't find the event editor!"); } } catch { UnityEngine.Debug.LogError("Rush Hour: Couldn't load the event editor!"); } } CimTools.CimToolsHandler.CimToolBase.Translation.RefreshLanguages(); }
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"); } }