// Create world using data received from server public void CreateWorldFromDataReceivedFromServer() { MyMwcLog.WriteLine("CreateWorldFromDataReceivedFromServer - START"); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("CreateWorldFromDataReceivedFromServer"); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MySession.BeforeLoad"); MySession.Static.BeforeLoad(m_checkpoint); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); CreateWorldFromDataReceivedFromServer_LoadCheckpoint(); bool canUseGenerator = m_sessionType.Value != MyMwcStartSessionRequestTypeEnum.EDITOR_SANDBOX && m_sessionType.Value != MyMwcStartSessionRequestTypeEnum.SANDBOX_OWN && MyFakes.ENABLE_GENERATED_ASTEROIDS; if (m_checkpoint.SectorObjectBuilder.FromGenerator && canUseGenerator) // When no sector on server, use procedural generator { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("ProceduralGenerator.Player"); if (m_checkpoint.PlayerObjectBuilder == null) { MyMwcObjectBuilder_SmallShip_Player playerShipObjectBuilder = CreatePlayerShip(); playerShipObjectBuilder.PositionAndOrientation.Position = Vector3.Zero; playerShipObjectBuilder.PositionAndOrientation.Up = Vector3.Up; playerShipObjectBuilder.PositionAndOrientation.Forward = Vector3.Forward; m_checkpoint.PlayerObjectBuilder = new MyMwcObjectBuilder_Player(100f, 10000f, 0f, null, playerShipObjectBuilder, null); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } UpdateSmallshipsOfferedByVendors(m_checkpoint); if (((m_checkpoint.SectorObjectBuilder.FromGenerator && MyFakes.ENABLE_GENERATED_ASTEROIDS) || canUseGenerator)) // When no sector on server, use procedural generator { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Generating sector"); //Use objects from server and generate new items into them //m_checkpoint.SectorObjectBuilder.SectorObjects = new List<MyMwcObjectBuilder_Base>(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Safe areas"); if (m_checkpoint.SectorObjectBuilder.SectorObjects == null) { m_checkpoint.SectorObjectBuilder.SectorObjects = new List<MyMwcObjectBuilder_Base>(); } MyMwcLog.WriteLine("Adding safe areas"); List<BoundingSphere> safeAreas = new List<BoundingSphere>(); foreach (MyMwcObjectBuilder_Base objectBuilder in m_checkpoint.SectorObjectBuilder.SectorObjects) { MyMwcObjectBuilder_DummyPoint dummyObjectBuilder = objectBuilder as MyMwcObjectBuilder_DummyPoint; if (dummyObjectBuilder != null && dummyObjectBuilder.DummyFlags.HasFlag(MyDummyPointFlags.SAFE_AREA)) { safeAreas.Add(new BoundingSphere(dummyObjectBuilder.PositionAndOrientation.Position, dummyObjectBuilder.Size.Length() / 2.0f)); } MyMwcObjectBuilder_VoxelMap voxelObjectBuilder = objectBuilder as MyMwcObjectBuilder_VoxelMap; if (voxelObjectBuilder != null) { MyMwcVector3Int sizeInVoxels = MyVoxelFiles.Get(voxelObjectBuilder.VoxelFile).SizeInVoxels; Vector3 sizeInMeters = new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES * sizeInVoxels.X, MyVoxelConstants.VOXEL_SIZE_IN_METRES * sizeInVoxels.Y, MyVoxelConstants.VOXEL_SIZE_IN_METRES * sizeInVoxels.Z); safeAreas.Add(new BoundingSphere(voxelObjectBuilder.PositionAndOrientation.Position, sizeInMeters.Length() / 2.0f)); } } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MyMwcLog.WriteLine("GenerateSector"); MySolarSystemMapSectorData sectorData = GenerateSector(m_sectorIdentifier.Position, m_checkpoint.SectorObjectBuilder.SectorObjects, safeAreas, m_checkpoint.SectorObjectBuilder.SectorObjects.Count > 0); //MySolarSystemMapSectorData sectorData = GenerateSectorData(); m_checkpoint.SectorObjectBuilder.AreaTemplate = sectorData.Area; m_checkpoint.SectorObjectBuilder.AreaMultiplier = sectorData.AreaInfluenceMultiplier; MySector.UseGenerator = true; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else if (!m_checkpoint.SectorObjectBuilder.AreaTemplate.HasValue) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Generating sector area data"); MySolarSystemMapSectorData sectorData = GenerateSectorData(); m_checkpoint.SectorObjectBuilder.AreaTemplate = sectorData.Area; m_checkpoint.SectorObjectBuilder.AreaMultiplier = sectorData.AreaInfluenceMultiplier; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } MyMwcLog.WriteLine("CreateFromSectorObjectBuilder"); CreateFromSectorObjectBuilder(m_checkpoint.SectorObjectBuilder); MyTrailerLoad.TrailerAnimation = null; // If null, then loop above didn't contain player's ship MyCommonDebugUtils.AssertRelease(MySession.PlayerShip != null); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Preload cockpit models"); MySmallShip playerShip = MySession.PlayerShip; // Pre-load player's cockpit interior models // IMPORTANT: Only data and no vertex buffers, because this method is called from Update and not from Draw MyModels.GetModelOnlyData(MySession.PlayerShip.CockpitInteriorModelEnum); MyModels.GetModelOnlyData(MySession.PlayerShip.CockpitGlassModelEnum); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); //0002325: AI - Add friend bot to story and sandbox, he will be there by default. if (!IsEditorActive() && MyFakes.SPAWN_FRIENDS == true) { MySession.PlayerFriends.Clear();// when saving bots will be enabled please remove this if (MySession.PlayerFriends.Count == 0) { MySmallShipBot bot = CreateFakeBot("Friend", MyMwcObjectBuilder_SmallShip_TypesEnum.GREISER, MySession.PlayerShip.WorldMatrix.Translation + new Vector3(0, 30, 30), 1f, MyMwcObjectBuilder_FactionEnum.Euroamerican); MySession.PlayerFriends.Add(bot); bot.Follow(MySession.PlayerShip); bot.Save = false; bot = CreateFakeBot("Friend", MyMwcObjectBuilder_SmallShip_TypesEnum.GREISER, MySession.PlayerShip.WorldMatrix.Translation + new Vector3(0, -30, 30), 1f, MyMwcObjectBuilder_FactionEnum.Euroamerican); MySession.PlayerFriends.Add(bot); bot.Follow(MySession.PlayerShip); bot.Save = false; } } MyMwcLog.WriteLine("MySession.Static.AfterLoad"); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("AfterLoad"); MySession.Static.AfterLoad(m_checkpoint); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Side missions"); // Side missions foreach (var dummy in MyEntities.GetEntities().OfType<MyDummyPoint>()) { if ((dummy.DummyFlags & MyDummyPointFlags.SIDE_MISSION) != 0) { MyMwcLog.WriteLine("Side missions"); // TODO: Choose random submission var sideMission = new MySideMissionAssassination(new MyMissionBase.MyMissionLocation(m_checkpoint.CurrentSector.Position, dummy.EntityId.Value.NumericValue)); if (MyMissions.GetMissionByID(sideMission.ID) == null) { MyMissions.AddMission(sideMission); } } } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MyMwcLog.WriteLine("MySession.Static.Player.TravelEnter"); //Unpacks player friends needed for mission script MySession.Static.Player.TravelEnter(); if (MySession.Is25DSector) MyGlobalEvents.DisableAllGlobalEvents(); else MyGlobalEvents.EnableAllGlobalEvents(); // Init active mission System.Diagnostics.Debug.Assert(MyMissions.ActiveMission == null); MyMwcLog.WriteLine("Active mission load - START"); if (GetGameType() == MyGuiScreenGamePlayType.GAME_STORY && (MyMultiplayerGameplay.Static == null || MyMultiplayerGameplay.Static.IsHost)) { MyMwcLog.WriteLine("Starting story mission"); if (m_checkpoint.ActiveMissionID != -1) { MyMwcLog.WriteLine("ActiveMissionID: " + m_checkpoint.ActiveMissionID); MyMission mission = MyMissions.GetMissionByID((MyMissionID)m_checkpoint.ActiveMissionID) as MyMission; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Load active mission"); if (mission.IsMainSector) { mission.InsertRequiredActors(); } mission.Load(); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); } else { MyMwcLog.WriteLine("ActiveMissionID: none"); if (m_missionToStart.HasValue) { MyMission mission = MyMissions.GetMissionByID(m_missionToStart.Value) as MyMission; MyScriptWrapper.DebugSetFactions(mission); mission.Accept(); m_missionToStart = null; } } MyMissions.RefreshAvailableMissions(); if (m_travelReason == MyMwcTravelTypeEnum.SOLAR) { if (MyMissions.ActiveMission == null || MyMissions.ActiveMission.MovePlayerToMadelynHangar) { if (MyMissionBase.IsPlayerShipNearMadelyn()) { if (MyMissions.ActiveMission != null) MyMissionBase.MovePlayerAndFriendsToHangar(MyMissions.ActiveMission.RequiredActors); else MyMissionBase.MovePlayerAndFriendsToHangar(new MyActorEnum[] { MyActorEnum.MARCUS, MyActorEnum.TARJA, MyActorEnum.VALENTIN }); } } } } else if (GetGameType() == MyGuiScreenGamePlayType.GAME_SANDBOX) { MyMwcLog.WriteLine("Starting sandbox mission"); MyMissions.StartSandboxMission(m_checkpoint.CurrentSector.Position); } MyMwcLog.WriteLine("Active mission load - END"); MyEntities.UpdateAfterSimulation(); //Updates AABBs of objects if (MyMultiplayerGameplay.IsStory()) { MyMultiplayerGameplay.MakeInventoryItemsTradeable(MySession.PlayerShip); } if (MyFakes.MWBUILDER) { MyVoxelMap voxelMap = null; if (MyVoxelMaps.GetVoxelMapsCount() == 0) { // MyMwcObjectBuilder_VoxelMap voxelMapOb = new MyMwcObjectBuilder_VoxelMap(Vector3.Zero, MyMwcVoxelFilesEnum.Cube_512x512x512, MyMwcVoxelMaterialsEnum.Stone_01); // voxelMap = (MyVoxelMap)MyEntities.CreateFromObjectBuilderAndAdd(null, voxelMapOb, Matrix.Identity); voxelMap = new MyVoxelMap(); voxelMap.Init(Vector3.Zero, new MyMwcVector3Int(1024, 1024, 1024), MyMwcVoxelMaterialsEnum.Stone_01); //MyVoxelImport.Fill(voxelMap); MyVoxelImport.FillEmpty(voxelMap); MyEntities.Add(voxelMap); voxelMap.SetPosition(Vector3.Zero); MyVoxelGenerator.CreateSphere(voxelMap, new BoundingSphere(Vector3.Zero, 1024)); voxelMap.InvalidateCache(new MyMwcVector3Int(0, 0, 0), new MyMwcVector3Int(1024, 1024, 1024)); MyVoxelMaps.RecalcVoxelMaps(); voxelMap.UpdateAABBHr(); voxelMap.SaveVoxelContents(Path.Combine(MyMinerGame.Static.RootDirectory, "VoxelMaps", MyVoxelFiles.ExportFile + ".vox")); //MyVoxelGenerator.CutOutBoxRelative(voxelMap, new Vector3(0, 0.5f, 0), new Vector3(1, 1, 1)); /* MyVoxelGenerator.ChangeMaterialInBoxRelative(voxelMap, new Vector3(0, 0.49f, 0), new Vector3(1, 0.5f, 1), MyMwcVoxelMaterialsEnum.Uranite_01); MyVoxelGenerator.ChangeMaterialInBoxRelative(voxelMap, new Vector3(0, 0.2f, 0), new Vector3(1, 0.49f, 1), MyMwcVoxelMaterialsEnum.Nickel_01); MyVoxelGenerator.ChangeMaterialInBoxRelative(voxelMap, new Vector3(0, 0.0f, 0), new Vector3(1, 0.1f, 1), MyMwcVoxelMaterialsEnum.Lava_01); */ } else { voxelMap = MyVoxelMaps.GetVoxelMaps()[0]; MyPhysics.physicsSystem.GravitationPoints.Clear(); MyPhysics.physicsSystem.GravitationPoints.Add(new Tuple<BoundingSphere,float>(new BoundingSphere(voxelMap.WorldAABB.GetCenter(), voxelMap.WorldAABB.Size().Length()), 2000)); // voxelMap.Init(Vector3.Zero, new MyMwcVector3Int(1024, 1024, 1024), MyMwcVoxelMaterialsEnum.Stone_01); // MyVoxelImport.Fill(voxelMap); // MyVoxelGenerator.CutOutBoxRelative(voxelMap, new Vector3(0, 0.3f, 0), new Vector3(1, 1, 1)); // string name = Path.Combine(MyFileSystemUtils.GetApplicationUserDataFolder(), "VoxelMap_0_mikrogen.vox"); // voxelMap.SaveVoxelContents(name); // voxelMap.SetName("VoxelMap_0_mikrogen.vox"); // voxelMap.Init(null, Vector3.Zero, null); } MySpectator.Position = voxelMap.WorldAABB.GetCenter(); MyCamera.SetViewMatrix(MySpectator.GetViewMatrix()); } MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MyMwcLog.WriteLine("CreateWorldFromDataReceivedFromServer - END"); }