1 /*
2  * Copyright (C) 2002-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 
20 #include "editor/tools/delete_immovable_tool.h"
21 
22 #include "base/macros.h"
23 #include "editor/editorinteractive.h"
24 #include "logic/field.h"
25 #include "logic/map_objects/immovable.h"
26 #include "logic/mapregion.h"
27 
28 /**
29  * Deletes the immovable at the given location
30  */
handle_click_impl(const Widelands::NodeAndTriangle<> & center,EditorInteractive & eia,EditorActionArgs * args,Widelands::Map * map)31 int32_t EditorDeleteImmovableTool::handle_click_impl(const Widelands::NodeAndTriangle<>& center,
32                                                      EditorInteractive& eia,
33                                                      EditorActionArgs* args,
34                                                      Widelands::Map* map) {
35 	Widelands::MapRegion<Widelands::Area<Widelands::FCoords>> mr(
36 	   *map, Widelands::Area<Widelands::FCoords>(map->get_fcoords(center.node), args->sel_radius));
37 	do
38 		if (upcast(Widelands::Immovable, immovable, mr.location().field->get_immovable())) {
39 			args->old_immovable_types.push_back(immovable->descr().name());
40 			immovable->remove(eia.egbase());  //  Delete no buildings or stuff.
41 		} else {
42 			args->old_immovable_types.push_back("");
43 		}
44 	while (mr.advance(*map));
45 	return mr.radius() + 2;
46 }
47 
handle_undo_impl(const Widelands::NodeAndTriangle<Widelands::Coords> & center,EditorInteractive & parent,EditorActionArgs * args,Widelands::Map * map)48 int32_t EditorDeleteImmovableTool::handle_undo_impl(
49    const Widelands::NodeAndTriangle<Widelands::Coords>& center,
50    EditorInteractive& parent,
51    EditorActionArgs* args,
52    Widelands::Map* map) {
53 	return parent.tools()->place_immovable.handle_undo_impl(center, parent, args, map);
54 }
55 
format_args_impl(EditorInteractive & parent)56 EditorActionArgs EditorDeleteImmovableTool::format_args_impl(EditorInteractive& parent) {
57 	return EditorTool::format_args_impl(parent);
58 }
59