From 2c98d3eef488233b99a76ca44d69c1c9d53404af Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 7 Dec 2014 16:12:49 +0000 Subject: Cleanup of the slots code, unified model weapon and dock tags into a single slots list, load dock tags into entity slots, represent entity slot locations in entity coordinate space, have r_slots render fixed-size slot indicators regardless of model scale. --- src/game/base/ship.cc | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'src/game/base/ship.cc') diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index b3f6fd0..9a4218f 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -96,8 +96,10 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro inventory()->set_capacity(ship_shipmodel->maxcargo()); if (model()) { + const float modelscale = radius() / model()->radius(); + add_slots(); - slots()->load(model()); + slots()->load(model(), modelscale); } // menus for docked players @@ -537,20 +539,30 @@ void Ship::launch() get_axis().assign(ship_dock->axis()); get_location().assign(ship_dock->location() + (ship_dock->axis().forward() * (PLANET_SAFE_DISTANCE + this->radius() + ship_dock->radius()))); - } else { - if (ship_dock->model() && ship_dock->model()->docks().size()) { - // choose a random dock to launch from - model::Model::Docks::iterator dit = ship_dock->model()->docks().begin(); - int launchbay_index = math::randomi(ship_dock->model()->docks().size()); - for (int i = 0; i < launchbay_index; i++) { - ++dit; + } else { + int nbdocks = 0; + + if (ship_dock->slots()) { + for (core::Slots::iterator slit = ship_dock->slots()->begin(); slit != ship_dock->slots()->end(); ++slit) { + if ((*slit)->type() == model::Slot::Dock) { + ++nbdocks; + } } - model::Dock *launchbay = (*dit); - - const float modelscale = ship_dock->radius() / ship_dock->model()->radius(); + } + + if (nbdocks) { + // choose a random dock to launch from + core::Slots::iterator slit = ship_dock->slots()->begin(); + int launchbay_index = math::randomi(nbdocks); + for (int i = 0; i < launchbay_index; ++slit) { + if ((*slit)->type() == model::Slot::Dock) { + ++i; + } + } + core::Slot *launchbay = (*slit); get_axis().assign(ship_dock->axis() * launchbay->axis()); - get_location().assign(ship_dock->location() + ship_dock->axis() * ( launchbay->location() * modelscale + launchbay->axis().forward() * radius())); + get_location().assign(ship_dock->location() + ship_dock->axis() * ( launchbay->location() + launchbay->axis().forward() * radius())); } else { const float r = radius() + ship_dock->radius(); @@ -1173,8 +1185,6 @@ void Ship::frame(const unsigned long elapsed) // fire weapons if (slots() && (state() == core::Entity::Normal) && has_target_controlflag(core::EntityControlable::ControlFlagFire)) { - const float modelscale = radius() / (model() ? model()->radius() : 1.0f); - for (core::Slots::iterator it = slots()->begin(); it != slots()->end(); it++) { core::Slot *slot = (*it); @@ -1198,7 +1208,7 @@ void Ship::frame(const unsigned long elapsed) const float projectile_radius = core::PROJECTILE_RADIUS; // 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() + 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()); -- cgit v1.2.3