Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-11-18 15:10:37 +0000
committerStijn Buys <ingar@osirion.org>2012-11-18 15:10:37 +0000
commitab61530779c73e7e145193efcb1e23a47c16e7f3 (patch)
tree9aed75947be45585cf884effc3a59575a1b1bb8e /src/game/base/ship.cc
parent69b0cd536aee5cf948e5a97af4df3dd75a545bd0 (diff)
Implements server-side ship damage,
adds a damage key to the weapons.ini file, configurable spacemine damage.
Diffstat (limited to 'src/game/base/ship.cc')
-rw-r--r--src/game/base/ship.cc61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 854bdab..ac4db15 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -14,6 +14,7 @@
#include "base/game.h"
#include "base/ship.h"
#include "base/projectile.h"
+#include "base/spacemine.h"
#include "math/functions.h"
using math::degrees360f;
@@ -40,6 +41,11 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
ship_dock = 0;
ship_spawn = 0;
+ ship_maxarmor = 100.0f;
+
+ ship_maxshield = 0.0f;
+ ship_shield = 0.0f;
+
current_impulse = false;
// apply ship type settings
@@ -106,6 +112,8 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
set_flag(core::Entity::Dockable);
}
+ ship_armor = maxarmor();
+
// initialize physics
// FIXME probably should not be called here
//reset();
@@ -318,6 +326,10 @@ void Ship::set_dock(core::Entity *dock)
get_location().assign(dock->location());
get_axis().assign(dock->axis());
ship_dock = dock;
+ if (dock->zone() != zone())
+ {
+ set_zone(dock->zone());
+ }
set_state(core::Entity::Docked);
reset();
@@ -436,6 +448,8 @@ void Ship::collision(core::Entity *other)
// do not fly into planets
if (other->moduletype() == planet_enttype) {
+
+ // ran into a planet
explode();
if (owner()) {
@@ -449,16 +463,60 @@ void Ship::collision(core::Entity *other)
die();
}
} else if (other->moduletype() == star_enttype) {
+
+ // flew into a star
explode();
if (owner()) {
std::string message("^B");
message.append(owner()->name());
- message.append(" ^Bcould not resist the light.");
+ message.append(" ^Bflew into a star.");
core::server()->broadcast(message);
} else {
die();
}
+
+ } else if (other->moduletype() == spacemine_enttype) {
+
+ // hit by a mine
+ SpaceMine * spacemine = static_cast<SpaceMine *>(other);
+ if (spacemine->state() != core::Entity::Destroyed) {
+ ship_armor -= spacemine->damage();
+ }
+
+ // destroyed
+ if (ship_armor <= 0) {
+ if (owner()) {
+ ship_armor = 0;
+ std::string message("^B");
+ message.append(owner()->name());
+ message.append(" ^Bwent boom.");
+ explode();
+ } else {
+ die();
+ }
+ }
+
+ } else if (other->moduletype() == projectile_enttype) {
+
+ // hit by projectile
+ Projectile * projectile = static_cast<Projectile *>(other);
+ if (projectile->state() != core::Entity::Destroyed) {
+ ship_armor -= projectile->damage();
+ }
+
+ // destroyed
+ if (ship_armor <= 0) {
+ if (owner()) {
+ ship_armor = 0;
+ std::string message("^B");
+ message.append(owner()->name());
+ message.append(" ^Bwas blown to bits.");
+ explode();
+ } else {
+ die();
+ }
+ }
}
}
@@ -773,6 +831,7 @@ void Ship::frame(const unsigned long elapsed)
if ((*it)->last_fired() + (*it)->interval() <= core::server()->timestamp()) {
(*it)->set_last_fired(core::server()->timestamp());
Projectile * projectile = new Projectile((*it)->lifespan());
+ projectile->set_damage(10.0f);
projectile->set_zone(zone());
projectile->set_axis(axis() * (*it)->axis());
projectile->set_location(location() + (axis() * (*it)->location() * modelscale) + projectile->axis().forward() * projectile->radius());