Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base/ship.cc')
-rw-r--r--src/game/base/ship.cc40
1 files changed, 25 insertions, 15 deletions
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());