/** * @brief Ends this state. * @param next_state the next state */ void Hero::LiftingState::stop(State *next_state) { State::stop(next_state); if (lifted_item != NULL) { get_sprites().set_lifted_item(NULL); // the lifted item is still managed by this state switch (next_state->get_previous_carried_item_behavior(*lifted_item)) { case CarriedItem::BEHAVIOR_THROW: throw_item(); break; case CarriedItem::BEHAVIOR_DESTROY: delete lifted_item; lifted_item = NULL; break; case CarriedItem::BEHAVIOR_KEEP: lifted_item = NULL; break; } get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_NONE); } }
/** * \brief Ends this state. * \param next_state the next state */ void Hero::LiftingState::stop(const State* next_state) { State::stop(next_state); if (lifted_item != NULL) { get_sprites().set_lifted_item(NULL); // the lifted item is still managed by this state switch (next_state->get_previous_carried_item_behavior()) { case CarriedItem::BEHAVIOR_THROW: throw_item(); break; case CarriedItem::BEHAVIOR_DESTROY: destroy_lifted_item(); break; case CarriedItem::BEHAVIOR_KEEP: // The next state is now the owner and has incremented the refcount. Debug::check_assertion(lifted_item->get_refcount() > 1, "Invalid carried item refcount"); RefCountable::unref(lifted_item); lifted_item = NULL; break; } get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_NONE); } }
/** * \brief Notifies this state that the action command was just pressed. */ void Hero::CarryingState::notify_action_command_pressed() { if (get_keys_effect().get_action_key_effect() == KeysEffect::ACTION_KEY_THROW) { throw_item(); hero.set_state(new FreeState(hero)); } }
/** * \brief Stops this state. * \param next_state the next state */ void Hero::CarryingState::stop(State *next_state) { PlayerMovementState::stop(next_state); get_sprites().set_lifted_item(NULL); get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_NONE); if (carried_item != NULL) { switch (next_state->get_previous_carried_item_behavior(*carried_item)) { case CarriedItem::BEHAVIOR_THROW: throw_item(); break; case CarriedItem::BEHAVIOR_DESTROY: delete carried_item; carried_item = NULL; break; case CarriedItem::BEHAVIOR_KEEP: carried_item = NULL; break; default: Debug::die("Invalid carried item behavior"); } } }
/** * \brief Ends this state. * \param next_state the next state */ void Hero::LiftingState::stop(const State* next_state) { State::stop(next_state); if (lifted_item != nullptr) { get_sprites().set_lifted_item(nullptr); // the lifted item is still managed by this state switch (next_state->get_previous_carried_item_behavior()) { case CarriedItem::BEHAVIOR_THROW: throw_item(); break; case CarriedItem::BEHAVIOR_DESTROY: case CarriedItem::BEHAVIOR_KEEP: lifted_item = nullptr; break; } get_commands_effects().set_action_key_effect(CommandsEffects::ACTION_KEY_NONE); } }