The Battle for Wesnoth  1.17.0-dev
handlers.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 the handlers 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 tracking these definitions.
23  */
24 
25 #pragma once
26 
27 #include "config.hpp"
28 
29 #include <string>
30 
31 class game_data;
32 class game_lua_kernel;
33 
34 namespace game_events
35 {
36 struct queued_event;
37 
39 {
40 public:
41  event_handler(config&& cfg, bool is_menu_item, const std::vector<std::string>& types);
42 
43  const std::vector<std::string>& names() const
44  {
45  return types_;
46  }
47 
48  bool disabled() const
49  {
50  return disabled_;
51  }
52 
53  bool is_menu_item() const
54  {
55  return is_menu_item_;
56  }
57 
58  /** Flag this handler as disabled. */
59  void disable();
60 
61  /**
62  * Handles the queued event, according to our WML instructions.
63  *
64  * @param[in] event_info Information about the event that needs handling.
65  * @param[in] lk The lua kernel to run the WML command.
66  */
67  void handle_event(const queued_event& event_info, game_lua_kernel& lk);
68 
69  const config& get_config() const
70  {
71  return cfg_;
72  }
73 
74 private:
77  bool disabled_;
79  std::vector<std::string> types_;
80 };
81 
82 }
void handle_event(const queued_event &event_info, game_lua_kernel &lk)
Handles the queued event, according to our WML instructions.
Definition: handlers.cpp:60
event_handler(config &&cfg, bool is_menu_item, const std::vector< std::string > &types)
Definition: handlers.cpp:45
Definitions for the interface to Wesnoth Markup Language (WML).
const config & get_config() const
Definition: handlers.hpp:69
Domain specific events.
Definition: action_wml.cpp:87
void disable()
Flag this handler as disabled.
Definition: handlers.cpp:54
const std::vector< std::string > & names() const
Definition: handlers.hpp:43
std::vector< std::string > types_
Definition: handlers.hpp:79
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
bool is_menu_item() const
Definition: handlers.hpp:53