diff options
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r-- | src/core/entity.cc | 69 |
1 files changed, 53 insertions, 16 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 08fddbf..ece1e9b 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -13,6 +13,7 @@ #include "core/entity.h" #include "core/cvar.h" #include "core/application.h" +#include "core/gameinterface.h" namespace core { @@ -71,18 +72,42 @@ void Entity::erase(unsigned int id) } } +void Entity::clear() +{ + for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { + delete(*it).second; + } + Entity::registry().clear(); + entity_nextid = 0; +} + +void Entity::list_header() +{ + con_print << " " + << " id " + << "type " + << "label " + << "name" << std::endl; +} + +void Entity::list(const Entity *entity) +{ + con_print << " " + << "^B" << std::setw(4) << entity->id() << " " + << "^B" << std::setfill('0') << std::setw(4) << entity->type() << ":" << std::setw(4) << entity->moduletype() << std::setfill(' ') << " " + << "^B" << aux::pad_right(entity->label(), 24) << " " + << "^N" << entity->name() << std::endl; +} + void Entity::list() { - Registry::iterator it; - for (it = entity_registry.begin(); it != entity_registry.end(); it++) { + list_header(); + for (Registry::iterator it = entity_registry.begin(); it != entity_registry.end(); it++) { std::string typeindicator; Entity *entity = (*it).second; - con_print << " id " << std::setw(4) << entity->id() - << " type " << std::setw(4) << entity->type() - << ":" << std::setw(4) << entity->moduletype() - << " " << entity->label() << std::endl; + list(entity); } - con_print << entity_registry.size() << " registered entities" << std::endl; + con_print << entity_registry.size() << " entities" << std::endl; } /* ---- class Entity ----------------------------------------------- */ @@ -241,9 +266,10 @@ void Entity::serialize_server_create(std::ostream & os) const << radius() << " " << std::setprecision(8) << entity_axis.forward() << " " << std::setprecision(8) << entity_axis.left() << " " - << label() << " " + << "\"" <<label() << "\" " << "\"" << name() << "\" " - << "\"" << (entity_model ? entity_model->name() : "") << "\" "; + << "\"" << (entity_model ? entity_model->name() : "") << "\" " + << (info() ? info()->id() : 0) << " "; } void Entity::receive_server_create(std::istream &is) @@ -252,6 +278,7 @@ void Entity::receive_server_create(std::istream &is) unsigned int zo; unsigned int o = 0; std::string n; + char c; is >> entity_moduletypeid; is >> entity_flags; @@ -284,24 +311,34 @@ void Entity::receive_server_create(std::istream &is) is >> entity_axis[1]; entity_axis[2] = math::crossproduct(entity_axis.forward(), entity_axis.left()); - char c; - is >> n; - set_label(n); + // read label n.clear(); - + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; + set_label(n); + // read name + n.clear(); while ((is.get(c)) && (c != '"')); while ((is.get(c)) && (c != '"')) n += c; set_name(n); - n.clear(); - + // read model name + n.clear(); while ((is.get(c)) && (c != '"')); while ((is.get(c)) && (c != '"')) n += c; - set_modelname(n); + + // read info id + is >> o; + if (o) + set_info(game()->info(o)); + else + set_info(0); + entity_dirty = false; } |