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