-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
action_village.cpp
98 lines (77 loc) · 2.15 KB
/
action_village.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright (C) 2008 - 2018 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* @file
* Editor label action classes
*/
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "editor/action/action_village.hpp"
#include "editor/map/map_context.hpp"
#include "team.hpp"
namespace editor
{
IMPLEMENT_ACTION(village)
editor_action* editor_action_village::perform(map_context& mc) const
{
if(!mc.map().is_village(loc_)) {
return nullptr;
}
std::vector<team>& teams = mc.teams();
try {
if(teams.at(side_number_).owns_village(loc_)) {
return nullptr;
}
} catch(const std::out_of_range&) {
// side_number_ was an invalid team index.
}
editor_action_ptr undo(new editor_action_village_delete(loc_));
for(const team& t : teams) {
if(t.owns_village(loc_)) {
undo.reset(new editor_action_village(loc_, t.side() - 1));
}
}
perform_without_undo(mc);
return undo.release();
}
void editor_action_village::perform_without_undo(map_context& mc) const
{
std::vector<team>& teams = mc.teams();
for(team& t : teams) {
if(t.owns_village(loc_)) {
t.lose_village(loc_);
}
}
// TODO 0 is a bad argument
teams[side_number_].get_village(loc_, 0, nullptr);
}
IMPLEMENT_ACTION(village_delete)
editor_action* editor_action_village_delete::perform(map_context& mc) const
{
editor_action_ptr undo;
for(const team& t : mc.teams()) {
if(t.owns_village(loc_)) {
perform_without_undo(mc);
undo.reset(new editor_action_village(loc_, t.side() - 1));
}
}
return undo.release();
}
void editor_action_village_delete::perform_without_undo(map_context& mc) const
{
for(team& t : mc.teams()) {
if(t.owns_village(loc_)) {
t.lose_village(loc_);
mc.add_changed_location(loc_);
}
}
}
} // end namespace editor