← Back to team overview

widelands-dev team mailing list archive

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

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/empire04_unused_key_return_on_dismantle_no_ui into lp:widelands.

Commit message:
Allow return on dismantle values without buildcost.

UI fix has been postponed until after Build 20, c.f.

https://code.launchpad.net/~widelands-dev/widelands/empire04_unused_key_return_on_dismantle/+merge/358273

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/empire04_unused_key_return_on_dismantle_no_ui/+merge/358305
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/empire04_unused_key_return_on_dismantle_no_ui into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc	2018-09-23 11:10:56 +0000
+++ src/logic/map_objects/tribes/building.cc	2018-11-05 09:06:36 +0000
@@ -133,17 +133,22 @@
 		}
 	}
 
+    // We define a building as buildable if it has a "buildcost" table.
+    // A buildable building must also define "return_on_dismantle".
+    // However, we support "return_on_dismantle" without "buildable", because this is used by custom scenario buildings.
+    if (table.has_key("return_on_dismantle")) {
+        return_dismantle_ = Buildcost(table.get_table("return_on_dismantle"), egbase_.tribes());
+    }
 	if (table.has_key("buildcost")) {
 		buildable_ = true;
-		try {
-			buildcost_ = Buildcost(table.get_table("buildcost"), egbase_.tribes());
-			return_dismantle_ = Buildcost(table.get_table("return_on_dismantle"), egbase_.tribes());
-		} catch (const WException& e) {
-			throw wexception(
-			   "A buildable building must define \"buildcost\" and \"return_on_dismantle\": %s",
-			   e.what());
-		}
+        if (!table.has_key("return_on_dismantle")) {
+            throw wexception(
+			   "The building '%s' has a \"buildcost\" but no \"return_on_dismantle\"",
+			   name().c_str());
+        }
+		buildcost_ = Buildcost(table.get_table("buildcost"), egbase_.tribes());
 	}
+
 	if (table.has_key("enhancement_cost")) {
 		enhanced_building_ = true;
 		try {
@@ -151,9 +156,9 @@
 			return_enhanced_ =
 			   Buildcost(table.get_table("return_on_dismantle_on_enhanced"), egbase_.tribes());
 		} catch (const WException& e) {
-			throw wexception("An enhanced building must define \"enhancement_cost\""
+			throw wexception("The enhanced building '%s' must define \"enhancement_cost\""
 			                 "and \"return_on_dismantle_on_enhanced\": %s",
-			                 e.what());
+			                 name().c_str(), e.what());
 		}
 	}
 


Follow ups