The Battle for Wesnoth  1.13.4+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 - 2016 by David White <[email protected]>
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 #ifndef GAME_EVENTS_ACTION_WML_H_INCLUDED
26 #define GAME_EVENTS_ACTION_WML_H_INCLUDED
27 
28 #include "terrain/type_data.hpp"
29 #include <map>
30 #include <string>
31 
32 class config;
33 struct map_location;
34 class vconfig;
35 
36 namespace t_translation {
37  struct t_terrain;
38 }
39 
40 
41 namespace game_events
42 {
43  struct queued_event;
44 
45 
46  // Most of the functionality in the source file is accessed via callbacks,
47  // accessed by iterating over wml_action.
48 
49  class wml_action {
50  public:
51  typedef void (*handler)(const queued_event &, const vconfig &);
52  typedef std::map<std::string, handler> map;
53 
54  /// Using this constructor for a static object outside action_wml.cpp
55  /// will likely lead to a static initialization fiasco.
56  wml_action(const std::string & tag, handler function);
57 
58  /// The first registered action.
59  static map::const_iterator begin() { return registry_.begin(); }
60  /// One past the last registered action.
61  static map::const_iterator end() { return registry_.end(); }
62  static const map& registry() { return registry_; }
63  private:
64  /// Tracks the known action handlers.
65  static map registry_;
66  };
67 
68 
69  /**
70  * Changes a terrain location.
71  * Ensures that villages are properly lost and that new terrains are discovered.
72  */
73  void change_terrain(const map_location &loc, const t_translation::t_terrain &t,
74  terrain_type_data::tmerge_mode mode, bool replace_if_failed);
75 }
76 
77 #endif // GAME_EVENTS_ACTION_WML_H_INCLUDED
78 
std::map< std::string, handler > map
Definition: action_wml.hpp:52
static map::const_iterator begin()
The first registered action.
Definition: action_wml.hpp:59
void(* handler)(const queued_event &, const vconfig &)
Definition: action_wml.hpp:51
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
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:215
GLenum mode
Definition: glew.h:2390
GLdouble GLdouble t
Definition: glew.h:1366
static map::const_iterator end()
One past the last registered action.
Definition: action_wml.hpp:61
void change_terrain(const map_location &loc, const t_translation::t_terrain &t, terrain_type_data::tmerge_mode mode, bool replace_if_failed)
Changes a terrain location.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:47
Encapsulates the map of the game.
Definition: location.hpp:38
Domain specific events.
Definition: action_wml.cpp:93
static map registry_
Tracks the known action handlers.
Definition: action_wml.hpp:65
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
static const map & registry()
Definition: action_wml.hpp:62
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503