/// <summary>
        /// Saves the current RICO settings to file and then applies them live in-game.
        /// </summary>
        private void SaveAndApply()
        {
            // Find current prefab instance.
            BuildingData currentBuildingData = Loading.xmlManager.prefabHash[currentSelection.prefab];

            // Save first.
            Save();

            // Get the currently applied RICO settings (local, author, mod).
            RICOBuilding currentData = RICOUtils.CurrentRICOSetting(currentSelection);

            if (currentData != null)
            {
                // Convert the 'live' prefab (instance in PrefabCollection) and update household count and builidng level for all current instances.
                Loading.convertPrefabs.ConvertPrefab(currentData, PrefabCollection <BuildingInfo> .FindLoaded(currentBuildingData.prefab.name));
                CitizenUnitUtils.UpdateCitizenUnits(currentBuildingData.prefab.name);
            }
            else
            {
                Logging.Message("no current RICO settings to apply to prefab ", currentBuildingData.prefab.name);
            }

            // Force an update of all panels with current values.
            SettingsPanel.Panel.UpdateSelectedBuilding(currentSelection);
        }
Esempio n. 2
0
        //This is called by the settings panel. It will serialize any new local settings the player sets in game.
        public static void SaveLocal(RICOBuilding newBuildingData)
        {
            Debug.Log("SaveLocal");

            if (File.Exists("LocalRICOSettings.xml") && newBuildingData != null)
            {
                PloppableRICODefinition localSettings = null;
                var newlocalSettings = new PloppableRICODefinition();

                var xmlSerializer = new XmlSerializer(typeof(PloppableRICODefinition));

                using (StreamReader streamReader = new System.IO.StreamReader("LocalRICOSettings.xml"))
                {
                    localSettings = xmlSerializer.Deserialize(streamReader) as PloppableRICODefinition;
                }

                foreach (var buildingDef in localSettings.Buildings)
                {
                    if (buildingDef.name != newBuildingData.name)
                    {
                        newlocalSettings.Buildings.Add(buildingDef);
                    }
                }

                //newBuildingData.name = newBuildingData.name;
                newlocalSettings.Buildings.Add(newBuildingData);

                using (TextWriter writer = new StreamWriter("LocalRICOSettings.xml"))
                {
                    xmlSerializer.Serialize(writer, newlocalSettings);
                }
            }
        }
        /// <summary>
        /// Saves the current RICO settings to file and then applies them live in-game.
        /// </summary>
        private void SaveAndApply()
        {
            // Find current prefab instance.
            BuildingData currentBuildingData = Loading.xmlManager.prefabHash[currentSelection.prefab];

            // Save first.
            Save();

            // If we're converting a residential building to something else, then we first should clear out all households.
            if (currentBuildingData.prefab.GetService() == ItemClass.Service.Residential && !IsCurrentResidential())
            {
                // removeAll argument to true to remove all households.
                UpdateHouseholds(currentBuildingData.prefab.name, removeAll: true);
            }

            // Get the currently applied RICO settings (local, author, mod).
            RICOBuilding currentData = RICOUtils.CurrentRICOSetting(currentSelection);

            if (currentData != null)
            {
                // Convert the 'live' prefab (instance in PrefabCollection) and update household count and builidng level for all current instances.
                Loading.convertPrefabs.ConvertPrefab(currentData, PrefabCollection <BuildingInfo> .FindLoaded(currentBuildingData.prefab.name));
                UpdateHouseholds(currentBuildingData.prefab.name, currentData.level);
            }
            else
            {
                Debugging.Message("no current RICO settings to apply to prefab " + currentBuildingData);
            }

            // Force an update of all panels with current values.
            SettingsPanel.Panel.UpdateSelectedBuilding(currentSelection);
        }
 public void RaiseBuildingPropertyChanged(RICOBuilding building)
 {
     if (BuildingPropertyChanged != null)
     {
         var e = new BuildingChangedEventArgs();
         e.building = building;
         BuildingPropertyChanged(this, e);
     }
 }
        /// <summary>
        /// Handles click events for Ploppable Tool panel tabs.
        /// </summary>
        /// <param name="panel">The Ploppable Tool panel for the selected tab</param>
        /// <param name="sprite">The sprite icon for the selected tab</param>
        public void TabClicked(int uiCategory, UISprite sprite)
        {
            // Clear the scroll panel.
            scrollPanel.Clear();

            // List of buildings in this category.
            List <BuildingData> buildingList = new List <BuildingData>();

            // Iterate through each prefab in our collection and see if it has RICO settings with a matching UI category.
            foreach (BuildingData buildingData in Loading.xmlManager.prefabHash.Values)
            {
                // Get the currently active RICO setting (if any) for this building.
                RICOBuilding ricoSetting = RICOUtils.CurrentRICOSetting(buildingData);

                // See if there's a valid RICO setting.
                if (ricoSetting != null)
                {
                    // Valid setting - if the UI category matches this one, add it to the list.
                    if (UICategoryIndex(ricoSetting.UiCategory) == uiCategory)
                    {
                        buildingList.Add(buildingData);
                    }
                }
            }

            // Set display FastList using our list of selected buildings, sorted alphabetically.
            scrollPanel.itemsData.m_buffer = buildingList.OrderBy(x => x.DisplayName).ToArray();
            scrollPanel.itemsData.m_size   = buildingList.Count;

            // Display the scroll panel.
            scrollPanel.DisplayAt(0);

            // Redraw all tab sprites in their base state (unfocused).
            for (int i = 0; i <= NumTypes; i++)
            {
                if (i <= 5)
                {
                    TabSprites[i].spriteName = "Zoning" + Names[i];
                }
                else
                {
                    TabSprites[i].spriteName = "IconPolicy" + Names[i];
                }
            }

            // Focus this sprite (no focused versions for AD or GC sprites so exclude those).
            if (sprite.spriteName != "IconPolicyLeisure" && sprite.spriteName != "IconPolicyTourist" && sprite.spriteName != "IconPolicyHightech" && sprite.spriteName != "IconPolicyOrganic" && sprite.spriteName != "IconPolicySelfsufficient")
            {
                sprite.spriteName += "Focused";
            }
        }
        public RICOBuilding addBuilding(RICOBuilding buildingDef = null)
        {
            _isDirty = true;

            if (buildingDef == null)
            {
                buildingDef        = new RICOBuilding();
                buildingDef.name   = "* unnamed";
                buildingDef.parent = this;
            }

            Buildings.Add(buildingDef);

            return(buildingDef);
        }
