[Add] Set speed control mode.
This commit is contained in:
		
							parent
							
								
									762d7fcd3e
								
							
						
					
					
						commit
						7b92a3fdf9
					
				| @ -23,12 +23,14 @@ void Player::Save(void) { | ||||
|   using namespace Serializer::Write; | ||||
|   Ship::Save(); | ||||
|   wr_int(static_cast<int>(m_flightControlState)); | ||||
|   wr_float(m_setSpeed); | ||||
| } | ||||
| 
 | ||||
| void Player::Load(void) { | ||||
|   using namespace Serializer::Read; | ||||
|   Ship::Load(); | ||||
|   m_flightControlState = static_cast<FlightControlState>(rd_int()); | ||||
|   m_setSpeed = rd_float(); | ||||
| } | ||||
| 
 | ||||
| void Player::SetFlightControlState(enum FlightControlState s) { | ||||
| @ -41,6 +43,9 @@ void Player::SetFlightControlState(enum FlightControlState s) { | ||||
|     } else if(target) { | ||||
|       AIInstruct(Ship::DO_KILL, target); | ||||
|     } | ||||
|   } else if(m_flightControlState == CONTROL_FIXSPEED) { | ||||
|     AIClearInstructions(); | ||||
|     m_setSpeed = GetVelocity().Length(); | ||||
|   } else { | ||||
|     AIClearInstructions(); | ||||
|   } | ||||
| @ -65,21 +70,35 @@ void Player::SetDockedWith(SpaceStation* s, int port) { | ||||
| } | ||||
| 
 | ||||
| void Player::TimeStepUpdate(const float timeStep) { | ||||
|   if(GetFlightState() == Ship::FLYING) { | ||||
|     /* When world view not selected. */ | ||||
|     if(!polledControlsThisTurn) { | ||||
|       const float time_accel = L3D::GetTimeAccel(); | ||||
|       const float ta2 = time_accel*time_accel; | ||||
|       ClearThrusterState(); | ||||
|       /* Still must apply rotation damping. */ | ||||
|       vector3d damping = CalcRotDamping(); | ||||
|       damping *= 1.0f/ta2; | ||||
|       SetAngThrusterState(0, -damping.x); | ||||
|       SetAngThrusterState(1, -damping.y); | ||||
|       SetAngThrusterState(2, -damping.z); | ||||
|     } | ||||
|   } | ||||
|   ClearThrusterState(); | ||||
|   polledControlsThisTurn = false; | ||||
|   if(L3D::GetView() == L3D::worldView) PollControls(); | ||||
| 
 | ||||
|   if(GetFlightState() == Ship::FLYING) { | ||||
|     switch(m_flightControlState) { | ||||
|       case CONTROL_MANUAL: | ||||
|         /* When world view not selected. */ | ||||
|         if(!polledControlsThisTurn) { | ||||
|           const float time_accel = L3D::GetTimeAccel(); | ||||
|           const float ta2 = time_accel*time_accel; | ||||
|           /* We still must apply rotation damping. */ | ||||
|           vector3d damping = CalcRotDamping(); | ||||
|           damping *= 1.0f/ta2; | ||||
|           SetAngThrusterState(0, -damping.x); | ||||
|           SetAngThrusterState(1, -damping.y); | ||||
|           SetAngThrusterState(2, -damping.z); | ||||
|         } | ||||
|         break; | ||||
|       case CONTROL_FIXSPEED: | ||||
|         AIAccelToModelRelativeVelocity(vector3d(0,0,-m_setSpeed)); | ||||
|         break; | ||||
|       case CONTROL_AUTOPILOT: | ||||
|         break; | ||||
|     } | ||||
|   } else { | ||||
|     m_flightControlState = CONTROL_MANUAL; | ||||
|     AIClearInstructions(); | ||||
|   } | ||||
|   Ship::TimeStepUpdate(timeStep); | ||||
| } | ||||
| 
 | ||||
| @ -129,6 +148,10 @@ void Player::PollControls(void) { | ||||
|       angThrust.x = m_mouseCMov[1] / MOUSE_CTRL_AREA; | ||||
|     } | ||||
| 
 | ||||
