示例#1
0
        public void CalculateLevels(Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
        {
            ItemClass itemClass = this.m_info.m_class;

            ItemClass.SubService subService = itemClass.m_subService;
            int[] workplaceDistribution     = { 0, 0, 0, 0, 0 };

            if (m_ricoData.workplaceDistribution != null)
            {
                workplaceDistribution = m_ricoData.workplaceDistribution;
            }
            else
            if (itemClass.m_level == ItemClass.Level.Level1)
            {
                workplaceDistribution = new int[] { 100, 0, 40, 50, 10 }
            }
            ;
            else if (itemClass.m_level == ItemClass.Level.Level2)
            {
                workplaceDistribution = new int[] { 100, 0, 20, 50, 30 }
            }
            ;
            else
            {
                workplaceDistribution = new int[] { 100, 0, 0, 40, 60 }
            };

            WorkplaceAIHelper.distributeWorkplaceLevels(r, workplaceDistribution, m_workplaceCount, out level0, out level1, out level2, out level3);
        }
        public static void CalculateWorkplaceCount(PloppableRICODefinition.Building 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);
            PloppableRICODefinition.Building rc = ricoData;

            if (rc == null)
            {
                WorkplaceAIHelper.SetWorkplaceLevels(out level0, out level1, out level2, out level3, 10, 20, 30, 40);
            }
            else
            // reality mod is running and the xml file says ignore-reality="false"
            if (rc.useReality)
            {
                ai.CalculateBaseLevels(r, width, length, out level0, out level1, out level2, out level3);
            }
            else
            {
                if (rc.workplaceCount > 0)
                {
                    ai.CalculateLevels(r, width, length, out level0, out level1, out level2, out level3);
                }
                if (rc.workplaceDetailsEnabled)
                {
                    // this adds to the results of the usual workplaces calculation
                    WorkplaceAIHelper.SetWorkplaceLevels(out level0, out level1, out level2, out level3, rc.uneducated + level0, rc.educated + level1, rc.wellEducated + level2, rc.highEducated + level3);
                }
                // Comment that out and uncomment the following to ignore "workplaces"
                // and just use the details setting
                // WorkplaceAIHelper.SetWorkplaceLevels(out level0, out level1, out level2, out level3, m_ricoData);
            }
        }
