コード例 #1
0
        public List <ResilientBuildings.ResilientInfoV1> convertVersionZeroListToOne(List <ResilientBuildings.ResilientInfo> list)
        {
            CODebug.Log(LogChannel.Modding, Mod.modName + " - Converting save data from version 0 to 1");
            List <ResilientBuildings.ResilientInfoV1> newList = new List <ResilientBuildings.ResilientInfoV1>();

            for (int i = 0; i < list.Count; i++)
            {
                ResilientBuildings.ResilientInfo   ri0 = list[i];
                ResilientBuildings.ResilientInfoV1 ri1 = new ResilientBuildings.ResilientInfoV1();
                ri1.activatedDate       = ri0.activatedDate;
                ri1.buildingID          = ri0.buildingID;
                ri1.chosenLevel         = ri0.chosenLevel;
                ri1.currentVisits       = ri0.currentVisits;
                ri1.description         = ri0.description;
                ri1.goodsBuffer1        = ri0.goodsBuffer1;
                ri1.goodsBuffer2        = ri0.goodsBuffer2;
                ri1.goodsBuffer3        = ri0.goodsBuffer3;
                ri1.goodsBuffer4        = ri0.goodsBuffer4;
                ri1.resiliencyActivated = ri0.resiliencyActivated;
                ri1.totalIncome         = ri0.totalIncome;
                ri1.totalVisits         = ri0.totalVisits;
                ri1.unsuscribed         = ri0.unsuscribed;
                ri1.unsuscribeTimer     = ri0.unsuscribeTimer;
                ri1.namesBuffer         = new List <string>();
                newList.Add(ri1);
            }
            return(newList);
        }
コード例 #2
0
        void SaveDescription(string desc)
        {
            if (!m_allowEvents)
            {
                return;
            }
            int buildIndex = m_info.GetResilientBuildingIndex(m_currentSelectedBuildingID);

            if (buildIndex != -1)
            {
                ResilientBuildings.ResilientInfoV1 ri = m_info.m_resilients [buildIndex];
                ri.description = desc;
                m_info.m_resilients [buildIndex] = ri;
            }
        }
