The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
map_context.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Tomasz Sniatowski <[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 #define GETTEXT_DOMAIN "wesnoth-editor"
15 
16 #include "editor/action/action.hpp"
18 #include "map_context.hpp"
19 
20 #include "config_assign.hpp"
21 #include "display.hpp"
22 #include "filesystem.hpp"
23 #include "gettext.hpp"
24 #include "map/exception.hpp"
25 #include "map/label.hpp"
26 #include "resources.hpp"
28 #include "serialization/parser.hpp"
29 #include "terrain/type_data.hpp"
30 #include "team.hpp"
31 #include "units/unit.hpp"
32 #include "wml_exception.hpp"
33 
34 
35 #include "formula/string_utils.hpp"
36 
37 #include <boost/regex.hpp>
38 
39 
40 namespace editor {
41 
42 const size_t map_context::max_action_stack_size_ = 100;
43 
44 map_context::map_context(const editor_map& map, const display& disp, bool pure_map, const config& schedule)
45  : filename_()
46  , map_data_key_()
47  , embedded_(false)
48  , pure_map_(pure_map)
49  , map_(map)
50  , undo_stack_()
51  , redo_stack_()
52  , actions_since_save_(0)
53  , starting_position_label_locs_()
54  , needs_reload_(false)
55  , needs_terrain_rebuild_(false)
56  , needs_labels_reset_(false)
57  , changed_locations_()
58  , everything_changed_(false)
59  , scenario_id_()
60  , scenario_name_()
61  , scenario_description_()
62  , xp_mod_(70)
63  , victory_defeated_(true)
64  , random_time_(false)
65  , active_area_(-1)
66  , labels_(disp, nullptr)
67  , units_()
68  , teams_()
69  , tod_manager_(new tod_manager(schedule))
70  , mp_settings_()
71  , game_classification_()
72  , music_tracks_()
73 {
74 }
75 
76 map_context::map_context(const config& game_config, const std::string& filename, const display& disp)
77  : filename_(filename)
78  , map_data_key_()
79  , embedded_(false)
80  , pure_map_(false)
81  , map_(game_config)
82  , undo_stack_()
83  , redo_stack_()
84  , actions_since_save_(0)
85  , starting_position_label_locs_()
86  , needs_reload_(false)
87  , needs_terrain_rebuild_(false)
88  , needs_labels_reset_(false)
89  , changed_locations_()
90  , everything_changed_(false)
91  , scenario_id_()
92  , scenario_name_()
93  , scenario_description_()
94  , xp_mod_(70)
95  , victory_defeated_(true)
96  , random_time_(false)
97  , active_area_(-1)
98  , labels_(disp, nullptr)
99  , units_()
100  , teams_()
101  , tod_manager_(new tod_manager(game_config.find_child("editor_times", "id", "default")))
102  , mp_settings_()
103  , game_classification_()
104  , music_tracks_()
105 {
106  /*
107  * Overview of situations possibly found in the file:
108  *
109  * 0. Not a scenario or map file.
110  * 0.1 File not found
111  * 0.2 Map file empty
112  * 0.3 No valid data
113  * 1. It's a file containing only pure map data.
114  * * embedded_ = false
115  * * pure_map_ = true
116  * 2. A scenario embedding the map
117  * * embedded_ = true
118  * * pure_map_ = true
119  * The data/scenario-test.cfg for example.
120  * The map is written back to the file.
121  * 3. The map file is referenced by map_data={MACRO_ARGUEMENT}.
122  * * embedded_ = false
123  * * pure_map_ = true
124  * 4. The file contains an editor generated scenario file.
125  * * embedded_ = false
126  * * pure_map_ = false
127  */
128 
129  log_scope2(log_editor, "Loading file " + filename);
130 
131  // 0.1 File not found
132  if (!filesystem::file_exists(filename) || filesystem::is_directory(filename))
133  throw editor_map_load_exception(filename, _("File not found"));
134 
135  std::string file_string = filesystem::read_file(filename);
136 
137  // 0.2 Map file empty
138  if (file_string.empty()) {
139  std::string message = _("Empty file");
140  throw editor_map_load_exception(filename, message);
141  }
142 
143  // 1.0 Pure map data
144  boost::regex rexpression_map_data("map_data\\s*=\\s*\"(.+?)\"");
145  boost::smatch matched_map_data;
146  if (!boost::regex_search(file_string, matched_map_data, rexpression_map_data,
147  boost::regex_constants::match_not_dot_null)) {
148  map_ = editor_map::from_string(game_config, file_string); //throws on error
149  pure_map_ = true;
150 
152  return;
153  }
154 
155  // 2.0 Embedded map
156  const std::string& map_data = matched_map_data[1];
157  boost::regex rexpression_macro("\\{(.+?)\\}");
158  boost::smatch matched_macro;
159  if (!boost::regex_search(map_data, matched_macro, rexpression_macro)) {
160  // We have a map_data string but no macro ---> embedded or scenario
161 
162  boost::regex rexpression_scenario("\\[scenario\\]|\\[test\\]|\\[multiplayer\\]");
163  if (!boost::regex_search(file_string, rexpression_scenario)) {
164  LOG_ED << "Loading generated scenario file" << std::endl;
165  // 4.0 editor generated scenario
166  try {
167  load_scenario(game_config);
168  } catch (config::error & e) {
169  throw editor_map_load_exception("load_scenario", e.message); //we already caught and rethrew this exception in load_scenario
170  }
171  } else {
172  LOG_ED << "Loading embedded map file" << std::endl;
173  embedded_ = true;
174  pure_map_ = true;
175  map_ = editor_map::from_string(game_config, map_data);
176  }
177 
179  return;
180  }
181 
182  // 3.0 Macro referenced pure map
183  const std::string& macro_argument = matched_macro[1];
184  LOG_ED << "Map looks like a scenario, trying {" << macro_argument << "}" << std::endl;
185  std::string new_filename = filesystem::get_wml_location(macro_argument,
186  filesystem::directory_name(macro_argument));
187  if (new_filename.empty()) {
188  std::string message = _("The map file looks like a scenario, "
189  "but the map_data value does not point to an existing file")
190  + std::string("\n") + macro_argument;
191  throw editor_map_load_exception(filename, message);
192  }
193  LOG_ED << "New filename is: " << new_filename << std::endl;
194  filename_ = new_filename;
195  file_string = filesystem::read_file(filename_);
196  map_ = editor_map::from_string(game_config, file_string);
197  pure_map_ = true;
198 
200 }
201 
202 void map_context::set_side_setup(int side, const std::string& team_name, const std::string& user_team_name,
203  int gold, int income, int village_gold, int village_support,
204  bool fog, bool shroud, team::SHARE_VISION share_vision,
205  team::CONTROLLER controller, bool hidden, bool no_leader)
206 {
207  assert(teams_.size() > static_cast<unsigned int>(side));
208  team& t = teams_[side];
209 // t.set_save_id(id);
210 // t.set_name(name);
211  t.change_team(team_name, user_team_name);
212  t.have_leader(!no_leader);
213  t.change_controller(controller);
214  t.set_gold(gold);
215  t.set_base_income(income);
216  t.set_hidden(hidden);
217  t.set_fog(fog);
218  t.set_shroud(shroud);
219  t.set_share_vision(share_vision);
220  t.set_village_gold(village_gold);
221  t.set_village_support(village_support);
223 }
224 
225 void map_context::set_scenario_setup(const std::string& id, const std::string& name, const std::string& description,
226  int turns, int xp_mod, bool victory_defeated, bool random_time)
227 {
228  scenario_id_ = id;
230  scenario_description_ = description;
231  random_time_ = random_time;
233  tod_manager_->set_number_of_turns(turns);
234  xp_mod_ = xp_mod;
236 }
237 
239 {
240  tod_manager_->set_current_time(time);
241  if (!pure_map_)
243 }
244 
246 {
247  tod_manager_->remove_time_area(index);
248  active_area_--;
250 }
251 
252 void map_context::replace_schedule(const std::vector<time_of_day>& schedule)
253 {
254  tod_manager_->replace_schedule(schedule);
255  if (!pure_map_)
257 }
258 
259 void map_context::replace_local_schedule(const std::vector<time_of_day>& schedule)
260 {
261  tod_manager_->replace_local_schedule(schedule, active_area_);
262  if (!pure_map_)
264 }
265 
267 {
268  config scenario;
269 
270  try {
271  read(scenario, *(preprocess_file(filename_)));
272  } catch (config::error & e) {
273  LOG_ED << "Caught a config error while parsing file: '" << filename_ << "'\n" << e.message << std::endl;
274  throw e;
275  }
276 
277  scenario_id_ = scenario["id"].str();
278  scenario_name_ = scenario["name"].str();
279  scenario_description_ = scenario["description"].str();
280 
281  xp_mod_ = scenario["experience_modifier"].to_int();
282 
283  victory_defeated_ = scenario["victory_when_enemies_defeated"].to_bool(true);
284  random_time_ = scenario["random_start_time"].to_bool(false);
285 
286  map_ = editor_map::from_string(game_config, scenario["map_data"]); //throws on error
287 
288  labels_.read(scenario);
289 
290  tod_manager_.reset(new tod_manager(scenario));
291  for(const config &time_area : scenario.child_range("time_area")) {
292  tod_manager_->add_time_area(map_,time_area);
293  }
294 
295  for(const config& item : scenario.child_range("item")) {
296  const map_location loc(item);
297  overlays_.insert(std::pair<map_location,
298  overlay>(loc, overlay(item) ));
299  }
300 
301  for(const config& music : scenario.child_range("music")) {
302  music_tracks_.insert(std::pair<std::string, sound::music_track>(music["name"], sound::music_track(music)));
303  }
304 
306 
307  int i = 1;
308  for(config &side : scenario.child_range("side"))
309  {
310  team t;
311  side["side"] = i;
312  t.build(side, map_);
313  teams_.push_back(t);
314 
315  for(config &a_unit : side.child_range("unit")) {
316  map_location loc(a_unit, nullptr);
317  a_unit["side"] = i;
318  units_.add(loc, unit(a_unit, true) );
319  }
320  i++;
321  }
322 }
323 
325 {
328 }
329 
331 {
332  return map_.set_selection(tod_manager_->get_area_by_index(index));
333 }
334 
336  const map_location& loc, bool one_layer_only)
337 {
338  t_translation::t_terrain full_terrain = one_layer_only ? terrain :
340 
341  draw_terrain_actual(full_terrain, loc, one_layer_only);
342 }
343 
345  const map_location& loc, bool one_layer_only)
346 {
347  if (!map_.on_board_with_border(loc)) {
348  //requests for painting off the map are ignored in set_terrain anyway,
349  //but ideally we should not have any
350  LOG_ED << "Attempted to draw terrain off the map (" << loc << ")\n";
351  return;
352  }
353  t_translation::t_terrain old_terrain = map_.get_terrain(loc);
354  if (terrain != old_terrain) {
355  if (terrain.base == t_translation::NO_LAYER) {
357  } else if (one_layer_only) {
359  } else {
360  map_.set_terrain(loc, terrain);
361  }
363  }
364 }
365 
367  const std::set<map_location>& locs, bool one_layer_only)
368 {
369  t_translation::t_terrain full_terrain = one_layer_only ? terrain :
371 
372  for(const map_location& loc : locs) {
373  draw_terrain_actual(full_terrain, loc, one_layer_only);
374  }
375 }
376 
378 {
379  everything_changed_ = false;
380  changed_locations_.clear();
381 }
382 
384 {
385  if (!everything_changed())
386  changed_locations_.insert(loc);
387 }
388 
389 void map_context::add_changed_location(const std::set<map_location>& locs)
390 {
391  if (!everything_changed())
392  changed_locations_.insert(locs.begin(), locs.end());
393 }
394 
396 {
397  everything_changed_ = true;
398 }
399 
401 {
402  return everything_changed_;
403 }
404 
406 {
407  disp.labels().clear_all();
409 }
410 
412 {
413  std::set<map_location> new_label_locs = map_.set_starting_position_labels(disp);
414  starting_position_label_locs_.insert(new_label_locs.begin(), new_label_locs.end());
415 }
416 
418 {
421  set_needs_labels_reset(false);
422 }
423 
425 {
426  config scenario;
427 
428  scenario["id"] = scenario_id_;
429  scenario["name"] = t_string(scenario_name_);
430  scenario["description"] = scenario_description_;
431 
432  scenario["experience_modifier"] = xp_mod_;
433  scenario["victory_when_enemies_defeated"] = victory_defeated_;
434  scenario["random_starting_time"] = random_time_;
435 
436  scenario.append(tod_manager_->to_config());
437  scenario.remove_attribute("turn_at");
438 
439  scenario["map_data"] = map_.write();
440 
441  labels_.write(scenario);
442 
443  overlay_map::const_iterator it;
444  for (it = overlays_.begin(); it != overlays_.end(); ++it) {
445 
446  config& item = scenario.add_child("item");
447  it->first.write(item);
448  item["image"] = it->second.image;
449  item["id"] = it->second.id;
450  item["halo"] = it->second.halo;
451  item["visible_in_fog"] = it->second.visible_in_fog;
452  item["name"] = it->second.name;
453  item["team_name"] = it->second.team_name;
454  }
455 
456  for(const music_map::value_type& track : music_tracks_) {
457  track.second.write(scenario, true);
458  }
459 
460  for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
461  int side_num = t - teams_.begin() + 1;
462 
463  config& side = scenario.add_child("side");
464 
465  side["side"] = side_num;
466  side["hidden"] = t->hidden();
467 
468  side["controller"] = t->controller();
469  side["no_leader"] = t->no_leader();
470 
471  side["team_name"] = t->team_name();
472  side["user_team_name"] = t->user_team_name();
473 
474  // TODO
475  // side["allow_player"] = "yes";
476 
477  side["fog"] = t->uses_fog();
478  side["shroud"] = t->uses_shroud();
479  side["share_vision"] = t->share_vision();
480 
481  side["gold"] = t->gold();
482  side["income"] = t->base_income();
483 
484  for(const map_location& village : t->villages()) {
485  village.write(side.add_child("village"));
486  }
487 
488  //current visible units
489  for(unit_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
490  if(i->side() == side_num) {
491  config& u = side.add_child("unit");
492  i->get_location().write(u);
493  u["type"] = i->type_id();
494  u["canrecruit"] = i->can_recruit();
495  u["unrenamable"] = i->unrenamable();
496  u["id"] = i->id();
497  u["name"] = i->name();
498  u["extra_recruit"] = utils::join(i->recruits());
499  u["facing"] = map_location::write_direction(i->facing());
500  }
501  }
502  }
503 
504  return scenario;
505 }
506 
508 {
509  assert(!is_embedded());
510 
511  if (scenario_id_.empty())
513  if (scenario_name_.empty())
515 
516  try {
517  std::stringstream wml_stream;
518  {
519  config_writer out(wml_stream, false);
520  out.write(to_config());
521  }
522  if (!wml_stream.str().empty())
523  filesystem::write_file(get_filename(), wml_stream.str());
524  clear_modified();
525  } catch (filesystem::io_exception& e) {
526  utils::string_map symbols;
527  symbols["msg"] = e.what();
528  const std::string msg = vgettext("Could not save the scenario: $msg", symbols);
529  throw editor_map_save_exception(msg);
530  }
531  // TODO the return value of this method does not need to be boolean.
532  // We either return true or there is an exception thrown.
533  return true;
534 }
535 
537 {
538  std::string map_data = map_.write();
539 
540  try {
541  if (!is_embedded()) {
543  } else {
545  boost::regex rexpression_map_data("(.*map_data\\s*=\\s*\")(.+?)(\".*)");
546  boost::smatch matched_map_data;
547  if (boost::regex_search(map_string, matched_map_data, rexpression_map_data,
548  boost::regex_constants::match_not_dot_null)) {
549  std::stringstream ss;
550  ss << matched_map_data[1];
551  ss << map_data;
552  ss << matched_map_data[3];
554  } else {
555  throw editor_map_save_exception(_("Could not save into scenario"));
556  }
557  }
559  clear_modified();
560  } catch (filesystem::io_exception& e) {
561  utils::string_map symbols;
562  symbols["msg"] = e.what();
563  const std::string msg = vgettext("Could not save the map: $msg", symbols);
564  throw editor_map_save_exception(msg);
565  }
566  //TODO the return value of this method does not need to be boolean.
567  //We either return true or there is an exception thrown.
568  return true;
569 }
570 
572 {
573  if (map_.h() != map.h() || map_.w() != map.w()) {
575  } else {
577  }
578  map_ = map;
579 }
580 
582 {
583  LOG_ED << "Performing action " << action.get_id() << ": " << action.get_name()
584  << ", actions count is " << action.get_instance_count() << std::endl;
585  editor_action* undo = action.perform(*this);
586  if (actions_since_save_ < 0) {
587  //set to a value that will make it impossible to get to zero, as at this point
588  //it is no longer possible to get back the original map state using undo/redo
589  actions_since_save_ = 1 + undo_stack_.size();
590  }
592  undo_stack_.push_back(undo);
595 }
596 
598 {
599  LOG_ED << "Performing (partial) action " << action.get_id() << ": " << action.get_name()
600  << ", actions count is " << action.get_instance_count() << std::endl;
601  if (!can_undo()) {
602  throw editor_logic_exception("Empty undo stack in perform_partial_action()");
603  }
604  editor_action_chain* undo_chain = dynamic_cast<editor_action_chain*>(last_undo_action());
605  if (undo_chain == nullptr) {
606  throw editor_logic_exception("Last undo action not a chain in perform_partial_action()");
607  }
608  editor_action* undo = action.perform(*this);
609  //actions_since_save_ += action.action_count();
610  undo_chain->prepend_action(undo);
612 }
613 
615 {
616  return actions_since_save_ != 0;
617 }
618 
620 {
622 }
623 
625 {
627 }
628 
630 {
631  return !undo_stack_.empty();
632 }
633 
635 {
636  return !redo_stack_.empty();
637 }
638 
640 {
641  return undo_stack_.empty() ? nullptr : undo_stack_.back();
642 }
643 
645 {
646  return redo_stack_.empty() ? nullptr : redo_stack_.back();
647 }
648 
650 {
651  return undo_stack_.empty() ? nullptr : undo_stack_.back();
652 }
653 
655 {
656  return redo_stack_.empty() ? nullptr : redo_stack_.back();
657 }
658 
660 {
661  LOG_ED << "undo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
662  if (can_undo()) {
665  } else {
666  WRN_ED << "undo() called with an empty undo stack" << std::endl;
667  }
668  LOG_ED << "undo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
669 }
670 
672 {
673  LOG_ED << "redo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
674  if (can_redo()) {
677  } else {
678  WRN_ED << "redo() called with an empty redo stack" << std::endl;
679  }
680  LOG_ED << "redo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
681 }
682 
684 {
685  //callers should check for these conditions
686  if (!can_undo()) {
687  throw editor_logic_exception("Empty undo stack in partial_undo()");
688  }
689  editor_action_chain* undo_chain = dynamic_cast<editor_action_chain*>(last_undo_action());
690  if (undo_chain == nullptr) {
691  throw editor_logic_exception("Last undo action not a chain in partial undo");
692  }
693  //a partial undo performs the first action form the current action's action_chain that would be normally performed
694  //i.e. the *first* one.
695  boost::scoped_ptr<editor_action> first_action_in_chain(undo_chain->pop_first_action());
696  if (undo_chain->empty()) {
698  delete undo_chain;
699  undo_stack_.pop_back();
700  }
701  redo_stack_.push_back(first_action_in_chain.get()->perform(*this));
702  //actions_since_save_ -= last_redo_action()->action_count();
703 }
704 
706 {
709 }
710 
712 {
713  if (stack.size() > max_action_stack_size_) {
714  delete stack.front();
715  stack.pop_front();
716  }
717 }
718 
720 {
721  for (editor_action* a : stack) {
722  delete a;
723  }
724  stack.clear();
725 }
726 
728 {
729  assert(!from.empty());
730  boost::scoped_ptr<editor_action> action(from.back());
731  from.pop_back();
732  editor_action* reverse_action = action->perform(*this);
733  to.push_back(reverse_action);
734  trim_stack(to);
735 }
736 
737 } //end namespace editor
void add_changed_location(const map_location &loc)
bool on_board_with_border(const map_location &loc) const
Definition: map.cpp:472
child_itors child_range(const std::string &key)
Definition: config.cpp:613
int actions_since_save_
Number of actions performed since the map was saved.
action_stack undo_stack_
The undo stack.
bool victory_defeated() const
editor_action * last_redo_action()
void remove_attribute(const std::string &key)
Definition: config.cpp:534
void undo()
Un-does the last action, and puts it in the redo stack for a possible redo.
virtual const gamemap & map() const
editor_map map_
The map object of this map_context.
::tod_manager * tod_manager
Definition: resources.cpp:31
void set_shroud(bool shroud)
Definition: team.hpp:323
unit_iterator end()
Definition: map.hpp:311
std::set< map_location > starting_position_label_locs_
Cache of set starting position labels.
void write(const config &cfg)
void write(config &res) const
Definition: label.cpp:70
int village_support
Definition: game_config.cpp:39
Definition: unit.hpp:95
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:566
void perform_action_between_stacks(action_stack &from, action_stack &to)
Perform an action at the back of one stack, and then move it to the back of the other stack...
const char * what() const
Definition: exceptions.hpp:35
std::set< map_location > set_starting_position_labels(display &disp)
Set labels for staring positions in the given display object.
Definition: editor_map.cpp:149
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
bool save_scenario()
Saves the scenario under the current filename.
variant map_
Definition: formula.cpp:306
virtual ~map_context()
Map context destructor.
bool modified() const
#define LOG_ED
unit_iterator begin()
Definition: map.hpp:308
bool everything_changed() const
void build(const config &cfg, const gamemap &map, int gold=default_team_gold_)
Definition: team.cpp:306
static int get_instance_count()
Debugging aid.
Definition: action_base.hpp:94
map_context(const editor_map &map, const display &disp, bool pure_map, const config &schedule)
Create a map context from an existing map.
Definition: map_context.cpp:44
void redo()
Re-does a previously undid action, and puts it back in the undo stack.
lg::log_domain log_editor
Container action wrapping several actions into one.
Definition: action.hpp:79
const std::string & get_filename() const
-file sdl_utils.hpp
void change_controller(const std::string &new_controller)
Definition: team.hpp:275
void set_share_vision(const std::string &vision_status)
Definition: team.hpp:390
void draw_terrain(const t_translation::t_terrain &terrain, const map_location &loc, bool one_layer_only=false)
Draw a terrain on a single location on the map.
void clear_stack(action_stack &stack)
Clears an action stack and deletes all its contents.
void set_hidden(bool value)
Definition: team.hpp:345
GLdouble GLdouble t
Definition: glew.h:1366
std::string scenario_description_
std::string scenario_name_
void set_needs_reload(bool value=true)
Setter for the reload flag.
void clear_modified()
Clear the modified state.
void partial_undo()
Un-does a single step from a undo action chain.
bool embedded_
Whether the map context refers to a map embedded in a scenario file.
void set_scenario_setup(const std::string &id, const std::string &name, const std::string &description, int turns, int xp_mod, bool victory_defeated, bool random_time)
TODO.
void remove_area(int index)
void set_map(const editor_map &map)
std::string filename_
Definition: action_wml.cpp:506
void set_side_setup(int side, const std::string &id, const std::string &name, int gold, int income, int village_gold, int village_support, bool fog, bool shroud, team::SHARE_VISION share_vision, team::CONTROLLER controller, bool hidden, bool no_leader)
TODO.
#define WRN_ED
bool pure_map_
Whether the map context refers to a file containing only the pure map data.
static const size_t max_action_stack_size_
Action stack (i.e.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:50
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
void have_leader(bool value=true)
Definition: team.hpp:343
std::map< std::string, t_string > string_map
GLuint id
Definition: glew.h:1647
std::vector< team > teams_
std::vector< team > * teams
Definition: resources.cpp:29
std::deque< editor_action * > action_stack
Container type used to store actions in the undo and redo stacks.
Class for writing a config out to a file in pieces.
void reset_starting_position_labels(display &disp)
void write_file(const std::string &fname, const std::string &data)
Throws io_exception if an error occurs.
std::string base_name(const std::string &file)
Returns the base filename of a file, with directory name stripped.
void draw_terrain_actual(const t_translation::t_terrain &terrain, const map_location &loc, bool one_layer_only=false)
Actual drawing function used by both overloaded variants of draw_terrain.
editor_action * pop_first_action()
Remove the first added action and return it, transferring ownership to the caller.
Definition: action.cpp:128
int w() const
Effective map width.
Definition: map.hpp:105
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
virtual const char * get_name() const
Definition: action_base.hpp:75
void replace_schedule(const std::vector< time_of_day > &schedule)
void add_to_recent_files()
Adds the map to the editor's recent files list.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
Editor action classes.
void set_starting_time(int time)
TODO.
config & add_child(const std::string &key)
Definition: config.cpp:743
bool save_map()
Saves the map under the current filename.
void set_village_support(int support)
Definition: team.hpp:206
#define log_scope2(domain, description)
Definition: log.hpp:186
map_display and display: classes which take care of displaying the map and game-data on the screen...
editor_action * last_undo_action()
Manage the empty-palette in the editor.
Definition: action.cpp:28
void perform_action(const editor_action &action)
Performs an action (thus modifying the map).
bool can_undo() const
static const ::config * terrain
The terrain used to create the cache.
Definition: minimap.cpp:135
void set_fog(bool fog)
Definition: team.hpp:324
std::pair< unit_iterator, bool > add(const map_location &l, const unit &u)
Adds a copy of unit u at location l of the map.
Definition: map.cpp:70
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
std::string scenario_id_
Encapsulates the map of the game.
Definition: location.hpp:38
void set_village_gold(int income)
Definition: team.hpp:199
const terrain_type & get_terrain_info(const t_translation::t_terrain &terrain) const
Definition: map.cpp:100
void perform_partial_action(const editor_action &action)
Performs a partial action, assumes that the top undo action has been modified to maintain coherent st...
static editor_map from_string(const config &terrain_cfg, const std::string &data)
Wrapper around editor_map(cfg, data) that catches possible exceptions and wraps them in a editor_map_...
Definition: editor_map.cpp:59
std::string write() const
Definition: map.cpp:247
void clear_changed_locations()
void set_starting_position_labels(display &disp)
bool can_redo() const
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:70
void set_gold(int amount)
Definition: team.hpp:211
int h() const
Effective map height.
Definition: map.hpp:108
std::string get_wml_location(const std::string &filename, const std::string &current_dir=std::string())
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
Game configuration data as global variables.
Definition: build_info.cpp:38
An exception object used when an IO error occurs.
Definition: filesystem.hpp:40
GLuint index
Definition: glew.h:1782
Base class for all editor actions.
Definition: action_base.hpp:41
Internal representation of music tracks.
void prepend_action(editor_action *a)
Add an action at the beginning of the chain.
Definition: action.cpp:116
size_t i
Definition: function.cpp:1057
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:112
void load_scenario(const config &game_config)
t_translation::t_terrain terrain_with_default_base() const
Definition: terrain.cpp:285
Declarations for File-IO.
overlay_map overlays_
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:400
void set_terrain(const map_location &loc, const t_translation::t_terrain &terrain, const terrain_type_data::tmerge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false)
Clobbers over the terrain at location 'loc', with the given terrain.
Definition: map.cpp:479
boost::shared_ptr< std::vector< unit_const_ptr > > units_
Definition: dialogs.cpp:100
const t_layer NO_LAYER
Definition: translation.hpp:38
action_stack redo_stack_
The redo stack.
std::string vgettext(const char *msgid, const utils::string_map &symbols)
GLuint const GLchar * name
Definition: glew.h:1782
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:341
void read(const config &cfg)
Definition: label.cpp:84
std::istream * preprocess_file(std::string const &fname, preproc_map *defines)
int get_id() const
Debugging aid.
Definition: action_base.hpp:89
boost::scoped_ptr< tod_manager > tod_manager_
void clear_undo_redo()
Clear the undo and redo stacks.
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
std::string message
Definition: exceptions.hpp:29
void replace_local_schedule(const std::vector< time_of_day > &schedule)
Replace the [time]s of the currently active area.
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
std::string filename_
The actual filename of this map.
void change_team(const std::string &name, const t_string &user_name)
Definition: team.cpp:534
void trim_stack(action_stack &stack)
Checks if an action stack reached its capacity and removes the front element if so.
map_labels & labels()
Definition: display.cpp:2773
#define e
void set_base_income(int amount)
Definition: team.hpp:214
void add_recent_files_entry(const std::string &path)
Adds an entry to the recent files list.
void clear_all()
Definition: label.cpp:246
std::set< map_location > changed_locations_
virtual editor_action * perform(map_context &) const
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action.cpp:60
void clear_starting_position_labels(display &disp)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool file_exists(const std::string &name)
Returns true if a file or directory with such name already exists.
static std::string write_direction(DIRECTION dir)
Definition: location.cpp:144
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool is_embedded() const
bool set_selection(const std::set< map_location > &area)
Select the given area.
Definition: editor_map.cpp:181
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
bool select_area(int index)
Select the nth tod area.