The Battle for Wesnoth  1.13.10+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 - 2017 by Fabian Mueller <fabianmueller5@gmx.de>
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 {
28 IMPLEMENT_ACTION(village)
29 
31 {
32  if(!mc.get_map().is_village(loc_)) {
33  return nullptr;
34  }
35 
36  std::vector<team>& teams = mc.get_teams();
37 
38  try {
39  if(teams.at(side_number_).owns_village(loc_)) {
40  return nullptr;
41  }
42  } catch(const std::out_of_range&) {
43  // side_number_ was an invalid team index.
44  }
45 
47 
48  for(const team& t : teams) {
49  if(t.owns_village(loc_)) {
50  undo.reset(new editor_action_village(loc_, t.side() - 1));
51  }
52  }
53 
54  perform_without_undo(mc);
55  return undo.release();
56 }
57 
59 {
60  std::vector<team>& teams = mc.get_teams();
61 
62  for(team& t : teams) {
63  if(t.owns_village(loc_)) {
64  t.lose_village(loc_);
65  }
66  }
67 
68  // TODO 0 is a bad argument
69  teams[side_number_].get_village(loc_, 0, nullptr);
70 }
71 
72 IMPLEMENT_ACTION(village_delete)
73 
75 {
76  editor_action_ptr undo;
77 
78  for(const team& t : mc.get_teams()) {
79  if(t.owns_village(loc_)) {
80  perform_without_undo(mc);
81  undo.reset(new editor_action_village(loc_, t.side() - 1));
82  }
83  }
84 
85  return undo.release();
86 }
87 
89 {
90  for(team& t : mc.get_teams()) {
91  if(t.owns_village(loc_)) {
92  t.lose_village(loc_);
94  }
95  }
96 }
97 
98 } // end namespace editor
void add_changed_location(const map_location &loc)
std::unique_ptr< editor_action > editor_action_ptr
Action pointer typedef.
Sets the ownership of a village to the current side.
-file sdl_utils.hpp
map_location loc_
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:44
Manage the empty-palette in the editor.
Definition: action.cpp:29
std::vector< team > & get_teams()
Get the team from the current map context object.
Base class for all editor actions.
Definition: action_base.hpp:40
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:55
void perform_without_undo(map_context &mc) const
Perform the action without creating an undo action.
Editor action classes.
double t
Definition: astarsearch.cpp:64
#define IMPLEMENT_ACTION(id)
Helper macro to implement common action methods.
Clears the ownership of a village.