Esempio n. 7
0
        public static void CalculateWorkplaceCount(RICOBuilding ricoData, IWorkplaceLevelCalculator ai, Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
        {
            SetWorkplaceLevels(out level0, out level1, out level2, out level3, 0, 0, 0, 0);
            RICOBuilding rc = ricoData;

            if (rc != null)
            {
                // reality mod is running and the xml file says ignore-reality="false"
                if (rc.useReality)
                {
                    ai.CalculateBaseWorkplaceCount(r, width, length, out level0, out level1, out level2, out level3);
                }
                else
                {
                    SetWorkplaceLevels(out level0, out level1, out level2, out level3, deviateWorkplaces(ricoData.workplaces, ricoData.workplaceDeviation));
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Called by other mods to determine whether or not Ploppable RICO Revisited is controlling the population of this prefab.
        /// </summary>
        /// <param name="prefab">Prefab reference</param>
        /// <returns>True if Ploppable RICO is controlling the population of this prefab, false otherwise.</returns>
        public static bool IsRICOPopManaged(BuildingInfo prefab)
        {
            // First, do we have a setting at all?
            if (prefab != null && Loading.xmlManager.prefabHash.ContainsKey(prefab))
            {
                // Get active RICO settings.
                RICOBuilding building = RICOUtils.CurrentRICOSetting(Loading.xmlManager.prefabHash[prefab]);

                // Check that it's enabled and isn't using reality.
                if (building != null && building.ricoEnabled && !building.UseReality)
                {
                    return(true);
                }
            }

            // If we got here, we don't have an active setting.
            return(false);
        }
Esempio n. 9
0
        internal static void CalculateWorkplaceCount(ItemClass.Level level, RICOBuilding ricoData, IWorkplaceLevelCalculator ai, Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
        {
            SetWorkplaceLevels(out level0, out level1, out level2, out level3, 0, 0, 0, 0);
            RICOBuilding rc = ricoData;

            if (rc != null)
            {
                // reality mod is running and the xml file says ignore-reality="false"
                if (rc.UseReality)
                {
                    ai.CalculateBaseWorkplaceCount(level, r, width, length, out level0, out level1, out level2, out level3);
                }
                else
                {
                    SetWorkplaceLevels(out level0, out level1, out level2, out level3, ricoData.Workplaces);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Event handler for demolish warning checkbox.
        /// </summary>
        /// <param name="control">Calling UIComponent</param>
        /// <param name="isChecked">New isChecked state</param>
        private void DemolishWarnCheckChanged(UIComponent control, bool isChecked)
        {
            // Update mod settings.
            ModSettings.warnBulldoze = isChecked;

            // If we're in-game (dictionary has been initialized), iterate through dictionary, looking for RICO ploppable buildings and updating their auto-remove flags.
            if (Loading.xmlManager?.prefabHash != null)
            {
                foreach (BuildingInfo prefab in Loading.xmlManager.prefabHash.Keys)
                {
                    // Get active RICO settings.
                    RICOBuilding building = RICOUtils.CurrentRICOSetting(Loading.xmlManager.prefabHash[prefab]);

                    // Check that it's enabled and isn't growable.
                    if (building != null && building.ricoEnabled && !building.growable)
                    {
                        // Apply flag.
                        prefab.m_autoRemove = !isChecked;
                    }
                }
            }
        }
Esempio n. 11
0
        public void ConvertPrefab(RICOBuilding buildingData, string name)
        {
            var prefab = PrefabCollection <BuildingInfo> .FindLoaded(name);

            int num2;
            int num3;
            //prefab.GetWidthRange(out num2, out num3);
            int num4;
            int num5;

            //prefab.GetLengthRange(out num4, out num5);

            //This filters out Larger Footprint buildings.
            //if (!(prefab.m_cellWidth < num2 || prefab.m_cellWidth > num3 || prefab.m_cellLength < num4 || prefab.m_cellLength > num5))
            // {

            if (prefab != null)
            {
                if (buildingData.service == "dummy")
                {
                    var ai = prefab.gameObject.AddComponent <DummyBuildingAI>();

                    prefab.m_buildingAI        = ai;
                    prefab.m_buildingAI.m_info = prefab;
                    try
                    {
                        prefab.InitializePrefab();
                    }
                    catch
                    {
                        Debug.Log("InitPrefab Failed" + prefab.name);
                    }
                    prefab.m_placementStyle = ItemClass.Placement.Manual;
                }

                else if (buildingData.service == "residential")
                {
                    var ai = prefab.gameObject.AddComponent <PloppableResidential>();
                    if (ai == null)
                    {
                        throw (new Exception("Residential-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_constructionCost = buildingData.constructionCost;
                    ai.m_homeCount        = buildingData.homeCount;


                    //If GC installed, apply eco service if set
                    if (Util.isGCinstalled())
                    {
                        Debug.Log("Green Cites Installed");

                        if (buildingData.subService == "low eco")
                        {
                            InitializePrefab(prefab, ai, "Low Residential - Level" + buildingData.level);
                        }
                        else if (buildingData.subService == "high eco")
                        {
                            InitializePrefab(prefab, ai, "High Residential - Level" + buildingData.level);
                        }
                        else if (buildingData.subService == "high")
                        {
                            InitializePrefab(prefab, ai, "High Residential - Level" + buildingData.level);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Low Residential - Level" + buildingData.level);
                        }
                    }
                    //if no DLC, apply normal services
                    else
                    {
                        if (buildingData.subService == "high eco" || buildingData.service == "high")
                        {
                            InitializePrefab(prefab, ai, "High" + " Residential - Level" + buildingData.level);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Low" + " Residential - Level" + buildingData.level);
                        }
                    }
                }
                else if (buildingData.service == "office")
                {
                    var ai = prefab.gameObject.AddComponent <PloppableOffice>();
                    if (ai == null)
                    {
                        throw (new Exception("Office-AI not found."));
                    }
                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;

                    //Apply IT cluster if DLC installed
                    if (Util.isGCinstalled())
                    {
                        if (buildingData.subService == "high tech")
                        {
                            InitializePrefab(prefab, ai, "Office - Level3");
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Office - Level" + buildingData.level);
                        }
                    }
                    //If no DLC, make IT buildngs level 3 office.
                    else
                    {
                        if (buildingData.service == "high tech")
                        {
                            InitializePrefab(prefab, ai, "Office - Level3");
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Office - Level" + buildingData.level);
                        }
                    }
                }
                else if (buildingData.service == "industrial")
                {
                    var ai = prefab.gameObject.AddComponent <PloppableIndustrial>();
                    if (ai == null)
                    {
                        throw (new Exception("Industrial-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;
                    ai.m_pollutionEnabled = buildingData.pollutionEnabled;

                    if (Util.industryServices.Contains(buildingData.subService))
                    {
                        InitializePrefab(prefab, ai, Util.ucFirst(buildingData.subService) + " - Processing");
                    }
                    else
                    {
                        InitializePrefab(prefab, ai, "Industrial - Level" + buildingData.level);
                    }
                }
                else if (buildingData.service == "extractor")
                {
                    var ai = prefab.gameObject.AddComponent <PloppableExtractor>();
                    if (ai == null)
                    {
                        throw (new Exception("Extractor-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;
                    ai.m_pollutionEnabled = buildingData.pollutionEnabled;

                    if (Util.industryServices.Contains(buildingData.subService))
                    {
                        InitializePrefab(prefab, ai, Util.ucFirst(buildingData.subService) + " - Extractor");
                    }
                }

                else if (buildingData.service == "commercial")
                {
                    string itemClass = "";
                    var    ai        = prefab.gameObject.AddComponent <PloppableCommercial>();
                    if (ai == null)
                    {
                        throw (new Exception("Commercial-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;

                    // high and low
                    if (Util.vanillaCommercialServices.Contains(buildingData.subService))
                    {
                        itemClass = Util.ucFirst(buildingData.subService) + " Commercial - Level" + buildingData.level;
                    }

                    //apply AD subservice if DLC installed
                    else if (Util.isADinstalled())
                    {
                        if (buildingData.subService == "tourist")
                        {
                            itemClass = "Tourist Commercial - Land";
                        }
                        else if (buildingData.subService == "leisure")
                        {
                            itemClass = "Leisure Commercial";
                        }
                        else
                        {
                            itemClass = Util.ucFirst(buildingData.subService) + " Commercial - Level" + buildingData.level;
                        }
                    }

                    //apply GC subservice if DLC installed
                    else if (Util.isGCinstalled())
                    {
                        if (buildingData.subService == "eco")
                        {
                            itemClass = "Low Commercial - Level3";
                        }
                        else
                        {
                            itemClass = Util.ucFirst(buildingData.subService) + " Commercial - Level" + buildingData.level;
                        }
                    }

                    //use com high as default if no DLCs installed yet DLC settings found

                    InitializePrefab(prefab, ai, itemClass);
                }
                //}
            }
        }
Esempio n. 12
0
 public static void distributeWorkplaceLevels(RICOBuilding ricoData, out int level0, out int level1, out int level2, out int level3)
 {
     distributeWorkplaceLevels(ricoData.workplaceCount, Util.WorkplaceDistributionOf(ricoData.service, ricoData.subService, "Level" + ricoData.level.ToString()), ricoData.workplaceDeviation, out level0, out level1, out level2, out level3);
 }
Esempio n. 13
0
        public void SelectionChanged(BuildingData buildingData)
        {
            //When dropdowns are updated, this disables the event logic
            disableEvents = true;

            ricoEnabled.Enable();
            service.Enable();
            subService.Enable();
            level.Enable();
            uiCategory.Enable();
            construction.Enable();
            manual.Enable();
            popBalanceEnabled.Enable();

            //If selected asset has local settings, update option UI elements with those settings.
            if (buildingData.hasLocal)
            {
                currentSelection = buildingData.local;
                UpdateElements(buildingData.local.service);
                UpdateValues(buildingData.local);
                label.text    = "Local Settings";
                disableEvents = false;
                return;
            }
            else if (buildingData.hasAuthor)
            {
                currentSelection = buildingData.author;
                UpdateElements(buildingData.author.service);
                UpdateValues(buildingData.author);
                label.text = "Author Settings";
                ricoEnabled.Disable();
                service.Disable();
                subService.Disable();
                level.Disable();
                uiCategory.Disable();
                construction.Disable();
                manual.Disable();
                popBalanceEnabled.Disable();
                disableEvents = false;
                return;
            }
            else if (buildingData.hasMod)
            {
                currentSelection = buildingData.mod;
                label.text       = "Mod Settings";
                UpdateElements(buildingData.mod.service);
                UpdateValues(buildingData.mod);
                ricoEnabled.Disable();
                service.Disable();
                subService.Disable();
                level.Disable();
                uiCategory.Disable();
                construction.Disable();
                manual.Disable();
                popBalanceEnabled.Disable();
                disableEvents = false;
                return;
            }
            else
            {
                ricoEnabled.isChecked = false;
                ricoEnabled.Disable();
                label.text = "No Settings";
            }

            disableEvents = false;
        }
 public RICOBuilding removeBuilding(RICOBuilding buildingDef)
 {
     Buildings.Remove(buildingDef);
     _isDirty = true;
     return(buildingDef);
 }
        /// <summary>
        /// Interpret and apply RICO settings to a building prefab.
        /// </summary>
        /// <param name="buildingData">RICO building data to apply</param>
        /// <param name="prefab">The building prefab to be changed</param>
        internal void ConvertPrefab(RICOBuilding buildingData, BuildingInfo prefab)
        {
            // AI class  for prefab init.
            string aiClass;


            if (prefab != null)
            {
                // Check eligibility for any growable assets.
                if (buildingData.growable)
                {
                    // Growables can't have any dimension greater than 4.
                    if (prefab.GetWidth() > 4 || prefab.GetLength() > 4)
                    {
                        buildingData.growable = false;
                        Logging.Error("building '", prefab.name, "' can't be growable because it is too big");
                    }

                    // Growables can't have net structures.
                    if (prefab.m_paths != null && prefab.m_paths.Length != 0)
                    {
                        buildingData.growable = false;
                        Logging.Error("building '", prefab.name, "' can't be growable because it contains network assets");
                    }
                }

                // Apply AI based on service.
                switch (buildingData.service)
                {
                // Dummy AI.
                case "dummy":

                    // Get AI.
                    DummyBuildingAI dummyAI = prefab.gameObject.AddComponent <DummyBuildingAI>();

                    // Use beautification ItemClass to avoid issues, and never make growable.
                    InitializePrefab(prefab, dummyAI, "Beautification Item", false);

                    // Final circular reference.
                    prefab.m_buildingAI.m_info = prefab;

                    // Dummy is a special case, and we're done here.
                    return;

                // Residential AI.
                case "residential":

                    // Get AI.
                    GrowableResidentialAI residentialAI = buildingData.growable ? prefab.gameObject.AddComponent <GrowableResidentialAI>() : prefab.gameObject.AddComponent <PloppableResidentialAI>();
                    if (residentialAI == null)
                    {
                        throw new Exception("Ploppable RICO residential AI not found.");
                    }

                    // Assign basic parameters.
                    residentialAI.m_ricoData         = buildingData;
                    residentialAI.m_constructionCost = buildingData.ConstructionCost;
                    residentialAI.m_homeCount        = buildingData.homeCount;

                    // Determine AI class string according to subservice.
                    switch (buildingData.subService)
                    {
                    case "low eco":
                        // Apply eco service if GC installed, otherwise use normal low residential.
                        if (Util.IsGCinstalled())
                        {
                            aiClass = "Low Residential Eco - Level";
                        }
                        else
                        {
                            aiClass = "Low Residential - Level";
                        }
                        break;

                    case "high eco":
                        // Apply eco service if GC installed, otherwise use normal high residential.
                        if (Util.IsGCinstalled())
                        {
                            aiClass = "High Residential Eco - Level";
                        }
                        else
                        {
                            aiClass = "High Residential - Level";
                        }
                        break;

                    case "high":
                        // Stock standard high commercial.
                        aiClass = "High Residential - Level";
                        break;

                    default:
                        // Fall back to low residential as default.
                        aiClass = "Low Residential - Level";

                        // If invalid subservice, report.
                        if (buildingData.subService != "low")
                        {
                            Logging.Message("Residential building ", buildingData.Name, " has invalid subservice ", buildingData.subService, "; reverting to low residential");
                        }
                        break;
                    }

                    // Initialize the prefab.
                    InitializePrefab(prefab, residentialAI, aiClass + buildingData.level, buildingData.growable);

                    break;

                // Office AI.
                case "office":

                    // Get AI.
                    GrowableOfficeAI officeAI = buildingData.growable ? prefab.gameObject.AddComponent <GrowableOfficeAI>() : prefab.gameObject.AddComponent <PloppableOfficeAI>();
                    if (officeAI == null)
                    {
                        throw new Exception("Ploppable RICO Office AI not found.");
                    }

                    // Assign basic parameters.
                    officeAI.m_ricoData         = buildingData;
                    officeAI.m_workplaceCount   = buildingData.WorkplaceCount;
                    officeAI.m_constructionCost = buildingData.ConstructionCost;

                    // Check if this is an IT Cluster specialisation.

                    // Determine AI class string according to subservice.
                    if (buildingData.subService == "high tech")
                    {
                        // Apply IT cluster if GC installed, otherwise use Level 3 office.
                        if (Util.IsGCinstalled())
                        {
                            aiClass = "Office - Hightech";
                        }
                        else
                        {
                            aiClass = "Office - Level3";
                        }
                    }
                    else
                    {
                        // Not IT cluster - boring old ordinary office.
                        aiClass = "Office - Level" + buildingData.level;
                    }

                    // Initialize the prefab.
                    InitializePrefab(prefab, officeAI, aiClass, buildingData.growable);

                    break;

                // Industrial AI.
                case "industrial":
                    // Get AI.
                    GrowableIndustrialAI industrialAI = buildingData.growable ? prefab.gameObject.AddComponent <GrowableIndustrialAI>() : prefab.gameObject.AddComponent <PloppableIndustrialAI>();
                    if (industrialAI == null)
                    {
                        throw new Exception("Ploppable RICO Industrial AI not found.");
                    }

                    // Assign basic parameters.
                    industrialAI.m_ricoData         = buildingData;
                    industrialAI.m_workplaceCount   = buildingData.WorkplaceCount;
                    industrialAI.m_constructionCost = buildingData.ConstructionCost;
                    industrialAI.m_pollutionEnabled = buildingData.pollutionEnabled;

                    // Determine AI class string according to subservice.
                    // Check for valid subservice.
                    if (IsValidIndSubServ(buildingData.subService))
                    {
                        // Specialised industry.
                        aiClass = ServiceName(buildingData.subService) + " - Processing";
                    }
                    else
                    {
                        // Generic industry.
                        aiClass = "Industrial - Level" + buildingData.level;
                    }

                    // Initialize the prefab.
                    InitializePrefab(prefab, industrialAI, aiClass, buildingData.growable);

                    break;

                // Extractor AI.
                case "extractor":
                    // Get AI.
                    GrowableExtractorAI extractorAI = buildingData.growable ? prefab.gameObject.AddComponent <GrowableExtractorAI>() : prefab.gameObject.AddComponent <PloppableExtractorAI>();
                    if (extractorAI == null)
                    {
                        throw new Exception("Ploppable RICO Extractor AI not found.");
                    }

                    // Assign basic parameters.
                    extractorAI.m_ricoData         = buildingData;
                    extractorAI.m_workplaceCount   = buildingData.WorkplaceCount;
                    extractorAI.m_constructionCost = buildingData.ConstructionCost;
                    extractorAI.m_pollutionEnabled = buildingData.pollutionEnabled;

                    // Check that we have a valid industry subservice.
                    if (IsValidIndSubServ(buildingData.subService))
                    {
                        // Initialise the prefab.
                        InitializePrefab(prefab, extractorAI, ServiceName(buildingData.subService) + " - Extractor", buildingData.growable);
                    }
                    else
                    {
                        Logging.Error("invalid industry subservice ", buildingData.subService, " for extractor ", buildingData.Name);
                    }

                    break;

                // Commercial AI.
                case "commercial":
                    // Get AI.
                    GrowableCommercialAI commercialAI = buildingData.growable ? prefab.gameObject.AddComponent <GrowableCommercialAI>() : prefab.gameObject.AddComponent <PloppableCommercialAI>();
                    if (commercialAI == null)
                    {
                        throw new Exception("Ploppable RICO Commercial AI not found.");
                    }

                    // Assign basic parameters.
                    commercialAI.m_ricoData         = buildingData;
                    commercialAI.m_workplaceCount   = buildingData.WorkplaceCount;
                    commercialAI.m_constructionCost = buildingData.ConstructionCost;

                    // Determine AI class string according to subservice.
                    switch (buildingData.subService)
                    {
                    // Organic and Local Produce.
                    case "eco":
                        // Apply eco specialisation if GC installed, otherwise use Level 1 low commercial.
                        if (Util.IsGCinstalled())
                        {
                            // Eco commercial buildings only import food goods.
                            commercialAI.m_incomingResource = TransferManager.TransferReason.Food;
                            aiClass = "Eco Commercial";
                        }
                        else
                        {
                            aiClass = "Low Commercial - Level1";
                        }
                        break;

                    // Tourism.
                    case "tourist":
                        // Apply tourist specialisation if AD installed, otherwise use Level 1 low commercial.
                        if (Util.IsADinstalled())
                        {
                            aiClass = "Tourist Commercial - Land";
                        }
                        else
                        {
                            aiClass = "Low Commercial - Level1";
                        }
                        break;

                    // Leisure.
                    case "leisure":
                        // Apply leisure specialisation if AD installed, otherwise use Level 1 low commercial.
                        if (Util.IsADinstalled())
                        {
                            aiClass = "Leisure Commercial";
                        }
                        else
                        {
                            aiClass = "Low Commercial - Level1";
                        }
                        break;

                    // Bog standard high commercial.
                    case "high":
                        aiClass = "High Commercial - Level" + buildingData.level;
                        break;

                    // Fall back to low commercial as default.
                    default:
                        aiClass = "Low Commercial - Level" + buildingData.level;

                        // If invalid subservice, report.
                        if (buildingData.subService != "low")
                        {
                            Logging.Message("Commercial building ", buildingData.Name, " has invalid subService ", buildingData.subService, "; reverting to low commercial.");
                        }
                        break;
                    }

                    // Initialize the prefab.
                    InitializePrefab(prefab, commercialAI, aiClass, buildingData.growable);

                    break;
                }
            }
        }
Esempio n. 16
0
        public void UpdateValues(RICOBuilding buildingData)
        {
            //Updates the values in the RICO options panel to match the selected building.

            manual.text = buildingData.workplaceCount.ToString();


            if (buildingData.service == "residential")
            {
                manual.text           = buildingData.homeCount.ToString();
                service.selectedIndex = 1;


                if (currentSelection.subService == "high")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "low")
                {
                    subService.selectedIndex = 1;
                }
                // else if (currentSelection.subService == "high eco") subService.selectedIndex = 2;
                //else if (currentSelection.subService == "low eco") subService.selectedIndex = 3;
            }

            else if (buildingData.service == "industrial")
            {
                service.selectedIndex = 2;
                subService.items      = IndustrialSub;

                if (currentSelection.subService == "generic")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "forest")
                {
                    subService.selectedIndex = 1;
                }
                else if (currentSelection.subService == "oil")
                {
                    subService.selectedIndex = 2;
                }
                else if (currentSelection.subService == "ore")
                {
                    subService.selectedIndex = 3;
                }
                else if (currentSelection.subService == "farming")
                {
                    subService.selectedIndex = 4;
                }
            }

            else if (buildingData.service == "office")
            {
                service.selectedIndex = 3;
                subService.items      = OfficeSub;

                if (currentSelection.subService == "none")
                {
                    subService.selectedIndex = 0;
                }
                //else if (currentSelection.subService == "high tech") subService.selectedIndex = 1;
            }

            else if (buildingData.service == "commercial")
            {
                service.selectedIndex = 4;
                subService.items      = ComSub;

                if (currentSelection.subService == "high")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "low")
                {
                    subService.selectedIndex = 1;
                }
                else if (currentSelection.subService == "tourist")
                {
                    subService.selectedIndex = 2;
                }
                else if (currentSelection.subService == "leisure")
                {
                    subService.selectedIndex = 3;
                }
                //else if (currentSelection.subService == "eco") subService.selectedIndex = 4;
            }

            else if (buildingData.service == "extractor")
            {
                service.selectedIndex = 5;
                subService.items      = ExtractorSub;

                if (currentSelection.subService == "forest")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "oil")
                {
                    subService.selectedIndex = 1;
                }
                else if (currentSelection.subService == "ore")
                {
                    subService.selectedIndex = 2;
                }
                else if (currentSelection.subService == "farming")
                {
                    subService.selectedIndex = 3;
                }
            }

            else if (buildingData.service == "dummy")
            {
                service.selectedIndex    = 6;
                subService.selectedIndex = 0;
                subService.items         = OfficeSub;
            }

            if (buildingData.uiCategory == "reslow")
            {
                uiCategory.selectedIndex = 0;
            }
            else if (buildingData.uiCategory == "reshigh")
            {
                uiCategory.selectedIndex = 1;
            }
            else if (buildingData.uiCategory == "comlow")
            {
                uiCategory.selectedIndex = 2;
            }
            else if (buildingData.uiCategory == "comhigh")
            {
                uiCategory.selectedIndex = 3;
            }
            else if (buildingData.uiCategory == "office")
            {
                uiCategory.selectedIndex = 4;
            }
            else if (buildingData.uiCategory == "industrial")
            {
                uiCategory.selectedIndex = 5;
            }
            else if (buildingData.uiCategory == "farming")
            {
                uiCategory.selectedIndex = 6;
            }
            else if (buildingData.uiCategory == "oil")
            {
                uiCategory.selectedIndex = 7;
            }
            else if (buildingData.uiCategory == "forest")
            {
                uiCategory.selectedIndex = 8;
            }
            else if (buildingData.uiCategory == "ore")
            {
                uiCategory.selectedIndex = 9;
            }
            else if (buildingData.uiCategory == "tourist")
            {
                uiCategory.selectedIndex = 10;
            }
            else if (buildingData.uiCategory == "leisure")
            {
                uiCategory.selectedIndex = 11;
            }
            else if (buildingData.uiCategory == "none")
            {
                uiCategory.selectedIndex = 12;
            }

            level.selectedIndex = (buildingData.level - 1);

            popBalanceEnabled.isChecked = !buildingData.popbalanceEnabled;
            construction.text           = buildingData.constructionCost.ToString();

            ricoEnabled.isChecked = buildingData.ricoEnabled;
        }
        /// <summary>
        /// Interpret and apply RICO settings to a building prefab.
        /// </summary>
        /// <param name="buildingData">RICO building data to apply</param>
        /// <param name="prefab">The building prefab to be changed</param>
        internal void ConvertPrefab(RICOBuilding buildingData, BuildingInfo prefab)
        {
            if (prefab != null)
            {
                // Check eligibility for any growable assets.
                if (buildingData.growable)
                {
                    // Growables can't have any dimension greater than 4.
                    if (prefab.GetWidth() > 4 || prefab.GetLength() > 4)
                    {
                        buildingData.growable = false;
                        Debugging.Message("building '" + prefab.name + "' can't be growable because it is too big");
                    }

                    // Growables can't have net structures.
                    if (prefab.m_paths != null && prefab.m_paths.Length != 0)
                    {
                        buildingData.growable = false;
                        Debugging.Message("building '" + prefab.name + "' can't be growable because it contains network assets");
                    }
                }

                if (buildingData.service == "dummy")
                {
                    var ai = prefab.gameObject.AddComponent <DummyBuildingAI>();

                    // Use beautification ItemClass to avoid issues, and never make growable.
                    InitializePrefab(prefab, ai, "Beautification Item", false);

                    // Final circular reference.
                    prefab.m_buildingAI.m_info = prefab;
                }
                else if (buildingData.service == "residential")
                {
                    var ai = buildingData.growable ? prefab.gameObject.AddComponent <GrowableResidentialAI>() : prefab.gameObject.AddComponent <PloppableResidentialAI>();
                    if (ai == null)
                    {
                        throw (new Exception("Residential-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_constructionCost = buildingData.constructionCost;
                    ai.m_homeCount        = buildingData.homeCount;

                    if (buildingData.subService == "low eco")
                    {
                        // Apply eco service if GC installed, otherwise use normal low residential.
                        if (Util.isGCinstalled())
                        {
                            InitializePrefab(prefab, ai, "Low Residential Eco - Level" + buildingData.level, buildingData.growable);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Low Residential - Level" + buildingData.level, buildingData.growable);
                        }
                    }
                    else if (buildingData.subService == "high eco")
                    {
                        // Apply eco service if GC installed, otherwise use normal high residential.
                        if (Util.isGCinstalled())
                        {
                            InitializePrefab(prefab, ai, "High Residential Eco - Level" + buildingData.level, buildingData.growable);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "High Residential - Level" + buildingData.level, buildingData.growable);
                        }
                    }
                    else if (buildingData.subService == "high")
                    {
                        // Stock standard high commercial.
                        InitializePrefab(prefab, ai, "High Residential - Level" + buildingData.level, buildingData.growable);
                    }
                    else
                    {
                        // Fall back to low residential as default.
                        InitializePrefab(prefab, ai, "Low Residential - Level" + buildingData.level, buildingData.growable);

                        // If invalid subservice, report.
                        if (buildingData.subService != "low")
                        {
                            Debugging.ErrorBuffer.AppendLine("Residential building " + buildingData.name + " has invalid subservice " + buildingData.subService + "; reverting to low residential.");
                        }
                    }
                }
                else if (buildingData.service == "office")
                {
                    var ai = buildingData.growable ? prefab.gameObject.AddComponent <GrowableOfficeAI>() : prefab.gameObject.AddComponent <PloppableOfficeAI>();
                    if (ai == null)
                    {
                        throw (new Exception("Office-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;

                    if (buildingData.subService == "high tech")
                    {
                        // Apply IT cluster if GC installed, otherwise use Level 3 office.
                        if (Util.isGCinstalled())
                        {
                            InitializePrefab(prefab, ai, "Office - Hightech", buildingData.growable);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Office - Level3", buildingData.growable);
                        }
                    }
                    else
                    {
                        // Not IT cluster - boring old ordinary office.
                        InitializePrefab(prefab, ai, "Office - Level" + buildingData.level, buildingData.growable);
                    }
                }
                else if (buildingData.service == "industrial")
                {
                    var ai = buildingData.growable ? prefab.gameObject.AddComponent <GrowableIndustrialAI>() : prefab.gameObject.AddComponent <PloppableIndustrialAI>();
                    if (ai == null)
                    {
                        throw (new Exception("Industrial-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;
                    ai.m_pollutionEnabled = buildingData.pollutionEnabled;

                    if (Util.industryServices.Contains(buildingData.subService))
                    {
                        InitializePrefab(prefab, ai, Util.ucFirst(buildingData.subService) + " - Processing", buildingData.growable);
                    }
                    else
                    {
                        InitializePrefab(prefab, ai, "Industrial - Level" + buildingData.level, buildingData.growable);
                    }
                }
                else if (buildingData.service == "extractor")
                {
                    var ai = buildingData.growable ? prefab.gameObject.AddComponent <GrowableExtractorAI>() : prefab.gameObject.AddComponent <PloppableExtractorAI>();
                    if (ai == null)
                    {
                        throw (new Exception("Extractor-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;
                    ai.m_pollutionEnabled = buildingData.pollutionEnabled;

                    if (Util.industryServices.Contains(buildingData.subService))
                    {
                        InitializePrefab(prefab, ai, Util.ucFirst(buildingData.subService) + " - Extractor", buildingData.growable);
                    }
                }

                else if (buildingData.service == "commercial")
                {
                    var ai = buildingData.growable ? prefab.gameObject.AddComponent <GrowableCommercialAI>() : prefab.gameObject.AddComponent <PloppableCommercialAI>();
                    if (ai == null)
                    {
                        throw (new Exception("Commercial-AI not found."));
                    }

                    ai.m_ricoData         = buildingData;
                    ai.m_workplaceCount   = buildingData.workplaceCount;
                    ai.m_constructionCost = buildingData.constructionCost;

                    if (buildingData.subService == "eco")
                    {
                        // Apply eco specialisation if GC installed, otherwise use Level 1 low commercial.
                        if (Util.isGCinstalled())
                        {
                            // Eco commercial buildings only import food goods.
                            ai.m_incomingResource = TransferManager.TransferReason.Food;
                            InitializePrefab(prefab, ai, "Eco Commercial", buildingData.growable);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Low Commercial - Level1", buildingData.growable);
                        }
                    }
                    else if (buildingData.subService == "tourist")
                    {
                        // Apply tourist specialisation if AD installed, otherwise use Level 1 low commercial.
                        if (Util.isADinstalled())
                        {
                            InitializePrefab(prefab, ai, "Tourist Commercial - Land", buildingData.growable);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Low Commercial - Level1", buildingData.growable);
                        }
                    }
                    else if (buildingData.subService == "leisure")
                    {
                        // Apply leisure specialisation if AD installed, otherwise use Level 1 low commercial.
                        if (Util.isADinstalled())
                        {
                            InitializePrefab(prefab, ai, "Leisure Commercial", buildingData.growable);
                        }
                        else
                        {
                            InitializePrefab(prefab, ai, "Low Commercial - Level1", buildingData.growable);
                        }
                    }
                    else if (buildingData.subService == "high")
                    {
                        // Bog standard high commercial.
                        InitializePrefab(prefab, ai, "High Commercial - Level" + buildingData.level, buildingData.growable);
                    }
                    else
                    {
                        // Fall back to low commercial as default.
                        InitializePrefab(prefab, ai, "Low Commercial - Level" + buildingData.level, buildingData.growable);

                        // If invalid subservice, report.
                        if (buildingData.subService != "low")
                        {
                            Debugging.ErrorBuffer.AppendLine("Commercial building " + buildingData.name + " has invalid subService " + buildingData.subService + "; reverting to low commercial.");
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Updates the values in the RICO options panel to match the selected building (control visibility should already be set).
        /// </summary>
        /// <param name="buildingData">RICO building record</param>
        internal void UpdateValues(RICOBuilding building)
        {
            // Updates the values in the RICO options panel to match the selected building.

            // Workplaces.
            manual.text         = building.workplaceCount.ToString();
            uneducated.text     = building.workplaces[0].ToString();
            educated.text       = building.workplaces[1].ToString();
            welleducated.text   = building.workplaces[2].ToString();
            highlyeducated.text = building.workplaces[3].ToString();

            // Service and sub-service.
            switch (building.service)
            {
            case "residential":

                manual.text           = building.homeCount.ToString();
                service.selectedIndex = 1;

                if (currentSelection.subService == "high")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "low")
                {
                    subService.selectedIndex = 1;
                }
                else if (currentSelection.subService == "high eco")
                {
                    subService.selectedIndex = 2;
                }
                else if (currentSelection.subService == "low eco")
                {
                    subService.selectedIndex = 3;
                }

                break;

            case "industrial":

                service.selectedIndex = 2;
                subService.items      = IndustrialSub;

                if (currentSelection.subService == "generic")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "farming")
                {
                    subService.selectedIndex = 1;
                }
                else if (currentSelection.subService == "forest")
                {
                    subService.selectedIndex = 2;
                }
                else if (currentSelection.subService == "oil")
                {
                    subService.selectedIndex = 3;
                }
                else if (currentSelection.subService == "ore")
                {
                    subService.selectedIndex = 4;
                }

                break;

            case "office":

                service.selectedIndex = 3;
                subService.items      = OfficeSub;

                if (currentSelection.subService == "none")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "high tech")
                {
                    subService.selectedIndex = 1;
                }
                break;

            case "commercial":

                service.selectedIndex = 4;
                subService.items      = ComSub;

                if (currentSelection.subService == "high")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "low")
                {
                    subService.selectedIndex = 1;
                }
                else if (currentSelection.subService == "leisure")
                {
                    subService.selectedIndex = 2;
                }
                else if (currentSelection.subService == "tourist")
                {
                    subService.selectedIndex = 3;
                }
                else if (currentSelection.subService == "eco")
                {
                    subService.selectedIndex = 4;
                }
                break;

            case "extractor":

                service.selectedIndex = 5;
                subService.items      = ExtractorSub;

                if (currentSelection.subService == "farming")
                {
                    subService.selectedIndex = 0;
                }
                else if (currentSelection.subService == "forest")
                {
                    subService.selectedIndex = 1;
                }
                else if (currentSelection.subService == "oil")
                {
                    subService.selectedIndex = 2;
                }
                else if (currentSelection.subService == "ore")
                {
                    subService.selectedIndex = 3;
                }

                break;

            case "dummy":

                service.selectedIndex    = 6;
                subService.selectedIndex = 0;
                subService.items         = DummySub;

                break;

            default:

                service.selectedIndex    = 0;
                subService.selectedIndex = 0;
                subService.items         = DummySub;
                break;
            }

            // UI category.
            switch (building.uiCategory)
            {
            case "reslow":
                uiCategory.selectedIndex = 0;
                break;

            case "reshigh":
                uiCategory.selectedIndex = 1;
                break;

            case "comlow":
                uiCategory.selectedIndex = 2;
                break;

            case "comhigh":
                uiCategory.selectedIndex = 3;
                break;

            case "office":
                uiCategory.selectedIndex = 4;
                break;

            case "industrial":
                uiCategory.selectedIndex = 5;
                break;

            case "farming":
                uiCategory.selectedIndex = 6;
                break;

            case "forest":
                uiCategory.selectedIndex = 7;
                break;

            case "oil":
                uiCategory.selectedIndex = 8;
                break;

            case "ore":
                uiCategory.selectedIndex = 9;
                break;

            case "leisure":
                uiCategory.selectedIndex = 10;
                break;

            case "tourist":
                uiCategory.selectedIndex = 11;
                break;

            case "organic":
                uiCategory.selectedIndex = 12;
                break;

            case "hightech":
                uiCategory.selectedIndex = 13;
                break;

            case "selfsufficient":
                uiCategory.selectedIndex = 14;
                break;

            default:
                uiCategory.selectedIndex = 15;
                break;
            }

            // Building level.
            level.selectedIndex = (building.level - 1);

            // Construction cost.
            construction.text = building.constructionCost.ToString();

            // Use realistic population.
            realityIgnored.isChecked = !building.RealityIgnored;

            // Pollution enabled
            pollutionEnabled.isChecked = building.pollutionEnabled;

            // Growable.
            growable.isChecked = building.growable;

            // Enable RICO.
            ricoEnabled.isChecked = building.ricoEnabled;
        }
Esempio n. 19
0
        /// <summary>
        /// Updates the options panel when the building selection changes, including showing/hiding relevant controls.
        /// </summary>
        /// <param name="buildingData">RICO building data</param>
        internal void SelectionChanged(BuildingData buildingData)
        {
            // Disable the event logic while dropdowns are being updated.
            disableEvents = true;

            // Disable all input controls by default; activate them later if needed.
            ricoEnabled.Disable();
            growable.Disable();
            growable.parent.Hide();
            service.Disable();
            subService.Disable();
            level.Disable();
            uiCategory.Disable();
            construction.Disable();
            manual.Disable();
            realityIgnored.Disable();
            uneducated.Disable();
            educated.Disable();
            welleducated.Disable();
            highlyeducated.Disable();

            // Update option UI elements, in priority order (local, author, mod).
            if (buildingData.hasLocal)
            {
                currentSelection = buildingData.local;
                UpdateElements(buildingData.local.service);
                UpdateValues(buildingData.local);
                label.text = Translations.Translate("PRR_SET_HASLOC");

                // If the building has local settings, enable input fields.
                ricoEnabled.Enable();
                service.Enable();
                subService.Enable();
                level.Enable();
                uiCategory.Enable();
                construction.Enable();
                manual.Enable();
                realityIgnored.Enable();
                uneducated.Enable();
                educated.Enable();
                welleducated.Enable();
                highlyeducated.Enable();

                // 'Growable' can only be set in local settings.
                // Only show growable checkbox where assets meet the prequisites:
                // Growables can't have any dimension greater than 4 or contain any net structures.
                if (buildingData.prefab.GetWidth() <= 4 && buildingData.prefab.GetLength() <= 4 && !(buildingData.prefab.m_paths != null && buildingData.prefab.m_paths.Length != 0))
                {
                    growable.Enable();
                    growable.parent.Show();
                }
            }
            else if (buildingData.hasAuthor)
            {
                // If the building has author settings, then disable input fields.
                currentSelection = buildingData.author;
                UpdateElements(buildingData.author.service);
                UpdateValues(buildingData.author);
                label.text = Translations.Translate("PRR_SET_HASAUT");
            }
            else if (buildingData.hasMod)
            {
                // If the building has mod settings, then disable input fields.
                currentSelection = buildingData.mod;
                label.text       = Translations.Translate("PRR_SET_HASMOD");
                UpdateElements(buildingData.mod.service);
                UpdateValues(buildingData.mod);
            }
            else
            {
                // Fallback - building has no Ploppable RICO data anywhere, disable Ploppable RICO.
                ricoEnabled.isChecked = false;
                ricoEnabled.Disable();
                label.text = Translations.Translate("PRR_SET_HASNON");
            }

            // Re-enable event logic now that dropdowns are up-to-date before returning.
            disableEvents = false;
        }