The Battle for Wesnoth  1.17.0-dev
action_wml.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Define actions for the game's events mechanism.
19  *
20  * Events might be units moving or fighting, or when victory or defeat occurs.
21  * A scenario's configuration file will define actions to take when certain events occur.
22  * This module is responsible for implementing some of those actions (i.e. Action WML).
23  * The actions not implemented in this module are implemented in Lua.
24  */
25 
26 #pragma once
27 
28 #include "terrain/type_data.hpp"
29 #include <map>
30 #include <string>
31 
32 class config;
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  /**
54  * Using this constructor for a static object outside action_wml.cpp
55  * will likely lead to a static initialization fiasco.
56  */
57  wml_action(const std::string & tag, handler function);
58 
59  /** The first registered action. */
60  static map::const_iterator begin() { return registry_.begin(); }
61  /** One past the last registered action. */
62  static map::const_iterator end() { return registry_.end(); }
63  static const map& registry() { return registry_; }
64  private:
65  /** Tracks the known action handlers. */
66  static map registry_;
67  };
68 }
std::map< std::string, handler > map
Definition: action_wml.hpp:51
static map::const_iterator begin()
The first registered action.
Definition: action_wml.hpp:60
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
static map::const_iterator end()
One past the last registered action.
Definition: action_wml.hpp:62
Domain specific events.
Definition: action_wml.cpp:87
static map registry_
Tracks the known action handlers.
Definition: action_wml.hpp:66
A variable-expanding proxy for the config class.
Definition: variable.hpp:44
static const map & registry()
Definition: action_wml.hpp:63
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61