private static void ResetComponentsStaticValues()
 {
     if (staticResetFunctions != null)
     {
         staticResetFunctions.Invoke();
         staticResetFunctions = null;
     }
     DockSystem.ResetRequest();
     Crew.Reset();
     Expedition.GameReset();
 }
Beispiel #2
0
    public bool LoadGame(string fullname)
    {
        bool       debug_noresource = weNeedNoResources;
        FileStream fs          = File.Open(fullname, FileMode.Open);
        double     realHashSum = GetHashSum(fs, true);
        var        data        = new byte[8];

        fs.Read(data, 0, 8);
        double readedHashSum = System.BitConverter.ToDouble(data, 0);
        string errorReason   = "reason not stated";

        if (realHashSum == readedHashSum)
        {
            fs.Position = 0;
            SetPause(true);
            loading = true;
            // ОЧИСТКА
            StopAllCoroutines();
            if (Zeppelin.current != null)
            {
                Destroy(Zeppelin.current);
            }
            if (mainChunk != null)
            {
                mainChunk.ClearChunk();
            }
            // очистка подписчиков на ивенты невозможна, сами ивенты к этому моменту недоступны
            Crew.Reset();
            Expedition.GameReset();
            Structure.ResetToDefaults_Static(); // все наследуемые resetToDefaults внутри
            if (colonyController != null)
            {
                colonyController.ResetToDefaults();                           // подчищает все списки
            }
            else
            {
                colonyController = gameObject.AddComponent <ColonyController>();
                colonyController.Prepare();
            }
            //UI.current.Reset();


            // НАЧАЛО ЗАГРУЗКИ
            if (gameStarted)
            {
                SetDefaultValues();
            }
            #region gms mainPartLoading
            data = new byte[4];
            fs.Read(data, 0, 4);
            uint saveSystemVersion = System.BitConverter.ToUInt32(data, 0); // может пригодиться в дальнейшем
            //start writing
            data = new byte[65];
            fs.Read(data, 0, data.Length);
            gameSpeed                      = System.BitConverter.ToSingle(data, 0);
            lifeGrowCoefficient            = System.BitConverter.ToSingle(data, 4);
            demolitionLossesPercent        = System.BitConverter.ToSingle(data, 8);
            lifepowerLossesPercent         = System.BitConverter.ToSingle(data, 12);
            LUCK_COEFFICIENT               = System.BitConverter.ToSingle(data, 16);
            sellPriceCoefficient           = System.BitConverter.ToSingle(data, 20);
            tradeVesselsTrafficCoefficient = System.BitConverter.ToSingle(data, 24);
            upgradeDiscount                = System.BitConverter.ToSingle(data, 28);
            upgradeCostIncrease            = System.BitConverter.ToSingle(data, 32);
            warProximity                   = System.BitConverter.ToSingle(data, 36);

            difficulty    = (Difficulty)data[40];
            startGameWith = (GameStart)data[41];
            prevCutHeight = data[42];
            day           = data[43];
            month         = data[44];

            year              = System.BitConverter.ToUInt32(data, 45);
            timeGone          = System.BitConverter.ToSingle(data, 49);
            gearsDegradeSpeed = System.BitConverter.ToSingle(data, 53);
            labourTimer       = System.BitConverter.ToSingle(data, 57);
            RecruitingCenter.SetHireCost(System.BitConverter.ToSingle(data, 61));
            #endregion

            DockSystem.LoadDockSystem(fs);
            globalMap.Load(fs);
            if (loadingFailed)
            {
                errorReason = "global map error";
                goto FAIL;
            }

            environmentMaster.Load(fs);
            if (loadingFailed)
            {
                errorReason = "environment error";
                goto FAIL;
            }

            Artifact.LoadStaticData(fs); // crews & monuments
            if (loadingFailed)
            {
                errorReason = "artifacts load failure";
                goto FAIL;
            }

            Crew.LoadStaticData(fs);
            if (loadingFailed)
            {
                errorReason = "crews load failure";
                goto FAIL;
            }

            if (mainChunk == null)
            {
                GameObject g = new GameObject("chunk");
                mainChunk = g.AddComponent <Chunk>();
            }
            mainChunk.LoadChunkData(fs);
            if (loadingFailed)
            {
                errorReason = "chunk load failure";
                goto FAIL;
            }
            else
            {
                if (blockersRestoreEvent != null)
                {
                    blockersRestoreEvent();
                }
            }


            Settlement.TotalRecalculation(); // Totaru Annihirationu no imoto-chan
            if (loadingFailed)
            {
                errorReason = "settlements load failure";
                goto FAIL;
            }

            colonyController.Load(fs); // < --- COLONY CONTROLLER
            if (loadingFailed)
            {
                errorReason = "colony controller load failure";
                goto FAIL;
            }

            if (loadingFailed)
            {
                errorReason = "dock load failure";
                goto FAIL;
            }
            QuestUI.current.Load(fs);
            if (loadingFailed)
            {
                errorReason = "quest load failure";
                goto FAIL;
            }
            Expedition.LoadStaticData(fs);
            Knowledge.Load(fs);
            fs.Close();

            FollowingCamera.main.WeNeedUpdate();
            loading  = false;
            savename = fullname;

            if (afterloadRecalculationEvent != null)
            {
                afterloadRecalculationEvent();
                afterloadRecalculationEvent = null;
            }
            SetPause(false);
            colonyController.FORCED_PowerGridRecalculation();

            return(true);
        }
        else
        {
            GameLogUI.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : hashsum incorrect");
            if (soundEnabled)
            {
                audiomaster.Notify(NotificationSound.SystemError);
            }
            SetPause(true);
            fs.Close();
            return(false);
        }
FAIL:
        GameLogUI.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : data corruption");
        if (soundEnabled)
        {
            audiomaster.Notify(NotificationSound.SystemError);
        }
        print(errorReason);
        SetPause(true);
        fs.Close();
        if (debug_noresource)
        {
            weNeedNoResources = true;
        }
        return(false);
    }
