The Battle for Wesnoth
1.19.7+dev
editor
action
action_village.cpp
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 label action classes
19
*/
20
#define GETTEXT_DOMAIN "wesnoth-editor"
21
22
#include "
editor/action/action_village.hpp
"
23
24
#include "
editor/map/map_context.hpp
"
25
#include "
team.hpp
"
26
27
namespace
editor
28
{
29
IMPLEMENT_ACTION
(village)
30
31
std::unique_ptr<
editor_action
>
editor_action_village
::perform(
map_context
& mc)
const
32
{
33
if
(!mc.map().is_village(
loc_
)) {
34
return
nullptr
;
35
}
36
37
std::vector<team>& teams = mc.teams();
38
39
try
{
40
if
(teams.at(side_number_).owns_village(
loc_
)) {
41
return
nullptr
;
42
}
43
}
catch
(
const
std::out_of_range&) {
44
// side_number_ was an invalid team index.
45
}
46
47
auto
undo =
static_cast<
std::unique_ptr<editor_action>
>
(std::make_unique<editor_action_village_delete>(
loc_
));
48
49
for
(
const
team
&
t
: teams) {
50
if
(
t
.owns_village(
loc_
)) {
51
undo = std::make_unique<editor_action_village>(
loc_
,
t
.side() - 1);
52
}
53
}
54
55
perform_without_undo(mc);
56
return
undo;
57
}
58
59
void
editor_action_village::perform_without_undo
(
map_context
& mc)
const
60
{
61
std::vector<team>& teams = mc.
teams
();
62
63
for
(
team
&
t
: teams) {
64
if
(
t
.owns_village(
loc_
)) {
65
t
.lose_village(
loc_
);
66
}
67
}
68
69
// TODO 0 is a bad argument
70
teams[
side_number_
].get_village(
loc_
, 0,
nullptr
);
71
}
72
73
IMPLEMENT_ACTION
(village_delete)
74
75
std::unique_ptr<
editor_action
>
editor_action_village_delete
::perform(
map_context
& mc)
const
76
{
77
// \todo: can this delete more than one village? If it can't, why isn't the return statement
78
// inside the loop? If it can, why doesn't it return an editor_action_chain of undo actions?
79
std::unique_ptr<editor_action> undo;
80
81
for
(
const
team
&
t
: mc.teams()) {
82
if
(
t
.owns_village(
loc_
)) {
83
perform_without_undo(mc);
84
undo = std::make_unique<editor_action_village>(
loc_
,
t
.side() - 1);
85
}
86
}
87
88
return
undo;
89
}
90
91
void
editor_action_village_delete::perform_without_undo
(
map_context
& mc)
const
92
{
93
for
(
team
&
t
: mc.
teams
()) {
94
if
(
t
.owns_village(
loc_
)) {
95
t
.lose_village(
loc_
);
96
mc.
add_changed_location
(
loc_
);
97
}
98
}
99
}
100
101
}
// end namespace editor
IMPLEMENT_ACTION
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
Definition:
action_base.hpp:125
action_village.hpp
Editor action classes.
t
double t
Definition:
astarsearch.cpp:63
editor::editor_action_location::loc_
map_location loc_
Definition:
action.hpp:191
editor::editor_action_village_delete
Clears the ownership of a village.
Definition:
action_village.hpp:58
editor::editor_action_village_delete::perform_without_undo
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition:
action_village.cpp:91
editor::editor_action_village
Sets the ownership of a village to the current side.
Definition:
action_village.hpp:37
editor::editor_action_village::side_number_
int side_number_
Definition:
action_village.hpp:51
editor::editor_action_village::perform_without_undo
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition:
action_village.cpp:59
editor::editor_action
Base class for all editor actions.
Definition:
action_base.hpp:42
editor::map_context
This class wraps around a map to provide a concise interface for the editor to work with.
Definition:
map_context.hpp:63
editor::map_context::teams
virtual const std::vector< team > & teams() const override
Const teams accessor.
Definition:
map_context.hpp:141
editor::map_context::add_changed_location
void add_changed_location(const map_location &loc)
Definition:
map_context.cpp:584
team
This class stores all the data for a single 'side' (in game nomenclature).
Definition:
team.hpp:75
loc_
map_location loc_
Definition:
function_table.cpp:157
map_context.hpp
editor
Manage the empty-palette in the editor.
Definition:
action.cpp:31
team.hpp
Generated by
1.9.1