← Back to team overview

widelands-dev team mailing list archive

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

 

Benedikt Straub has proposed merging lp:~widelands-dev/widelands/constructionsite_options into lp:widelands.

Commit message:
Fixes for some errors in constructionsite settings

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1597310 in widelands: "Possibility to set building options when building is under construction"
  https://bugs.launchpad.net/widelands/+bug/1597310

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

As happens so often, new bugs are found directly after the feature that causes them has been merged :)

– Fix two errors with ware priorities and max fills (we need to distinguish between the constructionsite´s real input queues and those for the settings)
– Minimum allowed capacity for milsites is 1, not 0
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/constructionsite_options into lp:widelands.
=== modified file 'src/logic/game.cc'
--- src/logic/game.cc	2019-06-23 11:41:17 +0000
+++ src/logic/game.cc	2019-06-23 14:34:42 +0000
@@ -789,17 +789,19 @@
 void Game::send_player_set_ware_priority(PlayerImmovable& imm,
                                          int32_t const type,
                                          DescriptionIndex const index,
-                                         int32_t const prio) {
+                                         int32_t const prio,
+                                         bool cs) {
 	send_player_command(
-	   new CmdSetWarePriority(get_gametime(), imm.owner().player_number(), imm, type, index, prio));
+	   new CmdSetWarePriority(get_gametime(), imm.owner().player_number(), imm, type, index, prio, cs));
 }
 
 void Game::send_player_set_input_max_fill(PlayerImmovable& imm,
                                           DescriptionIndex const index,
                                           WareWorker type,
-                                          uint32_t const max_fill) {
+                                          uint32_t const max_fill,
+                                          bool cs) {
 	send_player_command(new CmdSetInputMaxFill(
-	   get_gametime(), imm.owner().player_number(), imm, index, type, max_fill));
+	   get_gametime(), imm.owner().player_number(), imm, index, type, max_fill, cs));
 }
 
 void Game::send_player_change_training_options(TrainingSite& ts,

=== modified file 'src/logic/game.h'
--- src/logic/game.h	2019-06-09 10:33:51 +0000
+++ src/logic/game.h	2019-06-23 14:34:42 +0000
@@ -268,11 +268,13 @@
 	void send_player_set_ware_priority(PlayerImmovable&,
 	                                   int32_t type,
 	                                   DescriptionIndex index,
-	                                   int32_t prio);
+	                                   int32_t prio,
+	                                   bool is_cs = false);
 	void send_player_set_input_max_fill(PlayerImmovable&,
 	                                    DescriptionIndex index,
 	                                    WareWorker type,
-	                                    uint32_t);
+	                                    uint32_t,
+	                                    bool is_cs = false);
 	void send_player_change_training_options(TrainingSite&, TrainingAttribute, int32_t);
 	void send_player_drop_soldier(Building&, int32_t);
 	void send_player_change_soldier_capacity(Building&, int32_t);

=== modified file 'src/logic/playercommand.cc'
--- src/logic/playercommand.cc	2019-06-23 11:41:17 +0000
+++ src/logic/playercommand.cc	2019-06-23 14:34:42 +0000
@@ -1049,25 +1049,29 @@
                                        PlayerImmovable& imm,
                                        const int32_t init_type,
                                        const DescriptionIndex i,
-                                       const int32_t init_priority)
+                                       const int32_t init_priority,
+                                       bool cs_setting)
    : PlayerCommand(init_duetime, init_sender),
      serial_(imm.serial()),
      type_(init_type),
      index_(i),
