From b277c65615482f17c966771341ae6b7a89cc9568 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 20 Oct 2013 14:36:45 +0000 Subject: Make wingmen follow you through jumpgates. --- src/game/base/npc.cc | 42 ++++++++++++++++++++++++++++++------------ src/game/base/ship.cc | 10 +++++++--- src/game/base/ship.h | 7 ++++++- 3 files changed, 43 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/game/base/npc.cc b/src/game/base/npc.cc index be7a754..8e820a7 100644 --- a/src/game/base/npc.cc +++ b/src/game/base/npc.cc @@ -84,6 +84,8 @@ void NPC::frame(const unsigned long elapsed) } else if (leader()->zone() == zone()) { + // leader is in this zone + if (leader()->state() == Docked) { if (state() != core::Entity::Docked) { @@ -98,6 +100,15 @@ void NPC::frame(const unsigned long elapsed) unset_autopilot_flag(Ship::AutoPilotEnabled); } + } else if ((leader()->state() == JumpInitiate) || (leader()->state() == Jump)) { + + // goto wherever the leader is jumping + + set_autopilot_target(leader()->jumpdepart()); + set_autopilot_flag(Ship::AutoPilotEnabled); + set_autopilot_flag(Ship::AutoPilotDock); + unset_autopilot_flag(Ship::AutoPilotFormation); + } else { if (state() == core::Entity::Docked) { @@ -116,20 +127,27 @@ void NPC::frame(const unsigned long elapsed) } } else { - unset_autopilot_flag(Ship::AutoPilotEnabled); - - target_direction = 0; - target_pitch = 0; - target_roll = 0; - target_strafe = 0.0f; - target_vstrafe = 0.0f; - - target_afterburner = 0.0f; - target_thrust = 0; - if (state() == core::Entity::Impulse) { + // leader is not in this zone + if (!autopilot_target()) { + + target_direction = 0; + target_pitch = 0; + target_roll = 0; + target_strafe = 0.0f; + target_vstrafe = 0.0f; + + target_afterburner = 0.0f; + target_thrust = 0; + + if (state() == core::Entity::Impulse) { - func_impulse(); + func_impulse(); + } + } else { + set_autopilot_flag(Ship::AutoPilotEnabled); + set_autopilot_flag(Ship::AutoPilotDock); + unset_autopilot_flag(Ship::AutoPilotFormation); } } } diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 75656dc..c017ce1 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -693,10 +693,13 @@ void Ship::frame(const unsigned long elapsed) set_zone(ship_jumpdepart->target()->zone()); - if (owner() && owner()->view() && (owner()->view()->zone() != ship_jumpdepart->target()->zone())) - owner()->set_view(0); + if (owner()) { + if (owner()->view() && (owner()->view()->zone() != ship_jumpdepart->target()->zone())) { + owner()->set_view(0); + } - owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name()); + owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name()); + } } else { set_state(core::Entity::Normal); } @@ -1155,6 +1158,7 @@ void Ship::frame_autopilot_dock(const unsigned long elapsed, core::Entity *targe // jumpgates have their own docking function JumpGate *jumpgate = static_cast(target); jumpgate->func_dock(this); + unset_autopilot_flag(AutoPilotDock); return; diff --git a/src/game/base/ship.h b/src/game/base/ship.h index 61ff1c7..fa6e60d 100644 --- a/src/game/base/ship.h +++ b/src/game/base/ship.h @@ -83,6 +83,11 @@ public: return ship_spawn; } + inline JumpPoint *jumpdepart() + { + return ship_jumpdepart; + } + /// current autopilot target inline core::Entity *autopilot_target() { @@ -230,7 +235,7 @@ protected: * @brief autopilot formation flying * */ void frame_autopilot_formation(const unsigned long elapsed, core::Entity *target); - + private: JumpPoint *find_closest_jumppoint(); -- cgit v1.2.3