public static void CalculateBuildingMoneyAndSalary(Building building, ushort buildingID)
        {
            if (BuildingData.buildingMoney[buildingID] > MainDataStore.maxBuildingMoneyLimit)
            {
                BuildingData.buildingMoney[buildingID] = MainDataStore.maxBuildingMoneyLimit;
            }
            else if (BuildingData.buildingMoney[buildingID] < -MainDataStore.maxBuildingMoneyLimit)
            {
                BuildingData.buildingMoney[buildingID] = -MainDataStore.maxBuildingMoneyLimit;
            }


            if (building.Info.m_class.m_service == ItemClass.Service.Industrial || building.Info.m_class.m_service == ItemClass.Service.Commercial || building.Info.m_class.m_service == ItemClass.Service.Office)
            {
                Citizen.BehaviourData behaviourData = default;
                int aliveWorkerCount = 0;
                int totalWorkerCount = 0;
                RealCityCommonBuildingAI.InitDelegate();
                RealCityCommonBuildingAI.GetWorkBehaviour((CommonBuildingAI)building.Info.m_buildingAI, buildingID, ref building, ref behaviourData, ref aliveWorkerCount, ref totalWorkerCount);
                float bossTake       = 0;
                float investToOffice = 0;
                float profitShare    = 0;

                switch (building.Info.m_class.m_subService)
                {
                case ItemClass.SubService.OfficeGeneric:
                case ItemClass.SubService.OfficeHightech:
                    profitShare = 1f; break;

                case ItemClass.SubService.IndustrialFarming:
                case ItemClass.SubService.IndustrialForestry:
                    if (building.Info.m_buildingAI is IndustrialExtractorAI)
                    {
                        bossTake       = MainDataStore.bossRatioInduExtractor;
                        investToOffice = MainDataStore.investRatioInduExtractor;
                        profitShare    = MainDataStore.profitShareRatioInduExtractor;
                    }
                    else
                    {
                        bossTake       = MainDataStore.bossRatioInduOther;
                        investToOffice = MainDataStore.investRatioInduOther;
                        profitShare    = MainDataStore.profitShareRatioInduOther;
                    }
                    break;

                case ItemClass.SubService.IndustrialOil:
                case ItemClass.SubService.IndustrialOre:
                    bossTake       = MainDataStore.bossRatioInduOther;
                    investToOffice = MainDataStore.investRatioInduOther;
                    profitShare    = MainDataStore.profitShareRatioInduOther; break;

                case ItemClass.SubService.IndustrialGeneric:
                    if (building.Info.m_class.m_level == ItemClass.Level.Level1)
                    {
                        bossTake       = MainDataStore.bossRatioInduLevel1;
                        investToOffice = MainDataStore.investRatioInduLevel1;
                        profitShare    = MainDataStore.profitShareRatioInduLevel1;
                    }
                    else if (building.Info.m_class.m_level == ItemClass.Level.Level2)
                    {
                        bossTake       = MainDataStore.bossRatioInduLevel2;
                        investToOffice = MainDataStore.investRatioInduLevel2;
                        profitShare    = MainDataStore.profitShareRatioInduLevel2;
                    }
                    else
                    {
                        bossTake       = MainDataStore.bossRatioInduLevel3;
                        investToOffice = MainDataStore.investRatioInduLevel3;
                        profitShare    = MainDataStore.profitShareRatioInduLevel3;
                    }
                    break;

                case ItemClass.SubService.CommercialHigh:
                case ItemClass.SubService.CommercialLow:
                    if (building.Info.m_class.m_level == ItemClass.Level.Level1)
                    {
                        bossTake       = MainDataStore.bossRatioCommLevel1;
                        investToOffice = MainDataStore.investRatioCommLevel1;
                        profitShare    = MainDataStore.profitShareRatioCommLevel1;
                    }
                    else if (building.Info.m_class.m_level == ItemClass.Level.Level2)
                    {
                        bossTake       = MainDataStore.bossRatioCommLevel2;
                        investToOffice = MainDataStore.investRatioCommLevel2;
                        profitShare    = MainDataStore.profitShareRatioCommLevel2;
                    }
                    else
                    {
                        bossTake       = MainDataStore.bossRatioCommLevel3;
                        investToOffice = MainDataStore.investRatioCommLevel3;
                        profitShare    = MainDataStore.profitShareRatioCommLevel1;
                    }
                    break;

                case ItemClass.SubService.CommercialTourist:
                    bossTake       = MainDataStore.bossRatioCommTou;
                    investToOffice = MainDataStore.investRatioCommTou;
                    profitShare    = MainDataStore.profitShareRatioCommTou;
                    break;

                case ItemClass.SubService.CommercialLeisure:
                    bossTake       = MainDataStore.bossRatioCommOther;
                    investToOffice = MainDataStore.investRatioCommOther;
                    profitShare    = MainDataStore.profitShareRatioCommOther; break;

                case ItemClass.SubService.CommercialEco:
                    bossTake       = MainDataStore.bossRatioCommECO;
                    investToOffice = MainDataStore.investRatioCommECO;
                    profitShare    = MainDataStore.profitShareRatioCommECO; break;
                }
                // boss take and return to office
                if (BuildingData.buildingMoney[buildingID] > 0)
                {
                    //Reduce Boss fee
                    long investToOfficeFee = (long)(BuildingData.buildingMoney[buildingID] * investToOffice);
                    long bossTakeFee       = (long)(BuildingData.buildingMoney[buildingID] * bossTake);
                    if (building.Info.m_class.m_service == ItemClass.Service.Commercial)
                    {
                        //Commercial have help tourism
                        MainDataStore.outsideTouristMoney += ((bossTakeFee - investToOfficeFee) * MainDataStore.outsideCompanyProfitRatio * MainDataStore.outsideTouristSalaryProfitRatio);
                    }
                    RealCityPrivateBuildingAI.profitBuildingMoney += investToOfficeFee;
                    BuildingData.buildingMoney[buildingID]        -= bossTakeFee;
                }

                if (building.Info.m_class.m_service == ItemClass.Service.Office)
                {
                    float allOfficeWorker     = RealCityPrivateBuildingAI.allOfficeLevel1WorkCountFinal + RealCityPrivateBuildingAI.allOfficeLevel2WorkCountFinal + RealCityPrivateBuildingAI.allOfficeLevel3WorkCountFinal + RealCityPrivateBuildingAI.allOfficeHighTechWorkCountFinal;
                    float averageOfficeSalary = 0;
                    if (allOfficeWorker != 0)
                    {
                        averageOfficeSalary = (RealCityPrivateBuildingAI.profitBuildingMoneyFinal / allOfficeWorker);
                    }

                    if (building.Info.m_class.m_subService == ItemClass.SubService.OfficeGeneric)
                    {
                        if (building.Info.m_class.m_level == ItemClass.Level.Level1)
                        {
                            BuildingData.buildingMoney[buildingID] = averageOfficeSalary * totalWorkerCount * 0.6f;
                        }
                        else if (building.Info.m_class.m_level == ItemClass.Level.Level2)
                        {
                            BuildingData.buildingMoney[buildingID] = averageOfficeSalary * totalWorkerCount * 0.8f;
                        }
                        else if (building.Info.m_class.m_level == ItemClass.Level.Level3)
                        {
                            BuildingData.buildingMoney[buildingID] = averageOfficeSalary * totalWorkerCount * 1f;
                        }
                    }
                    else if (building.Info.m_class.m_subService == ItemClass.SubService.OfficeHightech)
                    {
                        BuildingData.buildingMoney[buildingID] = averageOfficeSalary * totalWorkerCount * 0.75f;
                    }

                    ProcessLandFeeOffice(building, buildingID, totalWorkerCount);
                }

                //Calculate building salary
                int buildingAsset = (int)(BuildingData.buildingMoney[buildingID] + building.m_customBuffer1 * RealCityIndustryBuildingAI.GetResourcePrice(RealCityPrivateBuildingAI.GetIncomingProductionType(buildingID, building)));
                int salary        = 0;
                if ((buildingAsset > 0) && (totalWorkerCount != 0))
                {
                    salary = (int)(buildingAsset * profitShare / totalWorkerCount);
                    switch (building.Info.m_class.m_subService)
                    {
                    case ItemClass.SubService.IndustrialFarming:
                    case ItemClass.SubService.IndustrialForestry:
                    case ItemClass.SubService.IndustrialOil:
                    case ItemClass.SubService.IndustrialOre:
                        salary = Math.Min(salary, MainDataStore.salaryInduOtherMax); break;

                    case ItemClass.SubService.IndustrialGeneric:
                        if (building.Info.m_class.m_level == ItemClass.Level.Level1)
                        {
                            salary = Math.Min(salary, MainDataStore.salaryInduLevel1Max);
                        }
                        else if (building.Info.m_class.m_level == ItemClass.Level.Level2)
                        {
                            salary = Math.Min(salary, MainDataStore.salaryInduLevel2Max);
                        }
                        else
                        {
                            salary = Math.Min(salary, MainDataStore.salaryInduLevel3Max);
                        }
                        break;

                    case ItemClass.SubService.CommercialHigh:
                    case ItemClass.SubService.CommercialLow:
                        if (building.Info.m_class.m_level == ItemClass.Level.Level1)
                        {
                            salary = Math.Min(salary, MainDataStore.salaryCommLevel1Max);
                        }
                        else if (building.Info.m_class.m_level == ItemClass.Level.Level2)
                        {
                            salary = Math.Min(salary, MainDataStore.salaryCommLevel2Max);
                        }
                        else
                        {
                            salary = Math.Min(salary, MainDataStore.salaryCommLevel3Max);
                        }
                        break;

                    case ItemClass.SubService.CommercialTourist:
                        salary = Math.Min(salary, MainDataStore.salaryCommTouMax); break;

                    case ItemClass.SubService.CommercialLeisure:
                        salary = Math.Min(salary, MainDataStore.salaryCommOtherMax); break;

                    case ItemClass.SubService.CommercialEco:
                        salary = Math.Min(salary, MainDataStore.salaryCommECOMax); break;
                    }
                }

                if (salary > 0)
                {
                    BuildingData.buildingWorkCount[buildingID] = salary;
                }
                else
                {
                    BuildingData.buildingWorkCount[buildingID] = 0;
                }
            }
            else
            {
                //resident building
                ItemClass                 @class             = building.Info.m_class;
                int                       incomeAccumulation = 0;
                DistrictManager           instance           = Singleton <DistrictManager> .instance;
                byte                      district           = instance.GetDistrict(building.m_position);
                DistrictPolicies.Taxation taxationPolicies   = instance.m_districts.m_buffer[district].m_taxationPolicies;
                if (@class.m_subService == ItemClass.SubService.ResidentialLow)
                {
                    switch (@class.m_level)
                    {
                    case ItemClass.Level.Level1:
                        incomeAccumulation = MainDataStore.residentLowLevel1Rent;
                        break;

                    case ItemClass.Level.Level2:
                        incomeAccumulation = MainDataStore.residentLowLevel2Rent;
                        break;

                    case ItemClass.Level.Level3:
                        incomeAccumulation = MainDataStore.residentLowLevel3Rent;
                        break;

                    case ItemClass.Level.Level4:
                        incomeAccumulation = MainDataStore.residentLowLevel4Rent;
                        break;

                    case ItemClass.Level.Level5:
                        incomeAccumulation = MainDataStore.residentLowLevel5Rent;
                        break;
                    }
                }
                else if (@class.m_subService == ItemClass.SubService.ResidentialLowEco)
                {
                    switch (@class.m_level)
                    {
                    case ItemClass.Level.Level1:
                        incomeAccumulation = MainDataStore.residentLowLevel1Rent;
                        break;

                    case ItemClass.Level.Level2:
                        incomeAccumulation = MainDataStore.residentLowLevel2Rent;
                        break;

                    case ItemClass.Level.Level3:
                        incomeAccumulation = MainDataStore.residentLowLevel3Rent;
                        break;

                    case ItemClass.Level.Level4:
                        incomeAccumulation = MainDataStore.residentLowLevel4Rent;
                        break;

                    case ItemClass.Level.Level5:
                        incomeAccumulation = MainDataStore.residentLowLevel5Rent;
                        break;
                    }
                }
                else if (@class.m_subService == ItemClass.SubService.ResidentialHigh)
                {
                    switch (@class.m_level)
                    {
                    case ItemClass.Level.Level1:
                        incomeAccumulation = MainDataStore.residentHighLevel1Rent;
                        break;

                    case ItemClass.Level.Level2:
                        incomeAccumulation = MainDataStore.residentHighLevel2Rent;
                        break;

                    case ItemClass.Level.Level3:
                        incomeAccumulation = MainDataStore.residentHighLevel3Rent;
                        break;

                    case ItemClass.Level.Level4:
                        incomeAccumulation = MainDataStore.residentHighLevel4Rent;
                        break;

                    case ItemClass.Level.Level5:
                        incomeAccumulation = MainDataStore.residentHighLevel5Rent;
                        break;
                    }
                }
                else
                {
                    switch (@class.m_level)
                    {
                    case ItemClass.Level.Level1:
                        incomeAccumulation = MainDataStore.residentHighLevel1Rent;
                        break;

                    case ItemClass.Level.Level2:
                        incomeAccumulation = MainDataStore.residentHighLevel2Rent;
                        break;

                    case ItemClass.Level.Level3:
                        incomeAccumulation = MainDataStore.residentHighLevel3Rent;
                        break;

                    case ItemClass.Level.Level4:
                        incomeAccumulation = MainDataStore.residentHighLevel4Rent;
                        break;

                    case ItemClass.Level.Level5:
                        incomeAccumulation = MainDataStore.residentHighLevel5Rent;
                        break;
                    }
                }
                int num2;
                num2 = Singleton <EconomyManager> .instance.GetTaxRate(@class, taxationPolicies);

                incomeAccumulation = (int)((num2 * incomeAccumulation) / 100f);
                BuildingData.buildingWorkCount[buildingID] = incomeAccumulation;
            }
        }
