From 4ca3ba6e59b871fc77662eccb51e0c773a95299f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 22 Dec 2014 21:34:20 +0000 Subject: Wingmen will try to repair their ship when not in combat. --- src/game/base/npc.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/game') diff --git a/src/game/base/npc.cc b/src/game/base/npc.cc index ec43ea0..f327f16 100644 --- a/src/game/base/npc.cc +++ b/src/game/base/npc.cc @@ -14,8 +14,10 @@ namespace game { -const float NPC_WIMPY = 20.0f; // indicates the health percentage at which the NPC willtry to repair itself -const float NPC_REPAIR_ARMOR_PER_SECOND = 25.0f; // repair rate in units of armor per second +const float NPC_REPAIR_WIMPY = 20.0f; // the health percentage at which the NPC willtry to repair itself +const float NPC_REPAIR_IDLE = 70.0f; //the health percentage at which the NPC willtry to repair itself when not in combat +const float NPC_REPAIR_RATE = 25.0f; // repair rate in units of armor per second + // NPC Wingman factory function NPC *NPC::add_wingman(Ship *leader) @@ -322,7 +324,7 @@ void NPC::frame(const unsigned long elapsed) } else { while (npc_repair_timestamp + 1000 < now) { - set_armor(armor() + NPC_REPAIR_ARMOR_PER_SECOND); + set_armor(armor() + NPC_REPAIR_RATE); npc_repair_timestamp += 1000; } } @@ -339,7 +341,7 @@ void NPC::frame(const unsigned long elapsed) } } } else { - if (leader()->has_flag(core::Entity::Dockable) && (health() < NPC_WIMPY)) + if (leader()->has_flag(core::Entity::Dockable) && (health() < NPC_REPAIR_WIMPY)) { set_autopilot_target(leader()); @@ -364,8 +366,16 @@ void NPC::frame(const unsigned long elapsed) set_autopilot_flag(Ship::AutoPilotEnabled); unset_autopilot_flag(Ship::AutoPilotCombat); - unset_autopilot_flag(Ship::AutoPilotDock); - set_autopilot_flag(Ship::AutoPilotFormation); + + if (leader()->has_flag(core::Entity::Dockable) && (health() < NPC_REPAIR_IDLE)) + { + set_autopilot_flag(Ship::AutoPilotDock); + unset_autopilot_flag(Ship::AutoPilotFormation); + } else + { + unset_autopilot_flag(Ship::AutoPilotDock); + set_autopilot_flag(Ship::AutoPilotFormation); + } } } } -- cgit v1.2.3