diff --git a/icons/blastoff.png b/icons/blastoff.png new file mode 100644 index 0000000..398cb3e Binary files /dev/null and b/icons/blastoff.png differ diff --git a/icons/hyperspace_f8.png b/icons/hyperspace_f8.png index badcc43..412962d 100644 Binary files a/icons/hyperspace_f8.png and b/icons/hyperspace_f8.png differ diff --git a/icons/labels_off.png b/icons/labels_off.png index d0303b9..eae8223 100644 Binary files a/icons/labels_off.png and b/icons/labels_off.png differ diff --git a/icons/labels_on.png b/icons/labels_on.png index e3ce687..461ed66 100644 Binary files a/icons/labels_on.png and b/icons/labels_on.png differ diff --git a/icons/sectorview_f6_systeminfo.png b/icons/sectorview_f6_systeminfo.png index c789f96..c6efe22 100644 Binary files a/icons/sectorview_f6_systeminfo.png and b/icons/sectorview_f6_systeminfo.png differ diff --git a/icons/wheels_down.png b/icons/wheels_down.png index 0ca9961..e5f0716 100644 Binary files a/icons/wheels_down.png and b/icons/wheels_down.png differ diff --git a/icons/wheels_up.png b/icons/wheels_up.png index 9b2af35..97ac359 100644 Binary files a/icons/wheels_up.png and b/icons/wheels_up.png differ diff --git a/icons/zoom_in_f7.png b/icons/zoom_in_f7.png index 3f9618b..fd3b036 100644 Binary files a/icons/zoom_in_f7.png and b/icons/zoom_in_f7.png differ diff --git a/icons/zoom_out_f8.png b/icons/zoom_out_f8.png index d341cce..84faaf0 100644 Binary files a/icons/zoom_out_f8.png and b/icons/zoom_out_f8.png differ diff --git a/src/player.cpp b/src/player.cpp index 58b0f95..fa5f0d4 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -54,17 +54,19 @@ void Player::ApplyExternalViewRotation(matrix4x4d& m) { } void Player::TimeStepUpdate(const float timeStep) { - /* 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); + 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); + } } polledControlsThisTurn = false; Ship::TimeStepUpdate(timeStep); @@ -91,70 +93,68 @@ void Player::PollControls(void) { m_external_view_dist = MAX(50, m_external_view_dist); /* When landed don't let external view look from below. */ - if(m_isLanded) m_external_view_rotx = CLAMP(m_external_view_rotx, -170.0, -10); + if(GetFlightState() == LANDED) m_external_view_rotx = CLAMP(m_external_view_rotx, -170.0, -10); } - if((time_accel == 0) || GetDockedWith()) { + if((time_accel == 0) || GetDockedWith() || + (GetFlightState() != FLYING)) { return; } - ClearThrusterState(); + /* If flying. */ + { + ClearThrusterState(); - vector3f angThrust(0.0f); + vector3f angThrust(0.0f); - if(L3D::MouseButtonState(3)) { - float restitution = powf(MOUSE_RESTITUTION, L3D::GetTimeStep()); - L3D::GetMouseMotion(mouseMotion); - m_mouseCMov[0] += mouseMotion[0]; - m_mouseCMov[1] += mouseMotion[1]; - m_mouseCMov[0] = CLAMP(m_mouseCMov[0]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); - m_mouseCMov[1] = CLAMP(m_mouseCMov[1]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); - angThrust.y = -m_mouseCMov[0] / MOUSE_CTRL_AREA; - angThrust.x = m_mouseCMov[1] / MOUSE_CTRL_AREA; - } - - 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); - if(L3D::KeyState(SDLK_x)) SetThrusterState(ShipType::THRUSTER_BOTTOM,1.0f); - if(L3D::KeyState(SDLK_a)) SetThrusterState(ShipType::THRUSTER_LEFT, 1.0f); - if(L3D::KeyState(SDLK_d)) SetThrusterState(ShipType::THRUSTER_RIGHT, 1.0f); - - if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && - L3D::MouseButtonState(3))) SetGunState(0, 1); - else SetGunState(0,0); - - /* No torques at huge time accels -- ODE hates it. */ - if(time_accel <= 10) { - if(L3D::GetCamType() != L3D::CAM_EXTERNAL) { - if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1; - if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1; - if(L3D::KeyState(SDLK_UP)) angThrust.x += -1; - if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1; + if(L3D::MouseButtonState(3)) { + float restitution = powf(MOUSE_RESTITUTION, L3D::GetTimeStep()); + L3D::GetMouseMotion(mouseMotion); + m_mouseCMov[0] += mouseMotion[0]; + m_mouseCMov[1] += mouseMotion[1]; + m_mouseCMov[0] = CLAMP(m_mouseCMov[0]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); + m_mouseCMov[1] = CLAMP(m_mouseCMov[1]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); + angThrust.y = -m_mouseCMov[0] / MOUSE_CTRL_AREA; + angThrust.x = m_mouseCMov[1] / MOUSE_CTRL_AREA; } - /* Rotation damping. */ - vector3d damping = CalcRotDamping(); - angThrust.x -= damping.x; - angThrust.y -= damping.y; - angThrust.z -= damping.z; + 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); + if(L3D::KeyState(SDLK_x)) SetThrusterState(ShipType::THRUSTER_BOTTOM, 1.0f); + if(L3D::KeyState(SDLK_a)) SetThrusterState(ShipType::THRUSTER_LEFT, 1.0f); + if(L3D::KeyState(SDLK_d)) SetThrusterState(ShipType::THRUSTER_RIGHT, 1.0f); - /* - * Divided by time step so controls don't go totally insane when - * used at 10x accel. - */ - angThrust *= 1.0f/ta2; - SetAngThrusterState(0, angThrust.x); - SetAngThrusterState(1, angThrust.y); - SetAngThrusterState(2, angThrust.z); - } - if(time_accel > 10) { - dBodySetAngularVel(m_body, 0, 0, 0); - } + if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) SetGunState(0,1); + else SetGunState(0,0); - if(GetNavTarget() && L3D::KeyState(SDLK_END)) { - /* Temp test: Kill ("end") the target. */ - Space::KillBody(GetNavTarget()); + /* No torques at huge time accels -- ODE doesn't like it. */ + if(time_accel <= 10) { + if(L3D::GetCamType() != L3D::CAM_EXTERNAL) { + if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1; + if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1; + if(L3D::KeyState(SDLK_UP)) angThrust.x += -1; + if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1; + } + /* Rotation damping. */ + vector3d damping = CalcRotDamping(); + + angThrust.x -= damping.x; + angThrust.y -= damping.y; + angThrust.z -= damping.z; + + /* + * Dividing by time step so controls don't go insane when + * used at 10x accel. + */ + angThrust *= 1.0f/ta2; + SetAngThrusterState(0, angThrust.x); + SetAngThrusterState(1, angThrust.y); + SetAngThrusterState(2, angThrust.z); + } + if(time_accel > 10) { + dBodySetAngularVel(m_body, 0, 0, 0); + } } } diff --git a/src/sector_view.cpp b/src/sector_view.cpp index f438f4b..79dd62f 100644 --- a/src/sector_view.cpp +++ b/src/sector_view.cpp @@ -19,15 +19,15 @@ SectorView::SectorView(void) : GenericSystemView() { Gui::ImageButton* ib = new Gui::ImageButton("icons/sectorview_f6_systeminfo.png"); ib->onClick.connect(sigc::mem_fun(this, &SectorView::OnClickSystemInfo)); - ib->SetShortcut(SDLK_F6, KMOD_NONE); + ib->SetShortcut(SDLK_F5, KMOD_NONE); m_rightButtonBar->Add(ib, 2, 2); m_zoomInButton = new Gui::ImageButton("icons/zoom_in_f7.png"); - m_zoomInButton->SetShortcut(SDLK_F7, KMOD_NONE); + m_zoomInButton->SetShortcut(SDLK_F6, KMOD_NONE); m_rightButtonBar->Add(m_zoomInButton, 34, 2); m_zoomOutButton = new Gui::ImageButton("icons/zoom_out_f8.png"); - m_zoomOutButton->SetShortcut(SDLK_F8, KMOD_NONE); + m_zoomOutButton->SetShortcut(SDLK_F7, KMOD_NONE); m_rightButtonBar->Add(m_zoomOutButton, 66, 2); m_gluDiskDlist = glGenLists(1); diff --git a/src/ship.cpp b/src/ship.cpp index 11dc6a4..a3932c2 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -23,16 +23,17 @@ static ObjParams params = { }; Ship::Ship(ShipType::Type shipType) : DynamicBody() { - m_isLanded = false; - m_testLanded = false; - m_wheelTransition = 0; - m_wheelState = 0; - m_dockedWith = 0; - dockingTimer = 0; - m_navTarget = 0; - m_combatTarget = 0; - m_shipType = shipType; - m_angThrusters[0] = m_angThrusters[1] = m_angThrusters[2] = 0; + m_flightState = FLYING; + m_testLanded = false; + m_launchLockTimeout = 0; + m_wheelTransition = 0; + m_wheelState = 0; + m_dockedWith = 0; + dockingTimer = 0; + m_navTarget = 0; + m_combatTarget = 0; + m_shipType = shipType; + m_angThrusters[0] = m_angThrusters[1] = m_angThrusters[2] = 0; m_laserCollisionObj.owner = this; m_equipment = EquipSet(shipType); for(int i = 0; i < ShipType::GUNMOUNT_MAX; i++) { @@ -56,7 +57,8 @@ void Ship::UpdateMass(void) { bool Ship::OnCollision(Body* b, Uint32 flags) { if(b->GetType() == Object::PLANET) { - if(m_isLanded) return false; + /* Geoms still enabled when landed. */ + if(m_flightState != FLYING) return false; else m_testLanded = true; } return true; @@ -82,7 +84,9 @@ void Ship::ClearThrusterState(void) { SetAngThrusterState(1, 0.0f); SetAngThrusterState(2, 0.0f); - for(int i = 0; i < ShipType::THRUSTER_MAX; i++) m_thrusters[i] = 0; + if(m_launchLockTimeout == 0) { + for(int i = 0; i < ShipType::THRUSTER_MAX; i++) m_thrusters[i] = 0; + } } /* Hyperspace range is: @@ -107,13 +111,34 @@ void Ship::CalcStats(shipstats_t* stats) { stats->hyperspace_range = 200 * hyperclass * hyperclass / stats->total_mass; } +void Ship::Blastoff(void) { + if(m_flightState != LANDED) return; + + ClearThrusterState(); + m_flightState = FLYING; + m_testLanded = false; + m_dockedWith = 0; + m_launchLockTimeout = 1.0; /* One second of applying thrusters. */ + + Enable(); + const double planetRadius = GetFrame()->m_astroBody->GetRadius(); + vector3d up = vector3d::Normalize(GetPosition()); + dBodySetLinearVel(m_body, 0, 0, 0); + dBodySetAngularVel(m_body, 0, 0, 0); + dBodySetForce(m_body, 0, 0, 0); + dBodySetTorque(m_body, 0, 0, 0); + SetPosition(up*planetRadius+10.0*up); + SetThrusterState(ShipType::THRUSTER_TOP, 1.0f); +} + void Ship::TestLanded(void) { + if(m_launchLockTimeout != 0) return; if(GetFrame()->m_astroBody) { const dReal* vel = dBodyGetLinearVel(m_body); double speed = vector3d(vel[0], vel[1], vel[2]).Length(); const double planetRadius = GetFrame()->m_astroBody->GetRadius(); - if(speed < 15) { + if(speed < 20) { printf("Landed!\n"); /* Orient the damn thing right! */ @@ -138,7 +163,7 @@ void Ship::TestLanded(void) { */ dBodyDisable(m_body); ClearThrusterState(); - m_isLanded = true; + m_flightState = LANDED; m_testLanded = false; } } @@ -148,6 +173,10 @@ void Ship::TimeStepUpdate(const float timeStep) { dockingTimer = (dockingTimer-timeStep > 0 ? dockingTimer-timeStep : 0); /* ODE tri mesh likes to know our old position. */ TriMeshUpdateLastPos(); + + m_launchLockTimeout -= timeStep; + if(m_launchLockTimeout < 0) m_launchLockTimeout = 0; + const ShipType& stype = GetShipType(); for(int i = 0; i < ShipType::THRUSTER_MAX; i++) { float force = timeStep * stype.linThrust[i] * m_thrusters[i]; @@ -302,7 +331,7 @@ static void render_coll_mesh(const CollMesh* m) { } void Ship::Render(const Frame* camFrame) { - if((!dBodyIsEnabled(m_body)) && !m_isLanded) return; + if((!dBodyIsEnabled(m_body)) && !m_flightState) return; const ShipType& stype = GetShipType(); params.angthrust[0] = m_angThrusters[0]; params.angthrust[1] = m_angThrusters[1]; diff --git a/src/ship.h b/src/ship.h index ea32331..bc22bf1 100644 --- a/src/ship.h +++ b/src/ship.h @@ -34,11 +34,14 @@ public: void UpdateMass(void); vector3d CalcRotDamping(); void SetWheelState(bool down); + void Blastoff(void); float GetDockingTimer(void) { return dockingTimer; } void SetDockingTimer(float t) { dockingTimer = t; } virtual void TimeStepUpdate(const float timeStep); virtual void NotifyDeath(const Body* const dyingBody); virtual bool OnCollision(Body* b, Uint32 flags); + enum FlightState { FLYING, LANDED }; + FlightState GetFlightState(void) { return m_flightState; } class LaserObj : public Object { public: @@ -51,14 +54,15 @@ protected: void RenderLaserfire(void); SpaceStation* m_dockedWith; - bool m_isLanded; enum ShipType::Type m_shipType; Uint32 m_gunState[ShipType::GUNMOUNT_MAX]; private: bool IsFiringLasers(void); void TestLanded(void); + FlightState m_flightState; bool m_testLanded; + float m_launchLockTimeout; float m_wheelState; float m_wheelTransition; diff --git a/src/system_view.cpp b/src/system_view.cpp index 04e3787..91893fe 100644 --- a/src/system_view.cpp +++ b/src/system_view.cpp @@ -12,11 +12,11 @@ SystemView::SystemView(void): View() { Add(m_timePoint, 24, 5); m_zoomInButton = new Gui::ImageButton("icons/zoom_in_f7.png"); - m_zoomInButton->SetShortcut(SDLK_F7, KMOD_NONE); + m_zoomInButton->SetShortcut(SDLK_F6, KMOD_NONE); m_rightButtonBar->Add(m_zoomInButton, 34, 2); m_zoomOutButton = new Gui::ImageButton("icons/zoom_out_f8.png"); - m_zoomOutButton->SetShortcut(SDLK_F8, KMOD_NONE); + m_zoomOutButton->SetShortcut(SDLK_F7, KMOD_NONE); m_rightButtonBar->Add(m_zoomOutButton, 66, 2); Gui::ImageButton* b = new Gui::ImageButton("icons/sysview_accel_r3.png", diff --git a/src/world_view.cpp b/src/world_view.cpp index 805ea0f..1620508 100644 --- a/src/world_view.cpp +++ b/src/world_view.cpp @@ -22,24 +22,33 @@ WorldView::WorldView(void): View() { Add(commsOptions, 10, 20); Gui::MultiStateImageButton* wheels_button = new Gui::MultiStateImageButton(); - wheels_button->SetShortcut(SDLK_F7, KMOD_NONE); + wheels_button->SetShortcut(SDLK_F6, KMOD_NONE); wheels_button->AddState(0, "icons/wheels_up.png"); wheels_button->AddState(1, "icons/wheels_down.png"); wheels_button->onClick.connect(sigc::mem_fun(this, &WorldView::OnChangeWheelsState)); m_rightButtonBar->Add(wheels_button, 34, 2); Gui::MultiStateImageButton* labels_button = new Gui::MultiStateImageButton(); - labels_button->SetShortcut(SDLK_9, KMOD_NONE); + labels_button->SetShortcut(SDLK_8, KMOD_NONE); labels_button->AddState(1, "icons/labels_on.png"); labels_button->AddState(0, "icons/labels_off.png"); labels_button->onClick.connect(sigc::mem_fun(this, &WorldView::OnChangeLabelsState)); m_rightButtonBar->Add(labels_button, 98, 2); m_hyperspaceButton = new Gui::ImageButton("icons/hyperspace_f8.png"); - m_hyperspaceButton->SetShortcut(SDLK_F8, KMOD_NONE); + m_hyperspaceButton->SetShortcut(SDLK_F7, KMOD_NONE); m_hyperspaceButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickHyperspace)); m_rightButtonBar->Add(m_hyperspaceButton, 66, 2); + launchButton = new Gui::ImageButton("icons/blastoff.png"); + launchButton->SetShortcut(SDLK_F5, KMOD_NONE); + launchButton->onClick.connect(sigc::mem_fun(this, &WorldView::OnClickBlastoff)); + m_rightButtonBar->Add(launchButton, 2, 2); + + flightStatus = new Gui::Label(""); + flightStatus->SetColor(1, .7, 0); + m_rightRegion2->Add(flightStatus, 10, 3); + m_bgstarsDlist = glGenLists(1); glNewList(m_bgstarsDlist, GL_COMPILE); @@ -70,6 +79,10 @@ void WorldView::OnChangeLabelsState(Gui::MultiStateImageButton* b) { labelsOn = b->GetState(); } +void WorldView::OnClickBlastoff(void) { + L3D::player->Blastoff(); +} + void WorldView::OnClickHyperspace(void) { StarSystem* s = L3D::GetSelectedSystem(); if(s /* && isn's current system. */) { @@ -163,6 +176,14 @@ void WorldView::Update(void) { } else { //commsOptions->HideAll(); } + + if(L3D::player->GetFlightState() == Ship::LANDED) { + flightStatus->SetText("Landed"); + launchButton->Show(); + } else { + flightStatus->SetText("Manual Controls"); + launchButton->Hide(); + } } Gui::Button* WorldView::AddCommsOption(std::string msg, int ypos) { diff --git a/src/world_view.h b/src/world_view.h index 01c967a..ed71573 100644 --- a/src/world_view.h +++ b/src/world_view.h @@ -16,6 +16,7 @@ public: private: Gui::Button* AddCommsOption(const std::string msg, int ypos); void OnClickHyperspace(void); + void OnClickBlastoff(void); void OnChangeWheelsState(Gui::MultiStateImageButton* b); void OnChangeLabelsState(Gui::MultiStateImageButton* b); virtual bool OnMouseDown(Gui::MouseButtonEvent* e); @@ -23,6 +24,8 @@ private: Gui::ImageButton* m_hyperspaceButton; GLuint m_bgstarsDlist; Gui::Fixed* commsOptions; + Gui::Label* flightStatus; + Gui::ImageButton* launchButton; bool labelsOn; };