The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
action_wml.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
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  * Define actions for the game's events mechanism.
18  *
19  * Events might be units moving or fighting, or when victory or defeat occurs.
20  * A scenario's configuration file will define actions to take when certain events occur.
21  * This module is responsible for implementing some of those actions (i.e. Action WML).
22  * The actions not implemented in this module are implemented in Lua.
23  */
24 
25 #pragma once
26 
27 #include "terrain/type_data.hpp"
28 #include <map>
29 #include <string>
30 
31 class config;
32 struct map_location;
33 class vconfig;
34 
35 namespace t_translation {
36  struct terrain_code;
37 }
38 
39 
40 namespace game_events
41 {
42  struct queued_event;
43 
44 
45  // Most of the functionality in the source file is accessed via callbacks,
46  // accessed by iterating over wml_action.
47 
48  class wml_action {
49  public:
50  typedef void (*handler)(const queued_event &, const vconfig &);
51  typedef std::map<std::string, handler> map;
52 
53  /// Using this constructor for a static object outside action_wml.cpp
54  /// will likely lead to a static initialization fiasco.
55  wml_action(const std::string & tag, handler function);
56 
57  /// The first registered action.
58  static map::const_iterator begin() { return registry_.begin(); }
59  /// One past the last registered action.
60  static map::const_iterator end() { return registry_.end(); }
61  static const map& registry() { return registry_; }
62  private:
63  /// Tracks the known action handlers.
64  static map registry_;
65  };
66 
67 
68  /**
69  * Changes a terrain location.
70  * Ensures that villages are properly lost and that new terrains are discovered.
71  */
73  terrain_type_data::merge_mode mode, bool replace_if_failed);
74 }
std::map< std::string, handler > map
Definition: action_wml.hpp:51
static map::const_iterator begin()
The first registered action.
Definition: action_wml.hpp:58
std::vector< char_t > string
void(* handler)(const queued_event &, const vconfig &)
Definition: action_wml.hpp:50
wml_action(const std::string &tag, handler function)
Using this constructor for a static object outside action_wml.cpp will likely lead to a static initia...
Definition: action_wml.cpp:217
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:55
static map::const_iterator end()
One past the last registered action.
Definition: action_wml.hpp:60
Encapsulates the map of the game.
Definition: location.hpp:40
Domain specific events.
Definition: action_wml.cpp:88
static map registry_
Tracks the known action handlers.
Definition: action_wml.hpp:64
double t
Definition: astarsearch.cpp:64
A variable-expanding proxy for the config class.
Definition: variable.hpp:42
void change_terrain(const map_location &loc, const t_translation::terrain_code &t, terrain_type_data::merge_mode mode, bool replace_if_failed)
Changes a terrain location.
static const map & registry()
Definition: action_wml.hpp:61
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93