diff --git a/src/ship.cpp b/src/ship.cpp index a3932c2..e1efa72 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -29,7 +29,7 @@ Ship::Ship(ShipType::Type shipType) : DynamicBody() { m_wheelTransition = 0; m_wheelState = 0; m_dockedWith = 0; - dockingTimer = 0; + m_dockingTimer = 0; m_navTarget = 0; m_combatTarget = 0; m_shipType = shipType; @@ -139,38 +139,45 @@ void Ship::TestLanded(void) { const double planetRadius = GetFrame()->m_astroBody->GetRadius(); if(speed < 20) { - printf("Landed!\n"); - - /* Orient the damn thing right! */ + /* Orient the damn thing right! + * Why is the inverse of the body rot matrix being used?!?! + * *shrugs* it just works this way. + */ matrix4x4d rot; GetRotMatrix(rot); + matrix4x4d invRot = rot.InverseOf(); vector3d up = vector3d::Normalize(GetPosition()); - /* Position at zero altitude. */ - SetPosition(up * planetRadius); + /* Check player is sortof sensibly oriented for landing. */ + const double dot = vector3d::Dot(vector3d::Normalize(vector3d(invRot[1], invRot[5], invRot[9])), up); + if(dot > 0.99) { + /* Position at zero altitude. */ + SetPosition(up * planetRadius); - vector3d forward = rot * vector3d(0, 0, 1); - vector3d other = vector3d::Normalize(vector3d::Cross(up, forward)); + vector3d forward = rot * vector3d(0,0,1); + vector3d other = vector3d::Normalize(vector3d::Cross(up, forward)); + forward = vector3d::Cross(other, up); - rot = matrix4x4d::MakeRotMatrix(other, up, forward); - rot = rot.InverseOf(); - SetRotMatrix(rot); + rot = matrix4x4d::MakeRotMatrix(other, up, forward); + rot = rot.InverseOf(); + SetRotMatrix(rot); - /* - * We don'tuse DynamicBody::Disable because that also disables the geom - * and that must still get collisions. - */ - dBodyDisable(m_body); - ClearThrusterState(); - m_flightState = LANDED; - m_testLanded = false; + /* + * We don't use DynamicBody::Disable because that also disables + * the geom, and that must still get collisions. + */ + dBodyDisable(m_body); + ClearThrusterState(); + m_flightState = LANDED; + m_testLanded = false; + } } } } void Ship::TimeStepUpdate(const float timeStep) { - dockingTimer = (dockingTimer-timeStep > 0 ? dockingTimer-timeStep : 0); + m_dockingTimer = (m_dockingTimer-timeStep > 0 ? m_dockingTimer-timeStep : 0); /* ODE tri mesh likes to know our old position. */ TriMeshUpdateLastPos(); @@ -255,7 +262,7 @@ void Ship::SetDockedWith(SpaceStation* s) { m_dockedWith = 0; } else { m_dockedWith = s; - dockingTimer = 0.0f; + m_dockingTimer = 0.0f; SetVelocity(vector3d(0, 0, 0)); SetAngVelocity(vector3d(0, 0, 0)); Disable(); @@ -266,9 +273,11 @@ void Ship::SetGunState(int idx, int state) { m_gunState[idx] = state; } -void Ship::SetWheelState(bool down) { +bool Ship::SetWheelState(bool down) { + if(m_flightState != FLYING) return false; if(down) m_wheelTransition = 1; else m_wheelTransition = -1; + return true; } void Ship::SetNavTarget(Body* const target) { diff --git a/src/ship.h b/src/ship.h index bc22bf1..4e9ce00 100644 --- a/src/ship.h +++ b/src/ship.h @@ -33,10 +33,10 @@ public: void CalcStats(shipstats_t* stats); void UpdateMass(void); vector3d CalcRotDamping(); - void SetWheelState(bool down); + bool SetWheelState(bool down); /* Returns success of state change, NOT state itself. */ void Blastoff(void); - float GetDockingTimer(void) { return dockingTimer; } - void SetDockingTimer(float t) { dockingTimer = t; } + float GetDockingTimer(void) { return m_dockingTimer; } + void SetDockingTimer(float t) { m_dockingTimer = t; } virtual void TimeStepUpdate(const float timeStep); virtual void NotifyDeath(const Body* const dyingBody); virtual bool OnCollision(Body* b, Uint32 flags); @@ -68,7 +68,7 @@ private: float m_thrusters[ShipType::THRUSTER_MAX]; float m_angThrusters[3]; - float dockingTimer; + float m_dockingTimer; dGeomID m_tempLaserGeom[ShipType::GUNMOUNT_MAX]; LaserObj m_laserCollisionObj; diff --git a/src/world_view.cpp b/src/world_view.cpp index 1620508..8659e10 100644 --- a/src/world_view.cpp +++ b/src/world_view.cpp @@ -72,7 +72,9 @@ WorldView::WorldView(void): View() { } void WorldView::OnChangeWheelsState(Gui::MultiStateImageButton* b) { - L3D::player->SetWheelState(b->GetState()); + if(!L3D::player->SetWheelState(b->GetState())) { + b->StatePrev(); + } } void WorldView::OnChangeLabelsState(Gui::MultiStateImageButton* b) {