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>2013-11-07 20:08:05 +0000
committerStijn Buys <ingar@osirion.org>2013-11-07 20:08:05 +0000
commit87d5637c09dca61a650fe81d83ef328943176503 (patch)
tree60b97aa68a593d71b9a5566242da8d7f0676c3ef /src/game
parentcd9ad2786e0e4b0f0448363252d4b010dfe6515c (diff)
Save/load player reputation,
count player NPC and PVP kills.
Diffstat (limited to 'src/game')
-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
5 files changed, 94 insertions, 32 deletions
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) {