The Battle for Wesnoth  1.15.12+dev
stage.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Yurii Chernyi <terraninfo@terraninfo.net>
3  Part of the Battle for Wesnoth Project https://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 
75 std::string stage::get_id() const
76 {
77  return cfg_["id"];
78 }
79 
80 std::string stage::get_engine() const
81 {
82  return cfg_["engine"];
83 }
84 
85 std::string stage::get_name() const
86 {
87  return cfg_["name"];
88 }
89 
90 // =======================================================================
91 // COMPOSITE AI IDLE STAGE
92 // =======================================================================
93 
94 idle_stage::idle_stage( ai_context &context, const config &cfg )
95  : stage(context,cfg)
96 {
97 }
98 
100 {
101 }
102 
104  LOG_AI_STAGE << "Turn " << resources::tod_manager->turn() << ": playing idle stage for side: "<< get_side() << std::endl;
105  return false;
106 }
107 
108 // This is defined in the source file so that it can easily access the logger
109 bool stage_factory::is_duplicate(const std::string& name)
110 {
111  if (get_list().find(name) != get_list().end()) {
112  ERR_AI_STAGE << "Error: Attempt to double-register stage " << name << std::endl;
113  return true;
114  }
115  return false;
116 }
117 
118 } //end of namespace ai
::tod_manager * tod_manager
Definition: resources.cpp:29
virtual std::string get_name() const
Definition: stage.cpp:85
virtual bool do_play_stage()
Play the turn - implementation.
Definition: stage.cpp:103
idle_stage(ai_context &context, const config &cfg)
Definition: stage.cpp:94
virtual std::string get_engine() const
Definition: stage.cpp:80
bool play_stage()
Play the turn - strategy.
Definition: stage.cpp:56
recursion_counter recursion_counter_
Definition: stage.hpp:74
virtual std::string get_id() const
Definition: stage.cpp:75
Composite AI stages.
AI Support engine - creating specific ai components from config.
virtual ~stage()
Destructor.
Definition: stage.cpp:52
A small explanation about what&#39;s going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
bool is_duplicate(const std::string &name)
Definition: stage.cpp:109
#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:94
config cfg_
Definition: stage.hpp:76
stage(ai_context &context, const config &cfg)
Constructor.
Definition: stage.cpp:41
virtual side_number get_side() const override
Get the side number.
Definition: contexts.hpp:400
virtual config to_config() const
serialize
Definition: stage.cpp:66
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
Standard logging facilities (interface).
int get_count() const
Get the current value of the recursion counter.
Definition: contexts.hpp:69
int turn() const
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
int get_recursion_count() const
get the value of the recursion counter
Definition: stage.cpp:61