public bool SaveTerrain(string name) { string path = SaveSystemUI.GetTerrainsPath() + '/'; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } Stream fs = File.Create(path + name + '.' + SaveSystemUI.TERRAIN_FNAME_EXTENSION); fs.Write(System.BitConverter.GetBytes(GameConstants.SAVE_SYSTEM_VERSION), 0, 4); mainChunk.SaveChunkData(fs); fs.Close(); return(true); }
void PrepareSession() { if (sessionPrepared) { return; } bool activateEventTracker = false; switch (gameMode) { case GameMode.Survival: { uicontroller.ChangeUIMode(UIMode.Standart, true); difficulty = startSettings.DefineDifficulty(); SetDefaultValues(); var cgs = startSettings.GetChunkGenerationSettings(); var chunkAction = cgs.preparingActionMode; if (chunkAction != ChunkPreparingAction.NoAction) { if (chunkAction == ChunkPreparingAction.Load) { LoadTerrain(SaveSystemUI.GetTerrainsPath() + '/' + cgs.GetTerrainName() + '.' + SaveSystemUI.TERRAIN_FNAME_EXTENSION); } else { mainChunk = Constructor.ConstructChunk(cgs); var slist = mainChunk.GetSurfaces(); if (slist != null) { geologyModule.SpreadMinerals(slist); } mainChunk.InitializeNature().FirstLifeformGeneration(Chunk.chunkSize * Chunk.chunkSize * 500f); } } // var fcm = FollowingCamera.main; fcm.CameraToStartPosition(); fcm.ResetTouchRightBorder(); fcm.CameraRotationBlock(false); warProximity = 0.01f; layerCutHeight = Chunk.chunkSize; prevCutHeight = layerCutHeight; // switch (startSettings.DefineFoundingType()) { case StartFoundingType.Zeppelin: { Zeppelin.CreateNew(); AnnouncementCanvasController.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.SetLandingPoint)); break; } case StartFoundingType.Headquarters: { Plane sb = mainChunk.GetRandomSurface(); 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.GetNearestUnoccupiedSurface(b.pos); StorageHouse firstStorage = Structure.GetStructureByID(Structure.STORAGE_0_ID) as StorageHouse; firstStorage.SetBasement(sb, PixelPosByte.zero); SetStartResources(); break; } } fcm.WeNeedUpdate(); activateEventTracker = true; break; } case GameMode.Editor: { uicontroller.ChangeUIMode(UIMode.Editor, true); 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.Rebuild(blocksArray); FollowingCamera.main.CameraToStartPosition(); break; } case GameMode.Scenario: { uicontroller.ChangeUIMode(UIMode.Standart, true); switch (startSettings.GetScenarioType()) { case ScenarioType.Embedded: { switch ((EmbeddedScenarioType)startSettings.GetSecondSubIndex()) { case EmbeddedScenarioType.Tutorial: { gameRules = GameRules.GetTutorialRules(); LoadTerrainFromAssets(TutorialScenarioNS.TutorialScenario.tutorialTerrainName); TutorialScenarioNS.TutorialUI.Initialize(); break; } } break; } } activateEventTracker = true; FollowingCamera.main.CameraToStartPosition(); break; } } if (activateEventTracker) { eventTracker = new EventChecker(); } startSettings = null; sessionPrepared = true; if (testMode) { AnnouncementCanvasController.MakeAnnouncement("game master loaded"); } autosaveTimer = AUTOSAVE_TIME; }
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; }
public void NG_UsePresetButton() { newGameGenMode = ChunkGenerationMode.TerrainLoading; GameMaster.SetSavename(string.Empty); generationPanel.SetActive(false); generateButtonImage.overrideSprite = null; gameStartButton.interactable = false; //preparing terrains list string directoryPath = SaveSystemUI.GetTerrainsPath(); Transform contentHolder = terrainPresetsPanel.transform.GetChild(0).GetChild(0); RectTransform zeroButton = contentHolder.GetChild(0).GetComponent <RectTransform>(); bool no_saves_found = true; if (Directory.Exists(directoryPath)) { terrainSavenames = Directory.GetFiles(directoryPath, "*." + SaveSystemUI.TERRAIN_FNAME_EXTENSION); if (terrainSavenames.Length != 0) { no_saves_found = false; int c = contentHolder.childCount; int i = 0; zeroButton.GetComponent <Button>().interactable = true; for (; i < terrainSavenames.Length; i++) { string s = terrainSavenames[i]; int lastSlashPos = s.LastIndexOf('\\'); // в редакторе так if (lastSlashPos == -1) { lastSlashPos = s.LastIndexOf('/'); } terrainSavenames[i] = s.Substring(lastSlashPos + 1, s.Length - lastSlashPos - 5); // от последнего слеша до ".sav" Transform t; if (i < c) { t = contentHolder.GetChild(i); // 0 - example } else { t = Instantiate(zeroButton, contentHolder).transform; t.transform.localPosition = zeroButton.localPosition + Vector3.down * (zeroButton.rect.height * i + 16); } t.gameObject.SetActive(true); t.GetComponent <Button>().onClick.RemoveAllListeners(); // т.к. на example тоже может висеть listener t.GetChild(0).GetComponent <Text>().text = terrainSavenames[i]; int index = i; t.GetComponent <Button>().onClick.AddListener(() => { this.NG_SelectTerrain(index); }); t.GetComponent <Image>().overrideSprite = null; } if (i < c) { i++; for (; i < c; i++) { contentHolder.GetChild(i).gameObject.SetActive(false); } } } } if (no_saves_found) { terrainSavenames = null; zeroButton.GetChild(0).GetComponent <Text>().text = Localization.GetPhrase(LocalizedPhrase.NoSavesFound); zeroButton.GetComponent <Button>().interactable = false; zeroButton.GetComponent <Image>().overrideSprite = null; zeroButton.gameObject.SetActive(true); if (contentHolder.childCount > 1) { while (contentHolder.childCount > 1) { Destroy(contentHolder.GetChild(1)); } } } terrainPresetsPanel.SetActive(true); usePresetsButtonImage.overrideSprite = overridingSprite; }