From 4c45315c9f76bc32e1015a2a2bd9b3ae635023a7 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 18 Nov 2012 16:34:29 +0000 Subject: ADded support for enitty information printing, print current armor values for ships, print death messages --- src/core/commandbuffer.cc | 20 +++++++++++--- src/core/entity.cc | 70 +++++++++++++++++++++++++++++++++-------------- src/core/entity.h | 19 +++++++++++-- 3 files changed, 82 insertions(+), 27 deletions(-) (limited to 'src/core') diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 78b76af..53d200f 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -121,9 +121,20 @@ void func_list_var(std::string const &args) Cvar::list(); } -void func_list_ent(std::string const &args) +void func_list_entity(std::string const &args) { - Entity::list(); + unsigned long id; + std::istringstream argstream(args); + if (argstream >> id) { + Entity *entity = Entity::find(id); + if (entity) { + entity->print(); + } else { + con_print << "Could not find entity with id " << id << std::endl; + } + } else { + Entity::list(); + } } void func_list_inventory(std::string const &args) @@ -133,7 +144,8 @@ void func_list_inventory(std::string const &args) if (argstream >> id) { Entity *entity = Entity::find(id); if (entity) { - entity->list_inventory(); + entity->print_header(); + entity->print_inventory(); } else { con_print << "Could not find entity with id " << id << std::endl; } @@ -269,7 +281,7 @@ void CommandBuffer::init() //con_debug << "Initializing command buffer...\n"; Func *func = 0; - func = Func::add("list_ent", (FuncPtr)func_list_ent); + func = Func::add("list_entity", (FuncPtr)func_list_entity); func->set_info("list entities"); func = Func::add("list_func", (FuncPtr)func_list_func); diff --git a/src/core/entity.cc b/src/core/entity.cc index 7ed1328..70d3a4f 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -86,26 +86,6 @@ void Entity::clear() entity_nextid = 0; } -void Entity::list_inventory() const -{ - con_print << " entity id ^B" << id() << " ^Nlabel ^B" << label() << " ^Nname ^B" << name() << std::endl; - if (!entity_inventory) { - con_print << "no inventory availble" << std::endl; - return; - } - - con_print << " ^Nitem info infotype amount" << std::endl; - for (Inventory::Items::const_iterator it = entity_inventory->items().begin(); it != entity_inventory->items().end(); it++) { - Item *item = (*it); - con_print << " " - << " ^B" << std::setw(4) << item->id() - << " ^N" << aux::pad_right((item->info()->type() ? item->info()->type()->label() : "NULL"), 8) - << " ^N" << aux::pad_right(item->info()->label(), 24) - << std::setw(5) << item->amount() << std::endl; - } - con_print << "^B " << entity_inventory->items().size() << " inventory items" << std::endl; -} - void Entity::list_header() { con_print << " " @@ -261,6 +241,56 @@ Entity::~Entity() } } +void Entity::print() const +{ + // print header + print_header(); + + // print entity flags + con_print << " flags ^B"; + + if (has_flag(NonSolid)) { + con_print << " nonsolid"; + } + if (has_flag(Bright)) { + con_print << " bright"; + } + if (has_flag(Dockable)) { + con_print << " dockable"; + } + if (has_flag(ShowOnMap)) { + con_print << " shwonmap"; + } + if (has_flag(KeepAlive)) { + con_print << " keepalive"; + } +} + +void Entity::print_header() const +{ + con_print << " entity id ^B" << id() << " ^Nlabel ^B" << label() << " ^Nname ^B" << name() << std::endl; +} + +void Entity::print_inventory() const +{ + if (!entity_inventory) { + con_print << "no inventory availble" << std::endl; + return; + } + + con_print << " ^Nitem info infotype amount" << std::endl; + for (Inventory::Items::const_iterator it = entity_inventory->items().begin(); it != entity_inventory->items().end(); it++) { + Item *item = (*it); + // TODO item flags + con_print << " " + << " ^B" << std::setw(4) << item->id() + << " ^N" << aux::pad_right((item->info()->type() ? item->info()->type()->label() : "NULL"), 8) + << " ^N" << aux::pad_right(item->info()->label(), 24) + << std::setw(5) << item->amount() << std::endl; + } + con_print << "^B " << entity_inventory->items().size() << " inventory items" << std::endl; +} + void Entity::die() { entity_destroyed = true; diff --git a/src/core/entity.h b/src/core/entity.h index d90de8b..d3c8522 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -75,6 +75,22 @@ public: /// destroy an entity virtual ~Entity(); + + /** + * @brief print information about the entity + * */ + virtual void print() const; + + /** + * @brief print information header + * */ + virtual void print_header() const; + + /** + * @brief print inventory if available + * */ + virtual void print_inventory() const; + /*----- inspectors ------------------------------------------------ */ @@ -234,9 +250,6 @@ public: return entity_keepalive; } - /// list inventory, if available, to console - void list_inventory() const; - /* ---- mutators -------------------------------------------------- */ /// assign shape -- cgit v1.2.3