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 /src/core/zone.cc
parent164e3c5b1cd9e6d6f7ca26964df4c54394eb1c84 (diff)
Improved list_zone, list_ships
Ship price and cargo size
Diffstat (limited to 'src/core/zone.cc')
-rw-r--r--src/core/zone.cc113
1 files changed, 74 insertions, 39 deletions
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 << " ";