The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
action_unit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Fabian Mueller <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Editor action classes. Some important points:
18  * - This is a polymorphic hierarchy of classes, so actions are usually passed around
19  * as editor_action pointers
20  * - The pointers can, in general, be null. Always check for null before doing anything.
21  * The helper functions perform_ that take a pointer do that.
22  * - The perform() functions can throw when an error occurs. Use smart pointers if you
23  * need to ensure the pointer is deleted.
24  */
25 
26 #ifndef EDITOR_ACTION_UNIT_HPP
27 #define EDITOR_ACTION_UNIT_HPP
28 
29 #include "editor/action/action.hpp"
30 
31 #include "units/unit.hpp"
32 
33 namespace editor {
34 
35 
36 /**
37  * place a new unit on the map
38  */
40 {
41  public:
43  const unit& u)
44  : editor_action_location(loc), u_(u)
45  {
46  }
47  editor_action_unit* clone() const;
48  editor_action* perform(map_context& mc) const;
49  void perform_without_undo(map_context& mc) const;
50  const char* get_name() const { return "unit"; }
51  protected:
53 };
54 
55 /**
56  * Remove a unit from the map.
57  */
59 {
60  public:
63  {
64  }
66  editor_action* perform(map_context& mc) const;
67  void perform_without_undo(map_context& mc) const;
68  const char* get_name() const { return "unit_delete"; }
69 };
70 
72 {
73  public:
75  : editor_action_location(loc), new_loc_(new_loc)
76  {
77  }
79  editor_action* perform(map_context& mc) const;
80  void perform_without_undo(map_context& mc) const;
81  const char* get_name() const { return "unit_replace"; }
82  protected:
84 };
85 
87 {
88  public:
90  : editor_action_location(loc), new_direction_(new_direction), old_direction_(old_direction)
91  {
92  }
94  editor_action* perform(map_context& mc) const;
95  void perform_without_undo(map_context& mc) const;
96  const char* get_name() const { return "unit_facing"; }
97 protected:
100 };
101 
102 
103 } //end namespace editor
104 
105 #endif
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
editor_action_unit_facing * clone() const
Action cloning.
editor_action_unit_delete(map_location loc)
Definition: action_unit.hpp:61
editor_action_unit_replace * clone() const
Action cloning.
Definition: action_unit.cpp:84
Definition: unit.hpp:95
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_unit.cpp:46
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action_unit.cpp:89
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action_unit.cpp:59
Base class for actions which act on a specified location (and possibly on other locations that can be...
Definition: action.hpp:177
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
editor_action_unit * clone() const
Action cloning.
Definition: action_unit.cpp:34
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_unit.cpp:97
editor_action_unit_replace(map_location loc, map_location new_loc)
Definition: action_unit.hpp:74
const char * get_name() const
Definition: action_unit.hpp:81
Editor action classes.
const char * get_name() const
Definition: action_unit.hpp:50
editor_action_unit_delete * clone() const
Action cloning.
Definition: action_unit.cpp:54
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action_unit.cpp:39
Manage the empty-palette in the editor.
Definition: action.cpp:28
Encapsulates the map of the game.
Definition: location.hpp:38
place a new unit on the map
Definition: action_unit.hpp:39
editor_action_unit(map_location loc, const unit &u)
Definition: action_unit.hpp:42
Base class for all editor actions.
Definition: action_base.hpp:41
editor_action_unit_facing(map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
Definition: action_unit.hpp:89
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:40
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_unit.cpp:73
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:41
Remove a unit from the map.
Definition: action_unit.hpp:58
map_location::DIRECTION old_direction_
Definition: action_unit.hpp:99
map_location::DIRECTION new_direction_
Definition: action_unit.hpp:98
const char * get_name() const
Definition: action_unit.hpp:68
const char * get_name() const
Definition: action_unit.hpp:96