From ff60e4463365d274aad2c5cf8ae23a6a665b4fcd Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 8 Mar 2011 18:36:46 +0000 Subject: Replaced the func_impulse if-soup with a nice switch() block. --- src/game/base/ship.cc | 58 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 84b4e0a..1298d05 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -1,3 +1,4 @@ + /* base/ship.cc This file is part of the Osirion project and is distributed under @@ -113,35 +114,37 @@ void Ship::reset() EntityControlable::reset(); } -void Ship::func_impulse() -{ - if (entity_state == core::Entity::Impulse) { - entity_state = core::Entity::Normal; - target_thrust = 1.0f; - entity_thrust = 0.0f; - set_dirty(); - return; - } - - if (entity_state == core::Entity::ImpulseInitiate) { - entity_state = core::Entity::Normal; - set_dirty(); - return; - } +void Ship::func_impulse() { - if (entity_state == core::Entity::JumpInitiate) { - entity_state = core::Entity::Normal; - ship_jumpdrive_timer = 0; - entity_timer = 0; - set_dirty(); + switch (entity_state) { + case core::Entity::Impulse: + entity_state = core::Entity::Normal; + target_thrust = 1.0f; + entity_thrust = 0.0f; + set_dirty(); + break; + + case core::Entity::ImpulseInitiate: + entity_state = core::Entity::Normal; + set_dirty(); + break; + + case core::Entity::JumpInitiate: + entity_state = core::Entity::Normal; + ship_jumpdrive_timer = 0; + entity_timer = 0; + set_dirty(); + break; + + case core::Entity::Normal: + entity_state = core::Entity::ImpulseInitiate; + entity_timer = impulse_timer_delay; + ship_impulsedrive_timer = core::server()->time(); + break; + + default: + break; } - - if (entity_state != core::Entity::Normal) - return; - - entity_state = core::Entity::ImpulseInitiate; - entity_timer = impulse_timer_delay; - ship_impulsedrive_timer = core::server()->time(); } @@ -309,6 +312,7 @@ void Ship::action (btScalar seconds) maxspeed = 0.0f; engine_force = 0.0f; break; + case core::Entity::Docked: maxspeed = 0.0f; engine_force = 0.0f; -- cgit v1.2.3