/* base/jumppoint.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include "base/game.h" #include "base/jumppoint.h" namespace game { /* ---- class JumpPoint -------------------------------------------- */ JumpPoint::JumpPoint() : core::EntityDynamic() { entity_shape = core::Entity::Diamond; get_color().assign(0.0f, 0.8f, 0.8f, 1.0f); get_color_second().assign(0.6f, 1.0f); set_radius(0.25f); set_flag(core::Entity::Bright); // FIXME jumppoints should be harder to find set_flag(core::Entity::ShowOnMap); entity_moduletypeid = jumppoint_enttype; jumppoint_target = 0; set_serverside(false); } JumpPoint::~JumpPoint() { } void JumpPoint::set_targetlabel(const std::string &label) { jumppoint_targetlabel.assign(label); } void JumpPoint::validate() { jumppoint_target = 0; if (targetlabel().size() < 3) { con_warn << " Jumppoint with invalid target label '" << targetlabel() << "'\n"; return; } size_t pos = targetlabel().find(':'); if ((pos < 1) || (pos >= (targetlabel().size() - 1))) { con_warn << " Jumppoint with invalid target label '" << targetlabel() << "'\n"; return; } std::string zonelabel(targetlabel().substr(0, pos)); std::string entitylabel(targetlabel().substr(pos + 1, targetlabel().size() - pos)); core::Zone *targetzone = core::Zone::find(zonelabel); if (!targetzone) { con_warn << " Jumppoint with invalid target zone '" << zonelabel << "'\n"; return; } core::Entity *targetentity = targetzone->find_entity(entitylabel); if (!targetentity) { con_warn << " Could not find target jumppoint '" << entitylabel << "' in zone '" << zonelabel << "'\n"; return; } if ((targetentity->moduletype() != jumppoint_enttype) && (targetentity->moduletype() != jumpgate_enttype)) { con_warn << " Jumppoint with invalid target jumppoint '" << entitylabel << "' in zone '" << zonelabel << "'\n"; return; } jumppoint_target = static_cast(targetentity); con_debug << " jumppoint to " << targetzone->label() << std::endl; //con_debug << " Jumppoint " << zone->label() << ":" << label() << " with target " << targetlabel() << std::endl; } /* ---- class JumpGate --------------------------------------------- */ JumpGate::JumpGate() : JumpPoint() { unset_flag(core::Entity::Bright); set_flag(core::Entity::ShowOnMap); set_radius(1.0f); entity_moduletypeid = jumpgate_enttype; entity_state = core::Entity::NoPower; jumpgate_timer = 0; } JumpGate::~JumpGate() { } void JumpGate::validate() { JumpPoint::validate(); if (target()) { set_flag(core::Entity::Dockable); } else { unset_flag(core::Entity::Dockable); } } void JumpGate::func_dock(Ship *ship) { if (target()) { if (activated()) { if (ship->owner()) ship->owner()->send("Jumpgate in use"); return; } ship->initiate_jump(this); activate(); if (target()->moduletype() == jumpgate_enttype) { static_cast(target())->activate(); } if (ship->owner() && ship->owner()->control() == ship) { ship->owner()->set_view(this); } } else { if (ship->owner()) ship->owner()->send("Jumpgate inactive"); return; } } void JumpGate::activate() { jumpgate_timer = jump_timer_delay; set_state(core::Entity::Normal); } void JumpGate::frame(float elapsed) { if (jumpgate_timer > 0) { jumpgate_timer -= elapsed; if (jumpgate_timer < 0) { set_state(core::Entity::NoPower); jumpgate_timer = 0; } } } }