← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug1186906 into lp:widelands

 

cghislai has proposed merging lp:~widelands-dev/widelands/bug1186906 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1186906 in widelands: "Remove entries from the message list that have become obsolete"
  https://bugs.launchpad.net/widelands/+bug/1186906

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug1186906/+merge/177204

This adds a new serial field in the Message class. When the message list is filled, if no map object is still registered with the serial, the message gets automatically archived.
Also the message paquet reader/writer and the message senders are updated to make use of this new change.

I tested this with the Build16 compatibility savegame. The messages already present when loading are usable - they do not have any serial associated. When the mine exhausted message comes in and that the mine is destroyed, opening the list afterwards will autoarchive the message.
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug1186906/+merge/177204
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug1186906 into lp:widelands.
=== modified file 'src/logic/building.cc'
--- src/logic/building.cc	2013-07-23 14:49:48 +0000
+++ src/logic/building.cc	2013-07-26 18:31:33 +0000
@@ -948,7 +948,7 @@
 
 	Message * msg = new Message
 		(msgsender, game.get_gametime(), 60 * 60 * 1000,
-		 title, rt_description, get_position());
+		 title, rt_description, get_position(), m_serial);
 
 	if (throttle_time)
 		owner().add_message_with_timeout

=== modified file 'src/logic/instances.h'
--- src/logic/instances.h	2013-07-10 15:24:32 +0000
+++ src/logic/instances.h	2013-07-26 18:31:33 +0000
@@ -346,7 +346,7 @@
 
 	Map_Object * get_object(Serial const serial) const {
 		const objmap_t::const_iterator it = m_objects.find(serial);
-		return it != m_objects.end() ? it->second : 0;
+		return it != m_objects.end() ? it->second : nullptr;
 	}
 
 	void insert(Map_Object *);

=== modified file 'src/logic/message.h'
--- src/logic/message.h	2013-02-10 19:36:24 +0000
+++ src/logic/message.h	2013-07-26 18:31:33 +0000
@@ -36,6 +36,7 @@
 		 const std::string &       t,
 		 const std::string &       b,
 		 Widelands::Coords   const c = Coords::Null(),
+		 Widelands::Serial         ser = 0,
 		 Status                    s = New)
 		:
 		m_sender(msgsender),
@@ -44,6 +45,7 @@
 		m_sent    (sent_time),
 		m_duration(d),
 		m_position(c),
+		m_serial  (ser),
 		m_status  (s)
 	{}
 
@@ -53,6 +55,7 @@
 	const std::string & title() const throw ()      {return m_title;}
 	const std::string & body () const               {return m_body;}
 	Widelands::Coords   position() const            {return m_position;}
+	Widelands::Serial   serial() const              {return m_serial;}
 	Status              status  () const {return m_status;}
 	Status set_status(Status const s) {return m_status = s;}
 
@@ -63,6 +66,7 @@
 	uint32_t          m_sent;
 	Duration          m_duration; /// will expire after this duration
 	Widelands::Coords m_position;
+	Widelands::Serial m_serial; // serial to map object
 	Status            m_status;
 };
 

=== modified file 'src/logic/ship.cc'
--- src/logic/ship.cc	2013-07-21 08:27:10 +0000
+++ src/logic/ship.cc	2013-07-26 18:31:33 +0000
@@ -718,7 +718,7 @@
 
 	Message * msg = new Message
 		(msgsender, game.get_gametime(), 60 * 60 * 1000,
-		 title, rt_description, get_position());
+		 title, rt_description, get_position(), m_serial);
 
 	m_economy->owner().add_message(game, *msg);
 }

=== modified file 'src/logic/soldier.cc'
--- src/logic/soldier.cc	2013-07-14 10:38:26 +0000
+++ src/logic/soldier.cc	2013-07-26 18:31:33 +0000
@@ -1481,7 +1481,8 @@
 						 	 game.get_gametime(), Forever(),
 						 	 _("Logic error"),
 						 	 buffer,
-						 	 get_position()));
+						 	 get_position(),
+							 m_serial));
 					opponent.owner().add_message
 						(game,
 						 *new Message
@@ -1489,7 +1490,8 @@
 						 	 game.get_gametime(), Forever(),
 						 	 _("Logic error"),
 						 	 buffer,
-						 	 opponent.get_position()));
+						 	 opponent.get_position(),
+							 m_serial));
 					game.gameController()->setDesiredSpeed(0);
 					return pop_task(game);
 				}

=== modified file 'src/logic/worker.cc'
--- src/logic/worker.cc	2013-07-21 08:27:10 +0000
+++ src/logic/worker.cc	2013-07-26 18:31:33 +0000
@@ -957,7 +957,9 @@
 				 	 game.get_gametime(), 60 * 60 * 1000,
 				 	 rdescr->descname(),
 				 	 message,
-				 	 position),
+				 	 position,
+					 m_serial
+					),
 				 300000, 8);
 		}
 
@@ -1859,7 +1861,8 @@
 			 	 game.get_gametime(), Forever(),
 			 	 _("Worker got lost!"),
 			 	 buffer,
