← Back to team overview

widelands-dev team mailing list archive

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

 

Jens Beyer has proposed merging lp:~widelands-dev/widelands/bug580923 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #580923 in widelands: "Production of carrier does not respect building costs"
  https://bugs.launchpad.net/widelands/+bug/580923

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

Freely creating workers in special situations (cheating ^^) is gone.

For widelands game itself it should not make a big difference, as the carrier doesn't cost anything. The game still creates carriers once a second or so, even if not needed.

But when you apply a buildcost to the carrier, the automatic creation stops, and they are created only if necessary.

If there is no carrier, and no resources to create one, the economy stalls...

Please test thoroughly, I don't know if I have found all cases and circumstances to test.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug580923 into lp:widelands.
=== modified file 'src/logic/warehouse.cc'
--- src/logic/warehouse.cc	2015-07-24 18:21:58 +0000
+++ src/logic/warehouse.cc	2015-10-02 18:14:41 +0000
@@ -788,11 +788,17 @@
 {
 	WareIndex const carrierid = descr().tribe().safe_worker_index("carrier");
 
-	if (!m_supply->stock_workers(carrierid)) // XXX yep, let's cheat
-		insert_workers(carrierid, 1);
-
-	launch_worker(game, carrierid, Requirements()).start_task_fetchfromflag
-		(game);
+	if (!m_supply->stock_workers(carrierid))
+	{
+		if (can_create_worker(game, carrierid))
+		{
+			create_worker(game, carrierid);
+		}
+	}
+	if (m_supply->stock_workers(carrierid))
+	{
+		launch_worker(game, carrierid, Requirements()).start_task_fetchfromflag(game);
+	}
 
 	return true;
 }
@@ -930,29 +936,38 @@
 	// Create the ware
 	WareInstance & ware = *new WareInstance(ware_index, descr().tribe().get_ware_descr(ware_index));
 	ware.init(game);
-	do_launch_ware(game, ware);
-
-	m_supply->remove_wares(ware_index, 1);
-
+	if (do_launch_ware(game, ware))
+	{
+		m_supply->remove_wares(ware_index, 1);
+	}
 	return ware;
 }
 
 
 /// Get a carrier to actually move this ware out of the warehouse.
-void Warehouse::do_launch_ware(Game & game, WareInstance & ware)
+bool Warehouse::do_launch_ware(Game & game, WareInstance & ware)
 {
 	// Create a carrier
 	WareIndex const carrierid = descr().tribe().worker_index("carrier");
-	const WorkerDescr & workerdescr = *descr().tribe().get_worker_descr(carrierid);
-
-	Worker & worker = workerdescr.create(game, owner(), this, m_position);
 
 	// Yup, this is cheating.
+	if (!m_supply->stock_workers(carrierid))
+	{
+		if (can_create_worker(game, carrierid))
+		{
+			create_worker(game, carrierid);
+		}
+	}
 	if (m_supply->stock_workers(carrierid))
-		m_supply->remove_workers(carrierid, 1);
+	{
+		Widelands::Worker & worker = launch_worker(game, carrierid, Requirements());
+		// Setup the carrier
+		worker.start_task_dropoff(game, ware);
+		return true;
+	}
 
-	// Setup the carrier
-	worker.start_task_dropoff(game, ware);
+	//we did not launch the ware...
+	return false;
 }
 
 

=== modified file 'src/logic/warehouse.h'
--- src/logic/warehouse.h	2015-02-12 21:49:05 +0000
+++ src/logic/warehouse.h	2015-10-02 18:14:41 +0000
@@ -183,7 +183,7 @@
 	void incorporate_worker(EditorGameBase&, Worker* worker);
 
 	WareInstance & launch_ware(Game &, WareIndex);
-	void do_launch_ware(Game &, WareInstance &);
+	bool do_launch_ware(Game &, WareInstance &);
 
 	// Adds the ware to our inventory. Takes ownership and might delete 'ware'.
 	void incorporate_ware(EditorGameBase&, WareInstance* ware);


Follow ups