The Battle for Wesnoth  1.15.0-dev
map_context.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
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 
17 
18 #include "display.hpp"
19 #include "editor/action/action.hpp"
20 #include "filesystem.hpp"
21 #include "formula/string_utils.hpp"
22 #include "gettext.hpp"
23 #include "map/exception.hpp"
24 #include "map/label.hpp"
25 #include "preferences/editor.hpp"
27 #include "serialization/parser.hpp"
28 #include "team.hpp"
29 #include "terrain/type_data.hpp"
30 #include "units/unit.hpp"
31 
32 #include <boost/regex.hpp>
33 
34 namespace editor
35 {
37  : side(t.side())
38  , id(t.team_name())
39  , name(t.user_team_name())
40  , gold(t.gold())
41  , income(t.base_income())
44  , fog(t.uses_fog())
45  , shroud(t.uses_shroud())
46  , share_vision(t.share_vision())
47  , controller(t.controller())
48  , no_leader(t.no_leader())
49  , hidden(t.hidden())
50 {
51 }
52 
53 const std::size_t map_context::max_action_stack_size_ = 100;
54 
55 map_context::map_context(const editor_map& map, bool pure_map, const config& schedule)
56  : filename_()
57  , map_data_key_()
58  , embedded_(false)
59  , pure_map_(pure_map)
60  , map_(map)
61  , undo_stack_()
62  , redo_stack_()
63  , actions_since_save_(0)
64  , starting_position_label_locs_()
65  , needs_reload_(false)
66  , needs_terrain_rebuild_(false)
67  , needs_labels_reset_(false)
68  , changed_locations_()
69  , everything_changed_(false)
70  , scenario_id_()
71  , scenario_name_()
72  , scenario_description_()
73  , xp_mod_(70)
74  , victory_defeated_(true)
75  , random_time_(false)
76  , active_area_(-1)
77  , labels_(nullptr)
78  , units_()
79  , teams_()
80  , tod_manager_(new tod_manager(schedule))
81  , mp_settings_()
82  , game_classification_()
83  , music_tracks_()
84 {
85 }
86 
87 map_context::map_context(const config& game_config, const std::string& filename)
88  : filename_(filename)
89  , map_data_key_()
90  , embedded_(false)
91  , pure_map_(false)
92  , map_(game_config)
93  , undo_stack_()
94  , redo_stack_()
97  , needs_reload_(false)
98  , needs_terrain_rebuild_(false)
99  , needs_labels_reset_(false)
101  , everything_changed_(false)
102  , scenario_id_()
103  , scenario_name_()
105  , xp_mod_(70)
106  , victory_defeated_(true)
107  , random_time_(false)
108  , active_area_(-1)
109  , labels_(nullptr)
110  , units_()
111  , teams_()
112  , tod_manager_(new tod_manager(game_config.find_child("editor_times", "id", "default")))
113  , mp_settings_()
115  , music_tracks_()
116 {
117  /*
118  * Overview of situations possibly found in the file:
119  *
120  * 0. Not a scenario or map file.
121  * 0.1 File not found
122  * 0.2 Map file empty
123  * 0.3 No valid data
124  * 1. It's a file containing only pure map data.
125  * * embedded_ = false
126  * * pure_map_ = true
127  * 2. A scenario embedding the map
128  * * embedded_ = true
129  * * pure_map_ = true
130  * The data/scenario-test.cfg for example.
131  * The map is written back to the file.
132  * 3. The map file is referenced by map_data={MACRO_ARGUEMENT}.
133  * * embedded_ = false
134  * * pure_map_ = true
135  * 4. The file contains an editor generated scenario file.
136  * * embedded_ = false
137  * * pure_map_ = false
138  */
139 
140  log_scope2(log_editor, "Loading file " + filename);
141 
142  // 0.1 File not found
143  if(!filesystem::file_exists(filename) || filesystem::is_directory(filename)) {
144  throw editor_map_load_exception(filename, _("File not found"));
145  }
146 
147  std::string file_string = filesystem::read_file(filename);
148 
149  // 0.2 Map file empty
150  if(file_string.empty()) {
151  std::string message = _("Empty file");
152  throw editor_map_load_exception(filename, message);
153  }
154 
155  // 1.0 Pure map data
156  boost::regex rexpression_map_data(R"""(map_data\s*=\s*"(.+?)")""");
157  boost::smatch matched_map_data;
158 
159  if(!boost::regex_search(
160  file_string, matched_map_data, rexpression_map_data, boost::regex_constants::match_not_dot_null)
161  ) {
162  map_ = editor_map::from_string(game_config, file_string); // throws on error
163  pure_map_ = true;
164 
166  return;
167  }
168 
169  // 2.0 Embedded map
170  const std::string& map_data = matched_map_data[1];
171 
172  boost::regex rexpression_macro(R"""(\{(.+?)\})""");
173  boost::smatch matched_macro;
174 
175  if(!boost::regex_search(map_data, matched_macro, rexpression_macro)) {
176  // We have a map_data string but no macro ---> embedded or scenario
177 
178  boost::regex rexpression_scenario(R"""(\[(scenario|test|multiplayer|tutorial)\])""");
179  if(!boost::regex_search(file_string, rexpression_scenario)) {
180  LOG_ED << "Loading generated scenario file" << std::endl;
181  // 4.0 editor generated scenario
182  try {
183  load_scenario(game_config);
184  } catch(const config::error& e) {
185  // We already caught and rethrew this exception in load_scenario
186  throw editor_map_load_exception("load_scenario", e.message);
187  }
188  } else {
189  LOG_ED << "Loading embedded map file" << std::endl;
190  embedded_ = true;
191  pure_map_ = true;
192  map_ = editor_map::from_string(game_config, map_data);
193  }
194 
196  return;
197  }
198 
199  // 3.0 Macro referenced pure map
200  const std::string& macro_argument = matched_macro[1];
201  LOG_ED << "Map looks like a scenario, trying {" << macro_argument << "}" << std::endl;
202 
203  std::string new_filename = filesystem::get_wml_location(macro_argument,
205 
206  if(new_filename.empty()) {
207  std::string message = _("The map file looks like a scenario, "
208  "but the map_data value does not point to an existing file")
209  + std::string("\n") + macro_argument;
210  throw editor_map_load_exception(filename, message);
211  }
212 
213  LOG_ED << "New filename is: " << new_filename << std::endl;
214 
215  filename_ = new_filename;
216  file_string = filesystem::read_file(filename_);
217  map_ = editor_map::from_string(game_config, file_string);
218  pure_map_ = true;
219 
221 }
222 
224 {
225  undo_stack_.clear();
226  redo_stack_.clear();
227 }
228 
230 {
231  teams_.emplace_back();
232 
233  config cfg;
234  cfg["side"] = teams_.size(); // side is 1-indexed, so we can just use size()
235  cfg["hidden"] = false;
236 
237  // TODO: build might be slight overkill here just to set the side...
238  teams_.back().build(cfg, map());
239 
241 }
242 
244 {
245  assert(teams_.size() >= static_cast<unsigned int>(info.side));
246 
247  team& t = teams_[info.side - 1];
248  // t.set_save_id(id);
249  // t.set_name(name);
250  t.change_team(info.id, info.name);
251  t.have_leader(!info.no_leader);
253  t.set_gold(info.gold);
254  t.set_base_income(info.income);
255  t.set_hidden(info.hidden);
256  t.set_fog(info.fog);
257  t.set_shroud(info.shroud);
261 
263 }
264 
265 void map_context::set_scenario_setup(const std::string& id,
266  const std::string& name,
267  const std::string& description,
268  int turns,
269  int xp_mod,
270  bool victory_defeated,
271  bool random_time)
272 {
273  scenario_id_ = id;
274  scenario_name_ = name;
275  scenario_description_ = description;
276  random_time_ = random_time;
278  tod_manager_->set_number_of_turns(turns);
279  xp_mod_ = xp_mod;
281 }
282 
284 {
285  tod_manager_->set_current_time(time);
286  if(!pure_map_) {
288  }
289 }
290 
292 {
293  tod_manager_->remove_time_area(index);
294  active_area_--;
296 }
297 
298 void map_context::replace_schedule(const std::vector<time_of_day>& schedule)
299 {
300  tod_manager_->replace_schedule(schedule);
301  if(!pure_map_) {
303  }
304 }
305 
306 void map_context::replace_local_schedule(const std::vector<time_of_day>& schedule)
307 {
308  tod_manager_->replace_local_schedule(schedule, active_area_);
309  if(!pure_map_) {
311  }
312 }
313 
315 {
316  config scenario;
317 
318  try {
319  read(scenario, *(preprocess_file(filename_)));
320  } catch(const config::error& e) {
321  LOG_ED << "Caught a config error while parsing file: '" << filename_ << "'\n" << e.message << std::endl;
322  throw;
323  }
324 
325  scenario_id_ = scenario["id"].str();
326  scenario_name_ = scenario["name"].str();
327  scenario_description_ = scenario["description"].str();
328 
329  xp_mod_ = scenario["experience_modifier"].to_int();
330 
331  victory_defeated_ = scenario["victory_when_enemies_defeated"].to_bool(true);
332  random_time_ = scenario["random_start_time"].to_bool(false);
333 
334  map_ = editor_map::from_string(game_config, scenario["map_data"]); // throws on error
335 
336  labels_.read(scenario);
337 
338  tod_manager_.reset(new tod_manager(scenario));
339  for(const config& time_area : scenario.child_range("time_area")) {
340  tod_manager_->add_time_area(map_, time_area);
341  }
342 
343  for(const config& item : scenario.child_range("item")) {
344  const map_location loc(item);
345  overlays_.emplace(loc, overlay(item));
346  }
347 
348  for(const config& music : scenario.child_range("music")) {
349  music_tracks_.emplace(music["name"], sound::music_track(music));
350  }
351 
352  int i = 1;
353  for(config& side : scenario.child_range("side")) {
354  teams_.emplace_back();
355 
356  side["side"] = i;
357  teams_.back().build(side, map_);
358 
359  for(config& a_unit : side.child_range("unit")) {
360  a_unit["side"] = i;
361 
362  units_.insert(unit::create(a_unit, true));
363  }
364 
365  ++i;
366  }
367 }
368 
370 {
371  return map_.set_selection(tod_manager_->get_area_by_index(index));
372 }
373 
374 void map_context::draw_terrain(const t_translation::terrain_code& terrain, const map_location& loc, bool one_layer_only)
375 {
376  t_translation::terrain_code full_terrain = one_layer_only
377  ? terrain
379 
380  draw_terrain_actual(full_terrain, loc, one_layer_only);
381 }
382 
384  const t_translation::terrain_code& terrain, const map_location& loc, bool one_layer_only)
385 {
386  if(!map_.on_board_with_border(loc)) {
387  // requests for painting off the map are ignored in set_terrain anyway,
388  // but ideally we should not have any
389  LOG_ED << "Attempted to draw terrain off the map (" << loc << ")\n";
390  return;
391  }
392 
393  t_translation::terrain_code old_terrain = map_.get_terrain(loc);
394 
395  if(terrain != old_terrain) {
396  if(terrain.base == t_translation::NO_LAYER) {
398  } else if(one_layer_only) {
400  } else {
401  map_.set_terrain(loc, terrain);
402  }
403 
405  }
406 }
407 
409  const t_translation::terrain_code& terrain, const std::set<map_location>& locs, bool one_layer_only)
410 {
411  t_translation::terrain_code full_terrain = one_layer_only
412  ? terrain
414 
415  for(const map_location& loc : locs) {
416  draw_terrain_actual(full_terrain, loc, one_layer_only);
417  }
418 }
419 
421 {
422  everything_changed_ = false;
423  changed_locations_.clear();
424 }
425 
427 {
428  if(!everything_changed()) {
429  changed_locations_.insert(loc);
430  }
431 }
432 
433 void map_context::add_changed_location(const std::set<map_location>& locs)
434 {
435  if(!everything_changed()) {
436  changed_locations_.insert(locs.begin(), locs.end());
437  }
438 }
439 
441 {
442  everything_changed_ = true;
443 }
444 
446 {
447  return everything_changed_;
448 }
449 
451 {
452  disp.labels().clear_all();
454 }
455 
457 {
458  std::set<map_location> new_label_locs = map_.set_starting_position_labels(disp);
459  starting_position_label_locs_.insert(new_label_locs.begin(), new_label_locs.end());
460 }
461 
463 {
466  set_needs_labels_reset(false);
467 }
468 
470 {
471  config scenario;
472 
473  scenario["id"] = scenario_id_;
474  scenario["name"] = t_string(scenario_name_);
475  scenario["description"] = scenario_description_;
476 
477  scenario["experience_modifier"] = xp_mod_;
478  scenario["victory_when_enemies_defeated"] = victory_defeated_;
479  scenario["random_start_time"] = random_time_;
480 
481  scenario.append(tod_manager_->to_config());
482  scenario.remove_attribute("turn_at");
483  scenario.remove_attribute("it_is_a_new_turn");
484  if(scenario["turns"].to_int() == -1) {
485  scenario.remove_attribute("turns");
486  }
487 
488  scenario["map_data"] = map_.write();
489 
490  labels_.write(scenario);
491 
492  for(const auto& overlay_pair : overlays_) {
493  config& item = scenario.add_child("item");
494 
495  // Write x,y location
496  overlay_pair.first.write(item);
497 
498  const overlay& o = overlay_pair.second;
499 
500  // These should always have a value
501  item["image"] = o.image;
502  item["visible_in_fog"] = o.visible_in_fog;
503 
504  // Optional keys
505  item["id"].write_if_not_empty(o.id);
506  item["name"].write_if_not_empty(o.name);
507  item["team_name"].write_if_not_empty(o.team_name);
508  item["halo"].write_if_not_empty(o.halo);
509  }
510 
511  for(const music_map::value_type& track : music_tracks_) {
512  track.second.write(scenario, true);
513  }
514 
515  for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
516  int side_num = t - teams_.begin() + 1;
517 
518  config& side = scenario.add_child("side");
519 
520  side["side"] = side_num;
521  side["hidden"] = t->hidden();
522 
523  side["controller"] = t->controller();
524  side["no_leader"] = t->no_leader();
525 
526  side["team_name"] = t->team_name();
527  side["user_team_name"].write_if_not_empty(t->user_team_name());
528 
529  // TODO
530  // side["allow_player"] = true;
531 
532  side["fog"] = t->uses_fog();
533  side["shroud"] = t->uses_shroud();
534  side["share_vision"] = t->share_vision();
535 
536  side["gold"] = t->gold();
537  side["income"] = t->base_income();
538 
539  for(const map_location& village : t->villages()) {
540  village.write(side.add_child("village"));
541  }
542 
543  // current visible units
544  for(unit_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
545  if(i->side() == side_num) {
546  config& u = side.add_child("unit");
547 
548  i->get_location().write(u);
549 
550  u["type"] = i->type_id();
551  u["name"].write_if_not_empty(i->name());
552  u["facing"] = map_location::write_direction(i->facing());
553 
554  if(!boost::regex_match(i->id(), boost::regex(".*-[0-9]+"))) {
555  u["id"] = i->id();
556  }
557 
558  if(i->can_recruit()) {
559  u["canrecruit"] = i->can_recruit();
560  }
561 
562  if(i->unrenamable()) {
563  u["unrenamable"] = i->unrenamable();
564  }
565 
566  if(!i->recruits().empty()) {
567  u["extra_recruit"] = utils::join(i->recruits());
568  }
569  }
570  }
571  }
572 
573  return scenario;
574 }
575 
577 {
578  assert(!is_embedded());
579 
580  if(scenario_id_.empty()) {
582  }
583 
584  if(scenario_name_.empty()) {
586  }
587 
588  try {
589  std::stringstream wml_stream;
590  {
591  config_writer out(wml_stream, false);
592  out.write(to_config());
593  }
594 
595  if(!wml_stream.str().empty()) {
596  filesystem::write_file(get_filename(), wml_stream.str());
597  }
598 
599  clear_modified();
600  } catch(const filesystem::io_exception& e) {
601  utils::string_map symbols;
602  symbols["msg"] = e.what();
603  const std::string msg = VGETTEXT("Could not save the scenario: $msg", symbols);
604 
605  throw editor_map_save_exception(msg);
606  }
607 
608  // TODO the return value of this method does not need to be boolean.
609  // We either return true or there is an exception thrown.
610  return true;
611 }
612 
614 {
615  std::string map_data = map_.write();
616 
617  try {
618  if(!is_embedded()) {
620  } else {
621  std::string map_string = filesystem::read_file(get_filename());
622 
623  boost::regex rexpression_map_data(R"""((.*map_data\s*=\s*")(.+?)(".*))""");
624  boost::smatch matched_map_data;
625 
626  if(boost::regex_search(map_string, matched_map_data, rexpression_map_data,
627  boost::regex_constants::match_not_dot_null)) {
628  std::stringstream ss;
629  ss << matched_map_data[1];
630  ss << map_data;
631  ss << matched_map_data[3];
632 
634  } else {
635  throw editor_map_save_exception(_("Could not save into scenario"));
636  }
637  }
638 
640 
641  clear_modified();
642  } catch(const filesystem::io_exception& e) {
643  utils::string_map symbols;
644  symbols["msg"] = e.what();
645  const std::string msg = VGETTEXT("Could not save the map: $msg", symbols);
646 
647  throw editor_map_save_exception(msg);
648  }
649 
650  // TODO the return value of this method does not need to be boolean.
651  // We either return true or there is an exception thrown.
652  return true;
653 }
654 
656 {
657  if(map_.h() != map.h() || map_.w() != map.w()) {
659  } else {
661  }
662 
663  map_ = map;
664 }
665 
667 {
668  LOG_ED << "Performing action " << action.get_id() << ": " << action.get_name() << ", actions count is "
669  << action.get_instance_count() << std::endl;
670  editor_action* undo = action.perform(*this);
671  if(actions_since_save_ < 0) {
672  // set to a value that will make it impossible to get to zero, as at this point
673  // it is no longer possible to get back the original map state using undo/redo
674  actions_since_save_ = 1 + undo_stack_.size();
675  }
676 
678 
679  undo_stack_.emplace_back(undo);
680 
682 
683  redo_stack_.clear();
684 }
685 
687 {
688  LOG_ED << "Performing (partial) action " << action.get_id() << ": " << action.get_name() << ", actions count is "
689  << action.get_instance_count() << std::endl;
690  if(!can_undo()) {
691  throw editor_logic_exception("Empty undo stack in perform_partial_action()");
692  }
693 
694  editor_action_chain* undo_chain = dynamic_cast<editor_action_chain*>(last_undo_action());
695  if(undo_chain == nullptr) {
696  throw editor_logic_exception("Last undo action not a chain in perform_partial_action()");
697  }
698 
699  editor_action* undo = action.perform(*this);
700 
701  // actions_since_save_ += action.action_count();
702  undo_chain->prepend_action(undo);
703 
704  redo_stack_.clear();
705 }
706 
708 {
709  return actions_since_save_ != 0;
710 }
711 
713 {
715 }
716 
718 {
720 }
721 
723 {
724  return !undo_stack_.empty();
725 }
726 
728 {
729  return !redo_stack_.empty();
730 }
731 
733 {
734  return undo_stack_.empty() ? nullptr : undo_stack_.back().get();
735 }
736 
738 {
739  return redo_stack_.empty() ? nullptr : redo_stack_.back().get();
740 }
741 
743 {
744  return undo_stack_.empty() ? nullptr : undo_stack_.back().get();
745 }
746 
748 {
749  return redo_stack_.empty() ? nullptr : redo_stack_.back().get();
750 }
751 
753 {
754  LOG_ED << "undo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
755 
756  if(can_undo()) {
759  } else {
760  WRN_ED << "undo() called with an empty undo stack" << std::endl;
761  }
762 
763  LOG_ED << "undo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
764 }
765 
767 {
768  LOG_ED << "redo() beg, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
769 
770  if(can_redo()) {
773  } else {
774  WRN_ED << "redo() called with an empty redo stack" << std::endl;
775  }
776 
777  LOG_ED << "redo() end, undo stack is " << undo_stack_.size() << ", redo stack " << redo_stack_.size() << std::endl;
778 }
779 
781 {
782  // callers should check for these conditions
783  if(!can_undo()) {
784  throw editor_logic_exception("Empty undo stack in partial_undo()");
785  }
786 
787  editor_action_chain* undo_chain = dynamic_cast<editor_action_chain*>(last_undo_action());
788  if(undo_chain == nullptr) {
789  throw editor_logic_exception("Last undo action not a chain in partial undo");
790  }
791 
792  // a partial undo performs the first action form the current action's action_chain that would be normally performed
793  // i.e. the *first* one.
794  const editor_action_ptr first_action_in_chain(undo_chain->pop_first_action());
795  if(undo_chain->empty()) {
797  undo_stack_.pop_back();
798  }
799 
800  redo_stack_.emplace_back(first_action_in_chain->perform(*this));
801  // actions_since_save_ -= last_redo_action()->action_count();
802 }
803 
805 {
806  undo_stack_.clear();
807  redo_stack_.clear();
808 }
809 
811 {
812  if(stack.size() > max_action_stack_size_) {
813  stack.pop_front();
814  }
815 }
816 
818 {
819  assert(!from.empty());
820 
821  editor_action_ptr action(nullptr);
822  action.swap(from.back());
823 
824  from.pop_back();
825 
826  editor_action* reverse_action = action->perform(*this);
827  to.emplace_back(reverse_action);
828 
829  trim_stack(to);
830 }
831 
833 {
834  return is_pure_map() ? _("New Map") : _("New Scenario");
835 }
836 
837 } // end namespace editor
void add_changed_location(const map_location &loc)
void set_side_setup(editor_team_info &info)
TODO.
int actions_since_save_
Number of actions performed since the map was saved.
action_stack undo_stack_
The undo stack.
std::string map_data_key_
When a scenario file is loaded, the referenced map is loaded instead.
editor_action * last_redo_action()
void undo()
Un-does the last action, and puts it in the redo stack for a possible redo.
editor_map map_
The map object of this map_context.
::tod_manager * tod_manager
Definition: resources.cpp:29
int h() const
Effective map height.
Definition: map.hpp:93
void set_shroud(bool shroud)
Definition: team.hpp:322
game_classification game_classification_
unit_iterator end()
Definition: map.hpp:415
std::set< map_location > starting_position_label_locs_
Cache of set starting position labels.
bool needs_terrain_rebuild_
Refresh flag indicating the terrain in the map has changed and requires a rebuild.
void write(const config &cfg)
std::map< std::string, t_string > string_map
int village_support
Definition: game_config.cpp:55
std::unique_ptr< editor_action > editor_action_ptr
Action pointer typedef.
void append(const config &cfg)
Append data from another config object to this one.
Definition: config.cpp:291
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...
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
bool visible_in_fog
Definition: overlay.hpp:43
team::SHARE_VISION share_vision
Definition: map_context.hpp:42
std::set< map_location > set_starting_position_labels(display &disp)
Set labels for staring positions in the given display object.
Definition: editor_map.cpp:138
umap_retval_pair_t insert(unit_ptr p)
Inserts the unit pointed to by p into the map.
Definition: map.cpp:135
virtual const std::string & get_name() const
Definition: action_base.hpp:74
void new_side()
Adds a new side to the map.
static bool file_exists(const fs::path &fpath)
Definition: filesystem.cpp:300
bool save_scenario()
Saves the scenario under the current filename.
logger & info()
Definition: log.cpp:90
virtual ~map_context()
Map context destructor.
const std::string & get_filename() const
child_itors child_range(config_key_type key)
Definition: config.cpp:366
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:63
#define LOG_ED
bool needs_reload_
Refresh flag indicating the map in this context should be completely reloaded by the display...
void draw_terrain(const t_translation::terrain_code &terrain, const map_location &loc, bool one_layer_only=false)
Draw a terrain on a single location on the map.
unit_iterator begin()
Definition: map.hpp:405
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:49
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
Definition: map.cpp:96
static int get_instance_count()
Debugging aid.
const ter_layer NO_LAYER
Definition: translation.hpp:40
void redo()
Re-does a previously undid action, and puts it back in the undo stack.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Definition: debugger.cpp:109
lg::log_domain log_editor
Container action wrapping several actions into one.
Definition: action.hpp:90
-file sdl_utils.hpp
void change_controller(const std::string &new_controller)
Definition: team.hpp:272
void set_share_vision(const std::string &vision_status)
Definition: team.hpp:390
std::deque< editor_action_ptr > action_stack
Action stack typedef.
void set_hidden(bool value)
Definition: team.hpp:344
void remove_attribute(config_key_type key)
Definition: config.cpp:239
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.
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
Definition: unit.hpp:122
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)
t_translation::terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:299
void set_terrain(const map_location &loc, const t_translation::terrain_code &terrain, const terrain_type_data::merge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false)
Clobbers over the terrain at location &#39;loc&#39;, with the given terrain.
Definition: map.cpp:379
void set_map(const editor_map &map)
std::string filename_
Definition: action_wml.cpp:555
bool modified() const
std::string id
Definition: overlay.hpp:40
#define WRN_ED
bool fog()
Definition: game.cpp:539
bool pure_map_
Whether the map context refers to a file containing only the pure map data.
std::string write() const
Definition: map.cpp:204
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
void have_leader(bool value=true)
Definition: team.hpp:342
std::unique_ptr< tod_manager > tod_manager_
std::vector< team > teams_
editor_team_info(const team &t)
Definition: map_context.cpp:36
bool on_board_with_border(const map_location &loc) const
Definition: map.cpp:372
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:612
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.
Definition: filesystem.cpp:955
int get_id() const
Debugging aid.
Definition: action_base.hpp:92
editor_action * pop_first_action()
Remove the first added action and return it, transferring ownership to the caller.
Definition: action.cpp:151
void replace_schedule(const std::vector< time_of_day > &schedule)
t_string name
Definition: overlay.hpp:39
void add_to_recent_files()
Adds the map to the editor&#39;s recent files list.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
Definition: filesystem.cpp:984
void write(config &res) const
Definition: label.cpp:79
Editor action classes.
void set_starting_time(int time)
TODO.
bool save_map()
Saves the map under the current filename.
void set_village_support(int support)
Definition: team.hpp:200
std::string get_short_wml_path(const std::string &filename)
Returns a short path to filename, skipping the (user) data directory.
#define log_scope2(domain, description)
Definition: log.hpp:187
map_display and display: classes which take care of displaying the map and game-data on the screen...
editor_action * last_undo_action()
bool is_pure_map() const
int village_gold()
Definition: game.cpp:669
Manage the empty-palette in the editor.
Definition: action.cpp:29
void perform_action(const editor_action &action)
Performs an action (thus modifying the map).
const char * what() const noexcept
Definition: exceptions.hpp:37
void set_fog(bool fog)
Definition: team.hpp:323
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
Definition: filesystem.cpp:886
bool can_redo() const
bool is_embedded() const
void set_needs_terrain_rebuild(bool value=true)
Setter for the terrain rebuild flag.
bool needs_labels_reset_
Refresh flag indicating the labels in the map have changed.
std::string scenario_id_
Encapsulates the map of the game.
Definition: location.hpp:42
void set_village_gold(int income)
Definition: team.hpp:193
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:55
void clear_changed_locations()
bool shroud()
Definition: game.cpp:549
void set_starting_position_labels(display &disp)
int w() const
Effective map width.
Definition: map.hpp:90
This class adds extra editor-specific functionality to a normal gamemap.
Definition: editor_map.hpp:69
std::size_t i
Definition: function.cpp:933
void set_gold(int amount)
Definition: team.hpp:205
std::string get_wml_location(const std::string &filename, const std::string &current_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn&#39;t pres...
Game configuration data as global variables.
Definition: build_info.cpp:46
map_context(const map_context &)=delete
int village_income
Definition: game_config.cpp:54
t_translation::terrain_code terrain_with_default_base() const
Definition: terrain.cpp:285
An exception object used when an IO error occurs.
Definition: filesystem.hpp:48
Base class for all editor actions.
Definition: action_base.hpp:40
Internal representation of music tracks.
void prepend_action(editor_action *a)
Add an action at the beginning of the chain.
Definition: action.cpp:130
void draw_terrain_actual(const t_translation::terrain_code &terrain, const map_location &loc, bool one_layer_only=false)
Actual drawing function used by both overloaded variants of draw_terrain.
void load_scenario(const config &game_config)
Declarations for File-IO.
overlay_map overlays_
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
#define VGETTEXT(msgid,...)
config & add_child(config_key_type key)
Definition: config.cpp:479
action_stack redo_stack_
The redo stack.
bool can_undo() const
std::string base_name(const std::string &file, const bool remove_extension)
Returns the base filename of a file, with directory name stripped.
std::string halo
Definition: overlay.hpp:37
bool victory_defeated() const
void read(const config &cfg)
Definition: label.cpp:91
int turns()
Definition: game.cpp:559
double t
Definition: astarsearch.cpp:63
virtual const editor_map & map() const override
Const map accessor.
team::CONTROLLER controller
Definition: map_context.hpp:43
void clear_undo_redo()
Clear the undo and redo stacks.
void set_needs_labels_reset(bool value=true)
Setter for the labels reset flag.
static const std::size_t max_action_stack_size_
Action stack (i.e.
std::string message
Definition: exceptions.hpp:31
void replace_local_schedule(const std::vector< time_of_day > &schedule)
Replace the [time]s of the currently active area.
std::string filename_
The actual filename of this map.
void change_team(const std::string &name, const t_string &user_name)
Definition: team.cpp:598
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:1407
#define e
void set_base_income(int amount)
Definition: team.hpp:208
void add_recent_files_entry(const std::string &path)
Adds an entry to the recent files list.
Definition: editor.cpp:123
void clear_all()
Definition: label.cpp:239
std::set< map_location > changed_locations_
std::string team_name
Definition: overlay.hpp:38
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:68
filesystem::scoped_istream preprocess_file(const std::string &fname, preproc_map *defines)
static std::string write_direction(DIRECTION dir)
Definition: location.cpp:139
mp_game_settings mp_settings_
bool set_selection(const std::set< map_location > &area)
Select the given area.
Definition: editor_map.cpp:170
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
const t_string get_default_context_name() const
bool select_area(int index)
Select the nth tod area.
std::string image
Definition: overlay.hpp:36
bool everything_changed() const