← Back to team overview

widelands-dev team mailing list archive

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

 

SirVer has proposed merging lp:~widelands-dev/widelands/add_player_to_note_economy into lp:widelands.

Commit message:
Add player number to NoteEconomy to truly uniquely identify the economy.


Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1732765 in widelands: "Configure economy window disappears if only headquarter is available"
  https://bugs.launchpad.net/widelands/+bug/1732765

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/add_player_to_note_economy/+merge/334371
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/add_player_to_note_economy into lp:widelands.
=== modified file 'src/economy/economy.cc'
--- src/economy/economy.cc	2017-08-20 17:45:42 +0000
+++ src/economy/economy.cc	2017-11-28 11:44:08 +0000
@@ -75,7 +75,7 @@
 Economy::~Economy() {
 	const size_t economy_number = owner_.get_economy_number(this);
 	Notifications::publish(
-	   NoteEconomy(economy_number, economy_number, NoteEconomy::Action::kDeleted));
+	   NoteEconomy{owner_.player_number(), economy_number, economy_number, NoteEconomy::Action::kDeleted});
 	owner_.remove_economy(*this);
 
 	if (requests_.size())
@@ -530,9 +530,9 @@
 	//  If the options window for e is open, but not the one for this, the user
 	//  should still have an options window after the merge.
 	if (e.has_window() && !has_window()) {
-		Notifications::publish(NoteEconomy(e.owner().get_economy_number(&e),
-		                                   owner_.get_economy_number(this),
-		                                   NoteEconomy::Action::kMerged));
+		Notifications::publish(
+		   NoteEconomy{e.owner().player_number(), e.owner().get_economy_number(&e),
+		               owner_.get_economy_number(this), NoteEconomy::Action::kMerged});
 	}
 
 	for (std::vector<Flag*>::size_type i = e.get_nrflags() + 1; --i;) {

=== modified file 'src/economy/economy.h'
--- src/economy/economy.h	2017-06-24 08:47:46 +0000
+++ src/economy/economy.h	2017-11-28 11:44:08 +0000
@@ -52,6 +52,9 @@
 struct NoteEconomy {
 	CAN_BE_SENT_AS_NOTE(NoteId::Economy)
 
+	// The owner of the economy.
+	int player_number;
+
 	// When 2 economies have been merged, this is the economy number that has
 	// been removed, while the other one is the number of the resulting economy.
 	// For all other messages old_economy == new_economy.
@@ -60,10 +63,6 @@
 
 	enum class Action { kMerged, kDeleted };
 	const Action action;
-
-	NoteEconomy(size_t init_old, size_t init_new, const Action& init_action)
-	   : old_economy(init_old), new_economy(init_new), action(init_action) {
-	}
 };
 
 /**

=== modified file 'src/wui/economy_options_window.cc'
--- src/wui/economy_options_window.cc	2017-06-11 20:09:05 +0000
+++ src/wui/economy_options_window.cc	2017-11-28 11:44:08 +0000
@@ -57,6 +57,9 @@
 }
 
 void EconomyOptionsWindow::on_economy_note(const Widelands::NoteEconomy& note) {
+	if (owner_.player_number() != note.player_number) {
+		return;
+	}
 	if (note.old_economy == economy_number_) {
 		switch (note.action) {
 		case Widelands::NoteEconomy::Action::kMerged:


Follow ups