diff options
author | Stijn Buys <ingar@osirion.org> | 2008-11-08 10:17:37 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-11-08 10:17:37 +0000 |
commit | 4cad4a27677b0490d3ba0018bc3404961f925ed5 (patch) | |
tree | f9d59542f27f66a9fb4c8938f40aec66994449fc /src/game | |
parent | 27ab3566118e77754fefb32a41ee06cf24a59dfe (diff) |
docking, bumps network protocol version
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/base.cc | 97 | ||||
-rw-r--r-- | src/game/base/base.h | 1 | ||||
-rw-r--r-- | src/game/base/ship.cc | 29 |
3 files changed, 110 insertions, 17 deletions
diff --git a/src/game/base/base.cc b/src/game/base/base.cc index 6a3738e..a5492ea 100644 --- a/src/game/base/base.cc +++ b/src/game/base/base.cc @@ -6,6 +6,7 @@ #include <vector> #include <string> +#include <assert.h> #include "auxiliary/functions.h" #include "core/gameserver.h" @@ -39,11 +40,15 @@ void func_join(core::Player *player, std::string const &args) if (player->control()) return; - player->set_zone(Base::default_zone); Ship *ship = new Ship(player, Base::default_shipmodel); - ship->set_zone(Base::default_zone); + ship->set_zone(player->zone()); player->set_control(ship); +/* + core::Entity *dock = ship->zone()->default_view(); + ship->entity_location.assign(dock->location() + (dock->axis().forward() * dock->radius()*2.0f)); + ship->entity_axis.assign(dock->axis()); +*/ core::server()->send_sound(player, "game/buy-ship"); std::string message("^B"); @@ -68,6 +73,11 @@ void func_spectate(core::Player *player, std::string const &args) if (player->control()) { player->remove_asset(player->control()); } + + if (!player->zone()) + player->set_zone(Base::default_zone); + + player->set_view(0); } /// a player buys a ship @@ -99,13 +109,14 @@ void func_buy(core::Player *player, std::string const &args) } Ship * ship = new Ship(player, shipmodel); - if (player->zone()) { - ship->set_zone(player->zone()); - } else { - ship->set_zone(Base::default_zone); + ship->set_zone(player->zone()); + if (player->view()) { + core::Entity *dock = player->view(); + ship->entity_location.assign(dock->location() + (dock->axis().forward() * dock->radius()*2.0f)); + ship->entity_axis.assign(dock->axis()); } + player->set_control(ship); - core::server()->broadcast("^B" + player->name() + " ^Bpurchased " + aux::article(shipmodel->name())); core::server()->send_sound(player, "game/buy-ship"); @@ -168,7 +179,42 @@ void func_dock(core::Player *player,core::Entity *entity) if (player->control()->zone() != entity->zone()) return; - core::server()->send(player, "^BSending docking request to " + entity->name() + "^B..."); + if ((entity->flags() & core::Entity::Dockable) == 0) + return; + + if (player->control()->eventstate() == core::Entity::Docked) + return; + + if (math::distance(entity->location(), player->control()->location()) > 2.0f * entity->radius()) { + core::server()->send(player, "^B" + entity->name() + " is out of range!"); + return; + } + + player->control()->location().assign(entity->location()); + player->control()->set_eventstate(core::Entity::Docked); + player->set_view(entity); + core::server()->send(player, "^BDocking at " + entity->name() + "^B..."); +} + +/// launch request +void func_launch(core::Player *player, std::string const &args) +{ + if (!player->control()) + return; + + if (!player->view()) + return; + + if (player->control()->eventstate() != core::Entity::Docked) + return; + + assert(player->view()->zone() == player->control()->zone()); + + core::Entity *dock = player->view(); + player->control()->entity_location.assign(dock->location() + (dock->axis().forward() * dock->radius()*2.0f)); + player->control()->entity_axis.assign(dock->axis()); + player->control()->set_eventstate(core::Entity::Normal); + player->set_view(0); } /* -- class Base static members ----------------------------------- */ @@ -224,7 +270,10 @@ void Base::init() func->set_info("buy a ship"); func = core::Func::add("@dock", (core::TargetFuncPtr) func_dock); - func->set_info("send a docking request"); + func->set_info("dock with target object"); + + func = core::Func::add("launch", (core::GameFuncPtr) func_launch); + func->set_info("launch to space when docked"); func = core::Func::add("jump", (core::GameFuncPtr) func_jump); func->set_info("[string] activate or deactivate hyperspace jump drive"); @@ -243,7 +292,7 @@ void Base::init() 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 = core::Cvar::get("g_strafespeed", "0.01", 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); @@ -276,6 +325,8 @@ bool Base::load_world() return false; } + con_print << "^BLoading world..." << std::endl; + core::Zone *zone = 0; std::string label; @@ -349,6 +400,8 @@ bool Base::load_zone(core::Zone *zone) return false; } + con_print << "^BLoading zone " << zone->label() << "..." << std::endl; + size_t count = 0; Planet *planet = 0; @@ -461,6 +514,17 @@ bool Base::load_zone(core::Zone *zone) continue; } else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) { continue; + } else if (zoneini.got_key_bool("dock", b)) { + if (b) + planet->set_flag(core::Entity::Dockable); + else + planet->unset_flag(core::Entity::Dockable); + + } else if (zoneini.got_key_bool("default", b)) { + if (b) { + zone->set_default_view(planet); + } + continue; } else { zoneini.unkown_key(); } @@ -482,6 +546,17 @@ bool Base::load_zone(core::Zone *zone) } else if (zoneini.in_section("entity")) { if (core::Parser::got_entity_key(zoneini, entity)) { continue; + } else if (zoneini.got_key_bool("default", b)) { + if (b) { + zone->set_default_view(entity); + } + } else if (zoneini.got_key_bool("dock", b)) { + if (b) { + entity->set_flag(core::Entity::Dockable); + //core::Parser::read_entity_menu(entity, "zones/" + zone->label() + "/" + entity->label()); + } else { + entity->unset_flag(core::Entity::Dockable); + } } else { zoneini.unkown_key(); } @@ -625,6 +700,8 @@ void Base::player_connect(core::Player *player) { std::string args; player->set_zone(default_zone); + player->set_view(0); // not docked + func_spectate(player, args); } diff --git a/src/game/base/base.h b/src/game/base/base.h index 34b3bd7..fcf39d1 100644 --- a/src/game/base/base.h +++ b/src/game/base/base.h @@ -29,6 +29,7 @@ const unsigned int star_enttype = 257; const unsigned int planet_enttype = 258; const unsigned int navpoint_enttype = 259; const unsigned int jumppoint_enttype = 260; +const unsigned int jumpgate_enttype = 261; /// the base Project::OSiRiON game model class Base : public core::Module { diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 412668d..20f37c8 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -59,14 +59,13 @@ void Ship::reset() } void Ship::impulse() { - if (entity_eventstate == core::Entity::Jump) { - return; - - } else if ((entity_eventstate == core::Entity::Impulse) || (entity_eventstate == core::Entity::ImpulseInitiate)) { + if ((entity_eventstate == core::Entity::Impulse) || (entity_eventstate == core::Entity::ImpulseInitiate)) { entity_eventstate = core::Entity::Normal; - + + } else if (entity_eventstate != core::Entity::Normal) { + return; + } else { - if (entity_eventstate == core::Entity::JumpInitiate) { ship_jumpdrive_timer = 0; entity_timer = 0; @@ -87,6 +86,10 @@ void Ship::impulse() void Ship::jump(std::string const &args) { + if (entity_eventstate == core::Entity::Docked) { + return; + } + // devel mode provides instant jump access to arbitrary systems if (Base::g_devel->value() && (args.size())) { @@ -215,7 +218,19 @@ void Ship::frame(float seconds) // target axis math::Axis target_axis(entity_axis); - if (entity_eventstate == core::Entity::JumpInitiate) { + if (entity_eventstate == core::Entity::Docked) { + + target_thrust = 0; + target_pitch = 0; + target_roll = 0; + target_direction = 0; + target_afterburner = 0.0f; + target_thrust = 0; + + entity_speed = 0; + return; + + } else if (entity_eventstate == core::Entity::JumpInitiate) { if (ship_jumpdrive_timer + 1.0f <= core::server()->time()) { entity_timer -= 1.0f; |