コード例 #3
0
        public override int OnAddResource(EconomyResource resource, int amount, Service service, SubService subService, Level level)
        {
            if (!LoadingExtension.installed)
            {
                return(amount);
            }

            //check if OnAddResource call match what we are looking for
            if (!resource.Equals(EconomyResource.PrivateIncome)) //interested in private incomes only
            {
                return(amount);
            }

            if (service != Service.Office)            //only office buildings tracked here
            {
                return(amount);
            }

            //CODebug.Log(LogChannel.Modding, Mod.modName + " - IncomeTracker search building with service " + service + " subservice " + subService + " level " + level + " amount "+amount);

            SimulationManager instance  = Singleton <SimulationManager> .instance;
            BuildingManager   instance2 = Singleton <BuildingManager> .instance;

            //sync with simulation frame
            if (checkedFrameIndex != instance.m_currentFrameIndex)
            {
                checkedFrameIndex = instance.m_currentFrameIndex;
                int num6 = (int)(instance.m_currentFrameIndex & 255u);
                buildingID    = (ushort)(num6 * 192);
                maxBuildingID = (ushort)((num6 + 1) * 192 - 1);
            }

            //sync with BuildingManager SimulationStep loop
            bool skipping = true;
            bool error    = false;

            do
            {
                if ((instance2.m_buildings.m_buffer[buildingID].m_flags & Building.Flags.Created) == Building.Flags.None)
                {
                    skipping = true;
                }
                //abandoned buildings do no go through SimulationStepActive
                else if ((instance2.m_buildings.m_buffer[buildingID].m_flags & (Building.Flags.Abandoned | Building.Flags.BurnedDown)) != Building.Flags.None)
                {
                    skipping = true;
                }
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Residential)
//					{
//						skipping = false;
//						if(service != Service.Residential)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Industrial)
//					{
//						skipping = false;
//						if(service != Service.Industrial)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Commercial)
//					{
//						skipping = false;
//						if(service != Service.Commercial)
//							error = true;
//					}
                else if (instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Office)
                {
                    skipping = false;
                }
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Beautification)
//					{
//						skipping = false;
//						if(service != Service.Beautification)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Citizen)
//					{
//						skipping = false;
//						if(service != Service.Citizen)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Education)
//					{
//						skipping = false;
//						if(service != Service.Education)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Electricity)
//					{
//						skipping = false;
//						if(service != Service.Electricity)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.FireDepartment)
//					{
//						skipping = false;
//						if(service != Service.FireDepartment)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Garbage)
//					{
//						skipping = false;
//						if(service != Service.Garbage)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Government)
//					{
//						skipping = false;
////						if(service != Service.Governement)
////							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.HealthCare)
//					{
//						skipping = false;
//						if(service != Service.HealthCare)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Monument)
//					{
//						skipping = false;
//						if(service != Service.Monument)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.PoliceDepartment)
//					{
//						skipping = false;
//						if(service != Service.PoliceDepartment)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.PublicTransport)
//					{
//						skipping = false;
//						if(service != Service.PublicTransport)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Road)
//					{
//						skipping = false;
//						if(service != Service.Road)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Water)
//					{
//						skipping = false;
//						if(service != Service.Water)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Unused1)
//					{
//						skipping = false;
////						if(service != Service.)
////							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Unused2)
//					{
//						skipping = false;
////						if(service != Service.Education)
////							error = true;
//					}
//					else
//					{
////						CODebug.Log(LogChannel.Modding, "income tracker private income for service "+instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service);
////						skipping = true;
//						skipping = false;
//						if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service.ToString() != service.ToString())
//						{
//							CODebug.Log(LogChannel.Modding, "income tracker mismatch "+instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service.ToString()+" "+service.ToString());
//						}
//					}

                if (skipping)
                {
                    buildingID++;
                    if (buildingID > maxBuildingID)
                    {
                        error    = true;
                        skipping = false;
                    }
                }
            }while(skipping);


            //check if active and history is activated
            if (!error)
            {
                if (instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Office)
                {
                    int    buildIndex = s_info.GetResilientBuildingIndex((ushort)buildingID);
                    String buildinfo2 = Singleton <BuildingManager> .instance.GetBuildingName(buildingID, default(InstanceID));

                    //CODebug.Log(LogChannel.Modding, Mod.modName + " - IncomeTracker found building with id " + buildingID + " buildIndex " + buildIndex + " " + buildinfo2);
                    if (buildIndex != -1)
                    {
                        ResilientBuildings.ResilientInfoV1 ri = s_info.m_resilients[buildIndex];
                        ri.totalIncome += amount;
                        s_info.m_resilients[buildIndex] = ri;
                    }
                }
                buildingID++; //ensure search starts from next building at next function call
            }
            else
            {
                CODebug.Log(LogChannel.Modding, Mod.modName + " - IncomeTracker could not meet building with service " + service + " subservice " + subService + " level " + level);
            }

            return(amount);
        }
