diff options
Diffstat (limited to 'src/game/base/shipmodel.cc')
-rw-r--r-- | src/game/base/shipmodel.cc | 52 |
1 files changed, 45 insertions, 7 deletions
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) { |