14 #define GETTEXT_DOMAIN "wesnoth-editor"
37 #include <boost/regex.hpp>
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)
61 , scenario_description_()
63 , victory_defeated_(true)
66 , labels_(disp, nullptr)
71 , game_classification_()
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)
93 , scenario_description_()
95 , victory_defeated_(true)
98 , labels_(disp, nullptr)
101 , tod_manager_(new
tod_manager(game_config.find_child(
"editor_times",
"id",
"default")))
103 , game_classification_()
138 if (file_string.empty()) {
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)) {
157 boost::regex rexpression_macro(
"\\{(.+?)\\}");
158 boost::smatch matched_macro;
159 if (!boost::regex_search(map_data, matched_macro, rexpression_macro)) {
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;
172 LOG_ED <<
"Loading embedded map file" << std::endl;
183 const std::string& macro_argument = matched_macro[1];
184 LOG_ED <<
"Map looks like a scenario, trying {" << macro_argument <<
"}" << std::endl;
187 if (new_filename.empty()) {
189 "but the map_data value does not point to an existing file")
193 LOG_ED <<
"New filename is: " << new_filename << std::endl;
204 bool fog,
bool shroud, team::SHARE_VISION share_vision,
205 team::CONTROLLER
controller,
bool hidden,
bool no_leader)
207 assert(
teams_.size() >
static_cast<unsigned int>(side));
226 int turns,
int xp_mod,
bool victory_defeated,
bool random_time)
281 xp_mod_ = scenario[
"experience_modifier"].to_int();
284 random_time_ = scenario[
"random_start_time"].to_bool(
false);
350 LOG_ED <<
"Attempted to draw terrain off the map (" << loc <<
")\n";
354 if (terrain != old_terrain) {
357 }
else if (one_layer_only) {
367 const std::set<map_location>& locs,
bool one_layer_only)
432 scenario[
"experience_modifier"] =
xp_mod_;
443 overlay_map::const_iterator it;
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;
457 track.second.write(scenario,
true);
460 for(std::vector<team>::const_iterator
t =
teams_.begin();
t !=
teams_.end(); ++
t) {
461 int side_num =
t -
teams_.begin() + 1;
465 side[
"side"] = side_num;
466 side[
"hidden"] =
t->hidden();
468 side[
"controller"] =
t->controller();
469 side[
"no_leader"] =
t->no_leader();
471 side[
"team_name"] =
t->team_name();
472 side[
"user_team_name"] =
t->user_team_name();
477 side[
"fog"] =
t->uses_fog();
478 side[
"shroud"] =
t->uses_shroud();
479 side[
"share_vision"] =
t->share_vision();
481 side[
"gold"] =
t->gold();
482 side[
"income"] =
t->base_income();
485 village.write(side.
add_child(
"village"));
490 if(
i->side() == side_num) {
492 i->get_location().write(u);
493 u[
"type"] =
i->type_id();
494 u[
"canrecruit"] =
i->can_recruit();
495 u[
"unrenamable"] =
i->unrenamable();
497 u[
"name"] =
i->name();
517 std::stringstream wml_stream;
522 if (!wml_stream.str().empty())
527 symbols[
"msg"] = e.
what();
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];
552 ss << matched_map_data[3];
562 symbols[
"msg"] = e.
what();
605 if (undo_chain ==
nullptr) {
666 WRN_ED <<
"undo() called with an empty undo stack" << std::endl;
678 WRN_ED <<
"redo() called with an empty redo stack" << std::endl;
690 if (undo_chain ==
nullptr) {
695 boost::scoped_ptr<editor_action> first_action_in_chain(undo_chain->
pop_first_action());
696 if (undo_chain->
empty()) {
701 redo_stack_.push_back(first_action_in_chain.get()->perform(*
this));
714 delete stack.front();
729 assert(!from.empty());
730 boost::scoped_ptr<editor_action> action(from.back());
733 to.push_back(reverse_action);
void add_changed_location(const map_location &loc)
bool on_board_with_border(const map_location &loc) const
child_itors child_range(const std::string &key)
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)
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
void set_shroud(bool shroud)
std::set< map_location > starting_position_label_locs_
Cache of set starting position labels.
void write(const config &cfg)
void write(config &res) const
void append(const config &cfg)
Append data from another config object to this one.
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
std::set< map_location > set_starting_position_labels(display &disp)
Set labels for staring positions in the given display object.
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.
virtual ~map_context()
Map context destructor.
bool everything_changed() const
void build(const config &cfg, const gamemap &map, int gold=default_team_gold_)
static int get_instance_count()
Debugging aid.
map_context(const editor_map &map, const display &disp, bool pure_map, const config &schedule)
Create a map context from an existing map.
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.
const std::string & get_filename() const
void change_controller(const std::string &new_controller)
void set_share_vision(const std::string &vision_status)
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)
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)
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.
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).
static UNUSEDNOWARN std::string _(const char *str)
void have_leader(bool value=true)
std::map< std::string, t_string > string_map
std::vector< team > teams_
std::vector< team > * teams
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.
int w() const
Effective map width.
GLboolean GLboolean GLboolean GLboolean a
virtual const char * get_name() const
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.
void set_starting_time(int time)
TODO.
config & add_child(const std::string &key)
bool save_map()
Saves the map under the current filename.
void set_village_support(int support)
#define log_scope2(domain, description)
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.
void perform_action(const editor_action &action)
Performs an action (thus modifying the map).
static const ::config * terrain
The terrain used to create the cache.
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.
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...
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.
Encapsulates the map of the game.
void set_village_gold(int income)
const terrain_type & get_terrain_info(const t_translation::t_terrain &terrain) const
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_...
std::string write() const
void clear_changed_locations()
void set_starting_position_labels(display &disp)
void set_everything_changed()
This class adds extra editor-specific functionality to a normal gamemap.
void set_gold(int amount)
int h() const
Effective map height.
std::string get_wml_location(const std::string &filename, const std::string ¤t_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.
An exception object used when an IO error occurs.
Base class for all editor actions.
Internal representation of music tracks.
void prepend_action(editor_action *a)
Add an action at the beginning of the chain.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void load_scenario(const config &game_config)
t_translation::t_terrain terrain_with_default_base() const
Declarations for File-IO.
void read(config &cfg, std::istream &in, abstract_validator *validator)
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.
boost::shared_ptr< std::vector< unit_const_ptr > > units_
action_stack redo_stack_
The redo stack.
GLuint const GLchar * name
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
void read(const config &cfg)
std::istream * preprocess_file(std::string const &fname, preproc_map *defines)
int get_id() const
Debugging aid.
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.
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
std::string filename_
The actual filename of this map.
void change_team(const std::string &name, const t_string &user_name)
void trim_stack(action_stack &stack)
Checks if an action stack reached its capacity and removes the front element if so.
void set_base_income(int amount)
void add_recent_files_entry(const std::string &path)
Adds an entry to the recent files list.
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 ...
void clear_starting_position_labels(display &disp)
A config object defines a single node in a WML file, with access to child nodes.
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)
GLsizei const GLcharARB ** string
bool set_selection(const std::set< map_location > &area)
Select the given area.
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.