From ab61530779c73e7e145193efcb1e23a47c16e7f3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 18 Nov 2012 15:10:37 +0000 Subject: Implements server-side ship damage, adds a damage key to the weapons.ini file, configurable spacemine damage. --- src/game/base/ship.cc | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'src/game/base/ship.cc') 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(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(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()); -- cgit v1.2.3