From 874c85f8a009a1c16a85b439c2dccfb04e3371f9 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 28 Feb 2015 22:27:17 +0000 Subject: Added abandon engine function to drop the current character. --- src/game/base/game.cc | 128 ++++++++++++++++++++++++++++++++++++---------- src/game/base/game.h | 1 + src/game/base/savegame.cc | 14 ++++- 3 files changed, 116 insertions(+), 27 deletions(-) (limited to 'src/game/base') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 77917f6..ffd2c90 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -221,7 +221,10 @@ void Game::func_join(core::Player *player, std::string const &args) { // override default reputation with faction reputation for (core::Reputation::FactionReps::const_iterator rip = character->faction()->reputation().factionreps().begin(); rip != character->faction()->reputation().factionreps().end(); ++rip) { - player->reputation().set_reputation((*rip)->faction(), (*rip)->reputation()); + if ((*rip)->faction() != Faction::default_faction()) + { + player->reputation().set_reputation((*rip)->faction(), (*rip)->reputation()); + } } player->reputation().set_reputation(character->faction(), 100.0f); @@ -234,28 +237,86 @@ void Game::func_join(core::Player *player, std::string const &args) player->set_dirty(); } -// a player joins the spectators +// spectate void Game::func_spectate(core::Player *player, std::string const &args) { if (!player->control()) + { + return; + } + + if (core::server()->mode() != core::GameServer::MultiPlayer) + { return; + } core::server()->module()->player_save(player); + + if (player->control()) + { + player->remove_asset(player->control()); + } + if (!player->zone()) + { + player->set_zone(Default::zone); + } + player->set_view(0); + std::string message("^B"); message.append(player->name()); message.append("^B spectates."); core::server()->broadcast(message); +} - if (player->control()) { +// abandon current character +void Game::func_abandon(core::Player *player, std::string const &args) +{ + if (!player->control()) + { + return; + } + + std::istringstream is(args); + std::string strconfirm; + bool confirm = true; + if ((is >> strconfirm) && (strconfirm.compare("confirm") == 0)) { + confirm = false; + } + + if (!confirm) + { + std::ostringstream strmsg; + strmsg << "Abandon current character?"; + player->messagebox(strmsg.str().c_str(), "OK", "abandon", "Close"); + return; + } + + if (core::server()->mode() != core::GameServer::MultiPlayer) + { + core::server()->module()->player_save(player); + } + + if (player->control()) + { player->remove_asset(player->control()); } - if (!player->zone()) { + if (!player->zone()) + { player->set_zone(Default::zone); } - player->set_view(0); + + if (core::server()->mode() == core::GameServer::MultiPlayer) + { + core::server()->module()->player_save(player); + } + + std::string message("^B"); + message.append(player->name()); + message.append("^B abandons character."); + core::server()->broadcast(message); } // a player actives the hyperspace jump drive on his ship @@ -1337,8 +1398,8 @@ void Game::func_repair(core::Player *player, const std::string &args) core::Entity *dock = ship->dock(); - // can only buy at planets and stations - if ((dock->moduletype() != station_enttype) && (dock->moduletype() != planet_enttype)) { + // can only repair at planets, ships and stations + if ((dock->moduletype() != station_enttype) && (dock->moduletype() != planet_enttype) && (dock->moduletype() != ship_enttype)) { player->send("^WCan not repair here"); return; } @@ -1361,23 +1422,38 @@ void Game::func_repair(core::Player *player, const std::string &args) std::istringstream is(args); std::string strconfirm; - bool confirm = false; + bool confirm = true; if ((is >> strconfirm) && (strconfirm.compare("confirm") == 0)) { - confirm = true; + confirm = false; } if (!confirm) { std::ostringstream strmsg; strmsg << "Repair ship for " << price << " credits?"; - player->messagebox(strmsg.str().c_str(), "OK", "repair confirm", "Close"); + player->messagebox(strmsg.str().c_str(), "OK", "repair", "Close"); return; - } else { - player->set_credits(player->credits() - (long) price); - ship->set_armor(ship->armor() + amount); - - std::ostringstream strmsg; - strmsg << "Ship repaired for " << price << " credits."; - player->send(strmsg.str()); + } + player->set_credits(player->credits() - (long) price); + ship->set_armor(ship->armor() + amount); + + std::ostringstream strmsg; + strmsg << "Ship repaired for " << price << " credits."; + player->send(strmsg.str()); + + if (dock->moduletype() == ship_enttype) + { + // if the player is docked at a carrier, the carrier's owner receives the credits + Ship *carrier = static_cast(dock); + if (carrier->owner()) + { + carrier->owner()->set_credits(carrier->owner()->credits() + (long) price); + std::ostringstream strmsg2; + strmsg2 << "Received " << price << " credits from " << player->name(); + carrier->owner()->send(strmsg2.str()); + + carrier->owner()->set_dirty(); + carrier->owner()->sound("game/buy"); + } } player->set_dirty(); @@ -1956,6 +2032,9 @@ Game::Game() : core::Module("Project::OSiRiON", true) func = core::Func::add("spectate", Game::func_spectate); func->set_info("leave the game and spectate"); + + func = core::Func::add("abandon", Game::func_abandon); + func->set_info("abandon current character"); func = core::Func::add("buy", Game::func_buy); func->set_info("[string] [string] [int] buy an item: specify type, label and amount"); @@ -2972,7 +3051,7 @@ bool Game::generate_entity_menus(core::Entity *entity) // add repair button button = new ButtonDescription(); button->set_text("Repair"); - button->set_command("repair", ButtonDescription::CommandGame); + button->set_command("repair confirm", ButtonDescription::CommandGame); button->set_alignment(ButtonDescription::Center); menu_main->add_button(button); @@ -3194,10 +3273,7 @@ void Game::player_connect(core::Player *player) { std::string args; player->set_zone(Default::zone); - player->set_view(0); // not docked - - // FIXME load player - func_spectate(player, args); + player->set_view(0); } void Game::player_disconnect(core::Player *player) @@ -3279,11 +3355,11 @@ void Game::game_save(core::Player *player, std::ostream & os) void Game::player_save(core::Player *player) { - if ((!player->control()) || (player->control()->moduletype() != ship_enttype)) { - return; - } - if (core::server()->mode() == core::GameServer::SinglePlayer) { + if ((!player->control()) || (player->control()->moduletype() != ship_enttype)) { + return; + } + std::string command("savegame autosave AUTOSAVE"); core::CommandBuffer::exec(command); diff --git a/src/game/base/game.h b/src/game/base/game.h index 25d3cb1..5e49394 100644 --- a/src/game/base/game.h +++ b/src/game/base/game.h @@ -142,6 +142,7 @@ private: static void func_join(core::Player *player, std::string const &args); static void func_spectate(core::Player *player, std::string const &args); + static void func_abandon(core::Player *player, std::string const &args); static void func_jump(core::Player *player, std::string const &args); static void func_impulse(core::Player *player, std::string const &args); static void func_launch(core::Player *player, std::string const &args); diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc index ab2ecc2..8542a00 100644 --- a/src/game/base/savegame.cc +++ b/src/game/base/savegame.cc @@ -124,6 +124,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) continue; } else if (inifile.got_key_label("zone", str)) { + if (!ship) { + continue; + } zone = core::Zone::find(str); continue; @@ -143,6 +146,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) continue; } else if (inifile.got_key_string("spawn", str)) { + if (!ship) { + continue; + } if (!str.size()) { continue; } else if (str.size() < 3) { @@ -189,6 +195,11 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) } else if (inifile.in_section("item")) { + if (!ship) + { + continue; + } + if (inifile.got_key_label("type", itemtype)) { core::InfoType *item_infotype = core::InfoType::find(itemtype); if (!itemtype.size() || !item_infotype) { @@ -327,7 +338,8 @@ void SaveGame::player_to_stream(core::Player *player, std::ostream & os) os << std::endl; // player reputation - for (core::Reputation::FactionReps::const_iterator it = player->reputation().factionreps().begin(); it != player->reputation().factionreps().end(); ++it) { + for (core::Reputation::FactionReps::const_iterator it = player->reputation().factionreps().begin(); it != player->reputation().factionreps().end(); ++it) + { os << "[reputation]" << std::endl; os << "faction=" << (*it)->faction()->label() << std::endl; os << "reputation=" << (*it)->reputation() << std::endl; -- cgit v1.2.3