1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details 2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt 3 4 #pragma once 5 6 #include "Input.h" 7 #include "ShipController.h" 8 9 // autopilot AI + input 10 class PlayerShipController : public ShipController { 11 public: 12 PlayerShipController(); 13 ~PlayerShipController(); 14 GetType()15 Type GetType() override { return PLAYER; } 16 void SaveToJson(Json &jsonObj, Space *s) override; 17 void LoadFromJson(const Json &jsonObj) override; 18 void PostLoadFixup(Space *s) override; 19 void StaticUpdate(float timeStep) override; 20 // Poll controls, set thruster states, gun states and target velocity 21 void PollControls(float timeStep, const bool force_rotation_damping, int *mouseMotion); IsMouseActive()22 bool IsMouseActive() const { return m_mouseActive; } SetDisableMouseFacing(bool disabled)23 void SetDisableMouseFacing(bool disabled) { m_disableMouseFacing = disabled; } GetSetSpeed()24 double GetSetSpeed() const override { return m_setSpeed; } ChangeSetSpeed(double delta)25 void ChangeSetSpeed(double delta) override { m_setSpeed += delta; } GetFlightControlState()26 FlightControlState GetFlightControlState() const override { return m_flightControlState; } 27 vector3d GetMouseDir() const; // in local frame 28 29 // Return the current mouse direction in camera space. 30 vector3d GetMouseViewDir() const; SetMouseForRearView(bool enable)31 void SetMouseForRearView(bool enable) { m_invertMouse = enable; } 32 void SetFlightControlState(FlightControlState s) override; GetLowThrustPower()33 float GetLowThrustPower() const { return m_lowThrustPower; } 34 void SetLowThrustPower(float power); 35 GetRotationDamping()36 bool GetRotationDamping() const { return m_rotationDamping; } 37 void SetRotationDamping(bool enabled); 38 void ToggleRotationDamping(); 39 void FireMissile(); 40 void ToggleSetSpeedMode(); 41 42 //targeting 43 //XXX AI should utilize one or more of these 44 Body *GetCombatTarget() const; 45 Body *GetNavTarget() const; 46 Body *GetSetSpeedTarget() const override; 47 void SetCombatTarget(Body *const target, bool setSpeedTo = false); 48 void SetNavTarget(Body *const target); 49 void SetSetSpeedTarget(Body *const target); 50 51 sigc::signal<void> onRotationDampingChanged; 52 sigc::signal<void> onChangeTarget; 53 sigc::signal<void> onChangeFlightControlState; 54 55 private: 56 struct InputBinding : public Input::InputFrame { 57 using InputFrame::InputFrame; 58 59 // Weapons 60 Action *targetObject; 61 Action *primaryFire; 62 Action *secondaryFire; 63 64 // Flight 65 Axis *pitch; 66 Axis *yaw; 67 Axis *roll; 68 Action *killRot; 69 Action *toggleRotationDamping; 70 71 // Manual Control 72 Axis *thrustForward; 73 Axis *thrustUp; 74 Axis *thrustLeft; 75 Action *thrustLowPower; 76 77 // Speed Control 78 Axis *speedControl; 79 Action *toggleSetSpeed; 80 81 void RegisterBindings() override; 82 } InputBindings; 83 84 // FIXME: separate the propusion controller from the input system, pass in wanted velocity correction directly. 85 friend class Propulsion; 86 87 bool IsAnyAngularThrusterKeyDown(); 88 bool IsAnyLinearThrusterKeyDown(); 89 //do a variety of checks to see if input is allowed 90 void CheckControlsLock(); 91 Body *m_combatTarget; 92 Body *m_navTarget; 93 Body *m_setSpeedTarget; 94 bool m_controlsLocked; 95 bool m_invertMouse; // used for rear view, *not* for invert Y-axis option (which is Pi::input->IsMouseYInvert) 96 bool m_mouseActive; 97 bool m_disableMouseFacing; 98 bool m_rotationDamping; 99 double m_mouseX; 100 double m_mouseY; 101 double m_setSpeed; 102 FlightControlState m_flightControlState; 103 float m_fovY; //for mouse acceleration adjustment 104 float m_joystickDeadzone; 105 float m_lowThrustPower; 106 int m_combatTargetIndex; //for PostLoadFixUp 107 int m_navTargetIndex; 108 int m_setSpeedTargetIndex; 109 vector3d m_mouseDir; 110 111 sigc::connection m_connRotationDampingToggleKey; 112 sigc::connection m_fireMissileKey; 113 sigc::connection m_setSpeedMode; 114 }; 115