← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1428315 into lp:widelands

 

TiborB has proposed merging lp:~widelands-dev/widelands/bug-1428315 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1428315 in widelands: "Fully upgraded soldier in training site"
  https://bugs.launchpad.net/widelands/+bug/1428315
  Bug #1490116 in widelands: "fully promoted soldiers remaining in training sites"
  https://bugs.launchpad.net/widelands/+bug/1490116

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1428315/+merge/269673

For unknown reasons, a trainingsite sometimes does not drop fully upgraded soldiers and all upgrading can be therefore stuck, f.e. if there is only one slot for soldiers.
Might be a problem of save/load. 
Attached savegames does not show an instant when problem happened, so I cannot properly debug it.

Now checking for fully upgraded soldiers are done everytime training cycle ends. Overhead is negligible...
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1428315 into lp:widelands.
=== modified file 'src/logic/ship.cc'
--- src/logic/ship.cc	2015-07-29 20:06:11 +0000
+++ src/logic/ship.cc	2015-08-31 19:52:12 +0000
@@ -719,7 +719,8 @@
  * @note This is supposed to be called only from the scheduling code of @ref Fleet.
  */
 void Ship::set_destination(Game& game, PortDock& pd) {
-	molog("set_destination / sending to portdock %u (carrying %" PRIuS " items)\n", pd.serial(), m_items.size());
+	molog("set_destination / sending to portdock %u (carrying %" PRIuS " items)\n",
+	pd.serial(), m_items.size());
 	m_destination = &pd;
 	send_signal(game, "wakeup");
 }

=== modified file 'src/logic/trainingsite.cc'
--- src/logic/trainingsite.cc	2015-05-20 19:17:56 +0000
+++ src/logic/trainingsite.cc	2015-08-31 19:52:12 +0000
@@ -442,6 +442,7 @@
  */
 void TrainingSite::drop_unupgradable_soldiers(Game &)
 {
+
 	std::vector<Soldier *> droplist;
 
 	for (uint32_t i = 0; i < m_soldiers.size(); ++i) {
@@ -469,6 +470,7 @@
  */
 void TrainingSite::drop_stalled_soldiers(Game &)
 {
+
 	Soldier * soldier_to_drop = nullptr;
 	uint32_t highest_soldier_level_seen = 0;
 
@@ -551,21 +553,34 @@
 
 void TrainingSite::program_end(Game & game, ProgramResult const result)
 {
+
 	m_result = result;
 	ProductionSite::program_end(game, result);
+	// For unknown reasons sometimes there is a fully upgraded soldier
+	// that failed to be send away, so at the end of this function
+	// we test for such soldiers, unless another drop_soldiers
+	// function were run
+	bool leftover_soldiers_check = true;
 
 	if (m_current_upgrade) {
 		if (m_result == Completed) {
 			drop_unupgradable_soldiers(game);
+			leftover_soldiers_check = false;
 			m_current_upgrade->lastsuccess = true;
 			m_current_upgrade->failures = 0;
 		}
 		else {
 			m_current_upgrade->failures++;
 			drop_stalled_soldiers(game);
+			leftover_soldiers_check = false;
 		}
 		m_current_upgrade = nullptr;
 	}
+
+	if (leftover_soldiers_check) {
+		drop_unupgradable_soldiers(game);
+	}
+
 	training_done();
 }
 
@@ -579,6 +594,7 @@
  */
 void TrainingSite::find_and_start_next_program(Game & game)
 {
+
 	for (;;) {
 		uint32_t maxprio = 0;
 		uint32_t maxcredit = 0;
@@ -595,8 +611,9 @@
 				maxcredit  = upgrade.credit;
 		}
 
-		if (maxprio == 0)
+		if (maxprio == 0) {
 			return program_start(game, "sleep");
+		}
 
 		uint32_t const multiplier = 1 + (10 - maxcredit) / maxprio;
 


Follow ups