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.cc131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/game/base/faction.cc b/src/game/base/faction.cc
new file mode 100644
index 0000000..2194844
--- /dev/null
+++ b/src/game/base/faction.cc
@@ -0,0 +1,131 @@
+/*
+ base/faction.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "core/func.h"
+#include "core/parser.h"
+#include "base/faction.h"
+
+namespace game {
+
+core::InfoType *Faction::faction_infotype = 0;
+
+void func_list_faction(const std::string &args)
+{
+ Faction::list();
+}
+
+Faction *Faction::find(const std::string & label)
+{
+ if (!label.size()) {
+ return 0;
+ }
+
+ return (Faction *) core::Info::find(faction_infotype, label);
+}
+
+void Faction::list()
+{
+ core::Info::list(faction_infotype);
+}
+
+bool Faction::init()
+{
+ // initialize faction InfoType
+ faction_infotype = new core::InfoType("faction");
+
+ std::string inifilename("ini/factions");
+
+ filesystem::IniFile inifile;
+ inifile.open(inifilename);
+
+ if (!inifile.is_open()) {
+ con_warn << "Could not open " << inifile.name() << std::endl;
+ return false;
+ }
+
+ con_print << "^BLoading factions..." << std::endl;
+
+ size_t count = 0;
+ Faction *faction = 0;
+ std::string strvalue;
+ math::Color colorvalue;
+
+ while (inifile.getline()) {
+
+ if (inifile.got_section()) {
+
+ faction = 0;
+
+ if (inifile.got_section("faction")) {
+ count++;
+ faction = new Faction();
+
+ } else {
+ inifile.unknown_section();
+ }
+
+ } else if (inifile.got_key()) {
+
+ if (inifile.in_section("faction")) {
+
+ if (inifile.got_key_label("label", strvalue)) {
+ faction->set_label(strvalue);
+
+ } else if (inifile.got_key_string("name", strvalue)) {
+ faction->set_name(strvalue);
+
+ } else if (inifile.got_key_string("info", strvalue)) {
+ faction->add_text(strvalue);
+
+ } else if (inifile.got_key_color("color", colorvalue)) {
+ faction->set_color(colorvalue);
+
+ } else if (inifile.got_key_color("colorsecond", colorvalue)) {
+ faction->set_color_second(colorvalue);
+
+ } else {
+ inifile.unkown_key();
+ }
+ }
+ }
+ }
+
+ inifile.close();
+
+ if (!count) {
+ con_warn << "No factions found!" << std::endl;
+ return true; // non-fatal
+ }
+
+ 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;
+}
+
+Faction::Faction() :
+ core::Info(faction_infotype),
+ faction_color(),
+ faction_color_second()
+{
+}
+
+Faction::~Faction()
+{
+}
+
+void Faction::apply(core::Entity *entity) const
+{
+ // set primary color
+ entity->set_color(color());
+
+ // set secondary color
+ entity->set_color(color());
+}
+
+} // namespace game