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 class vconfig;
33 
34 namespace t_translation {
35  struct terrain_code;
36 }
37 
38 
39 namespace game_events
40 {
41  struct queued_event;
42 
43 
44  // Most of the functionality in the source file is accessed via callbacks,
45  // accessed by iterating over wml_action.
46 
47  class wml_action {
48  public:
49  typedef void (*handler)(const queued_event &, const vconfig &);
50  typedef std::map<std::string, handler> map;
51 
52  /// Using this constructor for a static object outside action_wml.cpp
53  /// will likely lead to a static initialization fiasco.
54  wml_action(const std::string & tag, handler function);
55 
56  /// The first registered action.
57  static map::const_iterator begin() { return registry_.begin(); }
58  /// One past the last registered action.
59  static map::const_iterator end() { return registry_.end(); }
60  static const map& registry() { return registry_; }
61  private:
62  /// Tracks the known action handlers.
63  static map registry_;
64  };
65 }
std::map< std::string, handler > map
Definition: action_wml.hpp:50
static map::const_iterator begin()
The first registered action.
Definition: action_wml.hpp:57
std::vector< char_t > string
void(* handler)(const queued_event &, const vconfig &)
Definition: action_wml.hpp:49
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:59
Domain specific events.
Definition: action_wml.cpp:88
static map registry_
Tracks the known action handlers.
Definition: action_wml.hpp:63
A variable-expanding proxy for the config class.
Definition: variable.hpp:42
static const map & registry()
Definition: action_wml.hpp:60
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93