From d3ed23de89a7c1ddbb92990eee966966ee8fbeee Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 1 Jan 2013 16:16:59 +0000 Subject: Turrets and cannons can only be mounted in an approriate slot. --- src/game/base/game.cc | 6 +++--- src/game/base/savegame.cc | 7 +++++-- src/game/base/ship.cc | 16 +++++++++++++--- src/game/base/weapon.h | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index a44650b..efb89fe 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -1213,7 +1213,7 @@ void Game::func_mount(core::Player *player, const std::string &args) } const Weapon *weapon = static_cast(item->info()); - if (!item->unique() || (weapon->subtype() != Weapon::Cannon)) { + if (!item->unique() || ((weapon->subtype() != Weapon::Cannon) && (weapon->subtype() != Weapon::Turret)) ) { if (ship->owner()) { std::stringstream msgstr; msgstr << "^W" << weapon->name() << " can not be mounted"; @@ -1244,8 +1244,8 @@ void Game::func_mount(core::Player *player, const std::string &args) // 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)) { + for(core::Slots::iterator it = ship->slots()->begin(); (!slot) && (it != ship->slots()->end()); ++it) { + if (((*it)->type() == weapon->slot_type()) && !(*it)->has_flag(core::Slot::Mounted)) { slot = (*it); } } diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc index ce08659..6d492d0 100644 --- a/src/game/base/savegame.cc +++ b/src/game/base/savegame.cc @@ -185,10 +185,13 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) } } } else if (inifile.got_key_long("slot", l)) { + // verify item type + const Weapon *weapon = ( item->info()->type() == Weapon::infotype() ? static_cast(item->info()) : 0); + if ((l > 0) && ((size_t) l <= ship->slots()->size())) { + // verify slot type core::Slot *slot = ship->slots()->operator[]((size_t) (l - 1)); - - if (slot) { + if (slot && (slot->type() == weapon->slot_type())) { slot->set_item(item); slot->set_flag(core::Slot::Active); slot->set_flag(core::Slot::Mounted); diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 4c3885a..7ce6d36 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -912,16 +912,26 @@ void Ship::frame(const unsigned long elapsed) core::Slot *slot = (*it); // create projectiles - if (slot->has_flag(core::Slot::Mounted) && slot->item() && (slot->item()->info()->type() == Weapon::infotype())) { + if (!slot->has_flag(core::Slot::Mounted)) { + continue; + + } else if ( !(slot->item() && (slot->item()->info()->type() == Weapon::infotype()))) { + continue; + + } else { const Weapon *weapon = static_cast(slot->item()->info()); - if ((weapon->subtype() == Weapon::Cannon) && (weapon->projectile_interval() > 0) && (slot->last_fired() + weapon->projectile_interval() <= core::server()->timestamp())) { + + if ((weapon->subtype() != Weapon::Cannon) && (weapon->subtype() != Weapon::Turret) ) { + continue; + + } else if ((weapon->projectile_interval() > 0) && (slot->last_fired() + weapon->projectile_interval() <= core::server()->timestamp())) { // aim const float projectile_radius = 0.01f; // FIXME this should be defined somewhere math::Axis projectile_axis(axis() * slot->axis()); - math::Vector3f projectile_location(location() + (axis() * slot->location() * modelscale) + projectile_axis.forward() * projectile_radius); + math::Vector3f projectile_location(location() + (axis() * slot->location() * modelscale) + projectile_axis.forward() * projectile_radius); math::Vector3f projectile_direction(target_aim - projectile_location); projectile_direction.normalize(); float cosa = math::dotproduct(projectile_direction, projectile_axis.forward()); diff --git a/src/game/base/weapon.h b/src/game/base/weapon.h index 31ce5de..ec071ad 100644 --- a/src/game/base/weapon.h +++ b/src/game/base/weapon.h @@ -83,6 +83,21 @@ public: { return weapon_projectile_soundname; } + + inline const model::Weapon::Type slot_type() const + { + switch (weapon_subtype) { + case Cannon: + return model::Weapon::Cannon; + break; + case Turret: + return model::Weapon::Turret; + break; + default: + return model::Weapon::Unmountable; + } + } + /* --- mutators -------------------------------------------- */ -- cgit v1.2.3