diff options
author | Stijn Buys <ingar@osirion.org> | 2010-10-09 20:23:01 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-10-09 20:23:01 +0000 |
commit | 0ecdd8bc98ba583bbee801b838d785c6f881d7df (patch) | |
tree | 0ae456cb1254544e43de8abf8fa4dbb6afc91e79 | |
parent | e5be0871b6fed09eed40ff17201d1c7a4a990744 (diff) |
removed physics references, transfer inventory on ship aquisition
-rw-r--r-- | doc/ROADMAP | 2 | ||||
-rw-r--r-- | doc/TODO | 13 | ||||
-rw-r--r-- | doc/installation.html | 6 | ||||
-rw-r--r-- | src/core/item.cc | 9 | ||||
-rw-r--r-- | src/core/item.h | 3 | ||||
-rw-r--r-- | src/game/base/Makefile.am | 7 | ||||
-rw-r--r-- | src/game/base/collision.cc | 75 | ||||
-rw-r--r-- | src/game/base/collision.h | 33 | ||||
-rw-r--r-- | src/game/base/game.cc | 40 | ||||
-rw-r--r-- | src/game/base/physics.cc | 307 | ||||
-rw-r--r-- | src/game/base/physics.h | 185 | ||||
-rw-r--r-- | src/game/base/ship.cc | 50 | ||||
-rw-r--r-- | src/game/base/ship.h | 3 | ||||
-rw-r--r-- | src/game/base/shipmodel.cc | 14 | ||||
-rw-r--r-- | src/game/base/station.cc | 3 | ||||
-rw-r--r-- | src/game/base/station.h | 4 |
16 files changed, 68 insertions, 686 deletions
diff --git a/doc/ROADMAP b/doc/ROADMAP index 9afaab8..bad4cf4 100644 --- a/doc/ROADMAP +++ b/doc/ROADMAP @@ -97,7 +97,7 @@ player-to-player trading player shops player must be capable of setting the kind and price of items to sell - item 'tradeable' flag + item 'tradeable' flag shop allows multiple buyers, p2p trading just one player factory ships + base factories, per-item adjustabe conversion rate and ratio e.g. 2 units of niobum to 1 superconductor per 30 seconds @@ -51,6 +51,7 @@ network: fix lag/client interpolation cl_prediction or cl_interpolation detect and disconnect clients behaving badly + let server track Entity::State changes EXT messages, update extended property "ext id prop value prop value etc", type checking/seperator etc.. EXT zone/color/shield/armor/health @@ -62,16 +63,20 @@ client: fix camera frustum clip (size issue, postponed) tracking camera absolute speed/position gui concept artwork + hud target/target hoover inconsistency render: - star light strenght + fix skybox envmapping + star light strenght sphere texture distortion at the poles - skybox + skybox (ok) + ui: modelview lighting (-> it uses current zone lighting) - unify evennt handlers, expand Event class ad make derived event classes - + unify event handlers, expand Event class ad make derived event classes + fix slider mouse dragging + sound: entity/event positional sounds jump drive sound events diff --git a/doc/installation.html b/doc/installation.html index c10011c..838c754 100644 --- a/doc/installation.html +++ b/doc/installation.html @@ -186,9 +186,9 @@ svn co svn://intranifty.no-ip.org/osirion osirion <p> To download and install the library: <div class="code"> -wget http://bullet.googlecode.com/files/bullet-2.75-rc3.tgz<br> -tar zxvf bullet-2.75-rc3.tgz<br> -cd bullet-2.75-rc3<br> +wget http://bullet.googlecode.com/files/bullet-2.77.tgz<br> +tar zxvf bullet-2.77.tgz<br> +cd bullet-2.77<br> ./autogen.sh<br> ./configure --prefix=/usr/local<br> make<br> diff --git a/src/core/item.cc b/src/core/item.cc index 8ab4784..df12885 100644 --- a/src/core/item.cc +++ b/src/core/item.cc @@ -27,10 +27,19 @@ Item::Item(const Info *info) set_timestamp(game() ? game()->timestamp() : 1); } +Item::Item(const Item &other) +{ + item_info = other.info(); + item_amount = other.amount(); + item_price = other.price(); + set_timestamp(game() ? game()->timestamp() : 1); +} + Item::~Item() { item_info = 0; item_amount = 0; + item_amount = 0; } void Item::set_amount(const long amount) diff --git a/src/core/item.h b/src/core/item.h index e4e8507..0e9e167 100644 --- a/src/core/item.h +++ b/src/core/item.h @@ -21,6 +21,9 @@ class Item public: Item(const Info *info); + /// copy constructor + Item(const Item &other); + ~Item(); /* ---- inspectors --------------------------------------------- */ diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am index b86d14a..8e58bd8 100644 --- a/src/game/base/Makefile.am +++ b/src/game/base/Makefile.am @@ -2,8 +2,7 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game METASOURCES = AUTO libbase_la_LDFLAGS = -avoid-version noinst_LTLIBRARIES = libbase.la -libbase_la_SOURCES = collision.cc cargo.cc game.cc jumppoint.cc navpoint.cc physics.cc \ - planet.cc racetrack.cc ship.cc shipmodel.cc star.cc station.cc -noinst_HEADERS = game.h collision.h cargo.h jumppoint.h navpoint.h physics.h planet.h \ +libbase_la_SOURCES = cargo.cc game.cc jumppoint.cc navpoint.cc planet.cc \ + racetrack.cc ship.cc shipmodel.cc star.cc station.cc +noinst_HEADERS = cargo.h game.h jumppoint.h navpoint.h planet.h \ racetrack.h ship.h shipmodel.h star.h station.h - diff --git a/src/game/base/collision.cc b/src/game/base/collision.cc deleted file mode 100644 index e009b7a..0000000 --- a/src/game/base/collision.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* - base/collision.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2. -*/ - -#include "base/collision.h" -#include "base/game.h" -#include "base/planet.h" -#include "core/zone.h" -#include "math/functions.h" -#include "math/vector3f.h" - -namespace game -{ - -void Collision::distance_test(core::EntityControlable *first, core::Entity *second) -{ - if (!first->owner()) - return; - - if (first->state() == core::Entity::Docked) - return; - - // FIXME - use distancesquared - const float d = math::distance(first->location(), second->location()); - const float r = first->radius() + second->radius(); - - if (second->type() == core::Entity::Globe) { - // collision with a star or a planet - - if ((d - r) < 0.0f) { - // crash zone - if ((first->moduletype() == ship_enttype) && (first->state() != core::Entity::Destroyed)) { - first->owner()->send_warning("^RBOOM!^N"); - static_cast<Ship *>(first)->explode(); - first->entity_speed = 0; - } - } else if (first->owner()->last_warning() + 5.0f < core::application()->time()) { - // warning zone: star corona or planet atmosphere - if ((second->moduletype() == star_enttype) && (d - r < 50.0f)) { - first->owner()->send_warning("^3Warning: entering star corona!^N"); - } else if ((second->moduletype() == planet_enttype) && (d - r < planet_safe_distance)) { - first->owner()->send_warning("^3Warning: entering planet gravity well!^N"); - } - } - } -} - -void Collision::frame_zone(core::Zone *zone) -{ - core::Zone::Content::iterator first; - core::Zone::Content::iterator second; - - for (first = zone->content().begin(); first != zone->content().end(); first ++) { - second = first; - for (second++; second != zone->content().end(); second++) { - if ((*first)->type() == core::Entity::Controlable) { - distance_test(static_cast<core::EntityControlable *>((*first)), (*second)); - } else if ((*second)->type() == core::Entity::Controlable) { - distance_test(static_cast<core::EntityControlable *>((*second)), (*first)); - } - } - } -} - -void Collision::frame(const float elapsed) -{ - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - frame_zone((*it).second); - } -} - -} // namespace game - diff --git a/src/game/base/collision.h b/src/game/base/collision.h deleted file mode 100644 index d74e6d6..0000000 --- a/src/game/base/collision.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - base/collision.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_BASE_COLLISION_H__ -#define __INCLUDED_BASE_COLLISION_H__ - -#include "core/zone.h" - -namespace game -{ - -/// collision detection functions -class Collision -{ -public: - /// do collision detection - static void frame(const float elapsed); - -private: - /// do collision detection for a single zone - static void frame_zone(core::Zone *zone); - - /// do a distance test between two entities - static void distance_test(core::EntityControlable *first, core::Entity *second); -}; - -} - -#endif // __INCLUDED_BASE_COLLISION_H__ - diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 7fc3eb5..19b3968 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -16,7 +16,6 @@ #include "filesystem/inifile.h" #include "base/game.h" #include "base/cargo.h" -#include "base/collision.h" #include "base/navpoint.h" #include "base/jumppoint.h" #include "base/planet.h" @@ -227,12 +226,25 @@ void Game::func_give(core::Player *player, const std::string &args) return; } + // check if there's enough space available to transfer inventory + if (shipmodel->maxcargo() < player->control()->inventory()->capacity_used()) { + player->send("^WNot enough cargo space to transfer inventory!"); + return; + } + Ship * ship = new Ship(player, shipmodel); core::Entity *view = player->view(); if (view && (view == player->control())) { view = ship; } + // 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))); + } + ship->inventory()->set_dirty(); + // FIME move this into a method in the Ship class ship->set_zone(player->control()->zone()); ship->get_location().assign(player->control()->location()); @@ -465,7 +477,6 @@ void Game::func_launch(core::Player *player, std::string const &args) assert(player->control()->moduletype() == ship_enttype); Ship *ship = static_cast<Ship *>(player->control()); - ship->shutdown_physics(); if (dock->type() == core::Entity::Globe) ship->get_location().assign(dock->location() + (dock->axis().forward() *(planet_safe_distance + ship->radius() + dock->radius()))); @@ -474,7 +485,6 @@ void Game::func_launch(core::Player *player, std::string const &args) ship->get_axis().assign(dock->axis()); ship->set_state(core::Entity::Normal); - ship->init_physics(ship->radius()); ship->set_state(core::Entity::Jump); player->set_view(0); @@ -496,8 +506,6 @@ void Game::func_respawn(core::Player *player, std::string const &args) Ship *ship = static_cast<Ship *>(player->control()); core::Entity *dock = player->control()->zone()->default_view(); - ship->shutdown_physics(); - if (dock) { ship->get_location().assign(dock->location()); ship->get_axis().assign(dock->axis()); @@ -513,7 +521,6 @@ void Game::func_respawn(core::Player *player, std::string const &args) } ship->set_zone(Default::zone); - ship->init_physics(ship->radius()); } @@ -535,8 +542,6 @@ void Game::func_goto(core::Player *player, const std::string &args) Ship *ship = static_cast<Ship *>(player->control()); if (dock) { - ship->shutdown_physics(); - if (dock->type() == core::Entity::Globe) ship->get_location().assign(dock->location() + (dock->axis().forward() *(planet_safe_distance + ship->radius() + dock->radius()))); else @@ -546,7 +551,6 @@ void Game::func_goto(core::Player *player, const std::string &args) ship->get_axis().change_direction(180.0f); ship->set_state(core::Entity::Normal); - ship->init_physics(ship->radius()); ship->set_state(core::Entity::Jump); player->set_view(0); @@ -563,8 +567,6 @@ Game::Game() : core::Module("Project::OSiRiON", true) // reset default player values Default::clear(); - Physics::init(); - // read cargo.ini if (!Cargo::init()) { abort(); @@ -647,8 +649,6 @@ Game::~Game() // we explicity clear game data to prevent bullet from beeing confused core::game()->clear(); - - Physics::shutdown(); } bool Game::load_world() @@ -665,7 +665,7 @@ bool Game::load_world() con_print << "^BLoading world..." << std::endl; - PhysicsZone *zone = 0; + core::Zone *zone = 0; std::string label; while (worldini.getline()) { @@ -684,7 +684,7 @@ bool Game::load_world() if (worldini.got_key_string("zone", label)) { aux::to_label(label); - zone = new PhysicsZone(label); + zone = new core::Zone(label); core::Zone::add(zone); } else { worldini.unkown_key(); @@ -1040,11 +1040,6 @@ bool Game::validate_zone(core::Zone *zone) jumpgate->validate(); } else { - if (entity->entity_moduletypeid == station_enttype) { - Station *station = static_cast<Station *>(entity); - station->init_physics(0.0f); - } - if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) { generate_entity_menus(entity); } @@ -1211,13 +1206,8 @@ bool Game::load_player() void Game::frame(float seconds) { -#ifdef HAVE_BULLET if (!running()) return; - - Physics::frame(seconds); -#endif - } void Game::player_connect(core::Player *player) diff --git a/src/game/base/physics.cc b/src/game/base/physics.cc deleted file mode 100644 index 3cc7427..0000000 --- a/src/game/base/physics.cc +++ /dev/null @@ -1,307 +0,0 @@ -/* - base/physics.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2. -*/ - -#include "base/physics.h" -#include "base/collision.h" -#include "base/game.h" -#include "core/zone.h" -#include "math/functions.h" -#include "math/vector3f.h" -#include "model/vertexarray.h" -#include "sys/sys.h" - -#ifdef HAVE_BULLET -#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" -#include "BulletCollision/Gimpact/btGImpactShape.h" -#endif - -namespace game -{ - -/* ---- class ColliderShape ---------------------------------------- */ - -CollisionShape::Registry CollisionShape::shape_registry; - -CollisionShape::CollisionShape(model::Model *model, const bool moving) -{ - shape_label.assign(model->name()); - shape_moving = moving; - -#ifdef HAVE_BULLET - btGImpactMeshShape *moving_shape = 0; - btBvhTriangleMeshShape *static_shape = 0; - - shape_mesh = new btTriangleMesh(); - - size_t count = 0; - - model::VertexArray *vertexarray = model::VertexArray::instance(); - - // iterate model FragmentGroups - for (model::Model::Groups::iterator git = model->groups().begin(); git != model->groups().end(); git++) { - - model::FragmentGroup *group = (*git); - - // FIXME ignore moving parts - if (group->type() == model::FragmentGroup::None) { - - // for each fragment - for (model::FragmentGroup::iterator fit = group->begin(); fit != group->end(); fit++) { - model::Fragment *fragment = (*fit); - - const size_t index = fragment->index(); - const size_t triangle_count = (fragment->structural_size() + fragment->detail_size()) / 3; - - // load vertices from the global VertexArray into the bullet shape - for (size_t i = 0; i < triangle_count; i++) { - float *f = vertexarray->vertex() + index + (i * 9); - - btVector3 v0(f[0], f[1], f[2]); - btVector3 v1(f[3], f[4], f[5]); - btVector3 v2(f[6], f[7], f[8]); - - shape_mesh->addTriangle(v0, v1, v2); - } - - count += triangle_count; - } - } - } - - if (moving) { - moving_shape = new btGImpactMeshShape(shape_mesh); - moving_shape->updateBound(); - moving_shape->postUpdate(); - shape_bulletshape = moving_shape; - - } else { - static_shape = new btBvhTriangleMeshShape(shape_mesh, true, false); - shape_bulletshape = static_shape; - } - - - con_debug << " collision data for " << model->name() << ": " << count << " tris " << std::endl; -#endif -} - -CollisionShape::~CollisionShape() -{ - shape_label.clear(); -#ifdef HAVE_BULLET - delete shape_bulletshape; -#endif -} - -void CollisionShape::clear() -{ - for (Registry::iterator it = shape_registry.begin(); it != shape_registry.end(); it++) { - CollisionShape *shape = (*it); - delete shape; - } - shape_registry.clear(); -} - -CollisionShape *CollisionShape::add(model::Model *model, const bool moving) -{ - CollisionShape *shape = new CollisionShape(model, moving); - - shape_registry.push_back(shape); - return shape; -} - -CollisionShape *CollisionShape::find(model::Model *model, const bool moving) -{ - for (Registry::iterator it = shape_registry.begin(); it != shape_registry.end(); it++) { - CollisionShape *shape = (*it); - - if ((shape->moving() == moving) && (shape->label().compare(model->name()) == 0)) { - return shape; - } - } - return 0; -} - -/* ---- class Physics ---------------------------------------------- */ - -#ifdef HAVE_BULLET - -btDefaultCollisionConfiguration *Physics::configuration; -btCollisionDispatcher *Physics::dispatcher; -btSequentialImpulseConstraintSolver *Physics::solver; - -void Physics::init() -{ - con_print << "^BInitializing bullet physics..." << std::endl; - - configuration = new btDefaultCollisionConfiguration(); - dispatcher = new btCollisionDispatcher(configuration); - solver = new btSequentialImpulseConstraintSolver; - -} - -void Physics::frame(const float seconds) -{ - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - PhysicsZone *bz = static_cast<PhysicsZone *>((*it).second); - bz->dynamics_world()->stepSimulation(seconds); - } -} - -void Physics::shutdown() -{ - con_print << "^BShutting down bullet physics..." << std::endl; - - CollisionShape::clear(); - - delete solver; - delete dispatcher; - delete configuration; -} - -#else - -void Physics::init() -{ -} - -void Physics::frame(const float seconds) -{ - Collision::frame(seconds); -} - -void Physics::shutdown() -{ -} - -#endif - -/* ---- class PhysicsZone ------------------------------------------ */ - -PhysicsZone::PhysicsZone(const std::string &label) : core::Zone(label) -{ -#ifdef HAVE_BULLET - btVector3 worldAabbMin(-10000, -10000, -10000); - btVector3 worldAabbMax(10000, 10000, 10000); - const int maxProxies = 1024; - - zone_cache = new btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies); - zone_dynamics_world = new btDiscreteDynamicsWorld(Physics::dispatcher, zone_cache, Physics::solver, Physics::configuration); - - // disable gravity - zone_dynamics_world->setGravity(btVector3(0.0f, 0.0f, 0.0f)); -#endif -} - -PhysicsZone::~PhysicsZone() -{ -#ifdef HAVE_BULLET - if (zone_cache) { - delete zone_cache; - zone_cache = 0; - } - - if (zone_dynamics_world) { - delete zone_dynamics_world; - zone_dynamics_world = 0; - } -#endif -} - -/* ---- class PhysicsBody ------------------------------------------ */ - -PhysicsBody::PhysicsBody(core::Entity *entity) -{ - collider_entity = entity; - collider_shape = 0; - collider_mass = 0; -#ifdef HAVE_BULLET - collider_body = 0; -#endif -} - -PhysicsBody::~PhysicsBody() -{ -#ifdef HAVE_BULLET - if (collider_body) { - delete collider_body; - collider_body = 0; - } -#endif -} - -void PhysicsBody::init_physics(const float mass) -{ - collider_mass = mass; - -#ifdef HAVE_BULLET - bool moving = (mass > 0.0f); - - if (!entity()->model()) - return; - - if (!collider_shape) { - collider_shape = CollisionShape::find(entity()->model(), moving); - if (!collider_shape) { - collider_shape = CollisionShape::add(entity()->model(), moving); - - } - } - - if (!collider_body) { - btVector3 inertia(0, 0, 0); - - btTransform t; - t.setIdentity(); - t.setOrigin(to_btVector3(entity()->location())); - t.setBasis(to_btMatrix3x3(entity()->axis())); - - - if (moving) { - collider_shape->bullet_shape()->calculateLocalInertia(mass, inertia); - - btMotionState *motionstate = new btDefaultMotionState(t); - btRigidBody::btRigidBodyConstructionInfo body_info(mass, motionstate, collider_shape->bullet_shape(), inertia); - collider_body = new btRigidBody(body_info); - collider_body->setUserPointer((void *)entity()); - collider_body->setLinearFactor(btVector3(1, 1, 1)); - collider_body->setCcdMotionThreshold(0.0001f); - } else { - collider_body = new btRigidBody(mass, 0, collider_shape->bullet_shape(), inertia); - collider_body->setWorldTransform(t); - } - } - - if (entity()->zone()) { - PhysicsZone *zone = static_cast<PhysicsZone *>(entity()->zone()); - zone->dynamics_world()->addRigidBody(collider_body); - if (moving) { - //collider_body->setActivationState(ISLAND_SLEEPING); - //collider_body->setActivationState(ACTIVE_TAG); - //collider_body->activate(true); - } - } -#endif -} - -void PhysicsBody::shutdown_physics() -{ -#ifdef HAVE_BULLET - if (collider_body && entity()->zone()) { - PhysicsZone *zone = static_cast<PhysicsZone *>(entity()->zone()); - - if (collider_body->getMotionState()) { - delete collider_body->getMotionState(); - } - zone->dynamics_world()->removeCollisionObject(collider_body); - - delete collider_body; - collider_body = 0; - } -#endif - collider_mass = 0; -} - -} diff --git a/src/game/base/physics.h b/src/game/base/physics.h deleted file mode 100644 index 3bbd749..0000000 --- a/src/game/base/physics.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - base/physics.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_BASE_PHYSICS_H__ -#define __INCLUDED_BASE_PHYSICS_H__ - -#include "sys/sys.h" -#include "core/zone.h" -#include <vector> - -#ifdef HAVE_BULLET -#include "btBulletDynamicsCommon.h" -#include "BulletCollision/CollisionShapes/btTriangleMesh.h" -#endif - -/* - - This file provides the interface between the osirion game library - and the bullet physics library - -*/ - -namespace game -{ - -#ifdef HAVE_BULLET -/// helper function to convert math:Vector3f to btVector3 -inline btVector3 to_btVector3(const math::Vector3f & v) -{ - return btVector3(v[0], v[1], v[2]); -} - -/// helper function to conver math::Axis to btMatrix3x3 -inline btMatrix3x3 to_btMatrix3x3(const math::Axis &a) -{ - return btMatrix3x3(a[0][0], a[0][1], a[0][2], - a[1][0], a[1][1], a[1][2], - a[2][0], a[2][1], a[2][2]); -}; -#endif - -/* ---- class CollisionShape --------------------------------------- */ - -/// a bullet collision shape -class CollisionShape -{ -public: - CollisionShape(model::Model *model, const bool moving); - - ~CollisionShape(); - - inline const std::string &label() const { - return shape_label; - } - - inline const bool moving() const { - return shape_moving; - } - -#ifdef HAVE_BULLET - inline btCollisionShape *bullet_shape() { - return shape_bulletshape; - } -#endif - - /* ----- static functions for the shape registry ------------------- */ - - /// tpye definition for the collision shape registry - typedef std::vector<CollisionShape *> Registry; - - static void clear(); - - static CollisionShape *add(model::Model *model, const bool moving); - - static CollisionShape *find(model::Model *model, const bool moving); - -private: - std::string shape_label; - bool shape_moving; - -#ifdef HAVE_BULLET - btCollisionShape *shape_bulletshape; - btTriangleMesh *shape_mesh; -#endif - - /// collision shape registry - static Registry shape_registry; -}; - -/* ---- class Physics ---------------------------------------------- */ - -/// main physics functions -class Physics -{ -public: - /// intialize world physics - static void init(); - - /// run a world physics frame - static void frame(const float elapsed); - - /// shutdown world physics - static void shutdown(); - -#ifdef HAVE_BULLET - static btDefaultCollisionConfiguration *configuration; - - static btCollisionDispatcher *dispatcher; - - static btSequentialImpulseConstraintSolver *solver; -#endif -}; - -/* ---- class PhysicsZone ------------------------------------------ */ - -/// a zone containing collision objects -class PhysicsZone : public core::Zone -{ -public: - PhysicsZone(const std::string &label); - virtual ~PhysicsZone(); - -#ifdef HAVE_BULLET - inline btDiscreteDynamicsWorld *dynamics_world() { - return zone_dynamics_world; - } - -private: - btAxisSweep3 *zone_cache; - btDiscreteDynamicsWorld *zone_dynamics_world; -#endif -}; - -/* ---- class PhysicsBody ------------------------------------------ */ - -/// an object that is capable of colliding with other objects -class PhysicsBody -{ -public: - /// initialize a collider attached to an entity - /** - * a PhysicsBody with zero mass is considered non-moving - */ - PhysicsBody(core::Entity *entity); - ~PhysicsBody(); - - /// initialize the collision body - void init_physics(const float mass); - - /// shutdown the collision body - void shutdown_physics(); - - /// collider mass - inline const float mass() const { - return collider_mass; - } - - /// the entity the collider is attached to - inline core::Entity *entity() { - return collider_entity; - } - -#ifdef HAVE_BULLET - /// the bullet rigid body associated with this collider - inline btRigidBody *body() { - return collider_body; - } -#endif - -private: - CollisionShape *collider_shape; - core::Entity *collider_entity; -#ifdef HAVE_BULLET - btRigidBody *collider_body; -#endif - float collider_mass; -}; - -} - -#endif // __INCLUDED_BASE_PHYSICS_H__ - diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 78764e3..696033c 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -27,7 +27,7 @@ const float impulse_delay = 3.0f; // 3 second delay before impulse kicks in // note: this delay must match the impulse drive sound set const float jump_delay = 5.0f; // 5 seconds delay before jump driv kicks in -Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(), PhysicsBody(this) +Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable() { entity_moduletypeid = ship_enttype; @@ -81,7 +81,6 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable( Ship::~Ship() { - shutdown_physics(); } void Ship::reset() @@ -282,35 +281,30 @@ void Ship::explode() void Ship::set_zone(core::Zone *zone) { - shutdown_physics(); - core::EntityControlable::set_zone(zone); if (owner() && (owner()->control() == (EntityControlable*) this)) owner()->set_zone(zone); - - init_physics(radius()); } void Ship::frame(float seconds) { - float actual_maxspeed = ship_shipmodel->maxspeed(); - float actual_turnspeed = ship_shipmodel->turnspeed(); - float actual_acceleration = ship_shipmodel->acceleration(); - float actual_thrust = 0; - -#ifndef HAVE_BULLET const float direction_reaction = 2.0f; // direction controls reaction time factor const float thrust_reaction = 0.5f; // thrust control reaction time factor const float strafe_reaction = 1.5f; const float afterburner_reaction = 1.0f; // a fterburner control reaction time + float actual_maxspeed = ship_shipmodel->maxspeed(); + float actual_turnspeed = ship_shipmodel->turnspeed(); + float actual_acceleration = ship_shipmodel->acceleration(); + float actual_thrust = 0; float cosangle; // cosine of an angle float angle; // angle in radians math::Vector3f n; // normal of a plane - math::Axis target_axis(axis()); // target axis -#endif + + math::Axis target_axis(axis()); // target axis + entity_movement = 0; /* -- update state ----------------------------------------- */ @@ -511,7 +505,6 @@ void Ship::frame(float seconds) actual_thrust = 1.0f; } - // update strafe control target if (current_target_strafe < target_strafe) { current_target_strafe += strafe_reaction * seconds; @@ -522,9 +515,6 @@ void Ship::frame(float seconds) if (current_target_strafe < target_strafe) current_target_strafe = target_strafe; } -#ifndef HAVE_BULLET - - /* -- original frame --------------------------------------- */ // update roll control target if (current_target_roll < target_roll) { @@ -615,30 +605,6 @@ void Ship::frame(float seconds) get_location() += axis().forward() * speed() * seconds; } -#else /* #ifndef HAVE_BULLET */ - - /* -- bullet frame ----------------------------------------- */ - - // get entity speed from physics body - btVector3 velocity(body()->getInterpolationLinearVelocity()); - entity_speed = velocity.length(); - - // get physics body world transformation - btTransform t; - if (body()->getMotionState()) - body()->getMotionState()->getWorldTransform(t); - else - t = body()->getWorldTransform(); - - // get entity location from physics body - btVector3 v(t.getOrigin()); - entity_location.assign(v[0], v[1], v[2]); - - // apply engine trust to the body - body()->applyCentralImpulse(to_btVector3(axis().forward() * actual_thrust * actual_acceleration * seconds * 20.0f)); - -#endif /* else #ifndef HAVE_BULLET */ - entity_movement = target_thrust; entity_movement = math::max(entity_movement, fabs(current_target_pitch)); entity_movement = math::max(entity_movement, fabs(current_target_direction)); diff --git a/src/game/base/ship.h b/src/game/base/ship.h index f66bb66..1114df2 100644 --- a/src/game/base/ship.h +++ b/src/game/base/ship.h @@ -9,7 +9,6 @@ #include "core/player.h" #include "core/entity.h" -#include "base/physics.h" #include "base/shipmodel.h" #include "base/jumppoint.h" #include "math/vector3f.h" @@ -18,7 +17,7 @@ namespace game { /// A ship in the game, controled by a player -class Ship : public core::EntityControlable, public PhysicsBody +class Ship : public core::EntityControlable { public: Ship(core::Player *owner, ShipModel *shipmodel); diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc index 6ff6c43..9133d28 100644 --- a/src/game/base/shipmodel.cc +++ b/src/game/base/shipmodel.cc @@ -224,6 +224,12 @@ void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller) assert(seller_item->info() == this); } + // check if there's enough space available to transfer inventory + if (player->control() && (maxcargo() < player->control()->inventory()->capacity_used())) { + player->send("^WNot enough cargo space to transfer inventory!"); + return; + } + // check price if (price() > player->credits()) { player->send("^WCan not afford transaction!"); @@ -243,6 +249,14 @@ void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller) ship->set_state(core::Entity::Docked); ship->get_axis().assign(seller->axis()); ship->get_axis().change_direction(180.0f); + + // 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))); + } + ship->inventory()->set_dirty(); + player->set_control(ship); player->set_view(seller); diff --git a/src/game/base/station.cc b/src/game/base/station.cc index a093c0e..f5dc50a 100644 --- a/src/game/base/station.cc +++ b/src/game/base/station.cc @@ -11,7 +11,7 @@ namespace game { -Station::Station() : Entity(), PhysicsBody(this) +Station::Station() : Entity() { entity_moduletypeid = station_enttype; set_flag(core::Entity::Dockable); @@ -20,7 +20,6 @@ Station::Station() : Entity(), PhysicsBody(this) Station::~Station() { - shutdown_physics(); } void Station::dock(core::Entity *entity) diff --git a/src/game/base/station.h b/src/game/base/station.h index ea7fdbd..3f8bea6 100644 --- a/src/game/base/station.h +++ b/src/game/base/station.h @@ -7,12 +7,10 @@ #ifndef __INCLUDED_BASE_STATION_H__ #define __INCLUDED_BASE_STATION_H__ -#include "base/physics.h" - namespace game { -class Station : public core::Entity, public PhysicsBody +class Station : public core::Entity { public: Station(); |