diff options
author | Stijn Buys <ingar@osirion.org> | 2008-09-28 15:05:13 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-09-28 15:05:13 +0000 |
commit | fd778219e40c5fbb4d0af1839cbc313caaf10d9d (patch) | |
tree | b6e413f4c1a5ba4091503ba97c784278485d3933 /src | |
parent | bedcff956d253621ec00aa7d2919c22a4c88b0b2 (diff) |
move base game module to new subdirectory
Diffstat (limited to 'src')
-rw-r--r-- | src/core/application.cc | 2 | ||||
-rw-r--r-- | src/core/gameserver.cc | 5 | ||||
-rw-r--r-- | src/core/module.cc | 70 | ||||
-rw-r--r-- | src/core/module.h | 29 | ||||
-rw-r--r-- | src/game/Makefile.am | 10 | ||||
-rw-r--r-- | src/game/base/Makefile.am | 8 | ||||
-rw-r--r-- | src/game/base/base.cc | 661 | ||||
-rw-r--r-- | src/game/base/base.h | 77 | ||||
-rw-r--r-- | src/game/base/game.cc | 661 | ||||
-rw-r--r-- | src/game/base/jumppoint.cc (renamed from src/game/jumppoint.cc) | 8 | ||||
-rw-r--r-- | src/game/base/jumppoint.h (renamed from src/game/jumppoint.h) | 10 | ||||
-rw-r--r-- | src/game/base/navpoint.cc (renamed from src/game/navpoint.cc) | 8 | ||||
-rw-r--r-- | src/game/base/navpoint.h (renamed from src/game/navpoint.h) | 10 | ||||
-rw-r--r-- | src/game/base/planet.cc (renamed from src/game/planet.cc) | 8 | ||||
-rw-r--r-- | src/game/base/planet.h (renamed from src/game/planet.h) | 10 | ||||
-rw-r--r-- | src/game/base/racetrack.cc (renamed from src/game/racetrack.cc) | 6 | ||||
-rw-r--r-- | src/game/base/racetrack.h (renamed from src/game/racetrack.h) | 10 | ||||
-rw-r--r-- | src/game/base/ship.cc (renamed from src/game/ship.cc) | 30 | ||||
-rw-r--r-- | src/game/base/ship.h (renamed from src/game/ship.h) | 14 | ||||
-rw-r--r-- | src/game/base/shipmodel.cc (renamed from src/game/shipmodel.cc) | 6 | ||||
-rw-r--r-- | src/game/base/shipmodel.h (renamed from src/game/shipmodel.h) | 10 | ||||
-rw-r--r-- | src/game/base/star.cc (renamed from src/game/star.cc) | 8 | ||||
-rw-r--r-- | src/game/base/star.h (renamed from src/game/star.h) | 10 | ||||
-rw-r--r-- | src/game/game.cc | 653 | ||||
-rw-r--r-- | src/game/game.h | 68 | ||||
-rw-r--r-- | src/game/intro/Makefile.am | 2 | ||||
-rw-r--r-- | src/osirion.cc | 7 | ||||
-rw-r--r-- | src/osiriond.cc | 5 |
28 files changed, 1584 insertions, 822 deletions
diff --git a/src/core/application.cc b/src/core/application.cc index 6207a0d..f8b9a73 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -251,6 +251,8 @@ void Application::shutdown() save_config(); + Module::clear(); + // remove our engine functions Func::remove("say"); Func::remove("help"); diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index f251b75..e086096 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -114,7 +114,7 @@ GameServer::GameServer() : GameInterface() server_frametime = 0.0f; server_maxplayerid = 1; - server_module = Module::preload(); + server_module = Module::current(); if (!server_module) { con_error << "No module loaded.\n"; abort(); @@ -199,9 +199,6 @@ GameServer::~GameServer() player_disconnect(localplayer()); server_module->shutdown(); - - if (server_module != Module::preload()) - delete server_module; } Func::remove("kick"); diff --git a/src/core/module.cc b/src/core/module.cc index 447e2b3..89bc2fe 100644 --- a/src/core/module.cc +++ b/src/core/module.cc @@ -5,36 +5,82 @@ */ #include "core/module.h" +#include "sys/sys.h" namespace core { +/*-- static functions ----------------------------------------------*/ + Module *Module::module_preload = 0; +Module::Registry Module::module_registry; -Module::Module(const char *name) : - module_name(name) +Module *Module::find(std::string const &name) { - module_running = false; + Registry::iterator it = module_registry.find(name); + if (it == module_registry.end()) + return 0; + else + return (*it).second; } -Module::~Module() +Module *Module::find(const char *name) { - module_running = false; - module_name.clear(); + return(find(std::string(name))); } - -void Module::load(Module *module) +Module *Module::add(const char *name, Module *module) { + Module *m = find(name); + if (m) { + con_warn << "module '" << name << "' already loaded!" << std::endl; + delete module; + return 0; + } + module_registry[std::string(name)] = module; + if (!module_preload) { + module_preload = module; + con_debug << " " << name << " " << module->name() << std::endl; + } + return module; +} + +Module *Module::load(const char *name) +{ + Module *module = find(name); + if (!module) { + con_warn << "could not find module '" << name << "'" << std::endl; + return 0; + } + + con_debug << " " << name << " " << module->name() << std::endl; module_preload = module; + return module; } -void Module::unload() +void Module::clear() { - if (module_preload) { - delete module_preload; - module_preload = 0; + for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) { + Module *module = (*it).second; + delete module; } + + module_registry.clear(); + module_preload = 0; +} + +/*-- instance functions --------------------------------------------*/ + +Module::Module(const char *name) : + module_name(name) +{ + module_running = false; +} + +Module::~Module() +{ + module_running = false; + module_name.clear(); } void Module::abort() diff --git a/src/core/module.h b/src/core/module.h index 61dc0dc..bd99034 100644 --- a/src/core/module.h +++ b/src/core/module.h @@ -49,23 +49,38 @@ public: /*----- static ---------------------------------------------------- */ - /// load a game module - static void load(Module *module); + typedef std::map<std::string, Module *> Registry; - /// unload the preloaded module - static void unload(); + /// find a registered game module + static Module *find(const char *name); + + /// find a registered game module + static Module *find(std::string const &name); - /// the preloaded module - inline static Module *preload() { return module_preload; }; + /// register a game module + static Module *add(const char *name, Module *module); + + /// load a registered game module + static Module *load(const char *name); + + /// unload all modules + static void clear(); + + /// currently loaded module + static inline Module *current() { return module_preload; } protected: /// set the disconnected state void abort(); + bool module_running; private: - static Module *module_preload; std::string module_name; + + static Module *module_preload; + + static Registry module_registry; }; } diff --git a/src/game/Makefile.am b/src/game/Makefile.am index ff591eb..91838e6 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -1,10 +1,10 @@ -INCLUDES = -I$(top_srcdir)/src +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game METASOURCES = AUTO libgame_la_LDFLAGS = -avoid-version -libgame_la_SOURCES = game.cc jumppoint.cc navpoint.cc planet.cc racetrack.cc \ - ship.cc shipmodel.cc star.cc +libgame_la_SOURCES = game.cc noinst_LTLIBRARIES = libgame.la -noinst_HEADERS = game.h navpoint.h planet.h racetrack.h ship.h shipmodel.h \ - star.h jumppoint.h +noinst_HEADERS = game.h +SUBDIRS = base intro +libgame_la_LIBADD = $(top_builddir)/src/game/base/libbase.la diff --git a/src/game/base/Makefile.am b/src/game/base/Makefile.am new file mode 100644 index 0000000..a8258b2 --- /dev/null +++ b/src/game/base/Makefile.am @@ -0,0 +1,8 @@ +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/game +METASOURCES = AUTO +libbase_la_LDFLAGS = -avoid-version +noinst_LTLIBRARIES = libbase.la +libbase_la_SOURCES = base.cc jumppoint.cc navpoint.cc planet.cc racetrack.cc \ + ship.cc shipmodel.cc star.cc +noinst_HEADERS = base.h jumppoint.h navpoint.h planet.h racetrack.h ship.h \ + shipmodel.h star.h diff --git a/src/game/base/base.cc b/src/game/base/base.cc new file mode 100644 index 0000000..70d9335 --- /dev/null +++ b/src/game/base/base.cc @@ -0,0 +1,661 @@ +/* + base/base.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include <vector> +#include <string> + +#include "auxiliary/functions.h" +#include "core/gameserver.h" +#include "filesystem/filesystem.h" +#include "filesystem/inifile.h" +#include "base/base.h" +#include "base/navpoint.h" +#include "base/jumppoint.h" +#include "base/planet.h" +#include "base/racetrack.h" +#include "base/ship.h" +#include "base/star.h" +#include "math/mathlib.h" +#include "sys/sys.h" + +namespace base +{ + +ShipModel *default_shipmodel = 0; +core::Zone *default_zone = 0; + +/*----- engine game functions ------------------------------------- */ + +/// list the ship model registry +void func_list_ship(std::string const &args) +{ + ShipModel::list(); +} + +/// a player joins the game +void func_join(core::Player *player, std::string const &args) +{ + if (player->control()) + return; + + player->set_zone(default_zone); + Ship *ship = new Ship(player, default_shipmodel); + ship->set_zone(default_zone); + player->set_control(ship); + + core::server()->send_sound(player, "game/buy-ship"); + + std::string message("^B"); + message.append(player->name()); + message.append("^B joins the game."); + core::server()->broadcast(message); + + player->player_dirty = true; +} + +/// a player joins the spectators +void func_spectate(core::Player *player, std::string const &args) +{ + if (!player->control()) + return; + + std::string message("^B"); + message.append(player->name()); + message.append("^B spectates."); + core::server()->broadcast(message); + + if (player->control()) { + player->remove_asset(player->control()); + } +} + +/// a player buys a ship +void func_buy(core::Player *player, std::string const &args) +{ + + std::string shipname; + std::string helpstr; + std::istringstream is(args); + is >> shipname; + aux::to_lowercase(shipname); + + ShipModel *shipmodel = 0; + for (ShipModel::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { + if (shipname == (*smit).first) { + shipmodel = (*smit).second; + break; + } + + if (helpstr.size()) + helpstr.append("^N|^B"); + helpstr.append((*smit).second->label()); + } + + if (shipmodel) { + // player has only ship for now + if (player->control()) { + player->remove_asset(player->control()); + } + + Ship * ship = new Ship(player, shipmodel); + if (player->zone()) { + ship->set_zone(player->zone()); + } else { + ship->set_zone(default_zone); + } + player->set_control(ship); + + core::server()->broadcast("^B" + player->name() + " ^Bpurchased " + aux::article(shipmodel->name())); + core::server()->send_sound(player, "game/buy-ship"); + + } else { + core::server()->send(player, "Usage: buy [^B" + helpstr + "^N]"); + } +} + +/// a player sends standard hails +void func_hail(core::Player *player, std::string const &args) +{ + std::string target; + std::istringstream is(args); + if (!(is >> target)) { + core::server()->send(player, "Usage: hail [player]"); + return; + } + + core::Player *targetplayer = core::server()->find_player(target); + if (!targetplayer) { + core::server()->send(player, "^BPlayer " + target + "^B not found."); + return; + } + + core::server()->send(player, "^BYou hail " + targetplayer->name() + "^B."); + core::server()->send_sound(player, "com/hail"); + + core::server()->send(targetplayer, "^B" + player->name() + "^B hails you!"); + core::server()->send_sound(targetplayer, "com/hail"); +} + +/// a player actives the hyperspace jump drive on his ship +void func_jump(core::Player *player, std::string const &args) +{ + if (!player->control()) + return; + if (!player->control()->moduletype() == ship_enttype) + return; + Ship * ship = static_cast<Ship *>(player->control()); + ship->jump(args); +} + +/// a player actives the kinetic impulse drive on his ship +void func_impulse(core::Player *player, std::string const &args) +{ + if (!player->control()) + return; + if (!player->control()->moduletype() == ship_enttype) + return; + Ship * ship = static_cast<Ship *>(player->control()); + ship->impulse(); +} + +/* ---- The Game class --------------------------------------------- */ + +Base *Base::game_instance = 0; + +Base::Base() : core::Module("Project::OSiRiON") +{ + game_instance = this; + g_impulsespeed = 0; +} + +Base::~Base() +{ + game_instance = 0; +} + +void Base::init() +{ + module_running = false; + + ShipModel::clear(); + + if (!load_world()) { + abort(); + return; + } + + if (!load_ships()) { + abort(); + return; + } + + // add engine game functions + core::Func *func = 0; + + func = core::Func::add("join", (core::GameFuncPtr) func_join); + func->set_info("join the game"); + func = core::Func::add("hail", (core::GameFuncPtr) func_hail); + func->set_info("send a standard hail"); + func = core::Func::add("spectate", (core::GameFuncPtr) func_spectate); + func->set_info("leave the game and spectate"); + + func = core::Func::add("buy", (core::GameFuncPtr) func_buy); + func->set_info("buy a ship"); + + func = core::Func::add("jump", (core::GameFuncPtr) func_jump); + func->set_info("[string] activate or deactivate hyperspace jump drive"); + + func = core::Func::add("impulse", (core::GameFuncPtr) func_impulse); + func->set_info("activate are deactive kinetic impulse drive"); + + // add engine core functions + func = core::Func::add("list_ship", (core::FuncPtr) func_list_ship); + func->set_info("list ship statistics"); + + g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive); + g_impulsespeed->set_info("[float] speed of the impulse drive"); + + g_impulseacceleration = core::Cvar::get("g_impulseacceleration", "5", core::Cvar::Game | core::Cvar::Archive); + g_impulseacceleration->set_info("[float] acceleration of the impulse drive"); + + 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"); + + // indicate the module is ready to run frames + module_running = true; +} + +void Base::shutdown() +{ + g_impulsespeed = 0; + // game functions are automaticly removed + + // remove engine core functions + core::Func::remove("list_ship"); + + ShipModel::clear(); + module_running = false; +} + +bool Base::load_world() +{ + std::string inifilename("world"); + + filesystem::IniFile worldini; + worldini.open(inifilename); + + if (!worldini.is_open()) { + con_error << "Could not open " << worldini.name() << std::endl; + return false; + } + + core::Zone *zone = 0; + std::string label; + + while (worldini.getline()) { + + if (worldini.got_section()) { + + if (worldini.got_section("world")) { + continue; + } else { + con_warn << worldini.name() << " unknown section '" << worldini.section() << "' at line " << worldini.line() << std::endl; + } + + } else if (worldini.section().compare("world") == 0 ) { + if (worldini.got_key_string("zone", label)) { + aux::to_label(label); + zone = new core::Zone(label); + core::Zone::add(zone); + } + } + } + worldini.close(); + + if (!core::Zone::registry().size()) { + con_error << "No zones found!" << std::endl; + return false; + } + + con_debug << " " << worldini.name() << " " << core::Zone::registry().size() << " zones" << std::endl; + + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { + if (!load_zone((*it).second)) { + return false; + } + } + + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { + if (!validate_zone((*it).second)) { + return false; + } + } + + if (!default_zone) { + con_error << "No default zone found!" << std::endl; + return false; + } + + return true; +} + +bool Base::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 Base::load_zone(core::Zone *zone) +{ + using math::Vector3f; + using math::Color; + + std::string inifilename("zones/"); + inifilename.append(zone->label()); + + filesystem::IniFile zoneini; + zoneini.open(inifilename); + + if (!zoneini.is_open()) { + con_error << "Could not open " << zoneini.name() << std::endl; + return false; + } + + size_t count = 0; + + Planet *planet = 0; + Star *star = 0; + NavPoint *navpoint = 0; + JumpPoint *jumppoint = 0; + RaceTrack *racetrack = 0; + CheckPoint *checkpoint = 0; + core::Entity *entity = 0; + + bool b; + + std::string strval; + + // set th default sky + zone->set_sky("sky"); + + while (zoneini.getline()) { + 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)) { + zone->set_sky(strval); + continue; + } else if (zoneini.got_key_bool("default", b)) { + if (b) default_zone = zone; + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } else if (zoneini.section().compare("star") == 0) { + if (got_entity_key(zoneini, star)) { + continue; + } else if (zoneini.got_key_string("texture", star->entity_texture)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } else if (zoneini.section().compare("navpoint") == 0) { + 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 (got_entity_key(zoneini, jumppoint)) { + continue; + } else if (zoneini.got_key_string("target", jumppoint->jumppoint_targetlabel)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } else if (zoneini.section().compare("planet") == 0) { + if (got_entity_key(zoneini, planet)) { + continue; + } else if (zoneini.got_key_string("texture", planet->entity_texture)) { + continue; + } else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + + } else if (zoneini.section().compare("racetrack") == 0) { + 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 (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) { + if (got_entity_key(zoneini, entity)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } + } else if (zoneini.got_section("zone")) { + continue; + + } else if (zoneini.got_section("star")) { + star = new Star(); + star->set_zone(zone); + count ++; + + } else if (zoneini.got_section("navpoint")) { + navpoint = new NavPoint(); + navpoint->set_zone(zone); + count ++; + + } else if (zoneini.got_section("jumppoint")) { + jumppoint = new JumpPoint(); + jumppoint->set_zone(zone); + count ++; + + } else if(zoneini.got_section("racetrack")) { + racetrack = new RaceTrack(); + racetrack->set_zone(zone); + + } else if(zoneini.got_section("checkpoint")) { + checkpoint = new CheckPoint(racetrack); + if (!racetrack) { + con_warn << zoneini.name() << " checkpoint without racetrack at line " << zoneini.line() << std::endl; + } + + } else if (zoneini.got_section("planet")) { + planet = new Planet(); + planet->set_zone(zone); + count ++; + + } else if (zoneini.got_section("entity")) { + entity = new core::Entity(); + entity->entity_flags += core::Entity::Static; + entity->set_zone(zone); + count ++; + + } else if (zoneini.got_section()) { + con_warn << zoneini.name() << " unknown section '" << zoneini.section() << "' at line " << zoneini.line() << std::endl; + } + } + zoneini.close(); + + con_debug << " " << zoneini.name() << " " << zone->content().size() << " entities" << std::endl; + + + return true; +} + +bool Base::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); + + if (entity->entity_moduletypeid == jumppoint_enttype) { + JumpPoint *jumppoint = static_cast<JumpPoint *>(entity); + + if (jumppoint->targetlabel().size() < 3) { + con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; + continue; + } + size_t pos = jumppoint->targetlabel().find(':'); + if ((pos < 1 ) || (pos >= (jumppoint->targetlabel().size()-1))) { + con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; + continue; + } + + std::string zonelabel(jumppoint->targetlabel().substr(0, pos)); + std::string entitylabel(jumppoint->targetlabel().substr(pos+1, jumppoint->targetlabel().size()-pos)); + + core::Zone *targetzone = core::Zone::find(zonelabel); + if (!targetzone) { + con_warn << " Jumppoint with invalid target zone '" << zonelabel << "'\n"; + continue; + } + + core::Entity *targetentity = targetzone->find_entity(entitylabel); + if (!targetentity) { + con_warn << " Could not find target jumppoint '" << entitylabel << "'\n"; + continue; + } + + if (targetentity->moduletype() != jumppoint_enttype) { + con_warn << " Jumppoint with invalid target jumppoint '" << entitylabel << "'\n"; + continue; + } + + jumppoint->jumppoint_target = static_cast<JumpPoint *>(targetentity); + + //con_debug << " Jumppoint " << zone->label() << ":" << jumppoint->label() << " with target " << jumppoint->targetlabel() << std::endl; + } + } + + return true; +} + +// read ship model specifications +bool Base::load_ships() +{ + using math::Vector3f; + using math::Color; + + default_shipmodel = 0; + + filesystem::IniFile shipsini; + shipsini.open("ships"); + if (!shipsini.is_open()) { + con_error << "Could not open ini/ships.ini!" << std::endl; + return false; + } + + ShipModel *shipmodel = 0; + std::string label; + bool b; + + while (shipsini.getline()) { + if (shipsini.got_key()) { + if (shipsini.section().compare("ship") == 0) { + if (shipsini.got_key_string("label", label)) { + aux::to_label(label); + shipmodel->shipmodel_label.assign(label); + ShipModel::add(shipmodel); + continue; + } else if (shipsini.got_key_string("name",shipmodel->shipmodel_name)) { + continue; + } else if (shipsini.got_key_string("model", shipmodel->shipmodel_modelname)) { + continue; + } else if (shipsini.got_key_bool("default", b)) { + if (b) default_shipmodel = shipmodel; + continue; + } else if (shipsini.got_key_bool("jumpdrive", shipmodel->shipmodel_jumpdrive)) { + continue; + } else if (shipsini.got_key_float("acceleration", shipmodel->shipmodel_acceleration)) { + continue; + } else if (shipsini.got_key_float("maxspeed", shipmodel->shipmodel_maxspeed)) { + continue; + } else if (shipsini.got_key_float("turnspeed", shipmodel->shipmodel_turnspeed)) { + math::clamp(shipmodel->shipmodel_turnspeed, 0.0f, 90.0f); + continue; + } else { + con_warn << shipsini.name() << " unknown key '" << shipsini.key() << "' at line " << shipsini.line() << std::endl; + } + } + } else if (shipsini.got_section("ship")) { + shipmodel = new ShipModel(); + + if (!default_shipmodel) + default_shipmodel = shipmodel; + + } else if (shipsini.got_section()) { + con_warn << shipsini.name() << " unknown section '" << shipsini.section() << "' at line " << shipsini.line() << std::endl; + } + } + shipsini.close(); + + con_debug << " " << shipsini.name() << " " << ShipModel::registry.size() << " ship models" << std::endl; + + if (!default_shipmodel) { + con_error << "No default ship model found!\n"; + return false; + } + + return true; +} + +void Base::frame(float seconds) +{ + if (!running()) + return; +} + +void Base::player_connect(core::Player *player) +{ + std::string args; + player->set_zone(default_zone); + func_spectate(player, args); +} + +void Base::player_disconnect(core::Player *player) +{ + player->remove_asset(player->control()); +} + +} // namespace game + diff --git a/src/game/base/base.h b/src/game/base/base.h new file mode 100644 index 0000000..fea1919 --- /dev/null +++ b/src/game/base/base.h @@ -0,0 +1,77 @@ +/* + game/game.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_BASE_H__ +#define __INCLUDED_BASE_H__ + +#include <vector> +#include <string> + +#include "base/ship.h" +#include "base/star.h" +#include "core/core.h" +#include "filesystem/inifile.h" +#include "sys/sys.h" + +/// the base game module +/** the base game module containis the game-specific code for Project::Osirion + */ +namespace base +{ + +// entity type constants +const unsigned int ship_enttype = 256; +const unsigned int star_enttype = 257; +const unsigned int planet_enttype = 258; +const unsigned int navpoint_enttype = 259; +const unsigned int jumppoint_enttype = 260; + +class Base : public core::Module { +public: + Base(); + ~Base(); + + /// initialize the game + void init(); + + /// shutdown the game + void shutdown(); + + /// run one time frame + void frame(float seconds); + + /// is called when a player connects + void player_connect(core::Player *player); + + /// is called when a player disconnects + void player_disconnect(core::Player *player); + + static inline Base *instance() { return game_instance; } + + 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); + + bool validate_zone(core::Zone *zone); + + bool load_ships(); + + static Base *game_instance; +}; + +} + +#endif // __INCLUDED_BASE_H__ + diff --git a/src/game/base/game.cc b/src/game/base/game.cc new file mode 100644 index 0000000..4d66cbe --- /dev/null +++ b/src/game/base/game.cc @@ -0,0 +1,661 @@ +/* + game/game.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include <vector> +#include <string> + +#include "auxiliary/functions.h" +#include "core/gameserver.h" +#include "filesystem/filesystem.h" +#include "filesystem/inifile.h" +#include "game/game.h" +#include "game/navpoint.h" +#include "game/jumppoint.h" +#include "game/planet.h" +#include "game/racetrack.h" +#include "game/ship.h" +#include "game/star.h" +#include "math/mathlib.h" +#include "sys/sys.h" + +namespace game +{ + +ShipModel *default_shipmodel = 0; +core::Zone *default_zone = 0; + +/*----- engine game functions ------------------------------------- */ + +/// list the ship model registry +void func_list_ship(std::string const &args) +{ + ShipModel::list(); +} + +/// a player joins the game +void func_join(core::Player *player, std::string const &args) +{ + if (player->control()) + return; + + player->set_zone(default_zone); + Ship *ship = new Ship(player, default_shipmodel); + ship->set_zone(default_zone); + player->set_control(ship); + + core::server()->send_sound(player, "game/buy-ship"); + + std::string message("^B"); + message.append(player->name()); + message.append("^B joins the game."); + core::server()->broadcast(message); + + player->player_dirty = true; +} + +/// a player joins the spectators +void func_spectate(core::Player *player, std::string const &args) +{ + if (!player->control()) + return; + + std::string message("^B"); + message.append(player->name()); + message.append("^B spectates."); + core::server()->broadcast(message); + + if (player->control()) { + player->remove_asset(player->control()); + } +} + +/// a player buys a ship +void func_buy(core::Player *player, std::string const &args) +{ + + std::string shipname; + std::string helpstr; + std::istringstream is(args); + is >> shipname; + aux::to_lowercase(shipname); + + ShipModel *shipmodel = 0; + for (ShipModel::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { + if (shipname == (*smit).first) { + shipmodel = (*smit).second; + break; + } + + if (helpstr.size()) + helpstr.append("^N|^B"); + helpstr.append((*smit).second->label()); + } + + if (shipmodel) { + // player has only ship for now + if (player->control()) { + player->remove_asset(player->control()); + } + + Ship * ship = new Ship(player, shipmodel); + if (player->zone()) { + ship->set_zone(player->zone()); + } else { + ship->set_zone(default_zone); + } + player->set_control(ship); + + core::server()->broadcast("^B" + player->name() + " ^Bpurchased " + aux::article(shipmodel->name())); + core::server()->send_sound(player, "game/buy-ship"); + + } else { + core::server()->send(player, "Usage: buy [^B" + helpstr + "^N]"); + } +} + +/// a player sends standard hails +void func_hail(core::Player *player, std::string const &args) +{ + std::string target; + std::istringstream is(args); + if (!(is >> target)) { + core::server()->send(player, "Usage: hail [player]"); + return; + } + + core::Player *targetplayer = core::server()->find_player(target); + if (!targetplayer) { + core::server()->send(player, "^BPlayer " + target + "^B not found."); + return; + } + + core::server()->send(player, "^BYou hail " + targetplayer->name() + "^B."); + core::server()->send_sound(player, "com/hail"); + + core::server()->send(targetplayer, "^B" + player->name() + "^B hails you!"); + core::server()->send_sound(targetplayer, "com/hail"); +} + +/// a player actives the hyperspace jump drive on his ship +void func_jump(core::Player *player, std::string const &args) +{ + if (!player->control()) + return; + if (!player->control()->moduletype() == ship_enttype) + return; + Ship * ship = static_cast<Ship *>(player->control()); + ship->jump(args); +} + +/// a player actives the kinetic impulse drive on his ship +void func_impulse(core::Player *player, std::string const &args) +{ + if (!player->control()) + return; + if (!player->control()->moduletype() == ship_enttype) + return; + Ship * ship = static_cast<Ship *>(player->control()); + ship->impulse(); +} + +/* ---- The Game class --------------------------------------------- */ + +Game *Game::game_instance = 0; + +Game::Game() : core::Module("Project::OSiRiON") +{ + game_instance = this; + g_impulsespeed = 0; +} + +Game::~Game() +{ + game_instance = 0; +} + +void Game::init() +{ + module_running = false; + + ShipModel::clear(); + + if (!load_world()) { + abort(); + return; + } + + if (!load_ships()) { + abort(); + return; + } + + // add engine game functions + core::Func *func = 0; + + func = core::Func::add("join", (core::GameFuncPtr) func_join); + func->set_info("join the game"); + func = core::Func::add("hail", (core::GameFuncPtr) func_hail); + func->set_info("send a standard hail"); + func = core::Func::add("spectate", (core::GameFuncPtr) func_spectate); + func->set_info("leave the game and spectate"); + + func = core::Func::add("buy", (core::GameFuncPtr) func_buy); + func->set_info("buy a ship"); + + func = core::Func::add("jump", (core::GameFuncPtr) func_jump); + func->set_info("[string] activate or deactivate hyperspace jump drive"); + + func = core::Func::add("impulse", (core::GameFuncPtr) func_impulse); + func->set_info("activate are deactive kinetic impulse drive"); + + // add engine core functions + func = core::Func::add("list_ship", (core::FuncPtr) func_list_ship); + func->set_info("list ship statistics"); + + g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive); + g_impulsespeed->set_info("[float] speed of the impulse drive"); + + g_impulseacceleration = core::Cvar::get("g_impulseacceleration", "5", core::Cvar::Game | core::Cvar::Archive); + g_impulseacceleration->set_info("[float] acceleration of the impulse drive"); + + 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"); + + // indicate the module is ready to run frames + module_running = true; +} + +void Game::shutdown() +{ + g_impulsespeed = 0; + // game functions are automaticly removed + + // remove engine core functions + core::Func::remove("list_ship"); + + ShipModel::clear(); + module_running = false; +} + +bool Game::load_world() +{ + std::string inifilename("world"); + + filesystem::IniFile worldini; + worldini.open(inifilename); + + if (!worldini.is_open()) { + con_error << "Could not open " << worldini.name() << std::endl; + return false; + } + + core::Zone *zone = 0; + std::string label; + + while (worldini.getline()) { + + if (worldini.got_section()) { + + if (worldini.got_section("world")) { + continue; + } else { + con_warn << worldini.name() << " unknown section '" << worldini.section() << "' at line " << worldini.line() << std::endl; + } + + } else if (worldini.section().compare("world") == 0 ) { + if (worldini.got_key_string("zone", label)) { + aux::to_label(label); + zone = new core::Zone(label); + core::Zone::add(zone); + } + } + } + worldini.close(); + + if (!core::Zone::registry().size()) { + con_error << "No zones found!" << std::endl; + return false; + } + + con_debug << " " << worldini.name() << " " << core::Zone::registry().size() << " zones" << std::endl; + + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { + if (!load_zone((*it).second)) { + return false; + } + } + + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { + if (!validate_zone((*it).second)) { + return false; + } + } + + if (!default_zone) { + con_error << "No default zone found!" << std::endl; + return false; + } + + 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; + using math::Color; + + std::string inifilename("zones/"); + inifilename.append(zone->label()); + + filesystem::IniFile zoneini; + zoneini.open(inifilename); + + if (!zoneini.is_open()) { + con_error << "Could not open " << zoneini.name() << std::endl; + return false; + } + + size_t count = 0; + + Planet *planet = 0; + Star *star = 0; + NavPoint *navpoint = 0; + JumpPoint *jumppoint = 0; + RaceTrack *racetrack = 0; + CheckPoint *checkpoint = 0; + core::Entity *entity = 0; + + bool b; + + std::string strval; + + // set th default sky + zone->set_sky("sky"); + + while (zoneini.getline()) { + 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)) { + zone->set_sky(strval); + continue; + } else if (zoneini.got_key_bool("default", b)) { + if (b) default_zone = zone; + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } else if (zoneini.section().compare("star") == 0) { + if (got_entity_key(zoneini, star)) { + continue; + } else if (zoneini.got_key_string("texture", star->entity_texture)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } else if (zoneini.section().compare("navpoint") == 0) { + 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 (got_entity_key(zoneini, jumppoint)) { + continue; + } else if (zoneini.got_key_string("target", jumppoint->jumppoint_targetlabel)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } else if (zoneini.section().compare("planet") == 0) { + if (got_entity_key(zoneini, planet)) { + continue; + } else if (zoneini.got_key_string("texture", planet->entity_texture)) { + continue; + } else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + + } else if (zoneini.section().compare("racetrack") == 0) { + 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 (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) { + if (got_entity_key(zoneini, entity)) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } + } + } else if (zoneini.got_section("zone")) { + continue; + + } else if (zoneini.got_section("star")) { + star = new Star(); + star->set_zone(zone); + count ++; + + } else if (zoneini.got_section("navpoint")) { + navpoint = new NavPoint(); + navpoint->set_zone(zone); + count ++; + + } else if (zoneini.got_section("jumppoint")) { + jumppoint = new JumpPoint(); + jumppoint->set_zone(zone); + count ++; + + } else if(zoneini.got_section("racetrack")) { + racetrack = new RaceTrack(); + racetrack->set_zone(zone); + + } else if(zoneini.got_section("checkpoint")) { + checkpoint = new CheckPoint(racetrack); + if (!racetrack) { + con_warn << zoneini.name() << " checkpoint without racetrack at line " << zoneini.line() << std::endl; + } + + } else if (zoneini.got_section("planet")) { + planet = new Planet(); + planet->set_zone(zone); + count ++; + + } else if (zoneini.got_section("entity")) { + entity = new core::Entity(); + entity->entity_flags += core::Entity::Static; + entity->set_zone(zone); + count ++; + + } else if (zoneini.got_section()) { + con_warn << zoneini.name() << " unknown section '" << zoneini.section() << "' at line " << zoneini.line() << std::endl; + } + } + zoneini.close(); + + con_debug << " " << zoneini.name() << " " << zone->content().size() << " entities" << std::endl; + + + return true; +} + +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); + + if (entity->entity_moduletypeid == jumppoint_enttype) { + JumpPoint *jumppoint = static_cast<JumpPoint *>(entity); + + if (jumppoint->targetlabel().size() < 3) { + con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; + continue; + } + size_t pos = jumppoint->targetlabel().find(':'); + if ((pos < 1 ) || (pos >= (jumppoint->targetlabel().size()-1))) { + con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; + continue; + } + + std::string zonelabel(jumppoint->targetlabel().substr(0, pos)); + std::string entitylabel(jumppoint->targetlabel().substr(pos+1, jumppoint->targetlabel().size()-pos)); + + core::Zone *targetzone = core::Zone::find(zonelabel); + if (!targetzone) { + con_warn << " Jumppoint with invalid target zone '" << zonelabel << "'\n"; + continue; + } + + core::Entity *targetentity = targetzone->find_entity(entitylabel); + if (!targetentity) { + con_warn << " Could not find target jumppoint '" << entitylabel << "'\n"; + continue; + } + + if (targetentity->moduletype() != jumppoint_enttype) { + con_warn << " Jumppoint with invalid target jumppoint '" << entitylabel << "'\n"; + continue; + } + + jumppoint->jumppoint_target = static_cast<JumpPoint *>(targetentity); + + //con_debug << " Jumppoint " << zone->label() << ":" << jumppoint->label() << " with target " << jumppoint->targetlabel() << std::endl; + } + } + + return true; +} + +// read ship model specifications +bool Game::load_ships() +{ + using math::Vector3f; + using math::Color; + + default_shipmodel = 0; + + filesystem::IniFile shipsini; + shipsini.open("ships"); + if (!shipsini.is_open()) { + con_error << "Could not open ini/ships.ini!" << std::endl; + return false; + } + + ShipModel *shipmodel = 0; + std::string label; + bool b; + + while (shipsini.getline()) { + if (shipsini.got_key()) { + if (shipsini.section().compare("ship") == 0) { + if (shipsini.got_key_string("label", label)) { + aux::to_label(label); + shipmodel->shipmodel_label.assign(label); + ShipModel::add(shipmodel); + continue; + } else if (shipsini.got_key_string("name",shipmodel->shipmodel_name)) { + continue; + } else if (shipsini.got_key_string("model", shipmodel->shipmodel_modelname)) { + continue; + } else if (shipsini.got_key_bool("default", b)) { + if (b) default_shipmodel = shipmodel; + continue; + } else if (shipsini.got_key_bool("jumpdrive", shipmodel->shipmodel_jumpdrive)) { + continue; + } else if (shipsini.got_key_float("acceleration", shipmodel->shipmodel_acceleration)) { + continue; + } else if (shipsini.got_key_float("maxspeed", shipmodel->shipmodel_maxspeed)) { + continue; + } else if (shipsini.got_key_float("turnspeed", shipmodel->shipmodel_turnspeed)) { + math::clamp(shipmodel->shipmodel_turnspeed, 0.0f, 90.0f); + continue; + } else { + con_warn << shipsini.name() << " unknown key '" << shipsini.key() << "' at line " << shipsini.line() << std::endl; + } + } + } else if (shipsini.got_section("ship")) { + shipmodel = new ShipModel(); + + if (!default_shipmodel) + default_shipmodel = shipmodel; + + } else if (shipsini.got_section()) { + con_warn << shipsini.name() << " unknown section '" << shipsini.section() << "' at line " << shipsini.line() << std::endl; + } + } + shipsini.close(); + + con_debug << " " << shipsini.name() << " " << ShipModel::registry.size() << " ship models" << std::endl; + + if (!default_shipmodel) { + con_error << "No default ship model found!\n"; + return false; + } + + return true; +} + +void Game::frame(float seconds) +{ + if (!running()) + return; +} + +void Game::player_connect(core::Player *player) +{ + std::string args; + player->set_zone(default_zone); + func_spectate(player, args); +} + +void Game::player_disconnect(core::Player *player) +{ + player->remove_asset(player->control()); +} + +} // namespace game + diff --git a/src/game/jumppoint.cc b/src/game/base/jumppoint.cc index d2c6bc1..bcaf8c5 100644 --- a/src/game/jumppoint.cc +++ b/src/game/base/jumppoint.cc @@ -1,13 +1,13 @@ /* - game/jumppoint.cc + base/jumppoint.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 "game/jumppoint.h" -#include "game/game.h" +#include "base/base.h" +#include "base/jumppoint.h" -namespace game +namespace base { JumpPoint::JumpPoint() : core::Entity(core::Entity::Static) diff --git a/src/game/jumppoint.h b/src/game/base/jumppoint.h index 59ec69c..4680832 100644 --- a/src/game/jumppoint.h +++ b/src/game/base/jumppoint.h @@ -1,18 +1,18 @@ /* - game/jumppoint.h + base/jumppoint.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_GAME_JUMPPOINT_H__ -#define __INCLUDED_GAME_JUMPPOINT_H__ +#ifndef __INCLUDED_BASE_JUMPPOINT_H__ +#define __INCLUDED_BASE_JUMPPOINT_H__ #include "core/entity.h" #include "math/mathlib.h" #include <string> -namespace game { +namespace base { /// a jump point /** @@ -36,5 +36,5 @@ public: } -#endif // __INCLUDED_GAME_JUMPPOINT_H__ +#endif // __INCLUDED_BASE_JUMPPOINT_H__ diff --git a/src/game/navpoint.cc b/src/game/base/navpoint.cc index 24e87ca..560962c 100644 --- a/src/game/navpoint.cc +++ b/src/game/base/navpoint.cc @@ -1,13 +1,13 @@ /* - game/navpoint.cc + base/navpoint.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 "game/navpoint.h" -#include "game/game.h" +#include "base/navpoint.h" +#include "base/base.h" -namespace game +namespace base { NavPoint::NavPoint() : core::Entity(core::Entity::Static | core::Entity::Bright) diff --git a/src/game/navpoint.h b/src/game/base/navpoint.h index ef60267..7ea505d 100644 --- a/src/game/navpoint.h +++ b/src/game/base/navpoint.h @@ -1,18 +1,18 @@ /* - game/navpoint.h + base/navpoint.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_GAME_NAVPOINT_H__ -#define __INCLUDED_GAME_NAVPOINT_H__ +#ifndef __INCLUDED_BASE_NAVPOINT_H__ +#define __INCLUDED_BASE_NAVPOINT_H__ #include "core/entity.h" #include "math/mathlib.h" #include <string> -namespace game { +namespace base { /// a navigation point class NavPoint : public core::Entity { @@ -23,5 +23,5 @@ public: } -#endif // __INCLUDED_GAME_NAVPOINT_H__ +#endif // __INCLUDED_BASE_NAVPOINT_H__ diff --git a/src/game/planet.cc b/src/game/base/planet.cc index 80e4922..83f3d65 100644 --- a/src/game/planet.cc +++ b/src/game/base/planet.cc @@ -1,14 +1,14 @@ /* - game/planet.cc + base/planet.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2. */ -#include "game/game.h" -#include "game/planet.h" +#include "base/base.h" +#include "base/planet.h" -namespace game { +namespace base { Planet::Planet() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid) { diff --git a/src/game/planet.h b/src/game/base/planet.h index cc258c9..005157d 100644 --- a/src/game/planet.h +++ b/src/game/base/planet.h @@ -1,18 +1,18 @@ /* - game/planet.h + base/planet.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_GAME_PLANET_H__ -#define __INCLUDED_GAME_PLANET_H__ +#ifndef __INCLUDED_BASE_PLANET_H__ +#define __INCLUDED_BASE_PLANET_H__ #include "core/entity.h" #include "math/mathlib.h" #include <string> -namespace game { +namespace base { /// a planet class Planet : public core::EntityGlobe { @@ -23,5 +23,5 @@ public: } -#endif // __INCLUDED_GAME_PLANET_H__ +#endif // __INCLUDED_BASE_PLANET_H__ diff --git a/src/game/racetrack.cc b/src/game/base/racetrack.cc index cfacb82..ee2ecc7 100644 --- a/src/game/racetrack.cc +++ b/src/game/base/racetrack.cc @@ -1,5 +1,5 @@ /* - game/racetrack.cc + base/racetrack.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 */ @@ -7,10 +7,10 @@ #include <string> #include <sstream> -#include "game/racetrack.h" +#include "base/racetrack.h" #include "core/gameserver.h" -namespace game { +namespace base { /* ---- class CheckPoint ------------------------------------------- */ diff --git a/src/game/racetrack.h b/src/game/base/racetrack.h index 733051a..b5b5dad 100644 --- a/src/game/racetrack.h +++ b/src/game/base/racetrack.h @@ -1,11 +1,11 @@ /* - game/racetrack.h + base/racetrack.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_GAME_RACETRACK_H__ -#define __INCLUDED_GAME_RACETRACK_H__ +#ifndef __INCLUDED_BASE_RACETRACK_H__ +#define __INCLUDED_BASE_RACETRACK_H__ #include "core/entity.h" #include "core/player.h" @@ -13,7 +13,7 @@ #include <string> -namespace game { +namespace base { class CheckPoint; @@ -59,5 +59,5 @@ private: } -#endif // __INCLUDED_GAME_NAVPOINT_H__ +#endif // __INCLUDED_BASE_NAVPOINT_H__ diff --git a/src/game/ship.cc b/src/game/base/ship.cc index 1828172..0fdfd3f 100644 --- a/src/game/ship.cc +++ b/src/game/base/ship.cc @@ -1,5 +1,5 @@ /* - game/ship.cc + base/ship.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 */ @@ -10,8 +10,8 @@ #include "auxiliary/functions.h" #include "core/gameserver.h" #include "core/entity.h" -#include "game/game.h" -#include "game/ship.h" +#include "base/base.h" +#include "base/ship.h" #include "math/functions.h" @@ -19,7 +19,7 @@ using math::degrees360f; using math::degrees180f; -namespace game { +namespace base { const float MIN_DELTA = 0.000001f; @@ -73,7 +73,7 @@ void Ship::impulse() } entity_eventstate = core::Entity::ImpulseInitiate; - if (Game::instance()->g_devel->value()) { + if (Base::instance()->g_devel->value()) { entity_timer = 0; } else { entity_timer = 3; @@ -88,7 +88,7 @@ void Ship::impulse() void Ship::jump(std::string const &args) { // devel mode provides instant jump access to arbitrary systems - if (Game::instance()->g_devel->value() && (args.size())) { + if (Base::instance()->g_devel->value() && (args.size())) { core::Zone *jumptargetzone = 0; std::string target; @@ -130,7 +130,7 @@ void Ship::jump(std::string const &args) return; } else { - if (!jumpdrive() && !Game::instance()->g_devel->value()) { + if (!jumpdrive() && !Base::instance()->g_devel->value()) { core::server()->send(owner(), "This ship is not equiped with a hyperspace drive!"); return; @@ -150,7 +150,7 @@ void Ship::jump(std::string const &args) } entity_eventstate = core::Entity::JumpInitiate; - if (Game::instance()->g_devel->value()) { + if (Base::instance()->g_devel->value()) { entity_timer = 0; } else { entity_timer = 8; @@ -179,7 +179,7 @@ JumpPoint * Ship::find_closest_jumppoint() } if (jumppoint && jumppoint->target()) { - if (Game::instance()->g_jumppointrange->value() < d) { + if (Base::instance()->g_jumppointrange->value() < d) { core::server()->send(owner(), "Jumppoint out of range!"); return 0; } else { @@ -274,8 +274,8 @@ void Ship::frame(float seconds) entity_timer -= 1.0f; if (entity_timer <= 0) { - actual_maxspeed = Game::instance()->g_impulsespeed->value(); - actual_acceleration = Game::instance()->g_impulseacceleration->value(); + actual_maxspeed = Base::instance()->g_impulsespeed->value(); + actual_acceleration = Base::instance()->g_impulseacceleration->value(); entity_eventstate = core::Entity::Impulse; entity_timer = 0; entity_dirty = true; @@ -301,8 +301,8 @@ void Ship::frame(float seconds) math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); target_afterburner = 0.0f; - actual_maxspeed = Game::instance()->g_impulsespeed->value(); - actual_acceleration = Game::instance()->g_impulseacceleration->value(); + actual_maxspeed = Base::instance()->g_impulsespeed->value(); + actual_acceleration = Base::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; } else if (entity_eventstate == core::Entity::Normal) { @@ -315,7 +315,7 @@ void Ship::frame(float seconds) math::clamp(target_afterburner, -1.0f, 1.0f); if (speed() > actual_maxspeed * 1.15f) { - actual_acceleration = Game::instance()->g_impulseacceleration->value(); + actual_acceleration = Base::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; } @@ -443,7 +443,7 @@ void Ship::frame(float seconds) } if (fabs(current_target_strafe) > MIN_DELTA) { - entity_location += entity_axis.left() * (current_target_strafe * Game::instance()->g_strafespeed->value()); + entity_location += entity_axis.left() * (current_target_strafe * Base::instance()->g_strafespeed->value()); } entity_movement = target_thrust; diff --git a/src/game/ship.h b/src/game/base/ship.h index 3a62a9d..d3c8bbf 100644 --- a/src/game/ship.h +++ b/src/game/base/ship.h @@ -1,19 +1,19 @@ /* - game/ship.h + base/ship.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_GAME_SHIP_H__ -#define __INCLUDED_GAME_SHIP_H__ +#ifndef __INCLUDED_BASE_SHIP_H__ +#define __INCLUDED_BASE_SHIP_H__ #include "core/player.h" #include "core/entity.h" -#include "game/shipmodel.h" -#include "game/jumppoint.h" +#include "base/shipmodel.h" +#include "base/jumppoint.h" #include "math/vector3f.h" -namespace game { +namespace base { /// A ship in the game, controled by a player class Ship : public core::EntityControlable @@ -56,5 +56,5 @@ private: } -#endif // __INCLUDED_GAME_SHIP_H__ +#endif // __INCLUDED_BASE_SHIP_H__ diff --git a/src/game/shipmodel.cc b/src/game/base/shipmodel.cc index 8ff182f..6018414 100644 --- a/src/game/shipmodel.cc +++ b/src/game/base/shipmodel.cc @@ -1,13 +1,13 @@ /* - game/shipmodel.cc + base/shipmodel.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 "sys/sys.h" -#include "game/shipmodel.h" +#include "base/shipmodel.h" -namespace game { +namespace base { // the ship model registry std::map<std::string, ShipModel *> ShipModel::registry; diff --git a/src/game/shipmodel.h b/src/game/base/shipmodel.h index a29f860..d92b840 100644 --- a/src/game/shipmodel.h +++ b/src/game/base/shipmodel.h @@ -1,16 +1,16 @@ /* - game/shipmodel.h + base/shipmodel.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_GAME_SHIPMODEL_H__ -#define __INCLUDED_GAME_SHIPMODEL_H__ +#ifndef __INCLUDED_BASE_SHIPMODEL_H__ +#define __INCLUDED_BASE_SHIPMODEL_H__ #include <map> #include <string> -namespace game { +namespace base { /// ship model specifications class ShipModel @@ -66,5 +66,5 @@ public: } -#endif // __INCLUDED_GAME_SHIPMODEL_H__ +#endif // __INCLUDED_BASE_SHIPMODEL_H__ diff --git a/src/game/star.cc b/src/game/base/star.cc index fd0c57b..cacd542 100644 --- a/src/game/star.cc +++ b/src/game/base/star.cc @@ -1,14 +1,14 @@ /* - game/star.cc + base/star.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2. */ -#include "game/game.h" -#include "game/star.h" +#include "base/base.h" +#include "base/star.h" -namespace game { +namespace base { Star::Star() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid | core::Entity::Bright) { diff --git a/src/game/star.h b/src/game/base/star.h index ecc7ade..5a78fc8 100644 --- a/src/game/star.h +++ b/src/game/base/star.h @@ -1,11 +1,11 @@ /* - game/star.h + base/star.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_GAME_STAR_H__ -#define __INCLUDED_GAME_STAR_H__ +#ifndef __INCLUDED_BASE_STAR_H__ +#define __INCLUDED_BASE_STAR_H__ // project headers #include "core/entity.h" @@ -14,7 +14,7 @@ // C++ headers #include <string> -namespace game { +namespace base { /// a star, that shines so bright class Star : public core::EntityGlobe { @@ -25,5 +25,5 @@ public: } -#endif // __INCLUDED_GAME_STAR_H__ +#endif // __INCLUDED_BASE_STAR_H__ diff --git a/src/game/game.cc b/src/game/game.cc index 4d66cbe..0b7e0f2 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -4,658 +4,19 @@ the terms of the GNU General Public License version 2 */ -#include <vector> -#include <string> - -#include "auxiliary/functions.h" -#include "core/gameserver.h" -#include "filesystem/filesystem.h" -#include "filesystem/inifile.h" #include "game/game.h" -#include "game/navpoint.h" -#include "game/jumppoint.h" -#include "game/planet.h" -#include "game/racetrack.h" -#include "game/ship.h" -#include "game/star.h" -#include "math/mathlib.h" +#include "base/base.h" +#include "core/core.h" #include "sys/sys.h" -namespace game -{ - -ShipModel *default_shipmodel = 0; -core::Zone *default_zone = 0; - -/*----- engine game functions ------------------------------------- */ - -/// list the ship model registry -void func_list_ship(std::string const &args) -{ - ShipModel::list(); -} - -/// a player joins the game -void func_join(core::Player *player, std::string const &args) -{ - if (player->control()) - return; - - player->set_zone(default_zone); - Ship *ship = new Ship(player, default_shipmodel); - ship->set_zone(default_zone); - player->set_control(ship); - - core::server()->send_sound(player, "game/buy-ship"); - - std::string message("^B"); - message.append(player->name()); - message.append("^B joins the game."); - core::server()->broadcast(message); - - player->player_dirty = true; -} - -/// a player joins the spectators -void func_spectate(core::Player *player, std::string const &args) -{ - if (!player->control()) - return; - - std::string message("^B"); - message.append(player->name()); - message.append("^B spectates."); - core::server()->broadcast(message); - - if (player->control()) { - player->remove_asset(player->control()); - } -} - -/// a player buys a ship -void func_buy(core::Player *player, std::string const &args) -{ - - std::string shipname; - std::string helpstr; - std::istringstream is(args); - is >> shipname; - aux::to_lowercase(shipname); - - ShipModel *shipmodel = 0; - for (ShipModel::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) { - if (shipname == (*smit).first) { - shipmodel = (*smit).second; - break; - } - - if (helpstr.size()) - helpstr.append("^N|^B"); - helpstr.append((*smit).second->label()); - } - - if (shipmodel) { - // player has only ship for now - if (player->control()) { - player->remove_asset(player->control()); - } - - Ship * ship = new Ship(player, shipmodel); - if (player->zone()) { - ship->set_zone(player->zone()); - } else { - ship->set_zone(default_zone); - } - player->set_control(ship); - - core::server()->broadcast("^B" + player->name() + " ^Bpurchased " + aux::article(shipmodel->name())); - core::server()->send_sound(player, "game/buy-ship"); - - } else { - core::server()->send(player, "Usage: buy [^B" + helpstr + "^N]"); - } -} - -/// a player sends standard hails -void func_hail(core::Player *player, std::string const &args) -{ - std::string target; - std::istringstream is(args); - if (!(is >> target)) { - core::server()->send(player, "Usage: hail [player]"); - return; - } - - core::Player *targetplayer = core::server()->find_player(target); - if (!targetplayer) { - core::server()->send(player, "^BPlayer " + target + "^B not found."); - return; - } - - core::server()->send(player, "^BYou hail " + targetplayer->name() + "^B."); - core::server()->send_sound(player, "com/hail"); - - core::server()->send(targetplayer, "^B" + player->name() + "^B hails you!"); - core::server()->send_sound(targetplayer, "com/hail"); -} - -/// a player actives the hyperspace jump drive on his ship -void func_jump(core::Player *player, std::string const &args) -{ - if (!player->control()) - return; - if (!player->control()->moduletype() == ship_enttype) - return; - Ship * ship = static_cast<Ship *>(player->control()); - ship->jump(args); -} - -/// a player actives the kinetic impulse drive on his ship -void func_impulse(core::Player *player, std::string const &args) -{ - if (!player->control()) - return; - if (!player->control()->moduletype() == ship_enttype) - return; - Ship * ship = static_cast<Ship *>(player->control()); - ship->impulse(); -} - -/* ---- The Game class --------------------------------------------- */ - -Game *Game::game_instance = 0; - -Game::Game() : core::Module("Project::OSiRiON") -{ - game_instance = this; - g_impulsespeed = 0; -} - -Game::~Game() -{ - game_instance = 0; -} - -void Game::init() -{ - module_running = false; - - ShipModel::clear(); - - if (!load_world()) { - abort(); - return; - } - - if (!load_ships()) { - abort(); - return; - } - - // add engine game functions - core::Func *func = 0; - - func = core::Func::add("join", (core::GameFuncPtr) func_join); - func->set_info("join the game"); - func = core::Func::add("hail", (core::GameFuncPtr) func_hail); - func->set_info("send a standard hail"); - func = core::Func::add("spectate", (core::GameFuncPtr) func_spectate); - func->set_info("leave the game and spectate"); - - func = core::Func::add("buy", (core::GameFuncPtr) func_buy); - func->set_info("buy a ship"); - - func = core::Func::add("jump", (core::GameFuncPtr) func_jump); - func->set_info("[string] activate or deactivate hyperspace jump drive"); - - func = core::Func::add("impulse", (core::GameFuncPtr) func_impulse); - func->set_info("activate are deactive kinetic impulse drive"); - - // add engine core functions - func = core::Func::add("list_ship", (core::FuncPtr) func_list_ship); - func->set_info("list ship statistics"); - - g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive); - g_impulsespeed->set_info("[float] speed of the impulse drive"); - - g_impulseacceleration = core::Cvar::get("g_impulseacceleration", "5", core::Cvar::Game | core::Cvar::Archive); - g_impulseacceleration->set_info("[float] acceleration of the impulse drive"); - - 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"); - - // indicate the module is ready to run frames - module_running = true; -} - -void Game::shutdown() -{ - g_impulsespeed = 0; - // game functions are automaticly removed - - // remove engine core functions - core::Func::remove("list_ship"); - - ShipModel::clear(); - module_running = false; -} - -bool Game::load_world() -{ - std::string inifilename("world"); - - filesystem::IniFile worldini; - worldini.open(inifilename); - - if (!worldini.is_open()) { - con_error << "Could not open " << worldini.name() << std::endl; - return false; - } - - core::Zone *zone = 0; - std::string label; - - while (worldini.getline()) { - - if (worldini.got_section()) { - - if (worldini.got_section("world")) { - continue; - } else { - con_warn << worldini.name() << " unknown section '" << worldini.section() << "' at line " << worldini.line() << std::endl; - } - - } else if (worldini.section().compare("world") == 0 ) { - if (worldini.got_key_string("zone", label)) { - aux::to_label(label); - zone = new core::Zone(label); - core::Zone::add(zone); - } - } - } - worldini.close(); - - if (!core::Zone::registry().size()) { - con_error << "No zones found!" << std::endl; - return false; - } - - con_debug << " " << worldini.name() << " " << core::Zone::registry().size() << " zones" << std::endl; - - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - if (!load_zone((*it).second)) { - return false; - } - } - - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - if (!validate_zone((*it).second)) { - return false; - } - } - - if (!default_zone) { - con_error << "No default zone found!" << std::endl; - return false; - } - - 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; - using math::Color; - - std::string inifilename("zones/"); - inifilename.append(zone->label()); - - filesystem::IniFile zoneini; - zoneini.open(inifilename); - - if (!zoneini.is_open()) { - con_error << "Could not open " << zoneini.name() << std::endl; - return false; - } - - size_t count = 0; - - Planet *planet = 0; - Star *star = 0; - NavPoint *navpoint = 0; - JumpPoint *jumppoint = 0; - RaceTrack *racetrack = 0; - CheckPoint *checkpoint = 0; - core::Entity *entity = 0; - - bool b; - - std::string strval; - - // set th default sky - zone->set_sky("sky"); - - while (zoneini.getline()) { - 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)) { - zone->set_sky(strval); - continue; - } else if (zoneini.got_key_bool("default", b)) { - if (b) default_zone = zone; - continue; - } else { - con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; - } - } else if (zoneini.section().compare("star") == 0) { - if (got_entity_key(zoneini, star)) { - continue; - } else if (zoneini.got_key_string("texture", star->entity_texture)) { - continue; - } else { - con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; - } - } else if (zoneini.section().compare("navpoint") == 0) { - 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 (got_entity_key(zoneini, jumppoint)) { - continue; - } else if (zoneini.got_key_string("target", jumppoint->jumppoint_targetlabel)) { - continue; - } else { - con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; - } - } else if (zoneini.section().compare("planet") == 0) { - if (got_entity_key(zoneini, planet)) { - continue; - } else if (zoneini.got_key_string("texture", planet->entity_texture)) { - continue; - } else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) { - continue; - } else { - con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; - } - - } else if (zoneini.section().compare("racetrack") == 0) { - 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 (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) { - if (got_entity_key(zoneini, entity)) { - continue; - } else { - con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; - } - } - } else if (zoneini.got_section("zone")) { - continue; - - } else if (zoneini.got_section("star")) { - star = new Star(); - star->set_zone(zone); - count ++; - - } else if (zoneini.got_section("navpoint")) { - navpoint = new NavPoint(); - navpoint->set_zone(zone); - count ++; - - } else if (zoneini.got_section("jumppoint")) { - jumppoint = new JumpPoint(); - jumppoint->set_zone(zone); - count ++; - - } else if(zoneini.got_section("racetrack")) { - racetrack = new RaceTrack(); - racetrack->set_zone(zone); - - } else if(zoneini.got_section("checkpoint")) { - checkpoint = new CheckPoint(racetrack); - if (!racetrack) { - con_warn << zoneini.name() << " checkpoint without racetrack at line " << zoneini.line() << std::endl; - } - - } else if (zoneini.got_section("planet")) { - planet = new Planet(); - planet->set_zone(zone); - count ++; - - } else if (zoneini.got_section("entity")) { - entity = new core::Entity(); - entity->entity_flags += core::Entity::Static; - entity->set_zone(zone); - count ++; - - } else if (zoneini.got_section()) { - con_warn << zoneini.name() << " unknown section '" << zoneini.section() << "' at line " << zoneini.line() << std::endl; - } - } - zoneini.close(); - - con_debug << " " << zoneini.name() << " " << zone->content().size() << " entities" << std::endl; - - - return true; -} - -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); - - if (entity->entity_moduletypeid == jumppoint_enttype) { - JumpPoint *jumppoint = static_cast<JumpPoint *>(entity); - - if (jumppoint->targetlabel().size() < 3) { - con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; - continue; - } - size_t pos = jumppoint->targetlabel().find(':'); - if ((pos < 1 ) || (pos >= (jumppoint->targetlabel().size()-1))) { - con_warn << " Jumppoint with invalid target label '" << jumppoint->targetlabel() << "'\n"; - continue; - } - - std::string zonelabel(jumppoint->targetlabel().substr(0, pos)); - std::string entitylabel(jumppoint->targetlabel().substr(pos+1, jumppoint->targetlabel().size()-pos)); - - core::Zone *targetzone = core::Zone::find(zonelabel); - if (!targetzone) { - con_warn << " Jumppoint with invalid target zone '" << zonelabel << "'\n"; - continue; - } - - core::Entity *targetentity = targetzone->find_entity(entitylabel); - if (!targetentity) { - con_warn << " Could not find target jumppoint '" << entitylabel << "'\n"; - continue; - } - - if (targetentity->moduletype() != jumppoint_enttype) { - con_warn << " Jumppoint with invalid target jumppoint '" << entitylabel << "'\n"; - continue; - } - - jumppoint->jumppoint_target = static_cast<JumpPoint *>(targetentity); - - //con_debug << " Jumppoint " << zone->label() << ":" << jumppoint->label() << " with target " << jumppoint->targetlabel() << std::endl; - } - } - - return true; -} - -// read ship model specifications -bool Game::load_ships() -{ - using math::Vector3f; - using math::Color; - - default_shipmodel = 0; - - filesystem::IniFile shipsini; - shipsini.open("ships"); - if (!shipsini.is_open()) { - con_error << "Could not open ini/ships.ini!" << std::endl; - return false; - } - - ShipModel *shipmodel = 0; - std::string label; - bool b; - - while (shipsini.getline()) { - if (shipsini.got_key()) { - if (shipsini.section().compare("ship") == 0) { - if (shipsini.got_key_string("label", label)) { - aux::to_label(label); - shipmodel->shipmodel_label.assign(label); - ShipModel::add(shipmodel); - continue; - } else if (shipsini.got_key_string("name",shipmodel->shipmodel_name)) { - continue; - } else if (shipsini.got_key_string("model", shipmodel->shipmodel_modelname)) { - continue; - } else if (shipsini.got_key_bool("default", b)) { - if (b) default_shipmodel = shipmodel; - continue; - } else if (shipsini.got_key_bool("jumpdrive", shipmodel->shipmodel_jumpdrive)) { - continue; - } else if (shipsini.got_key_float("acceleration", shipmodel->shipmodel_acceleration)) { - continue; - } else if (shipsini.got_key_float("maxspeed", shipmodel->shipmodel_maxspeed)) { - continue; - } else if (shipsini.got_key_float("turnspeed", shipmodel->shipmodel_turnspeed)) { - math::clamp(shipmodel->shipmodel_turnspeed, 0.0f, 90.0f); - continue; - } else { - con_warn << shipsini.name() << " unknown key '" << shipsini.key() << "' at line " << shipsini.line() << std::endl; - } - } - } else if (shipsini.got_section("ship")) { - shipmodel = new ShipModel(); - - if (!default_shipmodel) - default_shipmodel = shipmodel; - - } else if (shipsini.got_section()) { - con_warn << shipsini.name() << " unknown section '" << shipsini.section() << "' at line " << shipsini.line() << std::endl; - } - } - shipsini.close(); - - con_debug << " " << shipsini.name() << " " << ShipModel::registry.size() << " ship models" << std::endl; - - if (!default_shipmodel) { - con_error << "No default ship model found!\n"; - return false; - } - - return true; -} - -void Game::frame(float seconds) +namespace game { - if (!running()) - return; -} -void Game::player_connect(core::Player *player) +void register_modules(bool register_client_modules) { - std::string args; - player->set_zone(default_zone); - func_spectate(player, args); -} + con_print << "^BRegistering game modules..." << std::endl; + core::Module::add("base", new base::Base()); -void Game::player_disconnect(core::Player *player) -{ - player->remove_asset(player->control()); } -} // namespace game - +}
\ No newline at end of file diff --git a/src/game/game.h b/src/game/game.h index 3b65da1..544f26b 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -7,71 +7,9 @@ #ifndef __INCLUDED_GAME_H__ #define __INCLUDED_GAME_H__ -#include <vector> -#include <string> - -#include "filesystem/inifile.h" -#include "game/ship.h" -#include "game/star.h" -#include "core/core.h" -#include "sys/sys.h" - -/// the game-specific engine -/** The main game functions. - */ -namespace game -{ - -// entity type constants -const unsigned int ship_enttype = 256; -const unsigned int star_enttype = 257; -const unsigned int planet_enttype = 258; -const unsigned int navpoint_enttype = 259; -const unsigned int jumppoint_enttype = 260; - -class Game : public core::Module { -public: - Game(); - ~Game(); - - /// initialize the game - void init(); - - /// shutdown the game - void shutdown(); - - /// run one time frame - void frame(float seconds); - - /// is called when a player connects - void player_connect(core::Player *player); - - /// is called when a player disconnects - void player_disconnect(core::Player *player); - - static inline Game *instance() { return game_instance; } - - 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); - - bool validate_zone(core::Zone *zone); - - bool load_ships(); - - static Game *game_instance; -}; - +namespace game { + + void register_modules(bool register_client_modules=false); } #endif // __INCLUDED_GAME_H__ diff --git a/src/game/intro/Makefile.am b/src/game/intro/Makefile.am new file mode 100644 index 0000000..66ea90d --- /dev/null +++ b/src/game/intro/Makefile.am @@ -0,0 +1,2 @@ +INCLUDES = -I$(top_srcdir)/src +METASOURCES = AUTO diff --git a/src/osirion.cc b/src/osirion.cc index 2f0a5eb..71bd1ec 100644 --- a/src/osirion.cc +++ b/src/osirion.cc @@ -9,14 +9,11 @@ int main(int count, char **arguments) { - // preload the game module - core::Module::load(new game::Game()); + // load the game modules + game::register_modules(true); client::client_main(count, arguments); - // unload the game module - core::Module::unload(); - return 0; } diff --git a/src/osiriond.cc b/src/osiriond.cc index 0e8f6f7..bd88df0 100644 --- a/src/osiriond.cc +++ b/src/osiriond.cc @@ -10,12 +10,9 @@ int main(int count, char **arguments) { // preload the game module - core::Module::load(new game::Game()); + game::register_modules(false); server::main(count, arguments); - // unload the game module - core::Module::unload(); - return 0; } |