コード例 #1
0
            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);
            }
コード例 #2
0
        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);
        }
コード例 #3
0
            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);
            }
コード例 #4
0
ファイル: MySession.cs プロジェクト: liiir1985/SpaceEngineers
        /// <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);
        }
コード例 #5
0
        // 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);
            }
        }
コード例 #6
0
        // 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);
            }
        }
コード例 #7
0
 static void MyWorldGenerator_AfterGenerate(ref MyWorldGenerator.Args args)
 {
     if (MyPerGameSettings.EnablePregeneratedAsteroidHack)
         LoadPregeneratedAsteroids(ref args);
 }
コード例 #8
0
        /// <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");
            });
        }
コード例 #9
0
            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);
            }
コード例 #10
0
 public override void Apply()
 {
     MyWorldGenerator.AddObjectsPrefab(PrefabFile);
 }
コード例 #11
0
 public override void Apply()
 {
     MyWorldGenerator.AddAsteroidPrefab(PrefabName, Position, Name);
 }
コード例 #12
0
 public override void Apply()
 {
     MyWorldGenerator.SetupBase(PrefabFile, Offset, AsteroidName, BeaconName);
 }
コード例 #13
0
 public abstract void SetupCharacter(MyWorldGenerator.Args generatorArgs);
コード例 #14
0
        // 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");
        }
コード例 #15
0
 public override void Apply()
 {
     MyWorldGenerator.AddPlanetPrefab(PrefabName, DefinitionName, Position, AddGPS);
 }
コード例 #16
0
 public abstract void SetupCharacterDefault(MyPlayer player, MyWorldGenerator.Args args);
コード例 #17
0
 public override void Apply()
 {
     MyWorldGenerator.AddPlanetPrefab(PrefabName, Name);
 }