Example #1
0
        void FinishLoad()
        {
            Game.Saves.Selected = -1;
            ui.OpenScene("hud");
            var shp = Game.GameData.GetShip(session.PlayerShip);

            //Set up player object + camera
            player       = new GameObject(shp.ModelFile.LoadFile(Game.ResourceManager), Game.ResourceManager);
            control      = new ShipPhysicsComponent(player);
            control.Ship = shp;
            shipInput    = new ShipInputComponent(player);
            player.Components.Add(shipInput);
            player.Components.Add(control);
            weapons = new WeaponControlComponent(player);
            player.Components.Add(weapons);
            player.Components.Add(new CDamageFuseComponent(player, shp.Fuses));

            player.SetLocalTransform(session.PlayerOrientation * Matrix4x4.CreateTranslation(session.PlayerPosition));
            player.PhysicsComponent.Mass = shp.Mass;
            playerHealth               = new CHealthComponent(player);
            playerHealth.MaxHealth     = shp.Hitpoints;
            playerHealth.CurrentHealth = shp.Hitpoints;
            player.Components.Add(playerHealth);
            if (shp.Mass < 0)
            {
                FLLog.Error("Ship", "Mass < 0");
            }

            player.Tag = GameObject.ClientPlayerTag;
            foreach (var equipment in session.Items.Where(x => !string.IsNullOrEmpty(x.Hardpoint)))
            {
                EquipmentObjectManager.InstantiateEquipment(player, Game.ResourceManager, EquipmentType.LocalPlayer, equipment.Hardpoint, equipment.Equipment);
            }
            powerCore = player.GetComponent <PowerCoreComponent>();
            if (powerCore == null)
            {
                throw new Exception("Player launched without a powercore equipped!");
            }
            camera = new ChaseCamera(Game.RenderContext.CurrentViewport, Game.GameData.Ini.Cameras);
            camera.ChasePosition    = session.PlayerPosition;
            camera.ChaseOrientation = player.LocalTransform.ClearTranslation();
            var offset = shp.ChaseOffset;

            camera.DesiredPositionOffset = offset;
            if (shp.CameraHorizontalTurnAngle > 0)
            {
                camera.HorizontalTurnAngle = shp.CameraHorizontalTurnAngle;
            }
            if (shp.CameraVerticalTurnUpAngle > 0)
            {
                camera.VerticalTurnUpAngle = shp.CameraVerticalTurnUpAngle;
            }
            if (shp.CameraVerticalTurnDownAngle > 0)
            {
                camera.VerticalTurnDownAngle = shp.CameraVerticalTurnDownAngle;
            }
            camera.Reset();

            sysrender           = new SystemRenderer(camera, Game.GameData, Game.ResourceManager, Game);
            sysrender.ZOverride = true; //Draw all with regular Z
            world = new GameWorld(sysrender);
            world.LoadSystem(sys, Game.ResourceManager, false, session.SpawnTime);
            session.WorldReady();
            player.World = world;
            world.AddObject(player);
            world.RenderUpdate  += World_RenderUpdate;
            world.PhysicsUpdate += World_PhysicsUpdate;
            player.Register(world.Physics);
            Game.Sound.PlayMusic(sys.MusicSpace);
            //world.Physics.EnableWireframes(debugphysics);
            cur_arrow                = Game.ResourceManager.GetCursor("arrow");
            cur_cross                = Game.ResourceManager.GetCursor("cross");
            cur_reticle              = Game.ResourceManager.GetCursor("fire_neutral");
            current_cur              = cur_cross;
            Game.Keyboard.TextInput += Game_TextInput;
            Game.Keyboard.KeyDown   += Keyboard_KeyDown;
            Game.Mouse.MouseDown    += Mouse_MouseDown;
            Game.Mouse.MouseUp      += Mouse_MouseUp;
            input = new InputManager(Game);
            input.ToggleActivated += Input_ToggleActivated;
            input.ToggleUp        += Input_ToggleUp;
            pilotcomponent         = new AutopilotComponent(player);
            player.Components.Add(pilotcomponent);
            player.World              = world;
            world.MessageBroadcasted += World_MessageBroadcasted;
            Game.Sound.ResetListenerVelocity();
            FadeIn(0.5, 0.5);
        }
