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); }
void Start() { if (gameStarted) { return; } if (gameMode != GameMode.Editor) { difficulty = gameStartSettings.difficulty; SetDefaultValues(); //byte chunksize = gss.chunkSize; byte chunksize; chunksize = gameStartSettings.chunkSize; if (testMode && savenameToLoad != string.Empty) { gameStartSettings = new GameStartSettings(ChunkGenerationMode.GameLoading); savename = savenameToLoad; } if (gameStartSettings.generationMode != ChunkGenerationMode.GameLoading) { if (gameStartSettings.generationMode != ChunkGenerationMode.DontGenerate) { if (gameStartSettings.generationMode != ChunkGenerationMode.TerrainLoading) { Constructor.ConstructChunk(chunksize, gameStartSettings.generationMode); // Constructor.ConstructBlock(chunksize); if (gameStartSettings.generationMode == ChunkGenerationMode.Peak) { environmentMaster.PrepareIslandBasis(ChunkGenerationMode.Peak); } } else { LoadTerrain(SaveSystemUI.GetTerrainsPath() + '/' + savename + '.' + SaveSystemUI.TERRAIN_FNAME_EXTENSION); } } FollowingCamera.main.ResetTouchRightBorder(); FollowingCamera.main.CameraRotationBlock(false); warProximity = 0.01f; layerCutHeight = Chunk.chunkSize; prevCutHeight = layerCutHeight; switch (startGameWith) { case GameStart.Zeppelin: Instantiate(Resources.Load <GameObject>("Prefs/Zeppelin")); if (needTutorial) { GameLogUI.EnableDecisionWindow(null, Localization.GetTutorialHint(LocalizedTutorialHint.Landing)); } else { GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.SetLandingPoint)); } break; case GameStart.Headquarters: var sblocks = mainChunk.surfaces; Plane sb = sblocks[Random.Range(0, sblocks.Length)]; int xpos = sb.pos.x; int zpos = sb.pos.z; Structure s; if (testMode) { s = HeadQuarters.GetHQ(6); weNeedNoResources = true; } else { weNeedNoResources = false; s = HeadQuarters.GetHQ(1); } Plane b = mainChunk.GetHighestSurfacePlane(xpos, zpos); s.SetBasement(b, PixelPosByte.zero); sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos + 1); if (sb == null) { sb = mainChunk.GetHighestSurfacePlane(xpos, zpos + 1); if (sb == null) { sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos + 1); if (sb == null) { sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos); if (sb == null) { sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos); if (sb == null) { sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos - 1); if (sb == null) { sb = mainChunk.GetHighestSurfacePlane(xpos, zpos - 1); if (sb == null) { sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos - 1); if (sb == null) { print("bad generation, do something!"); } } } } } } } } StorageHouse firstStorage = Structure.GetStructureByID(Structure.STORAGE_0_ID) as StorageHouse; firstStorage.SetBasement(sb, PixelPosByte.zero); SetStartResources(); break; } FollowingCamera.main.WeNeedUpdate(); } else { LoadGame(SaveSystemUI.GetSavesPath() + '/' + savename + ".sav"); } } else { gameObject.AddComponent <PoolMaster>().Load(); mainChunk = new GameObject("chunk").AddComponent <Chunk>(); int size = Chunk.chunkSize; int[,,] blocksArray = new int[size, size, size]; size /= 2; blocksArray[size, size, size] = ResourceType.STONE_ID; mainChunk.CreateNewChunk(blocksArray); } { // set look point FollowingCamera.camBasisTransform.position = sceneCenter; } gameStarted = true; }