From 21e6267e3f998a467ca3b5ec225e6d03653aed97 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 20 Oct 2010 14:44:12 +0000 Subject: advanced ship physics specifications, specs game function --- src/game/base/game.cc | 96 +++++++++++++++++++++++++++++++------ src/game/base/game.h | 6 +-- src/game/base/ship.cc | 117 ++++++++++++++++++++------------------------- src/game/base/ship.h | 56 +++++++++++++++++++++- src/game/base/shipmodel.cc | 42 +++++++++------- src/game/base/shipmodel.h | 85 ++++++++++++++++++++++---------- 6 files changed, 275 insertions(+), 127 deletions(-) (limited to 'src') diff --git a/src/game/base/game.cc b/src/game/base/game.cc index ebf09ce..418bfb5 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -51,7 +51,6 @@ void Default::clear() // game variables core::Cvar *Game::g_impulsespeed = 0; -core::Cvar *Game::g_impulseacceleration = 0; core::Cvar *Game::g_jumppointrange = 0; core::Cvar *Game::g_devel = 0; core::Cvar *Game::g_damping = 0; @@ -148,7 +147,7 @@ void Game::func_jump(core::Player *player, std::string const &args) { if (!player->control()) return; - if (!player->control()->moduletype() == ship_enttype) + if (player->control()->moduletype() != ship_enttype) return; Ship * ship = static_cast(player->control()); ship->func_jump(args); @@ -159,7 +158,7 @@ void Game::func_impulse(core::Player *player, std::string const &args) { if (!player->control()) return; - if (!player->control()->moduletype() == ship_enttype) + if (player->control()->moduletype() != ship_enttype) return; Ship * ship = static_cast(player->control()); ship->func_impulse(); @@ -236,12 +235,13 @@ void Game::func_give(core::Player *player, const std::string &args) return; } + ShipModel *shipmodel = 0; if (!(is >> labelstr)) { player->send("Usage: give ship [string]"); - return; + } else { + shipmodel = ShipModel::find(labelstr); } - ShipModel *shipmodel = ShipModel::find(labelstr); if (!shipmodel) { // enable rcon buffering sys::ConsoleInterface::instance()->set_rcon(true); @@ -282,8 +282,8 @@ void Game::func_give(core::Player *player, const std::string &args) ship->get_location().assign(player->control()->location()); ship->set_state(player->control()->state()); ship->get_axis().assign(player->control()->axis()); - ship->set_speed(player->control()->speed()); ship->set_thrust(player->control()->thrust()); + ship->reset(); //target_thrust is protected //ship->target_thrust = player->control()->target_thrust()); @@ -316,12 +316,13 @@ void Game::func_give(core::Player *player, const std::string &args) player->send("^WNeed a ship to load cargo!"); } + Cargo *cargo = 0; if (!(is >> labelstr)) { player->send("Usage: give cargo [string] [int]"); - return; + } else { + cargo = Cargo::find(labelstr); } - Cargo *cargo = Cargo::find(labelstr); if (!cargo) { // enable rcon buffering sys::ConsoleInterface::instance()->set_rcon(true); @@ -375,6 +376,74 @@ void Game::func_give(core::Player *player, const std::string &args) } } + +void Game::func_specs(core::Player *player, const std::string &args) +{ + if (!Game::g_devel->value()) { + player->send("Cheats disabled"); + return; + } + + if (!player->control()) { + player->send("^WYou need to join the game first!"); + return; + } + + if (player->control()->moduletype() != ship_enttype) + return; + Ship * ship = static_cast(player->control()); + + std::istringstream is(args); + std::string str; + + if (!(is >> str)) { + // enable rcon buffering + sys::ConsoleInterface::instance()->set_rcon(true); + + con_print << "Current ship specifications for " + ship->name() << std::endl; + con_print << " mass = " << ship->shipmodel()->mass() << std::endl; + con_print << " thrust = " << ship->thrust_force() << std::endl; + con_print << " impulse = " << ship->impulse_force() << std::endl; + con_print << " strafe = " << ship->strafe_force() << std::endl; + con_print << " torque = " << ship->torque_force() << std::endl; + + // disable rcon buffering + sys::ConsoleInterface::instance()->set_rcon(false); + + while (sys::ConsoleInterface::instance()->rconbuf().size()) { + player->send((*sys::ConsoleInterface::instance()->rconbuf().begin())); + sys::ConsoleInterface::instance()->rconbuf().pop_front(); + } + + } else { + float value; + if (!(is >> value)) + return; + + aux::to_label(str); + std::stringstream msgstr; + + if (str.compare("thrust") == 0) { + ship->set_thrust_force(value); + msgstr << "Ship thrust force set to " << value; + } else if (str.compare("impulse") == 0) { + ship->set_impulse_force(value); + msgstr << "Ship impulse force set to " << value; + } else if (str.compare("strafe") == 0) { + ship->set_strafe_force(value) ; + msgstr << "Ship strafe force set to " << value; + } else if (str.compare("torque") == 0) { + ship->set_torque_force(value); + msgstr << "Ship torque force set to " << value; + } else { + msgstr << "^WUnknown ship specification '" << str << "'"; + } + + player->send(msgstr.str()); + } + +} + // sell request from a player void Game::func_sell(core::Player *player, const std::string &args) { @@ -769,6 +838,9 @@ Game::Game() : core::Module("Project::OSiRiON", true) func = core::Func::add("give", Game::func_give); func->set_info("cheat functions"); + + func = core::Func::add("specs", Game::func_specs); + func->set_info("change ship specifications"); func = core::Func::add("jump", Game::func_jump); func->set_info("[string] activate or deactivate hyperspace jump drive"); @@ -789,12 +861,9 @@ Game::Game() : core::Module("Project::OSiRiON", true) func->set_info("dock with target object"); // add engine variables - g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive); + g_impulsespeed = core::Cvar::get("g_impulsespeed", "1500", 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_jumppointrange = core::Cvar::get("g_jumppointrange", "512", core::Cvar::Game | core::Cvar::Archive); g_jumppointrange->set_info("[float] jumppoint range"); @@ -920,9 +989,6 @@ bool Game::load_zone(core::Zone *zone) std::string strval; - // set th default sky - zone->set_sky("sky"); - while (zoneini.getline()) { if (zoneini.got_section()) { diff --git a/src/game/base/game.h b/src/game/base/game.h index 07df62d..7dc17bb 100644 --- a/src/game/base/game.h +++ b/src/game/base/game.h @@ -69,12 +69,9 @@ public: /* --- game variables -------------------------------------- */ - /// game variable: speed of the impulse drive + /// game variable: maximum speed of the impulse drive static core::Cvar *g_impulsespeed; - /// game variable: acceleration of the impulse drive - static core::Cvar *g_impulseacceleration; - /// game variable: jumppoint range static core::Cvar *g_jumppointrange; @@ -117,6 +114,7 @@ private: static void func_buy(core::Player *player, std::string const &args); static void func_sell(core::Player *player, const std::string &args); static void func_give(core::Player *player, const std::string &args); + static void func_specs(core::Player *player, const std::string &args); static void func_eject(core::Player *player, const std::string &args); static void func_beam(core::Player *player, const std::string &args); }; diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 7cd602e..d234783 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -76,12 +76,17 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable( set_flag(core::Entity::Dockable); } - - set_mass(radius() * 10.0f); + + set_mass(shipmodel->mass()); + set_impulse_force(shipmodel->impulse_force()); + set_thrust_force(shipmodel->thrust_force()); + set_strafe_force(shipmodel->strafe_force()); + set_torque_force(shipmodel->torque_force()); reset(); - const float linear_damp = 0.5f; - const float angular_damp = 0.75f; + const float linear_damp = 0.8f; + const float angular_damp = 0.8f; + body()->setDamping(linear_damp, angular_damp); } @@ -301,48 +306,43 @@ void Ship::set_zone(core::Zone *zone) void Ship::action (btScalar seconds) { - /* controls - * - * current_target_direction - * current_target_pitch - * current_target_roll - * current_target_strafe - * current_target_vstrafe - * entity_thrust - */ - - float actual_maxspeed = 0; - float actual_acceleration = 0; - float actual_thrust = 0; + float maxspeed = 0; + float engine_force = 0; + btTransform t; switch (entity_state) { case core::Entity::Normal: - actual_maxspeed = ship_shipmodel->maxspeed(); - actual_acceleration = ship_shipmodel->acceleration(); - actual_thrust = entity_thrust; + engine_force = ship_thrust_force * entity_thrust; + maxspeed = ship_shipmodel->maxspeed() * entity_thrust; break; + case core::Entity::ImpulseInitiate: case core::Entity::Impulse: - actual_maxspeed = Game::g_impulsespeed->value(); - actual_acceleration = Game::g_impulseacceleration->value(); - actual_thrust = 1.0f; + engine_force = ship_impulse_force; + maxspeed = (Game::g_impulsespeed ? Game::g_impulsespeed->value() * 0.01f : 0.0f); break; + case core::Entity::JumpInitiate: case core::Entity::Jump: - actual_maxspeed = 0.0f; - actual_acceleration = Game::g_impulseacceleration->value(); - actual_thrust = 0.0f; + maxspeed = 0.0f; + engine_force = 0.0f; break; case core::Entity::Docked: - + maxspeed = 0.0f; + engine_force = 0.0f; + t.setIdentity(); t.setOrigin(to_btVector3(location())); t.setBasis(to_btMatrix3x3(axis())); body()->setWorldTransform(t); + zone()->physics()->synchronizeSingleMotionState(entity_body); + return; break; default: + maxspeed = 0.0f; + engine_force = 0.0f; break; } @@ -350,42 +350,41 @@ void Ship::action (btScalar seconds) entity_motionstate->getWorldTransform(t); get_location().assign(t.getOrigin()); get_axis().assign(t.getBasis()); - - const float force_scale = 1.0f; - const float thrust_scale = 4.0f; - body()->applyCentralImpulse(math::to_btVector3(axis().up() * current_target_vstrafe * actual_acceleration * force_scale)); - body()->applyCentralImpulse(math::to_btVector3(axis().left() * current_target_strafe * actual_acceleration * force_scale)); + const float torque_scale = 0.001f; + const float roll_scale = 0.25f; - body()->applyCentralImpulse(math::to_btVector3(axis().forward() * current_target_afterburner * actual_acceleration * force_scale)); + // apply strafe + body()->applyCentralImpulse(math::to_btVector3(axis().up() * current_target_vstrafe * ship_strafe_force)); + body()->applyCentralImpulse(math::to_btVector3(axis().left() * current_target_strafe * ship_strafe_force)); + + // apply afterburner + body()->applyCentralImpulse(math::to_btVector3(axis().forward() * current_target_afterburner * ship_strafe_force)); + // apply main thruster if (current_target_afterburner >= 0) { - body()->applyCentralImpulse(math::to_btVector3(axis().forward() * actual_thrust * actual_acceleration * thrust_scale)); + body()->applyCentralImpulse(math::to_btVector3(axis().forward() * engine_force)); } + + // apply direction + body()->applyTorqueImpulse(math::to_btVector3(axis().up() * current_target_direction * ship_torque_force * torque_scale)); + // apply pitch + body()->applyTorqueImpulse(math::to_btVector3(axis().left() * -current_target_pitch * ship_torque_force * torque_scale)); + // apply roll + body()->applyTorqueImpulse(math::to_btVector3(axis().forward() * -current_target_roll * ship_torque_force * roll_scale * torque_scale)); - const float torque_scale = 0.001f; - body()->applyTorqueImpulse(math::to_btVector3(axis().up() * current_target_direction * ship_shipmodel->turnspeed() * torque_scale)); - body()->applyTorqueImpulse(math::to_btVector3(axis().left() * -current_target_pitch * ship_shipmodel->turnspeed() * torque_scale)); - - body()->applyTorqueImpulse(math::to_btVector3(axis().forward() * -current_target_roll * ship_shipmodel->turnspeed() * torque_scale * 0.25f)); - + // limit speed entity_speed = (float) entity_body->getLinearVelocity().length(); - if (entity_speed > Game::g_impulsespeed->value()) { - body()->setLinearVelocity(math::to_btVector3(axis().forward() * Game::g_impulsespeed->value())); - entity_speed = actual_maxspeed; + if (entity_speed > Game::g_impulsespeed->value() * 0.01f) { + entity_speed = Game::g_impulsespeed->value() * 0.01f; + body()->setLinearVelocity(math::to_btVector3(axis().forward() * entity_speed)); } - } void Ship::frame(float seconds) { - const float direction_reaction = 2.0f; // direction controls reaction time factor - const float thrust_reaction = 0.5f; // thrust control reaction time factor - const float strafe_reaction = 1.5f; - const float afterburner_reaction = 1.0f; // a fterburner control reaction time - //const float actual_turnspeed = ship_shipmodel->turnspeed(); - - float actual_maxspeed = ship_shipmodel->maxspeed(); - float actual_acceleration = ship_shipmodel->acceleration(); - //float actual_thrust = 0; + const float direction_reaction = 2.0f; // directional control reaction time + const float thrust_reaction = 0.5f; // thrust control reaction time + const float strafe_reaction = 1.5f; // strafe control reaction time + const float afterburner_reaction = 1.0f; // afterburner control reaction time math::Vector3f n; // normal of a plane math::Axis target_axis(axis()); // target axis @@ -419,7 +418,7 @@ void Ship::frame(float seconds) if (entity_timer <= 0) { if (ship_jumpdepart && ship_jumpdepart->target()) { set_state(core::Entity::Jump); - entity_speed = Game::g_impulsespeed->value(); + entity_speed = Game::g_impulsespeed->value() * 0.01f; if (ship_jumpdepart->moduletype() == jumpgate_enttype) { get_axis().assign(ship_jumpdepart->target()->axis()); get_location().assign(ship_jumpdepart->target()->location()); @@ -493,8 +492,6 @@ void Ship::frame(float seconds) entity_timer -= 1.0f; if (entity_timer <= 0) { - actual_maxspeed = Game::g_impulsespeed->value(); - actual_acceleration = Game::g_impulseacceleration->value(); entity_state = core::Entity::Impulse; entity_timer = 0; set_dirty(); @@ -510,9 +507,6 @@ void Ship::frame(float seconds) math::clamp(target_pitch, -1.0f, 1.0f); math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); - - actual_maxspeed = Game::g_impulsespeed->value(); - actual_acceleration = Game::g_impulseacceleration->value(); } } else if (entity_state == core::Entity::Impulse) { @@ -530,8 +524,6 @@ void Ship::frame(float seconds) target_thrust = 1.0f; entity_thrust = 1.0f; } else { - actual_maxspeed = Game::g_impulsespeed->value(); - actual_acceleration = Game::g_impulseacceleration->value(); target_afterburner = 0.0f; target_thrust = 0.0f; } @@ -545,9 +537,6 @@ void Ship::frame(float seconds) math::clamp(target_direction, -1.0f, 1.0f); math::clamp(target_afterburner, -1.0f, 1.0f); - if (speed() > actual_maxspeed * 1.15f) { - actual_acceleration = Game::g_impulseacceleration->value(); - } } else if (entity_state == core::Entity::Destroyed) { diff --git a/src/game/base/ship.h b/src/game/base/ship.h index 2c1bc2c..c8d478c 100644 --- a/src/game/base/ship.h +++ b/src/game/base/ship.h @@ -23,6 +23,31 @@ public: Ship(core::Player *owner, ShipModel *shipmodel); ~Ship(); + /// shipmodel + inline const ShipModel *shipmodel() const { + return ship_shipmodel; + } + + /// impulse drive force + inline const float impulse_force() const { + return ship_impulse_force; + } + + /// thruster force + inline const float thrust_force() const { + return ship_thrust_force; + } + + /// strafe force + inline const float strafe_force() const { + return ship_strafe_force; + } + + /// torque force + inline const float torque_force() const { + return ship_torque_force; + } + /// physices frame virtual void action (btScalar seconds); @@ -36,7 +61,29 @@ public: inline bool jumpdrive() const { return ship_jumpdrive; } - + + /// set impulse drive force + inline void set_impulse_force(const float impulse) { + ship_impulse_force = impulse; + + } + + /// set thruster force + inline void set_thrust_force(const float thrust) { + ship_thrust_force = thrust; + } + + /// set strafe force + inline void set_strafe_force(const float strafe) { + ship_strafe_force = strafe; + } + + /// set torque force + inline void set_torque_force(const float torque) { + ship_torque_force = torque; + } + + /// Initiate jump, departing from a jump point /** Initiates a jump even if the ship has no jumpdrive */ @@ -54,6 +101,7 @@ public: /// toggle jump drive activation void func_jump(std::string const & args); + virtual void dock(Entity *entity); private: @@ -73,8 +121,12 @@ private: float ship_impulsedrive_timer; - JumpPoint *ship_jumpdepart; + + float ship_impulse_force; + float ship_thrust_force; + float ship_strafe_force; + float ship_torque_force; }; } diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc index 3630d11..de68413 100644 --- a/src/game/base/shipmodel.cc +++ b/src/game/base/shipmodel.cc @@ -69,15 +69,23 @@ bool ShipModel::init() } else if (shipsini.got_key_bool("dock", b)) { shipmodel->set_dock(b); continue; - } else if (shipsini.got_key_float("acceleration", f)) { - shipmodel->set_acceleration(f); - continue; } else if (shipsini.got_key_float("maxspeed", f)) { - shipmodel->set_maxspeed(f); + shipmodel->set_maxspeed(f * 0.01f); + continue; + } else if (shipsini.got_key_float("impulse", f)) { + shipmodel->set_impulse_force(f); + continue; + } else if (shipsini.got_key_float("thrust", f)) { + shipmodel->set_thrust_force(f); continue; - } else if (shipsini.got_key_float("turnspeed", f)) { - math::clamp(f, 0.0f, 90.0f); - shipmodel->set_turnspeed(f); + } else if (shipsini.got_key_float("strafe", f)) { + shipmodel->set_strafe_force(f); + continue; + } else if (shipsini.got_key_float("torque", f)) { + shipmodel->set_torque_force(f); + continue; + } else if (shipsini.got_key_float("mass", f)) { + shipmodel->set_mass(f); continue; } else { shipsini.unkown_key(); @@ -115,11 +123,15 @@ bool ShipModel::init() ShipModel::ShipModel() : core::Info(shipmodel_infotype) { + shipmodel_maxspeed = 0; //default specifications - shipmodel_acceleration = 1.0f; // thruster acceleration in game untits/second^2 - shipmodel_maxspeed = 3.0f; // maximum thruster speed in game units/second - shipmodel_turnspeed = 45.0f; // 45 degrees per second - shipmodel_maxcargo = 0; + shipmodel_mass = 10.0f; + shipmodel_thrust_force = 0.8f; + shipmodel_impulse_force = 4.0f; + shipmodel_strafe_force = 0.1f; + shipmodel_torque_force = 2.5f; + + shipmodel_maxcargo = 0.0f; shipmodel_jumpdrive = false; // no jumpdrive capability shipmodel_dock = false; // not dockable @@ -150,14 +162,10 @@ void ShipModel::generate_info() add_text(str.str()); str.str(""); - str << "response: ^B" << turnspeed() << " ^Ndps"; + str << "mass: ^B" << mass() << " ^Nmetric tonnes"; add_text(str.str()); str.str(""); - - str << "acceleration: ^B" << acceleration() << " ^Nstandard"; - add_text(str.str()); - str.str(""); - + if (jumpdrive()) { add_text("^Bhyperspace jump drive"); } diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h index a7c8500..e90c59e 100644 --- a/src/game/base/shipmodel.h +++ b/src/game/base/shipmodel.h @@ -37,21 +37,36 @@ public: return shipmodel_dock; } - /// acceleration - inline const float acceleration() const { - return shipmodel_acceleration; + /// default mass + inline const float mass() const { + return shipmodel_mass; + } + + /// default impulse drive force + inline const float impulse_force() const { + return shipmodel_impulse_force; + } + + /// default thruster force + inline const float thrust_force() const { + return shipmodel_thrust_force; + } + + /// default strafe force + inline const float strafe_force() const { + return shipmodel_strafe_force; + } + + /// default torque force + inline const float torque_force() const { + return shipmodel_torque_force; } - /// maximum speed + /// maximum thrust speed inline const float maxspeed() const { return shipmodel_maxspeed; } - - /// turn speed in rotations per second - inline const float turnspeed() const { - return shipmodel_turnspeed; - } - + /// size of the cargo hold, in cubic meters inline const float maxcargo() const { return shipmodel_maxcargo; @@ -59,21 +74,37 @@ public: /* ---- mutators -------------------------------------------------- */ - /// set acceleration - inline void set_acceleration(const float acceleration) { - shipmodel_acceleration = acceleration; + /// set mass + inline void set_mass(const float mass) { + shipmodel_mass = mass; + } + + /// set impulse drive force + inline void set_impulse_force(const float impulse) { + shipmodel_impulse_force = impulse; + + } + + /// set thruster force + inline void set_thrust_force(const float thrust) { + shipmodel_thrust_force = thrust; + } + + /// set strafe force + inline void set_strafe_force(const float strafe) { + shipmodel_strafe_force = strafe; + } + + /// set torque force + inline void set_torque_force(const float torque) { + shipmodel_torque_force = torque; } /// set maximum speed inline void set_maxspeed(const float maxspeed) { shipmodel_maxspeed = maxspeed; } - - /// set turn speed - inline void set_turnspeed(const float turnspeed) { - shipmodel_turnspeed = turnspeed; - } - + /// set size of the cargo hold inline void set_maxcargo(const float maxcargo) { shipmodel_maxcargo = maxcargo; @@ -105,14 +136,18 @@ public: static core::InfoType *shipmodel_infotype; -private: - bool shipmodel_jumpdrive; - bool shipmodel_dock; +private: + float shipmodel_mass; + float shipmodel_impulse_force; + float shipmodel_thrust_force; + float shipmodel_strafe_force; + float shipmodel_torque_force; - float shipmodel_acceleration; - float shipmodel_maxspeed; - float shipmodel_turnspeed; + float shipmodel_maxspeed; float shipmodel_maxcargo; + + bool shipmodel_jumpdrive; + bool shipmodel_dock; }; } -- cgit v1.2.3