47 #define DBG_NG LOG_STREAM(debug, log_engine)
48 #define LOG_NG LOG_STREAM(info, log_engine)
49 #define ERR_NG LOG_STREAM(err, log_engine)
52 #define DBG_WML LOG_STREAM(debug, log_wml)
53 #define LOG_WML LOG_STREAM(info, log_wml)
54 #define WRN_WML LOG_STREAM(warn, log_wml)
55 #define ERR_WML LOG_STREAM(err, log_wml)
58 #define DBG_EH LOG_STREAM(debug, log_event_handler)
63 #ifndef GETLINE_PATCHED
64 #pragma message("warning: the std::getline implementation in your compiler might be broken.")
65 #pragma message(" http://support.microsoft.com/default.aspx?scid=kb;EN-US;q240015")
80 explicit state(
bool s,
bool m =
true) : mutated(
m), skip_messages(s) {}
85 scoped(std::stack<context::state> & contexts,
bool m =
true);
108 , internal_wml_tracking(0)
109 , wml_messages_stream()
121 pump_manager(pump_impl & );
130 return impl_.instance_count;
147 pump_manager::pump_manager(pump_impl & impl) :
160 pump_manager::~pump_manager() {
170 std::vector<queued_event> temp;
216 bool special_matches = special_filters.empty();
217 if ( !special_matches && unit1 != units->
end() )
221 for (
const vconfig &
f : special_filters)
224 special_matches =
true;
225 else if ( !matches_unit )
228 special_matches = special_matches ||
232 if(!special_matches) {
243 special_filters =
filters.get_children(
"filter_second_attack");
244 special_matches = special_filters.empty();
245 if ( !special_matches && unit2 != units->
end() )
249 for (
const vconfig &
f : special_filters)
252 special_matches =
true;
253 else if ( !matches_unit )
256 special_matches = special_matches ||
260 if(!special_matches) {
296 ++
impl_->internal_wml_tracking;
302 if(ev.
name ==
"select") {
319 std::getline(source, msg);
329 if(msg_map.find(msg) == msg_map.end()) {
352 std::map<std::string, int> messages;
356 for(std::map<std::string, int>::const_iterator
itor = messages.begin();
359 std::stringstream
msg;
361 if(
itor->second > 1) {
362 msg <<
" (" <<
itor->second <<
")";
368 std::cerr << caption <<
": " << msg.str() <<
'\n';
383 static const std::string caption(
"Invalid WML found");
404 logger(
log_wml) << message << std::endl;
407 impl_->wml_messages_stream << prefix << message << std::endl;
413 : contexts_(contexts)
424 assert(contexts_.size() > 1);
425 bool mutated = contexts_.top().mutated;
427 contexts_.top().mutated |= mutated;
432 assert(
impl_->contexts_.size() > 0);
433 return impl_->contexts_.top().mutated;
438 assert(
impl_->contexts_.size() > 0);
439 impl_->contexts_.top().mutated =
b;
444 assert(
impl_->contexts_.size() > 0);
445 return impl_->contexts_.top().skip_messages;
450 assert(
impl_->contexts_.size() > 0);
451 impl_->contexts_.top().skip_messages =
b;
460 if (logger ==
"err" || logger ==
"error") {
461 put_wml_message(
lg::err(),
_(
"Error: "), message, in_chat );
462 }
else if (logger ==
"warn" || logger ==
"wrn" || logger ==
"warning") {
463 put_wml_message(
lg::warn(),
_(
"Warning: "), message, in_chat );
464 }
else if ((logger ==
"debug" || logger ==
"dbg") && !
lg::debug().dont_log(
log_wml)) {
465 put_wml_message(
lg::debug(),
_(
"Debug: "), message, in_chat );
467 put_wml_message(
lg::info(),
_(
"Info: "), message, in_chat );
488 DBG_EH <<
"raising event: " <<
event <<
"\n";
499 if (
impl_->events_queue.empty() ) {
500 DBG_EH <<
"Processing queued events, but none found.\n";
504 ERR_NG <<
"game_events pump waiting to process new events because "
509 std::stringstream ss;
511 ss <<
"name=" << ev.
name <<
"; ";
513 DBG_EH <<
"processing queued events: " << ss.str() <<
"\n";
516 const size_t old_wml_track =
impl_->internal_wml_tracking;
521 pump_manager pump_instance(*
impl_);
524 while ( !pump_instance.done() )
536 ++
impl_->internal_wml_tracking;
540 assert(
impl_->my_manager);
547 if ( *handler_iter ) {
555 while (
handler_ptr cur_handler = *handler_iter ) {
556 DBG_EH <<
"processing event " << event_name <<
" with id="<<
557 cur_handler->get_config()[
"id"] <<
"\n";
559 process_event(cur_handler, ev);
569 if ( old_wml_track !=
impl_->internal_wml_tracking )
574 return context_mutated();
604 return impl_->internal_wml_tracking;
bool context_skip_messages()
Returns whether or not we are skipping messages.
play_controller * controller
static thandler * handler
std::vector< queued_event > queue_
Tracks the events to process.
State when processing a particular flight of events or commands.
map_location last_selected
the last location where a select event fired.
bool dont_log(log_domain const &domain) const
bool match(const team &t) const
boost::scoped_ptr< pump_impl > impl_
std::stringstream wml_messages_stream
static std::map< std::string, tfilter > filters
The list of the available filters.
bool fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
void show_wml_messages()
Shows a summary of the messages generated so far by WML.
scoped(std::stack< context::state > &contexts, bool m=true)
void flush_messages()
Flushes WML messages and errors.
bool process_event(handler_ptr &handler_p, const queued_event &ev)
Processes an event through a single event handler.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
GLdouble GLdouble GLdouble b
static lg::log_domain log_engine("engine")
static void clear_status_caches()
Clear the unit status cache for all units.
static UNUSEDNOWARN std::string _(const char *str)
int current_side() const
Returns the number of the side whose turn it is.
void fill_wml_messages_map(std::map< std::string, int > &msg_map, std::stringstream &source)
Helper function for show_wml_messages(), which gathers the messages from a stringstream.
size_t wml_tracking()
This function can be used to detect when no WML/Lua has been executed.
const size_t max_loop
The maximum number of hexes on a map and items in an array and also used as maximum in wml loops...
bool matches_unit_filter(const unit_map::const_iterator &un_it, const vconfig &filter) const
Determines if un_it matches filter.
std::vector< queued_event > events_queue
static lg::log_domain log_event_handler("event_handler")
const config & get_config() const
GLuint GLuint GLsizei count
state(bool s, bool m=true)
Define conditionals for the game's events mechanism, a.k.a.
bool filter_event(const event_handler &handler, const queued_event &ev)
Returns true iff the given event passes all its filters.
std::map< std::string, tfilter >::iterator itor
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
bool matches_special_filter(const config &cfg, const vconfig &filter)
Define the game's event mechanism.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
void raise(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
The game event manager loads the scenario configuration object, and ensures that events are handled a...
bool context_mutated()
Context: The general environment within which events are processed.
This class is similar to an input iterator through event handlers, except each instance knows its own...
static lg::log_domain log_wml("wml")
display_chat_manager & get_chat_manager()
bool conditional_passed(const vconfig &cond)
bool matches_unit(const unit_map::const_iterator &un_it) const
Determines if un_it matches (using underlying ID) the unit that was supplied when this was constructe...
void show_wml_errors()
Shows a summary of the errors encountered in WML so far, to avoid a lot of the same messages to be sh...
Define the handlers for the game's events mechanism.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
game_lua_kernel * lua_kernel
Container associating units to locations.
GLsizei GLenum GLuint GLuint GLsizei char * message
boost::shared_ptr< wb::manager > whiteboard
std::stack< context::state > contexts_
std::stack< context::state > & contexts_
unit_iterator find(size_t id)
std::vector< vconfig > child_list
size_t internal_wml_tracking
The value returned by wml_tracking();.
Ensures that the real unit map is active for the duration of the struct's life.
A config object defines a single node in a WML file, with access to child nodes.
void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
void put_wml_message(const std::string &logger, const std::string &message, bool in_chat)
Helper function which determines whether a wml_message text can really be pushed into the wml_message...
GLsizei const GLcharARB ** string
GLsizei GLsizei GLchar * source
size_t pumped_count_
Tracks how many events have been processed.
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.