From 4c45315c9f76bc32e1015a2a2bd9b3ae635023a7 Mon Sep 17 00:00:00 2001
From: Stijn Buys <ingar@osirion.org>
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/game/base/game.cc     |  1 +
 src/game/base/savegame.cc |  7 +++++++
 src/game/base/ship.cc     | 16 +++++++++++++---
 src/game/base/ship.h      |  2 ++
 4 files changed, 23 insertions(+), 3 deletions(-)

(limited to 'src/game')

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
-- 
cgit v1.2.3