Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-11-25 21:29:39 +0000
committerStijn Buys <ingar@osirion.org>2012-11-25 21:29:39 +0000
commit71503d65f1099d9f34010de98d377f8f2f5e474e (patch)
tree0e54c6dd9b80e9de86742185853b1c6d796ee2c8 /src
parent159716799ed0aebb3c30ca156a7c253030ab09b1 (diff)
Removed game::Projectile, added initial support for ship health.
Diffstat (limited to 'src')
-rw-r--r--src/game/base/Makefile.am2
-rw-r--r--src/game/base/game.cc36
-rw-r--r--src/game/base/game.h1
-rw-r--r--src/game/base/projectile.cc174
-rw-r--r--src/game/base/projectile.h94
-rw-r--r--src/game/base/ship.cc41
6 files changed, 42 insertions, 306 deletions
diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am
index 9e54b6c..544cbb6 100644
--- a/src/game/base/Makefile.am
+++ b/src/game/base/Makefile.am
@@ -11,7 +11,6 @@ noinst_HEADERS = \
jumppoint.h \
navpoint.h \
planet.h \
- projectile.h \
racetrack.h \
savegame.h \
ship.h \
@@ -30,7 +29,6 @@ libbase_la_SOURCES = \
jumppoint.cc \
navpoint.cc \
planet.cc \
- projectile.cc \
racetrack.cc \
savegame.cc \
ship.cc \
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 1020fa8..e9ea476 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -751,6 +751,17 @@ void Game::func_sell(core::Player *player, const std::string &args)
buyer->inventory()->set_dirty();
}
+ // unmount if the item was mounted
+ core::Slot *slot = (seller->slots() ? seller->slots()->find(seller_item) : 0);
+
+ if (slot) {
+ slot->set_item(0);
+ slot->unset_flag(core::Slot::Active);
+ slot->unset_flag(core::Slot::Mounted);
+ seller_item->unset_flag(core::Item::Mounted);
+ }
+
+ // delete the item if the amount is 0
if (seller_item->amount() == 0) {
seller->inventory()->erase(seller_item->id());
seller->inventory()->set_dirty();
@@ -1195,7 +1206,7 @@ void Game::func_mount(core::Player *player, const std::string &args)
if (item->info()->type() != Weapon::infotype()) {
if (ship->owner()) {
std::stringstream msgstr;
- msgstr << "^WItem " << id << " can not be mounted";
+ msgstr << "^W" << item->info()->name() << " can not be mounted";
ship->owner()->send(msgstr.str());
}
return;
@@ -1205,7 +1216,7 @@ void Game::func_mount(core::Player *player, const std::string &args)
if (!item->unique() || (weapon->subtype() != Weapon::Cannon)) {
if (ship->owner()) {
std::stringstream msgstr;
- msgstr << "^WItem " << id << " can not be mounted";
+ msgstr << "^W" << weapon->name() << " can not be mounted";
ship->owner()->send(msgstr.str());
}
return;
@@ -1213,20 +1224,12 @@ void Game::func_mount(core::Player *player, const std::string &args)
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);
- }
- }
-
+ core::Slot *slot = ship->slots()->find(item);
if (slot) {
slot->set_item(0);
slot->unset_flag(core::Slot::Active);
slot->unset_flag(core::Slot::Mounted);
- item->unset_flag(core::Item::Mounted);
-
+ item->unset_flag(core::Item::Mounted);
if (ship->owner()) {
std::stringstream msgstr;
msgstr << "^BUnmounted " << weapon->name();
@@ -1247,7 +1250,7 @@ void Game::func_mount(core::Player *player, const std::string &args)
if (!slot) {
if (ship->owner()) {
std::stringstream msgstr;
- msgstr << "^WNo slot available to mount item " << id;
+ msgstr << "^WNo slot available to mount " << weapon->name();
ship->owner()->send(msgstr.str());
}
return;
@@ -1256,13 +1259,6 @@ void Game::func_mount(core::Player *player, const std::string &args)
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();
diff --git a/src/game/base/game.h b/src/game/base/game.h
index f535ec9..aab28bc 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -35,7 +35,6 @@ const unsigned int jumpgate_enttype = 261;
const unsigned int station_enttype = 262;
const unsigned int cargopod_enttype = 263;
const unsigned int spacemine_enttype = 264;
-const unsigned int projectile_enttype = 265;
const unsigned int race_enttype = 280;
// planet docking distance
diff --git a/src/game/base/projectile.cc b/src/game/base/projectile.cc
deleted file mode 100644
index 4dd483d..0000000
--- a/src/game/base/projectile.cc
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- base/projectile.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
-*/
-
-#include "base/projectile.h"
-#include "base/game.h"
-#include "core/gameserver.h"
-#include "math/functions.h"
-#include "sys/sys.h"
-
-namespace game
-{
-
-EntityProjectile::EntityProjectile(unsigned long lifespan) : EntityDynamic()
-{
- entity_moduletypeid = projectile_enttype;
- //set_name("");
- set_label("projectile");
-
- //set_serverside(true);
- set_flag(core::Entity::KeepAlive);
- set_shape(core::Entity::Sphere);
- set_radius(0.01f);
- set_mass(radius());
-
- //reset();
-
- //const float damp = Game::g_damping->value();
- //body()->setDamping(0.0f, 0.0f);
-
- projectile_damage = 0.0f;
- projectile_lifespan = lifespan;
- projectile_timestamp = core::server()->timestamp();
- projectile_ownerid = 0;
-}
-
-EntityProjectile::~EntityProjectile()
-{
-
-}
-
-void EntityProjectile::upkeep(const unsigned long timestamp)
-{
- die();
-}
-
-void EntityProjectile::collision(core::Entity *other)
-{
- if (state() == core::Entity::Destroyed) {
- return;
- }
-
- set_state(core::Entity::Destroyed);
- // this method is a bullet callback, we can not reset() here
-}
-
-void EntityProjectile::frame(const unsigned long elapsed)
-{
- EntityDynamic::frame(elapsed);
-
- if (projectile_timestamp + projectile_lifespan < core::server()->timestamp()) {
- set_state(core::Entity::Destroyed);
- }
-
- if (state() == core::Entity::Destroyed) {
- die();
- }
-}
-
-void EntityProjectile::reset()
-{
- // no bullet physics on NonSolid entities
- if (!radius() || has_flag(NonSolid)) {
- return;
- }
-
- // remove Docked and Destroyed entities from the physics simulation
- if (destroyed() || (state() == core::Entity::Docked) || (state() == core::Entity::Destroyed)) {
-
- if (entity_body) {
-
- if (entity_motionstate) {
- delete entity_motionstate;
- entity_motionstate = 0;
- }
-
- if (zone() && zone()->physics()) {
- entity_zone->physics()->removeRigidBody(body());
- }
-
- if (entity_collision_shape) {
- delete entity_collision_shape;
- entity_collision_shape = 0;
- }
-
- for (CollisionShapes::iterator sit = entity_collision_child_shapes.begin(); sit != entity_collision_child_shapes.end(); sit++) {
- delete (*sit);
- (*sit) = 0;
- }
- entity_collision_child_shapes.clear();
-
- if (entity_body) {
- delete entity_body;
- entity_body = 0;
- }
-
- if (entity_body_info) {
- delete entity_body_info;
- entity_body_info = 0;
- }
- }
-
- return;
- }
-
- // location and orientation
- btTransform t;
- t.setIdentity();
- t.setOrigin(to_btVector3(location()));
- t.setBasis(to_btMatrix3x3(axis()));
-
- // construct physics body if necessary
- if (!entity_body) {
- // use a sphere with a radius matching the entity
- btSphereShape *sphereshape = new btSphereShape(radius());
- entity_collision_shape = sphereshape;
-
- // set margin
- //entity_collision_shape->setMargin(core::Cvar::sv_collisionmargin->value());
-
- // calculate inertia
- btVector3 inertia(0, 0, 0);
- if (entity_mass)
- entity_collision_shape->calculateLocalInertia(entity_mass, inertia);
-
- // create motion state
- entity_motionstate = new btDefaultMotionState(t);
-
- // create physics body
- entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, entity_motionstate, entity_collision_shape, inertia);
- entity_body = new btRigidBody(*entity_body_info);
- // point the bullet user pointer to the entity
- entity_body->setUserPointer((void *) this);
- // enable custom collision callback
- entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
- //entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
-
- if (entity_mass) {
- entity_body->setActivationState(DISABLE_DEACTIVATION);
- } else {
- entity_body->setActivationState(ISLAND_SLEEPING);
- }
-
- if (zone())
- zone()->physics()->addRigidBody(entity_body);
- }
-
- // transfer entity location to motion state
- body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
- body()->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f));
- body()->setWorldTransform(t);
- body()->clearForces();
-
- if (motionstate()) {
- motionstate()->setWorldTransform(t);
- }
-
- set_dirty();
-}
-
-} // namespace game
-
diff --git a/src/game/base/projectile.h b/src/game/base/projectile.h
deleted file mode 100644
index 2513901..0000000
--- a/src/game/base/projectile.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- base/projectile.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_PROJECTILE_H__
-#define __INCLUDED_BASE_PROJECTILE_H__
-
-#include "core/entity.h"
-
-namespace game
-{
-
-class EntityProjectile : public core::EntityDynamic
-{
-public:
- EntityProjectile(unsigned long lifespan);
- virtual ~EntityProjectile();
-
- virtual void upkeep(const unsigned long timestamp);
-
- virtual void collision(Entity *other);
-
- virtual void frame(const unsigned long elapsed);
-
- /* --- inspectors ------------------------------------------ */
-
- inline const unsigned long timestamp() const
- {
- return projectile_timestamp;
- }
-
- /**
- * @brief the lifespan of this projectile, in milliseconds
- * */
- inline const unsigned long lifespan() const
- {
- return projectile_lifespan;
- }
-
- /**
- * @brief the amount of damage this projectile inflicts
- * */
- inline const float damage() const
- {
- return projectile_damage;
- }
-
- /**
- * @brief id of the player who fired the projectile
- * */
- inline const int ownerid() const
- {
- return projectile_ownerid;
- }
-
- /* --- mutators -------------------------------------------- */
-
- /**
- * @brief reset physics state
- * */
- virtual void reset();
-
- /**
- * @brief set the amount of damage this projectile inflicts
- * */
- inline void set_damage(const float damage)
- {
- projectile_damage = damage;
- }
-
- /**
- * @brief set the id of the player who fired the projectile
- * */
- inline void set_ownerid(const int ownerid)
- {
- projectile_ownerid = ownerid;
- }
-
-private:
- unsigned long projectile_timestamp;
-
- unsigned long projectile_lifespan;
-
- float projectile_damage;
-
- int projectile_ownerid;
-};
-
-} // namespace game
-
-#endif // __INCLUDED_BASE_PROJECTILE_H__
-
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index fc01b5c..f874fa3 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -13,10 +13,11 @@
#include "core/gameserver.h"
#include "core/entity.h"
+#include "core/entityprojectile.h"
#include "base/game.h"
#include "base/ship.h"
-#include "base/projectile.h"
+
#include "base/spacemine.h"
using math::degrees360f;
@@ -530,10 +531,10 @@ void Ship::collision(core::Entity *other)
}
}
- } else if (other->moduletype() == projectile_enttype) {
+ } else if (other->type() == core::Entity::Projectile) {
// hit by projectile
- game::EntityProjectile *projectile = static_cast<EntityProjectile *>(other);
+ core::EntityProjectile *projectile = static_cast<core::EntityProjectile *>(other);
if (projectile->state() != core::Entity::Destroyed) {
ship_armor -= projectile->damage();
}
@@ -762,6 +763,9 @@ void Ship::frame(const unsigned long elapsed)
entity_thrust = 0;
entity_controlflags = 0;
}
+
+ // current health
+ entity_health = armor() * 100.0f / maxarmor();
/* -- SNAPPY ------------------------------------------ */
@@ -880,24 +884,31 @@ void Ship::frame(const unsigned long elapsed)
const float modelscale = radius() / model()->radius();
for (core::Slots::iterator it = slots()->begin(); it != slots()->end(); it++) {
+ core::Slot *slot = (*it);
+
// create projectiles
- if ( ((*it)->projectile_interval() > 0) && ((*it)->has_flag(core::Slot::Mounted)) && ((*it)->has_flag(core::Slot::Active))) {
- if ((*it)->last_fired() + (*it)->projectile_interval() <= core::server()->timestamp()) {
- (*it)->set_last_fired(core::server()->timestamp());
- EntityProjectile * projectile = new EntityProjectile((*it)->projectile_lifespan());
- projectile->set_damage((*it)->projectile_damage());
+ if (slot->has_flag(core::Slot::Mounted) && slot->item() && (slot->item()->info()->type() == Weapon::infotype())) {
+
+ const Weapon *weapon = static_cast<const Weapon *>(slot->item()->info());
+ if ((weapon->subtype() == Weapon::Cannon) && (weapon->projectile_interval() > 0) && (slot->last_fired() + weapon->projectile_interval() <= core::server()->timestamp())) {
+ slot->set_last_fired(core::server()->timestamp());
+
+ core::EntityProjectile *projectile = new core::EntityProjectile();
+
+ projectile->set_damage(weapon->damage());
+ projectile->set_lifespan(weapon->projectile_lifespan());
+ projectile->set_projectile_modelname(weapon->projectile_modelname());
projectile->set_color(color());
+ projectile->set_color_second(color_second());
+ projectile->set_zone(zone());
+ projectile->set_axis(axis() * slot->axis());
+ projectile->set_location(location() + (axis() * slot->location() * modelscale) + projectile->axis().forward() * projectile->radius());
if (owner()) {
projectile->set_ownerid(owner()->id());
}
- projectile->set_zone(zone());
- projectile->set_axis(axis() * (*it)->axis());
- projectile->set_location(location() + (axis() * (*it)->location() * modelscale) + projectile->axis().forward() * projectile->radius());
- projectile->set_modelname("maps/projectiles/" + (*it)->projectile_modelname());
-
+ projectile->set_speed(weapon->projectile_speed());
projectile->reset();
- projectile->body()->setDamping(0.0f, 0.0f);
- projectile->body()->setLinearVelocity(math::to_btVector3(projectile->axis().forward() * (*it)->projectile_speed()));
+
}
}
}