Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base')
-rw-r--r--src/game/base/game.cc4
-rw-r--r--src/game/base/npc.cc37
-rw-r--r--src/game/base/npc.h21
3 files changed, 51 insertions, 11 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 62ceef8..2ec3c62 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -686,7 +686,7 @@ void Game::func_wingmen(core::Player *player, const std::string &args)
return;
}
- assert(player->control()->moduletype() == ship_enttype);
+ assert(player->control()->moduletype() == ship_enttype);
Ship * ship = static_cast<Ship *>(player->control());
std::istringstream is(args);
@@ -714,6 +714,8 @@ void Game::func_wingmen(core::Player *player, const std::string &args)
for (int count = 0; count < amount; ++count) {
NPC *npc = NPC::add_wingman(ship);
if (npc) {
+ npc->set_commander(player);
+
if (faction) {
faction->apply(npc);
player->send(faction->name() + " wingman standing by!");
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) {
diff --git a/src/game/base/npc.h b/src/game/base/npc.h
index 39395c0..411f807 100644
--- a/src/game/base/npc.h
+++ b/src/game/base/npc.h
@@ -31,7 +31,7 @@ public:
/* ---- inspectors ----------------------------------------- */
/**
- * @brief returns the general moode of the NPC
+ * @brief returns the general mood of the NPC
* */
inline const Mood mood() const
{
@@ -39,7 +39,7 @@ public:
}
/**
- * @brief returns this NPC's leader.
+ * @brief returns this NPC's leader
* */
inline Ship *leader()
{
@@ -47,13 +47,21 @@ public:
}
/**
- * @brief returns this NPC's patrol.
+ * @brief returns this NPC's patrol
* */
inline Patrol *patrol()
{
return npc_patrol;
}
+ /**
+ * @brief return this NPC;s fleet commander
+ * */
+ inline core::Player *commander()
+ {
+ return npc_commander;
+ }
+
/* ---- mutators ------------------------------------------- */
/**
@@ -72,6 +80,11 @@ public:
void set_patrol(Patrol *patrol);
/**
+ * @brief set the NPC's fleet commander
+ * */
+ void set_commander(core::Player *player);
+
+ /**
* @brief game frame
* */
virtual void frame(const unsigned long elapsed);
@@ -103,6 +116,8 @@ private:
float npc_weapon_range;
+ core::Player *npc_commander;
+
}; // class NPC
} // namespace game