|     if(m_flightControlState == CONTROL_FIXSPEED) { | ||||
|       if(L3D::KeyState(SDLK_RETURN)) m_setSpeed += MAX(m_setSpeed*0.05, 1.0); | ||||
|       if(L3D::KeyState(SDLK_RSHIFT)) m_setSpeed -= MAX(m_setSpeed*0.05, 1.0); | ||||
|     } | ||||
|     if(L3D::KeyState(SDLK_w)) SetThrusterState(ShipType::THRUSTER_REAR,   1.0f); | ||||
|     if(L3D::KeyState(SDLK_s)) SetThrusterState(ShipType::THRUSTER_FRONT,  1.0f); | ||||
|     if(L3D::KeyState(SDLK_2)) SetThrusterState(ShipType::THRUSTER_TOP,    1.0f); | ||||
| @ -271,6 +294,19 @@ void Player::DrawHUD(const Frame* cam_frame) { | ||||
|     glPopMatrix(); | ||||
|   } | ||||
| 
 | ||||
|   if(m_flightControlState == CONTROL_FIXSPEED) { | ||||
|     char buf[128]; | ||||
|     if(m_setSpeed > 1000) { | ||||
|       snprintf(buf, sizeof(buf), "Set speed %.2f km/s", m_setSpeed*0.001); | ||||
|     } else { | ||||
|       snprintf(buf, sizeof(buf), "Set speed %.0f m/s", m_setSpeed); | ||||
|     } | ||||
|     glPushMatrix(); | ||||
|     glTranslatef(200, 66, 0); | ||||
|     Gui::Screen::RenderString(buf); | ||||
|     glPopMatrix(); | ||||
|   } | ||||
| 
 | ||||
|   /* Altitude. */ | ||||
|   if(GetFrame()->m_astroBody) { | ||||
|     double radius = GetFrame()->m_astroBody->GetRadius(); | ||||
|  | ||||
| @ -13,7 +13,7 @@ public: | ||||
|   void DrawHUD(const Frame* cam_frame); | ||||
|   virtual void SetDockedWith(SpaceStation*, int port); | ||||
|   void TimeStepUpdate(const float timeStep); | ||||
|   enum FlightControlState { CONTROL_MANUAL, CONTROL_AUTOPILOT }; | ||||
|   enum FlightControlState { CONTROL_MANUAL, CONTROL_FIXSPEED, CONTROL_AUTOPILOT }; | ||||
|   FlightControlState GetFlightControlState(void) const { return m_flightControlState; } | ||||
|   void SetFlightControlState(FlightControlState s); | ||||
| protected: | ||||
| @ -25,5 +25,6 @@ private: | ||||
|   float m_mouseCMov[2]; | ||||
|   bool polledControlsThisTurn; | ||||
|   enum FlightControlState m_flightControlState; | ||||
|   float m_setSpeed; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -54,6 +54,7 @@ WorldView::WorldView(void): View() { | ||||
|   m_flightControlButton = new Gui::MultiStateImageButton(); | ||||
|   m_flightControlButton->SetShortcut(SDLK_F5, KMOD_NONE); | ||||
|   m_flightControlButton->AddState(Player::CONTROL_MANUAL, "icons/manual_control.png", "Manual control."); | ||||
|   m_flightControlButton->AddState(Player::CONTROL_FIXSPEED, "icons/manual_control.png", "Computer speed control."); | ||||
|   m_flightControlButton->AddState(Player::CONTROL_AUTOPILOT, "icons/autopilot.png", "Autopilot on."); | ||||
|   m_flightControlButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnChangeFlightState)); | ||||
|   m_rightButtonBar->Add(m_flightControlButton, 2, 2); | ||||
| @ -223,9 +224,6 @@ void WorldView::Update(void) { | ||||
|   } else { | ||||
|     m_hyperspaceButton->Hide(); | ||||
|   } | ||||
|   /* Player control inputs. */ | ||||
|   if(L3D::player) | ||||
|     L3D::player->PollControls(); | ||||
| 
 | ||||
|   Body* target = L3D::player->GetNavTarget(); | ||||
|   if(target) { | ||||
| @ -239,7 +237,15 @@ void WorldView::Update(void) { | ||||
|     m_launchButton->Show(); | ||||
|     m_flightControlButton->Hide(); | ||||
|   } else { | ||||
|     m_flightStatus->SetText("Manual Controls"); | ||||
|     Player::FlightControlState fstate = L3D::player->GetFlightControlState(); | ||||
|     switch(fstate) { | ||||
|       case Player::CONTROL_MANUAL: | ||||
|         m_flightStatus->SetText("Manual Control"); break; | ||||
|       case Player::CONTROL_FIXSPEED: | ||||
|         m_flightStatus->SetText("Speed Control"); break; | ||||
|       case Player::CONTROL_AUTOPILOT: | ||||
|         m_flightStatus->SetText("Autopilot"); break; | ||||
|     } | ||||
|     m_launchButton->Hide(); | ||||
|     m_flightControlButton->Show(); | ||||
|   } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Rtch90
						Rtch90