Merge lp:~janosch-peters-deactivatedaccount/widelands/editor-remove-invalid-resources into lp:widelands

Proposed by xxx-deleted
Status: Merged
Merged at revision: 7688
Proposed branch: lp:~janosch-peters-deactivatedaccount/widelands/editor-remove-invalid-resources
Merge into: lp:widelands
Diff against target: 2875 lines (+769/-768)
53 files modified
src/editor/map_generator.cc (+1/-1)
src/editor/tools/editor_decrease_height_tool.cc (+23/-23)
src/editor/tools/editor_decrease_height_tool.h (+8/-6)
src/editor/tools/editor_decrease_resources_tool.cc (+22/-41)
src/editor/tools/editor_decrease_resources_tool.h (+6/-6)
src/editor/tools/editor_delete_bob_tool.cc (+18/-18)
src/editor/tools/editor_delete_bob_tool.h (+6/-6)
src/editor/tools/editor_delete_immovable_tool.cc (+16/-17)
src/editor/tools/editor_delete_immovable_tool.h (+6/-6)
src/editor/tools/editor_draw_tool.cc (+18/-18)
src/editor/tools/editor_draw_tool.h (+6/-6)
src/editor/tools/editor_history.cc (+5/-5)
src/editor/tools/editor_increase_height_tool.cc (+21/-21)
src/editor/tools/editor_increase_height_tool.h (+6/-6)
src/editor/tools/editor_increase_resources_tool.cc (+25/-101)
src/editor/tools/editor_increase_resources_tool.h (+10/-9)
src/editor/tools/editor_info_tool.cc (+13/-13)
src/editor/tools/editor_info_tool.h (+3/-3)
src/editor/tools/editor_make_infrastructure_tool.cc (+5/-5)
src/editor/tools/editor_make_infrastructure_tool.h (+3/-3)
src/editor/tools/editor_noise_height_tool.cc (+23/-23)
src/editor/tools/editor_noise_height_tool.h (+6/-6)
src/editor/tools/editor_place_bob_tool.cc (+26/-26)
src/editor/tools/editor_place_bob_tool.h (+6/-6)
src/editor/tools/editor_place_immovable_tool.cc (+28/-29)
src/editor/tools/editor_place_immovable_tool.h (+6/-6)
src/editor/tools/editor_set_height_tool.cc (+26/-26)
src/editor/tools/editor_set_height_tool.h (+6/-6)
src/editor/tools/editor_set_origin_tool.cc (+14/-14)
src/editor/tools/editor_set_origin_tool.h (+6/-6)
src/editor/tools/editor_set_port_space_tool.cc (+69/-69)
src/editor/tools/editor_set_port_space_tool.h (+13/-13)
src/editor/tools/editor_set_resources_tool.cc (+61/-62)
src/editor/tools/editor_set_resources_tool.h (+19/-6)
src/editor/tools/editor_set_starting_pos_tool.cc (+12/-12)
src/editor/tools/editor_set_starting_pos_tool.h (+3/-3)
src/editor/tools/editor_set_terrain_tool.cc (+30/-30)
src/editor/tools/editor_set_terrain_tool.h (+6/-6)
src/editor/tools/editor_tool.h (+12/-12)
src/editor/ui_menus/editor_tool_change_resources_options_menu.cc (+8/-5)
src/logic/bob.h (+1/-1)
src/logic/game_controller.h (+1/-1)
src/logic/map.cc (+66/-21)
src/logic/map.h (+51/-25)
src/logic/widelands.h (+1/-0)
src/logic/worker.cc (+23/-27)
src/logic/world/world.cc (+5/-2)
src/map_io/widelands_map_loader.cc (+2/-0)
src/scripting/lua_map.cc (+7/-3)
src/ui_fsmenu/options.cc (+2/-1)
src/wui/overlay_manager.cc (+3/-1)
src/wui/overlay_manager.h (+1/-1)
test/maps/lua_testsuite.wmf/scripting/efield.lua (+5/-5)
To merge this branch: bzr merge lp:~janosch-peters-deactivatedaccount/widelands/editor-remove-invalid-resources
Reviewer Review Type Date Requested Status
SirVer Approve
Tino Needs Fixing
kaputtnik (community) Needs Fixing
TiborB Pending
Review via email: mp+281462@code.launchpad.net

Description of the change

1. Map::change_terrain verifies now if the new terrain matches the current resource. If it doesen't, the resource is deleted. This fixes the bug in the editor.

2. A new method Map::check_res_consistency is called when a map is loaded. The method looks for invalid resources on every node and if present, deletes them. This "fixes" broken maps on load and affects both the editor and the game.

Sidenote: I introduced a new special index for "No Resource" (until now fields without resources were set to (type:0,amount:0), which is confusing)

Testing:
1. Start the editor. Add "water" resource on a grass terrain. Then, change the terrain to mountain. The water resource should vanish.

2. I attached the map "invalid_resources.wmf" on #977980. If you load the map the invalid resource "water" on a mountain terrain node (7,5) are removed. Likewise, the invalid resource "gold" is removed from (2,3), a water node.

To post a comment you must log in.
Revision history for this message
kaputtnik (franku) wrote :

I got a total crash of the editor if i try to place fish on water... No output in console, just a total crash.

review: Needs Fixing
Revision history for this message
Tino (tino79) wrote :

Looks good and compiles fine.
But now, when I start the editor and increase a resource on any field I get a segfault.

review: Needs Fixing
Revision history for this message
xxx-deleted (janosch-peters-deactivatedaccount) wrote :

@kaputtnik,Tino: I missed a check for a nullptr. I fixed it in my latest push.

Revision history for this message
Tino (tino79) wrote :

Now it only segfaults when you decrease (shift-click) a resource or set to 0 (ctrl-click) on a field without a resource.

review: Needs Fixing
Revision history for this message
bunnybot (widelandsofficial) wrote :

