From d8be908233fd7b85492d7a9e87f07bb207173990 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 25 Nov 2012 12:06:13 +0000 Subject: Moved core::EntityGlobe into a separate file, added various methods to core::Item and core::Slot, added r_slots cvar to draw entity slots and docks, added game methods for mounting and umounting of weapons, added playerlist to chat window. --- src/game/base/game.cc | 155 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 149 insertions(+), 6 deletions(-) (limited to 'src/game/base/game.cc') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 2355a9e..1020fa8 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -340,9 +340,10 @@ void Game::func_give(core::Player *player, const std::string &args) } // transfer inventory - for (core::Inventory::Items::iterator it = player->control()->inventory()->items().begin(); - it != player->control()->inventory()->items().end(); it++) { - ship->inventory()->add(new core::Item(*(*it))); + for (core::Inventory::Items::iterator it = player->control()->inventory()->items().begin(); it != player->control()->inventory()->items().end(); it++) { + core::Item *item = new core::Item(*(*it)); + item->unset_flag(core::Item::Mounted); + ship->inventory()->add(item); } ship->inventory()->set_dirty(); @@ -973,7 +974,7 @@ void Game::func_drop(core::Player *player, const std::string &args) // cannot drop items while jumping if ((ship->state() == core::Entity::Jump) || (ship->state() == core::Entity::JumpInitiate)) { - player->send("^WCan not eject while hyperspace jump drive is active"); + player->send("^WCan not drop items while hyperspace jump drive is active"); return; } @@ -1112,9 +1113,10 @@ void Game::func_eject(core::Player *player, const std::string &args) pod->add_inventory(); pod->inventory()->set_capacity(item->info()->volume() * amount); - core::Item *loot = new core::Item(item->info()); + core::Item *loot = new core::Item(item->info()); loot->set_amount(amount); loot->set_flags(item->flags()); + loot->unset_flag(core::Item::Mounted); pod->inventory()->add(loot); pod->inventory()->set_dirty(); @@ -1134,11 +1136,147 @@ void Game::func_eject(core::Player *player, const std::string &args) } if (item->amount() == 0) { + if (item->has_flag(core::Item::Mounted)) { + // unmount + core::Slot *slot = 0; + + for(core::Slots::iterator it = ejector->slots()->begin(); (!slot) && (it != ejector->slots()->end()); ++it) { + if ((*it)->item() == item) { + slot = (*it); + } + } + + if (slot) { + slot->set_item(0); + slot->unset_flag(core::Slot::Active); + slot->unset_flag(core::Slot::Mounted); + item->unset_flag(core::Item::Mounted); + } + + } ejector->inventory()->erase(item->id()); } ejector->inventory()->set_dirty(); } +// mount weapons into slots +void Game::func_mount(core::Player *player, const std::string &args) +{ + if (!player->control()) { + return; + } + + Ship *ship = static_cast(player->control()); + + if (!ship->slots()) { + return; + } + + std::istringstream is(args); + unsigned int id = 0; + + if (!(is >> id)) { + ship->owner()->send("Usage: mount [id] mount weapon with id into the first available slot"); + return; + } + + // find item to be mounted + core::Item *item = ship->inventory()->find(id); + if (!item) { + if (ship->owner()) { + std::stringstream msgstr; + msgstr << "^WItem " << id << " not in inventory"; + ship->owner()->send(msgstr.str()); + } + return; + } + + // verify item is mountable + if (item->info()->type() != Weapon::infotype()) { + if (ship->owner()) { + std::stringstream msgstr; + msgstr << "^WItem " << id << " can not be mounted"; + ship->owner()->send(msgstr.str()); + } + return; + } + const Weapon *weapon = static_cast(item->info()); + + if (!item->unique() || (weapon->subtype() != Weapon::Cannon)) { + if (ship->owner()) { + std::stringstream msgstr; + msgstr << "^WItem " << id << " can not be mounted"; + ship->owner()->send(msgstr.str()); + } + return; + } + + if (item->has_flag(core::Item::Mounted)) { + // unmount + core::Slot *slot = 0; + + for(core::Slots::iterator it = ship->slots()->begin(); (!slot) && (it != ship->slots()->end()); ++it) { + if ((*it)->item() == item) { + slot = (*it); + } + } + + if (slot) { + slot->set_item(0); + slot->unset_flag(core::Slot::Active); + slot->unset_flag(core::Slot::Mounted); + item->unset_flag(core::Item::Mounted); + + if (ship->owner()) { + std::stringstream msgstr; + msgstr << "^BUnmounted " << weapon->name(); + ship->owner()->send(msgstr.str()); + } + } + + } else { + // mount + core::Slot *slot = 0; + + for(core::Slots::iterator it = ship->slots()->begin(); (!slot) && (it != ship->slots()->end()); ++it) { + if (!(*it)->has_flag(core::Slot::Mounted)) { + slot = (*it); + } + } + + if (!slot) { + if (ship->owner()) { + std::stringstream msgstr; + msgstr << "^WNo slot available to mount item " << id; + ship->owner()->send(msgstr.str()); + } + return; + } else { + slot->set_item(item); + slot->set_flag(core::Slot::Active); + slot->set_flag(core::Slot::Mounted); + item->set_flag(core::Item::Mounted); + + slot->set_projectile_damage(weapon->damage()); + slot->set_projectile_speed(weapon->projectile_speed()); + slot->set_projectile_lifespan(weapon->projectile_lifespan()); + slot->set_projectile_interval(weapon->projectile_interval()); + slot->set_projectile_modelname(weapon->projectile_modelname()); + + if (ship->owner()) { + std::stringstream msgstr; + msgstr << "^BMounted " << weapon->name(); + ship->owner()->send(msgstr.str()); + } + } + } +} + +// unmount weapons from slots +void Game::func_unmount(core::Player *player, const std::string &args) +{ +} + // beam in nearby cargo pods void Game::func_beam(core::Player *player, const std::string &args) { @@ -1180,6 +1318,8 @@ void Game::func_beam(core::Player *player, const std::string &args) } if (!iteminv) { iteminv = new core::Item(item->info()); + iteminv->set_flags(item->flags()); + iteminv->unset_flag(core::Item::Mounted); inventory->add(iteminv); } item->dec_amount(negotiated_amount); @@ -1424,7 +1564,10 @@ Game::Game() : core::Module("Project::OSiRiON", true) func->set_info("[label] drop an item and activate it"); func = core::Func::add("eject", Game::func_eject); - func->set_info("[string] [string] [int] eject an item from inventory: specify type, label and amount"); + func->set_info("[int] eject item with id from inventory"); + + func = core::Func::add("mount", Game::func_mount); + func->set_info("[int] mount a weapon into the first available slot"); func = core::Func::add("beam", Game::func_beam); func->set_info("beam nearby cargo pods in"); -- cgit v1.2.3