public void SetObservingRCenter(RecruitingCenter rc) { if (fullProgressBarLength == -1) { fullProgressBarLength = progressBar.rect.width; startOffset = progressBar.offsetMin.x; } if (rc == null) { SelfShutOff(); return; } UIWorkbuildingObserver uwb = WorkBuilding.workbuildingObserver; if (uwb == null) { uwb = UIWorkbuildingObserver.InitializeWorkbuildingObserverScript(); } else { uwb.gameObject.SetActive(true); } observingRCenter = rc; isObserving = true; uwb.SetObservingWorkBuilding(rc); PrepareCrewsWindow(); STATUS_UPDATE_TIME = 1f; timer = STATUS_UPDATE_TIME; }
override public void ShutOff() { isObserving = false; observingRCenter = null; WorkBuilding.workbuildingObserver.ShutOff(); gameObject.SetActive(false); }
public void PrepareWindow() { PrepareCrewsDropdown(); PrepareButtons(); crewSlotsInfo.text = Crew.crewsList.Count.ToString() + " / " + RecruitingCenter.GetCrewsSlotsCount().ToString(); hireButton.transform.GetChild(0).GetComponent <Text>().text = Localization.GetPhrase(LocalizedPhrase.HireNewCrew) + " (" + RecruitingCenter.GetHireCost().ToString() + ')'; }
public void StartHiring() { if (observingRCenter.finding) { observingRCenter.finding = false; hireButton.GetComponent <Image>().overrideSprite = null; return; } else { if (Crew.crewSlots > 0) { if (GameMaster.colonyController.energyCrystalsCount >= RecruitingCenter.GetHireCost()) { GameMaster.colonyController.GetEnergyCrystals(RecruitingCenter.GetHireCost()); observingRCenter.finding = true; hireButton.gameObject.SetActive(true); hireButton.GetComponent <Image>().overrideSprite = PoolMaster.gui_overridingSprite; } else { UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.NotEnoughEnergyCrystals)); hireButton.GetComponent <Image>().overrideSprite = null; } } else { UIController.current.MakeAnnouncement(Localization.GetRefusalReason(RefusalReason.NotEnoughSlots)); } } }
public static Crew CreateNewCrew(ColonyController home, int membersCount) { if (crewsList.Count >= RecruitingCenter.GetCrewsSlotsCount()) { return(null); } if (crewsList.Count > MAX_CREWS_COUNT) { GameLogUI.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.CrewsLimitReached)); GameMaster.LoadingFail(); return(null); } Crew c = new GameObject(Localization.NameCrew()).AddComponent <Crew>(); if (crewsContainer == null) { crewsContainer = new GameObject("crewsContainer"); } c.transform.parent = crewsContainer.transform; c.ID = nextID; nextID++; c.atHome = true; //normal parameters c.membersCount = (byte)membersCount; //attributes c.SetAttributes(home); // crewsList.Add(c); listChangesMarkerValue++; return(c); }
public bool SaveGame(string name) { // заменить потом на persistent - постоянный путь SetPause(true); string path = SaveSystemUI.GetSavesPath() + '/'; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } FileStream fs = File.Create(path + name + '.' + SaveSystemUI.SAVE_FNAME_EXTENSION); savename = name; //сразу передавать файловый поток для записи, чтобы не забивать озу #region gms mainPartFilling fs.Write(System.BitConverter.GetBytes(GameConstants.SAVE_SYSTEM_VERSION), 0, 4); // start writing fs.Write(System.BitConverter.GetBytes(gameSpeed), 0, 4); fs.Write(System.BitConverter.GetBytes(lifeGrowCoefficient), 0, 4); fs.Write(System.BitConverter.GetBytes(demolitionLossesPercent), 0, 4); fs.Write(System.BitConverter.GetBytes(lifepowerLossesPercent), 0, 4); fs.Write(System.BitConverter.GetBytes(LUCK_COEFFICIENT), 0, 4); fs.Write(System.BitConverter.GetBytes(sellPriceCoefficient), 0, 4); fs.Write(System.BitConverter.GetBytes(tradeVesselsTrafficCoefficient), 0, 4); fs.Write(System.BitConverter.GetBytes(upgradeDiscount), 0, 4); fs.Write(System.BitConverter.GetBytes(upgradeCostIncrease), 0, 4); fs.Write(System.BitConverter.GetBytes(warProximity), 0, 4); //40 fs.WriteByte((byte)difficulty); // 41 fs.WriteByte((byte)startGameWith); // 42 fs.WriteByte(prevCutHeight); //43 fs.WriteByte(day); // 44 fs.WriteByte(month); //45 fs.Write(System.BitConverter.GetBytes(year), 0, 4); fs.Write(System.BitConverter.GetBytes(timeGone), 0, 4); fs.Write(System.BitConverter.GetBytes(gearsDegradeSpeed), 0, 4); fs.Write(System.BitConverter.GetBytes(labourTimer), 0, 4); fs.Write(System.BitConverter.GetBytes(RecruitingCenter.GetHireCost()), 0, 4); //65 (+4) end #endregion DockSystem.SaveDockSystem(fs); globalMap.Save(fs); environmentMaster.Save(fs); Artifact.SaveStaticData(fs); Crew.SaveStaticData(fs); mainChunk.SaveChunkData(fs); colonyController.Save(fs); // <------- COLONY CONTROLLER QuestUI.current.Save(fs); Expedition.SaveStaticData(fs); Knowledge.GetCurrent().Save(fs); fs.Position = 0; double hashsum = GetHashSum(fs, false); fs.Write(System.BitConverter.GetBytes(hashsum), 0, 8); fs.Close(); SetPause(false); return(true); }
public bool SaveGame(string name) // заменить потом на persistent - постоянный путь { Time.timeScale = 0; GameMasterSerializer gms = new GameMasterSerializer(); #region gms mainPartFilling gms.gameSpeed = gameSpeed; gms.lifeGrowCoefficient = lifeGrowCoefficient; gms.demolitionLossesPercent = demolitionLossesPercent; gms.lifepowerLossesPercent = lifepowerLossesPercent; gms.luckCoefficient = LUCK_COEFFICIENT; gms.sellPriceCoefficient = sellPriceCoefficient; gms.tradeVesselsTrafficCoefficient = tradeVesselsTrafficCoefficient; gms.upgradeDiscount = upgradeDiscount; gms.upgradeCostIncrease = upgradeCostIncrease; gms.environmentalConditions = environmentalConditions; gms.warProximity = warProximity; gms.difficulty = difficulty; gms.startGameWith = startGameWith; gms.prevCutHeight = prevCutHeight; gms.diggingSpeed = diggingSpeed; gms.pouringSpeed = pouringSpeed; gms.manufacturingSpeed = manufacturingSpeed; gms.clearingSpeed = clearingSpeed; gms.gatheringSpeed = gatheringSpeed; gms.miningSpeed = miningSpeed; gms.machineConstructingSpeed = machineConstructingSpeed; gms.day = day; gms.week = week; gms.month = month; gms.year = year; gms.millenium = millenium; gms.t = timeGone; gms.windVector_x = windVector.x; gms.windVector_z = windVector.y; gms.windTimer = windTimer; gms.windChangeTime = windChangeTime; gms.labourTimer = labourTimer; gms.lifepowerTimer = lifepowerTimer; gms.recruiting_hireCost = RecruitingCenter.GetHireCost(); #endregion gms.chunkSerializer = mainChunk.SaveChunkData(); gms.colonyControllerSerializer = colonyController.Save(); gms.dockStaticSerializer = Dock.SaveStaticDockData(); gms.shuttleStaticSerializer = Shuttle.SaveStaticData(); gms.crewStaticSerializer = Crew.SaveStaticData(); gms.questStaticSerializer = QuestUI.current.Save(); gms.expeditionStaticSerializer = Expedition.SaveStaticData(); string path = Application.persistentDataPath + "/Saves/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } FileStream fs = File.Create(path + name + '.' + SaveSystemUI.SAVE_FNAME_EXTENSION); savename = name; BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, gms); fs.Close(); Time.timeScale = 1; return(true); }
public static void ResetToDefaults_Static() { OakTree.ResetToDefaults_Static_OakTree(); Corn.ResetToDefaults_Static_Corn(); Hospital.ResetToDefaults_Static_Hospital(); Dock.ResetToDefaults_Static_Dock(); RecruitingCenter.ResetToDefaults_Static_RecruitingCenter(); QuantumTransmitter.ResetToDefaults_Static_QuantumTransmitter(); Hangar.ResetToDefaults_Static_Hangar(); }
public void MembersButton() { if (observingCrew == null) { gameObject.SetActive(false); } else { if (RecruitingCenter.SelectAny()) { gameObject.SetActive(false); } } }
public void SetObservingRCenter(RecruitingCenter rc) { if (rc == null) { SelfShutOff(); return; } UIWorkbuildingObserver uwb = WorkBuilding.workbuildingObserver; if (uwb == null) { uwb = UIWorkbuildingObserver.InitializeWorkbuildingObserverScript(); } else { uwb.gameObject.SetActive(true); } observingRCenter = rc; isObserving = true; uwb.SetObservingPlace(rc); PrepareWindow(); }
public bool LoadGame(string fullname) { bool debug_noresource = weNeedNoResources, refreshUI = false; Stream 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; // НАЧАЛО ЗАГРУЗКИ #region gms mainPartLoading data = new byte[5]; fs.Read(data, 0, data.Length); int saveSystemVersion = System.BitConverter.ToInt32(data, 0); // может пригодиться в дальнейшем gameMode = (GameMode)data[4]; // if (sessionPrepared) { ClearPreviousSessionData(); refreshUI = true; } else { PrepareSession(); } //start reading data = new byte[68]; 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]; int i = 41; prevCutHeight = data[i++]; day = data[i++]; month = data[i++]; year = System.BitConverter.ToUInt32(data, i); i += 4; timeGone = System.BitConverter.ToSingle(data, i); i += 4; gearsDegradeSpeed = System.BitConverter.ToSingle(data, i); i += 4; labourTimer = System.BitConverter.ToSingle(data, i); i += 4; RecruitingCenter.SetHireCost(System.BitConverter.ToSingle(data, i)); i += 4; gameID = System.BitConverter.ToInt32(data, i); i += 4; #endregion DockSystem.LoadDockSystem(fs, saveSystemVersion); var b = fs.ReadByte(); if (b == 1) { globalMap.Load(fs, saveSystemVersion); } 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 (colonyController == null) { PrepareColonyController(false); } // if (mainChunk == null) { mainChunk = Chunk.InitializeChunk(); } mainChunk.LoadChunkData(fs); if (loadingFailed) { errorReason = "chunk load failure"; goto FAIL; } else { if (blockersRestoreEvent != null) { blockersRestoreEvent(); } } Settlement.TotalRecalculation(); // Totaru Annihiration 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); b = fs.ReadByte(); if (b == 1) { executingScenario = Scenario.StaticLoad(fs); } FollowingCamera.main.Load(fs); fs.Close(); FollowingCamera.main.WeNeedUpdate(); loading = false; currentSavename = fullname; //Debug.Log("recalculation event"); if (afterloadRecalculationEvent != null) { afterloadRecalculationEvent(); afterloadRecalculationEvent = null; } SetPause(false); //Debug.Log("power grid"); colonyController.FORCED_PowerGridRecalculation(); //Debug.Log("docks"); colonyController.SYSTEM_DocksRecalculation(); //Debug.Log("end"); if (refreshUI) { UIController.GetCurrent().GameWasReloaded(); } DEBUG_STOP = true; return(true); } else { AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : hashsum incorrect"); if (soundEnabled) { audiomaster.Notify(NotificationSound.SystemError); } SetPause(true); fs.Close(); return(false); } FAIL: AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : data corruption"); if (soundEnabled) { audiomaster.Notify(NotificationSound.SystemError); } Debug.Log(errorReason); SetPause(true); fs.Close(); if (debug_noresource) { weNeedNoResources = true; } return(false); }
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); }
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); } }
public void LocalizeButtonTitles() { hireButton.transform.GetChild(0).GetComponent <Text>().text = Localization.GetPhrase(LocalizedPhrase.HireNewCrew) + " (" + RecruitingCenter.GetHireCost() + ')'; dismissButton.transform.GetChild(0).GetComponent <Text>().text = Localization.GetWord(LocalizedWord.Dismiss); }
public void PrepareCrewsDropdown() { List <Dropdown.OptionData> crewButtons = new List <Dropdown.OptionData>(); crewButtons.Add(new Dropdown.OptionData(Localization.GetPhrase(LocalizedPhrase.HireNewCrew) + " (" + RecruitingCenter.GetHireCost() + ')')); var crews = Crew.crewsList; if (crews.Count > 0) { for (int i = 0; i < crews.Count; i++) { crewButtons.Add(new Dropdown.OptionData('\"' + crews[i].name + '\"')); } } crewListDropdown.options = crewButtons; }