Hi, I am bunnybot (https://github.com/widelands/bunnybot).

I am keeping the source branch lp:~janosch-peters/widelands/editor-remove-invalid-resources mirrored to https://github.com/widelands/widelands/tree/_janosch_peters_widelands_editor_remove_invalid_resources

The latest continuous integration build can always be found here: https://travis-ci.org/widelands/widelands/branches. Please do not merge without making sure that it passes.

You can give me commands by starting a line with @bunnybot <command>. I understand:
 merge: Merges the source branch into the target branch, closing the pull request.

Revision history for this message
Tino (tino79) wrote :

I've created a merge request for the last mentioned bug.

And I've noticed another inconsistency:
A field with e.g. a gold resource amount of 5. Now i cannot change the resource amount with the coal increase/decrease tool. But with coal-set-to amount (alt-click) tool i can "overwrite" the gold resource.
Of course this is no issue of this branch, but i was thinking perhaps we could find a better solution for this. Or is this the intentioned behavior?

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 132 has changed state to: failed. Details: https://travis-ci.org/widelands/widelands/builds/99834203.

Revision history for this message
TiborB (tiborb95) wrote :

Well now I dont know which branch is the "right" one, but still, I attached a custom map into bug - the one with problematic behavior, also see my comment in the diff

Revision history for this message
TiborB (tiborb95) wrote :

inserting comment into diff

Revision history for this message
xxx-deleted (janosch-peters-deactivatedaccount) wrote :

Please note: I found out that there was duplicated code in increase/decrease/set-methods. I extracted a method to remove the duplication. However, this will lead to a conflict with your fix in rev 7665. So I dont really know what to do with your merge proposal.

And I am really confused about your rev 7666. You changed 100+ files and I dont see the connection to my bugfix. Are all those changes neccessary to make travis work?

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 155 has changed state to: created. Details: https://travis-ci.org/widelands/widelands/builds/99868658.

Revision history for this message
Tino (tino79) wrote :

I've merged trunk. Although it does not conflict with your current status of the branch it contains some fixes that this branch can be build by travis-ci.
Just merge trunk before resubmitting this merge request.

And if your last fix includes the fix i've done, just dissapprove it (my merge request).

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 155 has changed state to: started. Details: https://travis-ci.org/widelands/widelands/builds/99868658.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 155 has changed state to: failed. Details: https://travis-ci.org/widelands/widelands/builds/99868658.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 155 has changed state to: failed. Details: https://travis-ci.org/widelands/widelands/builds/99868658.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 176 has changed state to: passed. Details: https://travis-ci.org/widelands/widelands/builds/100024382.

Revision history for this message
SirVer (sirver) wrote :

I think this is good to go. I have a couple of nits in the code still - most of them are your call, I do not feel strongly about them. Janosch, once you are happy with this change, please merge it by writing a comment on a line of its own: @bunnybot merge.

review: Approve
Revision history for this message
xxx-deleted (janosch-peters-deactivatedaccount) wrote :

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

'Branch' object has no attribute '_lp_object'

Revision history for this message
SirVer (sirver) wrote :

A bug in bunnybot :/. Let's try that again.

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

Running 'bzr merge ../_janosch_peters_widelands_editor_remove_invalid_resources' failed. Output:

bzr: ERROR: Working tree "/home/bunnybot/bunnybot/data/bzr_repo/_widelands_dev_widelands_trunk/" has uncommitted changes (See bzr status).

Revision history for this message
SirVer (sirver) wrote :

Three times a charm.

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/map_generator.cc'
2--- src/editor/map_generator.cc 2015-11-11 09:56:22 +0000
3+++ src/editor/map_generator.cc 2016-01-04 21:01:25 +0000
4@@ -133,7 +133,7 @@
5 uint8_t res_val = static_cast<uint8_t>(random_value / (kMaxElevation / max_amount));
6 res_val *= static_cast<uint8_t>(map_info_.resource_amount) + 1;
7 res_val /= 3;
8- if (editor_change_resource_tool_callback(fc, map_, world, res_idx)) {
9+ if (map_.is_resource_valid(world, fc, res_idx)) {
10 fc.field->set_resources(res_idx, res_val);
11 fc.field->set_initial_res_amount(res_val);
12 }
13
14=== modified file 'src/editor/tools/editor_decrease_height_tool.cc'
15--- src/editor/tools/editor_decrease_height_tool.cc 2014-09-10 14:08:25 +0000
16+++ src/editor/tools/editor_decrease_height_tool.cc 2016-01-04 21:01:25 +0000
17@@ -27,47 +27,47 @@
18 #include "logic/mapregion.h"
19
20 /// Decreases the heights by a value. Chages surrounding nodes if necessary.
21-int32_t EditorDecreaseHeightTool::handle_click_impl(Widelands::Map& map,
22- const Widelands::World& world,
23- Widelands::NodeAndTriangle<> center,
24- EditorInteractive& /* parent */,
25- EditorActionArgs& args) {
26- if (args.origHights.empty()) {
27+int32_t EditorDecreaseHeightTool::handle_click_impl(const Widelands::World& world,
28+ Widelands::NodeAndTriangle<> center,
29+ EditorInteractive& /* parent */,
30+ EditorActionArgs* args,
31+ Widelands::Map* map) {
32+ if (args->origHights.empty()) {
33 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
34- (map,
35+ (*map,
36 Widelands::Area<Widelands::FCoords>
37- (map.get_fcoords(center.node), args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
38- do args.origHights.push_back(mr.location().field->get_height());
39- while (mr.advance(map));
40+ (map->get_fcoords(center.node), args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
41+ do args->origHights.push_back(mr.location().field->get_height());
42+ while (mr.advance(*map));
43 }
44
45- return map.change_height(
46+ return map->change_height(
47 world,
48- Widelands::Area<Widelands::FCoords>(map.get_fcoords(center.node), args.sel_radius),
49- -args.change_by);
50+ Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius),
51+ -args->change_by);
52 }
53
54 int32_t EditorDecreaseHeightTool::handle_undo_impl
55- (Widelands::Map & map,
56- const Widelands::World& world,
57+ (const Widelands::World& world,
58 Widelands::NodeAndTriangle<> center,
59 EditorInteractive & /* parent */,
60- EditorActionArgs & args)
61+ EditorActionArgs* args,
62+ Widelands::Map* map)
63 {
64 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
65- (map,
66+ (*map,
67 Widelands::Area<Widelands::FCoords>
68- (map.get_fcoords(center.node), args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
69- std::list<Widelands::Field::Height>::iterator i = args.origHights.begin();
70+ (map->get_fcoords(center.node), args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
71+ std::list<Widelands::Field::Height>::iterator i = args->origHights.begin();
72
73 do {
74 mr.location().field->set_height(*i); ++i;
75- } while (mr.advance(map));
76+ } while (mr.advance(*map));
77
78- map.recalc_for_field_area(world,
79+ map->recalc_for_field_area(world,
80 Widelands::Area<Widelands::FCoords>(
81- map.get_fcoords(center.node),
82- args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 2));
83+ map->get_fcoords(center.node),
84+ args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 2));
85
86 return mr.radius() + 1;
87 }
88
89=== modified file 'src/editor/tools/editor_decrease_height_tool.h'
90--- src/editor/tools/editor_decrease_height_tool.h 2014-09-10 14:08:25 +0000
91+++ src/editor/tools/editor_decrease_height_tool.h 2016-01-04 21:01:25 +0000
92@@ -27,16 +27,18 @@
93 EditorDecreaseHeightTool() : EditorTool(*this, *this), m_change_by(1) {}
94
95 int32_t handle_click_impl
96- (Widelands::Map & map,
97- const Widelands::World& world,
98+ (const Widelands::World& world,
99 Widelands::NodeAndTriangle<> center,
100- EditorInteractive & parent, EditorActionArgs & args) override;
101+ EditorInteractive & parent,
102+ EditorActionArgs* args,
103+ Widelands::Map* map) override;
104
105 int32_t handle_undo_impl
106- (Widelands::Map & map,
107- const Widelands::World& world,
108+ (const Widelands::World& world,
109 Widelands::NodeAndTriangle<> center,
110- EditorInteractive & parent, EditorActionArgs & args) override;
111+ EditorInteractive& parent,
112+ EditorActionArgs* args,
113+ Widelands::Map* map) override;
114
115 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
116
117
118=== modified file 'src/editor/tools/editor_decrease_resources_tool.cc'
119--- src/editor/tools/editor_decrease_resources_tool.cc 2015-03-01 09:21:20 +0000
120+++ src/editor/tools/editor_decrease_resources_tool.cc 2016-01-04 21:01:25 +0000
121@@ -36,59 +36,40 @@
122 * there is not already another resource there.
123 */
124 int32_t
125-EditorDecreaseResourcesTool::handle_click_impl(Widelands::Map& map,
126- const Widelands::World& world,
127- Widelands::NodeAndTriangle<> const center,
128- EditorInteractive& /* parent */,
129- EditorActionArgs& args) {
130+EditorDecreaseResourcesTool::handle_click_impl(const Widelands::World& world,
131+ Widelands::NodeAndTriangle<> const center,
132+ EditorInteractive& /* parent */,
133+ EditorActionArgs* args,
134+ Widelands::Map* map) {
135 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
136- (map,
137+ (*map,
138 Widelands::Area<Widelands::FCoords>
139- (map.get_fcoords(center.node), args.sel_radius));
140+ (map->get_fcoords(center.node), args->sel_radius));
141 do {
142- int32_t res = mr.location().field->get_resources();
143 int32_t amount = mr.location().field->get_resources_amount();
144
145- amount -= args.change_by;
146+ amount -= args->change_by;
147 if (amount < 0)
148 amount = 0;
149
150- args.orgResT.push_back(res);
151- args.orgRes.push_back(mr.location().field->get_resources_amount());
152-
153- if (res == args.cur_res &&
154- editor_change_resource_tool_callback(mr.location(), map, world, args.cur_res)) {
155- // Ok, we're doing something. First remove the current overlays.
156- std::string str =
157- world.get_resource(res)->get_editor_pic
158- (mr.location().field->get_resources_amount());
159- const Image* pic = g_gr->images().get(str);
160- map.overlay_manager().remove_overlay(mr.location(), pic);
161- if (!amount) {
162- mr.location().field->set_resources(0, 0);
163- mr.location().field->set_initial_res_amount(0);
164- } else {
165- mr.location().field->set_resources(args.cur_res, amount);
166- mr.location().field->set_initial_res_amount(amount);
167- // set new overlay
168- str = world.get_resource(args.cur_res)->get_editor_pic(amount);
169- pic = g_gr->images().get(str);
170- map.overlay_manager().register_overlay(mr.location(), pic, 4);
171- map.recalc_for_field_area(
172- world, Widelands::Area<Widelands::FCoords>(mr.location(), 0));
173- }
174+ if (mr.location().field->get_resources() == args->cur_res &&
175+ map->is_resource_valid(world, mr.location(), args->cur_res)) {
176+ args->orgResT.push_back(mr.location().field->get_resources());
177+ args->orgRes.push_back(mr.location().field->get_resources_amount());
178+ EditorSetResourcesTool::set_res_and_overlay(world, amount, args->cur_res, &mr, args, map);
179 }
180- } while (mr.advance(map));
181+
182+
183+ } while (mr.advance(*map));
184 return mr.radius();
185 }
186
187-int32_t EditorDecreaseResourcesTool::handle_undo_impl(
188- Widelands::Map& map,
189- const Widelands::World& world,
190- Widelands::NodeAndTriangle<Widelands::Coords> center,
191- EditorInteractive& parent,
192- EditorActionArgs& args) {
193- return parent.tools.set_resources.handle_undo_impl(map, world, center, parent, args);
194+int32_t EditorDecreaseResourcesTool::handle_undo_impl(const Widelands::World& world,
195+ Widelands::NodeAndTriangle<> center,
196+ EditorInteractive& parent,
197+ EditorActionArgs* args,
198+ Widelands::Map* map) {
199+ return parent.tools.set_resources.handle_undo_impl(world, center, parent, args, map);
200 }
201
202 EditorActionArgs EditorDecreaseResourcesTool::format_args_impl(EditorInteractive & parent)
203
204=== modified file 'src/editor/tools/editor_decrease_resources_tool.h'
205--- src/editor/tools/editor_decrease_resources_tool.h 2015-11-11 09:56:22 +0000
206+++ src/editor/tools/editor_decrease_resources_tool.h 2016-01-04 21:01:25 +0000
207@@ -28,17 +28,17 @@
208 : EditorTool(*this, *this), m_cur_res(0), m_change_by(1)
209 {}
210
211- int32_t handle_click_impl(Widelands::Map& map,
212- const Widelands::World& world,
213+ int32_t handle_click_impl(const Widelands::World& world,
214 Widelands::NodeAndTriangle<> center,
215 EditorInteractive& parent,
216- EditorActionArgs& args) override;
217+ EditorActionArgs* args,
218+ Widelands::Map* map) override;
219
220- int32_t handle_undo_impl(Widelands::Map& map,
221- const Widelands::World& world,
222+ int32_t handle_undo_impl(const Widelands::World& world,
223 Widelands::NodeAndTriangle<> center,
224 EditorInteractive& parent,
225- EditorActionArgs& args) override;
226+ EditorActionArgs* args,
227+ Widelands::Map* map) override;
228
229 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
230
231
232=== modified file 'src/editor/tools/editor_delete_bob_tool.cc'
233--- src/editor/tools/editor_delete_bob_tool.cc 2014-09-10 14:08:25 +0000
234+++ src/editor/tools/editor_delete_bob_tool.cc 2016-01-04 21:01:25 +0000
235@@ -28,37 +28,37 @@
236 * Deletes the bob at the given location
237 */
238 int32_t
239-EditorDeleteBobTool::handle_click_impl(Widelands::Map& map,
240- const Widelands::World&,
241- Widelands::NodeAndTriangle<Widelands::Coords> center,
242- EditorInteractive& parent,
243- EditorActionArgs& args) {
244+EditorDeleteBobTool::handle_click_impl(const Widelands::World&,
245+ Widelands::NodeAndTriangle<Widelands::Coords> center,
246+ EditorInteractive& parent,
247+ EditorActionArgs* args,
248+ Widelands::Map* map) {
249 Widelands::EditorGameBase & egbase = parent.egbase();
250- const int32_t radius = args.sel_radius;
251+ const int32_t radius = args->sel_radius;
252 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
253- (map,
254+ (*map,
255 Widelands::Area<Widelands::FCoords>
256- (map.get_fcoords(center.node), radius));
257+ (map->get_fcoords(center.node), radius));
258
259 do if (Widelands::Bob * const bob = mr.location().field->get_first_bob()) {
260- args.obob_type.push_back(&bob->descr());
261+ args->obob_type.push_back(&bob->descr());
262 bob->remove(egbase);
263 } else {
264- args.obob_type.push_back(nullptr);
265+ args->obob_type.push_back(nullptr);
266 }
267- while (mr.advance(map));
268+ while (mr.advance(*map));
269 return radius + 2;
270 }
271
272 int32_t
273-EditorDeleteBobTool::handle_undo_impl(Widelands::Map& map,
274- const Widelands::World& world,
275- Widelands::NodeAndTriangle<Widelands::Coords> center,
276- EditorInteractive& parent,
277- EditorActionArgs& args) {
278+EditorDeleteBobTool::handle_undo_impl(const Widelands::World& world,
279+ Widelands::NodeAndTriangle<Widelands::Coords> center,
280+ EditorInteractive& parent,
281+ EditorActionArgs* args,
282+ Widelands::Map* map) {
283
284- uint32_t ret = parent.tools.place_bob.handle_undo_impl(map, world, center, parent, args);
285- args.obob_type.clear();
286+ uint32_t ret = parent.tools.place_bob.handle_undo_impl(world, center, parent, args, map);
287+ args->obob_type.clear();
288 return ret;
289 }
290
291
292=== modified file 'src/editor/tools/editor_delete_bob_tool.h'
293--- src/editor/tools/editor_delete_bob_tool.h 2014-09-10 14:08:25 +0000
294+++ src/editor/tools/editor_delete_bob_tool.h 2016-01-04 21:01:25 +0000
295@@ -26,17 +26,17 @@
296 struct EditorDeleteBobTool : public EditorTool {
297 EditorDeleteBobTool() : EditorTool(*this, *this) {}
298
299- int32_t handle_click_impl(Widelands::Map& map,
300- const Widelands::World& world,
301+ int32_t handle_click_impl(const Widelands::World& world,
302 Widelands::NodeAndTriangle<> center,
303 EditorInteractive& parent,
304- EditorActionArgs& args) override;
305+ EditorActionArgs* args,
306+ Widelands::Map* map) override;
307
308- int32_t handle_undo_impl(Widelands::Map& map,
309- const Widelands::World& world,
310+ int32_t handle_undo_impl(const Widelands::World& world,
311 Widelands::NodeAndTriangle<> center,
312 EditorInteractive& parent,
313- EditorActionArgs& args) override;
314+ EditorActionArgs* args,
315+ Widelands::Map* map) override;
316
317 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
318
319
320=== modified file 'src/editor/tools/editor_delete_immovable_tool.cc'
321--- src/editor/tools/editor_delete_immovable_tool.cc 2014-09-10 14:08:25 +0000
322+++ src/editor/tools/editor_delete_immovable_tool.cc 2016-01-04 21:01:25 +0000
323@@ -28,38 +28,37 @@
324 /**
325 * Deletes the immovable at the given location
326 */
327-int32_t EditorDeleteImmovableTool::handle_click_impl(Widelands::Map& map,
328- const Widelands::World&,
329- Widelands::NodeAndTriangle<> const center,
330- EditorInteractive& parent,
331- EditorActionArgs& args) {
332+int32_t EditorDeleteImmovableTool::handle_click_impl(const Widelands::World&,
333+ Widelands::NodeAndTriangle<> const center,
334+ EditorInteractive& parent,
335+ EditorActionArgs* args,
336+ Widelands::Map* map) {
337 Widelands::EditorGameBase & egbase = parent.egbase();
338 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
339- (map,
340+ (*map,
341 Widelands::Area<Widelands::FCoords>
342- (map.get_fcoords(center.node), args.sel_radius));
343+ (map->get_fcoords(center.node), args->sel_radius));
344 do if
345 (upcast
346 (Widelands::Immovable,
347 immovable,
348 mr.location().field->get_immovable()))
349 {
350- args.oimmov_types.push_back(immovable->descr().name());
351+ args->oimmov_types.push_back(immovable->descr().name());
352 immovable->remove(egbase); // Delete no buildings or stuff.
353 } else {
354- args.oimmov_types.push_back("");
355+ args->oimmov_types.push_back("");
356 }
357- while (mr.advance(map));
358+ while (mr.advance(*map));
359 return mr.radius() + 2;
360 }
361
362-int32_t EditorDeleteImmovableTool::handle_undo_impl(
363- Widelands::Map& map,
364- const Widelands::World& world,
365- Widelands::NodeAndTriangle<Widelands::Coords> center,
366- EditorInteractive& parent,
367- EditorActionArgs& args) {
368- return parent.tools.place_immovable.handle_undo_impl(map, world, center, parent, args);
369+int32_t EditorDeleteImmovableTool::handle_undo_impl(const Widelands::World& world,
370+ Widelands::NodeAndTriangle<Widelands::Coords> center,
371+ EditorInteractive& parent,
372+ EditorActionArgs* args,
373+ Widelands::Map* map) {
374+ return parent.tools.place_immovable.handle_undo_impl(world, center, parent, args, map);
375 }
376
377 EditorActionArgs EditorDeleteImmovableTool::format_args_impl(EditorInteractive & parent)
378
379=== modified file 'src/editor/tools/editor_delete_immovable_tool.h'
380--- src/editor/tools/editor_delete_immovable_tool.h 2014-09-10 14:08:25 +0000
381+++ src/editor/tools/editor_delete_immovable_tool.h 2016-01-04 21:01:25 +0000
382@@ -26,17 +26,17 @@
383 struct EditorDeleteImmovableTool : public EditorTool {
384 EditorDeleteImmovableTool() : EditorTool(*this, *this) {}
385
386- int32_t handle_click_impl(Widelands::Map& map,
387- const Widelands::World& world,
388+ int32_t handle_click_impl(const Widelands::World& world,
389 Widelands::NodeAndTriangle<> center,
390 EditorInteractive& parent,
391- EditorActionArgs& args) override;
392+ EditorActionArgs* args,
393+ Widelands::Map* map) override;
394
395- int32_t handle_undo_impl(Widelands::Map& map,
396- const Widelands::World& world,
397+ int32_t handle_undo_impl(const Widelands::World& world,
398 Widelands::NodeAndTriangle<> center,
399 EditorInteractive& parent,
400- EditorActionArgs& args) override;
401+ EditorActionArgs* args,
402+ Widelands::Map* map) override;
403
404 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
405
406
407=== modified file 'src/editor/tools/editor_draw_tool.cc'
408--- src/editor/tools/editor_draw_tool.cc 2014-09-10 14:08:25 +0000
409+++ src/editor/tools/editor_draw_tool.cc 2016-01-04 21:01:25 +0000
410@@ -34,40 +34,40 @@
411 }
412
413 int32_t
414-EditorDrawTool::handle_click_impl(Widelands::Map& /* map */,
415- const Widelands::World& world,
416- Widelands::NodeAndTriangle<Widelands::Coords> /* center */,
417- EditorInteractive& /* parent */,
418- EditorActionArgs& args) {
419+EditorDrawTool::handle_click_impl(const Widelands::World& world,
420+ Widelands::NodeAndTriangle<Widelands::Coords> /* center */,
421+ EditorInteractive& /* parent */,
422+ EditorActionArgs* args,
423+ Widelands::Map* /* map */) {
424
425 for
426- (std::list<EditorToolAction *>::iterator i = args.draw_actions.begin();
427- i != args.draw_actions.end();
428+ (std::list<EditorToolAction *>::iterator i = args->draw_actions.begin();
429+ i != args->draw_actions.end();
430 ++i)
431 {
432 (*i)->tool.handle_click
433 (static_cast<EditorTool::ToolIndex>((*i)->i),
434- (*i)->map, world, (*i)->center, (*i)->parent, *((*i)->args));
435+ world, (*i)->center, (*i)->parent, (*i)->args, &((*i)->map));
436 }
437- return args.draw_actions.size();
438+ return args->draw_actions.size();
439 }
440
441 int32_t
442-EditorDrawTool::handle_undo_impl(Widelands::Map& /* map */,
443- const Widelands::World& world,
444- Widelands::NodeAndTriangle<Widelands::Coords> /* center */,
445- EditorInteractive& /* parent */,
446- EditorActionArgs& args) {
447+EditorDrawTool::handle_undo_impl(const Widelands::World& world,
448+ Widelands::NodeAndTriangle<Widelands::Coords> /* center */,
449+ EditorInteractive& /* parent */,
450+ EditorActionArgs* args,
451+ Widelands::Map* /* map */) {
452 for
453- (std::list<EditorToolAction *>::reverse_iterator i = args.draw_actions.rbegin();
454- i != args.draw_actions.rend();
455+ (std::list<EditorToolAction *>::reverse_iterator i = args->draw_actions.rbegin();
456+ i != args->draw_actions.rend();
457 ++i)
458 {
459 (*i)->tool.handle_undo
460 (static_cast<EditorTool::ToolIndex>((*i)->i),
461- (*i)->map, world, (*i)->center, (*i)->parent, *((*i)->args));
462+ world, (*i)->center, (*i)->parent, (*i)->args, &((*i)->map));
463 }
464- return args.draw_actions.size();
465+ return args->draw_actions.size();
466 }
467
468 EditorActionArgs EditorDrawTool::format_args_impl(EditorInteractive & parent)
469
470=== modified file 'src/editor/tools/editor_draw_tool.h'
471--- src/editor/tools/editor_draw_tool.h 2014-09-10 14:08:25 +0000
472+++ src/editor/tools/editor_draw_tool.h 2016-01-04 21:01:25 +0000
473@@ -28,17 +28,17 @@
474 struct EditorDrawTool : public EditorTool {
475 EditorDrawTool() : EditorTool(*this, *this) {}
476
477- int32_t handle_click_impl(Widelands::Map& map,
478- const Widelands::World& world,
479+ int32_t handle_click_impl(const Widelands::World& world,
480 Widelands::NodeAndTriangle<> center,
481 EditorInteractive& parent,
482- EditorActionArgs& args) override;
483+ EditorActionArgs* args,
484+ Widelands::Map* map) override;
485
486- int32_t handle_undo_impl(Widelands::Map& map,
487- const Widelands::World& world,
488+ int32_t handle_undo_impl(const Widelands::World& world,
489 Widelands::NodeAndTriangle<> center,
490 EditorInteractive& parent,
491- EditorActionArgs& args) override;
492+ EditorActionArgs* args,
493+ Widelands::Map* map) override;
494
495 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
496
497
498=== modified file 'src/editor/tools/editor_history.cc'
499--- src/editor/tools/editor_history.cc 2014-09-10 14:08:25 +0000
500+++ src/editor/tools/editor_history.cc 2016-01-04 21:01:25 +0000
501@@ -67,11 +67,11 @@
502 m_redo_button.set_enabled(true);
503
504 return uac.tool.handle_undo(static_cast<EditorTool::ToolIndex>(uac.i),
505- uac.map,
506 world,
507 uac.center,
508 uac.parent,
509- *uac.args);
510+ uac.args,
511+ &(uac.map));
512 }
513
514 uint32_t EditorHistory::redo_action(const Widelands::World& world) {
515@@ -86,11 +86,11 @@
516 m_redo_button.set_enabled(!redo_stack.empty());
517
518 return rac.tool.handle_click(static_cast<EditorTool::ToolIndex>(rac.i),
519- rac.map,
520 world,
521 rac.center,
522 rac.parent,
523- *rac.args);
524+ rac.args,
525+ &(rac.map));
526 }
527
528 uint32_t EditorHistory::do_action(EditorTool& tool,
529@@ -131,7 +131,7 @@
530 m_undo_button.set_enabled(true);
531 m_redo_button.set_enabled(false);
532 }
533- return tool.handle_click(ind, map, world, center, parent, *ac.args);
534+ return tool.handle_click(ind, world, center, parent, ac.args, &map);
535 }
536
537
538
539=== modified file 'src/editor/tools/editor_increase_height_tool.cc'
540--- src/editor/tools/editor_increase_height_tool.cc 2014-09-10 14:08:25 +0000
541+++ src/editor/tools/editor_increase_height_tool.cc 2016-01-04 21:01:25 +0000
542@@ -24,35 +24,35 @@
543 #include "logic/map.h"
544 #include "logic/mapregion.h"
545
546-/// Increases the heights by a value. Chages surrounding nodes if necessary.
547-int32_t EditorIncreaseHeightTool::handle_click_impl(Widelands::Map& map,
548- const Widelands::World& world,
549- Widelands::NodeAndTriangle<> center,
550- EditorInteractive& /* parent */,
551- EditorActionArgs& args) {
552- if (args.origHights.empty()) {
553+/// Increases the heights by a value. Changes surrounding nodes if necessary.
554+int32_t EditorIncreaseHeightTool::handle_click_impl(const Widelands::World& world,
555+ Widelands::NodeAndTriangle<> center,
556+ EditorInteractive& /* parent */,
557+ EditorActionArgs* args,
558+ Widelands::Map* map) {
559+ if (args->origHights.empty()) {
560 Widelands::MapRegion<Widelands::Area<Widelands::FCoords>> mr(
561- map,
562+ *map,
563 Widelands::Area<Widelands::FCoords>(
564- map.get_fcoords(center.node),
565- args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
566+ map->get_fcoords(center.node),
567+ args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
568 do {
569- args.origHights.push_back(mr.location().field->get_height());
570- } while (mr.advance(map));
571+ args->origHights.push_back(mr.location().field->get_height());
572+ } while (mr.advance(*map));
573 }
574
575- return map.change_height(
576+ return map->change_height(
577 world,
578- Widelands::Area<Widelands::FCoords>(map.get_fcoords(center.node), args.sel_radius),
579- args.change_by);
580+ Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius),
581+ args->change_by);
582 }
583
584-int32_t EditorIncreaseHeightTool::handle_undo_impl(Widelands::Map& map,
585- const Widelands::World& world,
586- Widelands::NodeAndTriangle<> center,
587- EditorInteractive& parent,
588- EditorActionArgs& args) {
589- return m_decrease_tool.handle_undo_impl(map, world, center, parent, args);
590+int32_t EditorIncreaseHeightTool::handle_undo_impl(const Widelands::World& world,
591+ Widelands::NodeAndTriangle<> center,
592+ EditorInteractive& parent,
593+ EditorActionArgs* args,
594+ Widelands::Map* map) {
595+ return m_decrease_tool.handle_undo_impl(world, center, parent, args, map);
596 }
597
598 EditorActionArgs EditorIncreaseHeightTool::format_args_impl(EditorInteractive & parent)
599
600=== modified file 'src/editor/tools/editor_increase_height_tool.h'
601--- src/editor/tools/editor_increase_height_tool.h 2014-09-10 14:08:25 +0000
602+++ src/editor/tools/editor_increase_height_tool.h 2016-01-04 21:01:25 +0000
603@@ -34,17 +34,17 @@
604 m_change_by(1)
605 {}
606
607- int32_t handle_click_impl(Widelands::Map& map,
608- const Widelands::World& world,
609+ int32_t handle_click_impl(const Widelands::World& world,
610 Widelands::NodeAndTriangle<> center,
611 EditorInteractive& parent,
612- EditorActionArgs& args) override;
613+ EditorActionArgs* args,
614+ Widelands::Map* map) override;
615
616- int32_t handle_undo_impl(Widelands::Map& map,
617- const Widelands::World& world,
618+ int32_t handle_undo_impl(const Widelands::World& world,
619 Widelands::NodeAndTriangle<> center,
620 EditorInteractive& parent,
621- EditorActionArgs& args) override;
622+ EditorActionArgs* args,
623+ Widelands::Map* map) override;
624
625 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
626
627
628=== modified file 'src/editor/tools/editor_increase_resources_tool.cc'
629--- src/editor/tools/editor_increase_resources_tool.cc 2015-12-05 10:59:02 +0000
630+++ src/editor/tools/editor_increase_resources_tool.cc 2016-01-04 21:01:25 +0000
631@@ -30,120 +30,44 @@
632
633 using Widelands::TCoords;
634
635-namespace {
636-
637-int32_t resource_value(const Widelands::TerrainDescription& terrain,
638- const Widelands::DescriptionIndex resource) {
639- if (!terrain.is_resource_valid(resource)) {
640- return -1;
641- }
642- if (terrain.get_is() & Widelands::TerrainDescription::Is::kUnwalkable) {
643- return 8;
644- }
645- return 1;
646-}
647-
648-} // namespace
649-
650-
651-int32_t editor_change_resource_tool_callback
652- (const TCoords<Widelands::FCoords>& c, Widelands::Map& map,
653- const Widelands::World& world, int32_t const curres)
654-{
655- Widelands::FCoords f(c, &map[c]);
656-
657- Widelands::FCoords f1;
658- int32_t count = 0;
659-
660- // this field
661- count += resource_value(world.terrain_descr(f.field->terrain_r()), curres);
662- count += resource_value(world.terrain_descr(f.field->terrain_d()), curres);
663-
664- // If one of the neighbours is unwalkable, count its resource stronger.
665- // top left neigbour
666- map.get_neighbour(f, Widelands::WALK_NW, &f1);
667- count += resource_value(world.terrain_descr(f1.field->terrain_r()), curres);
668- count += resource_value(world.terrain_descr(f1.field->terrain_d()), curres);
669-
670- // top right neigbour
671- map.get_neighbour(f, Widelands::WALK_NE, &f1);
672- count += resource_value(world.terrain_descr(f1.field->terrain_d()), curres);
673-
674- // left neighbour
675- map.get_neighbour(f, Widelands::WALK_W, &f1);
676- count += resource_value(world.terrain_descr(f1.field->terrain_r()), curres);
677-
678- return count <= 3 ? 0 : f.field->nodecaps();
679-}
680-
681-/*
682-===========
683-EditorIncreaseResourcesTool::handle_click_impl()
684-
685-increase the resources of the current field by one if
686-there is not already another resource there.
687-===========
688-*/
689 int32_t
690-EditorIncreaseResourcesTool::handle_click_impl(Widelands::Map& map,
691- const Widelands::World& world,
692- Widelands::NodeAndTriangle<> const center,
693- EditorInteractive& /* parent */,
694- EditorActionArgs& args) {
695- OverlayManager & overlay_manager = map.overlay_manager();
696+EditorIncreaseResourcesTool::handle_click_impl(const Widelands::World& world,
697+ Widelands::NodeAndTriangle<> const center,
698+ EditorInteractive& /* parent */,
699+ EditorActionArgs* args,
700+ Widelands::Map* map) {
701 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
702- (map,
703+ (*map,
704 Widelands::Area<Widelands::FCoords>
705- (map.get_fcoords(center.node), args.sel_radius));
706+ (map->get_fcoords(center.node), args->sel_radius));
707 do {
708- int32_t res = mr.location().field->get_resources();
709 int32_t amount = mr.location().field->get_resources_amount();
710- int32_t max_amount = world.get_resource(args.cur_res)->max_amount();
711+ int32_t max_amount = args->cur_res != Widelands::kNoResource ?
712+ world.get_resource(args->cur_res)->max_amount() : 0;
713
714- amount += args.change_by;
715+ amount += args->change_by;
716 if (amount > max_amount)
717 amount = max_amount;
718
719- args.orgResT.push_back(res);
720- args.orgRes.push_back(mr.location().field->get_resources_amount());
721-
722- if
723- ((res == args.cur_res || !mr.location().field->get_resources_amount())
724- &&
725- editor_change_resource_tool_callback(mr.location(), map, world, args.cur_res))
726- {
727- // Ok, we're doing something. First remove the current overlays.
728- const Image* pic =
729- g_gr->images().get
730- (world.get_resource(res)->get_editor_pic
731- (mr.location().field->get_resources_amount()));
732- overlay_manager.remove_overlay(mr.location(), pic);
733-
734- if (!amount) {
735- mr.location().field->set_resources(0, 0);
736- mr.location().field->set_initial_res_amount(0);
737- } else {
738- mr.location().field->set_resources(args.cur_res, amount);
739- mr.location().field->set_initial_res_amount(amount);
740- // set new overlay
741- pic = g_gr->images().get
742- (world.get_resource(args.cur_res)->get_editor_pic(amount));
743- overlay_manager.register_overlay(mr.location(), pic, 4);
744- map.recalc_for_field_area(
745- world, Widelands::Area<Widelands::FCoords>(mr.location(), 0));
746- }
747+ if ((mr.location().field->get_resources() == args->cur_res ||
748+ !mr.location().field->get_resources_amount()) &&
749+ map->is_resource_valid(world, mr.location(), args->cur_res)) {
750+ args->orgResT.push_back(mr.location().field->get_resources());
751+ args->orgRes.push_back(mr.location().field->get_resources_amount());
752+ EditorSetResourcesTool::set_res_and_overlay(world, amount, args->cur_res, &mr, args, map);
753 }
754- } while (mr.advance(map));
755+
756+
757+ } while (mr.advance(*map));
758 return mr.radius();
759 }
760
761-int32_t EditorIncreaseResourcesTool::handle_undo_impl(
762- Widelands::Map& map,
763- const Widelands::World& world,
764- Widelands::NodeAndTriangle<Widelands::Coords> center,
765- EditorInteractive& parent,
766- EditorActionArgs& args) {
767- return m_set_tool.handle_undo_impl(map, world, center, parent, args);
768+int32_t EditorIncreaseResourcesTool::handle_undo_impl(const Widelands::World& world,
769+ Widelands::NodeAndTriangle<Widelands::Coords> center,
770+ EditorInteractive& parent,
771+ EditorActionArgs* args,
772+ Widelands::Map* map) {
773+ return m_set_tool.handle_undo_impl(world, center, parent, args, map);
774 }
775
776 EditorActionArgs EditorIncreaseResourcesTool::format_args_impl(EditorInteractive & parent)
777
778=== modified file 'src/editor/tools/editor_increase_resources_tool.h'
779--- src/editor/tools/editor_increase_resources_tool.h 2015-11-11 09:56:22 +0000
780+++ src/editor/tools/editor_increase_resources_tool.h 2016-01-04 21:01:25 +0000
781@@ -35,17 +35,21 @@
782 m_cur_res(0) {
783 }
784
785- int32_t handle_click_impl(Widelands::Map& map,
786- const Widelands::World& world,
787+ /***
788+ * Increase the resources of the current field by one if there is not already
789+ * another resource there.
790+ */
791+ int32_t handle_click_impl(const Widelands::World& world,
792 Widelands::NodeAndTriangle<> center,
793 EditorInteractive& parent,
794- EditorActionArgs& args) override;
795+ EditorActionArgs* args,
796+ Widelands::Map* map) override;
797
798- int32_t handle_undo_impl(Widelands::Map& map,
799- const Widelands::World& world,
800+ int32_t handle_undo_impl(const Widelands::World& world,
801 Widelands::NodeAndTriangle<> center,
802 EditorInteractive& parent,
803- EditorActionArgs& args) override;
804+ EditorActionArgs* args,
805+ Widelands::Map* map) override;
806
807 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
808
809@@ -72,8 +76,5 @@
810 Widelands::DescriptionIndex m_cur_res;
811 };
812
813-int32_t editor_change_resource_tool_callback
814- (const Widelands::TCoords<Widelands::FCoords>& c, Widelands::Map& map,
815- const Widelands::World& world, int32_t const curres);
816
817 #endif // end of include guard: WL_EDITOR_TOOLS_EDITOR_INCREASE_RESOURCES_TOOL_H
818
819=== modified file 'src/editor/tools/editor_info_tool.cc'
820--- src/editor/tools/editor_info_tool.cc 2015-12-05 10:59:02 +0000
821+++ src/editor/tools/editor_info_tool.cc 2016-01-04 21:01:25 +0000
822@@ -34,11 +34,11 @@
823 #include "ui_basic/window.h"
824
825 /// Show a window with information about the pointed at node and triangle.
826-int32_t EditorInfoTool::handle_click_impl(Widelands::Map& map,
827- const Widelands::World& world,
828- Widelands::NodeAndTriangle<> center,
829- EditorInteractive& parent,
830- EditorActionArgs& /* args */) {
831+int32_t EditorInfoTool::handle_click_impl(const Widelands::World& world,
832+ Widelands::NodeAndTriangle<> center,
833+ EditorInteractive& parent,
834+ EditorActionArgs* /* args */,
835+ Widelands::Map* map) {
836 UI::Window * const w =
837 new UI::Window
838 (&parent, "field_information", 30, 30, 400, 200,
839@@ -47,7 +47,7 @@
840 new UI::MultilineTextarea
841 (w, 0, 0, w->get_inner_w(), w->get_inner_h());
842
843- Widelands::Field & f = map[center.node];
844+ Widelands::Field & f = (*map)[center.node];
845
846 // *** Node info
847 std::string buf = _("Node:");
848@@ -101,7 +101,7 @@
849 // *** Terrain info
850 buf += std::string("\n") + _("Terrain:") + "\n";
851
852- const Widelands::Field & tf = map[center.triangle];
853+ const Widelands::Field & tf = (*map)[center.triangle];
854 const Widelands::TerrainDescription& ter = world.terrain_descr(
855 center.triangle.t == Widelands::TCoords<>::D ? tf.terrain_d() : tf.terrain_r());
856
857@@ -135,20 +135,20 @@
858
859 // *** Map info
860 buf += std::string("\n") + _("Map:") + "\n";
861- buf += "• " + (boost::format(pgettext("map_name", "Name: %s")) % map.get_name().c_str()).str() + "\n";
862+ buf += "• " + (boost::format(pgettext("map_name", "Name: %s")) % map->get_name().c_str()).str() + "\n";
863 buf += "• " + (boost::format(_("Size: %1$ix%2$i"))
864- % map.get_width() % map.get_height()).str() + "\n";
865+ % map->get_width() % map->get_height()).str() + "\n";
866
867- if (map.get_nrplayers() > 0) {
868+ if (map->get_nrplayers() > 0) {
869 buf += "• " +
870- (boost::format(_("Players: %u")) % static_cast<unsigned int>(map.get_nrplayers())).str() + "\n";
871+ (boost::format(_("Players: %u")) % static_cast<unsigned int>(map->get_nrplayers())).str() + "\n";
872 }
873 else {
874 buf += "• " + std::string(_("Players: -")) + "\n";
875 }
876
877- buf += "• " + (boost::format(_("Author: %s")) % map.get_author()).str() + "\n";
878- buf += "• " + (boost::format(_("Descr: %s")) % map.get_description().c_str()).str() + "\n";
879+ buf += "• " + (boost::format(_("Author: %s")) % map->get_author()).str() + "\n";
880+ buf += "• " + (boost::format(_("Descr: %s")) % map->get_description().c_str()).str() + "\n";
881
882 multiline_textarea->set_text(buf.c_str());
883
884
885=== modified file 'src/editor/tools/editor_info_tool.h'
886--- src/editor/tools/editor_info_tool.h 2015-07-25 19:25:00 +0000
887+++ src/editor/tools/editor_info_tool.h 2016-01-04 21:01:25 +0000
888@@ -27,11 +27,11 @@
889 EditorInfoTool() : EditorTool(*this, *this, false) {
890 }
891
892- int32_t handle_click_impl(Widelands::Map& map,
893- const Widelands::World& world,
894+ int32_t handle_click_impl(const Widelands::World& world,
895 Widelands::NodeAndTriangle<> center,
896 EditorInteractive& parent,
897- EditorActionArgs& args) override;
898+ EditorActionArgs* args,
899+ Widelands::Map* map) override;
900
901 char const* get_sel_impl() const override {
902 return "pics/fsel_editor_info.png";
903
904=== modified file 'src/editor/tools/editor_make_infrastructure_tool.cc'
905--- src/editor/tools/editor_make_infrastructure_tool.cc 2014-09-20 09:37:47 +0000
906+++ src/editor/tools/editor_make_infrastructure_tool.cc 2016-01-04 21:01:25 +0000
907@@ -46,11 +46,11 @@
908 *
909 * Obviously, this function ignores the sel radius
910 */
911-int32_t EditorMakeInfrastructureTool::handle_click_impl(Widelands::Map&,
912- const Widelands::World&,
913- Widelands::NodeAndTriangle<> const,
914- EditorInteractive& parent,
915- EditorActionArgs& /* args */) {
916+int32_t EditorMakeInfrastructureTool::handle_click_impl(const Widelands::World&,
917+ Widelands::NodeAndTriangle<> const,
918+ EditorInteractive& parent,
919+ EditorActionArgs* /* args */,
920+ Widelands::Map*) {
921 show_field_action
922 (&parent, parent.egbase().get_player(m_player), &m_registry);
923
924
925=== modified file 'src/editor/tools/editor_make_infrastructure_tool.h'
926--- src/editor/tools/editor_make_infrastructure_tool.h 2014-09-20 09:37:47 +0000
927+++ src/editor/tools/editor_make_infrastructure_tool.h 2016-01-04 21:01:25 +0000
928@@ -39,11 +39,11 @@
929 Widelands::PlayerNumber get_player() const
930 {return m_player;}
931
932- int32_t handle_click_impl(Widelands::Map& map,
933- const Widelands::World& world,
934+ int32_t handle_click_impl(const Widelands::World& world,
935 Widelands::NodeAndTriangle<> center,
936 EditorInteractive& parent,
937- EditorActionArgs& args) override;
938+ EditorActionArgs* args,
939+ Widelands::Map* map) override;
940
941 const char * get_sel_impl() const override
942 {return "pics/fsel.png";} // Standard sel icon, most complex tool of all
943
944=== modified file 'src/editor/tools/editor_noise_height_tool.cc'
945--- src/editor/tools/editor_noise_height_tool.cc 2014-09-10 14:08:25 +0000
946+++ src/editor/tools/editor_noise_height_tool.cc 2016-01-04 21:01:25 +0000
947@@ -27,47 +27,47 @@
948 #include "logic/mapregion.h"
949
950 /// Sets the heights to random values. Changes surrounding nodes if necessary.
951-int32_t EditorNoiseHeightTool::handle_click_impl(Widelands::Map& map,
952- const Widelands::World& world,
953- Widelands::NodeAndTriangle<> const center,
954- EditorInteractive& /* parent */,
955- EditorActionArgs& args) {
956- if (args.origHights.empty()) {
957+int32_t EditorNoiseHeightTool::handle_click_impl(const Widelands::World& world,
958+ Widelands::NodeAndTriangle<> const center,
959+ EditorInteractive& /* parent */,
960+ EditorActionArgs* args,
961+ Widelands::Map* map) {
962+ if (args->origHights.empty()) {
963 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
964- (map,
965+ (*map,
966 Widelands::Area<Widelands::FCoords>
967- (map.get_fcoords(center.node),
968- args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
969- do args.origHights.push_back(mr.location().field->get_height());
970- while (mr.advance(map));
971+ (map->get_fcoords(center.node),
972+ args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
973+ do args->origHights.push_back(mr.location().field->get_height());
974+ while (mr.advance(*map));
975 }
976
977 uint32_t max = 0;
978
979 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
980- (map,
981+ (*map,
982 Widelands::Area<Widelands::FCoords>
983- (map.get_fcoords(center.node), args.sel_radius));
984+ (map->get_fcoords(center.node), args->sel_radius));
985 do {
986 max = std::max(
987 max,
988- map.set_height(world,
989+ map->set_height(world,
990 mr.location(),
991- args.m_interval.min +
992+ args->m_interval.min +
993 static_cast<int32_t>(
994- static_cast<double>(args.m_interval.max - args.m_interval.min + 1) *
995+ static_cast<double>(args->m_interval.max - args->m_interval.min + 1) *
996 rand() / (RAND_MAX + 1.0))));
997- } while (mr.advance(map));
998+ } while (mr.advance(*map));
999 return mr.radius() + max;
1000 }
1001
1002 int32_t
1003-EditorNoiseHeightTool::handle_undo_impl(Widelands::Map& map,
1004- const Widelands::World& world,
1005- Widelands::NodeAndTriangle<Widelands::Coords> center,
1006- EditorInteractive& parent,
1007- EditorActionArgs& args) {
1008- return m_set_tool.handle_undo_impl(map, world, center, parent, args);
1009+EditorNoiseHeightTool::handle_undo_impl(const Widelands::World& world,
1010+ Widelands::NodeAndTriangle<Widelands::Coords> center,
1011+ EditorInteractive& parent,
1012+ EditorActionArgs* args,
1013+ Widelands::Map* map) {
1014+ return m_set_tool.handle_undo_impl(world, center, parent, args, map);
1015 }
1016
1017 EditorActionArgs EditorNoiseHeightTool::format_args_impl(EditorInteractive & parent)
1018
1019=== modified file 'src/editor/tools/editor_noise_height_tool.h'
1020--- src/editor/tools/editor_noise_height_tool.h 2014-09-10 14:08:25 +0000
1021+++ src/editor/tools/editor_noise_height_tool.h 2016-01-04 21:01:25 +0000
1022@@ -34,17 +34,17 @@
1023 m_interval(the_interval)
1024 {}
1025
1026- int32_t handle_click_impl(Widelands::Map& map,
1027- const Widelands::World& world,
1028+ int32_t handle_click_impl(const Widelands::World& world,
1029 Widelands::NodeAndTriangle<> center,
1030 EditorInteractive& parent,
1031- EditorActionArgs& args) override;
1032+ EditorActionArgs* args,
1033+ Widelands::Map* map) override;
1034
1035- int32_t handle_undo_impl(Widelands::Map& map,
1036- const Widelands::World& world,
1037+ int32_t handle_undo_impl(const Widelands::World& world,
1038 Widelands::NodeAndTriangle<> center,
1039 EditorInteractive& parent,
1040- EditorActionArgs& args) override;
1041+ EditorActionArgs* args,
1042+ Widelands::Map* map) override;
1043
1044 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
1045
1046
1047=== modified file 'src/editor/tools/editor_place_bob_tool.cc'
1048--- src/editor/tools/editor_place_bob_tool.cc 2014-09-10 14:08:25 +0000
1049+++ src/editor/tools/editor_place_bob_tool.cc 2016-01-04 21:01:25 +0000
1050@@ -30,31 +30,31 @@
1051 * Choses an object to place randomly from all enabled
1052 * and places this on the current field
1053 */
1054-int32_t EditorPlaceBobTool::handle_click_impl(Widelands::Map& map,
1055- const Widelands::World& world,
1056- Widelands::NodeAndTriangle<> const center,
1057- EditorInteractive& parent,
1058- EditorActionArgs& args) {
1059+int32_t EditorPlaceBobTool::handle_click_impl(const Widelands::World& world,
1060+ Widelands::NodeAndTriangle<> const center,
1061+ EditorInteractive& parent,
1062+ EditorActionArgs* args,
1063+ Widelands::Map* map) {
1064
1065- if (get_nr_enabled() && args.obob_type.empty()) {
1066+ if (get_nr_enabled() && args->obob_type.empty()) {
1067 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1068- (map,
1069+ (*map,
1070 Widelands::Area<Widelands::FCoords>
1071- (map.get_fcoords(center.node), args.sel_radius));
1072+ (map->get_fcoords(center.node), args->sel_radius));
1073 do {
1074 Widelands::Bob * const mbob = mr.location().field->get_first_bob();
1075- args.obob_type.push_back((mbob ? &mbob->descr() : nullptr));
1076- args.nbob_type.push_back(world.get_bob_descr(get_random_enabled()));
1077- } while (mr.advance(map));
1078+ args->obob_type.push_back((mbob ? &mbob->descr() : nullptr));
1079+ args->nbob_type.push_back(world.get_bob_descr(get_random_enabled()));
1080+ } while (mr.advance(*map));
1081 }
1082
1083- if (!args.nbob_type.empty()) {
1084+ if (!args->nbob_type.empty()) {
1085 Widelands::EditorGameBase & egbase = parent.egbase();
1086 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1087- (map,
1088+ (*map,
1089 Widelands::Area<Widelands::FCoords>
1090- (map.get_fcoords(center.node), args.sel_radius));
1091- std::list< const Widelands::BobDescr * >::iterator i = args.nbob_type.begin();
1092+ (map->get_fcoords(center.node), args->sel_radius));
1093+ std::list< const Widelands::BobDescr * >::iterator i = args->nbob_type.begin();
1094 do {
1095 const Widelands::BobDescr & descr = *(*i);
1096 if (mr.location().field->nodecaps() & descr.movecaps()) {
1097@@ -63,25 +63,25 @@
1098 descr.create(egbase, nullptr, mr.location());
1099 }
1100 ++i;
1101- } while (mr.advance(map));
1102+ } while (mr.advance(*map));
1103 return mr.radius() + 2;
1104 } else
1105 return 0;
1106 }
1107
1108 int32_t
1109-EditorPlaceBobTool::handle_undo_impl(Widelands::Map& map,
1110- const Widelands::World&,
1111- Widelands::NodeAndTriangle<Widelands::Coords> center,
1112- EditorInteractive& parent,
1113- EditorActionArgs& args) {
1114- if (!args.nbob_type.empty()) {
1115+EditorPlaceBobTool::handle_undo_impl(const Widelands::World&,
1116+ Widelands::NodeAndTriangle<Widelands::Coords> center,
1117+ EditorInteractive& parent,
1118+ EditorActionArgs* args,
1119+ Widelands::Map* map) {
1120+ if (!args->nbob_type.empty()) {
1121 Widelands::EditorGameBase & egbase = parent.egbase();
1122 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1123- (map,
1124+ (*map,
1125 Widelands::Area<Widelands::FCoords>
1126- (map.get_fcoords(center.node), args.sel_radius));
1127- std::list<const Widelands::BobDescr *>::iterator i = args.obob_type.begin();
1128+ (map->get_fcoords(center.node), args->sel_radius));
1129+ std::list<const Widelands::BobDescr *>::iterator i = args->obob_type.begin();
1130 do {
1131 if (*i) {
1132 const Widelands::BobDescr & descr = *(*i);
1133@@ -94,7 +94,7 @@
1134 bob->remove(egbase);
1135 }
1136 ++i;
1137- } while (mr.advance(map));
1138+ } while (mr.advance(*map));
1139 return mr.radius() + 2;
1140 } else
1141 return 0;
1142
1143=== modified file 'src/editor/tools/editor_place_bob_tool.h'
1144--- src/editor/tools/editor_place_bob_tool.h 2014-09-10 14:08:25 +0000
1145+++ src/editor/tools/editor_place_bob_tool.h 2016-01-04 21:01:25 +0000
1146@@ -29,17 +29,17 @@
1147 : EditorTool(tool, tool)
1148 {}
1149
1150- int32_t handle_click_impl(Widelands::Map& map,
1151- const Widelands::World& world,
1152+ int32_t handle_click_impl(const Widelands::World& world,
1153 Widelands::NodeAndTriangle<> center,
1154 EditorInteractive& parent,
1155- EditorActionArgs& args) override;
1156+ EditorActionArgs* args,
1157+ Widelands::Map* map) override;
1158
1159- int32_t handle_undo_impl(Widelands::Map& map,
1160- const Widelands::World& world,
1161+ int32_t handle_undo_impl(const Widelands::World& world,
1162 Widelands::NodeAndTriangle<> center,
1163 EditorInteractive& parent,
1164- EditorActionArgs& args) override;
1165+ EditorActionArgs* args,
1166+ Widelands::Map* map) override;
1167
1168 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
1169
1170
1171=== modified file 'src/editor/tools/editor_place_immovable_tool.cc'
1172--- src/editor/tools/editor_place_immovable_tool.cc 2015-01-25 12:02:06 +0000
1173+++ src/editor/tools/editor_place_immovable_tool.cc 2016-01-04 21:01:25 +0000
1174@@ -32,35 +32,35 @@
1175 * Choses an object to place randomly from all enabled
1176 * and places this on the current field
1177 */
1178-int32_t EditorPlaceImmovableTool::handle_click_impl(Widelands::Map& map,
1179- const Widelands::World&,
1180- Widelands::NodeAndTriangle<> const center,
1181- EditorInteractive& parent,
1182- EditorActionArgs& args) {
1183- const int32_t radius = args.sel_radius;
1184+int32_t EditorPlaceImmovableTool::handle_click_impl(const Widelands::World&,
1185+ Widelands::NodeAndTriangle<> const center,
1186+ EditorInteractive& parent,
1187+ EditorActionArgs* args,
1188+ Widelands::Map* map) {
1189+ const int32_t radius = args->sel_radius;
1190 if (!get_nr_enabled())
1191 return radius;
1192 Widelands::EditorGameBase & egbase = parent.egbase();
1193- if (args.oimmov_types.empty())
1194+ if (args->oimmov_types.empty())
1195 {
1196 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1197- (map,
1198+ (*map,
1199 Widelands::Area<Widelands::FCoords>
1200- (map.get_fcoords(center.node), radius));
1201+ (map->get_fcoords(center.node), radius));
1202 do {
1203 const Widelands::BaseImmovable * im = mr.location().field->get_immovable();
1204- args.oimmov_types.push_back((im ? im->descr().name() : ""));
1205- args.nimmov_types.push_back(get_random_enabled());
1206- } while (mr.advance(map));
1207+ args->oimmov_types.push_back((im ? im->descr().name() : ""));
1208+ args->nimmov_types.push_back(get_random_enabled());
1209+ } while (mr.advance(*map));
1210 }
1211
1212- if (!args.nimmov_types.empty())
1213+ if (!args->nimmov_types.empty())
1214 {
1215 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1216- (map,
1217+ (*map,
1218 Widelands::Area<Widelands::FCoords>
1219- (map.get_fcoords(center.node), radius));
1220- std::list<int32_t>::iterator i = args.nimmov_types.begin();
1221+ (map->get_fcoords(center.node), radius));
1222+ std::list<int32_t>::iterator i = args->nimmov_types.begin();
1223 do {
1224 if
1225 (!mr.location().field->get_immovable()
1226@@ -68,27 +68,26 @@
1227 (mr.location().field->nodecaps() & Widelands::MOVECAPS_WALK))
1228 egbase.create_immovable(mr.location(), *i);
1229 ++i;
1230- } while (mr.advance(map));
1231+ } while (mr.advance(*map));
1232 }
1233 return radius + 2;
1234 }
1235
1236-int32_t EditorPlaceImmovableTool::handle_undo_impl(
1237- Widelands::Map& map,
1238- const Widelands::World&,
1239- Widelands::NodeAndTriangle<Widelands::Coords> center,
1240- EditorInteractive& parent,
1241- EditorActionArgs& args) {
1242- const int32_t radius = args.sel_radius;
1243- if (args.oimmov_types.empty())
1244+int32_t EditorPlaceImmovableTool::handle_undo_impl(const Widelands::World&,
1245+ Widelands::NodeAndTriangle<Widelands::Coords> center,
1246+ EditorInteractive& parent,
1247+ EditorActionArgs* args,
1248+ Widelands::Map* map) {
1249+ const int32_t radius = args->sel_radius;
1250+ if (args->oimmov_types.empty())
1251 return radius;
1252
1253 Widelands::EditorGameBase & egbase = parent.egbase();
1254 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1255- (map,
1256+ (*map,
1257 Widelands::Area<Widelands::FCoords>
1258- (map.get_fcoords(center.node), radius));
1259- std::list<std::string>::iterator i = args.oimmov_types.begin();
1260+ (map->get_fcoords(center.node), radius));
1261+ std::list<std::string>::iterator i = args->oimmov_types.begin();
1262 do {
1263 if
1264 (upcast(Widelands::Immovable, immovable,
1265@@ -100,7 +99,7 @@
1266 egbase.create_immovable(mr.location(), *i);
1267
1268 ++i;
1269- } while (mr.advance(map));
1270+ } while (mr.advance(*map));
1271 return radius + 2;
1272 }
1273
1274
1275=== modified file 'src/editor/tools/editor_place_immovable_tool.h'
1276--- src/editor/tools/editor_place_immovable_tool.h 2014-09-10 14:08:25 +0000
1277+++ src/editor/tools/editor_place_immovable_tool.h 2016-01-04 21:01:25 +0000
1278@@ -31,17 +31,17 @@
1279 : EditorTool(tool, tool)
1280 {}
1281
1282- int32_t handle_click_impl(Widelands::Map& map,
1283- const Widelands::World& world,
1284+ int32_t handle_click_impl(const Widelands::World& world,
1285 Widelands::NodeAndTriangle<> center,
1286 EditorInteractive& parent,
1287- EditorActionArgs& args) override;
1288+ EditorActionArgs* args,
1289+ Widelands::Map* map) override;
1290
1291- int32_t handle_undo_impl(Widelands::Map& map,
1292- const Widelands::World& world,
1293+ int32_t handle_undo_impl(const Widelands::World& world,
1294 Widelands::NodeAndTriangle<> center,
1295 EditorInteractive& parent,
1296- EditorActionArgs& args) override;
1297+ EditorActionArgs* args,
1298+ Widelands::Map* map) override;
1299
1300 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
1301
1302
1303=== modified file 'src/editor/tools/editor_set_height_tool.cc'
1304--- src/editor/tools/editor_set_height_tool.cc 2014-09-10 14:08:25 +0000
1305+++ src/editor/tools/editor_set_height_tool.cc 2016-01-04 21:01:25 +0000
1306@@ -26,48 +26,48 @@
1307 #include "logic/map.h"
1308 #include "logic/mapregion.h"
1309
1310-int32_t EditorSetHeightTool::handle_click_impl(Widelands::Map& map,
1311- const Widelands::World& world,
1312- Widelands::NodeAndTriangle<> const center,
1313- EditorInteractive& /* parent */,
1314- EditorActionArgs& args) {
1315- if (args.origHights.empty())
1316+int32_t EditorSetHeightTool::handle_click_impl(const Widelands::World& world,
1317+ Widelands::NodeAndTriangle<> const center,
1318+ EditorInteractive& /* parent */,
1319+ EditorActionArgs* args,
1320+ Widelands::Map* map) {
1321+ if (args->origHights.empty())
1322 {
1323 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1324- (map,
1325+ (*map,
1326 Widelands::Area<Widelands::FCoords>
1327- (map.get_fcoords(center.node), args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
1328- do args.origHights.push_back(mr.location().field->get_height());
1329- while (mr.advance(map));
1330+ (map->get_fcoords(center.node), args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
1331+ do args->origHights.push_back(mr.location().field->get_height());
1332+ while (mr.advance(*map));
1333 }
1334- return map.set_height(
1335+ return map->set_height(
1336 world,
1337- Widelands::Area<Widelands::FCoords>(map.get_fcoords(center.node), args.sel_radius),
1338- args.m_interval);
1339+ Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius),
1340+ args->m_interval);
1341 }
1342
1343 int32_t
1344-EditorSetHeightTool::handle_undo_impl(Widelands::Map& map,
1345- const Widelands::World& world,
1346- Widelands::NodeAndTriangle<Widelands::Coords> center,
1347- EditorInteractive& /* parent */,
1348- EditorActionArgs& args) {
1349+EditorSetHeightTool::handle_undo_impl(const Widelands::World& world,
1350+ Widelands::NodeAndTriangle<Widelands::Coords> center,
1351+ EditorInteractive& /* parent */,
1352+ EditorActionArgs* args,
1353+ Widelands::Map* map) {
1354 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1355- (map,
1356+ (*map,
1357 Widelands::Area<Widelands::FCoords>
1358- (map.get_fcoords(center.node),
1359- args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
1360+ (map->get_fcoords(center.node),
1361+ args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 1));
1362
1363- std::list<Widelands::Field::Height>::iterator i = args.origHights.begin();
1364+ std::list<Widelands::Field::Height>::iterator i = args->origHights.begin();
1365
1366 do {
1367 mr.location().field->set_height(*i); ++i;
1368- } while (mr.advance(map));
1369+ } while (mr.advance(*map));
1370
1371- map.recalc_for_field_area
1372+ map->recalc_for_field_area
1373 (world, Widelands::Area<Widelands::FCoords>
1374- (map.get_fcoords(center.node),
1375- args.sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 2));
1376+ (map->get_fcoords(center.node),
1377+ args->sel_radius + MAX_FIELD_HEIGHT / MAX_FIELD_HEIGHT_DIFF + 2));
1378
1379 return mr.radius() + 1;
1380 }
1381
1382=== modified file 'src/editor/tools/editor_set_height_tool.h'
1383--- src/editor/tools/editor_set_height_tool.h 2014-09-10 14:08:25 +0000
1384+++ src/editor/tools/editor_set_height_tool.h 2016-01-04 21:01:25 +0000
1385@@ -30,17 +30,17 @@
1386 : EditorTool(*this, *this), m_interval(10, 10)
1387 {}
1388
1389- int32_t handle_click_impl(Widelands::Map& map,
1390- const Widelands::World& world,
1391+ int32_t handle_click_impl(const Widelands::World& world,
1392 Widelands::NodeAndTriangle<> center,
1393 EditorInteractive& parent,
1394- EditorActionArgs& args) override;
1395+ EditorActionArgs* args,
1396+ Widelands::Map* map) override;
1397
1398- int32_t handle_undo_impl(Widelands::Map& map,
1399- const Widelands::World& world,
1400+ int32_t handle_undo_impl(const Widelands::World& world,
1401 Widelands::NodeAndTriangle<> center,
1402 EditorInteractive& parent,
1403- EditorActionArgs& args) override;
1404+ EditorActionArgs* args,
1405+ Widelands::Map* map) override;
1406
1407 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
1408
1409
1410=== modified file 'src/editor/tools/editor_set_origin_tool.cc'
1411--- src/editor/tools/editor_set_origin_tool.cc 2014-09-10 14:08:25 +0000
1412+++ src/editor/tools/editor_set_origin_tool.cc 2016-01-04 21:01:25 +0000
1413@@ -24,12 +24,12 @@
1414 #include "wui/mapviewpixelconstants.h"
1415 #include "wui/overlay_manager.h"
1416
1417-int32_t EditorSetOriginTool::handle_click_impl(Widelands::Map& map,
1418- const Widelands::World&,
1419- Widelands::NodeAndTriangle<> const center,
1420- EditorInteractive& eia,
1421- EditorActionArgs& /* args */) {
1422- map.set_origin(center.node);
1423+int32_t EditorSetOriginTool::handle_click_impl(const Widelands::World&,
1424+ Widelands::NodeAndTriangle<> const center,
1425+ EditorInteractive& eia,
1426+ EditorActionArgs* /* args */,
1427+ Widelands::Map* map) {
1428+ map->set_origin(center.node);
1429 eia.register_overlays();
1430 eia.set_rel_viewpoint
1431 (Point
1432@@ -40,15 +40,15 @@
1433 }
1434
1435 int32_t
1436-EditorSetOriginTool::handle_undo_impl(Widelands::Map& map,
1437- const Widelands::World&,
1438- Widelands::NodeAndTriangle<Widelands::Coords> center,
1439- EditorInteractive& parent,
1440- EditorActionArgs& /* args */) {
1441+EditorSetOriginTool::handle_undo_impl(const Widelands::World&,
1442+ Widelands::NodeAndTriangle<Widelands::Coords> center,
1443+ EditorInteractive& parent,
1444+ EditorActionArgs* /* args */,
1445+ Widelands::Map* map) {
1446 Widelands::Coords nc
1447- (map.get_width() - center.node.x,
1448- map.get_height() - center.node.y);
1449- map.set_origin(nc);
1450+ (map->get_width() - center.node.x,
1451+ map->get_height() - center.node.y);
1452+ map->set_origin(nc);
1453 parent.register_overlays();
1454 parent.set_rel_viewpoint
1455 (Point
1456
1457=== modified file 'src/editor/tools/editor_set_origin_tool.h'
1458--- src/editor/tools/editor_set_origin_tool.h 2014-09-10 14:08:25 +0000
1459+++ src/editor/tools/editor_set_origin_tool.h 2016-01-04 21:01:25 +0000
1460@@ -27,17 +27,17 @@
1461 struct EditorSetOriginTool : public EditorTool {
1462 EditorSetOriginTool() : EditorTool(*this, *this) {}
1463
1464- int32_t handle_click_impl(Widelands::Map& map,
1465- const Widelands::World& world,
1466+ int32_t handle_click_impl(const Widelands::World& world,
1467 Widelands::NodeAndTriangle<> center,
1468 EditorInteractive& eia,
1469- EditorActionArgs& args) override;
1470+ EditorActionArgs* args,
1471+ Widelands::Map* map) override;
1472
1473- int32_t handle_undo_impl(Widelands::Map& map,
1474- const Widelands::World& world,
1475+ int32_t handle_undo_impl(const Widelands::World& world,
1476 Widelands::NodeAndTriangle<> center,
1477 EditorInteractive& parent,
1478- EditorActionArgs& args) override;
1479+ EditorActionArgs* args,
1480+ Widelands::Map* map) override;
1481
1482 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
1483
1484
1485=== modified file 'src/editor/tools/editor_set_port_space_tool.cc'
1486--- src/editor/tools/editor_set_port_space_tool.cc 2014-09-20 09:37:47 +0000
1487+++ src/editor/tools/editor_set_port_space_tool.cc 2016-01-04 21:01:25 +0000
1488@@ -31,7 +31,7 @@
1489
1490 /// static callback function for overlay calculation
1491 int32_t editor_Tool_set_port_space_callback
1492- (const Widelands::TCoords<Widelands::FCoords>& c, Map& map)
1493+ (const Widelands::TCoords<Widelands::FCoords>& c, const Map& map)
1494 {
1495 NodeCaps const caps = c.field->nodecaps();
1496 FCoords f = map.get_fcoords(*c.field);
1497@@ -55,72 +55,72 @@
1498 EditorTool(*this, *this)
1499 {}
1500
1501-int32_t EditorSetPortSpaceTool::handle_click_impl(Map& map,
1502- const Widelands::World& world,
1503- Widelands::NodeAndTriangle<> const center,
1504- EditorInteractive&,
1505- EditorActionArgs& args) {
1506- assert(0 <= center.node.x);
1507- assert(center.node.x < map.get_width());
1508- assert(0 <= center.node.y);
1509- assert(center.node.y < map.get_height());
1510-
1511- uint32_t nr = 0;
1512-
1513- Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1514- (map, Widelands::Area<Widelands::FCoords>(map.get_fcoords(center.node), args.sel_radius));
1515- do {
1516- // check if field is valid
1517- if (editor_Tool_set_port_space_callback(mr.location(), map)) {
1518- map.set_port_space(mr.location(), true);
1519- Area<FCoords> a(mr.location(), 0);
1520- map.recalc_for_field_area(world, a);
1521- ++nr;
1522- }
1523- } while (mr.advance(map));
1524-
1525- return nr;
1526-}
1527-
1528-int32_t EditorSetPortSpaceTool::handle_undo_impl(Map& map,
1529- const Widelands::World& world,
1530- NodeAndTriangle<Coords> center,
1531- EditorInteractive& parent,
1532- EditorActionArgs& args) {
1533- return parent.tools.unset_port_space.handle_click_impl(map, world, center, parent, args);
1534-}
1535-
1536-int32_t EditorUnsetPortSpaceTool::handle_click_impl(Map& map,
1537- const Widelands::World& world,
1538- NodeAndTriangle<> const center,
1539- EditorInteractive&,
1540- EditorActionArgs& args) {
1541- assert(0 <= center.node.x);
1542- assert(center.node.x < map.get_width());
1543- assert(0 <= center.node.y);
1544- assert(center.node.y < map.get_height());
1545-
1546- uint32_t nr = 0;
1547-
1548- Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1549- (map, Widelands::Area<Widelands::FCoords>(map.get_fcoords(center.node), args.sel_radius));
1550- do {
1551- // check if field is valid
1552- if (editor_Tool_set_port_space_callback(mr.location(), map)) {
1553- map.set_port_space(mr.location(), false);
1554- Area<FCoords> a(mr.location(), 0);
1555- map.recalc_for_field_area(world, a);
1556- ++nr;
1557- }
1558- } while (mr.advance(map));
1559-
1560- return nr;
1561-}
1562-
1563-int32_t EditorUnsetPortSpaceTool::handle_undo_impl(Map& map,
1564- const Widelands::World& world,
1565- NodeAndTriangle<Coords> center,
1566- EditorInteractive& parent,
1567- EditorActionArgs& args) {
1568- return parent.tools.set_port_space.handle_click_impl(map, world, center, parent, args);
1569+int32_t EditorSetPortSpaceTool::handle_click_impl(const Widelands::World& world,
1570+ Widelands::NodeAndTriangle<> const center,
1571+ EditorInteractive&,
1572+ EditorActionArgs* args,
1573+ Map* map) {
1574+ assert(0 <= center.node.x);
1575+ assert(center.node.x < map->get_width());
1576+ assert(0 <= center.node.y);
1577+ assert(center.node.y < map->get_height());
1578+
1579+ uint32_t nr = 0;
1580+
1581+ Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1582+ (*map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius));
1583+ do {
1584+ // check if field is valid
1585+ if (editor_Tool_set_port_space_callback(mr.location(), *map)) {
1586+ map->set_port_space(mr.location(), true);
1587+ Area<FCoords> a(mr.location(), 0);
1588+ map->recalc_for_field_area(world, a);
1589+ ++nr;
1590+ }
1591+ } while (mr.advance(*map));
1592+
1593+ return nr;
1594+}
1595+
1596+int32_t EditorSetPortSpaceTool::handle_undo_impl(const Widelands::World& world,
1597+ NodeAndTriangle<Coords> center,
1598+ EditorInteractive& parent,
1599+ EditorActionArgs* args,
1600+ Map* map) {
1601+ return parent.tools.unset_port_space.handle_click_impl(world, center, parent, args, map);
1602+}
1603+
1604+int32_t EditorUnsetPortSpaceTool::handle_click_impl(const Widelands::World& world,
1605+ NodeAndTriangle<> const center,
1606+ EditorInteractive&,
1607+ EditorActionArgs* args,
1608+ Map* map) {
1609+ assert(0 <= center.node.x);
1610+ assert(center.node.x < map->get_width());
1611+ assert(0 <= center.node.y);
1612+ assert(center.node.y < map->get_height());
1613+
1614+ uint32_t nr = 0;
1615+
1616+ Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1617+ (*map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius));
1618+ do {
1619+ // check if field is valid
1620+ if (editor_Tool_set_port_space_callback(mr.location(), *map)) {
1621+ map->set_port_space(mr.location(), false);
1622+ Area<FCoords> a(mr.location(), 0);
1623+ map->recalc_for_field_area(world, a);
1624+ ++nr;
1625+ }
1626+ } while (mr.advance(*map));
1627+
1628+ return nr;
1629+}
1630+
1631+int32_t EditorUnsetPortSpaceTool::handle_undo_impl(const Widelands::World& world,
1632+ NodeAndTriangle<Coords> center,
1633+ EditorInteractive& parent,
1634+ EditorActionArgs* args,
1635+ Map* map) {
1636+ return parent.tools.set_port_space.handle_click_impl(world, center, parent, args, map);
1637 }
1638
1639=== modified file 'src/editor/tools/editor_set_port_space_tool.h'
1640--- src/editor/tools/editor_set_port_space_tool.h 2014-09-20 09:37:47 +0000
1641+++ src/editor/tools/editor_set_port_space_tool.h 2016-01-04 21:01:25 +0000
1642@@ -31,17 +31,17 @@
1643 public:
1644 EditorUnsetPortSpaceTool();
1645
1646- int32_t handle_click_impl(Widelands::Map& map,
1647- const Widelands::World& world,
1648+ int32_t handle_click_impl(const Widelands::World& world,
1649 Widelands::NodeAndTriangle<> center,
1650 EditorInteractive& parent,
1651- EditorActionArgs& args) override;
1652+ EditorActionArgs* args,
1653+ Widelands::Map* map) override;
1654
1655- int32_t handle_undo_impl(Widelands::Map& map,
1656- const Widelands::World& world,
1657+ int32_t handle_undo_impl(const Widelands::World& world,
1658 Widelands::NodeAndTriangle<> center,
1659 EditorInteractive& parent,
1660- EditorActionArgs& args) override;
1661+ EditorActionArgs* args,
1662+ Widelands::Map* map) override;
1663
1664 char const * get_sel_impl() const override {return FSEL_EUPS_FILENAME;}
1665 };
1666@@ -52,22 +52,22 @@
1667 public:
1668 EditorSetPortSpaceTool(EditorUnsetPortSpaceTool &);
1669
1670- int32_t handle_click_impl(Widelands::Map& map,
1671- const Widelands::World& world,
1672+ int32_t handle_click_impl(const Widelands::World& world,
1673 Widelands::NodeAndTriangle<> center,
1674 EditorInteractive& parent,
1675- EditorActionArgs& args) override;
1676+ EditorActionArgs* args,
1677+ Widelands::Map* map) override;
1678
1679- int32_t handle_undo_impl(Widelands::Map& map,
1680- const Widelands::World& world,
1681+ int32_t handle_undo_impl(const Widelands::World& world,
1682 Widelands::NodeAndTriangle<> center,
1683 EditorInteractive& parent,
1684- EditorActionArgs& args) override;
1685+ EditorActionArgs* args,
1686+ Widelands::Map* map) override;
1687
1688 char const * get_sel_impl() const override {return FSEL_ESPS_FILENAME;}
1689 };
1690
1691 int32_t editor_Tool_set_port_space_callback
1692- (const Widelands::TCoords<Widelands::FCoords>& c, Widelands::Map& map);
1693+ (const Widelands::TCoords<Widelands::FCoords>& c, const Widelands::Map& map);
1694
1695 #endif // end of include guard: WL_EDITOR_TOOLS_EDITOR_SET_PORT_SPACE_TOOL_H
1696
1697=== modified file 'src/editor/tools/editor_set_resources_tool.cc'
1698--- src/editor/tools/editor_set_resources_tool.cc 2014-12-01 21:47:22 +0000
1699+++ src/editor/tools/editor_set_resources_tool.cc 2016-01-04 21:01:25 +0000
1700@@ -29,98 +29,66 @@
1701 #include "logic/world/world.h"
1702 #include "wui/overlay_manager.h"
1703
1704-/**
1705- * Sets the resources of the current to a fixed value
1706-*/
1707-int32_t EditorSetResourcesTool::handle_click_impl(Widelands::Map& map,
1708- const Widelands::World& world,
1709+
1710+int32_t EditorSetResourcesTool::handle_click_impl(const Widelands::World& world,
1711 Widelands::NodeAndTriangle<> const center,
1712 EditorInteractive& /* parent */,
1713- EditorActionArgs& args) {
1714- OverlayManager & overlay_manager = map.overlay_manager();
1715+ EditorActionArgs* args,
1716+ Widelands::Map* map)
1717+{
1718 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1719- (map,
1720+ (*map,
1721 Widelands::Area<Widelands::FCoords>
1722- (map.get_fcoords(center.node), args.sel_radius));
1723+ (map->get_fcoords(center.node), args->sel_radius));
1724 do {
1725- int32_t res = mr.location().field->get_resources();
1726- int32_t amount = args.set_to;
1727- int32_t max_amount = world.get_resource(args.cur_res)->max_amount();
1728-
1729+ int32_t amount = args->set_to;
1730+ int32_t max_amount = args->cur_res != Widelands::kNoResource ?
1731+ world.get_resource(args->cur_res)->max_amount() : 0;
1732 if (amount < 0)
1733 amount = 0;
1734- if (amount > max_amount)
1735+ else if (amount > max_amount)
1736 amount = max_amount;
1737
1738- args.orgResT.push_back(res);
1739- args.orgRes.push_back(mr.location().field->get_resources_amount());
1740-
1741- if (editor_change_resource_tool_callback(mr.location(), map, world, args.cur_res)) {
1742- // Ok, we're doing something. First remove the current overlays.
1743- const Image* pic = g_gr->images().get
1744- (world.get_resource(res)->get_editor_pic (mr.location().field->get_resources_amount()));
1745- overlay_manager.remove_overlay(mr.location(), pic);
1746-
1747- if (!amount) {
1748- mr.location().field->set_resources(0, 0);
1749- mr.location().field->set_initial_res_amount(0);
1750- } else {
1751- mr.location().field->set_resources(args.cur_res, amount);
1752- mr.location().field->set_initial_res_amount(amount);
1753- // set new overlay
1754- pic =
1755- g_gr->images().get(world.get_resource(args.cur_res)->get_editor_pic(amount));
1756- overlay_manager.register_overlay(mr.location(), pic, 4);
1757- map.recalc_for_field_area(world, Widelands::Area<Widelands::FCoords>(mr.location(), 0));
1758- }
1759+ if (map->is_resource_valid(world, mr.location(), args->cur_res)) {
1760+ args->orgResT.push_back(mr.location().field->get_resources());
1761+ args->orgRes.push_back(mr.location().field->get_resources_amount());
1762+ set_res_and_overlay(world, amount, args->cur_res, &mr, args, map);
1763 }
1764- } while (mr.advance(map));
1765+
1766+
1767+ } while (mr.advance(*map));
1768 return mr.radius();
1769 }
1770
1771 int32_t
1772-EditorSetResourcesTool::handle_undo_impl(Widelands::Map& map,
1773- const Widelands::World& world,
1774+EditorSetResourcesTool::handle_undo_impl(const Widelands::World& world,
1775 Widelands::NodeAndTriangle<Widelands::Coords> center,
1776 EditorInteractive& /* parent */,
1777- EditorActionArgs& args) {
1778- OverlayManager & overlay_manager = map.overlay_manager();
1779+ EditorActionArgs* args,
1780+ Widelands::Map* map) {
1781+ OverlayManager & overlay_manager = map->overlay_manager();
1782 Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > mr
1783- (map,
1784+ (*map,
1785 Widelands::Area<Widelands::FCoords>
1786- (map.get_fcoords(center.node), args.sel_radius));
1787- std::list<uint8_t>::iterator ir = args.orgRes.begin(), it = args.orgResT.begin();
1788+ (map->get_fcoords(center.node), args->sel_radius));
1789+ std::list<uint8_t>::iterator ir = args->orgRes.begin(), it = args->orgResT.begin();
1790 do {
1791 int32_t res = mr.location().field->get_resources();
1792 int32_t amount = *ir;
1793- int32_t max_amount = world.get_resource(args.cur_res)->max_amount();
1794+ int32_t max_amount = world.get_resource(args->cur_res)->max_amount();
1795
1796 if (amount < 0)
1797 amount = 0;
1798 if (amount > max_amount)
1799 amount = max_amount;
1800
1801- const Image* pic =
1802- g_gr->images().get
1803- (world.get_resource(res)->get_editor_pic(mr.location().field->get_resources_amount()));
1804- overlay_manager.remove_overlay(mr.location(), pic);
1805+ set_res_and_overlay(world, amount, *ir, &mr, args, map);
1806
1807- if (!amount) {
1808- mr.location().field->set_resources(0, 0);
1809- mr.location().field->set_initial_res_amount(0);
1810- } else {
1811- mr.location().field->set_resources(*it, amount);
1812- mr.location().field->set_initial_res_amount(amount);
1813- // set new overlay
1814- pic = g_gr->images().get(world.get_resource(*it)->get_editor_pic(amount));
1815- overlay_manager.register_overlay(mr.location(), pic, 4);
1816- map.recalc_for_field_area(world, Widelands::Area<Widelands::FCoords>(mr.location(), 0));
1817- }
1818 ++ir;
1819 ++it;
1820- } while (mr.advance(map));
1821- args.orgRes.clear();
1822- args.orgResT.clear();
1823+ } while (mr.advance(*map));
1824+ args->orgRes.clear();
1825+ args->orgResT.clear();
1826 return mr.radius();
1827 }
1828
1829@@ -131,3 +99,34 @@
1830 a.set_to = m_set_to;
1831 return a;
1832 }
1833+
1834+void EditorSetResourcesTool::set_res_and_overlay(const Widelands::World& world,
1835+ int32_t amount, uint8_t new_res,
1836+ Widelands::MapRegion<Widelands::Area<Widelands::FCoords> >* mr,
1837+ EditorActionArgs* args,
1838+ Widelands::Map* map) {
1839+ int32_t old_res = mr->location().field->get_resources();
1840+
1841+ // Ok, we're doing something. First remove the current overlays.
1842+ if (old_res != Widelands::kNoResource) {
1843+ std::string str = world.get_resource(old_res)->get_editor_pic(
1844+ mr->location().field->get_resources_amount());
1845+ const Image* pic = g_gr->images().get(str);
1846+ map->overlay_manager().remove_overlay(mr->location(), pic);
1847+ }
1848+
1849+ if (!amount) {
1850+ mr->location().field->set_resources(Widelands::kNoResource, 0);
1851+ mr->location().field->set_initial_res_amount(0);
1852+ } else {
1853+ mr->location().field->set_resources(new_res, amount);
1854+ mr->location().field->set_initial_res_amount(amount);
1855+ // set new overlay
1856+ std::string str = world.get_resource(new_res)->get_editor_pic(amount);
1857+ const Image* pic = g_gr->images().get(str);
1858+ map->overlay_manager().register_overlay(mr->location(), pic, 4);
1859+ map->recalc_for_field_area(
1860+ world, Widelands::Area<Widelands::FCoords>(mr->location(), 0));
1861+ }
1862+}
1863+
1864
1865=== modified file 'src/editor/tools/editor_set_resources_tool.h'
1866--- src/editor/tools/editor_set_resources_tool.h 2015-11-11 09:56:22 +0000
1867+++ src/editor/tools/editor_set_resources_tool.h 2016-01-04 21:01:25 +0000
1868@@ -20,6 +20,8 @@
1869 #ifndef WL_EDITOR_TOOLS_EDITOR_SET_RESOURCES_TOOL_H
1870 #define WL_EDITOR_TOOLS_EDITOR_SET_RESOURCES_TOOL_H
1871
1872+#include "logic/mapregion.h"
1873+#include "logic/widelands.h"
1874 #include "editor/tools/editor_tool.h"
1875
1876 /// Decreases the resources of a node by a value.
1877@@ -28,20 +30,30 @@
1878 : EditorTool(*this, *this), m_cur_res(0), m_set_to(0)
1879 {}
1880
1881- int32_t handle_click_impl(Widelands::Map& map,
1882- const Widelands::World& world,
1883+ /**
1884+ * Sets the resources of the current to a fixed value
1885+ */
1886+ int32_t handle_click_impl(const Widelands::World& world,
1887 Widelands::NodeAndTriangle<> center,
1888 EditorInteractive& parent,
1889- EditorActionArgs& args) override;
1890+ EditorActionArgs* args,
1891+ Widelands::Map* map) override;
1892
1893- int32_t handle_undo_impl(Widelands::Map& map,
1894- const Widelands::World& world,
1895+ int32_t handle_undo_impl(const Widelands::World& world,
1896 Widelands::NodeAndTriangle<> center,
1897 EditorInteractive& parent,
1898- EditorActionArgs& args) override;
1899+ EditorActionArgs* args,
1900+ Widelands::Map* map) override;
1901
1902 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
1903
1904+ /**
1905+ * Sets the resource amount and updates the overlay.
1906+ */
1907+ static void set_res_and_overlay(const Widelands::World& world, int32_t amount, uint8_t resIx,
1908+ Widelands::MapRegion<Widelands::Area<Widelands::FCoords> > *mr,
1909+ EditorActionArgs* args, Widelands::Map* map);
1910+
1911 char const * get_sel_impl() const override {
1912 return "pics/fsel_editor_set_resources.png";
1913 }
1914@@ -57,4 +69,5 @@
1915 uint8_t m_set_to;
1916 };
1917
1918+
1919 #endif // end of include guard: WL_EDITOR_TOOLS_EDITOR_SET_RESOURCES_TOOL_H
1920
1921=== modified file 'src/editor/tools/editor_set_starting_pos_tool.cc'
1922--- src/editor/tools/editor_set_starting_pos_tool.cc 2014-09-20 09:37:47 +0000
1923+++ src/editor/tools/editor_set_starting_pos_tool.cc 2016-01-04 21:01:25 +0000
1924@@ -62,17 +62,17 @@
1925 strcpy(fsel_picsname, FSEL_PIC_FILENAME);
1926 }
1927
1928-int32_t EditorSetStartingPosTool::handle_click_impl(Widelands::Map& map,
1929- const Widelands::World&,
1930- Widelands::NodeAndTriangle<> const center,
1931- EditorInteractive&,
1932- EditorActionArgs&) {
1933+int32_t EditorSetStartingPosTool::handle_click_impl(const Widelands::World&,
1934+ Widelands::NodeAndTriangle<> const center,
1935+ EditorInteractive&,
1936+ EditorActionArgs*,
1937+ Widelands::Map* map) {
1938 assert(0 <= center.node.x);
1939- assert(center.node.x < map.get_width());
1940+ assert(center.node.x < map->get_width());
1941 assert(0 <= center.node.y);
1942- assert(center.node.y < map.get_height());
1943+ assert(center.node.y < map->get_height());
1944 if (m_current_player) {
1945- if (map.get_nrplayers() < m_current_player) {
1946+ if (map->get_nrplayers() < m_current_player) {
1947 // Mmh, my current player is not valid. Maybe the user has loaded a
1948 // new map while this tool was active. We set the new player to a
1949 // valid one. The sel pointer is the only thing that stays wrong, but
1950@@ -80,7 +80,7 @@
1951 m_current_player = 1;
1952 }
1953
1954- Widelands::Coords const old_sp = map.get_starting_pos(m_current_player);
1955+ Widelands::Coords const old_sp = map->get_starting_pos(m_current_player);
1956
1957 char picname[] = "pics/editor_player_00_starting_pos.png";
1958 picname[19] += m_current_player / 10;
1959@@ -88,8 +88,8 @@
1960 const Image* pic = g_gr->images().get(picname);
1961
1962 // check if field is valid
1963- if (editor_tool_set_starting_pos_callback(map.get_fcoords(center.node), map)) {
1964- OverlayManager & overlay_manager = map.overlay_manager();
1965+ if (editor_tool_set_starting_pos_callback(map->get_fcoords(center.node), *map)) {
1966+ OverlayManager & overlay_manager = map->overlay_manager();
1967 // remove old overlay if any
1968 overlay_manager.remove_overlay(old_sp, pic);
1969
1970@@ -98,7 +98,7 @@
1971 (center.node, pic, 8, Point(pic->width() / 2, STARTING_POS_HOTSPOT_Y));
1972
1973 // set new player pos
1974- map.set_starting_pos(m_current_player, center.node);
1975+ map->set_starting_pos(m_current_player, center.node);
1976
1977 }
1978 }
1979
1980=== modified file 'src/editor/tools/editor_set_starting_pos_tool.h'
1981--- src/editor/tools/editor_set_starting_pos_tool.h 2014-09-20 09:37:47 +0000
1982+++ src/editor/tools/editor_set_starting_pos_tool.h 2016-01-04 21:01:25 +0000
1983@@ -34,11 +34,11 @@
1984 struct EditorSetStartingPosTool : public EditorTool {
1985 EditorSetStartingPosTool();
1986
1987- int32_t handle_click_impl(Widelands::Map&,
1988- const Widelands::World& world,
1989+ int32_t handle_click_impl(const Widelands::World& world,
1990 Widelands::NodeAndTriangle<>,
1991 EditorInteractive&,
1992- EditorActionArgs&) override;
1993+ EditorActionArgs*,
1994+ Widelands::Map*) override;
1995 char const * get_sel_impl() const override
1996 {return m_current_sel_pic;}
1997
1998
1999=== modified file 'src/editor/tools/editor_set_terrain_tool.cc'
2000--- src/editor/tools/editor_set_terrain_tool.cc 2015-11-11 09:54:53 +0000
2001+++ src/editor/tools/editor_set_terrain_tool.cc 2016-01-04 21:01:25 +0000
2002@@ -25,74 +25,74 @@
2003
2004 using Widelands::TCoords;
2005
2006-int32_t EditorSetTerrainTool::handle_click_impl(Widelands::Map& map,
2007- const Widelands::World& world,
2008- Widelands::NodeAndTriangle<> const center,
2009- EditorInteractive& /* parent */,
2010- EditorActionArgs& args) {
2011+int32_t EditorSetTerrainTool::handle_click_impl(const Widelands::World& world,
2012+ Widelands::NodeAndTriangle<> const center,
2013+ EditorInteractive& /* parent */,
2014+ EditorActionArgs* args,
2015+ Widelands::Map* map) {
2016 assert
2017 (center.triangle.t == TCoords<>::D || center.triangle.t == TCoords<>::R);
2018- uint16_t const radius = args.sel_radius;
2019+ uint16_t const radius = args->sel_radius;
2020 int32_t max = 0;
2021
2022- if (get_nr_enabled() && args.terrainType.empty()) {
2023+ if (get_nr_enabled() && args->terrainType.empty()) {
2024 Widelands::MapTriangleRegion<TCoords<Widelands::FCoords> > mr
2025- (map, Widelands::Area<TCoords<Widelands::FCoords> >
2026+ (*map, Widelands::Area<TCoords<Widelands::FCoords> >
2027 (TCoords<Widelands::FCoords>
2028- (Widelands::FCoords(map.get_fcoords(center.triangle)),
2029+ (Widelands::FCoords(map->get_fcoords(center.triangle)),
2030 static_cast<TCoords<Widelands::FCoords>::TriangleIndex>(center.triangle.t)),
2031 radius));
2032 do {
2033- args.origTerrainType.push_back
2034+ args->origTerrainType.push_back
2035 ((mr.location().t == TCoords<Widelands::FCoords>::D)
2036 ? mr.location().field->terrain_d() : mr.location().field->terrain_r());
2037- args.terrainType.push_back(get_random_enabled());
2038- } while (mr.advance(map));
2039+ args->terrainType.push_back(get_random_enabled());
2040+ } while (mr.advance(*map));
2041 }
2042
2043- if (!args.terrainType.empty()) {
2044+ if (!args->terrainType.empty()) {
2045 Widelands::MapTriangleRegion<TCoords<Widelands::FCoords> > mr
2046- (map, Widelands::Area<TCoords<Widelands::FCoords> >
2047+ (*map, Widelands::Area<TCoords<Widelands::FCoords> >
2048 (TCoords<Widelands::FCoords>
2049- (Widelands::FCoords(map.get_fcoords(center.triangle)),
2050+ (Widelands::FCoords(map->get_fcoords(center.triangle)),
2051 static_cast<TCoords<Widelands::FCoords>::TriangleIndex>(center.triangle.t)),
2052 radius));
2053- std::list<Widelands::DescriptionIndex>::iterator i = args.terrainType.begin();
2054+ std::list<Widelands::DescriptionIndex>::iterator i = args->terrainType.begin();
2055 do {
2056 max = std::max
2057- (max, map.change_terrain(world, mr.location(), *i));
2058+ (max, map->change_terrain(world, mr.location(), *i));
2059 ++i;
2060- } while (mr.advance(map));
2061+ } while (mr.advance(*map));
2062 }
2063 return radius + max;
2064 }
2065
2066 int32_t
2067-EditorSetTerrainTool::handle_undo_impl(Widelands::Map& map,
2068- const Widelands::World& world,
2069- Widelands::NodeAndTriangle<Widelands::Coords> center,
2070- EditorInteractive& /* parent */,
2071- EditorActionArgs& args) {
2072+EditorSetTerrainTool::handle_undo_impl(const Widelands::World& world,
2073+ Widelands::NodeAndTriangle<Widelands::Coords> center,
2074+ EditorInteractive& /* parent */,
2075+ EditorActionArgs* args,
2076+ Widelands::Map* map) {
2077 assert
2078 (center.triangle.t == TCoords<>::D || center.triangle.t == TCoords<>::R);
2079- uint16_t const radius = args.sel_radius;
2080- if (!args.terrainType.empty()) {
2081+ uint16_t const radius = args->sel_radius;
2082+ if (!args->terrainType.empty()) {
2083 int32_t max = 0;
2084 Widelands::MapTriangleRegion<TCoords<Widelands::FCoords> > mr
2085- (map,
2086+ (*map,
2087 Widelands::Area<TCoords<Widelands::FCoords> >
2088 (TCoords<Widelands::FCoords>
2089- (Widelands::FCoords(map.get_fcoords(center.triangle)),
2090+ (Widelands::FCoords(map->get_fcoords(center.triangle)),
2091 static_cast<TCoords<Widelands::FCoords>::TriangleIndex>
2092 (center.triangle.t)),
2093 radius));
2094
2095- std::list<Widelands::DescriptionIndex>::iterator i = args.origTerrainType.begin();
2096+ std::list<Widelands::DescriptionIndex>::iterator i = args->origTerrainType.begin();
2097 do {
2098 max = std::max
2099- (max, map.change_terrain(world, mr.location(), *i));
2100+ (max, map->change_terrain(world, mr.location(), *i));
2101 ++i;
2102- } while (mr.advance(map));
2103+ } while (mr.advance(*map));
2104 return radius + max;
2105 } else return radius;
2106 }
2107
2108=== modified file 'src/editor/tools/editor_set_terrain_tool.h'
2109--- src/editor/tools/editor_set_terrain_tool.h 2014-09-10 14:08:25 +0000
2110+++ src/editor/tools/editor_set_terrain_tool.h 2016-01-04 21:01:25 +0000
2111@@ -26,17 +26,17 @@
2112 struct EditorSetTerrainTool : public EditorTool, public MultiSelect {
2113 EditorSetTerrainTool() : EditorTool(*this, *this) {}
2114
2115- int32_t handle_click_impl(Widelands::Map& map,
2116- const Widelands::World& world,
2117+ int32_t handle_click_impl(const Widelands::World& world,
2118 Widelands::NodeAndTriangle<> center,
2119 EditorInteractive& parent,
2120- EditorActionArgs& args) override;
2121+ EditorActionArgs* args,
2122+ Widelands::Map* map) override;
2123
2124- int32_t handle_undo_impl(Widelands::Map& map,
2125- const Widelands::World& world,
2126+ int32_t handle_undo_impl(const Widelands::World& world,
2127 Widelands::NodeAndTriangle<> center,
2128 EditorInteractive& parent,
2129- EditorActionArgs& args) override;
2130+ EditorActionArgs* args,
2131+ Widelands::Map* map) override;
2132
2133 EditorActionArgs format_args_impl(EditorInteractive & parent) override;
2134
2135
2136=== modified file 'src/editor/tools/editor_tool.h'
2137--- src/editor/tools/editor_tool.h 2014-09-10 14:08:25 +0000
2138+++ src/editor/tools/editor_tool.h 2016-01-04 21:01:25 +0000
2139@@ -48,22 +48,22 @@
2140 enum ToolIndex {First, Second, Third};
2141 int32_t handle_click
2142 (const ToolIndex i,
2143- Widelands::Map & map, const Widelands::World& world, Widelands::NodeAndTriangle<> const center,
2144- EditorInteractive & parent, EditorActionArgs & args)
2145+ const Widelands::World& world, Widelands::NodeAndTriangle<> const center,
2146+ EditorInteractive& parent, EditorActionArgs* args, Widelands::Map* map)
2147 {
2148 return
2149 (i == First ? *this : i == Second ? m_second : m_third)
2150- .handle_click_impl(map, world, center, parent, args);
2151+ .handle_click_impl(world, center, parent, args, map);
2152 }
2153
2154 int32_t handle_undo
2155 (const ToolIndex i,
2156- Widelands::Map & map, const Widelands::World& world, Widelands::NodeAndTriangle<> const center,
2157- EditorInteractive & parent, EditorActionArgs & args)
2158+ const Widelands::World& world, Widelands::NodeAndTriangle<> const center,
2159+ EditorInteractive& parent, EditorActionArgs* args, Widelands::Map* map)
2160 {
2161 return
2162 (i == First ? *this : i == Second ? m_second : m_third)
2163- .handle_undo_impl(map, world, center, parent, args);
2164+ .handle_undo_impl(world, center, parent, args, map);
2165 }
2166
2167 const char * get_sel(const ToolIndex i) {
2168@@ -83,16 +83,16 @@
2169 virtual EditorActionArgs format_args_impl(EditorInteractive & parent) {
2170 return EditorActionArgs(parent);
2171 }
2172- virtual int32_t handle_click_impl(Widelands::Map&,
2173- const Widelands::World& world,
2174+ virtual int32_t handle_click_impl(const Widelands::World& world,
2175 Widelands::NodeAndTriangle<>,
2176 EditorInteractive&,
2177- EditorActionArgs&) = 0;
2178- virtual int32_t handle_undo_impl(Widelands::Map&,
2179- const Widelands::World&,
2180+ EditorActionArgs*,
2181+ Widelands::Map*) = 0;
2182+ virtual int32_t handle_undo_impl(const Widelands::World&,
2183 Widelands::NodeAndTriangle<>,
2184 EditorInteractive&,
2185- EditorActionArgs&) {
2186+ EditorActionArgs*,
2187+ Widelands::Map*) {
2188 return 0;
2189 } // non unduable tools don't need to implement this.
2190 virtual const char * get_sel_impl() const = 0;
2191
2192=== modified file 'src/editor/ui_menus/editor_tool_change_resources_options_menu.cc'
2193--- src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2015-11-11 09:56:22 +0000
2194+++ src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2016-01-04 21:01:25 +0000
2195@@ -31,6 +31,7 @@
2196 #include "logic/widelands.h"
2197 #include "logic/world/resource_description.h"
2198 #include "logic/world/world.h"
2199+#include "logic/widelands_geometry.h"
2200 #include "ui_basic/button.h"
2201 #include "wui/overlay_manager.h"
2202
2203@@ -212,16 +213,18 @@
2204 * called when a resource has been selected
2205 */
2206 void EditorToolChangeResourcesOptionsMenu::selected() {
2207- const int32_t n = m_radiogroup.get_state();
2208+ const int32_t resIx = m_radiogroup.get_state();
2209
2210- m_increase_tool.set_tool().set_cur_res(n);
2211- m_increase_tool.set_cur_res(n);
2212- m_increase_tool.decrease_tool().set_cur_res(n);
2213+ m_increase_tool.set_tool().set_cur_res(resIx);
2214+ m_increase_tool.set_cur_res(resIx);
2215+ m_increase_tool.decrease_tool().set_cur_res(resIx);
2216
2217 Widelands::EditorGameBase& egbase = eia().egbase();
2218 Widelands::Map & map = egbase.map();
2219 map.overlay_manager().register_overlay_callback_function(
2220- boost::bind(&editor_change_resource_tool_callback, _1, boost::ref(map), boost::ref(egbase.world()), n));
2221+ [&] (const Widelands::TCoords<Widelands::FCoords>& coords)
2222+ {return map.is_resource_valid(egbase.world(), coords, resIx);});
2223+
2224 map.recalc_whole_map(egbase.world());
2225 select_correct_tool();
2226
2227
2228=== modified file 'src/logic/bob.h'
2229--- src/logic/bob.h 2016-01-03 22:05:49 +0000
2230+++ src/logic/bob.h 2016-01-04 21:01:25 +0000
2231@@ -258,7 +258,7 @@
2232 // default tasks
2233 void reset_tasks(Game &);
2234
2235- // TODO correct (?) Send a signal that may switch to some other \ref Task
2236+ // TODO(feature-Hasi50): correct (?) Send a signal that may switch to some other \ref Task
2237 void send_signal(Game &, char const *);
2238 void start_task_idle(Game &, uint32_t anim, int32_t timeout);
2239
2240
2241=== modified file 'src/logic/game_controller.h'
2242--- src/logic/game_controller.h 2016-01-02 12:36:38 +0000
2243+++ src/logic/game_controller.h 2016-01-04 21:01:25 +0000
2244@@ -95,7 +95,7 @@
2245 * by the win_condition scripts.
2246 * \param player : the player idx;
2247 * \param result : the player result
2248- * \param info : The info string (\see \struct PlayerEndStatus)
2249+ * \param info : The info string (\see \struct PlayerEndStatus)
2250 */
2251 virtual void report_result
2252 (uint8_t /* player */,
2253
2254=== modified file 'src/logic/map.cc'
2255--- src/logic/map.cc 2015-12-11 20:12:29 +0000
2256+++ src/logic/map.cc 2016-01-04 21:01:25 +0000
2257@@ -172,26 +172,19 @@
2258 recalc_nodecaps_pass2(world, f);
2259 }
2260
2261- // Now only recaluclate the overlays.
2262+ // Now only recalculate the overlays.
2263 for (int16_t y = 0; y < m_height; ++y)
2264 for (int16_t x = 0; x < m_width; ++x)
2265 overlay_manager().recalc_field_overlays(get_fcoords(Coords(x, y)));
2266 }
2267
2268-/*
2269- * recalculates all default resources.
2270- *
2271- * This just needed for the game, not for
2272- * the editor. Since there, default resources
2273- * are not shown.
2274- */
2275 void Map::recalc_default_resources(const World& world) {
2276 for (int16_t y = 0; y < m_height; ++y)
2277 for (int16_t x = 0; x < m_width; ++x) {
2278 FCoords f, f1;
2279 f = get_fcoords(Coords(x, y));
2280 // only on unset nodes
2281- if (f.field->get_resources() != 0 || f.field->get_resources_amount())
2282+ if (f.field->get_resources() != Widelands::kNoResource || f.field->get_resources_amount())
2283 continue;
2284 std::map<int32_t, int32_t> m;
2285 int32_t amount = 0;
2286@@ -272,7 +265,7 @@
2287 amount /= 6;
2288
2289 if (res == -1 || !amount) {
2290- f.field->set_resources(0, 0);
2291+ f.field->set_resources(Widelands::kNoResource, 0);
2292 f.field->set_initial_res_amount(0);
2293 } else {
2294 f.field->set_resources(res, amount);
2295@@ -350,6 +343,7 @@
2296 for (; field < fields_end; ++field) {
2297 field->set_height(10);
2298 field->set_terrains(default_terrains);
2299+ field->set_resources(Widelands::kNoResource, 0);
2300 }
2301 }
2302 recalc_whole_map(world);
2303@@ -1855,22 +1849,34 @@
2304 return false;
2305 }
2306
2307-/*
2308-===========
2309-changes the given triangle's terrain.
2310-this happens in the editor and might happen in the game
2311-too if some kind of land increasement is implemented (like
2312-drying swamps).
2313-The nodecaps need to be recalculated
2314-
2315-returns the radius of changes (which are always 2)
2316-===========
2317-*/
2318 int32_t Map::change_terrain
2319 (const World& world, TCoords<FCoords> const c, DescriptionIndex const terrain)
2320 {
2321 c.field->set_terrain(c.t, terrain);
2322
2323+ // remove invalid resources if necessary
2324+ // check vertex to which the triangle belongs
2325+ if (!is_resource_valid(world, c, c.field->get_resources())){
2326+ c.field->set_resources(Widelands::kNoResource, 0);
2327+ overlay_manager().remove_overlay(c, NULL);
2328+ }
2329+
2330+ // always check south-east vertex
2331+ Widelands::FCoords f_se(c, c.field);
2332+ get_neighbour(f_se, Widelands::WALK_SE, &f_se);
2333+ if (!is_resource_valid(world, f_se, f_se.field->get_resources())){
2334+ f_se.field->set_resources(Widelands::kNoResource, 0);
2335+ overlay_manager().remove_overlay(f_se, NULL);
2336+ }
2337+
2338+ // check south-west vertex if d-Triangle is changed, check east vertex if r-Triangle is changed
2339+ Widelands::FCoords f_sw_e(c, c.field);
2340+ get_neighbour(f_sw_e, c.t == TCoords<FCoords>::D ? Widelands::WALK_SW : Widelands::WALK_E, &f_sw_e);
2341+ if (!is_resource_valid(world, f_sw_e, f_sw_e.field->get_resources())){
2342+ f_sw_e.field->set_resources(Widelands::kNoResource, 0);
2343+ overlay_manager().remove_overlay(f_sw_e, NULL);
2344+ }
2345+
2346 Notifications::publish(NoteFieldTransformed(c, c.field - &m_fields[0]));
2347
2348 recalc_for_field_area(world, Area<FCoords>(c, 2));
2349@@ -1878,6 +1884,45 @@
2350 return 2;
2351 }
2352
2353+bool Map::is_resource_valid
2354+ (const Widelands::World& world, const TCoords<Widelands::FCoords>& c, int32_t const curres)
2355+{
2356+ if (curres == Widelands::kNoResource)
2357+ return true;
2358+
2359+ Widelands::FCoords f(c, c.field);
2360+ Widelands::FCoords f1;
2361+
2362+ int32_t count = 0;
2363+
2364+ // this field
2365+ count += world.terrain_descr(f.field->terrain_r()).is_resource_valid(curres);
2366+ count += world.terrain_descr(f.field->terrain_d()).is_resource_valid(curres);
2367+
2368+ // If one of the neighbours is impassable, count its resource stronger.
2369+ // top left neigbour
2370+ get_neighbour(f, Widelands::WALK_NW, &f1);
2371+ count += world.terrain_descr(f1.field->terrain_r()).is_resource_valid(curres);
2372+ count += world.terrain_descr(f1.field->terrain_d()).is_resource_valid(curres);
2373+
2374+ // top right neigbour
2375+ get_neighbour(f, Widelands::WALK_NE, &f1);
2376+ count += world.terrain_descr(f1.field->terrain_d()).is_resource_valid(curres);
2377+
2378+ // left neighbour
2379+ get_neighbour(f, Widelands::WALK_W, &f1);
2380+ count += world.terrain_descr(f1.field->terrain_r()).is_resource_valid(curres);
2381+
2382+ return count > 1;
2383+}
2384+
2385+void Map::ensure_resource_consistency(const World& world)
2386+{
2387+ for (MapIndex i = 0; i < max_index(); ++i)
2388+ if (!is_resource_valid(world, get_fcoords(m_fields[i]), m_fields[i].get_resources()))
2389+ m_fields[i].set_resources(Widelands::kNoResource, 0);
2390+}
2391+
2392
2393 uint32_t Map::set_height(const World& world, const FCoords fc, uint8_t const new_value) {
2394 assert(new_value <= MAX_FIELD_HEIGHT);
2395
2396=== modified file 'src/logic/map.h'
2397--- src/logic/map.h 2015-12-04 17:58:39 +0000
2398+++ src/logic/map.h 2016-01-04 21:01:25 +0000
2399@@ -184,6 +184,19 @@
2400
2401 void recalc_whole_map(const World& world);
2402 virtual void recalc_for_field_area(const World& world, Area<FCoords>);
2403+
2404+ /***
2405+ * Ensures that resources match their adjacent terrains.
2406+ */
2407+ void ensure_resource_consistency(const World& world);
2408+
2409+ /***
2410+ * Recalculates all default resources.
2411+ *
2412+ * This is just needed for the game, not for
2413+ * the editor. Since there, default resources
2414+ * are not shown.
2415+ */
2416 void recalc_default_resources(const World& world);
2417
2418 void set_nrplayers(PlayerNumber);
2419@@ -370,9 +383,24 @@
2420 */
2421 uint32_t set_height(const World& world, Area<FCoords>, HeightInterval height_interval);
2422
2423- // change terrain of a triangle, recalculate buildcaps
2424+ /***
2425+ * Changes the given triangle's terrain. This happens in the editor and might
2426+ * happen in the game too if some kind of land increasement is implemented (like
2427+ * drying swamps). The nodecaps need to be recalculated
2428+ *
2429+ * @return the radius of changes (which are always 2)
2430+ */
2431 int32_t change_terrain(const World& world, TCoords<FCoords>, DescriptionIndex);
2432
2433+ /***
2434+ * Verify if a resource attached to a vertex has enough adjacent matching terrains to be valid.
2435+ *
2436+ * To qualify as valid, resources need to be surrounded by at least two matching terrains.
2437+ */
2438+ bool is_resource_valid
2439+ (const Widelands::World& world, const Widelands::TCoords<Widelands::FCoords>& c,
2440+ int32_t const curres);
2441+
2442 // The objectives that are defined in this map if it is a scenario.
2443 const Objectives& objectives() const {
2444 return objectives_;
2445@@ -448,10 +476,8 @@
2446 bool consider_mobs = true, NodeCaps initcaps = CAPS_NONE);
2447 bool is_cycle_connected
2448 (const FCoords & start, uint32_t length, const WalkingDir * dirs);
2449-
2450 template<typename functorT>
2451 void find_reachable(Area<FCoords>, const CheckStep &, functorT &);
2452-
2453 template<typename functorT> void find(const Area<FCoords>, functorT &) const;
2454
2455 MapVersion m_map_version;
2456@@ -545,7 +571,7 @@
2457 assert(0 <= o->y);
2458 assert(o->y < m_height);
2459 assert(m_fields.get() <= o->field);
2460- assert (o->field < m_fields.get() + max_index());
2461+ assert(o->field < m_fields.get() + max_index());
2462 }
2463 inline Coords Map::l_n(const Coords & f) const {
2464 assert(0 <= f.x);
2465@@ -567,7 +593,7 @@
2466 assert(0 <= f.y);
2467 assert(f.y < m_height);
2468 assert(m_fields.get() <= f.field);
2469- assert (f.field < m_fields.get() + max_index());
2470+ assert(f.field < m_fields.get() + max_index());
2471 FCoords result(Coords(f.x - 1, f.y), f.field - 1);
2472 if (result.x == -1) {
2473 result.x = m_width - 1;
2474@@ -578,7 +604,7 @@
2475 assert(0 <= result.y);
2476 assert(result.y < m_height);
2477 assert(m_fields.get() <= result.field);
2478- assert (result.field < m_fields.get() + max_index());
2479+ assert(result.field < m_fields.get() + max_index());
2480 return result;
2481 }
2482
2483@@ -615,7 +641,7 @@
2484 assert(0 <= o->y);
2485 assert(o->y < m_height);
2486 assert(m_fields.get() <= o->field);
2487- assert (o->field < m_fields.get() + max_index());
2488+ assert(o->field < m_fields.get() + max_index());
2489 }
2490 inline Coords Map::r_n(const Coords & f) const {
2491 assert(0 <= f.x);
2492@@ -637,7 +663,7 @@
2493 assert(0 <= f.y);
2494 assert(f.y < m_height);
2495 assert(m_fields.get() <= f.field);
2496- assert (f.field < m_fields.get() + max_index());
2497+ assert(f.field < m_fields.get() + max_index());
2498 FCoords result(Coords(f.x + 1, f.y), f.field + 1);
2499 if (result.x == m_width) {result.x = 0; result.field -= m_width;}
2500 assert(0 <= result.x);
2501@@ -645,7 +671,7 @@
2502 assert(0 <= result.y);
2503 assert(result.y < m_height);
2504 assert(m_fields.get() <= result.field);
2505- assert (result.field < m_fields.get() + max_index());
2506+ assert(result.field < m_fields.get() + max_index());
2507 return result;
2508 }
2509
2510@@ -676,7 +702,7 @@
2511 assert(0 <= f.y);
2512 assert(f.y < m_height);
2513 assert(m_fields.get() <= f.field);
2514- assert (f.field < m_fields.get() + max_index());
2515+ assert(f.field < m_fields.get() + max_index());
2516 o->y = f.y - 1;
2517 o->x = f.x;
2518 o->field = f.field - m_width;
2519@@ -697,7 +723,7 @@
2520 assert(0 <= o->y);
2521 assert(o->y < m_height);
2522 assert(m_fields.get() <= o->field);
2523- assert (o->field < m_fields.get() + max_index());
2524+ assert(o->field < m_fields.get() + max_index());
2525 }
2526 inline Coords Map::tl_n(const Coords & f) const {
2527 assert(0 <= f.x);
2528@@ -724,7 +750,7 @@
2529 assert(0 <= f.y);
2530 assert(f.y < m_height);
2531 assert(m_fields.get() <= f.field);
2532- assert (f.field < m_fields.get() + max_index());
2533+ assert(f.field < m_fields.get() + max_index());
2534 FCoords result(Coords(f.x, f.y - 1), f.field - m_width);
2535 if (result.y & 1) {
2536 if (result.y == -1) {
2537@@ -743,7 +769,7 @@
2538 assert(0 <= result.y);
2539 assert(result.y < m_height);
2540 assert(m_fields.get() <= result.field);
2541- assert (result.field < m_fields.get() + max_index());
2542+ assert(result.field < m_fields.get() + max_index());
2543 return result;
2544 }
2545
2546@@ -774,7 +800,7 @@
2547 assert(0 <= f.y);
2548 assert(f.y < m_height);
2549 assert(m_fields.get() <= f.field);
2550- assert (f.field < m_fields.get() + max_index());
2551+ assert(f.field < m_fields.get() + max_index());
2552 o->x = f.x;
2553 o->field = f.field - m_width;
2554 if (f.y & 1) {
2555@@ -795,7 +821,7 @@
2556 assert(0 <= o->y);
2557 assert(o->y < m_height);
2558 assert(m_fields.get() <= o->field);
2559- assert (o->field < m_fields.get() + max_index());
2560+ assert(o->field < m_fields.get() + max_index());
2561 }
2562 inline Coords Map::tr_n(const Coords & f) const {
2563 assert(0 <= f.x);
2564@@ -822,7 +848,7 @@
2565 assert(0 <= f.y);
2566 assert(f.y < m_height);
2567 assert(m_fields.get() <= f.field);
2568- assert (f.field < m_fields.get() + max_index());
2569+ assert(f.field < m_fields.get() + max_index());
2570 FCoords result(Coords(f.x, f.y - 1), f.field - m_width);
2571 if (f.y & 1) {
2572 ++result.x;
2573@@ -841,7 +867,7 @@
2574 assert(0 <= result.y);
2575 assert(result.y < m_height);
2576 assert(m_fields.get() <= result.field);
2577- assert (result.field < m_fields.get() + max_index());
2578+ assert(result.field < m_fields.get() + max_index());
2579 return result;
2580 }
2581
2582@@ -871,7 +897,7 @@
2583 assert(0 <= f.y);
2584 assert(f.y < m_height);
2585 assert(m_fields.get() <= f.field);
2586- assert (f.field < m_fields.get() + max_index());
2587+ assert(f.field < m_fields.get() + max_index());
2588 o->y = f.y + 1;
2589 o->x = f.x;
2590 o->field = f.field + m_width;
2591@@ -892,7 +918,7 @@
2592 assert(0 <= o->y);
2593 assert(o->y < m_height);
2594 assert(m_fields.get() <= o->field);
2595- assert (o->field < m_fields.get() + max_index());
2596+ assert(o->field < m_fields.get() + max_index());
2597 }
2598 inline Coords Map::bl_n(const Coords & f) const {
2599 assert(0 <= f.x);
2600@@ -919,7 +945,7 @@
2601 assert(0 <= f.y);
2602 assert(f.y < m_height);
2603 assert(m_fields.get() <= f.field);
2604- assert (f.field < m_fields.get() + max_index());
2605+ assert(f.field < m_fields.get() + max_index());
2606 FCoords result(Coords(f.x, f.y + 1), f.field + m_width);
2607 if (result.y == m_height) {
2608 result.y = 0;
2609@@ -938,7 +964,7 @@
2610 assert(0 <= result.y);
2611 assert(result.y < m_height);
2612 assert(m_fields.get() <= result.field);
2613- assert (result.field < m_fields.get() + max_index());
2614+ assert(result.field < m_fields.get() + max_index());
2615 return result;
2616 }
2617
2618@@ -971,7 +997,7 @@
2619 assert(0 <= f.y);
2620 assert(f.y < m_height);
2621 assert(m_fields.get() <= f.field);
2622- assert (f.field < m_fields.get() + max_index());
2623+ assert(f.field < m_fields.get() + max_index());
2624 o->x = f.x;
2625 o->field = f.field + m_width;
2626 if (f.y & 1) {
2627@@ -992,7 +1018,7 @@
2628 assert(0 <= o->y);
2629 assert(o->y < m_height);
2630 assert(m_fields.get() <= o->field);
2631- assert (o->field < m_fields.get() + max_index());
2632+ assert(o->field < m_fields.get() + max_index());
2633 }
2634 inline Coords Map::br_n(const Coords & f) const {
2635 assert(0 <= f.x);
2636@@ -1019,7 +1045,7 @@
2637 assert(0 <= f.y);
2638 assert(f.y < m_height);
2639 assert(m_fields.get() <= f.field);
2640- assert (f.field < m_fields.get() + max_index());
2641+ assert(f.field < m_fields.get() + max_index());
2642 FCoords result(Coords(f.x, f.y + 1), f.field + m_width);
2643 if (f.y & 1) {
2644 ++result.x;
2645@@ -1038,7 +1064,7 @@
2646 assert(0 <= result.y);
2647 assert(result.y < m_height);
2648 assert(m_fields.get() <= result.field);
2649- assert (result.field < m_fields.get() + max_index());
2650+ assert(result.field < m_fields.get() + max_index());
2651 return result;
2652 }
2653
2654
2655=== modified file 'src/logic/widelands.h'
2656--- src/logic/widelands.h 2015-11-11 09:56:22 +0000
2657+++ src/logic/widelands.h 2016-01-04 21:01:25 +0000
2658@@ -62,6 +62,7 @@
2659 using Direction = uint8_t;
2660 constexpr uint8_t INVALID_INDEX = std::numeric_limits<uint8_t>::max();
2661 constexpr DescriptionIndex kInvalidWare = INVALID_INDEX - 1;
2662+constexpr DescriptionIndex kNoResource = INVALID_INDEX - 1;
2663
2664 struct SoldierStrength {
2665 uint8_t hp, attack, defense, evade;
2666
2667=== modified file 'src/logic/worker.cc'
2668--- src/logic/worker.cc 2015-12-05 10:59:02 +0000
2669+++ src/logic/worker.cc 2016-01-04 21:01:25 +0000
2670@@ -945,26 +945,23 @@
2671 BaseImmovable const * const imm = position.field->get_immovable();
2672 const World & world = game.world();
2673
2674- if (imm && imm->get_size() > BaseImmovable::NONE) {
2675- //NoLog(" Field is no longer empty\n");
2676- } else if
2677- (const ResourceDescription * const rdescr =
2678- world.get_resource(position.field->get_resources()))
2679- {
2680+ if (!(imm && imm->get_size() > BaseImmovable::NONE)) {
2681+
2682+ const ResourceDescription * const rdescr =
2683+ world.get_resource(position.field->get_resources());
2684 const TribeDescr & t = owner().tribe();
2685 const Immovable& ri = game.create_immovable
2686- (position,
2687- t.get_resource_indicator
2688- (rdescr,
2689- rdescr->detectable() ?
2690- position.field->get_resources_amount() : 0),
2691- MapObjectDescr::OwnerType::kTribe);
2692+ (position,
2693+ t.get_resource_indicator
2694+ (rdescr,
2695+ (rdescr && rdescr->detectable()) ?
2696+ position.field->get_resources_amount() : 0),
2697+ MapObjectDescr::OwnerType::kTribe);
2698
2699 // Geologist also sends a message notifying the player
2700- if (rdescr->detectable() && position.field->get_resources_amount()) {
2701+ if (rdescr && rdescr->detectable() && position.field->get_resources_amount()) {
2702 const std::string message =
2703- (boost::format("<rt image=%s>"
2704- "<p font-face=serif font-size=14>%s</p></rt>")
2705+ (boost::format("<rt image=%s><p font-face=serif font-size=14>%s</p></rt>")
2706 % rdescr->get_editor_pic(rdescr->max_amount())
2707 % _("A geologist found resources.")).str();
2708
2709@@ -983,18 +980,17 @@
2710 // We should add a message to the player's message queue - but only,
2711 // if there is not already a similar one in list.
2712 owner().add_message_with_timeout
2713- (game,
2714- *new Message
2715- (message_type,
2716- game.get_gametime(),
2717- rdescr->descname(),
2718- ri.descr().representative_image_filename(),
2719- rdescr->descname(),
2720- message,
2721- position,
2722- m_serial
2723- ),
2724- 300000, 8);
2725+ (game,
2726+ *new Message
2727+ (message_type,
2728+ game.get_gametime(),
2729+ rdescr->descname(),
2730+ ri.descr().representative_image_filename(),
2731+ rdescr->descname(),
2732+ message,
2733+ position,
2734+ m_serial),
2735+ 300000, 8);
2736 }
2737 }
2738
2739
2740=== modified file 'src/logic/world/world.cc'
2741--- src/logic/world/world.cc 2015-11-11 10:03:41 +0000
2742+++ src/logic/world/world.cc 2016-01-04 21:01:25 +0000
2743@@ -172,11 +172,14 @@
2744 }
2745
2746 DescriptionIndex World::get_resource(const char* const name) const {
2747- return resources_->get_index(name);
2748+ return strcmp(name, "none") ? resources_->get_index(name): Widelands::kNoResource;
2749 }
2750
2751+/***
2752+ * @return The ResourceDescription for the given index. Returns Nullptr for kNoResource.
2753+ */
2754 ResourceDescription const* World::get_resource(DescriptionIndex const res) const {
2755- assert(res < resources_->size());
2756+ assert(res < resources_->size() || res == Widelands::kNoResource);
2757 return resources_->get_mutable(res);
2758 }
2759
2760
2761=== modified file 'src/map_io/widelands_map_loader.cc'
2762--- src/map_io/widelands_map_loader.cc 2015-09-18 18:17:01 +0000
2763+++ src/map_io/widelands_map_loader.cc 2016-01-04 21:01:25 +0000
2764@@ -290,6 +290,8 @@
2765
2766 m_map.recalc_whole_map(egbase.world());
2767
2768+ m_map.ensure_resource_consistency(egbase.world());
2769+
2770 set_state(STATE_LOADED);
2771
2772 return 0;
2773
2774=== modified file 'src/scripting/lua_map.cc'
2775--- src/scripting/lua_map.cc 2015-12-09 17:39:11 +0000
2776+++ src/scripting/lua_map.cc 2016-01-04 21:01:25 +0000
2777@@ -4432,9 +4432,12 @@
2778 :see also: :attr:`resource_amount`
2779 */
2780 int LuaField::get_resource(lua_State * L) {
2781+
2782+ const ResourceDescription* rDesc = get_egbase(L).world().get_resource
2783+ (fcoords(L).field->get_resources());
2784+
2785 lua_pushstring
2786- (L, get_egbase(L).world().get_resource
2787- (fcoords(L).field->get_resources())->name().c_str());
2788+ (L, rDesc ? rDesc->name().c_str() : "none");
2789
2790 return 1;
2791 }
2792@@ -4466,7 +4469,8 @@
2793 Field * field = fcoords(L).field;
2794 int32_t res = field->get_resources();
2795 int32_t amount = luaL_checkint32(L, -1);
2796- int32_t max_amount = get_egbase(L).world().get_resource(res)->max_amount();
2797+ const ResourceDescription * resDesc = get_egbase(L).world().get_resource(res);
2798+ int32_t max_amount = resDesc ? resDesc->max_amount() : 0;
2799
2800 if (amount < 0 || amount > max_amount)
2801 report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount, max_amount);
2802
2803=== modified file 'src/ui_fsmenu/options.cc'
2804--- src/ui_fsmenu/options.cc 2016-01-01 18:57:17 +0000
2805+++ src/ui_fsmenu/options.cc 2016-01-04 21:01:25 +0000
2806@@ -532,7 +532,8 @@
2807 * Handles communication between window class and options
2808 */
2809 OptionsCtrl::OptionsCtrl(Section & s)
2810-: opt_section_(s), opt_dialog_(std::unique_ptr<FullscreenMenuOptions>(new FullscreenMenuOptions(options_struct(0))))
2811+: opt_section_(s),
2812+ opt_dialog_(std::unique_ptr<FullscreenMenuOptions>(new FullscreenMenuOptions(options_struct(0))))
2813 {
2814 handle_menu();
2815 }
2816
2817=== modified file 'src/wui/overlay_manager.cc'
2818--- src/wui/overlay_manager.cc 2014-09-14 11:31:58 +0000
2819+++ src/wui/overlay_manager.cc 2016-01-04 21:01:25 +0000
2820@@ -182,6 +182,8 @@
2821
2822 /**
2823 * remove one (or many) overlays from a node or triangle
2824+ *
2825+ * @param pic The overlay to remove. If null, all overlays are removed.
2826 */
2827 void OverlayManager::remove_overlay
2828 (Widelands::TCoords<> const c, const Image* pic)
2829@@ -193,7 +195,7 @@
2830 if (overlay_map.count(c)) {
2831 RegisteredOverlaysMap::iterator it = overlay_map.lower_bound(c);
2832 do {
2833- if (pic && it->second.pic == pic) {
2834+ if (!pic || it->second.pic == pic) {
2835 overlay_map.erase(it);
2836 it = overlay_map.lower_bound(c);
2837 } else {
2838
2839=== modified file 'src/wui/overlay_manager.h'
2840--- src/wui/overlay_manager.h 2014-09-14 11:31:58 +0000
2841+++ src/wui/overlay_manager.h 2016-01-04 21:01:25 +0000
2842@@ -66,7 +66,7 @@
2843 };
2844
2845 using CallbackFn =
2846- boost::function<int32_t(const Widelands::TCoords<Widelands::FCoords>& coordinates)>;
2847+ boost::function<bool(const Widelands::TCoords<Widelands::FCoords>& coordinates)>;
2848
2849 OverlayManager();
2850
2851
2852=== modified file 'test/maps/lua_testsuite.wmf/scripting/efield.lua'
2853--- test/maps/lua_testsuite.wmf/scripting/efield.lua 2015-10-31 11:59:04 +0000
2854+++ test/maps/lua_testsuite.wmf/scripting/efield.lua 2016-01-04 21:01:25 +0000
2855@@ -5,15 +5,15 @@
2856 function field_resources_tests:test_default_resource_in_editor()
2857 -- The editor doesn't bother to set the default resources on the map.
2858 -- The user might want to overwrite them anyways. It therefore sets
2859- -- the resource of all fields to the first in the world and the amount
2860- -- to zero.
2861- assert_equal("coal", self.f.resource)
2862+ -- the resource of all fields to 'none' and the amount to zero.
2863+ assert_equal("none", self.f.resource)
2864 assert_equal(0, self.f.resource_amount)
2865 end
2866
2867 function field_resources_tests:test_initial_resource_in_editor()
2868- -- making sure that (set_) resource_amount sets also starting resource in the editor
2869- assert_equal("coal", self.f.resource)
2870+ -- making sure that (set_) resource_amount sets also initial resource in the editor
2871+ -- the resource has to be set to something different than 'none', as none has no amount
2872+ self.f.resource = "coal"
2873 self.f.resource_amount=10
2874 assert_equal(self.f.initial_resource_amount, self.f.resource_amount)
2875 assert_equal(10, self.f.initial_resource_amount)

Subscribers

People subscribed via source and target branches

to status/vote changes: