Beispiel #1
0
    ///////////////////////////////
    ///
    ///     Main function to load savegame
    ///     This is the one you call publicly
    ///
    public void LoadSaveData(SaveData saveData, Action callback = null)
    {
        Logger.Debug("Loading save data");

        try {
            // Loading misc
            GameManager.instance.player.playerName         = saveData.playerName;
            GameManager.instance.cityManager.cityName      = saveData.cityName;
            GameManager.instance.cityManager.isTutorialRun = saveData.isTutorialRun;
            GameManager.instance.temporality.SetDate(saveData.cyclesPassed);
            GameManager.instance.temporality.SetTimeOfDay(saveData.timeOfDay);

            GridManagement gridMan = GameManager.instance.gridManagement;

            // Loading grid
            Logger.Debug("Loading " + saveData.blockGrid.Count + " objects into the grid");
            foreach (KeyValuePair <Vector3Int, BlockSaveData> blockData in saveData.blockGrid)
            {
                // Todo : Load states aswell
                Vector3Int coords = blockData.Key;
                Logger.Debug("Spawning block #" + blockData.Value.id + " at position " + blockData.Key.ToString());
                GameObject spawnedBlock = gridMan.SpawnBlock(blockData.Value.id, blockData.Key);
                spawnedBlock.GetComponent <Block>().container.closed = false;
            }

            // Converting bridges list
            foreach (KeyValuePair <Vector3Int, Vector3Int> bridge in saveData.bridges)
            {
                Block origin      = gridMan.grid[bridge.Key.x, bridge.Key.y, bridge.Key.z].GetComponent <Block>();
                Block destination = gridMan.grid[bridge.Value.x, bridge.Value.y, bridge.Value.z].GetComponent <Block>();
                if (gridMan.CreateBridge(origin, destination) == null)
                {
                    Logger.Warn("Could not replicate bridge from " + origin + ":(" + bridge.Key + ") to " + destination + ":(" + bridge.Value + ")");
                }
                ;
            }

            // Loading population
            PopulationManager popMan = GameManager.instance.populationManager;
            popMan.populations.Clear();
            foreach (PopulationSaveData data in saveData.popSaveData)
            {
                Population pop = popMan.GetPopulationByID(data.popId);
                if (pop == null)
                {
                    Logger.Error("Error while loading population from savegame : [" + data.popId + "] is not a valid POP id");
                }
                List <PopulationManager.Citizen> citizens = new List <PopulationManager.Citizen>();
                foreach (CitizenSaveData cSD in data.citizens)
                {
                    citizens.Add(new PopulationManager.Citizen()
                    {
                        name = cSD.name,
                        type = pop
                    });
                }

                popMan.populations[pop] = new PopulationManager.PopulationInformation()
                {
                    moodModifiers = data.moodModifiers,
                    foodModifiers = data.foodModifiers,
                    riotRisk      = data.riotRisk,
                    averageMood   = data.averageMood,
                    citizens      = citizens
                };
            }

            // Loading unlocks
            CityManager city = GameManager.instance.cityManager;
            city.ClearLocks();
            foreach (int id in saveData.lockedBuildings)
            {
                city.LockBuilding(id);
            }

            // Loading population order
            int prio = 0;
            foreach (int popId in saveData.populationTypeIds)
            {
                Population pop = popMan.GetPopulationByID(popId);
                if (pop == null)
                {
                    Logger.Error("Error while loading population types from savegame : [" + popId + "] is not a valid POP id");
                }
                popMan.ChangePopulationPriority(pop, prio);
                prio++;
            }
            MoodsDisplay display = FindObjectOfType <MoodsDisplay>();
            if (display != null)
            {
                // Refresh interface
                display.InitializeMoods(popMan.populationTypeList);
            }

            // Bulletins pool
            BulletinsManager bullMan = GameManager.instance.bulletinsManager;
            bullMan.SetBulletinPool(saveData.bulletinList);
            bullMan.SetBulletin(saveData.currentBulletin);

            // Events pool
            EventManager eventMan = GameManager.instance.eventManager;
            eventMan.eventsPool = saveData.eventsPool;

            // End of loading
            if (callback != null)
            {
                callback.Invoke();
            }
        }

        catch (Exception e) {
            Logger.Error("Could not load the savegame : \n" + e.ToString() + "\n Going back to the main menu instead.");
            DestroySave();
            GameManager.instance.ExitToMenu();
        }
    }
Beispiel #2
0
    void FindAllReferences()
    {
        // SYSTEM
        if (temporality == null)
        {
            temporality = FindObjectOfType <Temporality>();
        }
        if (flagReader == null)
        {
            flagReader = FindObjectOfType <FlagReader>();
        }
        if (library == null)
        {
            library = FindObjectOfType <Library>();
        }
        if (soundManager == null)
        {
            soundManager = FindObjectOfType <SoundManager>();
        }
        if (systemManager == null)
        {
            systemManager = FindObjectOfType <SystemManager>();
        }
        if (missionCallbackManager == null)
        {
            missionCallbackManager = FindObjectOfType <MissionCallbackManager>();
        }
        if (missionManager == null)
        {
            missionManager = FindObjectOfType <MissionManager>();
        }
        if (cursorManagement == null)
        {
            cursorManagement = FindObjectOfType <CursorManagement>();
        }
        if (gridManagement == null)
        {
            gridManagement = FindObjectOfType <GridManagement>();
        }
        if (populationManager == null)
        {
            populationManager = FindObjectOfType <PopulationManager>();
        }
        if (saveManager == null)
        {
            saveManager = FindObjectOfType <SaveManager>();
        }
        if (cinematicManager == null)
        {
            cinematicManager = FindObjectOfType <CinematicManager>();
        }
        if (cityManager == null)
        {
            cityManager = FindObjectOfType <CityManager>();
        }
        if (bulletinsManager == null)
        {
            bulletinsManager = FindObjectOfType <BulletinsManager>();
        }
        if (overlayManager == null)
        {
            overlayManager = FindObjectOfType <OverlayManager>();
        }
        if (timelineController == null)
        {
            timelineController = FindObjectOfType <TimelineController>();
        }
        if (player == null)
        {
            player = FindObjectOfType <Player>();
        }
        if (eventManager == null)
        {
            eventManager = FindObjectOfType <EventManager>();
        }
        if (animationManager == null)
        {
            animationManager = FindObjectOfType <AnimationManager>();
        }
        if (achievementManager == null)
        {
            achievementManager = FindObjectOfType <AchievementManager>();
        }
        if (roamerManager == null)
        {
            roamerManager = FindObjectOfType <RoamerManager>();
        }
        if (environmentalFX == null)
        {
            environmentalFX = FindObjectOfType <EnvironmentalFX>();
        }


        // INTERFACE
        if (localization == null)
        {
            localization = FindObjectOfType <Localization>();
        }
        if (displayerManager == null)
        {
            displayerManager = FindObjectOfType <DisplayerManager>();
        }

        // INTERFACE - INGAME
        if (temporalityInterface == null)
        {
            temporalityInterface = FindObjectOfType <TemporalityInterface>();
        }
        if (tooltipGO == null)
        {
            tooltipGO = FindObjectOfType <TooltipGO>();
        }

        // DEBUG
        if (logger == null)
        {
            logger = FindObjectOfType <Logger>();
        }
    }