示例#3
0
 public override void CalculateWorkplaceCount(ItemClass.Level level, ColossalFramework.Math.Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
 {
     // See IndustrialAI.cs
     if (workplaceCount != null)
     {
         WorkplaceAIHelper.SetWorkplaceLevels(out level0, out level1, out level2, out level3, workplaceCount);
     }
     else
     {
         WorkplaceAIHelper.CalculateWorkplaceCount(level, m_ricoData, this, r, width, length, out level0, out level1, out level2, out level3);
         workplaceCount = new int[] { level0, level1, level2, level3 };
     }
 }
示例#4
0
 public override void CalculateWorkplaceCount(Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
 {
     // For some reason CalculateWorkplaceCount gets called every two seconds or so for every rico building currently plopped.
     // It's the bottleneck of the mod.
     // So we cache the calculation results, which might save a few cpu cycles.
     if (workplaceCount != null)
     {
         WorkplaceAIHelper.SetWorkplaceLevels(out level0, out level1, out level2, out level3, workplaceCount);
     }
     else
     {
         WorkplaceAIHelper.CalculateWorkplaceCount(m_ricoData, this, r, width, length, out level0, out level1, out level2, out level3);
         workplaceCount = new int[] { level0, level1, level2, level3 };
     }
 }
示例#5
0
        /// <summary>
        /// Updates workplace breakdowns to ratios applicable to current settings.
        /// </summary>
        private void UpdateWorkplaceBreakdowns()
        {
            int[] allocation = new int[4];
            int   totalJobs;


            // Ignore event if disabled flag is set.
            if (disableEvents)
            {
                return;
            }

            // If we catch an exception while parsing the manual textfield, it's probably because it's not ready yet (initial asset selection).
            // Simply return without doing anything.
            try
            {
                totalJobs = int.Parse(manual.text);
            }
            catch
            {
                return;
            }

            if (totalJobs > 0)
            {
                // Get current service and sub-service.
                GetService(out string serviceString, out string subServiceString);

                // Allocate out total workplaces ('manual').
                int[] distribution = Util.WorkplaceDistributionOf(serviceString, subServiceString, "Level" + (level.selectedIndex + 1));
                allocation = WorkplaceAIHelper.distributeWorkplaceLevels(int.Parse(manual.text), distribution, new int[] { 0, 0, 0, 0 });

                // Check and adjust for any rounding errors, assigning 'leftover' jobs to the lowest education level.
                allocation[0] += (int.Parse(manual.text) - allocation[0] - allocation[1] - allocation[2] - allocation[3]);
            }

            // Disable event handling while we update textfields.
            disableEvents = true;

            // Update workplace textfields.
            uneducated.text     = allocation[0].ToString();
            educated.text       = allocation[1].ToString();
            welleducated.text   = allocation[2].ToString();
            highlyeducated.text = allocation[3].ToString();

            // Resume event handling.
            disableEvents = false;
        }
示例#6
0
        /// <summary>
        /// Calculates the workplaces for this building according to RICO settings.
        /// </summary>
        /// <param name="level">Building level</param>
        /// <param name="r">Randomizer</param>
        /// <param name="width">Building plot width (in cells)</param>
        /// <param name="length">Building plot length (in cells)</param>
        /// <param name="level0">The number of uneducated jobs</param>
        /// <param name="level1">The number of educated jobs</param>
        /// <param name="level2">The number of well-educated jobs</param>
        /// <param name="level3">The number of highly-educated jobs</param>
        public override void CalculateWorkplaceCount(ItemClass.Level level, Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
        {
            // CalculateWorkplaceCount is called by the game every couple of seconds.  Why?  Who knows?
            // This makes it a potential performance bottleneck; thus, we cache results to save some CPU cycles.
            // Results are cached in workplaceCount.

            // Check to see if there's a cached value, and if so, use it.
            if (workplaceCount != null)
            {
                WorkplaceAIHelper.SetWorkplaceLevels(out level0, out level1, out level2, out level3, workplaceCount);
            }
            else
            {
                // If nothing is cached, then perform initial calculation.
                WorkplaceAIHelper.CalculateWorkplaceCount(level, m_ricoData, this, r, width, length, out level0, out level1, out level2, out level3);

                // Cache result.
                workplaceCount = new int[] { level0, level1, level2, level3 };
            }
        }
示例#7
0
 // In this house, jobs get done
 public override int GetConstructionCost()
 {
     return(WorkplaceAIHelper.GetConstructionCost(m_constructionCost, this.m_info.m_class.m_service, this.m_info.m_class.m_subService, this.m_info.m_class.m_level));
 }
示例#8
0
        /// <summary>
        /// Reads current settings from UI elements, and saves them to XML.
        /// </summary>
        internal void SaveRICO()
        {
            // Set service and subservice.
            GetService(out string serviceString, out string subServiceString);
            currentSelection.service    = serviceString;
            currentSelection.subService = subServiceString;

            // Set level.
            currentSelection.level = level.selectedIndex + 1;

            // Get home/total worker count, with default of zero.
            int manualCount = 0;

            int.TryParse(manual.text, out manualCount);
            currentSelection.homeCount = manualCount;

            // Get workplace breakdown.
            int[] a = new int[4] {
                0, 0, 0, 0
            };
            int.TryParse(uneducated.text, out a[0]);
            int.TryParse(educated.text, out a[1]);
            int.TryParse(welleducated.text, out a[2]);
            int.TryParse(highlyeducated.text, out a[3]);

            // If no breakdown has been provided, then we try the total jobs instead.
            // Yeah, it's a bit clunky to add the elements individually like this, but saves bringing in System.Linq for just this one case.
            if (a[0] + a[1] + a[2] + a[3] == 0)
            {
                // No workplace breakdown provided (all fields zero); use total workplaces ('manual', previously parsed as manualCount) and allocate.
                int[] d = Util.WorkplaceDistributionOf(currentSelection.service, currentSelection.subService, "Level" + currentSelection.level);
                a = WorkplaceAIHelper.distributeWorkplaceLevels(manualCount, d, new int[] { 0, 0, 0, 0 });

                // Check and adjust for any rounding errors, assigning 'leftover' jobs to the lowest education level.
                a[0] += (manualCount - a[0] - a[1] - a[2] - a[3]);
            }

            currentSelection.workplaces = a;

            currentSelection.constructionCost = int.Parse(construction.text);
            // Construction cost should be at least 10 to maintain compatibility with other mods (Real Time, Real Construction).
            if (currentSelection.constructionCost < 10)
            {
                currentSelection.constructionCost = 10;
                // If we've overridden the value (set it to 10), write that back to the construction cost text field so the user knows.
                construction.text = currentSelection.constructionCost.ToString();
            }

            // UI categories from menu.
            switch (uiCategory.selectedIndex)
            {
            case 0:
                currentSelection.uiCategory = "reslow";
                break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            default:
                currentSelection.uiCategory = "none";
                break;
            }

            // Remaining items.
            currentSelection.ricoEnabled      = ricoEnabled.isChecked;
            currentSelection.growable         = growable.isChecked;
            currentSelection.RealityIgnored   = !realityIgnored.isChecked;
            currentSelection.pollutionEnabled = pollutionEnabled.isChecked;
        }
示例#9
0
        public void CalculateLevels(Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3)
        {
            ItemClass itemClass = this.m_info.m_class;

            ItemClass.SubService subService = itemClass.m_subService;
            int[] workplaceDistribution     = { 100, 0, 0, 0, 0 };

            if (m_ricoData.workplaceDistribution != null)
            {
                workplaceDistribution = m_ricoData.workplaceDistribution;
            }
            else
            {
                switch (subService)
                {
                case ItemClass.SubService.CommercialLow:
                    if (itemClass.m_level == ItemClass.Level.Level1)
                    {
                        workplaceDistribution = new int[] { 100, 100, 0, 0, 0 }
                    }
                    ;
                    else if (itemClass.m_level == ItemClass.Level.Level2)
                    {
                        workplaceDistribution = new int[] { 100, 20, 60, 20, 0 }
                    }
                    ;
                    else
                    {
                        workplaceDistribution = new int[] { 100, 5, 15, 30, 50 }
                    };
                    break;

                case ItemClass.SubService.CommercialHigh:
                    if (itemClass.m_level == ItemClass.Level.Level1)
                    {
                        workplaceDistribution = new int[] { 100, 0, 40, 50, 10 }
                    }
                    ;
                    else if (itemClass.m_level == ItemClass.Level.Level2)
                    {
                        workplaceDistribution = new int[] { 100, 0, 20, 50, 30 }
                    }
                    ;
                    else
                    {
                        workplaceDistribution = new int[] { 100, 0, 0, 40, 60 }
                    };
                    break;

                case ItemClass.SubService.CommercialTourist:
                    workplaceDistribution = new int[] { 100, 20, 20, 30, 30 };
                    break;

                case ItemClass.SubService.CommercialLeisure:
                    workplaceDistribution = new int[] { 100, 30, 30, 20, 20 };
                    break;
                }
            }

            WorkplaceAIHelper.distributeWorkplaceLevels(r, workplaceDistribution, m_workplaceCount, out level0, out level1, out level2, out level3);
        }
示例#10
0
        public void SaveRICO()
        {
            //Reads current settings from UI elements, and saves them to the XMLData.


            if (service.selectedIndex == 0)
            {
                currentSelection.service = "none";
            }

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

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

                if (subService.selectedIndex == 0)
                {
                    currentSelection.subService = "none";
                }
                //else if (subService.selectedIndex == 1) currentSelection.subService = "high tech";
            }
            else if (service.selectedIndex == 4)
            {
                currentSelection.service = "commercial";
                if (subService.selectedIndex == 0)
                {
                    currentSelection.subService = "high";
                }
                else if (subService.selectedIndex == 1)
                {
                    currentSelection.subService = "low";
                }
                else if (subService.selectedIndex == 2)
                {
                    currentSelection.subService = "tourist";
                }
                else if (subService.selectedIndex == 3)
                {
                    currentSelection.subService = "leisure";
                }
                //else if (subService.selectedIndex == 4) currentSelection.subService = "eco";
            }
            else if (service.selectedIndex == 5)
            {
                currentSelection.service = "extractor";
                if (subService.selectedIndex == 0)
                {
                    currentSelection.subService = "forest";
                }
                else if (subService.selectedIndex == 1)
                {
                    currentSelection.subService = "oil";
                }
                else if (subService.selectedIndex == 2)
                {
                    currentSelection.subService = "ore";
                }
                else if (subService.selectedIndex == 3)
                {
                    currentSelection.subService = "farming";
                }
            }
            else if (service.selectedIndex == 6)
            {
                currentSelection.service    = "dummy";
                currentSelection.subService = "none";
            }

            var d = Util.WorkplaceDistributionOf(currentSelection.service, currentSelection.subService, "Level" + currentSelection.level);
            var a = WorkplaceAIHelper.distributeWorkplaceLevels(int.Parse(manual.text), d, new int[] { 0, 0, 0, 0 });

            currentSelection.workplaces = a;

            currentSelection.constructionCost = int.Parse(construction.text);

            currentSelection.homeCount = int.Parse(manual.text);


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

            currentSelection.level             = level.selectedIndex + 1;
            currentSelection.ricoEnabled       = ricoEnabled.isChecked;
            currentSelection.popbalanceEnabled = !popBalanceEnabled.isChecked;
        }
示例#11
0
 /// <summary>
 /// Calculates the workplaces for this building according to RICO settings.
 /// </summary>
 /// <param name="level">Building level</param>
 /// <param name="r">Randomizer</param>
 /// <param name="width">Building plot width (in cells)</param>
 /// <param name="length">Building plot length (in cells)</param>
 /// <param name="level0">The number of uneducated jobs</param>
 /// <param name="level1">The number of educated jobs</param>
 /// <param name="level2">The number of well-educated jobs</param>
 /// <param name="level3">The number of highly-educated jobs</param>
 public override void CalculateWorkplaceCount(ItemClass.Level level, Randomizer r, int width, int length, out int level0, out int level1, out int level2, out int level3) => WorkplaceAIHelper.CalculateWorkplaceCount(level, m_ricoData, this, r, width, length, out level0, out level1, out level2, out level3);