diff options
Diffstat (limited to 'src/game/base/game.cc')
-rw-r--r-- | src/game/base/game.cc | 139 |
1 files changed, 124 insertions, 15 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 128ae7c..667a4c1 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -15,8 +15,8 @@ #include "filesystem/filesystem.h" #include "filesystem/inifile.h" #include "base/game.h" +#include "base/cargo.h" #include "base/collision.h" -#include "base/commodity.h" #include "base/navpoint.h" #include "base/jumppoint.h" #include "base/planet.h" @@ -208,7 +208,7 @@ void Game::func_buy(core::Player *player, const std::string &args) } else if (typestr.compare("cargo") == 0) { player->send("Buying cargo is not supported"); } else { - player->send("unkown item type '" + typestr + "'"); + player->send("Unkown item type '" + typestr + "'"); } return; @@ -228,10 +228,47 @@ void Game::func_launch(core::Player *player, std::string const &args) assert(player->view()->zone() == player->control()->zone()); - Ship *ship = static_cast<Ship *>(player->control()); - ship->shutdown_physics(); core::Entity *dock = player->view(); + + if (dock->moduletype() == ship_enttype) { + + switch(static_cast<Ship *>(dock)->state()) { + case core::Entity::Normal: + case core::Entity::Docked: + break; + + case core::Entity::NoPower: + player->send("^BCan not launch while carrier has no power!"); + return; + break; + + case core::Entity::ImpulseInitiate: + case core::Entity::Impulse: + player->send("^BCan not launch while carrier is using impulse engines!"); + return; + break; + + case core::Entity::JumpInitiate: + case core::Entity::Jump: + player->send("^BCan not launch while carrier is jumping through hyperspace!"); + return; + break; + + default: + if (other_ship->state() != ) { + player->send("^BCan not launch from carrier!"); + return; + } + break; + } + } + + assert(player->control()->moduletype() == ship_enttype); + + Ship *ship = static_cast<Ship *>(player->control()); + ship->shutdown_physics(); + if (dock->type() == core::Entity::Globe) ship->get_location().assign(dock->location() + (dock->axis().forward() *(planet_safe_distance + ship->radius() + dock->radius()))); else @@ -712,12 +749,18 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) return false; } + + + filesystem::IniFile inifile; std::string strval; MenuDescription *menu_dealer = 0; ButtonDescription *button = 0; - ShipDealer *shipdealer = 0; + ShipDealer *shipdealer = 0; + + core::Inventory *inventory = 0; + core::Item *item = 0; inifile.open(menufilename); @@ -725,7 +768,11 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) while (inifile.getline()) { if (inifile.got_section()) { + + item = 0; + if (inifile.got_section("dealer")) { + // TODO replace [dealer] section with individual [ship] sections // dealer menu if (!menu_dealer) { menu_dealer = new MenuDescription(); @@ -739,6 +786,11 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) static_cast<Station *>(entity)->set_shipdealer(shipdealer); } } + + } else if (inifile.got_section("cargo")) { + + } else if (inifile.got_section("ship")) { + } else { inifile.unknown_section(); } @@ -759,16 +811,73 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) button->set_info(model); button->set_alignment(ButtonDescription::Left); menu_dealer->add_button(button); + } else { + std::string msg("unknown ship type '"); + msg.append(strval); + msg.append("'"); + inifile.unknown_error(msg); } } else { inifile.unkown_key(); } - } + } else if (inifile.in_section("cargo")) { + + if (inifile.got_key_label("label", strval)) { + Cargo *cargo = Cargo::find(strval); + if (cargo) { + if (!inventory) { + inventory = new core::Inventory(); + } + item = inventory->find(cargo); + if (!item) { + item = new core::Item(cargo); + item->set_amount(-1); + inventory->add(item); + } + } else { + std::string msg("unkown cargo type '"); + msg.append(strval); + msg.append("'"); + inifile.unknown_error(msg); + } + + } else { + inifile.unkown_key(); + } + + } else if (inifile.in_section("ship")) { + + if (inifile.got_key_label("label", strval)) { + ShipModel *shipmodel = ShipModel::find(strval); + if (shipmodel) { + if (!inventory) { + inventory = new core::Inventory(); + } + item = inventory->find(shipmodel); + if (!item) { + item = new core::Item(shipmodel); + item->set_amount(-1); + inventory->add(item); + } + } else { + std::string msg("unknown ship type '"); + msg.append(strval); + msg.append("'"); + inifile.unknown_error(msg); + } + + } else { + inifile.unkown_key(); + } + } } } } + + if (inventory) + entity->set_inventory(inventory); MenuDescription *menu_main = new MenuDescription(); menu_main->set_label("main"); @@ -810,7 +919,7 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename) bool Game::load_commodities() { // initialize commodities InfoType - Commodity::commodity_infotype = new core::InfoType("cargo"); + Cargo::cargo_infotype = new core::InfoType("cargo"); filesystem::IniFile cargoini; cargoini.open("cargo"); @@ -823,28 +932,28 @@ bool Game::load_commodities() size_t count = 0; - Commodity *commodity = 0; + Cargo *cargo = 0; std::string str; while (cargoini.getline()) { if (cargoini.got_key()) { if (cargoini.section().compare("cargo") == 0) { - if (cargoini.got_key_string("label", str)) { - commodity->set_label(std::string(str)); + if (cargoini.got_key_label("label", str)) { + cargo->set_label(std::string(str)); count++; continue; } else if (cargoini.got_key_string("name", str)) { - commodity->set_name(str); + cargo->set_name(str); continue; } else if (cargoini.got_key_string("info", str)) { - commodity->add_text(str); + cargo->add_text(str); continue; } else if (cargoini.got_key_string("model", str)) { - commodity->set_modelname(str); + cargo->set_modelname(str); continue; } else { @@ -855,7 +964,7 @@ bool Game::load_commodities() } else if (cargoini.got_section()) { if (cargoini.got_section("cargo")) { - commodity = new Commodity(); + cargo = new Cargo(); } else if (cargoini.got_section()) { cargoini.unknown_section(); @@ -898,7 +1007,7 @@ bool Game::load_ships() while (shipsini.getline()) { if (shipsini.got_key()) { if (shipsini.section().compare("ship") == 0) { - if (shipsini.got_key_string("label", str)) { + if (shipsini.got_key_label("label", str)) { shipmodel->set_label(str); count++; continue; |