Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/faction.cc45
-rw-r--r--src/game/base/faction.h11
-rw-r--r--src/game/base/ship.cc15
3 files changed, 68 insertions, 3 deletions
diff --git a/src/game/base/faction.cc b/src/game/base/faction.cc
index ef0a7b6..2dd8a1a 100644
--- a/src/game/base/faction.cc
+++ b/src/game/base/faction.cc
@@ -6,6 +6,7 @@
#include "core/func.h"
#include "core/parser.h"
+#include "core/range.h"
#include "base/faction.h"
namespace game {
@@ -193,6 +194,8 @@ Faction::~Faction()
void Faction::apply(core::Entity *entity) const
{
+ assert(entity);
+
// set primary color
entity->set_color(color());
@@ -203,10 +206,48 @@ void Faction::apply(core::Entity *entity) const
entity->set_faction(this);
}
+
+void Faction::apply_kill(core::Player *player) const
+{
+ assert(player);
+
+ // a kill will cost the player 5 reputation points with this faction
+ const float points = 5.0f;
+
+ // a kill will cost the player 1 reputation point with this faction's friends and allies
+ const float points_ally = 1.0f;
+
+ // adjust current player reputation for this faction
+ player->reputation().set_reputation(this, player->reputation(this) - points);
+
+ // adjust player reputation for this factions's allies and enemies
+ for (core::Reputation::FactionReps::const_iterator rip = faction_reputation.factionreps_begin(); rip != faction_reputation.factionreps_end(); ++rip) {
+ assert((*rip)->faction());
+
+ if ((*rip)->faction() != faction_default) {
+ const float other_faction_reputation = faction_reputation.reputation((*rip)->faction());
+ if (other_faction_reputation >= core::range::reputation_friendly) {
+ // allied faction
+ player->reputation().set_reputation((*rip)->faction(), player->reputation((*rip)->faction()) - points_ally);
+ } else if (other_faction_reputation <= core::range::reputation_hostile) {
+ //enemy faction
+ player->reputation().set_reputation((*rip)->faction(), player->reputation((*rip)->faction()) + points_ally);
+ }
+ }
+ }
+
+ player->reputation().set_dirty();
+}
+
+void Faction::apply_sale(core::Player *player, const float amount) const
+{
+ assert(player);
+}
+
+
void Faction::apply_default(core::Reputation & reputation)
{
- // apply default reputation
- Faction *faction_default = find("default");
+ // apply default reputation
if (faction_default) {
for (core::Reputation::FactionReps::const_iterator rip = faction_default->reputation().factionreps().begin(); rip != faction_default->reputation().factionreps().end(); ++rip) {
// only add defaults the reputation doesn't have yet
diff --git a/src/game/base/faction.h b/src/game/base/faction.h
index b459899..3f6a1e5 100644
--- a/src/game/base/faction.h
+++ b/src/game/base/faction.h
@@ -67,6 +67,16 @@ public:
faction_color_second.assign(color_second);
}
+ /**
+ * @brief adjust player reputation for a kill of a member of this faction
+ */
+ void apply_kill(core::Player *player) const;
+
+ /**
+ * @brief adjust player reputation for buying from/selling to this faction
+ */
+ void apply_sale(core::Player *player, const float amount) const;
+
/* --- static ----------------------------------------------------- */
/**
@@ -87,6 +97,7 @@ public:
* @brief apply default reputation
* */
static void apply_default(core::Reputation & reputation);
+
static inline const core::InfoType *infotype() {
return faction_infotype;
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 2a5d68f..338bc04 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -22,6 +22,7 @@
#include "base/racetrack.h"
#include "base/cargo.h"
#include "base/cargopod.h"
+#include "base/faction.h"
using math::degrees360f;
using math::degrees180f;
@@ -663,13 +664,16 @@ void Ship::hit(core::Entity *other)
message.append(" ^Bwent boom.");
}
core::server()->broadcast(message);
-
} else {
if (assassin) {
// assissin killed an NPC
assassin->set_npckills(assassin->npckills() + 1);
assassin->set_dirty();
+
+ // faction ship got killed
+ assert (faction()->type() == Faction::infotype());
+ static_cast<const Faction *>(faction())->apply_kill(assassin);
}
}
}
@@ -711,6 +715,15 @@ void Ship::hit(core::Entity *other)
message.append(" ^Bwas blown to bits.");
}
core::server()->broadcast(message);
+
+ } else if (faction()) {
+
+ if (assassin) {
+ // faction ship got killed
+ assert (faction()->type() == Faction::infotype());
+ static_cast<const Faction *>(faction())->apply_kill(assassin);
+ }
+
}
if (assassin) {