GunChleoc has proposed merging
lp:~widelands-dev/widelands/empire04_unused_key_return_on_dismantle into
lp:widelands.
Commit message:
Make dismantle button independent of buildable/enhanced. This fixes missing
Dismantle buttons in Empire scenario 4.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/empire04_unused_key_return_on_dismantle/+merge/358273
--
Your team Widelands Developers is requested to review the proposed merge of
lp:~widelands-dev/widelands/empire04_unused_key_return_on_dismantle 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 +
+++ src/logic/map_objects/tribes/building.cc 2018-11-03 16:33:17 +
@@ -60,6 +60,7 @@
: MapObjectDescr(init_type, table.get_string("name"), init_descname, table),
egbase_(egbase),
buildable_(false),
+ can_be_dismantled_(false),
size_(BaseImmovable::SMALL),
mine_(false),
port_(false),
@@ -133,17 +134,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,11 +157,12 @@
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());
}
}
+can_be_dismantled_ = (return_dismantle_.total() > 0 || return_enhanced_.total() > 0);
needs_seafaring_ = table.has_key("needs_seafaring") ? table.get_bool("needs_seafaring") : false;
@@ -310,7 +317,7 @@
const BuildingDescr& tmp_descr = descr();
if (tmp_descr.is_destructible()) {
caps |= PCap_Bulldoze;
- if (tmp_descr.is_buildable() || tmp_descr.is_enhanced())
+ if (tmp_descr.can_be_dismantled())
caps |= PCap_Dismantle;
}
if (tmp_descr.enhancement() != INVALID_INDEX)
=== modified file 'src/logic/map_objects/tribes/building.h'
--- src/logic/map_objects/tribes/building.h 2018-09-25 06:32:35 +
+++ src/logic/map_objects/tribes/building.h 2018-11-03 16:33:17 +
@@ -73,6 +73,9 @@
bool is_buildable() const {
return buildable_;
}
+bool can_be_dismantled() const {
+ return can_be_dismantled_;
+ }
bool is_destructible() const {
return destructible_;
}
@@ -173,6 +176,7 @@
private:
bool buildable_; // the player can build this himself
+bool can_be_dismantled_; // the player can dismantle this building
bool destructible_; // the player can destruct this himself
Buildcost buildcost_;
Buildcost return_dismantle_; // Returned wares on dismantle
___
Mailing list: https://launchpad.net/~widelands-dev
Post to : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help : https://help.launchpad.net/ListHelp