Example #2
0
        void FinishLoad()
        {
            var shp = Game.GameData.GetShip(session.PlayerShip);

            //Set up player object + camera
            player       = new GameObject(shp.ModelFile.LoadFile(Game.ResourceManager), Game.ResourceManager, true, false);
            control      = new ShipPhysicsComponent(player);
            control.Ship = shp;
            shipInput    = new ShipInputComponent(player);
            player.Components.Add(shipInput);
            player.Components.Add(control);
            weapons = new WeaponControlComponent(player);
            player.Components.Add(weapons);
            player.Transform             = session.PlayerOrientation * Matrix4x4.CreateTranslation(session.PlayerPosition);
            player.PhysicsComponent.Mass = shp.Mass;
            if (shp.Mass < 0)
            {
                FLLog.Error("Ship", "Mass < 0");
            }
            player.Nickname = "player";
            foreach (var equipment in session.Mounts)
            {
                var equip = Game.GameData.GetEquipment(equipment.Item);
                if (equip == null)
                {
                    continue;
                }
                EquipmentObjectManager.InstantiateEquipment(player, Game.ResourceManager, true, equipment.Hardpoint, equip);
            }
            powerCore = player.GetComponent <PowerCoreComponent>();
            if (powerCore == null)
            {
                throw new Exception("Player launched without a powercore equipped!");
            }
            camera = new ChaseCamera(Game.Viewport);
            camera.ChasePosition    = session.PlayerPosition;
            camera.ChaseOrientation = player.Transform.ClearTranslation();
            var offset = shp.ChaseOffset;

            camera.DesiredPositionOffset = offset;
            if (shp.CameraHorizontalTurnAngle > 0)
            {
                camera.HorizontalTurnAngle = shp.CameraHorizontalTurnAngle;
            }
            if (shp.CameraVerticalTurnUpAngle > 0)
            {
                camera.VerticalTurnUpAngle = shp.CameraVerticalTurnUpAngle;
            }
            if (shp.CameraVerticalTurnDownAngle > 0)
            {
                camera.VerticalTurnDownAngle = shp.CameraVerticalTurnDownAngle;
            }
            camera.Reset();

            sysrender = new SystemRenderer(camera, Game.GameData, Game.ResourceManager, Game);
            world     = new GameWorld(sysrender);
            world.LoadSystem(sys, Game.ResourceManager);
            session.WorldReady();
            player.World = world;
            world.Objects.Add(player);
            world.RenderUpdate  += World_RenderUpdate;
            world.PhysicsUpdate += World_PhysicsUpdate;
            player.Register(world.Physics);
            Game.Sound.PlayMusic(sys.MusicSpace);
            debugphysics = new PhysicsDebugRenderer();
            //world.Physics.EnableWireframes(debugphysics);
            cur_arrow                = Game.ResourceManager.GetCursor("cross");
            cur_reticle              = Game.ResourceManager.GetCursor("fire_neutral");
            current_cur              = cur_arrow;
            Game.Keyboard.TextInput += Game_TextInput;
            Game.Keyboard.KeyDown   += Keyboard_KeyDown;
            Game.Mouse.MouseDown    += Mouse_MouseDown;
            input = new InputManager(Game);
            input.ToggleActivated       += Input_ToggleActivated;
            input.ToggleUp              += Input_ToggleUp;
            pilotcomponent               = new AutopilotComponent(player);
            pilotcomponent.DockComplete += Pilotcomponent_DockComplete;
            player.Components.Add(pilotcomponent);
            player.World              = world;
            world.MessageBroadcasted += World_MessageBroadcasted;
            Game.Sound.ResetListenerVelocity();
            FadeIn(0.5, 0.5);
        }