diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/game.cc | 116 | ||||
-rw-r--r-- | src/game/base/savegame.cc | 10 |
2 files changed, 40 insertions, 86 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 79fd167..f2db00c 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -103,6 +103,10 @@ void Game::func_join(core::Player *player, std::string const &args) player->reputation().clear(); Faction::apply_default(player->reputation()); + + // reset player timestamps + player->set_time_wasted(0); + player->set_time_joined(); } player->set_dirty(); @@ -151,8 +155,15 @@ void Game::func_impulse(core::Player *player, std::string const &args) if (player->control()->moduletype() != ship_enttype) return; - + Ship * ship = static_cast<Ship *>(player->control()); + if (ship->has_autopilot_flag(Ship::AutoPilotEnabled)) { + ship->set_autopilot_target(0); + ship->unset_autopilot_flag(Ship::AutoPilotEnabled); + + // TODO replace with "Canceled" voice + player->send("Autopilot canceled"); + } ship->func_impulse(); } @@ -167,10 +178,13 @@ void Game::func_freeflight(core::Player *player, std::string const &args) Ship * ship = static_cast<Ship *>(player->control()); - ship->set_autopilot_target(0); - ship->unset_autopilot_flag(Ship::AutoPilotEnabled); - // TODO replace with "autopilot disabled" voice - player->send("Autopilot disabled"); + if (ship->has_autopilot_flag(Ship::AutoPilotEnabled)) { + ship->set_autopilot_target(0); + ship->unset_autopilot_flag(Ship::AutoPilotEnabled); + + // TODO replace with "Canceled" voice + player->send("Autopilot canceled"); + } } // autopilot goto @@ -194,85 +208,11 @@ void Game::func_target_goto(core::Player *player, core::Entity *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()); } -/* -void Game::func_target_dock(core::Player *player, core::Entity *entity) -{ - if (!player->control()) - return; - - if (player->control() == entity) - return; - - if (player->control()->zone() != entity->zone()) - return; - - if ((entity->flags() & core::Entity::Dockable) == 0) - return; - - if (player->control()->moduletype() != ship_enttype) - return; - - if (!(entity->flags() & core::Entity::Dockable)) { - return; - } - - Ship * ship = static_cast<Ship *>(player->control()); - - // check distance - float range = entity->radius() + ship->radius(); - - if (entity->moduletype() == planet_enttype) { - range += PLANET_SAFE_DISTANCE; - } - - core::Player *owner = (entity->type() == core::Entity::Controlable ? static_cast<core::EntityControlable *>(entity)->owner() : 0 ); - if (math::distance(entity->location(), ship->location()) > range) { - if (owner) { - player->send("^B" + owner->name() + "^B's " + entity->name() + " is out of range"); - } else { - player->send("^B" + entity->name() + "^B is out of range"); - } - return; - } - - if ((player->control()->state() == core::Entity::Impulse) || (player->control()->state() == core::Entity::ImpulseInitiate)) { - player->send("^BCan not dock at impulse speed"); - return; - } - - if (player->control()->state() != core::Entity::Normal) - return; - - if (entity->moduletype() == jumpgate_enttype) { - // jumpgates have their own docking function - JumpGate *jumpgate = static_cast<JumpGate *>(entity); - jumpgate->func_dock(ship); - return; - } else if (entity->moduletype() == race_enttype) { - RaceTrack *race = static_cast<RaceTrack *>(entity); - race->func_dock(ship); - } else { - ship->set_dock(entity); - - if (player->control() == ship) { - player->set_view(entity); - if (owner) { - player->send("^BDocking at " + owner->name() + "^B's " + entity->name()); - } else { - player->send("^BDocking at " + entity->name()); - } - } - - // force save - core::server()->module()->player_save(player); - } -} -*/ - // a player sends a docking request void Game::func_target_dock(core::Player *player, core::Entity *entity) { @@ -303,10 +243,8 @@ void Game::func_target_dock(core::Player *player, core::Entity *entity) 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()); - } + // 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) @@ -2677,6 +2615,10 @@ void Game::game_load(core::Player *player, filesystem::IniFile & inifile) return; } + // reset player timestamps + player->set_time_wasted(0); + player->set_time_joined(); + SaveGame::load_game(player, inifile); } @@ -2693,7 +2635,11 @@ void Game::player_load(core::Player *player) if (core::server()->mode() != core::GameServer::MultiPlayer) { return; } - + + // reset player timestamps + player->set_time_wasted(0); + player->set_time_joined(); + std::string guid(player->guid().str()); std::string directory(guid.substr(0,4)); diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc index b498717..90b7956 100644 --- a/src/game/base/savegame.cc +++ b/src/game/base/savegame.cc @@ -12,6 +12,8 @@ #include "base/ship.h" #include "base/weapon.h" +#include "core/gameserver.h" + namespace game { void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) @@ -77,7 +79,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) } else if (inifile.got_key_long("pvpkills", l)) { player->set_pvpkills(l); - } + + } else if (inifile.got_key_long("time", l)) { + player->set_time_wasted(l); } else { inifile.unknown_key(); @@ -98,6 +102,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) } else { player->reputation().set_reputation(faction, reputation); } + } else { + inifile.unknown_key(); + } } else if (inifile.in_section("ship")) { @@ -314,6 +321,7 @@ void SaveGame::player_to_stream(core::Player *player, std::ostream & os) os << "credits=" << player->credits() << std::endl; os << "npckills=" << player->npckills() << std::endl; os << "pvpkills=" << player->pvpkills() << std::endl; + os << "time=" << player->time_wasted() + core::server()->timestamp() - player->time_joined() << std::endl; os << std::endl; // player reputation |