From 5f0958c121a246d445507313984358ff8a6df3fa Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 10 Nov 2013 17:13:41 +0000 Subject: Adjust reputation on NPC kills, refresh reputation window if required. --- src/game/base/faction.cc | 45 +++++++++++++++++++++++++++++++++++++++++++-- src/game/base/faction.h | 11 +++++++++++ src/game/base/ship.cc | 15 ++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) (limited to 'src/game/base') 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(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(faction())->apply_kill(assassin); + } + } if (assassin) { -- cgit v1.2.3