Exemplo n.º 2
0
        private void RefreshDisplayData()
        {
            if (refeshOnce || (BuildingData.lastBuildingID != WorldInfoPanel.GetCurrentInstanceID().Building))
            {
                if (isVisible)
                {
                    BuildingData.lastBuildingID = WorldInfoPanel.GetCurrentInstanceID().Building;
                    Building buildingData = Singleton <BuildingManager> .instance.m_buildings.m_buffer[BuildingData.lastBuildingID];
                    if (buildingData.Info.m_class.m_service == ItemClass.Service.Residential)
                    {
                        Hide();
                    }
                    else
                    {
                        float  averageEmployeeFee = CaculateEmployeeOutcome(buildingData, out int totalWorkerCount);
                        int    landRentFee        = CaculateLandFee(buildingData, BuildingData.lastBuildingID);
                        string incomeType         = RealCityPrivateBuildingAI.GetProductionType(false, BuildingData.lastBuildingID, buildingData);
                        string outgoingType       = RealCityPrivateBuildingAI.GetProductionType(true, BuildingData.lastBuildingID, buildingData);
                        float  incomePrice        = RealCityPrivateBuildingAI.GetPrice(false, BuildingData.lastBuildingID, buildingData);
                        float  outgoingPrice      = RealCityPrivateBuildingAI.GetPrice(true, BuildingData.lastBuildingID, buildingData);
                        buildingMoney.text          = string.Format(Localization.Get("BUILDING_MONEY") + " [{0}]", BuildingData.buildingMoney[BuildingData.lastBuildingID]);
                        buildingNetAsset.text       = string.Format(Localization.Get("BUILDING_NETASSET") + " [{0}]", (BuildingData.buildingMoney[BuildingData.lastBuildingID] + buildingData.m_customBuffer1 * RealCityIndustryBuildingAI.GetResourcePrice(RealCityPrivateBuildingAI.GetIncomingProductionType(BuildingData.lastBuildingID, buildingData))));
                        buildingIncomeBuffer.text   = string.Format(Localization.Get("MATERIAL_BUFFER") + " [{0}]" + " " + incomeType, buildingData.m_customBuffer1);
                        buildingOutgoingBuffer.text = string.Format(Localization.Get("PRODUCTION_BUFFER") + " [{0}]" + " " + outgoingType, buildingData.m_customBuffer2);
                        employFee.text = Localization.Get("AVERAGE_EMPLOYFEE") + " " + averageEmployeeFee.ToString() + " " + Localization.Get("PROFIT_SHARING");
                        landRent.text  = string.Format(Localization.Get("BUILDING_LANDRENT") + " [{0:N2}]", landRentFee);
                        buyPrice.text  = string.Format(Localization.Get("BUY_PRICE") + " " + incomeType + "[{0:N2}]", incomePrice);
                        sellPrice.text = string.Format(Localization.Get("SELL_PRICE") + " " + outgoingType + " [{0:N2}]", outgoingPrice);

                        float consumptionDivider = 0f;
                        if (buildingData.Info.m_class.m_subService == ItemClass.SubService.IndustrialGeneric)
                        {
                            consumptionDivider    = RealCityPrivateBuildingAI.GetComsumptionDivider(buildingData, BuildingData.lastBuildingID) * 4f;
                            comsuptionDivide.text = string.Format(Localization.Get("MATERIAL_DIV_PRODUCTION") + " [1:{0:N2}]", consumptionDivider);
                        }
                        else
                        {
                            if ((buildingData.Info.m_buildingAI is IndustrialExtractorAI) || buildingData.Info.m_class.m_service == ItemClass.Service.Office)
                            {
                                comsuptionDivide.text = string.Format(Localization.Get("MATERIAL_DIV_PRODUCTION") + " N/A");
                            }
                            else
                            {
                                consumptionDivider    = RealCityPrivateBuildingAI.GetComsumptionDivider(buildingData, BuildingData.lastBuildingID);
                                comsuptionDivide.text = string.Format(Localization.Get("MATERIAL_DIV_PRODUCTION") + " [1:{0:N2}]", consumptionDivider);
                            }
                        }

                        int m_sellTax = RealCityPrivateBuildingAI.GetTaxRate(buildingData);
                        sellTax.text = string.Format(Localization.Get("SELL_TAX") + " [{0}%]", m_sellTax);

                        if (consumptionDivider == 0f)
                        {
                            profit.text = string.Format(Localization.Get("PROFIT") + " N/A");
                        }
                        else
                        {
                            float profitRatio = (outgoingPrice * (1f - m_sellTax / 100f) - (incomePrice / consumptionDivider)) / outgoingPrice;
                            if (buildingData.Info.m_class.m_service == ItemClass.Service.Commercial)
                            {
                                profit.text = string.Format(Localization.Get("PROFIT") + " [{0}%]" + Localization.Get("EXCLUDE_VISIT_INCOME"), (int)(profitRatio * 100f));
                            }
                            else
                            {
                                profit.text = string.Format(Localization.Get("PROFIT") + " [{0}%]", (int)(profitRatio * 100f));
                            }
                        }

                        int usedCar = 0;
                        int num     = 0;
                        int num1    = 0;
                        int num2    = 0;
                        int car     = 0;
                        if (buildingData.Info.m_class.m_service == ItemClass.Service.Industrial)
                        {
                            TransferManager.TransferReason tempReason = default(TransferManager.TransferReason);
                            if (buildingData.Info.m_buildingAI is IndustrialExtractorAI)
                            {
                                RealCityIndustrialExtractorAI.InitDelegate();
                                var industrialExtractorAI = (IndustrialExtractorAI)buildingData.Info.m_buildingAI;
                                int productionCapacity    = industrialExtractorAI.CalculateProductionCapacity((ItemClass.Level)buildingData.m_level, new Randomizer(BuildingData.lastBuildingID), buildingData.m_width, buildingData.m_length);
                                car        = Mathf.Max(1, productionCapacity / 6);
                                tempReason = RealCityIndustrialExtractorAI.GetOutgoingTransferReason((IndustrialExtractorAI)buildingData.Info.m_buildingAI);
                                RealCityCommonBuildingAI.InitDelegate();
                                RealCityCommonBuildingAI.CalculateOwnVehicles((IndustrialExtractorAI)buildingData.Info.m_buildingAI, BuildingData.lastBuildingID, ref buildingData, tempReason, ref usedCar, ref num, ref num1, ref num2);
                            }
                            else
                            {
                                RealCityIndustrialBuildingAI.InitDelegate();
                                var industrialBuildingAI = (IndustrialBuildingAI)buildingData.Info.m_buildingAI;
                                int productionCapacity   = industrialBuildingAI.CalculateProductionCapacity((ItemClass.Level)buildingData.m_level, new Randomizer(BuildingData.lastBuildingID), buildingData.m_width, buildingData.m_length);
                                car        = Mathf.Max(1, productionCapacity / 6);
                                tempReason = RealCityIndustrialBuildingAI.GetOutgoingTransferReason((IndustrialBuildingAI)buildingData.Info.m_buildingAI);
                                RealCityCommonBuildingAI.InitDelegate();
                                RealCityCommonBuildingAI.CalculateOwnVehicles((IndustrialBuildingAI)buildingData.Info.m_buildingAI, BuildingData.lastBuildingID, ref buildingData, tempReason, ref usedCar, ref num, ref num1, ref num2);
                            }

                            usedcar.text = string.Format(Localization.Get("CAR_USED") + " [{0}/{1}]", usedCar, car);
                        }
                        else if (buildingData.Info.m_class.m_service == ItemClass.Service.Commercial)
                        {
                            Citizen.BehaviourData behaviour = default;
                            int aliveVisitCount             = 0;
                            int totalVisitCount             = 0;
                            RealCityCommercialBuildingAI.InitDelegate();
                            RealCityCommercialBuildingAI.GetVisitBehaviour((CommercialBuildingAI)(buildingData.Info.m_buildingAI), BuildingData.lastBuildingID, ref buildingData, ref behaviour, ref aliveVisitCount, ref totalVisitCount);
                            var amount = buildingData.m_customBuffer2 / MainDataStore.maxGoodPurchase - totalVisitCount + aliveVisitCount;
                            var commercialBuildingAI = buildingData.Info.m_buildingAI as CommercialBuildingAI;
                            var maxCount             = commercialBuildingAI.CalculateVisitplaceCount((ItemClass.Level)buildingData.m_level, new Randomizer(BuildingData.lastBuildingID), buildingData.m_width, buildingData.m_length);
                            usedcar.text = string.Format("FORDEBUG" + " [{0}/{1}/{2}/{3}]", aliveVisitCount, totalVisitCount, maxCount, amount);
                        }
                        else
                        {
                            usedcar.text = Localization.Get("CAR_USED") + " 0/0";
                        }

                        BringToFront();
                        refeshOnce = false;
                    }
                }
            }
        }