The Battle for Wesnoth  1.13.10+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 - 2017 by Fabian Mueller <fabianmueller5@gmx.de>
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 #pragma once
27 
28 #include "editor/action/action.hpp"
29 
30 #include "units/unit.hpp"
31 
32 namespace editor
33 {
34 /**
35  * place a new unit on the map
36  */
38 {
39 public:
42  , u_(u)
43  {
44  }
45 
46  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
47  editor_action_unit* clone() const;
48 
49  editor_action* perform(map_context& mc) const;
50 
51  void perform_without_undo(map_context& mc) const;
52 
53  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
54  const std::string& get_name() const;
55 
56 protected:
58 };
59 
60 /**
61  * Remove a unit from the map.
62  */
64 {
65 public:
68  {
69  }
70 
71  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
73 
74  editor_action* perform(map_context& mc) const;
75 
76  void perform_without_undo(map_context& mc) const;
77 
78  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
79  const std::string& get_name() const;
80 };
81 
83 {
84 public:
87  , new_loc_(new_loc)
88  {
89  }
90 
91  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
93 
94  editor_action* perform(map_context& mc) const;
95 
96  void perform_without_undo(map_context& mc) const;
97 
98  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
99  const std::string& get_name() const;
100 
101 protected:
103 };
104 
106 {
107 public:
109  map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
111  , new_direction_(new_direction)
112  , old_direction_(old_direction)
113  {
114  }
115 
116  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
118 
119  editor_action* perform(map_context& mc) const;
120 
121  void perform_without_undo(map_context& mc) const;
122 
123  /** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
124  const std::string& get_name() const;
125 
126 protected:
129 };
130 
131 } // end namespace editor
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
std::vector< char_t > string
editor_action_unit_delete(map_location loc)
Definition: action_unit.hpp:66
This class represents a single unit of a specific type.
Definition: unit.hpp:100
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_unit.cpp:41
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:77
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:50
Base class for actions which act on a specified location (and possibly on other locations that can be...
Definition: action.hpp:189
editor_action_unit_delete * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_unit.cpp:85
editor_action_unit_replace(map_location loc, map_location new_loc)
Definition: action_unit.hpp:85
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action_unit_facing * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
Editor action classes.
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:34
Manage the empty-palette in the editor.
Definition: action.cpp:29
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
Encapsulates the map of the game.
Definition: location.hpp:40
place a new unit on the map
Definition: action_unit.hpp:37
editor_action_unit(map_location loc, const unit &u)
Definition: action_unit.hpp:40
Base class for all editor actions.
Definition: action_base.hpp:40
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
editor_action_unit_facing(map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:42
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Definition: action_unit.cpp:65
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:55
editor_action_unit * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
Remove a unit from the map.
Definition: action_unit.hpp:63
map_location::DIRECTION old_direction_
editor_action_unit_replace * clone() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.
map_location::DIRECTION new_direction_
const std::string & get_name() const
Inherited from editor_action, implemented by IMPLEMENT_ACTION.