← Back to team overview

widelands-dev team mailing list archive

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

 

Teppo Mäenpää has proposed merging lp:~widelands-dev/widelands/bug-1236538-minimalfix into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1236538 in widelands: "Too many soldiers are created"
  https://bugs.launchpad.net/widelands/+bug/1236538

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1236538-minimalfix/+merge/189864

minimal invasive fix to bug 1236538
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1236538-minimalfix/+merge/189864
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1236538-minimalfix into lp:widelands.
=== modified file 'src/economy/economy.cc'
--- src/economy/economy.cc	2013-07-26 20:19:36 +0000
+++ src/economy/economy.cc	2013-10-08 14:22:45 +0000
@@ -30,6 +30,7 @@
 #include "economy/warehousesupply.h"
 #include "logic/game.h"
 #include "logic/player.h"
+#include "logic/soldier.h"
 #include "logic/tribe.h"
 #include "logic/warehouse.h"
 #include "upcast.h"
@@ -794,6 +795,9 @@
 		_start_request_timer(rsps.nexttimer);
 }
 
+
+std::unique_ptr<Soldier> Economy::m_soldier_prototype = nullptr; // minimal invasive fix of bug 1236538
+
 /**
  * Check whether there is a supply for the given request. If the request is a
  * worker request without supply, attempt to create a new worker in a warehouse.
@@ -802,6 +806,26 @@
 {
 	unsigned demand = 0;
 
+	bool soldier_level_check;
+	const Tribe_Descr & tribe = owner().tribe();
+	const Worker_Descr & w_desc = *tribe.get_worker_descr(index);
+
+	// Make a dummy soldier, which should never be assigned to any economy
+	// Minimal invasive fix of bug 1236538
+	if (is_a(Soldier_Descr, &w_desc))
+	{
+		if (nullptr == m_soldier_prototype)
+		{
+			upcast(Soldier_Descr const, s_desc, &w_desc);
+			Soldier* test_rookie = static_cast<Soldier*> (&(s_desc->create_object()));
+			m_soldier_prototype = static_cast<std::unique_ptr<Widelands::Soldier>> (test_rookie);
+		}
+		soldier_level_check = true;
+	}
+	else
+		soldier_level_check = false;
+
+
 	container_iterate_const(RequestList, m_requests, j) {
 		const Request & req = **j.current;
 
@@ -813,17 +837,24 @@
 		if (m_supplies.have_supplies(game, req))
 			continue;
 
+		// Requests for heroes should not trigger the creation of more rookies
+		if (soldier_level_check)
+		{
+			if (not (req.get_requirements().check(*m_soldier_prototype)))
+				continue;
+		}
+
+
 		demand += req.get_open_count();
 	}
 
 	if (!demand)
 		return;
 
+
 	// We have worker demand that is not fulfilled by supplies
 	// Find warehouses where we can create the required workers,
 	// and collect stats about existing build prerequisites
-	const Tribe_Descr & tribe = owner().tribe();
-	const Worker_Descr & w_desc = *tribe.get_worker_descr(index);
 	const Worker_Descr::Buildcost & cost = w_desc.buildcost();
 	std::vector<uint32_t> total_available;
 	uint32_t total_planned = 0;

=== modified file 'src/economy/economy.h'
--- src/economy/economy.h	2013-07-26 20:19:36 +0000
+++ src/economy/economy.h	2013-10-08 14:22:45 +0000
@@ -20,6 +20,7 @@
 #ifndef ECONOMY_H
 #define ECONOMY_H
 
+#include <memory>
 #include <set>
 #include <vector>
 
@@ -27,6 +28,7 @@
 #include <boost/utility.hpp>
 
 #include "logic/instances.h"
+#include "logic/soldier.h"
 #include "logic/warelist.h"
 #include "logic/wareworker.h"
 #include "economy/supply_list.h"
@@ -225,6 +227,9 @@
 	 * excessive calls to the request/supply balancing logic.
 	 */
 	uint32_t m_request_timerid;
+
+	static std::unique_ptr<Soldier> m_soldier_prototype;
+
 };
 
 }

=== modified file 'src/logic/soldier.h'
--- src/logic/soldier.h	2013-09-14 14:52:25 +0000
+++ src/logic/soldier.h	2013-10-08 14:22:45 +0000
@@ -39,6 +39,7 @@
 #define HP_FRAMECOLOR RGBColor(255, 255, 255)
 
 struct Soldier_Descr : public Worker_Descr {
+	friend class Economy;
 	Soldier_Descr
 		(char const * const _name, char const * const _descname,
 		 const std::string & directory, Profile &, Section & global_s,


Follow ups