From 0840438435f3d229b1164e6f5677c3b15a0c5167 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 29 Jul 2016 23:54:29 +0200 Subject: Moved 'wingman add' functionality to 'give wingmen', minor code cleanups. --- src/game/base/game.cc | 119 ++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 51 deletions(-) (limited to 'src/game') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 59c1195..0b7e18d 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -550,7 +550,7 @@ void Game::func_give(core::Player *player, const std::string &args) ShipModel *shipmodel = 0; if (!(is >> labelstr)) { - player->send("Usage: give ship [string]"); + player->send("Usage: give ship [ship]"); } else { aux::to_label(labelstr); shipmodel = ShipModel::find(labelstr); @@ -624,7 +624,7 @@ void Game::func_give(core::Player *player, const std::string &args) long credits; if (!(is >> credits)) { - player->send("Usage: give credits [int]"); + player->send("Usage: give credits [amount]"); return; } @@ -641,7 +641,7 @@ void Game::func_give(core::Player *player, const std::string &args) Cargo *cargo = 0; if (!(is >> labelstr)) { - player->send("Usage: give cargo [string] [int]"); + player->send("Usage: give cargo [cargo] [amount]"); } else { aux::to_label(labelstr); cargo = Cargo::find(labelstr); @@ -707,7 +707,7 @@ void Game::func_give(core::Player *player, const std::string &args) Weapon *weapon = 0; if (!(is >> labelstr)) { - player->send("Usage: give weapon [string] [int]"); + player->send("Usage: give weapon [weapon] [amount]"); } else { aux::to_label(labelstr); weapon = Weapon::find(labelstr); @@ -801,7 +801,7 @@ void Game::func_give(core::Player *player, const std::string &args) Faction *faction = 0; if (!(is >> labelstr)) { - player->send("Usage: give reputation [faction label] [value]"); + player->send("Usage: give reputation [faction] [value]"); return; } else { aux::to_label(labelstr); @@ -847,23 +847,67 @@ void Game::func_give(core::Player *player, const std::string &args) msgstr << "Reputation for faction '" << faction->label() << "' set to " << reputation; player->send(msgstr.str().c_str()); - } else { - player->send("Usage: give cargo [cargo label] [amount]"); + } + else if (str.compare("wingmen") == 0) + { + std::string labelstr; + Faction *faction = 0; + int amount = 1; + + if (is >> labelstr) + { + std::stringstream amountstr(labelstr); + if ( !(amountstr >> amount)) { + aux::to_label(labelstr); + faction = Faction::find(labelstr); + if (!faction) + { + player->send("^WUnknown faction '" + labelstr + "'"); + return; + } + if ( !(is >> amount)) + { + amount = 1; + } + } + } + + if (amount <= 0) + { + return; + } + + Ship * ship = static_cast(player->control()); + for (int count = 0; count < amount; ++count) + { + NPC *npc = NPC::add_wingman(ship); + if (npc) { + npc->set_commander(player); + if (faction) { + faction->apply(npc); + player->send(faction->name() + " wingman standing by!"); + } else { + player->send("Wingman standing by!"); + } + } + } + player->sound("game/buy-ship"); + + } + else + { + player->send("Usage: give cargo [cargo] [amount]"); player->send(" give credits [amount]"); - player->send(" give reputation [faction label] [value]"); - player->send(" give ship [ship label]"); - player->send(" give weapon [weapon label] [amount]"); + player->send(" give reputation [faction] [value]"); + player->send(" give ship [ship]"); + player->send(" give weapon [weapon] [amount]"); + player->send(" give wingmen [faction] [amount]"); return; } } void Game::func_wingmen(core::Player *player, const std::string &args) { - if (!Game::g_devel->value()) { - player->send("Cheats disabled"); - return; - } - if (!player->control()) { player->send("^WYou need to join the game first!"); return; @@ -878,36 +922,7 @@ void Game::func_wingmen(core::Player *player, const std::string &args) is >> str; aux::to_label(str); - if (str.compare("add") == 0) { - Faction *faction = 0; - int amount = 1; - - if (is >> str) { - aux::to_label(str); - faction = Faction::find(str); - if (!faction) { - player->send("^WUnknown faction '" + str + "'"); - return; - } - if ( !(is >> amount)) { - amount = 1; - } - } - - for (int count = 0; count < amount; ++count) { - NPC *npc = NPC::add_wingman(ship); - if (npc) { - npc->set_commander(player); - - if (faction) { - faction->apply(npc); - player->send(faction->name() + " wingman standing by!"); - } else { - player->send("Wingman standing by!"); - } - } - } - } else if (str.compare("combat") == 0) + if (str.compare("combat") == 0) { if (ship->has_autopilot_flag(Ship::AutoPilotCombat)) { @@ -919,9 +934,11 @@ void Game::func_wingmen(core::Player *player, const std::string &args) player->send("^BWingmen entering combat!"); } - } else if ((str.compare("recall") == 0) || (str.compare("launch") == 0)) + } + else if ((str.compare("recall") == 0) || (str.compare("launch") == 0)) { - if (ship->has_flag(core::Entity::Dockable)) { + if (ship->has_flag(core::Entity::Dockable)) + { if (ship->has_autopilot_flag(Ship::AutoPilotRecall)) { ship->unset_autopilot_flag(Ship::AutoPilotRecall); @@ -936,11 +953,11 @@ void Game::func_wingmen(core::Player *player, const std::string &args) { player->send("^WWingmen can't dock at your ship!"); } - } else + } + else { - player->send("Usage: wingmen add [faction label] [amount]"); - player->send(" wingmen combat switch wingmen between formation flying and combat mode"); - player->send(" wingmen recall switched wingmend between docked and laucnhed"); + player->send("Usage: wingmen combat switch wingmen between formation flying and combat mode"); + player->send(" wingmen recall switch wingmen between docked and launched mode"); player->send(" wingmen launch alias for recall"); } } -- cgit v1.2.3