The Battle for Wesnoth  1.19.7+dev
action_wml.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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 vconfig;
33 
34 namespace game_events
35 {
36  struct queued_event;
37 
38 
39  // Most of the functionality in the source file is accessed via callbacks,
40  // accessed by iterating over wml_action.
41 
42  class wml_action {
43  public:
44  typedef void (*handler)(const queued_event &, const vconfig &);
45  typedef std::map<std::string, handler> map;
46 
47  /**
48  * Using this constructor for a static object outside action_wml.cpp
49  * will likely lead to a static initialization fiasco.
50  */
51  wml_action(const std::string & tag, handler function);
52 
53  /** The first registered action. */
54  static map::const_iterator begin() { return registry_.begin(); }
55  /** One past the last registered action. */
56  static map::const_iterator end() { return registry_.end(); }
57  static const map& registry() { return registry_; }
58  private:
59  /** Tracks the known action handlers. */
60  static map registry_;
61  };
62 }
void(* handler)(const queued_event &, const vconfig &)
Definition: action_wml.hpp:44
static map registry_
Tracks the known action handlers.
Definition: action_wml.hpp:60
static const map & registry()
Definition: action_wml.hpp:57
static map::const_iterator begin()
The first registered action.
Definition: action_wml.hpp:54
std::map< std::string, handler > map
Definition: action_wml.hpp:45
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:200
static map::const_iterator end()
One past the last registered action.
Definition: action_wml.hpp:56
A variable-expanding proxy for the config class.
Definition: variable.hpp:45
Domain specific events.
std::string tag(const std::string &tag_name, Args &&... contents)
Definition: markup.hpp:45