widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #07267
[Merge] lp:~widelands-dev/widelands/bug_1570094_resource into lp:widelands
kaputtnik has proposed merging lp:~widelands-dev/widelands/bug_1570094_resource into lp:widelands.
Commit message:
Fix for resource tool bug 1570094
Removed comparisons of UInt < 0
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1570094 in widelands: "Editor remove resources does not work as expected"
https://bugs.launchpad.net/widelands/+bug/1570094
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug_1570094_resource/+merge/291913
Fix for resource tool bug 1570094
Also removed some comparison against value 'amount' of type UInt (amount < 0).
The changes are in r7960: http://bazaar.launchpad.net/~widelands-dev/widelands/bug_1570094_resource/revision/7960
Don't know how often we had bugs against the resource tool in the past...
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug_1570094_resource into lp:widelands.
=== modified file 'src/editor/tools/decrease_resources_tool.cc'
--- src/editor/tools/decrease_resources_tool.cc 2016-04-11 07:06:22 +0000
+++ src/editor/tools/decrease_resources_tool.cc 2016-04-14 16:18:26 +0000
@@ -31,7 +31,7 @@
/**
- * Decrease the resources of the current field by one if
+ * Decrease the resources of the current field by the given value if
* there is not already another resource there.
*/
int32_t EditorDecreaseResourcesTool::handle_click_impl(const Widelands::World& world,
@@ -46,10 +46,7 @@
do {
Widelands::ResourceAmount amount = mr.location().field->get_resources_amount();
- amount -= args->change_by;
- if (amount < 0) {
- amount = 0;
- }
+ amount = (amount > args->change_by) ? amount - args->change_by : 0;
if (mr.location().field->get_resources() == args->current_resource &&
map->is_resource_valid(world, mr.location(), args->current_resource) &&
=== modified file 'src/editor/tools/set_resources_tool.cc'
--- src/editor/tools/set_resources_tool.cc 2016-04-12 07:08:21 +0000
+++ src/editor/tools/set_resources_tool.cc 2016-04-14 16:18:26 +0000
@@ -41,9 +41,8 @@
Widelands::ResourceAmount amount = args->set_to;
Widelands::ResourceAmount max_amount = args->current_resource != Widelands::kNoResource ?
world.get_resource(args->current_resource)->max_amount() : 0;
- if (amount < 0)
- amount = 0;
- else if (amount > max_amount)
+
+ if (amount > max_amount)
amount = max_amount;
if (map->is_resource_valid(world, mr.location(), args->current_resource) &&
@@ -71,8 +70,6 @@
Widelands::ResourceAmount amount = res.amount;
Widelands::ResourceAmount max_amount = world.get_resource(args->current_resource)->max_amount();
- if (amount < 0)
- amount = 0;
if (amount > max_amount)
amount = max_amount;
Follow ups