-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
action_village.cpp
97 lines (75 loc) · 2.58 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
/*
Copyright (C) 2008 - 2016 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"
namespace editor {
editor_action_village* editor_action_village::clone() const
{
return new editor_action_village(*this);
}
editor_action* editor_action_village::perform(map_context& mc) const
{
std::unique_ptr<editor_action> undo;
if(!mc.get_map().is_village(loc_)) return NULL;
std::vector<team>& teams = mc.get_teams();
team *t = unsigned(side_number_) < teams.size() ? &teams[side_number_] : NULL;
if (t && t->owns_village(loc_)) return NULL;
undo.reset(new editor_action_village_delete(loc_));
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
if (i->owns_village(loc_))
undo.reset(new editor_action_village(loc_, i->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.get_teams();
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
if (i->owns_village(loc_))
i->lose_village(loc_);
}
//TODO 0 is a bad argument
teams[side_number_].get_village(loc_, 0, NULL);
}
editor_action_village_delete* editor_action_village_delete::clone() const
{
return new editor_action_village_delete(*this);
}
editor_action* editor_action_village_delete::perform(map_context& mc) const
{
std::unique_ptr<editor_action> undo;
const std::vector<team>& teams = mc.get_teams();
for(std::vector<team>::const_iterator i = teams.begin(); i != teams.end(); ++i) {
if (i->owns_village(loc_)) {
perform_without_undo(mc);
undo.reset(new editor_action_village(loc_, i->side() -1));
}
}
return undo.release();
}
void editor_action_village_delete::perform_without_undo(map_context& mc) const
{
std::vector<team>& teams = mc.get_teams();
for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
if (i->owns_village(loc_)) {
i->lose_village(loc_);
mc.add_changed_location(loc_);
}
}
}
} //end namespace editor