The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
action_village.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Fabian Mueller <[email protected]>
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 label action classes
18  */
19 #define GETTEXT_DOMAIN "wesnoth-editor"
20 
22 
24 #include "team.hpp"
25 
26 namespace editor {
27 
29 {
30  return new editor_action_village(*this);
31 }
32 
34 {
35  std::unique_ptr<editor_action> undo;
36 
37  if(!mc.get_map().is_village(loc_)) return nullptr;
38  std::vector<team>& teams = mc.get_teams();
39  team *t = unsigned(side_number_) < teams.size() ? &teams[side_number_] : nullptr;
40  if (t && t->owns_village(loc_)) return nullptr;
41 
42  undo.reset(new editor_action_village_delete(loc_));
43 
44  for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
45  if (i->owns_village(loc_))
46  undo.reset(new editor_action_village(loc_, i->side() -1));
47  }
48 
50  return undo.release();
51 }
52 
54 {
55  std::vector<team>& teams = mc.get_teams();
56  for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
57  if (i->owns_village(loc_))
58  i->lose_village(loc_);
59  }
60 
61  //TODO 0 is a bad argument
62  teams[side_number_].get_village(loc_, 0, nullptr);
63 }
64 
65 
67 {
68  return new editor_action_village_delete(*this);
69 }
70 
72 {
73  std::unique_ptr<editor_action> undo;
74 
75  const std::vector<team>& teams = mc.get_teams();
76  for(std::vector<team>::const_iterator i = teams.begin(); i != teams.end(); ++i) {
77  if (i->owns_village(loc_)) {
79  undo.reset(new editor_action_village(loc_, i->side() -1));
80  }
81  }
82 
83  return undo.release();
84 }
85 
87 {
88  std::vector<team>& teams = mc.get_teams();
89  for(std::vector<team>::iterator i = teams.begin(); i != teams.end(); ++i) {
90  if (i->owns_village(loc_)) {
91  i->lose_village(loc_);
93  }
94  }
95 }
96 
97 
98 } //end namespace editor
void add_changed_location(const map_location &loc)
editor_action_village_delete(map_location loc)
bool owns_village(const map_location &loc) const
Definition: team.hpp:190
bool is_village(const map_location &loc) const
Definition: map.cpp:68
Sets the ownership of a village to the current side.
-file sdl_utils.hpp
GLdouble GLdouble t
Definition: glew.h:1366
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
static std::vector< team > *& teams
Definition: team.cpp:50
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
editor_action_village * clone() const
Action cloning.
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
editor_map & get_map()
Map accessor.
Definition: map_context.hpp:75
editor_action * perform(map_context &mc) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Manage the empty-palette in the editor.
Definition: action.cpp:28
editor_action_village_delete * clone() const
Action cloning.
std::vector< team > & get_teams()
Get the team from the current map context object.
Base class for all editor actions.
Definition: action_base.hpp:41
size_t i
Definition: function.cpp:1057
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:41
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Editor action classes.
editor_action_village(map_location loc, int side_number)
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
Clears the ownership of a village.