Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2014-11-22 21:57:08 +0000
committerStijn Buys <ingar@osirion.org>2014-11-22 21:57:08 +0000
commit068f25c5f7ec6fd42a16dda1fe6b0fe884523483 (patch)
tree81cc67375743d79ab6cb9ef80cf257c193eecf9c /src/game
parent667a4741169bb0c2a6273434efb0ed37460b2cf0 (diff)
Minor reputation check code cleanup.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/npc.cc28
-rw-r--r--src/game/base/platform.cc24
2 files changed, 28 insertions, 24 deletions
diff --git a/src/game/base/npc.cc b/src/game/base/npc.cc
index e0999da..3bd5ca0 100644
--- a/src/game/base/npc.cc
+++ b/src/game/base/npc.cc
@@ -36,6 +36,7 @@ NPC *NPC::add_wingman(Ship *leader)
npc->set_color_second(npc->leader()->color_second());
npc->set_location(leader->location() - leader->axis().forward() * 2.0f * (leader->radius() + npc->radius()));
+ npc->nudge();
npc->set_axis(leader->axis());
npc->set_zone(leader->zone());
@@ -150,14 +151,14 @@ Ship *NPC::target_closest_enemy()
for (core::Zone::Content::iterator zit = zone()->content().begin(); zit != zone()->content().end(); ++zit) {
if (((*zit)->moduletype() == ship_enttype) && ((*zit) != this)) {
- Ship *ship = static_cast<Ship *>((*zit));
+ Ship *other_ship = static_cast<Ship *>((*zit));
- if ((ship->state() != Normal) && (ship->state() != ImpulseInitiate) && (ship->state() != Impulse)) {
+ if ((other_ship->state() != Normal) && (other_ship->state() != ImpulseInitiate) && (other_ship->state() != Impulse)) {
continue;
}
- const float d = math::distance(location(), ship->location());
- const float r = radius() + ship->radius();
+ const float d = math::distance(location(), other_ship->location());
+ const float r = radius() + other_ship->radius();
// too far
if (d > r + core::range::fxdistance) {
@@ -170,21 +171,22 @@ Ship *NPC::target_closest_enemy()
}
float reputation = 0.0f;
- if (ship->owner()) {
- // check owner reputation for the faction the NPC belongs to
- reputation = ship->owner()->reputation(faction());
-
- } else if (faction() && (faction()->type() == Faction::infotype())) {
- //check NPC faction reputation for the other ships's faction
- reputation = static_cast<const Faction *>(faction())->reputation(ship->faction());
- }
+ if (other_ship->owner()) {
+ // check owner reputation for the faction this NPC belongs to
+ reputation = other_ship->owner()->reputation(faction());
+
+ } else if (other_ship->faction()) {
+ // check other ships's faction for the faction this NPC belongs to
+ assert(other_ship->faction()->type() == Faction::infotype());
+ reputation = static_cast<const Faction *>(other_ship->faction())->reputation(faction());
+ }
// reputation threshold to get attacked
if (reputation > core::range::reputation_hostile) {
continue;
}
- current_enemy = ship;
+ current_enemy = other_ship;
current_distance = d;
}
}
diff --git a/src/game/base/platform.cc b/src/game/base/platform.cc
index 15c7576..77059ae 100644
--- a/src/game/base/platform.cc
+++ b/src/game/base/platform.cc
@@ -50,35 +50,37 @@ void Platform::frame(const unsigned long elapsed)
for (core::Zone::Content::iterator zit = zone()->content().begin(); zit != zone()->content().end(); ++zit) {
if ((*zit)->moduletype() == ship_enttype) {
- Ship *ship = static_cast<Ship *>((*zit));
+ Ship *other_ship = static_cast<Ship *>((*zit));
- if ((ship->state() != Normal) && (ship->state() != ImpulseInitiate) && (ship->state() != Impulse)) {
+ if ((other_ship->state() != Normal) && (other_ship->state() != ImpulseInitiate) && (other_ship->state() != Impulse)) {
continue;
}
- const float d = math::distance(location(), ship->location());
- const float r = radius() + ship->radius();
+ const float d = math::distance(location(), other_ship->location());
+ const float r = radius() + other_ship->radius();
// too far
if (d > weapon_range + r) {
continue;
}
+ // reputation is interprated as "what others think of me"
float reputation = 0.0f;
- if (ship->owner()) {
- // check owner reputation for the faction the NPC belongs to
- reputation = ship->owner()->reputation(faction());
+ if (other_ship->owner()) {
+ // check owner reputation for the faction this platform belongs to
+ reputation = other_ship->owner()->reputation(faction());
- } else if (faction() && (faction()->type() == Faction::infotype())) {
- //check my faction reputation for the other ships's faction
- reputation = static_cast<const Faction *>(faction())->reputation(ship->faction());
+ } else if (other_ship->faction()) {
+ // check other ships's faction for the faction this platform belongs to
+ assert(other_ship->faction()->type() == Faction::infotype());
+ reputation = static_cast<const Faction *>(other_ship->faction())->reputation(faction());
}
// reputation threshold to get attacked
if (reputation > core::range::reputation_hostile) {
continue;
}
- enemylist.push_back(ship);
+ enemylist.push_back(other_ship);
}
}