public override void Apply() { MyPlanetGeneratorDefinition planetDefinition = MyDefinitionManager.Static.GetDefinition <MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(DefinitionName)); if (planetDefinition == null) { string message = String.Format("Definition for planet {0} could not be found. Skipping.", DefinitionName); Debug.Fail(message); MyLog.Default.WriteLine(message); return; } Vector3D position = PositionMinCorner; if (PositionCenter.IsValid()) { position = PositionCenter; var size = MyVoxelCoordSystems.FindBestOctreeSize(Diameter * (1 + planetDefinition.HillParams.Max)); position -= ((Vector3D)size) / 2; } int seed = MyRandom.Instance.Next(); var storageNameBase = DefinitionName + "-" + seed + "d" + Diameter; MyWorldGenerator.CreatePlanet(storageNameBase, planetDefinition.FolderName, ref position, seed, Diameter, MyRandom.Instance.NextLong(), ref planetDefinition, AddGPS); }
public override void SetupCharacter(MyWorldGenerator.Args generatorArgs) { string respawnShipId = m_respawnShipId; if (!MyDefinitionManager.Static.HasRespawnShip(m_respawnShipId)) respawnShipId = MyDefinitionManager.Static.GetFirstRespawnShip(); Debug.Assert(MySession.LocalHumanPlayer != null, "Local controller does not exist!"); if (MySession.LocalHumanPlayer == null) return; MySpaceRespawnComponent.Static.SpawnAtShip(MySession.LocalHumanPlayer, respawnShipId); }
public override void Apply() { MyFaction faction = null; if (FactionTag != null) { faction = MySession.Static.Factions.TryGetOrCreateFactionByTag(FactionTag); } long factionId = faction != null ? faction.FactionId : 0; MyWorldGenerator.SetupBase(PrefabFile, Offset, AsteroidName, BeaconName, factionId); }
/// <summary> /// Initializes a new single player session and start new game with parameters /// </summary> public static void Start( string name, string description, string password, MyObjectBuilder_SessionSettings settings, List<MyObjectBuilder_Checkpoint.ModItem> mods, MyWorldGenerator.Args generationArgs) { MyLog.Default.WriteLineAndConsole("Starting world " + name); MyEntityContainerEventExtensions.InitEntityEvents(); Static = new MySession(); Static.Name = name; Static.Mods = mods; Static.Description = description; Static.Password = password; Static.Settings = settings; Static.Scenario = generationArgs.Scenario; FixIncorrectSettings(Static.Settings); double radius = settings.WorldSizeKm * 500; //half size if (radius > 0) { Static.WorldBoundaries = new BoundingBoxD(new Vector3D(-radius, -radius, -radius), new Vector3D(radius, radius, radius)); } Static.InGameTime = generationArgs.Scenario.GameDate;//MyObjectBuilder_Checkpoint.DEFAULT_DATE; Static.RequiresDX = generationArgs.Scenario.HasPlanets ? 11 : 9; if (Static.OnlineMode != MyOnlineModeEnum.OFFLINE) StartServerRequest(); Static.IsCameraAwaitingEntity = true; // Find new non existing folder. The game folder name may be different from game name, so we have to // make sure we don't overwrite another save string safeName = MyUtils.StripInvalidChars(name); Static.CurrentPath = MyLocalCache.GetSessionSavesPath(safeName, false, false); while (Directory.Exists(Static.CurrentPath)) { Static.CurrentPath = MyLocalCache.GetSessionSavesPath(safeName + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false); } Static.PrepareBaseSession(mods, generationArgs.Scenario); MySector.EnvironmentDefinition = MyDefinitionManager.Static.GetDefinition<MyEnvironmentDefinition>(generationArgs.Scenario.Environment); MyWorldGenerator.GenerateWorld(generationArgs); if (Sync.IsServer) { // Factions have to be initialized before world is generated/loaded. Static.InitializeFactions(); } if (!Engine.Platform.Game.IsDedicated) { var playerId = new MyPlayer.PlayerId(Sync.MyId, 0); MyToolBarCollection.RequestCreateToolbar(playerId); } Static.SendSessionStartStats(); var scenarioName = generationArgs.Scenario.DisplayNameText.ToString(); Static.LogSettings(scenarioName, generationArgs.AsteroidAmount); if (generationArgs.Scenario.SunDirection.IsValid()) { MySector.SunProperties.SunDirectionNormalized = Vector3.Normalize(generationArgs.Scenario.SunDirection); MySector.SunProperties.BaseSunDirectionNormalized = Vector3.Normalize(generationArgs.Scenario.SunDirection); } //Because blocks fills SubBlocks in this method.. //TODO: Create LoadPhase2 MyEntities.UpdateOnceBeforeFrame(); Static.BeforeStartComponents(); Static.Save(); MyLocalCache.SaveLastLoadedTime(Static.CurrentPath, DateTime.Now); // Initialize Spectator light MySpectatorCameraController.Static.InitLight(false); }
// Backward compatibility method only used when the procedurally generated asteroids were not working private static void AddPregeneratedCluster(ref MyWorldGenerator.Args args, string name, float scale) { AddPregeneratedAsteroid(name, scale); args.AsteroidAmount -= 1; for (int i = 0; i < 5; ++i) { AddPregeneratedAsteroid(name + "moon" + i, scale); } }
// Backward compatibility method only used when the procedurally generated asteroids were not working public static void LoadPregeneratedAsteroids(ref MyWorldGenerator.Args args) { float offset = args.Scenario.AsteroidClustersOffset; float scale = Math.Max(offset / 700.0f, 1.0f); args.AsteroidAmount -= MySession.Static.VoxelMaps.Instances.Count; if (args.Scenario.CentralClusterEnabled) AddPregeneratedCluster(ref args, "centralAsteroid", scale); List<int> asteroidSelector = new List<int>(15); for (int i = 0; i < 15; ++i) asteroidSelector.Add(i); while (args.AsteroidAmount > 0 && asteroidSelector.Count > 0) { int i = MyRandom.Instance.Next(0, asteroidSelector.Count); int asteroidIndex = asteroidSelector[i]; asteroidSelector.RemoveAtFast(i); AddPregeneratedCluster(ref args, "asteroid" + asteroidIndex, scale); } }
static void MyWorldGenerator_AfterGenerate(ref MyWorldGenerator.Args args) { if (MyPerGameSettings.EnablePregeneratedAsteroidHack) LoadPregeneratedAsteroids(ref args); }
/// <summary> /// Starts new session and unloads outdated if theres any. /// </summary> /// <param name="sessionName">Created session name.</param> /// <param name="settings">Session settings OB.</param> /// <param name="mods">Mod selection.</param> /// <param name="scenarioDefinition">World generator argument.</param> /// <param name="asteroidAmount">Hostility settings.</param> /// <param name="description">Session description.</param> /// <param name="passwd">Session password.</param> public static void StartNewSession(string sessionName, MyObjectBuilder_SessionSettings settings, List <MyObjectBuilder_Checkpoint.ModItem> mods, MyScenarioDefinition scenarioDefinition = null, int asteroidAmount = 0, string description = "", string passwd = "") { MyLog.Default.WriteLine("StartNewSandbox - Start"); if (!MySteamWorkshop.CheckLocalModsAllowed(mods, settings.OnlineMode == MyOnlineModeEnum.OFFLINE)) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer), buttonType: MyMessageBoxButtonsType.OK)); MyLog.Default.WriteLine("LoadSession() - End"); return; } MySteamWorkshop.DownloadModsAsync(mods, delegate(bool success, string mismatchMods) { if (success || (settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(mods)) { CheckMismatchmods(mismatchMods, callback : delegate(ResultEnum val) { MyScreenManager.RemoveAllScreensExcept(null); if (asteroidAmount < 0) { MyWorldGenerator.SetProceduralSettings(asteroidAmount, settings); asteroidAmount = 0; } MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom); StartLoading(delegate { MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom); MySession.Start( sessionName, description, passwd, settings, mods, new MyWorldGenerator.Args() { AsteroidAmount = asteroidAmount, Scenario = scenarioDefinition } ); }); }); } else { if (MySteam.IsOnline) { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed), buttonType: MyMessageBoxButtonsType.OK)); } else { MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox( messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError), messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline), buttonType: MyMessageBoxButtonsType.OK)); } } MyLog.Default.WriteLine("StartNewSandbox - End"); }); }
public override void SetupCharacter(MyWorldGenerator.Args generatorArgs) { Debug.Assert(MySession.Static.LocalHumanPlayer != null, "Local controller does not exist!"); if (MySession.Static.LocalHumanPlayer == null) return; var characterOb = Sandbox.Game.Entities.Character.MyCharacter.Random(); if (Transform.HasValue && MyPerGameSettings.CharacterStartsOnVoxel) { var transform = Transform.Value; transform.Position = FixPositionToVoxel(transform.Position); characterOb.PositionAndOrientation = transform; } else { characterOb.PositionAndOrientation = Transform; } characterOb.JetpackEnabled = JetpackEnabled; characterOb.DampenersEnabled = DampenersEnabled; if (characterOb.Inventory == null) characterOb.Inventory = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Inventory>(); FillInventoryWithDefaults(characterOb.Inventory, generatorArgs.Scenario); var character = new MyCharacter(); character.Name = "Player"; character.Init(characterOb); MyEntities.RaiseEntityCreated(character); MyEntities.Add(character); this.CreateAndSetPlayerFaction(); MySession.Static.LocalHumanPlayer.SpawnIntoCharacter(character); }
public override void Apply() { MyWorldGenerator.AddObjectsPrefab(PrefabFile); }
public override void Apply() { MyWorldGenerator.AddAsteroidPrefab(PrefabName, Position, Name); }
public override void Apply() { MyWorldGenerator.SetupBase(PrefabFile, Offset, AsteroidName, BeaconName); }
public abstract void SetupCharacter(MyWorldGenerator.Args generatorArgs);
// Start game with some default values public static void QuickstartSandbox(MyObjectBuilder_SessionSettings quickstartSettings, MyWorldGenerator.Args? quickstartArgs) { MyLog.Default.WriteLine("QuickstartSandbox - START"); MyScreenManager.RemoveAllScreensExcept(null); MyGuiScreenGamePlay.StartLoading(delegate { var settings = (quickstartSettings != null) ? quickstartSettings : CreateBasicQuickStartSettings(); var args = (quickstartArgs != null) ? quickstartArgs.Value : CreateBasicQuickstartArgs(); var mods = new List<MyObjectBuilder_Checkpoint.ModItem>(0); MySession.Start("Created " + DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "", "", settings, mods, args); }); MyLog.Default.WriteLine("QuickstartSandbox - END"); }
public override void Apply() { MyWorldGenerator.AddPlanetPrefab(PrefabName, DefinitionName, Position, AddGPS); }
public abstract void SetupCharacterDefault(MyPlayer player, MyWorldGenerator.Args args);
public override void Apply() { MyWorldGenerator.AddPlanetPrefab(PrefabName, Name); }