Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-11-18 16:34:29 +0000
committerStijn Buys <ingar@osirion.org>2012-11-18 16:34:29 +0000
commit4c45315c9f76bc32e1015a2a2bd9b3ae635023a7 (patch)
tree3fbfe947a46aabea04d724e29307d40f9292f7f1 /src
parentab61530779c73e7e145193efcb1e23a47c16e7f3 (diff)
ADded support for enitty information printing, print current armor values for ships, print death messages
Diffstat (limited to 'src')
-rw-r--r--src/core/commandbuffer.cc20
-rw-r--r--src/core/entity.cc70
-rw-r--r--src/core/entity.h19
-rw-r--r--src/game/base/game.cc1
-rw-r--r--src/game/base/savegame.cc7
-rw-r--r--src/game/base/ship.cc16
-rw-r--r--src/game/base/ship.h2
7 files changed, 105 insertions, 30 deletions
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
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 47fab0f..a8a1aa2 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -573,6 +573,7 @@ void Game::func_specs(core::Player *player, const std::string &args)
con_print << " ^Nmass = ^B" << ship->mass() << std::endl;
con_print << " ^Nradius = ^B" << ship->radius() << std::endl;
con_print << " ^Ncargo = ^B" << ship->inventory()->capacity() << std::endl;
+ con_print << " ^Narmor = ^B" << ship->maxarmor() << std::endl;
con_print << "Engines:" << std::endl;
con_print << " ^Ndamping = ^B" << ship->body()->getLinearDamping() << " " << ship->body()->getAngularDamping() << std::endl;
con_print << " ^Nthrust = ^B" << ship->thrust_force() << std::endl;
diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc
index 90f3a57..85388f0 100644
--- a/src/game/base/savegame.cc
+++ b/src/game/base/savegame.cc
@@ -25,6 +25,7 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
core::Item *item = 0;
std::string itemtype;
std::string itemlabel;
+ float armor;
while (inifile.getline()) {
@@ -137,6 +138,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
if (ship) {
ship->set_spawn(spawn_entity);
}
+ } else if (inifile.got_key_float("armor", armor)) {
+ continue;
+
} else {
inifile.unknown_key();
}
@@ -204,6 +208,8 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
ship->inventory()->recalculate();
ship->inventory()->set_dirty();
+ ship->set_armor(armor);
+
if (!zone) {
zone = Default::zone;
}
@@ -283,6 +289,7 @@ void SaveGame::ship_to_stream(Ship *ship, std::ostream & os)
os << ship->spawn()->zone()->label() << ":" << ship->spawn()->label();
}
os << std::endl;
+ os << "armor=" << ship->armor() << std::endl;
}
void SaveGame::inventory_to_stream(core::Inventory *inventory, std::ostream & os)
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index ac4db15..a927e73 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -124,7 +124,14 @@ Ship::~Ship()
{
}
-void Ship::func_impulse() {
+void Ship::print() const
+{
+ core::EntityControlable::print();
+ con_print << " armor ^B" << armor() << "^N/^B" << maxarmor() << std::endl;
+}
+
+void Ship::func_impulse()
+{
switch (entity_state) {
case core::Entity::Impulse:
@@ -486,12 +493,14 @@ void Ship::collision(core::Entity *other)
// destroyed
if (ship_armor <= 0) {
+ explode();
+
if (owner()) {
ship_armor = 0;
std::string message("^B");
message.append(owner()->name());
message.append(" ^Bwent boom.");
- explode();
+ core::server()->broadcast(message);
} else {
die();
}
@@ -507,12 +516,13 @@ void Ship::collision(core::Entity *other)
// destroyed
if (ship_armor <= 0) {
+ explode();
+
if (owner()) {
ship_armor = 0;
std::string message("^B");
message.append(owner()->name());
message.append(" ^Bwas blown to bits.");
- explode();
} else {
die();
}
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index d68c647..8b06727 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -87,6 +87,8 @@ public:
return ship_armor;
}
+ virtual void print() const;
+
/* -- mutators --------------------------------------------- */
/// physics frame