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/game.cc197
-rw-r--r--src/game/game.h12
-rw-r--r--src/game/jumppoint.cc4
-rw-r--r--src/game/racetrack.cc13
-rw-r--r--src/game/ship.cc59
-rw-r--r--src/game/ship.h4
6 files changed, 133 insertions, 156 deletions
diff --git a/src/game/game.cc b/src/game/game.cc
index 0502ece..4d66cbe 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -224,6 +224,9 @@ void Game::init()
g_strafespeed = core::Cvar::get("g_strafespeed", "0.003", core::Cvar::Game | core::Cvar::Archive);
g_strafespeed->set_info("[float] strafe speed");
+ g_jumppointrange = core::Cvar::get("g_jumppointrange", "512", core::Cvar::Game | core::Cvar::Archive);
+ g_jumppointrange->set_info("[float] jumppoint range");
+
g_devel = core::Cvar::get("g_devel", "0", core::Cvar::Archive);
g_devel->set_info("[bool] enable or disable developer mode");
@@ -305,6 +308,65 @@ bool Game::load_world()
return true;
}
+bool Game::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
+{
+ std::string shapename;
+ std::string strval;
+ float direction;
+ float pitch;
+ float roll;
+
+ if (inifile.got_key_string("shape", shapename)) {
+
+ if (shapename.compare("axis") == 0) {
+ entity->entity_shape = core::Entity::Axis;
+ return true;
+ } else if (shapename.compare("cube") == 0) {
+ entity->entity_shape = core::Entity::Cube;
+ return true;
+ } else if (shapename.compare("diamond") == 0) {
+ entity->entity_shape = core::Entity::Diamond;
+ return true;
+ } else if (shapename.compare("sphere") == 0) {
+ entity->entity_shape = core::Entity::Sphere;
+ return true;
+ } else {
+ con_warn << inifile.name() << " unknown shape '" << shapename << "' at line " << inifile.line() << std::endl;
+ return false;
+ }
+
+ } else if (inifile.got_key_string("label", strval)) {
+ aux::to_label(strval);
+ entity->entity_label.assign(strval);
+ return true;
+ } else if (inifile.got_key_string("name", strval)) {
+ aux::strip_quotes(strval);
+ entity->entity_name.assign(strval);
+ return true;
+ } else if (inifile.got_key_string("model", entity->entity_modelname)) {
+ return true;
+ } else if (inifile.got_key_angle("direction", direction)) {
+ entity->axis().change_direction(direction);
+ return true;
+ } else if (inifile.got_key_angle("pitch", pitch)) {
+ entity->axis().change_pitch(pitch);
+ return true;
+ } else if (inifile.got_key_angle("roll", roll)) {
+ entity->axis().change_roll(roll);
+ return true;
+ } else if (inifile.got_key_angle("radius", entity->entity_radius)) {
+ return true;
+ } else if (inifile.got_key_vector3f("location", entity->entity_location)) {
+ return true;
+ } else if (inifile.got_key_color("color", entity->entity_color)) {
+ return true;
+ } else if (inifile.got_key_color("colorsecond", entity->entity_color_second)) {
+ return true;
+ }
+
+ return false;
+}
+
bool Game::load_zone(core::Zone *zone)
{
using math::Vector3f;
@@ -331,10 +393,6 @@ bool Game::load_zone(core::Zone *zone)
CheckPoint *checkpoint = 0;
core::Entity *entity = 0;
- float direction;
- float pitch;
- float roll;
-
bool b;
std::string strval;
@@ -346,6 +404,7 @@ bool Game::load_zone(core::Zone *zone)
if (zoneini.got_key()) {
if (zoneini.section().compare("zone") == 0) {
if (zoneini.got_key_string("name", strval)) {
+ aux::strip_quotes(strval);
zone->set_name(strval);
continue;
} else if (zoneini.got_key_string("sky", strval)) {
@@ -358,77 +417,32 @@ bool Game::load_zone(core::Zone *zone)
con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl;
}
} else if (zoneini.section().compare("star") == 0) {
-
- if (zoneini.got_key_string("label", strval)) {
- aux::to_label(strval);
- star->entity_label.assign(strval);
- continue;
- } else if (zoneini.got_key_string("name", star->entity_name)) {
- continue;
- } else if (zoneini.got_key_vector3f("location", star->entity_location )) {
- continue;
- } else if (zoneini.got_key_color("color", star->entity_color)) {
- continue;
- } else if (zoneini.got_key_angle("radius", star->entity_radius)) {
- continue;
- } else if (zoneini.got_key_angle("direction", direction)) {
- star->axis().change_direction(direction);
+ if (got_entity_key(zoneini, star)) {
continue;
} else if (zoneini.got_key_string("texture", star->entity_texture)) {
continue;
- } else if (zoneini.got_key_angle("pitch", pitch)) {
- star->axis().change_pitch(pitch);
- continue;
} else {
con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl;
}
} else if (zoneini.section().compare("navpoint") == 0) {
- if (zoneini.got_key_string("label", strval)) {
- aux::to_label(strval);
- navpoint->entity_label.assign(strval);
- continue;
- } else if (zoneini.got_key_string("name", navpoint->entity_name)) {
- continue;
- } else if (zoneini.got_key_vector3f("location", navpoint->entity_location )) {
+ if (got_entity_key(zoneini, navpoint)) {
continue;
} else {
con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl;
}
} else if (zoneini.section().compare("jumppoint") == 0) {
- if (zoneini.got_key_string("label", strval)) {
- aux::to_label(strval);
- jumppoint->entity_label.assign(strval);
- continue;
- } else if (zoneini.got_key_string("name", jumppoint->entity_name)) {
+ if (got_entity_key(zoneini, jumppoint)) {
continue;
} else if (zoneini.got_key_string("target", jumppoint->jumppoint_targetlabel)) {
continue;
- } else if (zoneini.got_key_vector3f("location", jumppoint->entity_location )) {
- continue;
} else {
con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl;
}
} else if (zoneini.section().compare("planet") == 0) {
- if (zoneini.got_key_string("label", strval)) {
- aux::to_label(strval);
- planet->entity_label.assign(strval);
- continue;
- } else if (zoneini.got_key_string("name", planet->entity_name)) {
+ if (got_entity_key(zoneini, planet)) {
continue;
} else if (zoneini.got_key_string("texture", planet->entity_texture)) {
continue;
- } else if (zoneini.got_key_vector3f("location", planet->entity_location )) {
- continue;
- } else if (zoneini.got_key_color("color", planet->entity_color)) {
- continue;
- } else if (zoneini.got_key_angle("radius", planet->entity_radius)) {
- continue;
- } else if (zoneini.got_key_angle("direction", direction)) {
- planet->axis().change_direction(direction);
- continue;
- } else if (zoneini.got_key_angle("pitch", pitch)) {
- planet->axis().change_pitch(pitch);
- continue;
} else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) {
continue;
} else {
@@ -436,88 +450,21 @@ bool Game::load_zone(core::Zone *zone)
}
} else if (zoneini.section().compare("racetrack") == 0) {
- if (zoneini.got_key_string("label", strval)) {
- aux::to_label(strval);
- racetrack->entity_label.assign(strval);
- continue;
- } else if (zoneini.got_key_string("name", racetrack->entity_name)) {
- continue;
- } else if (zoneini.got_key_vector3f("location", racetrack->entity_location )) {
- continue;
- } else if (zoneini.got_key_color("color", racetrack->entity_color)) {
- continue;
- } else if (zoneini.got_key_angle("direction", direction)) {
- racetrack->axis().change_direction(direction);
- continue;
- } else if (zoneini.got_key_angle("pitch", pitch)) {
- racetrack->axis().change_pitch(pitch);
- continue;
- } else if (zoneini.got_key_string("model", racetrack->entity_modelname)) {
+ if (got_entity_key(zoneini, racetrack)) {
continue;
} else {
con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl;
}
} else if (zoneini.section().compare("checkpoint") == 0) {
- if (zoneini.got_key_string("label", strval)) {
- aux::to_label(strval);
- checkpoint->entity_label.assign(strval);
- continue;
- } else if (zoneini.got_key_string("name", checkpoint->entity_name)) {
- continue;
- } else if (zoneini.got_key_vector3f("location", checkpoint->entity_location )) {
- continue;
- } else if (zoneini.got_key_angle("direction", direction)) {
- checkpoint->axis().change_direction(direction);
- continue;
- } else if (zoneini.got_key_angle("pitch", pitch)) {
- checkpoint->axis().change_pitch(pitch);
- continue;
- } else if (zoneini.got_key_string("model", checkpoint->entity_modelname)) {
+ if (got_entity_key(zoneini, checkpoint)) {
continue;
} else {
con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl;
}
} else if (zoneini.section().compare("entity") == 0) {
- std::string shapename;
- if (zoneini.got_key_string("shape", shapename)) {
- if (shapename.compare("axis") == 0) {
- entity->entity_shape = core::Entity::Axis;
- } else if (shapename.compare("cube") == 0) {
- entity->entity_shape = core::Entity::Cube;
- } else if (shapename.compare("diamond") == 0) {
- entity->entity_shape = core::Entity::Diamond;
- } else if (shapename.compare("sphere") == 0) {
- entity->entity_shape = core::Entity::Sphere;
- } else {
- con_warn << zoneini.name() << " unknown shape '" << shapename << "' at line " << zoneini.line() << std::endl;
- }
- continue;
- } else if (zoneini.got_key_string("label", strval)) {
- aux::to_label(strval);
- entity->entity_label.assign(strval);
- continue;
- } else if (zoneini.got_key_string("name", entity->entity_name)) {
- continue;
- } else if (zoneini.got_key_string("model", entity->entity_modelname)) {
- continue;
- } else if (zoneini.got_key_angle("direction", direction)) {
- entity->axis().change_direction(direction);
- continue;
- } else if (zoneini.got_key_angle("pitch", pitch)) {
- entity->axis().change_pitch(pitch);
- continue;
- } else if (zoneini.got_key_angle("roll", roll)) {
- entity->axis().change_roll(roll);
- continue;
- } else if (zoneini.got_key_angle("radius", entity->entity_radius)) {
- continue;
- } else if (zoneini.got_key_vector3f("location", entity->entity_location)) {
- continue;
- } else if (zoneini.got_key_color("color", entity->entity_color)) {
- continue;
- } else if (zoneini.got_key_color("colorsecond", entity->entity_color_second)) {
+ if (got_entity_key(zoneini, entity)) {
continue;
} else {
con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl;
@@ -576,6 +523,8 @@ bool Game::load_zone(core::Zone *zone)
bool Game::validate_zone(core::Zone *zone)
{
+ con_debug << " validating " << zone->name() << std::endl;
+
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
@@ -614,7 +563,7 @@ bool Game::validate_zone(core::Zone *zone)
jumppoint->jumppoint_target = static_cast<JumpPoint *>(targetentity);
- con_debug << " Jump point " << zone->label() << ":" << jumppoint->label() << " with target " << jumppoint->targetlabel() << std::endl;
+ //con_debug << " Jumppoint " << zone->label() << ":" << jumppoint->label() << " with target " << jumppoint->targetlabel() << std::endl;
}
}
diff --git a/src/game/game.h b/src/game/game.h
index c7ec040..3b65da1 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -7,16 +7,15 @@
#ifndef __INCLUDED_GAME_H__
#define __INCLUDED_GAME_H__
-// project headers
+#include <vector>
+#include <string>
+
+#include "filesystem/inifile.h"
#include "game/ship.h"
#include "game/star.h"
#include "core/core.h"
#include "sys/sys.h"
-// C++ headers
-#include <vector>
-#include <string>
-
/// the game-specific engine
/** The main game functions.
*/
@@ -55,10 +54,13 @@ public:
core::Cvar *g_impulsespeed;
core::Cvar *g_impulseacceleration;
core::Cvar *g_strafespeed;
+ core::Cvar *g_jumppointrange;
core::Cvar *g_devel;
private:
+ bool got_entity_key(filesystem::IniFile &inifile, core::Entity *entity);
+
bool load_world();
bool load_zone(core::Zone *zone);
diff --git a/src/game/jumppoint.cc b/src/game/jumppoint.cc
index a5f9b1a..d2c6bc1 100644
--- a/src/game/jumppoint.cc
+++ b/src/game/jumppoint.cc
@@ -13,13 +13,13 @@ namespace game
JumpPoint::JumpPoint() : core::Entity(core::Entity::Static)
{
entity_shape = core::Entity::Diamond;
- entity_color.assign(0.8f, 0.0f, 0.0f, 1.0f);
+ entity_color.assign(0.0f, 0.8f, 0.8f, 1.0f);
entity_color_second.assign(0.6f, 1.0f);
entity_radius = 0.25f;
entity_moduletypeid = jumppoint_enttype;
jumppoint_target = 0;
- entity_serverside = true;
+ entity_serverside = false;
}
JumpPoint::~JumpPoint()
diff --git a/src/game/racetrack.cc b/src/game/racetrack.cc
index 897a839..cfacb82 100644
--- a/src/game/racetrack.cc
+++ b/src/game/racetrack.cc
@@ -56,6 +56,9 @@ void RaceTrack::add_checkpoint(CheckPoint *checkpoint)
void RaceTrack::reset()
{
+ if (track_player) {
+ track_player->set_mission_target(0);
+ }
track_player = 0;
track_racestart = 0;
track_checkpointtime = 0;
@@ -64,8 +67,7 @@ void RaceTrack::reset()
(*cpit)->set_eventstate(core::Entity::NoPower);
}
- entity_eventstate |= core::Entity::NoPower;
- entity_dirty = true;
+ set_eventstate(core::Entity::NoPower);
}
void RaceTrack::frame(float seconds)
@@ -93,6 +95,7 @@ void RaceTrack::frame(float seconds)
message.append(track_player->name());
message.append(" ^Bactivated the race! Race starts in 5...");
core::server()->broadcast(message);
+ track_player->set_mission_target(this);
return;
}
}
@@ -149,6 +152,7 @@ void RaceTrack::frame(float seconds)
track_checkpointtime = core::server()->time() + 15.0f;
track_checkpoint = track_checkpoints.begin();
(*track_checkpoint)->set_eventstate(core::Entity::Normal);
+ track_player->set_mission_target((*track_checkpoint));
}
}
@@ -175,16 +179,13 @@ void RaceTrack::frame(float seconds)
(*track_checkpoint)->set_eventstate(core::Entity::NoPower);
track_checkpoint++;
(*track_checkpoint)->set_eventstate(core::Entity::Normal);
+ track_player->set_mission_target((*track_checkpoint));
} else {
std::stringstream msgstr;
msgstr << "^BRace completed in " << core::server()->time() - track_racestart << " seconds!";
core::server()->broadcast(msgstr.str());
- track_player = 0;
- track_racestart = 0;
- track_checkpointtime = 0;
-
reset();
}
}
diff --git a/src/game/ship.cc b/src/game/ship.cc
index 0dde90e..1828172 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -118,7 +118,7 @@ void Ship::jump(std::string const &args)
return;
}
- core::server()->send(owner(), "Jumping to '" + jumptargetzone->name() + '\'');
+ core::server()->send(owner(), "Jumping to the " + jumptargetzone->name());
set_zone(jumptargetzone);
if (owner()->control() == (EntityControlable*) this)
owner()->set_zone(jumptargetzone);
@@ -145,6 +145,10 @@ void Ship::jump(std::string const &args)
return;
}
+ if (!find_closest_jumppoint()) {
+ return;
+ }
+
entity_eventstate = core::Entity::JumpInitiate;
if (Game::instance()->g_devel->value()) {
entity_timer = 0;
@@ -157,6 +161,39 @@ void Ship::jump(std::string const &args)
}
}
+JumpPoint * Ship::find_closest_jumppoint()
+{
+ // find closest jumppoint
+ float d = -1;
+ JumpPoint *jumppoint = 0;
+ for (core::Zone::Content::iterator it = zone()->content().begin(); it != zone()->content().end(); it++) {
+ core::Entity *entity = (*it);
+ if (entity->moduletype() == jumppoint_enttype) {
+ JumpPoint *te = static_cast<JumpPoint *>(entity);
+ float d1 = math::distance(location(), te->location());
+ if ((d < 0) || (d1 < d)) {
+ d = d1;
+ jumppoint = te;
+ }
+ }
+ }
+
+ if (jumppoint && jumppoint->target()) {
+ if (Game::instance()->g_jumppointrange->value() < d) {
+ core::server()->send(owner(), "Jumppoint out of range!");
+ return 0;
+ } else {
+ core::server()->send(owner(), "Jumping to the " + jumppoint->target()->zone()->name());
+ return jumppoint;
+ }
+ } else {
+ core::server()->send(owner(), "No jumppoints found!");
+ return 0;
+ }
+
+ return 0;
+}
+
void Ship::frame(float seconds)
{
const float direction_change_speed = 2;
@@ -184,29 +221,15 @@ void Ship::frame(float seconds)
entity_timer -= 1.0f;
if (entity_timer <= 0) {
- // find closest jumppoint
- float d = -1;
- JumpPoint *jumppoint = 0;
- for (core::Zone::Content::iterator it = zone()->content().begin(); it != zone()->content().end(); it++) {
- core::Entity *entity = (*it);
- if (entity->moduletype() == jumppoint_enttype) {
- JumpPoint *te = static_cast<JumpPoint *>(entity);
- float d1 = math::distance(location(), te->location());
- if ((d < 0) || (d1 < d1)) {
- d = d1;
- jumppoint = te;
- }
- }
- }
- if (jumppoint && jumppoint->target()) {
- core::server()->send(owner(), "Jumping to '" + jumppoint->target()->zone()->name() + '\'');
+ JumpPoint *jumppoint = find_closest_jumppoint();
+
+ if (jumppoint) {
set_zone(jumppoint->target()->zone());
if (owner()->control() == (EntityControlable*) this)
owner()->set_zone(jumppoint->target()->zone());
entity_eventstate = core::Entity::Jump;
entity_location.assign(jumppoint->target()->location() + location() - jumppoint->location());
} else {
- core::server()->send(owner(), "Jump failed!");
entity_eventstate = core::Entity::Normal;
}
ship_jumpdrive_timer = 0;
diff --git a/src/game/ship.h b/src/game/ship.h
index 568997c..3a62a9d 100644
--- a/src/game/ship.h
+++ b/src/game/ship.h
@@ -49,7 +49,9 @@ private:
bool ship_jumpdrive;
float ship_jumpdrive_timer;
- float ship_impulsedrive_timer;
+ float ship_impulsedrive_timer;
+
+ JumpPoint * find_closest_jumppoint();
};
}