From 130682a299e202c4a02521c05ab11054fc0ba6b3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 22 Apr 2012 19:50:50 +0000 Subject: Load entity weapon slots, prevent the game from crashing when launching after obtaining a ship through 'give' while docked. --- src/game/base/game.cc | 10 +++++++++- src/game/base/ship.cc | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index d8af507..c116b8b 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -324,7 +324,9 @@ void Game::func_give(core::Player *player, const std::string &args) player->send("^WNot enough cargo space to transfer inventory!"); return; } - + assert(player->control()->moduletype() == ship_enttype); + Ship * oldship = static_cast(player->control()); + Ship * ship = new Ship(player, shipmodel); core::Entity *view = player->view(); if (view && (view == player->control())) { @@ -342,6 +344,7 @@ void Game::func_give(core::Player *player, const std::string &args) ship->set_zone(player->control()->zone()); ship->get_location().assign(player->control()->location()); ship->set_state(player->control()->state()); + ship->set_dock(oldship->dock()); ship->get_axis().assign(player->control()->axis()); ship->set_thrust(player->control()->thrust()); ship->reset(); @@ -1534,6 +1537,11 @@ bool Game::validate_zone(core::Zone *zone) if ((entity->entity_moduletypeid == planet_enttype) || (entity->model())) { entity->reset(); } + + if (entity->model()) { + entity->add_slots(); + entity->slots()->load(entity->model()); + } } return true; diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 9a6d02e..ba30d67 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -75,6 +75,11 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro add_inventory(); inventory()->set_capacity(ship_shipmodel->maxcargo()); } + + if (model()) { + add_slots(); + slots()->load(model()); + } // menus for docked players if (ship_shipmodel->dockable()) { @@ -354,8 +359,7 @@ void Ship::set_dock(core::Entity *dock) get_location().assign(dock->location()); get_axis().assign(dock->axis()); ship_dock = dock; - - + // if the dock is not owned by a player. set it as spawn set_state(core::Entity::Docked); const core::Player *owner = (dock->type() == core::Entity::Controlable ? static_cast(dock)->owner() : 0 ); -- cgit v1.2.3