From 164e3c5b1cd9e6d6f7ca26964df4c54394eb1c84 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 21 Dec 2008 18:03:58 +0000 Subject: multiple introductions --- src/game/intro/convoy.cc | 61 ++++++++---------------------- src/game/intro/convoy.h | 24 +++--------- src/game/intro/intro.cc | 98 +++++++++++++++++++++++++++++++----------------- src/game/intro/intro.h | 8 ++-- 4 files changed, 90 insertions(+), 101 deletions(-) (limited to 'src/game') diff --git a/src/game/intro/convoy.cc b/src/game/intro/convoy.cc index 3421538..6671369 100644 --- a/src/game/intro/convoy.cc +++ b/src/game/intro/convoy.cc @@ -19,15 +19,6 @@ Member::Member(std::string const &model) : core::EntityControlable(0, 1) set_modelname(model); entity_thrust = 1.0f; -/* - entity_speed = 1.0f; - - entity_location.x = -16.0f; - entity_location.y = -math::randomf(8.0f); - entity_location.z = math::randomf(8.0f) - 6.0f; - - entity_axis.change_direction(15.0f); -*/ } Member::~Member() @@ -36,15 +27,19 @@ Member::~Member() void Member::frame(float seconds) { - entity_location += entity_axis.forward() * speed() * thrust() * seconds; + entity_location += axis().forward() * speed() * thrust() * seconds; } -/* ---- class convoy ----------------------------------------------- */ +/* ---- class Convoy ----------------------------------------------- */ -Convoy::Convoy(core::Zone *zone) +Convoy::Convoy(core::Zone *zone) : core::EntityDynamic() { - convoy_zone = zone; - convoy_speed = 1; + set_zone(zone); + set_label("convoy"); + set_name("Convoy"); + + entity_speed = 1; + entity_serverside = true; } Convoy::~Convoy() @@ -52,30 +47,6 @@ Convoy::~Convoy() convoy_members.clear(); } -void Convoy::set_color(const math::Color &color) -{ - convoy_color.assign(color); -} -void Convoy::set_color_second(const math::Color &color) -{ - convoy_color_second.assign(color); -} - -void Convoy::set_location(const math::Vector3f &location) -{ - convoy_location.assign(location); -} - -void Convoy::change_direction(float angle) -{ - convoy_axis.change_direction(angle); -} - -void Convoy::set_speed(const float speed) -{ - convoy_speed = speed; -} - void Convoy::add(const char *model) { add(std::string(model)); @@ -87,21 +58,21 @@ void Convoy::add(const std::string &model) Member *member = new Member(model); convoy_members.push_back(member); - member->set_zone(convoy_zone); - member->entity_color.assign(convoy_color); - member->entity_color_second.assign(convoy_color_second); + member->set_zone(zone()); + member->entity_color.assign(color()); + member->entity_color_second.assign(color_second()); member->entity_thrust = 1.0f; - member->entity_speed = convoy_speed; + member->entity_speed = speed(); - member->entity_location.assign(convoy_location); + member->entity_location.assign(location()); d = ((float) convoy_members.size()) * 0.5f; member->entity_location.x += math::randomf((float) convoy_members.size()) -d; member->entity_location.y += math::randomf((float) convoy_members.size()) -d; member->entity_location.z += (math::randomf((float) convoy_members.size()) -d) * 0.5f; - member->entity_axis.change_direction(15.0f); + member->entity_axis.assign(axis()); } void Convoy::frame(float seconds) @@ -109,7 +80,7 @@ void Convoy::frame(float seconds) for (Members::iterator it = convoy_members.begin(); it != convoy_members.end(); ) { Member *member = (*it); if (member->location().length() > 64.0f) { - std::string model(member->label()); + std::string model(member->model()->name()); member->die(); convoy_members.erase(it++); add(model); diff --git a/src/game/intro/convoy.h b/src/game/intro/convoy.h index 20eb0e1..14016f4 100644 --- a/src/game/intro/convoy.h +++ b/src/game/intro/convoy.h @@ -14,6 +14,8 @@ namespace intro { +/* ---- class Member ----------------------------------------------- */ + class Member : public core::EntityControlable { public: @@ -23,7 +25,9 @@ public: void frame(float seconds); }; -class Convoy +/* ---- class Convoy ----------------------------------------------- */ + +class Convoy : public core::EntityDynamic { public: Convoy(core::Zone *zone); @@ -32,27 +36,11 @@ public: void add(const char *model); void add(const std::string &model); - void frame(float seconds); - - void set_color(const math::Color &color); - void set_color_second(const math::Color &color); - - void set_location(math::Vector3f const &location); - - void set_speed(const float speed); - - void change_direction(float angle); + virtual void frame(float seconds); private: typedef std::list Members; Members convoy_members; - core::Zone *convoy_zone; - math::Color convoy_color; - math::Color convoy_color_second; - - math::Vector3f convoy_location; - math::Axis convoy_axis; - float convoy_speed; }; } diff --git a/src/game/intro/intro.cc b/src/game/intro/intro.cc index ed512ca..edb80d4 100644 --- a/src/game/intro/intro.cc +++ b/src/game/intro/intro.cc @@ -21,21 +21,15 @@ core::Module *factory() Intro::Intro() : core::Module("Introduction", false) { - intro_zone = 0; - intro_convoy = 0; - - /// 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; } + + core::Func *func = 0; + + func = core::Func::add("intro", Intro::func_intro); + func->set_info("[int] view specified introduction"); } bool Intro::load_world() @@ -50,6 +44,9 @@ bool Intro::load_world() return false; } + core::Zone *zone = 0; + Convoy *convoy = 0; + std::string strval; core::EntityGlobe *globe = 0; math::Color color; @@ -61,53 +58,69 @@ bool Intro::load_world() if (ini.got_section()) { if (ini.got_section("intro")) { - continue; + + zone = new core::Zone("intro"); + zone->set_name("Introduction"); + zone->set_sky("sky"); + core::Zone::add(zone); } else if (ini.got_section("convoy")) { - continue; + if (zone) { + convoy = new Convoy(zone); + } } else if (ini.got_section("globe")) { - globe = new core::EntityGlobe(); - globe->set_zone(intro_zone); + if (zone) { + globe = new core::EntityGlobe(); + globe->set_zone(zone); + } } else { ini.unknown_section(); } - } else if (ini.got_key()) { + } else if (zone && ini.got_key()) { if (ini.in_section("intro")) { - if (ini.got_key_string("sky", strval)) { - intro_zone->set_sky(strval); - continue; + + if (ini.got_key_string("label", strval)) { + zone->set_label(strval); + + } else if (ini.got_key_string("sky", strval)) { + zone->set_sky(strval); } 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); + + if (ini.got_key_string("label", strval)) { + convoy->set_label(strval); + + } else if (ini.got_key_color("color", color)) { + convoy->set_color(color); } else if (ini.got_key_color("colorsecond", color)) { - intro_convoy->set_color_second(color); + convoy->set_color_second(color); } else if (ini.got_key_vector3f("location", v)) { - intro_convoy->set_location(v); + convoy->entity_location.assign(v); } else if (ini.got_key_float("direction", f)) { - intro_convoy->change_direction(f); + convoy->axis().change_direction(f); } else if (ini.got_key_float("speed", f)) { - intro_convoy->set_speed(f); + convoy->entity_speed = f; } else if (ini.got_key_string("ship", strval)) { - intro_convoy->add(strval); + 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)) { @@ -128,27 +141,44 @@ bool Intro::load_world() void Intro::player_connect(core::Player *player) { - player->set_zone(intro_zone); + core::Zone::Registry::iterator it = core::Zone::registry().begin(); + if (it != core::Zone::registry().end()) { + size_t m = math::randomi(core::Zone::registry().size()); + for (size_t i = 0; i < m; i++) { + it++; + } + player->set_zone((*it).second); + } } void Intro::player_disconnect(core::Player *player) { + } void Intro::frame(float seconds) { - if (intro_convoy) { - intro_convoy->frame(seconds); - } + } Intro::~Intro() { - intro_zone = 0; + core::Func::remove("intro"); +} - if (intro_convoy) { - delete intro_convoy; - intro_convoy = 0; +void Intro::func_intro(core::Player *player, std::string const &args) +{ + std::stringstream str(args); + size_t id; + if (str >> id) { + core::Zone *zone = core::Zone::find(id); + if (zone) { + player->set_zone(zone); + } else { + core::Zone::list(); + } + } else { + core::Zone::list(); } } diff --git a/src/game/intro/intro.h b/src/game/intro/intro.h index d94b1f5..2e2f8fb 100644 --- a/src/game/intro/intro.h +++ b/src/game/intro/intro.h @@ -31,12 +31,12 @@ public: /// is called when a player disconnects virtual void player_disconnect(core::Player *player); - private: - core::Zone *intro_zone; - Convoy *intro_convoy; - bool load_world(); + + /* ---- engine functions ----------------------------------- */ + + static void func_intro(core::Player *player, std::string const &args); }; /// factory function -- cgit v1.2.3