Beispiel #3
0
    public bool LoadGame(string fullname)
    {             // отдельно функцию проверки и коррекции сейв-файла
        if (true) // <- тут будет функция проверки
        {
            // ОЧИСТКА
            StopAllCoroutines();
            if (mainChunk != null)
            {
                Destroy(mainChunk.gameObject);
            }
            // очистка подписчиков на ивенты невозможна, сами ивенты к этому моменту недоступны
            Crew.Reset(); Shuttle.Reset();
            Grassland.ScriptReset();
            Expedition.GameReset();
            Structure.ResetToDefaults_Static(); // все наследуемые resetToDefaults внутри
            colonyController.ResetToDefaults(); // подчищает все списки
            FollowingCamera.main.ResetLists();
            //UI.current.Reset();


            // НАЧАЛО ЗАГРУЗКИ
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(fullname, FileMode.Open);
            Time.timeScale = 0; gameSpeed = 0;
            GameMasterSerializer gms = (GameMasterSerializer)bf.Deserialize(file);
            file.Close();
            #region gms mainPartLoading
            gameSpeed                      = gms.gameSpeed;
            lifeGrowCoefficient            = gms.lifeGrowCoefficient;
            demolitionLossesPercent        = gms.demolitionLossesPercent;
            lifepowerLossesPercent         = gms.lifepowerLossesPercent;
            LUCK_COEFFICIENT               = gms.luckCoefficient;
            sellPriceCoefficient           = gms.sellPriceCoefficient;
            tradeVesselsTrafficCoefficient = gms.tradeVesselsTrafficCoefficient;
            upgradeDiscount                = gms.upgradeDiscount;
            upgradeCostIncrease            = gms.upgradeCostIncrease;
            environmentalConditions        = gms.environmentalConditions;
            warProximity                   = gms.warProximity;
            difficulty                     = gms.difficulty;
            startGameWith                  = gms.startGameWith;
            prevCutHeight                  = gms.prevCutHeight;
            diggingSpeed                   = gms.diggingSpeed;
            pouringSpeed                   = gms.pouringSpeed;
            manufacturingSpeed             = gms.manufacturingSpeed;
            clearingSpeed                  = gms.clearingSpeed;
            gatheringSpeed                 = gms.gatheringSpeed;
            miningSpeed                    = gms.miningSpeed;
            machineConstructingSpeed       = gms.machineConstructingSpeed;
            day = gms.day; week = gms.week; month = gms.month; year = gms.year; millenium = gms.millenium; timeGone = gms.t;

            windVector     = new Vector2(gms.windVector_x, gms.windVector_z);
            windTimer      = gms.windTimer; windChangeTime = gms.windChangeTime;
            lifepowerTimer = gms.lifepowerTimer;
            labourTimer    = gms.labourTimer;
            #endregion
            RecruitingCenter.SetHireCost(gms.recruiting_hireCost);
            Crew.LoadStaticData(gms.crewStaticSerializer);
            Shuttle.LoadStaticData(gms.shuttleStaticSerializer); // because of hangars

            GameObject g = new GameObject("chunk");
            mainChunk = g.AddComponent <Chunk>();
            mainChunk.LoadChunkData(gms.chunkSerializer);
            colonyController.Load(gms.colonyControllerSerializer); // < --- COLONY CONTROLLER

            Dock.LoadStaticData(gms.dockStaticSerializer);
            QuestUI.current.Load(gms.questStaticSerializer);
            Expedition.LoadStaticData(gms.expeditionStaticSerializer);

            FollowingCamera.main.WeNeedUpdate();
            Time.timeScale = 1; gameSpeed = 1;

            savename = fullname;
            return(true);
        }
        else
        {
            UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed));
            return(false);
        }
    }