Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/game.cc17
-rw-r--r--src/game/base/ship.cc43
-rw-r--r--src/game/base/ship.h5
-rw-r--r--src/game/base/shipmodel.cc34
-rw-r--r--src/game/base/shipmodel.h14
5 files changed, 80 insertions, 33 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index d80fb3e..c8f3cc6 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -32,7 +32,7 @@
namespace game
{
-/* -- class Default ----------- ----------------------------------- */
+/* -- class Default ----------------------------------------------- */
// default player settings
core::Zone *Default::zone = 0;
@@ -1348,6 +1348,21 @@ bool Game::load_zone(core::Zone *zone)
} else {
entitytemplate->apply(entity);
}
+ } else if (zoneini.got_key_label("ship", strval)) {
+ ShipModel *shipmodel = ShipModel::find(strval);
+ if (!shipmodel) {
+ zoneini.unknown_error("unkown ship type '" + strval + "'");
+ } else {
+ shipmodel->apply(entity);
+ }
+
+ } else if (zoneini.got_key_label("ship", strval)) {
+ ShipModel *shipmodel = ShipModel::find(strval);
+ if (!shipmodel) {
+ zoneini.unknown_error("unkown ship type '" + strval + "'");
+ } else {
+ // TODO apply ship model
+ }
} else {
zoneini.unkown_key();
}
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index f88afd1..b8dc6d0 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -27,24 +27,19 @@ const float MIN_DELTA = 0.000001f;
Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityControlable()
{
assert(shipmodel);
- ship_shipmodel = shipmodel;
entity_moduletypeid = ship_enttype;
set_radius(0);
- // apply template settings
- if (ship_shipmodel->model_template()) {
- ship_shipmodel->model_template()->apply(this);
- }
+ ship_shipmodel = shipmodel;
+ ship_impulsedrive_timer = 0;
+ ship_jumpdrive_timer = 0;
+ ship_jumpdepart = 0;
+
+ // apply ship type settings
+ ship_shipmodel->apply(this);
- // apply ship model settings
- // shipmodel overrides template model and radius
- if (ship_shipmodel->modelname().size()) {
- set_modelname(ship_shipmodel->modelname());
- }
- if (ship_shipmodel->radius()) {
- set_radius(ship_shipmodel->radius());
- }
+ // radius fallback values
if (!radius()) {
if (model()) {
set_radius(model()->radius());
@@ -53,15 +48,7 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
if (!radius()) {
set_radius(0.5f);
}
-
- set_name(ship_shipmodel->name());
- set_info(ship_shipmodel);
-
- ship_jumpdrive = ship_shipmodel->jumpdrive();
- ship_impulsedrive_timer = 0;
- ship_jumpdrive_timer = 0;
- ship_jumpdepart = 0;
-
+
if (owner) {
// this ship is owned by a player,
// player colors override template colors
@@ -75,10 +62,9 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
// add an inventory
set_inventory(new core::Inventory());
inventory()->set_capacity(ship_shipmodel->maxcargo());
- } else {
- set_label(ship_shipmodel->label());
}
+ // menus for docked players
if (ship_shipmodel->dockable()) {
using core::MenuDescription;
using core::ButtonDescription;
@@ -97,18 +83,11 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
set_flag(core::Entity::Dockable);
}
- set_mass(ship_shipmodel->mass());
- set_impulse_force(ship_shipmodel->impulse_force());
- set_thrust_force(ship_shipmodel->thrust_force());
- set_strafe_force(ship_shipmodel->strafe_force());
- set_turn_force(ship_shipmodel->turn_force());
- set_roll_force(ship_shipmodel->roll_force());
-
+ // initialize physics
reset();
const float linear_damp = 0.8f;
const float angular_damp = 0.8f;
-
body()->setDamping(linear_damp, angular_damp);
}
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index ade7ff7..033f497 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -67,6 +67,11 @@ public:
return ship_jumpdrive;
}
+ /// set jumpdrive capability
+ inline void set_jumpdrive(const bool jumpdrive) {
+ ship_jumpdrive = jumpdrive;
+ }
+
/// set impulse drive force
inline void set_impulse_force(const float impulse) {
ship_impulse_force = impulse;
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index d9a9ed7..412fd14 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -339,4 +339,38 @@ void ShipModel::buy(core::EntityControlable *buyer, core::Entity *seller)
}
+void ShipModel::apply(core::Entity *entity) const
+{
+ // apply template settings if available
+ if (model_template())
+ model_template()->apply(entity);
+
+ // apply entity settings
+ if (label().size())
+ entity->set_label(label());
+
+ if (name().size())
+ entity->set_name(name());
+
+ if (modelname().size())
+ entity->set_modelname(modelname());
+
+ if (radius())
+ entity->set_radius(radius());
+}
+
+void ShipModel::apply(Ship *ship) const
+{
+ // apply ship model settings
+ apply (static_cast<core::Entity *>(ship));
+
+ ship->set_mass(mass());
+ ship->set_impulse_force(impulse_force());
+ ship->set_thrust_force(thrust_force());
+ ship->set_strafe_force(strafe_force());
+ ship->set_turn_force(turn_force());
+ ship->set_roll_force(roll_force());
+ ship->set_jumpdrive(jumpdrive());
+}
+
}
diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h
index 25473d4..bbb5798 100644
--- a/src/game/base/shipmodel.h
+++ b/src/game/base/shipmodel.h
@@ -16,6 +16,8 @@
namespace game
{
+class Ship;
+
/// ship model specification
class ShipModel : public core::Info
{
@@ -87,6 +89,18 @@ public:
inline const Template *model_template() const {
return shipmodel_template;
}
+
+ /* ---- actors ---------------------------------------------------- */
+
+ /**
+ * @brief apply ship type settings to an entity
+ */
+ void apply(core::Entity *entity) const;
+
+ /**
+ * @brief apply ship type settings to a ship
+ */
+ void apply(Ship *ship) const;
protected: