Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base/faction.cc')
-rw-r--r--src/game/base/faction.cc81
1 files changed, 76 insertions, 5 deletions
diff --git a/src/game/base/faction.cc b/src/game/base/faction.cc
index 80dfc9f..73e5140 100644
--- a/src/game/base/faction.cc
+++ b/src/game/base/faction.cc
@@ -11,6 +11,7 @@
namespace game {
core::InfoType *Faction::faction_infotype = 0;
+Faction *Faction::faction_default = 0;
void func_list_faction(const std::string &args)
{
@@ -48,24 +49,34 @@ bool Faction::init()
con_print << "^BLoading factions..." << std::endl;
+ core::Func *func = core::Func::add("list_faction", func_list_faction);
+ func->set_info("list available factions");
+
size_t count = 0;
Faction *faction = 0;
std::string strvalue;
+ float floatvalue;
math::Color colorvalue;
bool b = false;
+ std::string factionlabel;
+
while (inifile.getline()) {
if (inifile.got_section()) {
- faction = 0;
-
if (inifile.got_section("faction")) {
count++;
faction = new Faction();
+
+ } else if (inifile.got_section("reputation")) {
+ factionlabel.clear();
} else {
inifile.unknown_section();
+
+ faction = 0;
+ factionlabel.clear();
}
} else if (inifile.got_key()) {
@@ -74,24 +85,48 @@ bool Faction::init()
if (inifile.got_key_label("label", strvalue)) {
faction->set_label(strvalue);
+ continue;
} else if (inifile.got_key_string("name", strvalue)) {
faction->set_name(strvalue);
+ continue;
} else if (inifile.got_key_string("info", strvalue)) {
faction->add_text(strvalue);
+ continue;
} else if (inifile.got_key_color("color", colorvalue)) {
faction->set_color(colorvalue);
+ continue;
} else if (inifile.got_key_color("colorsecond", colorvalue)) {
faction->set_color_second(colorvalue);
+ continue;
} else if (inifile.got_key_bool("lawfull", b)) {
faction->set_lawfull(b);
+ continue;
+
} else {
inifile.unknown_key();
}
+ } else if (inifile.in_section("reputation")) {
+
+ if (faction) {
+ if (inifile.got_key_label("faction", factionlabel)) {
+ continue;
+
+ } else if (inifile.got_key_float("reputation", floatvalue)) {
+ if (factionlabel.size()) {
+ faction->reputation().set_reputation(factionlabel, floatvalue);
+ } else {
+ inifile.unknown_error("reputation key without faction");
+ }
+ continue;
+ } else {
+ inifile.unknown_key();
+ }
+ }
}
}
}
@@ -102,18 +137,51 @@ bool Faction::init()
con_warn << "No factions found!" << std::endl;
return true; // non-fatal
}
+
+ // create default faction
+ faction_default = Faction::find("default");
+ if (!faction_default) {
+ faction_default = new Faction();
+ faction_default->set_label("default");
+ faction_default->set_name("Default");
+ } else {
+ faction_default->reputation().clear();
+ }
+
+ // validate reputation
+ for (core::Info::Registry::iterator it = core::Info::registry().begin(); it != core::Info::registry().end(); it++) {
+ core::Info *info = (*it);
+
+ if (info->type() == faction_infotype) {
+ faction = static_cast<Faction *>(info);
+ core::Reputation::FactionReps::iterator rip = faction->reputation().factionreps().begin();
+ while (rip != faction->reputation().factionreps().end()) {
+ Faction *otherfaction = Faction::find((*rip)->label());
+
+ if (!otherfaction) {
+ con_warn << " faction '" << faction->label() << "': unknown faction '" << (*rip)->label() << "' in reputation" << std::endl;
+ faction->reputation().factionreps().erase(rip++);
+ } else {
+ if (otherfaction == faction_default) {
+ faction_default->reputation().set_reputation(faction, (*rip)->reputation());
+ }
+ (*rip)->set_faction(otherfaction);
+ ++rip;
+ }
+ }
+ }
+ }
con_debug << " " << inifile.name() << " " << count << " factions" << std::endl;
- core::Func *func = core::Func::add("list_faction", func_list_faction);
- func->set_info("list available factions");
-
return true;
}
void Faction::done()
{
core::Func::remove("list_faction");
+
+ faction_default = 0;
}
Faction::Faction() :
@@ -135,6 +203,9 @@ void Faction::apply(core::Entity *entity) const
// set secondary color
entity->set_color_second(color_second());
+
+ // set entity faction
+ entity->set_faction(this);
}
} // namespace game