game_events.hpp

Go to the documentation of this file.
00001 /* $Id: game_events.hpp 25333 2008-03-30 13:49:03Z jhinrichs $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 #ifndef GAME_EVENTS_H_INCLUDED
00015 #define GAME_EVENTS_H_INCLUDED
00016 
00017 #include "config.hpp"
00018 #include "map.hpp"
00019 #include "soundsource.hpp"
00020 #include "variable.hpp"
00021 #include "unit_map.hpp"
00022 
00023 #include <vector>
00024 #include <map>
00025 
00026 class game_display;
00027 class game_state;
00028 class gamestatus;
00029 class team;
00030 class t_string;
00031 class unit;
00032 
00033 
00034 //! @file game_events.hpp
00035 //! Define the game's events mechanism.
00036 //
00037 // Events might be units moving or fighting, or when victory or defeat occurs.
00038 // A scenario's configuration file will define actions to take when certain events occur.
00039 // This module is responsible for making sure that when the events occur, the actions take place.
00040 //
00041 // Note that game events have nothing to do with SDL events,
00042 // like mouse movement, keyboard events, etc.
00043 // See events.hpp for how they are handled.
00044 
00045 namespace game_events
00046 {
00047 // The game event manager loads the scenario configuration object,
00048 // and ensures that events are handled according to the
00049 // scenario configuration for its lifetime.
00050 //
00051 // Thus, a manager object should be created when a scenario is played,
00052 // and destroyed at the end of the scenario.
00053 struct manager {
00054     // Note that references will be maintained,
00055     // and must remain valid for the life of the object.
00056     manager(const config& scenario_cfg, game_display& disp, gamemap& map,
00057             soundsource::manager& sndsources, unit_map& units, std::vector<team>& teams,
00058             game_state& state_of_game, gamestatus& status);
00059     ~manager();
00060 
00061     variable::manager variable_manager;
00062 };
00063 
00064 struct entity_location : public gamemap::location {
00065     entity_location(gamemap::location loc, const std::string& id="");
00066     explicit entity_location(unit_map::iterator itor);
00067     bool requires_unit() const;
00068     bool matches_unit(const unit& u) const;
00069 private:
00070     std::string id_;
00071 };
00072 
00073 game_state* get_state_of_game();
00074 void write_events(config& cfg);
00075 void add_events(const config::child_list& cfgs,const std::string& id);
00076 
00077 bool unit_matches_filter(unit_map::const_iterator itor, const vconfig filter);
00078 
00079 //! Function to fire an event.
00080 // Events may have up to two arguments, both of which must be locations.
00081 bool fire(const std::string& event,
00082           const entity_location& loc1=gamemap::location::null_location,
00083           const entity_location& loc2=gamemap::location::null_location,
00084           const config& data=config());
00085 
00086 void raise(const std::string& event,
00087           const entity_location& loc1=gamemap::location::null_location,
00088           const entity_location& loc2=gamemap::location::null_location,
00089           const config& data=config());
00090 
00091 bool conditional_passed(const unit_map* units,
00092                         const vconfig cond, bool backwards_compat=true);
00093 bool pump();
00094 
00095 // The count of game event mutations to the unit_map
00096 Uint32 mutations();
00097 
00098 } // end namespace game_events
00099 
00100 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs