Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 0220d3d3e94cddcd523d4c35a6fc3a33bb6c2482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
   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;
}

void Faction::done()
{
	core::Func::remove("list_faction");
}

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_second(color_second());
}

} // namespace game