From 71b517e154e4644fcf0f8bb3b8b40b7898ecdd9d Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 16 Oct 2013 20:59:08 +0000 Subject: Added support for autopilot formation flight and docking. --- src/game/base/game.cc | 100 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 15 deletions(-) (limited to 'src/game/base/game.cc') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 72a684b..789f2d5 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -163,6 +163,7 @@ void Game::func_freeflight(core::Player *player, std::string const &args) ship->set_autopilot_target(0); ship->unset_autopilot_flag(Ship::AutoPilotEnabled); + // TODO replace with "autopilot disabled" voice player->send("Autopilot disabled"); } @@ -183,20 +184,15 @@ void Game::func_target_goto(core::Player *player, core::Entity *entity) Ship * ship = static_cast(player->control()); - if (ship->has_autopilot_flag(Ship::AutoPilotEnabled) && (entity == ship->autopilot_target())) { - ship->set_autopilot_target(0); - ship->unset_autopilot_flag(Ship::AutoPilotEnabled); - player->send("Autopilot disabled"); - } else { - ship->set_autopilot_target(entity); - ship->set_autopilot_flag(Ship::AutoPilotEnabled); - ship->unset_autopilot_flag(Ship::AutoPilotDock); - ship->unset_autopilot_flag(Ship::AutoPilotFormation); - player->send("Autopilot set to " + entity->name()); - } + ship->set_autopilot_target(entity); + ship->set_autopilot_flag(Ship::AutoPilotEnabled); + ship->unset_autopilot_flag(Ship::AutoPilotDock); + ship->unset_autopilot_flag(Ship::AutoPilotFormation); + // TODO replace with "goto" voice + player->send("Autopilot set to " + entity->name()); } -// a player sends a docking request +/* void Game::func_target_dock(core::Player *player, core::Entity *entity) { if (!player->control()) @@ -224,7 +220,7 @@ void Game::func_target_dock(core::Player *player, core::Entity *entity) float range = entity->radius() + ship->radius(); if (entity->moduletype() == planet_enttype) { - range += planet_safe_distance; + range += PLANET_SAFE_DISTANCE; } core::Player *owner = (entity->type() == core::Entity::Controlable ? static_cast(entity)->owner() : 0 ); @@ -269,6 +265,77 @@ void Game::func_target_dock(core::Player *player, core::Entity *entity) core::server()->module()->player_save(player); } } +*/ + +// a player sends a docking request +void Game::func_target_dock(core::Player *player, core::Entity *entity) +{ + if (!player->control()) { + return; + } + + if (player->control() == entity) { + return; + } + + if (!entity->has_flag(core::Entity::Dockable)) { + return; + } + + if (player->control()->zone() != entity->zone()) { + return; + } + + if (player->control()->moduletype() != ship_enttype) { + return; + } + + Ship * ship = static_cast(player->control()); + + ship->set_autopilot_target(entity); + ship->set_autopilot_flag(Ship::AutoPilotEnabled); + ship->set_autopilot_flag(Ship::AutoPilotDock); + ship->unset_autopilot_flag(Ship::AutoPilotFormation); + + if (math::distance(player->control()->location(), entity->location()) > (player->control()->radius() + entity->radius() + PLANET_SAFE_DISTANCE)) { + // TODO replace with "dock" voice + player->send("Autopilot set to dock at " + entity->name()); + } +} + +void Game::func_target_formation(core::Player *player, core::Entity *entity) +{ + if (!player->control()) { + return; + } + + if (player->control() == entity) + return; + + if (entity->type() != core::Entity::Controlable) { + return; + } + + if (player->control()->zone() != entity->zone()) { + return; + } + + if (player->control()->moduletype() != ship_enttype) { + return; + } + + Ship * ship = static_cast(player->control()); + + ship->set_autopilot_target(entity); + ship->set_autopilot_flag(Ship::AutoPilotEnabled); + ship->unset_autopilot_flag(Ship::AutoPilotDock); + ship->set_autopilot_flag(Ship::AutoPilotFormation); + + if (math::distance(player->control()->location(), entity->location()) > (player->control()->radius() + entity->radius() + PLANET_SAFE_DISTANCE)) { + // TODO replace with "formation" voice + player->send("Autopilot set to formation with " + entity->name()); + } +} // a player sends a standard hail void Game::func_target_hail(core::Player *player, core::Entity *entity) @@ -1561,7 +1628,7 @@ void Game::func_goto(core::Player *player, const std::string &args) if (dock) { if (dock->type() == core::Entity::Globe) { // target is a planet: keep a safe distance - ship->get_location().assign(dock->location() + (dock->axis().forward() * (planet_safe_distance + ship->radius() + dock->radius()))); + ship->get_location().assign(dock->location() + (dock->axis().forward() * (PLANET_SAFE_DISTANCE + ship->radius() + dock->radius()))); ship->get_axis().assign(dock->axis()); ship->get_axis().change_direction(180.0f); @@ -1696,7 +1763,10 @@ Game::Game() : core::Module("Project::OSiRiON", true) func->set_info("set autopilot to target"); func = core::Func::add("@dock", Game::func_target_dock); - func->set_info("send a docking request to target"); + func->set_info("set autopilot to dock at target"); + + func = core::Func::add("@formation", Game::func_target_formation); + func->set_info("set autopilot to formation flight with target"); func = core::Func::add("@hail", Game::func_target_hail); func->set_info("send a standard hail to target"); -- cgit v1.2.3