-			 	 get_position()));
+			 	 get_position()),
+				 m_serial);
 		set_location(0);
 		return pop_task(game);
 	}

=== modified file 'src/map_io/widelands_map_players_messages_data_packet.cc'
--- src/map_io/widelands_map_players_messages_data_packet.cc	2013-07-12 15:11:32 +0000
+++ src/map_io/widelands_map_players_messages_data_packet.cc	2013-07-26 18:31:33 +0000
@@ -26,7 +26,7 @@
 
 namespace Widelands {
 
-#define CURRENT_PACKET_VERSION 1
+#define CURRENT_PACKET_VERSION 2
 #define PLAYERDIRNAME_TEMPLATE "player/%u"
 #define FILENAME_TEMPLATE PLAYERDIRNAME_TEMPLATE "/messages"
 #define FILENAME_SIZE 19
@@ -45,8 +45,9 @@
 			snprintf(filename, sizeof(filename), FILENAME_TEMPLATE, p);
 			Profile prof;
 			try {prof.read(filename, 0, fs);} catch (...) {continue;}
-			prof.get_safe_section("global").get_positive
-				("packet_version", CURRENT_PACKET_VERSION);
+			uint32_t paquet_version =
+				prof.get_safe_section("global").get_positive
+					("packet_version", CURRENT_PACKET_VERSION);
 			MessageQueue & messages = player->messages();
 
 			{
@@ -119,7 +120,7 @@
 								 sent + duration, sent, duration, gametime);
 					}
 					Message::Status status = Message::Archived; //  default status
-					if (char const * const status_string = s->get_string("status"))
+					if (char const * const status_string = s->get_string("status")) {
 						try {
 							if      (not strcmp(status_string, "new"))
 								status = Message::New;
@@ -132,6 +133,12 @@
 						} catch (const _wexception & e) {
 							throw game_data_error("status: %s", e.what());
 						}
+					}
+					uint32_t serial = 0;
+					if (paquet_version >= 2) {
+						serial = s->get_int("serial");
+					}
+					
 					messages.add_message
 						(*new Message
 						 	(s->get_string     ("sender", ""),
@@ -140,6 +147,7 @@
 						 	 s->get_name       (),
 						 	 s->get_safe_string("body"),
 						 	 s->get_Coords     ("position", extent, Coords::Null()),
+							 serial,
 						 	 status));
 					//  Expiration is scheduled for all messages (with finite
 					//  duration) after the command queue has been loaded (in
@@ -188,6 +196,7 @@
 					 "\tbody: %s\n"
 					 "\tposition: (%i, %i)\n"
 					 "\tstatus: %s\n",
+					 "\tserial: %d\n",
 					 message.sent(), message.duration(),
 					 message.sent() + message.duration(), egbase.get_gametime(),
 					 message.sender().c_str(), message.title().c_str(),
@@ -195,7 +204,8 @@
 					 message.position().x, message.position().y,
 					 message.status() == Message::New      ? "new"      :
 					 message.status() == Message::Read     ? "read"     :
-					 message.status() == Message::Archived ? "archived" : "ERROR");
+					 message.status() == Message::Archived ? "archived" : "ERROR",
+					 message.serial());
 			assert
 				(message.duration() == Forever() or
 				 static_cast<uint32_t>(egbase.get_gametime())
@@ -225,6 +235,7 @@
 			default:
 				assert(false);
 			}
+			s.set_int       ("serial",    message.serial());
 		}
 		char filename[FILENAME_SIZE];
 		snprintf(filename, sizeof(filename), PLAYERDIRNAME_TEMPLATE, p);

=== modified file 'src/wui/game_message_menu.cc'
--- src/wui/game_message_menu.cc	2013-07-16 17:30:22 +0000
+++ src/wui/game_message_menu.cc	2013-07-26 18:31:33 +0000
@@ -26,6 +26,7 @@
 #include "logic/message_queue.h"
 #include "logic/player.h"
 #include "logic/playercommand.h"
+#include "logic/instances.h"
 
 #include "container_iterate.h"
 #include "timestring.h"
@@ -157,7 +158,23 @@
 	// Update messages in the list and remove messages
 	// that should no longer be shown
 	for (uint32_t j = list->size(); j; --j) {
-		if (Message const * const message = mq[Message_Id((*list)[j - 1])]) {
+		Message_Id m_id((*list)[j - 1]);
+		if (Message const * const message = mq[m_id]) {
+			// Check if the serialed object is still present,
+			// otherwise archive
+			if
+				(message->status() != Message::Archived &&
+				 message->serial() != 0)
+			{
+				Widelands::Map_Object* mo =
+					iplayer().get_game()->objects().get_object(message->serial());
+				if (mo == nullptr) {
+					Widelands::Game* game = iplayer().get_game();
+					game->send_player_command
+						(*new Widelands::Cmd_MessageSetStatusArchived
+					 	(game->get_gametime(), iplayer().player_number(), m_id));
+				}
+			}
 			if ((mode == Archive) != (message->status() == Message::Archived)) {
 				list->remove(j - 1);
 			} else {


Follow ups