The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
stage.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Yurii Chernyi <[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  * Stage of a composite AI
17  * @file
18  */
19 
20 #include "ai/composite/ai.hpp"
21 #include "ai/composite/engine.hpp"
22 #include "ai/composite/stage.hpp"
23 #include "ai/contexts.hpp"
24 #include "log.hpp"
25 #include "resources.hpp"
26 #include "tod_manager.hpp"
27 #include <map>
28 #include <string>
29 
30 namespace ai {
31 
32 static lg::log_domain log_ai_stage("ai/stage");
33 #define DBG_AI_STAGE LOG_STREAM(debug, log_ai_stage)
34 #define LOG_AI_STAGE LOG_STREAM(info, log_ai_stage)
35 #define ERR_AI_STAGE LOG_STREAM(err, log_ai_stage)
36 
37 // =======================================================================
38 // COMPOSITE AI STAGE
39 // =======================================================================
40 
41 stage::stage( ai_context &context, const config &cfg )
42  : recursion_counter_(context.get_recursion_count()), cfg_(cfg)
43 {
44  init_ai_context_proxy(context);
45 }
46 
48 {
49  LOG_AI_STAGE << "side "<< get_side() << " : "<<" created stage with name=["<<cfg_["name"]<<"]"<<std::endl;
50 }
51 
53 {
54 }
55 
57 {
58  return do_play_stage();
59 }
60 
62 {
64 }
65 
67 {
68  config cfg;
69  cfg["engine"] = cfg_["engine"];
70  cfg["name"] = cfg_["name"];
71  cfg["id"] = cfg_["id"];
72  return cfg;
73 }
74 
76 {
77  return cfg_["id"];
78 }
79 
81 {
82  return cfg_["engine"];
83 }
84 
86 {
87  return cfg_["name"];
88 }
89 
90 
91 
92 
93 // =======================================================================
94 // COMPOSITE AI IDLE STAGE
95 // =======================================================================
96 
97 
98 idle_stage::idle_stage( ai_context &context, const config &cfg )
99  : stage(context,cfg)
100 {
101 }
102 
104 {
105 }
106 
108  LOG_AI_STAGE << "Turn " << resources::tod_manager->turn() << ": playing idle stage for side: "<< get_side() << std::endl;
109  return false;
110 }
111 
112 
113 // This is defined in the source file so that it can easily access the logger
115 {
116  if (get_list().find(name) != get_list().end()) {
117  ERR_AI_STAGE << "Error: Attempt to double-register stage " << name << std::endl;
118  return true;
119  }
120  return false;
121 }
122 
123 
124 } //end of namespace ai
virtual side_number get_side() const
Get the side number.
Definition: contexts.hpp:480
::tod_manager * tod_manager
Definition: resources.cpp:31
virtual bool do_play_stage()
Play the turn - implementation.
Definition: stage.cpp:107
idle_stage(ai_context &context, const config &cfg)
Definition: stage.cpp:98
int get_recursion_count() const
get the value of the recursion counter
Definition: stage.cpp:61
bool play_stage()
Play the turn - strategy.
Definition: stage.cpp:56
recursion_counter recursion_counter_
Definition: stage.hpp:84
virtual std::string get_id() const
Definition: stage.cpp:75
Composite AI stages.
AI Support engine - creating specific ai components from config.
virtual std::string get_name() const
Definition: stage.cpp:85
virtual ~stage()
Destructor.
Definition: stage.cpp:52
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
GLuint GLuint end
Definition: glew.h:1221
static factory_map & get_list()
Definition: stage.hpp:108
virtual config to_config() const
serialize
Definition: stage.cpp:66
bool is_duplicate(const std::string &name)
Definition: stage.cpp:114
#define ERR_AI_STAGE
Definition: stage.cpp:35
Composite AI with turn sequence which is a vector of stages.
virtual void on_create()
Initialization.
Definition: stage.cpp:47
static lg::log_domain log_ai_stage("ai/stage")
void init_ai_context_proxy(ai_context &target)
Definition: contexts.hpp:112
int get_count() const
Get the current value of the recursion counter.
Definition: contexts.hpp:79
config cfg_
Definition: stage.hpp:86
stage(ai_context &context, const config &cfg)
Constructor.
Definition: stage.cpp:41
int turn() const
virtual bool do_play_stage()=0
Play the turn - implementation.
Helper functions for the object which operates in the context of AI for specific side this is part of...
#define LOG_AI_STAGE
Definition: stage.cpp:34
GLuint const GLchar * name
Definition: glew.h:1782
bool find(E event, F functor)
Tests whether an event handler is available.
Standard logging facilities (interface).
virtual std::string get_engine() const
Definition: stage.cpp:80
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