Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 4eb9a10e7b6af7afc51ea33206bd4a440cfa9e1b (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
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
   intro/intro.cc
   This file is part of the Osirion project and is distributed under 
   the terms of the GNU General Public License version 2 
*/

#include "intro/intro.h"
#include "core/core.h"
#include "core/parser.h"
#include "filesystem/filesystem.h"
#include "filesystem/inifile.h"
#include "math/color.h"
#include "sys/sys.h"

namespace intro {

Intro::Intro() : core::Module("Introduction")
{
	module_interactive = false;
	intro_zone = 0;
	intro_convoy = 0;
}

Intro::~Intro()
{
}

void Intro::init()
{
	/// intialize a single zone for the introduction
	intro_zone = new core::Zone("intro");
	intro_zone->set_name("Introduction");
	intro_zone->set_sky("sky");
	core::Zone::add(intro_zone);

	intro_convoy = new Convoy(intro_zone);

	if (!load_world()) {
		abort();
		return;
	}

	module_running = true;
}

bool Intro::load_world()
{
	std::string filename("intro");

	filesystem::IniFile ini;
	ini.open(filename);

	if (!ini.is_open()) {
		con_error << "Could not open " << ini.name() << std::endl;
		return false;
	}

	std::string strval;
	core::EntityGlobe *globe = 0;
	math::Color color;
	bool b;
	
	while (ini.getline()) {

		if (ini.got_section()) {
			if (ini.got_section("intro")) {
				continue;
	
			} else if (ini.got_section("convoy")) {
				continue;
	
			} else if (ini.got_section("globe")) {
				globe = new core::EntityGlobe();
				globe->set_zone(intro_zone);
	
			} else {
				ini.unknown_section();
			}
		} else if (ini.got_key()) {

			if (ini.in_section("intro")) {
				if (ini.got_key_string("sky", strval)) {
					intro_zone->set_sky(strval);
					continue;

				} else if (ini.got_key()) {
					ini.unkown_key();
				}

			} else if (ini.in_section("convoy")) {
				if (ini.got_key_color("color", color)) {
					intro_convoy->set_color(color);

				} else if (ini.got_key_color("colorsecond", color)) {
					intro_convoy->set_color_second(color);

				} else if (ini.got_key_string("ship", strval)) {
					intro_convoy->add(strval);

				} else if (ini.got_key()) {
					ini.unkown_key();
				}

			} else if (ini.in_section("globe")) {
				if (core::Parser::got_entity_key(ini, globe)) {
					continue;
				} else if (ini.got_key_string("texture", globe->entity_texture)) {
					continue;
				} else if (ini.got_key_float("rotationspeed", globe->entity_rotationspeed)) {
					continue;
				} else if (ini.got_key_bool("bright", b)) {
					if (b) { globe->entity_flags |= core::Entity::Bright; }
				} else if (ini.got_key()) {
					ini.unkown_key();
				}
			}
		}
	}

	return true;
}

void Intro::player_connect(core::Player *player)
{
	player->set_zone(intro_zone);
}

void Intro::player_disconnect(core::Player *player)
{
}

void Intro::frame(float seconds)
{
	if (intro_convoy) {
		intro_convoy->frame(seconds);
	}
}

void Intro::shutdown()
{
	intro_zone = 0;

	if (intro_convoy) {
		delete intro_convoy;
		intro_convoy = 0;
	}
}

}