Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 5a67ebfb5827a770a503de3f5639f082773d17a8 (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
137
/*
   base/cargo.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 <assert.h>
#include <cmath>

#include "sys/sys.h"
#include "filesystem/inifile.h"
#include "auxiliary/functions.h"
#include "core/func.h"
#include "base/game.h"
#include "base/cargo.h"

namespace game
{

core::InfoType *Cargo::cargo_infotype = 0;

void func_list_cargo(const std::string &args)
{
	Cargo::list();
}

// loads cargo types from ini file
bool Cargo::init()
{

	// initialize cargo InfoType
	cargo_infotype = new core::InfoType("cargo");
	
	filesystem::IniFile cargoini;
	cargoini.open("ini/cargo");
	if (!cargoini.is_open()) {
		con_error << "Could not open " << cargoini.name() << "!" << std::endl;
		return false;
	}

	con_print << "^BLoading cargo..." << std::endl;
	
	size_t count = 0;
	
	Cargo *cargo = 0;
	std::string str;
	long l;
	float f;
	
	while (cargoini.getline()) {
		if (cargoini.got_key()) {
		
			if (cargoini.section().compare("cargo") == 0) {
				if (cargoini.got_key_label("label", str)) {
					cargo->set_label(str);
					continue;
					
				} else if (cargoini.got_key_string("name", str)) {
					cargo->set_name(str);
					continue;

				} else if (cargoini.got_key_string("info", str)) {
					cargo->add_text(str);
					continue;
					
				} else if (cargoini.got_key_string("model", str)) {
					cargo->set_modelname(str);
					continue;
							
				} else if (cargoini.got_key_long("price", l)) {
					cargo->set_price(l);
					continue;
					
				} else if (cargoini.got_key_float("volume", f)) {
					cargo->set_volume(f);
					continue;
					
				} else {
					cargoini.unknown_key();
				}
			}
			
		} else if (cargoini.got_section()) {
		
			if (cargoini.got_section("cargo")) {
				cargo = new Cargo();
				count++;

			} else if (cargoini.got_section()) {
				cargoini.unknown_section();
			}		
		}
	}
	
	// add cargo infos
	con_debug << "  " << cargoini.name() << " " << count << " cargo types" << std::endl;
	
	cargoini.close();
	
	core::Func *func = core::Func::add("list_cargo", func_list_cargo);
	func->set_info("list available cargo types");
	
	return true;
}

void Cargo::done()
{
	core::Func::remove("list_cargo");
}

void Cargo::list()
{
	core::Info::list(cargo_infotype);
}

/* ---- class Cargo -------------------------------------------- */

Cargo::Cargo() : core::Info(cargo_infotype)
{
	set_volume(1);
}

Cargo::~Cargo()
{
}

Cargo *Cargo::find(const std::string & label)
{
	if (!label.size()) {
		return 0;
	}
	
	return (Cargo *) core::Info::find(cargo_infotype, label);
}

} // namespace game