Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/jumppoint.cc10
-rw-r--r--src/game/base/navpoint.cc6
-rw-r--r--src/game/base/planet.cc4
-rw-r--r--src/game/base/racetrack.cc6
-rw-r--r--src/game/base/ship.cc182
-rw-r--r--src/game/base/star.cc6
-rw-r--r--src/game/example/example.cc10
-rw-r--r--src/game/example/spectator.cc18
-rw-r--r--src/game/intro/convoy.cc6
9 files changed, 137 insertions, 111 deletions
diff --git a/src/game/base/jumppoint.cc b/src/game/base/jumppoint.cc
index e489055..9017f1c 100644
--- a/src/game/base/jumppoint.cc
+++ b/src/game/base/jumppoint.cc
@@ -15,13 +15,13 @@ namespace game
JumpPoint::JumpPoint() : core::EntityDynamic(core::Entity::Bright)
{
entity_shape = core::Entity::Diamond;
- entity_color.assign(0.0f, 0.8f, 0.8f, 1.0f);
- entity_color_second.assign(0.6f, 1.0f);
- entity_radius = 0.25f;
+ get_color().assign(0.0f, 0.8f, 0.8f, 1.0f);
+ get_color_second().assign(0.6f, 1.0f);
+ set_radius(0.25f);
entity_moduletypeid = jumppoint_enttype;
jumppoint_target = 0;
- entity_serverside = false;
+ set_serverside(false);
}
JumpPoint::~JumpPoint()
@@ -78,8 +78,8 @@ JumpGate::JumpGate() : JumpPoint()
{
unset_flag(core::Entity::Bright);
set_flag(core::Entity::ShowOnMap);
+ set_radius(1.0f);
- entity_radius = 1.0f;
entity_moduletypeid = jumpgate_enttype;
entity_state = core::Entity::NoPower;
}
diff --git a/src/game/base/navpoint.cc b/src/game/base/navpoint.cc
index 5dc35b2..7b48ee7 100644
--- a/src/game/base/navpoint.cc
+++ b/src/game/base/navpoint.cc
@@ -14,9 +14,9 @@ NavPoint::NavPoint() : core::Entity(core::Entity::Static | core::Entity::Bright)
{
//set_flag(core::Entity::ShowOnMap);
entity_shape = core::Entity::Diamond;
- entity_color.assign(1.0f, 1.0f);
- entity_color_second.assign(0.6f, 1.0f);
- entity_radius = 0.25f;
+ get_color().assign(1.0f, 1.0f);
+ get_color_second().assign(0.6f, 1.0f);
+ set_radius(0.25f);
entity_moduletypeid = navpoint_enttype;
}
diff --git a/src/game/base/planet.cc b/src/game/base/planet.cc
index 60885b1..b1ac976 100644
--- a/src/game/base/planet.cc
+++ b/src/game/base/planet.cc
@@ -14,8 +14,8 @@ Planet::Planet() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid)
{
set_flag(core::Entity::ShowOnMap);
- entity_color = math::Color(1,1,1,1); // white
- entity_radius = 64; // 64 game units
+ get_color().assign(1.0f, 1.0f); // white
+ set_radius(64.0f); // 64 game units
entity_moduletypeid = planet_enttype;
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc
index f54a24b..3d1cb69 100644
--- a/src/game/base/racetrack.cc
+++ b/src/game/base/racetrack.cc
@@ -20,8 +20,8 @@ CheckPoint::CheckPoint(RaceTrack *parent)
set_state(core::Entity::NoPower);
parent_track = parent;
if (parent) {
- entity_color = parent->color();
- entity_color_second = parent->color_second();
+ get_color().assign(parent->color());
+ get_color_second().assign(parent->color_second());
set_zone(parent->zone());
parent->add_checkpoint(this);
} else {
@@ -142,7 +142,7 @@ void RaceTrack::frame(float seconds)
if (track_racestart + 1.0f <= core::server()->time()) {
entity_timer -= 1.0f;
- entity_dirty = true;
+ set_dirty();
if (entity_timer > 0) {
std::stringstream msgstr;
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 03fe3de..8bc7799 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -36,8 +36,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
entity_moduletypeid = ship_enttype;
- entity_color = owner->color();
- entity_color_second = owner->color_second();
+ get_color().assign(owner->color());
+ get_color_second().assign(owner->color_second());
ship_shipmodel = shipmodel;
ship_jumpdrive = shipmodel->shipmodel_jumpdrive;
@@ -88,10 +88,9 @@ void Ship::func_impulse()
entity_timer = 3;
}
ship_impulsedrive_timer = core::server()->time();
- entity_dirty = true;
}
- entity_dirty = true;
+ set_dirty();
}
void Ship::initiate_jump(JumpPoint *depart)
@@ -114,7 +113,7 @@ void Ship::initiate_jump(JumpPoint *depart)
}
ship_jumpdrive_timer = core::server()->time();
- entity_dirty = true;
+ set_dirty();
}
void Ship::func_jump(std::string const &args)
@@ -149,8 +148,8 @@ void Ship::func_jump(std::string const &args)
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_state = core::Entity::Jump;
- entity_dirty = true;
+ set_state(core::Entity::Jump);
+ set_dirty();
return;
} else {
@@ -244,11 +243,16 @@ void Ship::frame(float seconds)
float actual_thrust = 0;
#ifndef HAVE_BULLET
- const float direction_change_speed = 2;
+ 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 cosangle; // cosine of an angle
float angle; // angle in radians
math::Vector3f n; // normal of a plane
- math::Axis target_axis(entity_axis); // target axis
+ math::Axis target_axis(axis()); // target axis
#endif
entity_movement = 0;
@@ -256,7 +260,7 @@ void Ship::frame(float seconds)
// speed might be set to 0 on this update
if (entity_speed != 0.0f)
- entity_dirty = true;
+ set_dirty();
if (entity_state == core::Entity::Docked) {
@@ -280,11 +284,11 @@ void Ship::frame(float seconds)
set_state(core::Entity::Jump);
entity_speed = Game::g_impulsespeed->value();
if (ship_jumpdepart->moduletype() == jumpgate_enttype) {
- entity_axis.assign(ship_jumpdepart->target()->axis());
- entity_location.assign(ship_jumpdepart->target()->location());
+ get_axis().assign(ship_jumpdepart->target()->axis());
+ get_location().assign(ship_jumpdepart->target()->location());
//entity_location += entity_axis.forward() * radius();
} else {
- entity_location.assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
+ get_location().assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
}
set_zone(ship_jumpdepart->target()->zone());
owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name());
@@ -294,11 +298,11 @@ void Ship::frame(float seconds)
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_dirty = true;
+ set_dirty();
return;
} else {
ship_jumpdrive_timer = core::server()->time();
- entity_dirty = true;
+ set_dirty();
}
}
@@ -323,7 +327,7 @@ void Ship::frame(float seconds)
// FIXME 5 second cooldown
entity_state = core::Entity::Normal;
- entity_dirty = true;
+ set_dirty();
if (owner() && owner()->view() && owner()->control() == (EntityControlable*) this)
owner()->set_view(0);
@@ -332,30 +336,38 @@ void Ship::frame(float seconds)
} else if (entity_state == core::Entity::ImpulseInitiate) {
- if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
- entity_timer -= 1.0f;
+ // cancel impulse drive if afterburner goes reverse
+ if (target_afterburner < 0.0f) {
+ set_state(core::Entity::Normal);
+ set_dirty();
+ entity_timer = 0;
+ } else {
- if (entity_timer <= 0) {
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
- entity_state = core::Entity::Impulse;
- entity_timer = 0;
- entity_dirty = true;
- } else {
- ship_impulsedrive_timer = core::server()->time();
- entity_dirty = true;
+ if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
+ entity_timer -= 1.0f;
+
+ if (entity_timer <= 0) {
+ actual_maxspeed = Game::g_impulsespeed->value();
+ actual_acceleration = Game::g_impulseacceleration->value();
+ entity_state = core::Entity::Impulse;
+ entity_timer = 0;
+ set_dirty();
+ } else {
+ ship_impulsedrive_timer = core::server()->time();
+ set_dirty();
+ }
}
+
+ // clamp input values
+ target_thrust = 0.0f;
+ math::clamp(target_pitch, -1.0f, 1.0f);
+ math::clamp(target_roll, -1.0f, 1.0f);
+ math::clamp(target_direction, -1.0f, 1.0f);
+ math::clamp(target_afterburner, -1.0f, 1.0f);
+
+ actual_turnspeed *= 0.5;
}
- // clamp input values
- target_thrust = 0.0f;
- math::clamp(target_pitch, -1.0f, 1.0f);
- math::clamp(target_roll, -1.0f, 1.0f);
- math::clamp(target_direction, -1.0f, 1.0f);
- math::clamp(target_afterburner, -1.0f, 1.0f);
-
- actual_turnspeed *= 0.5;
-
} else if (entity_state == core::Entity::Impulse) {
// clamp input values
@@ -365,9 +377,18 @@ void Ship::frame(float seconds)
math::clamp(target_direction, -1.0f, 1.0f);
target_afterburner = 0.0f;
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
- actual_turnspeed *= 0.5;
+ // cancel impulse drive if afterburner goes reverse
+ if (target_afterburner < 0.0f) {
+ set_state(core::Entity::Normal);
+ set_dirty();
+ entity_timer = 0;
+ target_thrust = 1.0f;
+ target_thrust = 1.0f;
+ } else {
+ actual_maxspeed = Game::g_impulsespeed->value();
+ actual_acceleration = Game::g_impulseacceleration->value();
+ actual_turnspeed *= 0.5;
+ }
} else if (entity_state == core::Entity::Normal) {
@@ -395,28 +416,30 @@ void Ship::frame(float seconds)
entity_thrust = 0;
}
- // update afterburner
+ // update afterburner control target
if (current_target_afterburner < target_afterburner) {
- current_target_afterburner += 2.0f * seconds;
+ current_target_afterburner += afterburner_reaction * seconds;
if (current_target_afterburner > target_afterburner)
current_target_afterburner = target_afterburner;
+
} else if (current_target_afterburner > target_afterburner) {
- current_target_afterburner -= 2.0f * seconds;
+ current_target_afterburner -= afterburner_reaction * seconds;
if (current_target_afterburner < target_afterburner)
current_target_afterburner = target_afterburner;
}
- // update thrust
+ // update thrust control target
if (current_target_afterburner < 0.0f) {
target_thrust = 0;
}
if (entity_thrust < target_thrust) {
- entity_thrust += seconds * 0.5f;
+ entity_thrust += thrust_reaction * seconds;
if (entity_thrust > target_thrust)
entity_thrust = target_thrust;
+
} else if (entity_thrust > target_thrust) {
- entity_thrust -= seconds * 0.5f;
+ entity_thrust -= thrust_reaction * seconds;
if (entity_thrust < target_thrust)
entity_thrust = target_thrust;
}
@@ -426,17 +449,28 @@ 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;
+ if (current_target_strafe > target_strafe)
+ current_target_strafe = target_strafe;
+ } else if (current_target_strafe > target_strafe) {
+ current_target_strafe -= strafe_reaction * seconds;
+ if (current_target_strafe < target_strafe)
+ current_target_strafe = target_strafe;
+ }
#ifndef HAVE_BULLET
/* -- original frame --------------------------------------- */
- // update roll
+ // update roll control target
if (current_target_roll < target_roll) {
- current_target_roll += direction_change_speed * seconds;
+ current_target_roll += direction_reaction * seconds;
if (current_target_roll > target_roll)
current_target_roll = target_roll;
} else if (current_target_roll > target_roll) {
- current_target_roll -= direction_change_speed * seconds;
+ current_target_roll -= direction_reaction * seconds;
if (current_target_roll < target_roll)
current_target_roll = target_roll;
}
@@ -444,19 +478,19 @@ void Ship::frame(float seconds)
if (fabs(current_target_roll) > MIN_DELTA) {
float roll_offset = seconds * current_target_roll;
- entity_axis.change_roll(actual_turnspeed * roll_offset);
+ get_axis().change_roll(actual_turnspeed * roll_offset);
} else {
current_target_roll = 0.0f;
}
- // update target_axis direction
+ // update direction control target
if (current_target_direction < target_direction) {
- current_target_direction += direction_change_speed * seconds;
+ current_target_direction += direction_reaction * seconds;
if (current_target_direction > target_direction) {
current_target_direction = target_direction;
}
} else if (current_target_direction > target_direction) {
- current_target_direction -= direction_change_speed * seconds;
+ current_target_direction -= direction_reaction * seconds;
if (current_target_direction < target_direction) {
current_target_direction = target_direction;
}
@@ -469,12 +503,13 @@ void Ship::frame(float seconds)
current_target_direction = 0.0f;
}
+ // update pitch control target
if (current_target_pitch < target_pitch) {
- current_target_pitch += direction_change_speed * seconds;
+ current_target_pitch += direction_reaction * seconds;
if (current_target_pitch > target_pitch)
current_target_pitch = target_pitch;
} else if (current_target_pitch > target_pitch) {
- current_target_pitch -= direction_change_speed * seconds;
+ current_target_pitch -= direction_reaction * seconds;
if (current_target_pitch < target_pitch)
current_target_pitch = target_pitch;
}
@@ -486,45 +521,36 @@ void Ship::frame(float seconds)
current_target_pitch = 0.0f;
}
- n.assign(math::crossproduct(entity_axis.forward(), target_axis.forward()));
+ // update axis
+ n.assign(math::crossproduct(axis().forward(), target_axis.forward()));
if (!(n.length() < MIN_DELTA)) {
n.normalize();
- cosangle = math::dotproduct(entity_axis.forward(), target_axis.forward());
+ cosangle = math::dotproduct(axis().forward(), target_axis.forward());
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
- entity_axis.rotate(n, -angle);
+ get_axis().rotate(n, -angle);
}
// update speed
- if (entity_speed < actual_thrust * actual_maxspeed) {
+ const float max = actual_thrust * actual_maxspeed;
+ if (entity_speed < max) {
entity_speed += actual_acceleration * seconds;
- if (entity_speed > actual_thrust * actual_maxspeed) {
- entity_speed = actual_thrust * actual_maxspeed;
+ if (entity_speed > max) {
+ entity_speed = max;
}
- } else if(entity_speed > actual_thrust * actual_maxspeed) {
+ } else if(entity_speed > max) {
entity_speed -= actual_acceleration * seconds;
- if (entity_speed < actual_thrust * actual_maxspeed) {
- entity_speed = actual_thrust * actual_maxspeed;
+ if (entity_speed < max) {
+ entity_speed = max;
}
}
- // update strafe
- if (current_target_strafe < target_strafe) {
- current_target_strafe += 2.0f * seconds;
- if (current_target_strafe > target_strafe)
- current_target_strafe = target_strafe;
- } else if (current_target_strafe > target_strafe) {
- current_target_strafe -= 2.0f * seconds;
- if (current_target_strafe < target_strafe)
- current_target_strafe = target_strafe;
- }
-
if (fabs(current_target_strafe) > MIN_DELTA) {
- entity_location += entity_axis.left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds;
+ get_location() += axis().left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds;
}
- if (entity_speed) {
- entity_location += entity_axis.forward() * entity_speed * seconds;
+ if (fabs(speed()) > MIN_DELTA) {
+ get_location() += axis().forward() * speed() * seconds;
}
#else /* #ifndef HAVE_BULLET */
@@ -559,7 +585,7 @@ void Ship::frame(float seconds)
entity_movement = math::max(entity_movement, fabs(current_target_strafe));
if ((entity_movement > 0)|| (entity_speed > 0)) {
- entity_dirty = true;
+ set_dirty();
}
}
diff --git a/src/game/base/star.cc b/src/game/base/star.cc
index fa5dc32..ba3ccba 100644
--- a/src/game/base/star.cc
+++ b/src/game/base/star.cc
@@ -14,9 +14,9 @@ Star::Star() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid | co
{
set_flag(core::Entity::ShowOnMap);
- entity_color.assign(1,1,1,1);
- entity_color_second.assign(1,1,1,1);
- entity_radius = 96; // 96 game units
+ get_color().assign(1.0f, 1.0f);
+ get_color_second().assign(1.0f, 1.0f);
+ set_radius(96.0f);
entity_moduletypeid = star_enttype;
}
diff --git a/src/game/example/example.cc b/src/game/example/example.cc
index 9d4c1ed..f368556 100644
--- a/src/game/example/example.cc
+++ b/src/game/example/example.cc
@@ -43,9 +43,9 @@ Example::Example() : core::Module("The Osirion Project Example", true)
cube->set_label("cube");
cube->set_name("The Red Cube");
cube->entity_shape = core::Entity::Cube; // set the shape to cube
- cube->get_location().assign(16, -8, 0); // set location
+ cube->get_location().assign(16, -8, 0); // set location
cube->get_color().assign(1, 0, 0); // set RGB color red
- cube->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
cube->set_zone(zone); // add the entity to the zone
core::Entity *sphere = new core::Entity(); // a new entity
@@ -54,7 +54,7 @@ Example::Example() : core::Module("The Osirion Project Example", true)
sphere->entity_shape = core::Entity::Sphere; // set the shape to sphere
sphere->get_location().assign(16, 0, 0); // set location
sphere->get_color().assign(0, 1, 0); // set RGB color green
- sphere->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
sphere->set_zone(zone); // add the entity to the zone
core::Entity *diamond = new core::Entity(); // a new entity
@@ -63,7 +63,7 @@ Example::Example() : core::Module("The Osirion Project Example", true)
diamond->entity_shape = core::Entity::Diamond; // set the shape to cube
diamond->get_location().assign(16, 8, 0); // set location
diamond->get_color().assign(0, 0, 1); // set RGB color blue
- diamond->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
diamond->set_zone(zone); // add the entity to the zone
core::Entity *axis = new core::Entity(); // a new entity
@@ -73,7 +73,7 @@ Example::Example() : core::Module("The Osirion Project Example", true)
axis->get_location().assign(0, 0, 0); // set location
axis->get_color().assign(1); // set greyscale color white
axis->get_color_second().assign(0.5f, 0.0f, 0.5f); // set RGB secondary color
- axis->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
axis->set_zone(zone); // add the entity to the zone
}
diff --git a/src/game/example/spectator.cc b/src/game/example/spectator.cc
index a2c4353..5fad0f1 100644
--- a/src/game/example/spectator.cc
+++ b/src/game/example/spectator.cc
@@ -15,11 +15,11 @@ Spectator::Spectator(core::Player *owner) : core::EntityControlable(owner)
{
// default properties
entity_shape = core::Entity::Diamond;
- entity_radius = 0.25f;
+ set_radius(0.25f);
// the spectator gets player color
- entity_color.assign(owner->color());
- entity_color_second.assign(owner->color_second());
+ get_color().assign(owner->color());
+ get_color_second().assign(owner->color_second());
// set dirty flag
set_dirty();
@@ -40,9 +40,9 @@ void Spectator::frame(float elapsed)
// rotate according to input
float rotation = g_spectatorrotation->value() * elapsed;
- entity_axis.change_direction(target_direction * rotation);
- entity_axis.change_pitch(target_pitch * rotation);
- entity_axis.change_roll(target_roll * rotation);
+ get_axis().change_direction(target_direction * rotation);
+ get_axis().change_pitch(target_pitch * rotation);
+ get_axis().change_roll(target_roll * rotation);
// assign speed from thruster
float maxspeed = g_spectatorspeed->value();
@@ -50,13 +50,13 @@ void Spectator::frame(float elapsed)
// assign new location
if (entity_speed)
- entity_location += entity_axis.forward() * entity_speed * elapsed;
+ get_location() += axis().forward() * entity_speed * elapsed;
if (target_afterburner)
- entity_location += entity_axis.forward() * maxspeed * target_afterburner * elapsed;
+ get_location() += axis().forward() * maxspeed * target_afterburner * elapsed;
if (target_strafe)
- entity_location += entity_axis.left() * maxspeed * target_strafe * elapsed;
+ get_location() += axis().left() * maxspeed * target_strafe * elapsed;
// set dirty flag
set_dirty();
diff --git a/src/game/intro/convoy.cc b/src/game/intro/convoy.cc
index 9e13ae5..a0cc27c 100644
--- a/src/game/intro/convoy.cc
+++ b/src/game/intro/convoy.cc
@@ -27,7 +27,7 @@ Member::~Member()
void Member::frame(float seconds)
{
- entity_location += axis().forward() * speed() * thrust() * seconds;
+ get_location() += axis().forward() * speed() * thrust() * seconds;
}
/* ---- class Convoy ----------------------------------------------- */
@@ -38,8 +38,8 @@ Convoy::Convoy(core::Zone *zone) : core::EntityDynamic()
set_label("convoy");
set_name("Convoy");
- entity_speed = 1;
- entity_serverside = true;
+ entity_speed = 1.0f;
+ set_serverside();
}
Convoy::~Convoy()