-     priority_(init_priority) {
+     priority_(init_priority),
+     is_constructionsite_setting_(cs_setting) {
 }
 
 void CmdSetWarePriority::execute(Game& game) {
 	MapObject* mo = game.objects().get_object(serial_);
-	if (upcast(ConstructionSite, cs, mo)) {
-		if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
-			for (auto& pair : s->ware_queues) {
-				if (pair.first == index_) {
-					pair.second.priority = priority_;
-					return;
+	if (is_constructionsite_setting_) {
+		if (upcast(ConstructionSite, cs, mo)) {
+			if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
+				for (auto& pair : s->ware_queues) {
+					if (pair.first == index_) {
+						pair.second.priority = priority_;
+						return;
+					}
 				}
+				NEVER_HERE();
 			}
-			NEVER_HERE();
 		}
 	} else if (upcast(Building, psite, mo)) {
 		if (psite->owner().player_number() == sender()) {
@@ -1076,7 +1080,7 @@
 	}
 }
 
-constexpr uint16_t kCurrentPacketVersionCmdSetWarePriority = 1;
+constexpr uint16_t kCurrentPacketVersionCmdSetWarePriority = 2;
 
 void CmdSetWarePriority::write(FileWrite& fw, EditorGameBase& egbase, MapObjectSaver& mos) {
 	fw.unsigned_16(kCurrentPacketVersionCmdSetWarePriority);
@@ -1087,6 +1091,7 @@
 	fw.unsigned_8(type_);
 	fw.signed_32(index_);
 	fw.signed_32(priority_);
+	fw.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
 }
 
 void CmdSetWarePriority::read(FileRead& fr, EditorGameBase& egbase, MapObjectLoader& mol) {
@@ -1098,6 +1103,7 @@
 			type_ = fr.unsigned_8();
 			index_ = fr.signed_32();
 			priority_ = fr.signed_32();
+			is_constructionsite_setting_ = fr.unsigned_8();
 		} else {
 			throw UnhandledVersionError(
 			   "CmdSetWarePriority", packet_version, kCurrentPacketVersionCmdSetWarePriority);
@@ -1113,7 +1119,8 @@
      serial_(des.unsigned_32()),
      type_(des.unsigned_8()),
      index_(des.signed_32()),
-     priority_(des.signed_32()) {
+     priority_(des.signed_32()),
+     is_constructionsite_setting_(des.unsigned_8()) {
 }
 
 void CmdSetWarePriority::serialize(StreamWrite& ser) {
@@ -1123,6 +1130,7 @@
 	ser.unsigned_8(type_);
 	ser.signed_32(index_);
 	ser.signed_32(priority_);
+	ser.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
 }
 
 /*** class Cmd_SetWareMaxFill ***/
@@ -1131,39 +1139,43 @@
                                        PlayerImmovable& imm,
                                        const DescriptionIndex index,
                                        const WareWorker type,
-                                       const uint32_t max_fill)
+                                       const uint32_t max_fill,
+                                       bool cs_setting)
    : PlayerCommand(init_duetime, init_sender),
      serial_(imm.serial()),
      index_(index),
      type_(type),
-     max_fill_(max_fill) {
+     max_fill_(max_fill),
+     is_constructionsite_setting_(cs_setting) {
 }
 
 void CmdSetInputMaxFill::execute(Game& game) {
 	MapObject* mo = game.objects().get_object(serial_);
-	if (upcast(ConstructionSite, cs, mo)) {
-		if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
-			switch (type_) {
-			case wwWARE:
-				for (auto& pair : s->ware_queues) {
-					if (pair.first == index_) {
-						assert(pair.second.max_fill >= max_fill_);
-						pair.second.desired_fill = max_fill_;
-						return;
-					}
-				}
-				NEVER_HERE();
-			case wwWORKER:
-				for (auto& pair : s->worker_queues) {
-					if (pair.first == index_) {
-						assert(pair.second.max_fill >= max_fill_);
-						pair.second.desired_fill = max_fill_;
-						return;
-					}
+	if (is_constructionsite_setting_) {
+		if (upcast(ConstructionSite, cs, mo)) {
+			if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
+				switch (type_) {
+				case wwWARE:
+					for (auto& pair : s->ware_queues) {
+						if (pair.first == index_) {
+							assert(pair.second.max_fill >= max_fill_);
+							pair.second.desired_fill = max_fill_;
+							return;
+						}
+					}
+					NEVER_HERE();
+				case wwWORKER:
+					for (auto& pair : s->worker_queues) {
+						if (pair.first == index_) {
+							assert(pair.second.max_fill >= max_fill_);
+							pair.second.desired_fill = max_fill_;
+							return;
+						}
+					}
+					NEVER_HERE();
 				}
 				NEVER_HERE();
 			}
-			NEVER_HERE();
 		}
 	} else if (upcast(Building, b, mo)) {
 		if (b->owner().player_number() == sender()) {
@@ -1172,7 +1184,7 @@
 	}
 }
 
-constexpr uint16_t kCurrentPacketVersionCmdSetInputMaxFill = 2;
+constexpr uint16_t kCurrentPacketVersionCmdSetInputMaxFill = 3;
 
 void CmdSetInputMaxFill::write(FileWrite& fw, EditorGameBase& egbase, MapObjectSaver& mos) {
 	fw.unsigned_16(kCurrentPacketVersionCmdSetInputMaxFill);
@@ -1187,6 +1199,7 @@
 		fw.unsigned_8(1);
 	}
 	fw.unsigned_32(max_fill_);
+	fw.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
 }
 
 void CmdSetInputMaxFill::read(FileRead& fr, EditorGameBase& egbase, MapObjectLoader& mol) {
@@ -1202,6 +1215,7 @@
 				type_ = wwWORKER;
 			}
 			max_fill_ = fr.unsigned_32();
+			is_constructionsite_setting_ = fr.unsigned_8();
 		} else {
 			throw UnhandledVersionError(
 			   "CmdSetInputMaxFill", packet_version, kCurrentPacketVersionCmdSetInputMaxFill);
@@ -1220,6 +1234,7 @@
 		type_ = wwWORKER;
 	}
 	max_fill_ = des.unsigned_32();
+	is_constructionsite_setting_ = des.unsigned_8();
 }
 
 void CmdSetInputMaxFill::serialize(StreamWrite& ser) {
@@ -1233,6 +1248,7 @@
 		ser.unsigned_8(1);
 	}
 	ser.unsigned_32(max_fill_);
+	ser.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
 }
 
 CmdChangeTargetQuantity::CmdChangeTargetQuantity(const uint32_t init_duetime,

=== modified file 'src/logic/playercommand.h'
--- src/logic/playercommand.h	2019-06-19 07:34:19 +0000
+++ src/logic/playercommand.h	2019-06-23 14:34:42 +0000
@@ -475,7 +475,8 @@
 	                   PlayerImmovable&,
 	                   int32_t type,
 	                   DescriptionIndex index,
-	                   int32_t priority);
+	                   int32_t priority,
+	                   bool cs);
 
 	// Write these commands to a file (for savegames)
 	void write(FileWrite&, EditorGameBase&, MapObjectSaver&) override;
@@ -495,6 +496,7 @@
 	int32_t type_;  ///< this is always WARE right now
 	DescriptionIndex index_;
 	int32_t priority_;
+	bool is_constructionsite_setting_;
 };
 
 struct CmdSetInputMaxFill : public PlayerCommand {
@@ -505,7 +507,8 @@
 	                   PlayerImmovable&,
 	                   DescriptionIndex,
 	                   WareWorker,
-	                   uint32_t maxfill);
+	                   uint32_t maxfill,
+	                   bool cs);
 
 	// Write these commands to a file (for savegames)
 	void write(FileWrite&, EditorGameBase&, MapObjectSaver&) override;
@@ -525,6 +528,7 @@
 	DescriptionIndex index_;
 	WareWorker type_;
 	uint32_t max_fill_;
+	bool is_constructionsite_setting_;
 };
 
 struct CmdChangeTargetQuantity : public PlayerCommand {

=== modified file 'src/wui/constructionsitewindow.cc'
--- src/wui/constructionsitewindow.cc	2019-06-23 11:41:17 +0000
+++ src/wui/constructionsitewindow.cc	2019-06-23 14:34:42 +0000
@@ -219,7 +219,7 @@
 			cs_soldier_capacity_decrease_->sigclicked.connect([this, ms]() {
 				igbase()->game().send_player_change_soldier_capacity(
 				   *construction_site_.get(igbase()->egbase()),
-				   SDL_GetModState() & KMOD_CTRL ? 0 : ms->desired_capacity - 1);
+				   SDL_GetModState() & KMOD_CTRL ? 1 : ms->desired_capacity - 1);
 			});
 			cs_soldier_capacity_increase_->sigclicked.connect([this, ms]() {
 				igbase()->game().send_player_change_soldier_capacity(

=== modified file 'src/wui/inputqueuedisplay.cc'
--- src/wui/inputqueuedisplay.cc	2019-06-23 11:41:17 +0000
+++ src/wui/inputqueuedisplay.cc	2019-06-23 14:34:42 +0000
@@ -405,7 +405,7 @@
 	if (SDL_GetModState() & KMOD_CTRL) {
 		update_siblings_priority(state);
 	}
-	igb_.game().send_player_set_ware_priority(building_, type_, index_, priority);
+	igb_.game().send_player_set_ware_priority(building_, type_, index_, priority, settings_ != nullptr);
 }
 
 void InputQueueDisplay::radiogroup_clicked() {
@@ -465,7 +465,7 @@
 	// Update the value of this queue if required
 	if (cache_max_fill_ > 0) {
 		igb_.game().send_player_set_input_max_fill(
-		   building_, index_, type_, ((SDL_GetModState() & KMOD_CTRL) ? 0 : cache_max_fill_ - 1));
+		   building_, index_, type_, ((SDL_GetModState() & KMOD_CTRL) ? 0 : cache_max_fill_ - 1), settings_ != nullptr);
 	}
 
 	// Update other queues of this building
@@ -484,7 +484,7 @@
 	if (cache_max_fill_ < cache_size_) {
 		igb_.game().send_player_set_input_max_fill(
 		   building_, index_, type_,
-		   ((SDL_GetModState() & KMOD_CTRL) ? cache_size_ : cache_max_fill_ + 1));
+		   ((SDL_GetModState() & KMOD_CTRL) ? cache_size_ : cache_max_fill_ + 1), settings_ != nullptr);
 	}
 
 	if (SDL_GetModState() & KMOD_SHIFT) {
@@ -512,7 +512,7 @@
 		                                 display->cache_size_));
 		if (new_fill != display->cache_max_fill_) {
 			igb_.game().send_player_set_input_max_fill(
-			   building_, display->index_, display->type_, new_fill);
+			   building_, display->index_, display->type_, new_fill, settings_ != nullptr);
 		}
 	} while ((sibling = sibling->get_next_sibling()));
 }


Follow ups