diff options
Diffstat (limited to 'src/game/base/npc.cc')
-rw-r--r-- | src/game/base/npc.cc | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/game/base/npc.cc b/src/game/base/npc.cc index 9aff6b2..0dd33c8 100644 --- a/src/game/base/npc.cc +++ b/src/game/base/npc.cc @@ -80,6 +80,7 @@ NPC::NPC(const ShipModel *shipmodel) : Ship(0, shipmodel) npc_patrol = 0; npc_leader = 0; + npc_commander = 0; npc_weapon_range = 0.0f; } @@ -138,6 +139,11 @@ void NPC::set_patrol(Patrol *patrol) npc_patrol = patrol; } +void NPC::set_commander(core::Player *commander) +{ + npc_commander = commander; +} + Ship *NPC::target_closest_enemy() { // scan for enemies @@ -217,17 +223,34 @@ void NPC::frame(const unsigned long elapsed) } } else { - // TODO pilot magic and mood witchcraft - if (leader()) { - + // TODO pilot magic and mood witchcraft + + if (leader()) + { // verify leader still exists - if (!core::Entity::find(leader())) { - + if (!core::Entity::find(leader())) + { set_leader(0); + + // verify the commander hasn't left the game + if (commander()) + { + set_commander(core::game()->find_player(commander())); + + if (commander() && commander()->control() && (commander()->control()->moduletype() == ship_enttype)) + { + set_leader(static_cast<Ship *>(commander()->control())); + } + } + } + + // if the leader has dissapeared, the NPC explodes + if (!leader()) + { explode(); npc_destroyed_timestamp = core::game()->time(); - - } else if (leader()->zone() == zone()) { + + } else if (leader()->zone() == zone()) { // leader is in this zone if (leader()->state() == Docked) { |