diff options
Diffstat (limited to 'src/game/base/game.cc')
-rw-r--r-- | src/game/base/game.cc | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index c0ef4ce..a075574 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -37,6 +37,8 @@ core::Entity *Default::view = 0; ShipModel *Default::shipmodel = 0; long Default::credits = 0; +const float planet_safe_distance = 150.0f; + void Default::clear() { zone = 0; @@ -74,9 +76,11 @@ void Game::func_join(core::Player *player, std::string const &args) ship->get_location().assign(dock->location() + (dock->axis().forward() *((ship->radius() + dock->radius())*2.0f))); ship->get_axis().assign(dock->axis()); ship->set_state(core::Entity::Docked); + ship->reset(); player->set_view(dock); } - + + std::string message("^B"); message.append(player->name()); message.append("^B joins the game."); @@ -177,8 +181,34 @@ void Game::func_dock(core::Player *player, core::Entity *entity) if (player->control()->state() != core::Entity::Normal) return; - if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) { - entity->dock(player->control()); + if (player->control()->moduletype() != ship_enttype) + return; + + if (!(entity->flags() & core::Entity::Dockable)) { + return; + } + + Ship * ship = static_cast<Ship *>(player->control()); + + float range = entity->radius() + ship->radius(); + if (entity->moduletype() == planet_enttype) { + range = planet_safe_distance; + } + + if (math::distance(entity->location(), ship->location()) > range) { + if (ship->owner()) { + ship->owner()->send("^W" + entity->name() + " out of range"); + } + return; + } + + ship->get_location().assign(entity->location()); + ship->set_state(core::Entity::Docked); + ship->reset(); + + if (ship->owner() && ship->owner()->control() == ship) { + ship->owner()->set_view(entity); + ship->owner()->send("^BDocking at " + entity->name()); } } @@ -1170,6 +1200,11 @@ bool Game::validate_zone(core::Zone *zone) generate_entity_menus(entity); } } + + // initialize physics on planets and entities with a model + if ((entity->entity_moduletypeid == planet_enttype) || (entity->model())) { + entity->reset(); + } } return true; |