diff options
Diffstat (limited to 'src/game/base/game.cc')
-rw-r--r-- | src/game/base/game.cc | 204 |
1 files changed, 133 insertions, 71 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index d20dd8c..7dcf300 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -18,6 +18,7 @@ #include "base/navpoint.h" #include "base/jumppoint.h" #include "base/planet.h" +#include "base/station.h" #include "base/racetrack.h" #include "base/ship.h" #include "base/star.h" @@ -95,61 +96,6 @@ void Game::func_spectate(core::Player *player, std::string const &args) player->set_view(0); } -// a player buys a ship -void Game::func_buy(core::Player *player, std::string const &args) -{ - if (!g_devel->value() && !player->view()) { - player->send("Cheats disabled."); - return; - } - - // FIXME verify the base sells this ship - - std::string shipname; - std::string helpstr; - std::istringstream is(args); - is >> shipname; - aux::to_lowercase(shipname); - - ShipModel *shipmodel = 0; - for (ShipModel::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { - if (shipname == (*smit).first) { - shipmodel = (*smit).second; - break; - } - - if (helpstr.size()) - helpstr.append("^N|^B"); - helpstr.append((*smit).second->label()); - } - - if (shipmodel) { - // player has only ship for now - if (player->control()) { - player->remove_asset(player->control()); - } - - core::Entity *dock = player->view(); - Ship * ship = new Ship(player, shipmodel); - ship->set_zone(player->zone()); - player->set_control(ship); - - if (dock) { - player->control()->location().assign(dock->location()); - player->control()->set_eventstate(core::Entity::Docked); - ship->entity_axis.assign(dock->axis()); - ship->entity_axis.change_direction(180.0f); - player->set_view(dock); - } - - player->send("^BPurchased " + aux::article(shipmodel->name())); - player->sound("game/buy-ship"); - - } else { - player->send("Usage: buy [^B" + helpstr + "^N]"); - } -} - // a player sends standard hails void Game::func_hail(core::Player *player, std::string const &args) { @@ -308,7 +254,7 @@ void Game::func_goto(core::Player *player, const std::string &args) } } -/* -- class Base -------------------------------------------------- */ +/* -- class Game -------------------------------------------------- */ Game::Game() : core::Module("base", "Project::OSiRiON", true) { @@ -324,16 +270,16 @@ void Game::init() { ShipModel::clear(); - if (!load_world()) { + if (!load_ships()) { abort(); return; } - - if (!load_ships()) { + + if (!load_world()) { abort(); return; } - + // add engine functions core::Func *func = 0; @@ -349,7 +295,7 @@ void Game::init() func = core::Func::add("spectate", Game::func_spectate); func->set_info("leave the game and spectate"); - func = core::Func::add("buy", Game::func_buy); + func = core::Func::add("buy", ShipDealer::func_buy); func->set_info("buy a ship"); func = core::Func::add("jump", Game::func_jump); @@ -486,6 +432,7 @@ bool Game::load_zone(core::Zone *zone) size_t count = 0; + Station *station = 0; Planet *planet = 0; Star *star = 0; NavPoint *navpoint = 0; @@ -541,6 +488,11 @@ bool Game::load_zone(core::Zone *zone) planet = new Planet(); planet->set_zone(zone); count ++; + + } else if (zoneini.got_section("station")) { + station = new Station(); + station->set_zone(zone); + count ++; } else if (zoneini.got_section("entity")) { entity = new core::Entity(); @@ -605,7 +557,6 @@ bool Game::load_zone(core::Zone *zone) } else if (zoneini.got_key_bool("dock", b)) { if (b) { planet->set_flag(core::Entity::Dockable); - core::Descriptions::load_entity_menus(planet, "zones/" + zone->label() + "/" + planet->label()); } else { planet->unset_flag(core::Entity::Dockable); } @@ -617,6 +568,17 @@ bool Game::load_zone(core::Zone *zone) } else { zoneini.unkown_key(); } + + } else if (zoneini.in_section("station")) { + if (core::Parser::got_entity_key(zoneini, station)) { + continue; + } else if (zoneini.got_key_bool("default", b)) { + if (b) { + zone->set_default_view(station); + } + } else { + zoneini.unkown_key(); + } } else if (zoneini.in_section("racetrack")) { if (core::Parser::got_entity_key(zoneini, racetrack)) { @@ -639,13 +601,6 @@ bool Game::load_zone(core::Zone *zone) if (b) { zone->set_default_view(entity); } - } else if (zoneini.got_key_bool("dock", b)) { - if (b) { - entity->set_flag(core::Entity::Dockable); - core::Descriptions::load_entity_menus(entity, "zones/" + zone->label() + "/" + entity->label()); - } else { - entity->unset_flag(core::Entity::Dockable); - } } else { zoneini.unkown_key(); } @@ -663,7 +618,7 @@ bool Game::load_zone(core::Zone *zone) bool Game::validate_zone(core::Zone *zone) { - con_debug << " validating " << zone->name() << std::endl; + con_print << "^BValidating zone " << zone->label() << "..." << std::endl; for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { core::Entity *entity = (*it); @@ -675,9 +630,113 @@ bool Game::validate_zone(core::Zone *zone) // validate jump gate JumpGate *jumpgate = static_cast<JumpGate *>(entity); jumpgate->validate(); + } else { + if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) + load_menus(entity, "zones/" + zone->label() + "/" + entity->label()); + } + } + + return true; +} + +bool Game::load_menus(core::Entity *entity, const std::string &menufilename) +{ + using core::MenuDescription; + using core::ButtonDescription; + + if ((entity->moduletype() != planet_enttype) && (entity->moduletype() != station_enttype)) { + return false; + } + + filesystem::IniFile inifile; + + std::string strval; + MenuDescription *menu_dealer = 0; + ButtonDescription *button = 0; + ShipDealer *shipdealer = 0; + + inifile.open(menufilename); + + if (inifile.is_open()) { + while (inifile.getline()) { + + if (inifile.got_section()) { + if (inifile.got_section("dealer")) { + // dealer menu + if (!menu_dealer) { + menu_dealer = new MenuDescription(); + menu_dealer->set_label("dealer"); + menu_dealer->set_text("Ship dealer"); + + shipdealer = new ShipDealer(); + if (entity->moduletype() == planet_enttype) { + static_cast<Planet *>(entity)->set_shipdealer(shipdealer); + } else if (entity->moduletype() == station_enttype) { + static_cast<Station *>(entity)->set_shipdealer(shipdealer); + } + } + } else { + inifile.unknown_section(); + } + + } else if (inifile.got_key()) { + + if (inifile.in_section("dealer")) { + + if (inifile.got_key_string("ship", strval)) { + aux::to_label(strval); + ShipModel *model = shipdealer->add(strval); + if (model) { + button = new ButtonDescription(); + button->set_text("buy " + model->name()); + button->set_command("buy " + model->label()); + button->set_modelname("ships/" + model->modelname()); + button->set_alignment(ButtonDescription::Left); + menu_dealer->add_button(button); + } + } else { + inifile.unkown_key(); + } + + } + } } + + } + + MenuDescription *menu_main = new MenuDescription(); + menu_main->set_label("main"); + menu_main->set_text("Launch area"); + entity->add_menu(menu_main); + + if (menu_dealer) { + button = new ButtonDescription(); + button->set_text("Return"); + button->set_command("menu view main"); + button->set_alignment(ButtonDescription::Center); + menu_dealer->add_button(button); + + entity->add_menu(menu_dealer); + + button = new ButtonDescription(); + button->set_text("Ship dealer"); + button->set_command("menu view dealer"); + button->set_alignment(ButtonDescription::Center); + menu_main->add_button(button); } + button = new ButtonDescription(); + button->set_text("Launch"); + button->set_command("launch"); + button->set_alignment(ButtonDescription::Center); + menu_main->add_button(button); + + if (inifile.is_open()) { + size_t n = entity->menus().size(); + con_debug << " " << inifile.name() << " " << n << " " << aux::plural("menu", n) << std::endl; + inifile.close(); + } + return true; } @@ -729,8 +788,8 @@ bool Game::load_ships() } } } else if (shipsini.got_section("ship")) { + if (shipmodel && !ShipModel::find(shipmodel)) delete shipmodel; shipmodel = new ShipModel(); - if (!default_shipmodel) default_shipmodel = shipmodel; @@ -740,6 +799,8 @@ bool Game::load_ships() } shipsini.close(); + if (shipmodel && !ShipModel::find(shipmodel)) delete shipmodel; + con_debug << " " << shipsini.name() << " " << ShipModel::registry.size() << " ship models" << std::endl; if (!default_shipmodel) { @@ -772,3 +833,4 @@ void Game::player_disconnect(core::Player *player) } // namespace game + |