Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-12-25 12:13:56 +0000
committerStijn Buys <ingar@osirion.org>2008-12-25 12:13:56 +0000
commitbfa10f9990a8a045b03474d11af75984c12a856a (patch)
tree87ff30329be78b8012d545b097b669b746ab0fc0
parent164e3c5b1cd9e6d6f7ca26964df4c54394eb1c84 (diff)
Improved list_zone, list_ships
Ship price and cargo size
-rw-r--r--doc/STORYLINE17
-rw-r--r--doc/models.html29
-rw-r--r--osirion.kdevelop18
-rw-r--r--src/core/commandbuffer.cc8
-rw-r--r--src/core/player.cc10
-rw-r--r--src/core/player.h27
-rw-r--r--src/core/zone.cc113
-rw-r--r--src/core/zone.h13
-rw-r--r--src/filesystem/inifile.cc12
-rw-r--r--src/filesystem/inifile.h2
-rw-r--r--src/game/base/game.cc44
-rw-r--r--src/game/base/ship.cc8
-rw-r--r--src/game/base/shipdealer.cc36
-rw-r--r--src/game/base/shipmodel.cc52
-rw-r--r--src/game/base/shipmodel.h64
15 files changed, 310 insertions, 143 deletions
diff --git a/doc/STORYLINE b/doc/STORYLINE
index 06de127..06831a2 100644
--- a/doc/STORYLINE
+++ b/doc/STORYLINE
@@ -42,7 +42,7 @@
planet Brogha
Cantor observatory
- - Whendune system
+ - Antwerp system
HOUSE LINDBLADE
@@ -89,8 +89,8 @@
------------------------------------------------------------------
TIMELINE
- Exodus -5000 years
- Great War -300 years
+ Exodus -5300 years
+ Great War -300 years
The Karelian Incident -50 years
------------------------------------------------------------------
@@ -210,11 +210,20 @@ The Alliance
through the Emperial forces like a knight with his spear, gave birth to the name
"Battle of The Lance".
-Turning of the Tide
+Wrath of the Fallen
+ The death of their Supreme Commander came as a shock to the Tsu-Khan. No one had expected
+ any serious level of resistance from tehese primitive humands, and a succesfull attack on
+ their fleet had been considered extremely unlikely. A wave of wrath and bloodlust swept
+ through the Empire, and left it with only one purpose: the total annihilation of mankind.
+
+ Their wrath was brutal.
+
+ // explain it took another 4 years of messing around to finish the war
Project Osirion
+
The Karelian Incident
diff --git a/doc/models.html b/doc/models.html
index 28ba9c7..740bc3d 100644
--- a/doc/models.html
+++ b/doc/models.html
@@ -224,11 +224,19 @@
small diference: the size of the flare is set through the radius
value. The default flare radius is 100. Rotate the entity or set the
angle value to point the flare in a different direction.
-<p>
- Use the <i>engine</i> option (spawnflag 4) To create a flare that
+</p><p>
+ Setting the <i>entity</i> option (spawnflag 2) will assign the entities
+ primary colour as flare colour.
+</p><p>
+ Use the <i>engine</i> option (spawnflag 4) to create a flare that
lights up depending on engine power.
-<p>
- <i>fx_flare</i> entities can only be rotated in the XY-plane.
+</p><p>
+ The direction of the flare can be set with the <i>direction</i>,
+ <i>pitch</i> and <i>roll</i> keys. <i>angle</i> is an alias for
+ <i>direction</i>.
+</p><p>
+ Flares will only be rendered if the entity is within detail range.
+</p>
<h2 id="particles">
Particles
@@ -240,7 +248,17 @@
</p><p>
The <i>script</i> value must be set to the label of the particles script.
</p><p>
- Particles will only be rendered if the model is within detail range.
+ Setting the <i>entity</i> option (spawnflag 2) will assign the entities
+ primary colour as particle system colour.
+</p><p>
+ Use the <i>engine</i> option (spawnflag 4) will assign the models engine colour
+ as particle system colour.
+</p><p>
+ The direction of the particle system can be set with the <i>direction</i>,
+ <i>pitch</i> and <i>roll</i> keys. <i>angle</i> is an alias for
+ <i>direction</i>.
+</p><p>
+ Particles will only be rendered if the entity is within detail range.
</p>
<h2 id="groups">
Function groups
@@ -258,6 +276,7 @@
<p>
<i>func_rotate</i> will create a rotating set of brushes. The center of the rotation
is automaticly calculated as the geometrical center of the group.
+ The rotation axis can be set with the <i>direction</i>, <i>pitch</i> and <i>roll</i> keys. <i>angle</i> is an alias for <i>direction</i>.
</p>
<h2 id="other_entities">
Other entities
diff --git a/osirion.kdevelop b/osirion.kdevelop
index a93ecf7..2c29f57 100644
--- a/osirion.kdevelop
+++ b/osirion.kdevelop
@@ -16,12 +16,12 @@
<projectdirectory>./</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description>The OSiRiON Project is an SDL+OpenGL space game.</description>
- <defaultencoding/>
- <versioncontrol/>
+ <defaultencoding></defaultencoding>
+ <versioncontrol></versioncontrol>
</general>
<kdevautoproject>
<general>
- <activetarget>tools/zone2map</activetarget>
+ <activetarget>src/osirion</activetarget>
<useconfiguration>debug</useconfiguration>
</general>
<run>
@@ -196,7 +196,7 @@
<designerpluginpaths/>
</qt>
<creategettersetter>
- <prefixGet/>
+ <prefixGet></prefixGet>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
@@ -228,11 +228,11 @@
</cppsupportpart>
<kdevdebugger>
<general>
- <gdbpath/>
- <dbgshell/>
- <configGdbScript/>
- <runShellScript/>
- <runGdbScript/>
+ <gdbpath></gdbpath>
+ <dbgshell></dbgshell>
+ <configGdbScript></configGdbScript>
+ <runShellScript></runShellScript>
+ <runGdbScript></runGdbScript>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 98cdc7a..e042eec 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -55,11 +55,9 @@ void func_list_ent(std::string const &args)
void func_list_zone(std::string const &args)
{
- std::istringstream argstream(args);
- std::string zonelabel;
- if (argstream >> zonelabel) {
- aux::lowercase(zonelabel);
- Zone::list_zone(zonelabel);
+ Zone *zone = Zone::search(args);
+ if (zone) {
+ zone->print();
} else {
Zone::list();
}
diff --git a/src/core/player.cc b/src/core/player.cc
index f968fc3..b499003 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -93,6 +93,16 @@ void Player::set_mission_target(Entity *new_mission_target)
}
}
+void Player::set_credits(long amount)
+{
+ player_credits = amount;
+}
+
+void Player::add_credits(long amount)
+{
+ player_credits += amount;
+}
+
void Player::update_info()
{
Cvar *cl_name = Cvar::find("cl_name");
diff --git a/src/core/player.h b/src/core/player.h
index 620f086..ecb9ea3 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -35,13 +35,13 @@ public:
/*----- inspectors ------------------------------------------------ */
/// id of the player
- inline int id() const { return player_id; }
+ inline const int id() const { return player_id; }
/// name of the player
- inline std::string const &name() const { return player_name; }
+ inline const std::string & name() const { return player_name; }
/// dirty flag
- inline bool dirty() const { return player_dirty; }
+ inline const bool dirty() const { return player_dirty; }
/// the entity the Player is currently controling
inline EntityControlable *control() const { return player_control; }
@@ -57,16 +57,16 @@ public:
/// set the zone the player is currently in
void set_zone(Zone *zone);
- inline bool zonechange() const { return player_zonechange; }
+ inline const bool zonechange() const { return player_zonechange; }
/// player primary color
- inline math::Color const & color() const { return player_color; }
+ inline const math::Color & color() const { return player_color; }
/// player secondary color
- inline math::Color const & color_second() const { return player_color_second; }
+ inline const math::Color & color_second() const { return player_color_second; }
/// player has been muted by admin or console
- inline bool mute() const { return player_mute; }
+ inline const bool mute() const { return player_mute; }
inline const std::string &rconpassword() const { return player_rconpassword; }
@@ -76,6 +76,12 @@ public:
/// view
inline Entity *view() { return player_view; }
+ /// credits
+ inline long credits() const { return player_credits; }
+
+ /// returns true of the player has enough credits to pay amount
+ inline bool has_credits(unsigned amount) const { return (player_credits >= amount); }
+
/*----- messages -------------------------------------------------- */
void send(const std::string name);
@@ -120,8 +126,13 @@ public:
void set_view(Entity *view);
+ void set_credits(long amount);
+
+ void add_credits(long amount);
+
inline void set_dirty() { player_dirty = true; }
+
/* -- should actually not be public --*/
/// dirty state
@@ -159,7 +170,7 @@ private:
// the zone the player is currently in
Zone *player_zone;
- float player_credits;
+ long player_credits;
std::string player_rconpassword;
};
diff --git a/src/core/zone.cc b/src/core/zone.cc
index 5d9c48f..3567090 100644
--- a/src/core/zone.cc
+++ b/src/core/zone.cc
@@ -55,20 +55,38 @@ Zone *Zone::find(std::string const & name)
return 0;
}
-Zone *Zone::find_zone(std::string const & searchname)
+
+Zone *Zone::search(std::string const & searchname)
{
- std::stringstream str(aux::lowercase(searchname));
+ std::string strsearchkey(aux::lowercase(searchname));
+ std::stringstream str(strsearchkey);
+
unsigned int id;
- Zone *zone = 0;
- if (str >> id) {
- zone = find(id);
- }
+ if (str >> id)
+ return find(id);
- if (!zone) {
- zone = find(searchname);
+ if (strsearchkey.size() < 3) {
+ return 0;
+ }
+
+ std::string label;
+ std::string name;
+
+ for (Registry::iterator it = zone_registry.begin(); it != zone_registry.end(); it++) {
+ Zone *zone = (*it).second;
+
+ label.assign(zone->label());
+ if (label.size() && (label.find(strsearchkey) != std::string::npos)) {
+ return zone;
+ }
+
+ name.assign(aux::lowercase(zone->name()));
+ if (name.size() && (name.find(strsearchkey) != std::string::npos)) {
+ return zone;
+ }
}
- return zone;
+ return 0;
}
void Zone::list()
@@ -80,36 +98,6 @@ void Zone::list()
con_print << zone_registry.size() << " registered zones" << std::endl;
}
-void Zone::list_zone(std::string const & searchname)
-{
- std::stringstream str(aux::lowercase(searchname));
- unsigned int id;
- Zone *zone = 0;
- if (str >> id) {
- zone = find(id);
- }
-
- if (!zone) {
- zone = find(searchname);
- }
-
- if (!zone) {
- con_print << "Unknown zone '" << searchname << "'" << std::endl;
- } else {
- con_print << "zone " << zone->id() << " " << zone->label() << " " << zone->name() << std::endl;
-
- for (Content::iterator it = zone->zone_content.begin(); it != zone->zone_content.end(); it++) {
- Entity *entity = (*it);
- con_print << " id " << std::setw(4) << entity->id()
- << " type " << std::setw(4) << entity->type()
- << ":" << std::setw(4) << entity->moduletype()
- << " " << std::setw(24) << entity->label()
- << " ^B" << entity->name() << "^N" << std::endl;
- }
- con_print << zone->zone_content.size() << " zone entities" << std::endl;
- }
-}
-
void Zone ::clear()
{
for (Registry::iterator it = zone_registry.begin(); it != zone_registry.end(); it++) {
@@ -145,6 +133,20 @@ Zone::~Zone()
zone_content.clear();
}
+void Zone::print()
+{
+ con_print << "id: ^B" << id() << " ^Nlabel: ^B" << label() << " ^Nname: ^B" << name() << std::endl;
+ for (Content::iterator it = zone_content.begin(); it != zone_content.end(); it++) {
+ Entity *entity = (*it);
+ con_print << " id " << std::setw(4) << entity->id()
+ << " type " << std::setw(4) << entity->type()
+ << ":" << std::setw(4) << entity->moduletype()
+ << " " << std::setw(24) << entity->label()
+ << " ^B" << entity->name() << "^N" << std::endl;
+ }
+ con_print << zone_content.size() << " registered zone entities" << std::endl;
+}
+
void Zone::add(Entity *entity)
{
zone_content.push_back(entity);
@@ -193,6 +195,39 @@ Entity *Zone::find_entity(const std::string & label)
return 0;
}
+Entity *Zone::search_entity(const std::string & searchname)
+{
+ std::string strsearchkey(aux::lowercase(searchname));
+ std::stringstream str(strsearchkey);
+
+ unsigned int id;
+ if (str >> id)
+ return find_entity(id);
+
+ if (strsearchkey.size() < 3) {
+ return 0;
+ }
+
+ std::string label;
+ std::string name;
+
+ for (Content::iterator it = zone_content.begin(); it != zone_content.end(); it++) {
+ Entity *entity = (*it);
+
+ label.assign(entity->label());
+ if (label.size() && (label.find(strsearchkey) != std::string::npos)) {
+ return entity;
+ }
+
+ name.assign(aux::lowercase(entity->name()));
+ if (name.size() && (name.find(strsearchkey) != std::string::npos)) {
+ return entity;
+ }
+ }
+
+ return 0;
+}
+
void Zone::serialize_server_update(std::ostream & os) const
{
os << zone_label << " ";
diff --git a/src/core/zone.h b/src/core/zone.h
index 4b64ffb..f93cea2 100644
--- a/src/core/zone.h
+++ b/src/core/zone.h
@@ -45,17 +45,14 @@ public:
/// find a zone in the zone registry
static Zone *find(std::string const & name);
- /// find a zone in the zone registry (searches on id and name)
- static Zone *find_zone(std::string const & searchname);
-
/// remove a zone from the zone registry
static void remove(Zone *zone);
/// list the zone registry
static void list();
- /// list the content of a single zone
- static void list_zone(std::string const & searchname);
+ /// search the zone registry for an id, label or name
+ static Zone *search(std::string const & searchname);
/// clear the zone registry
static void clear();
@@ -76,6 +73,9 @@ public:
/* ---- inspectors ----------------------------------------- */
+ /// print the content of a zone
+ void print();
+
/// zone id
inline unsigned int id() const { return zone_id; }
@@ -103,6 +103,9 @@ public:
/// find a labeled entity inside a zone
Entity *find_entity(const std::string & label);
+ /// search for an entity inside a zone
+ Entity *search_entity(const std::string & label);
+
/* ---- mutators ------------------------------------------- */
/// set the Zone label
diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc
index ddb1c63..96bfd55 100644
--- a/src/filesystem/inifile.cc
+++ b/src/filesystem/inifile.cc
@@ -161,6 +161,18 @@ bool IniFile::got_key_float(const char * keylabel, float & f) {
}
}
+bool IniFile::got_key_long(const char * keylabel, long & l) {
+ if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+ std::istringstream is(value_current);
+ if (!(is >> l)) {
+ l = 0;
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
bool IniFile::got_key(const char * keylabel) {
return (last_read_was_key && (key_current.compare(keylabel) == 0 ));
}
diff --git a/src/filesystem/inifile.h b/src/filesystem/inifile.h
index f118f7b..f064bc7 100644
--- a/src/filesystem/inifile.h
+++ b/src/filesystem/inifile.h
@@ -72,6 +72,8 @@ public:
bool got_key_angle(const char * keylabel, float & f);
+ bool got_key_long(const char * keylabel, long & l);
+
bool got_key_vector3f(const char * keylabel, math::Vector3f & v);
bool got_key_bool(const char * keylabel, bool & b);
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 48e1b05..c591ba4 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -47,7 +47,12 @@ core::Module *factory()
// list the ship model registry
void Game::func_list_ship(std::string const &args)
{
- ShipModel::list();
+ ShipModel *shipmodel = ShipModel::search(args);
+
+ if (shipmodel)
+ shipmodel->print();
+ else
+ ShipModel::list();
}
// a player joins the game
@@ -233,19 +238,7 @@ void Game::func_goto(core::Player *player, const std::string &args)
if (!player->control())
return;
- core::Entity *dock = 0;
- std::string label(args);
- aux::to_label(label);
-
- core::Zone *zone = player->control()->zone();
- for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it ++) {
- std::string str((*it)->label());
- aux::to_label(str);
- if (str.find(label) != std::string::npos) {
- dock = (*it);
- }
- }
-
+ core::Entity *dock = player->control()->zone()->search_entity(args);
if (dock) {
player->control()->entity_location.assign(dock->location() + (dock->axis().forward() * (player->control()->radius()+dock->radius())*2.0f));
player->control()->entity_axis.assign(dock->axis());
@@ -752,6 +745,8 @@ bool Game::load_ships()
ShipModel *shipmodel = 0;
std::string label;
bool b;
+ long l;
+ float f;
while (shipsini.getline()) {
if (shipsini.got_key()) {
@@ -768,17 +763,26 @@ bool Game::load_ships()
} else if (shipsini.got_key_bool("default", b)) {
if (b) default_shipmodel = shipmodel;
continue;
+ } else if (shipsini.got_key_long("price", l)) {
+ shipmodel->set_price(l);
+ continue;
+ } else if (shipsini.got_key_float("cargo", f)) {
+ shipmodel->set_maxcargo(f);
+ continue;
} else if (shipsini.got_key_bool("jumpdrive", shipmodel->shipmodel_jumpdrive)) {
continue;
- } else if (shipsini.got_key_float("acceleration", shipmodel->shipmodel_acceleration)) {
+ } else if (shipsini.got_key_float("acceleration",f)) {
+ shipmodel->set_acceleration(f);
continue;
- } else if (shipsini.got_key_float("maxspeed", shipmodel->shipmodel_maxspeed)) {
+ } else if (shipsini.got_key_float("maxspeed", f)) {
+ shipmodel->set_maxspeed(f);
continue;
- } else if (shipsini.got_key_float("turnspeed", shipmodel->shipmodel_turnspeed)) {
- math::clamp(shipmodel->shipmodel_turnspeed, 0.0f, 90.0f);
+ } else if (shipsini.got_key_float("turnspeed", f)) {
+ math::clamp(f, 0.0f, 90.0f);
+ shipmodel->set_turnspeed(f);
continue;
} else {
- con_warn << shipsini.name() << " unknown key '" << shipsini.key() << "' at line " << shipsini.line() << std::endl;
+ shipsini.unkown_key();
}
}
} else if (shipsini.got_section("ship")) {
@@ -788,7 +792,7 @@ bool Game::load_ships()
default_shipmodel = shipmodel;
} else if (shipsini.got_section()) {
- con_warn << shipsini.name() << " unknown section '" << shipsini.section() << "' at line " << shipsini.line() << std::endl;
+ shipsini.unknown_section();
}
}
shipsini.close();
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index d0bea4a..c48bf7a 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -122,18 +122,14 @@ void Ship::func_jump(std::string const &args)
// devel mode provides instant jump access to arbitrary systems
if (Game::g_devel->value() && (args.size())) {
- core::Zone *jumptargetzone = 0;
- std::string target(args);
+ core::Zone *jumptargetzone = core::Zone::search(args);
- aux::to_lowercase(target);
- jumptargetzone = core::Zone::find_zone(target);
if (!jumptargetzone) {
std::string helpstr;
for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
- core::Zone *zone = (*it).second;
if (helpstr.size())
helpstr.append("^N|^B");
- helpstr.append(zone->label());
+ helpstr.append((*it).second->label());
}
owner()->send("Usage: jump [^B" + helpstr + "^N]");
return;
diff --git a/src/game/base/shipdealer.cc b/src/game/base/shipdealer.cc
index fb6415c..c1d3b10 100644
--- a/src/game/base/shipdealer.cc
+++ b/src/game/base/shipdealer.cc
@@ -67,41 +67,33 @@ ShipModel *ShipDealer::find(ShipModel *shipmodel) const
void ShipDealer::func_buy(core::Player *player, const std::string &args)
{
core::Entity *dock = player->view();
- ShipModel *shipmodel = 0;
+
ShipDealer *shipdealer = 0;
// find the ship model
- std::string shipname;
- std::string helpstr;
- std::istringstream is(args);
- is >> shipname;
- aux::to_label(shipname);
-
- if (shipname.size()) {
- 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).first);
- }
- }
-
+ ShipModel *shipmodel = ShipModel::find(args);
if (!shipmodel) {
if (!Game::g_devel->value()) {
player->send("Cheats disabled");
return;
-
} else {
+ shipmodel = ShipModel::search(args);
+ }
+ }
+
+ if (!shipmodel) {
+ std::string helpstr;
+ for (ShipModel::iterator smit = ShipModel::registry.begin(); smit != ShipModel::registry.end(); smit++) {
+ if (helpstr.size())
+ helpstr.append("^N|^B");
+ helpstr.append((*smit).second->label());
+
player->send("Usage: buy [^B" + helpstr + "^N]");
return;
}
}
- /// find the ship dealer we're buying the ship from
+ // find the ship dealer we're buying the ship from
if (player->view()) {
if (player->view()->moduletype() == station_enttype) {
shipdealer = static_cast<Station *>(player->view())->shipdealer();
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index b4b60f4..78dc125 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -4,8 +4,11 @@
the terms and conditions of the GNU General Public License version 2
*/
-#include "sys/sys.h"
+#include <iomanip>
+
+#include "auxiliary/functions.h"
#include "base/shipmodel.h"
+#include "sys/sys.h"
namespace game {
@@ -18,6 +21,8 @@ ShipModel::ShipModel()
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_price = 0; // the ship is for free by default
+ shipmodel_maxcargo = 0;
shipmodel_jumpdrive = false;
}
@@ -35,15 +40,21 @@ void ShipModel::clear()
registry.clear();
}
+void ShipModel::print()
+{
+ con_print << "label: ^B" << label() << " ^Nname: ^B" << name() << std::endl;
+ con_print << " acceleration: ^B" << acceleration() << std::endl;
+ con_print << " turnspeed: ^B" << turnspeed() << std::endl;
+ con_print << " max speed: ^B" << maxspeed() << std::endl;
+ con_print << " max cargo: ^B" << maxcargo() << std::endl;
+ con_print << " price: ^B" << price() << std::endl;
+}
+
void ShipModel::list()
{
for (iterator smit = registry.begin(); smit != registry.end(); smit++) {
- con_print <<
- " " << (*smit).second->label() <<
- " " << (*smit).second->name() <<
- " accel " << (*smit).second->acceleration() <<
- " max " << (*smit).second->maxspeed() <<
- " turn " << (*smit).second->turnspeed() << "\n";
+ con_print << std::setw(24) << (*smit).second->label()
+ << " ^B" << (*smit).second->name() << "\n";
}
con_print << registry.size() << " registered ship models\n";
}
@@ -67,6 +78,33 @@ ShipModel *ShipModel::find(const std::string label)
return (*it).second;
}
+ShipModel *ShipModel::search(const std::string searchname)
+{
+ std::string strsearchkey(aux::lowercase(searchname));
+ if (strsearchkey.size() < 3) {
+ return 0;
+ }
+
+ std::string label;
+ std::string name;
+
+ for (iterator smit = registry.begin(); smit != registry.end(); smit++) {
+ ShipModel *shipmodel = (*smit).second;
+
+ label.assign(shipmodel->label());
+ if (label.size() && (label.find(strsearchkey) != std::string::npos)) {
+ return shipmodel;
+ }
+
+ name.assign(aux::lowercase(shipmodel->name()));
+ if (name.size() && (name.find(strsearchkey) != std::string::npos)) {
+ return shipmodel;
+ }
+ }
+
+ return 0;
+}
+
// add a new ship model
void ShipModel::add(ShipModel *shipmodel)
{
diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h
index 6452b8d..c194dc0 100644
--- a/src/game/base/shipmodel.h
+++ b/src/game/base/shipmodel.h
@@ -19,42 +19,70 @@ public:
ShipModel();
~ShipModel();
+ void print();
+
/// acceleration
- inline float acceleration() const { return shipmodel_acceleration; }
+ inline const float acceleration() const { return shipmodel_acceleration; }
/// maximum speed
- inline float maxspeed() const { return shipmodel_maxspeed; }
+ inline const float maxspeed() const { return shipmodel_maxspeed; }
/// turn speed in rotations per second
- inline float turnspeed() const { return shipmodel_turnspeed; }
+ inline const float turnspeed() const { return shipmodel_turnspeed; }
/// label of the ship model
- inline std::string const &label() const { return shipmodel_label; }
+ inline const std::string &label() const { return shipmodel_label; }
/// name of the ship model
- inline std::string const & name() const { return shipmodel_name; }
+ inline const std::string & name() const { return shipmodel_name; }
/// name of the model of the ship
- inline std::string const & modelname() const { return shipmodel_modelname; }
+ inline const std::string & modelname() const { return shipmodel_modelname; }
+
+ /// price of the ship
+ inline const long price() const { return shipmodel_price; }
+
+ /// size of the cargo hold
+ inline const float maxcargo() const { return shipmodel_maxcargo; }
+
+ /// set acceleration
+ inline void set_acceleration(const float acceleration) { shipmodel_acceleration = acceleration; }
+
+ /// 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 price
+ inline void set_price(const long price) { shipmodel_price = price; }
+
+ /// set size of the cargo hold
+ inline void set_maxcargo(const float maxcargo) { shipmodel_maxcargo = maxcargo; }
+
+ /// indicates of this model can be equiped with a jump drive
+ bool shipmodel_jumpdrive;
- float shipmodel_acceleration;
- float shipmodel_maxspeed;
- float shipmodel_turnspeed;
std::string shipmodel_label;
std::string shipmodel_name;
std::string shipmodel_modelname;
- /// indicates of this model can be equiped with a jump drive
- bool shipmodel_jumpdrive;
+ /* ---- static registry ------------------------------------ */
+
+ typedef std::map<std::string, ShipModel *>::iterator iterator;
+ /// find an exact match
static ShipModel *find(ShipModel *shipmodel);
+
+ /// find an exact match
static ShipModel *find(const std::string label);
+ /// search the registry
+ static ShipModel *search(const std::string label);
+
/// the ship model registry
static std::map<std::string, ShipModel *> registry;
- typedef std::map<std::string, ShipModel *>::iterator iterator;
-
/// clear the ship model registry
static void clear();
@@ -63,6 +91,16 @@ public:
/// add a new ship model
static void add(ShipModel *shipmodel);
+
+private:
+
+ float shipmodel_acceleration;
+ float shipmodel_maxspeed;
+ float shipmodel_turnspeed;
+ float shipmodel_maxcargo;
+
+ long shipmodel_price;
+
};
}