Exemple #1
0
        public override void OnLoadData()
        {
            base.OnLoadData();

            if (managers.loading.currentMode == AppMode.Game)
            {
                try
                {
                    TaxiMod.ClearTaxiBuildings();
                    TransferManagerMod.ClearBuildingToBuildingExclusions();

                    Datav4 data;

                    // Always try to load the latest version if possible.
                    if (Datav4.TryLoadData(this, out data))
                    {
                        Constraints.LoadData(data);
                    }
                    else if (Datav3.TryLoadData(this, out data))
                    {
                        Constraints.LoadData(data);
                    }
                    else if (Datav2.TryLoadData(this, out data))
                    {
                        Constraints.LoadData(data);
                    }
                    else if (Datav1.TryLoadData(this, out data))
                    {
                        Constraints.LoadData(data);
                    }
                    else
                    {
                        Constraints.Clear();
                    }

                    // Update Taxi buildings cache ...
                    // TODO, FIXME: Make this less hacky ...
                    var buildings = Utils.GetSupportedServiceBuildings();
                    foreach (var building in buildings)
                    {
                        TaxiMod.RegisterTaxiBuilding(building);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
            }
        }
        /// <summary>
        /// Load data from given object.
        /// </summary>
        /// <param name="data"></param>
        public static void LoadData(Serialization.Datav4 data)
        {
            Logger.Log($"Constraints::LoadData: version {data.Id}");
            Clear();

            var buildings = Utils.GetSupportedServiceBuildings();

            foreach (var building in buildings)
            {
                var name         = TransferManagerInfo.GetBuildingName(building);
                var buildingInfo = BuildingManager.instance.m_buildings.m_buffer[building].Info;
                var service      = buildingInfo.GetService();
                var subService   = buildingInfo.GetSubService();
                var ai           = buildingInfo.GetAI();

                Logger.Log($"Constraints::LoadData: buildingName={name}, buildingId={building}, service={service}, subService={subService}, ai={ai}");

                var restrictions1 = data.InputBuildingToAllLocalAreas[building];
                SetAllInputLocalAreas(building, restrictions1);

                var restrictions2 = data.InputBuildingToOutsideConnections[building];
                SetAllInputOutsideConnections(building, restrictions2);

                var restrictions3 = data.InputBuildingToDistrictServiced[building];
                if (restrictions3 != null)
                {
                    foreach (var districtPark in restrictions3)
                    {
                        AddInputDistrictParkServiced(building, DistrictPark.FromSerializedInt(districtPark));
                    }
                }

                var restrictions4 = data.OutputBuildingToAllLocalAreas[building];
                SetAllOutputLocalAreas(building, restrictions4);

                var restrictions5 = data.OutputBuildingToOutsideConnections[building];
                SetAllOutputOutsideConnections(building, restrictions5);

                var restrictions6 = data.OutputBuildingToDistrictServiced[building];
                if (restrictions6 != null)
                {
                    foreach (var districtPark in restrictions6)
                    {
                        AddOutputDistrictParkServiced(building, DistrictPark.FromSerializedInt(districtPark));
                    }
                }

                if (data.BuildingToInternalSupplyBuffer != null)
                {
                    var restrictions7 = data.BuildingToInternalSupplyBuffer[building];
                    SetInternalSupplyReserve(building, restrictions7);
                }

                if (data.BuildingToBuildingServiced != null)
                {
                    var restrictions8 = data.BuildingToBuildingServiced[building];
                    if (restrictions8 != null)
                    {
                        foreach (var destination in restrictions8)
                        {
                            AddSupplyChainConnection(building, (ushort)destination);
                        }
                    }
                }

                m_globalOutsideConnectionIntensity = data.GlobalOutsideConnectionIntensity;
                m_globalOutsideToOutsideMaxPerc    = data.GlobalOutsideToOutsideMaxPerc;

                Logger.Log("");
            }
        }
 public static bool TryLoadData(EnhancedDistrictServicesSerializableData loader, out Datav4 data)
 {
     if (loader.TryLoadData(m_id, null, out Datav4 target))
     {
         data = target;
         return(true);
     }
     else
     {
         data = null;
         return(false);
     }
 }
Exemple #4
0
 public static bool TryLoadData(EnhancedDistrictServicesSerializableData loader, out Datav4 data)
 {
     if (loader.TryLoadData(m_id, new Datav2Binder(), out Datav2 target))
     {
         if (target != null)
         {
             data = target.Upgrade().Upgrade();
             return(true);
         }
         else
         {
             data = null;
             return(false);
         }
     }
     else
     {
         data = null;
         return(false);
     }
 }