/* 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") { 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_key()) { if (ini.section().compare("intro") == 0) { if (ini.got_key_string("sky", strval)) { intro_zone->set_sky(strval); continue; } } else if (ini.section().compare("convoy") == 0) { 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.section().compare("globe") == 0) { 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 { con_warn << ini.name() << " unknown key '" << ini.key() << "' at line " << ini.line() << std::endl; } } } else if (ini.got_section("intro")) { continue; } else if (ini.got_section("globe")) { globe = new core::EntityGlobe(); globe->set_zone(intro_zone); } else if (ini.got_section()) { con_warn << ini.name() << " unknown section '" << ini.section() << "' at line " << ini.line() << std::endl; } } 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; } } }