コード例 #4
0
        public override void OnAfterSimulationFrame()
        {
            if (!LoadingExtension.installed)
            {
                return;
            }

            if (s_info == null)
            {
                return;
            }

            BuildingManager instance = Singleton <BuildingManager> .instance;

            int    num6          = (int)(Singleton <SimulationManager> .instance.m_currentFrameIndex & 255u);
            ushort minBuildingID = (ushort)(num6 * 192);
            ushort maxBuildingID = (ushort)((num6 + 1) * 192 - 1);

            //check if building should be added as part of a resilient district
            DistrictManager instance2 = Singleton <DistrictManager> .instance;

            for (ushort i = minBuildingID; i < maxBuildingID; i++)
            {
                if (instance.m_buildings.m_buffer[i].m_flags == Building.Flags.None)
                {
                    continue;
                }
                Building build         = instance.m_buildings.m_buffer[i];
                byte     districtID    = instance2.GetDistrict(build.m_position);
                int      districtIndex = s_info.GetResilientDistrictIndex(districtID);
                if (districtIndex != -1)
                {
                    if (s_info.m_districts[districtIndex].unsuscribed)
                    {
                        //s_info.RemoveBuilding(i);
                        s_info.UnsuscribeBuilding(i);
                    }
                    else if (s_info.m_districts[districtIndex].resiliencyActivated)
                    {
                        bool newly_added = s_info.AddBuilding(i, true);
                        if (newly_added)
                        {
                            ResilientBuildings.ResilientDistrict rd = s_info.m_districts[districtIndex];
                            rd.totalBuildings++;
                            s_info.m_districts[districtIndex] = rd;
                        }
                    }
                }
            }

            //districts timers
            for (int i = 0; i < s_info.m_districts.Count; i++)
            {
                if (s_info.m_districts[i].unsuscribed)
                {
                    ResilientBuildings.ResilientDistrict rd = s_info.m_districts[i];
                    rd.unsuscribeTimer++;
                    s_info.m_districts[i] = rd;
                    if (rd.unsuscribeTimer > REMOVE_DISTRICT_AFTER_UPDATES)
                    {
                        s_info.RemoveDistrict(rd.districtID);
                    }
                }
            }


            //check all buildings in resilients list
            for (int i = 0; i < s_info.m_resilients.Count; i++)
            {
                ushort buildingID = s_info.m_resilients[i].buildingID;

                //sync with buildManager, update only buildings that just had a SimulationStep
                if (buildingID < minBuildingID || buildingID >= maxBuildingID)
                {
                    continue;
                }

                ResilientBuildings.ResilientInfoV1 build = s_info.m_resilients[i];

                if (s_info.m_resilients[i].unsuscribed)                //building unsuscribed
                {
                    build.unsuscribeTimer++;
                    if (build.unsuscribeTimer > REMOVE_AFTER_UPDATES)
                    {
                        s_info.m_resilients.RemoveAt(i);
                        i--;
                        continue;
                    }
                    s_info.m_resilients[i] = build;
                    continue;
                }

                if (instance.m_buildings.m_buffer[buildingID].m_flags == Building.Flags.None)                //building was bulldozed, remove it from the list
                {
                    s_info.m_resilients.RemoveAt(i);
                    i--;
                    continue;
                }


                //update infos
                BuildingInfo buildinfo = Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID].Info;

                if (buildinfo.m_class.m_service == ItemClass.Service.Residential)
                {
                    s_info.UpdateResidentFamilies(i);
                }
                else
                {
                    s_info.UpdateWorkers(i);

                    if (buildinfo.m_class.m_service == ItemClass.Service.Commercial)
                    {
                        s_info.UpdateVisitsCount(i);
                    }
                    else if (buildinfo.m_class.m_service == ItemClass.Service.Industrial)
                    {
                        if (buildinfo.m_buildingAI.GetType().Equals(typeof(IndustrialExtractorAI)))
                        {
                            s_info.UpdatePrimaryResourceExport(i);
                        }
                        else if (buildinfo.m_buildingAI.GetType().Equals(typeof(IndustrialBuildingAI)))
                        {
                            s_info.UpdateGoodsExport(i);
                        }
                    }
                }

                if (build.resiliencyActivated)
                {
                    //instance.m_buildings.m_buffer[buildingID].m_electricityProblemTimer = 0;
                    //instance.m_buildings.m_buffer[buildingID].m_majorProblemTimer = 0;
                    //instance.m_buildings.m_buffer[buildingID].m_problems = Notification.Problem.TurnedOff;

                    //building will not be removed when dezoning, it must be bulldozed
                    //instance.m_buildings.m_buffer[buildingID].m_flags &= ~Building.Flags.ZonesUpdated;

                    //avoid major problem to trigger abandonment
                    instance.m_buildings.m_buffer[buildingID].m_majorProblemTimer = 0;
                    instance.m_buildings.m_buffer[buildingID].m_problems         &= ~Notification.Problem.MajorProblem;

                    //lower cap on unhappiness if problems
                    if (instance.m_buildings.m_buffer[buildingID].m_problems != Notification.Problem.None)
                    {
                        instance.m_buildings.m_buffer[buildingID].m_happiness = 60;
                    }

                    //reoccupy building when it is abandoned/burned down
                    if ((instance.m_buildings.m_buffer[buildingID].m_flags & (Building.Flags.Abandoned | Building.Flags.BurnedDown)) != Building.Flags.None)
                    {
                        //reset timers
                        instance.m_buildings.m_buffer[buildingID].m_electricityProblemTimer = 0;
                        instance.m_buildings.m_buffer[buildingID].m_waterProblemTimer       = 0;
                        instance.m_buildings.m_buffer[buildingID].m_majorProblemTimer       = 0;
                        instance.m_buildings.m_buffer[buildingID].m_deathProblemTimer       = 0;
                        instance.m_buildings.m_buffer[buildingID].m_serviceProblemTimer     = 0;
                        instance.m_buildings.m_buffer[buildingID].m_taxProblemTimer         = 0;
                        instance.m_buildings.m_buffer[buildingID].m_outgoingProblemTimer    = 0;
                        instance.m_buildings.m_buffer[buildingID].m_incomingProblemTimer    = 0;
                        instance.m_buildings.m_buffer[buildingID].m_heatingProblemTimer     = 0;
                        instance.m_buildings.m_buffer[buildingID].m_healthProblemTimer      = 0;
                        instance.m_buildings.m_buffer[buildingID].m_workerProblemTimer      = 0;

                        //reset buffers
                        instance.m_buildings.m_buffer[buildingID].m_crimeBuffer       = 0;
                        instance.m_buildings.m_buffer[buildingID].m_customBuffer1     = 0;
                        instance.m_buildings.m_buffer[buildingID].m_customBuffer2     = 0;
                        instance.m_buildings.m_buffer[buildingID].m_electricityBuffer = 0;
                        instance.m_buildings.m_buffer[buildingID].m_heatingBuffer     = 0;
                        instance.m_buildings.m_buffer[buildingID].m_garbageBuffer     = 0;
                        instance.m_buildings.m_buffer[buildingID].m_sewageBuffer      = 0;
                        instance.m_buildings.m_buffer[buildingID].m_waterBuffer       = 0;

                        //renovate building
                        Building.Frame carpentry = instance.m_buildings.m_buffer[buildingID].GetLastFrameData();
                        carpentry.m_constructState /= 2;
                        carpentry.m_fireDamage      = 0;
                        instance.m_buildings.m_buffer[buildingID].SetFrameData(Singleton <SimulationManager> .instance.m_currentFrameIndex, carpentry);

                        //repopulate building
                        instance.m_buildings.m_buffer[buildingID].m_flags = Building.Flags.Created;
                        instance.m_buildings.m_buffer[buildingID].Info.m_buildingAI.CreateBuilding(buildingID, ref instance.m_buildings.m_buffer[buildingID]);

                        //user feedback : remove notification
                        instance.m_buildings.m_buffer[buildingID].m_problems = Notification.Problem.None;
                    }

                    if (instance.m_buildings.m_buffer[buildingID].GetLastFrameData().m_fireDamage > 230 && Settings.inst.extinguishFires)                    //extinguish fire at last minute
                    {
                        instance.m_buildings.m_buffer[buildingID].m_fireIntensity = 0;
//						Building.Frame carpentry = instance.m_buildings.m_buffer[buildingID].GetLastFrameData();
//						carpentry.m_fireDamage = 0;
//						instance.m_buildings.m_buffer[buildingID].SetFrameData(Singleton<SimulationManager>.instance.m_currentFrameIndex+1, carpentry);
                    }
                }

                s_UI.CheckUpdateUI(buildingID);
            }
        }