diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/commandbuffer.cc | 8 | ||||
-rw-r--r-- | src/core/player.cc | 10 | ||||
-rw-r--r-- | src/core/player.h | 27 | ||||
-rw-r--r-- | src/core/zone.cc | 113 | ||||
-rw-r--r-- | src/core/zone.h | 13 |
5 files changed, 114 insertions, 57 deletions
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 |