Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/player.cc25
-rw-r--r--src/core/player.h34
-rw-r--r--src/game/base/faction.cc14
-rw-r--r--src/game/base/faction.h5
-rw-r--r--src/game/base/game.cc17
-rw-r--r--src/game/base/savegame.cc48
-rw-r--r--src/game/base/ship.cc42
7 files changed, 147 insertions, 38 deletions
diff --git a/src/core/player.cc b/src/core/player.cc
index e7fb024..eb5f08e 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -49,21 +49,24 @@ void Player::clear()
player_admin_level = 0;
player_reputation.clear();
+
+ player_npckills = 0;
+ player_pvpkills = 0;
}
void Player::print() const
{
con_print << "id: ^B" << id() << "^N name: ^B" << name() << "^N" << std::endl;
- con_print << " color ^B" << color() << std::endl;
- con_print << " ping ^B" << ping() << std::endl;
- con_print << " credits ^B" << credits() << std::endl;
- con_print << " level ^B" << level() << std::endl;
-
if (zone()) {
con_print << " zone ^B" << zone()->name() << std::endl;
}
-
+ con_print << " color ^B" << color() << std::endl;
+ con_print << " ping ^B" << ping() << std::endl;
+ con_print << " credits ^B" << credits() << std::endl;
+ con_print << " level ^B" << level() << std::endl;
+ con_print << " npc kills ^B" << npckills() << std::endl;
+ con_print << " pvp kills ^B" << pvpkills() << std::endl;
}
void Player::message(Message::Channel channel, const std::string text)
@@ -142,7 +145,17 @@ void Player::set_admin_level(const int admin_level)
{
player_admin_level = admin_level;
}
+
+void Player::set_npckills(const long kills)
+{
+ player_npckills = kills;
+}
+void Player::set_pvpkills(const long kills)
+{
+ player_pvpkills = kills;
+}
+
void Player::update_info()
{
Cvar *cl_name = Cvar::find("cl_name");
diff --git a/src/core/player.h b/src/core/player.h
index 91d66c5..8b60eee 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -157,6 +157,22 @@ public:
return player_reputation.reputation(faction);
}
+ /**
+ * @brief number of NPCs the player killed
+ * */
+ inline const long npckills() const
+ {
+ return player_npckills;
+ }
+
+ /**
+ * @brief number of other players the player killed
+ * */
+ inline const long pvpkills() const
+ {
+ return player_pvpkills;
+ }
+
/*----- server-side mesage functions ------------------------------ */
/// send a message to the player on one of the message channels
@@ -250,6 +266,16 @@ public:
inline void set_zonechange(const bool dirty = true) {
player_zonechange = dirty;
}
+
+ /**
+ * @brief set the number of NPCs the player killed
+ * */
+ void set_npckills(const long kills);
+
+ /**
+ * @brief set the number of other players the player killed
+ * */
+ void set_pvpkills(const long kills);
/* -- should actually not be public --*/
@@ -305,6 +331,14 @@ private:
float player_warningtime;
Reputation player_reputation;
+
+ long player_npckills;
+
+ long player_pvpkills;
+
+ unsigned long player_time_previously_wasted;
+
+ unsigned long player_time_last_joined;
};
diff --git a/src/game/base/faction.cc b/src/game/base/faction.cc
index 73e5140..8171a2d 100644
--- a/src/game/base/faction.cc
+++ b/src/game/base/faction.cc
@@ -208,4 +208,18 @@ void Faction::apply(core::Entity *entity) const
entity->set_faction(this);
}
+void Faction::apply_default(core::Reputation & reputation)
+{
+ // apply default reputation
+ Faction *faction_default = find("default");
+ 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
+ if (!reputation.find((*rip)->faction())) {
+ reputation.set_reputation((*rip)->faction(), (*rip)->reputation());
+ }
+ }
+ }
+}
+
} // namespace game
diff --git a/src/game/base/faction.h b/src/game/base/faction.h
index 6f995dc..5469dad 100644
--- a/src/game/base/faction.h
+++ b/src/game/base/faction.h
@@ -91,6 +91,11 @@ public:
static Faction *find(const std::string & label);
+ /**
+ * @brief apply default reputation
+ * */
+ static void apply_default(core::Reputation & reputation);
+
private:
/* --- attributes ------------------------------------------------- */
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index cbcafaf..79fd167 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -100,20 +100,11 @@ void Game::func_join(core::Player *player, std::string const &args)
player->send("^BYou received " + aux::article(Default::shipmodel->name()));
player->sound("game/buy-ship");
-
- // apply default reputation
- Faction *faction_default = Faction::find("default");
- if (faction_default) {
- player->reputation().assign(faction_default->reputation());
- }
- }
-
-
- // DEBUG
- for (core::Reputation::FactionReps::iterator rip = player->reputation().factionreps().begin(); rip != player->reputation().factionreps().end(); ++rip) {
- con_debug << " reputation with " << (*rip)->label() << " " << (*rip)->reputation() << std::endl;
+
+ player->reputation().clear();
+ Faction::apply_default(player->reputation());
}
-
+
player->set_dirty();
}
diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc
index 5100064..b498717 100644
--- a/src/game/base/savegame.cc
+++ b/src/game/base/savegame.cc
@@ -29,6 +29,8 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
std::string itemtype;
std::string itemlabel;
float armor;
+ float reputation;
+ Faction *faction = 0;
while (inifile.getline()) {
@@ -39,6 +41,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
continue;
} else if (inifile.got_section("player")) {
continue;
+ } else if (inifile.got_section("reputation")) {
+ faction = 0;
+ continue;
} else if (inifile.got_section("ship")) {
continue;
} else if (inifile.got_section("item")) {
@@ -67,9 +72,32 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
} else if (inifile.got_key_string("name", str)) {
continue;
+ } else if (inifile.got_key_long("npckills", l)) {
+ player->set_npckills(l);
+
+ } else if (inifile.got_key_long("pvpkills", l)) {
+ player->set_pvpkills(l);
+ }
+
} else {
inifile.unknown_key();
}
+
+ } else if (inifile.in_section("reputation")) {
+
+ if (inifile.got_key_label("faction", str)) {
+ faction = Faction::find (str);
+ if (!faction) {
+ inifile.unknown_error("unknown faction '" + str + "'");
+ }
+ continue;
+
+ } else if (inifile.got_key_float("reputation", reputation)) {
+ if (!faction) {
+ inifile.unknown_error("reputation without faction");
+ } else {
+ player->reputation().set_reputation(faction, reputation);
+ }
} else if (inifile.in_section("ship")) {
@@ -269,12 +297,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
player->set_control(ship);
}
}
-
- // FIXME load reputation from savegame
- Faction *faction_default = Faction::find("default");
- if (faction_default) {
- player->reputation().assign(faction_default->reputation());
- }
+
+ // apply default reputation
+ Faction::apply_default(player->reputation());
}
void SaveGame::player_to_stream(core::Player *player, std::ostream & os)
@@ -286,9 +311,18 @@ void SaveGame::player_to_stream(core::Player *player, std::ostream & os)
// player name
os << "name=" << player->name() << std::endl;
// credit
- os << "credits=" << player->credits() << std::endl;
+ os << "credits=" << player->credits() << std::endl;
+ os << "npckills=" << player->npckills() << std::endl;
+ os << "pvpkills=" << player->pvpkills() << std::endl;
os << std::endl;
+ // player reputation
+ for (core::Reputation::FactionReps::const_iterator it = player->reputation().factionreps().begin(); it != player->reputation().factionreps().end(); ++it) {
+ os << "[reputation]" << std::endl;
+ os << "faction=" << (*it)->faction()->label() << std::endl;
+ os << "reputation=" << (*it)->reputation() << std::endl;
+ os << std::endl;
+ }
// save ship
// TODO iterate assets and save all ships
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 5df0ced..664b557 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -427,6 +427,8 @@ void Ship::explode()
target_thrust = 0;
entity_thrust = 0;
+
+ ship_armor = 0;
set_state(core::Entity::Destroyed);
@@ -641,31 +643,37 @@ void Ship::hit(core::Entity *other)
if (ship_armor <= 0) {
explode();
+ core::Player *assassin = 0;
+ if (spacemine->owner_id()) {
+ assassin = core::server()->find_player(spacemine->owner_id());
+ }
+
if (owner()) {
- ship_armor = 0;
std::string message("^B");
message.append(owner()->name());
-
- core::Player *assassin = 0;
-
- if (spacemine->owner_id()) {
- assassin = core::server()->find_player(spacemine->owner_id());
- }
-
- if (assassin) {
+
+ if (assassin) {
if (assassin == owner()) {
message.append(" ^Bran into his own mine.");
} else {
message.append(" ^Bran into ");
message.append(assassin->name());
message.append(" ^B's mine.");
+
+ // asssissin killed a player
+ assassin->set_pvpkills(assassin->pvpkills() + 1);
}
} else {
message.append(" ^Bwent boom.");
}
core::server()->broadcast(message);
+
+
} else {
- die();
+ if (assassin) {
+ // assissin killed an NPC
+ assassin->set_npckills(assassin->npckills() + 1);
+ }
}
}
@@ -690,7 +698,7 @@ void Ship::hit(core::Entity *other)
explode();
if (owner()) {
- ship_armor = 0;
+ // broadcast death message
std::string message("^B");
message.append(owner()->name());
@@ -708,10 +716,20 @@ void Ship::hit(core::Entity *other)
core::server()->broadcast(message);
}
- // send kill sound to assassin
if (assassin) {
+ // send kill sound to assassin
assassin->sound("game/target_kill");
+
+ // update assassin stats
+ if (owner()) {
+ // asssissin killed a player
+ assassin->set_pvpkills(assassin->pvpkills() + 1);
+ } else {
+ // assissin killed an NPC
+ assassin->set_npckills(assassin->npckills() + 1);
+ }
}
+
} else {
// send hit sound to assassin
if (assassin) {