The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
stage.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 - 2025
3 by Yurii Chernyi <terraninfo@terraninfo.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 * Stage of a composite AI
18 * @file
19 */
20
22#include "ai/contexts.hpp"
23#include "log.hpp"
24#include "resources.hpp"
25#include "tod_manager.hpp"
26#include <map>
27#include <string>
28
29namespace ai {
30
31static lg::log_domain log_ai_stage("ai/stage");
32#define DBG_AI_STAGE LOG_STREAM(debug, log_ai_stage)
33#define LOG_AI_STAGE LOG_STREAM(info, log_ai_stage)
34#define ERR_AI_STAGE LOG_STREAM(err, log_ai_stage)
35
36// =======================================================================
37// COMPOSITE AI STAGE
38// =======================================================================
39
40stage::stage( ai_context &context, const config &cfg )
41 : recursion_counter_(context.get_recursion_count()), cfg_(cfg)
42{
43 init_ai_context_proxy(context);
44}
45
47{
48 LOG_AI_STAGE << "side "<< get_side() << " : "<<" created stage with name=["<<cfg_["name"]<<"]";
49}
50
52{
53}
54
56{
57 return do_play_stage();
58}
59
64
66{
67 config cfg;
68 cfg["engine"] = cfg_["engine"];
69 cfg["name"] = cfg_["name"];
70 cfg["id"] = cfg_["id"];
71 return cfg;
72}
73
74std::string stage::get_id() const
75{
76 return cfg_["id"];
77}
78
79std::string stage::get_engine() const
80{
81 return cfg_["engine"];
82}
83
84std::string stage::get_name() const
85{
86 return cfg_["name"];
87}
88
89// =======================================================================
90// COMPOSITE AI IDLE STAGE
91// =======================================================================
92
94 : stage(context,cfg)
95{
96}
97
101
103 LOG_AI_STAGE << "Turn " << resources::tod_manager->turn() << ": playing idle stage for side: "<< get_side();
104 return false;
105}
106
107// This is defined in the source file so that it can easily access the logger
108bool stage_factory::is_duplicate(const std::string& name)
109{
110 if (get_list().find(name) != get_list().end()) {
111 ERR_AI_STAGE << "Error: Attempt to double-register stage " << name;
112 return true;
113 }
114 return false;
115}
116
117} //end of namespace ai
void init_ai_context_proxy(ai_context &target)
Definition contexts.hpp:92
virtual bool do_play_stage()
Play the turn - implementation.
Definition stage.cpp:102
idle_stage(ai_context &context, const config &cfg)
Definition stage.cpp:93
int get_count() const
Get the current value of the recursion counter.
Definition contexts.hpp:65
virtual side_number get_side() const override
Get the side number.
Definition contexts.hpp:393
bool is_duplicate(const std::string &name)
Definition stage.cpp:108
static factory_map & get_list()
Definition stage.hpp:96
int get_recursion_count() const
get the value of the recursion counter
Definition stage.cpp:60
recursion_counter recursion_counter_
Definition stage.hpp:74
virtual std::string get_engine() const
Definition stage.cpp:79
virtual std::string get_id() const
Definition stage.cpp:74
virtual ~stage()
Destructor.
Definition stage.cpp:51
config cfg_
Definition stage.hpp:76
bool play_stage()
Play the turn - strategy.
Definition stage.cpp:55
stage(ai_context &context, const config &cfg)
Constructor.
Definition stage.cpp:40
virtual bool do_play_stage()=0
Play the turn - implementation.
virtual config to_config() const
serialize
Definition stage.cpp:65
virtual void on_create()
Initialization.
Definition stage.cpp:46
virtual std::string get_name() const
Definition stage.cpp:84
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
int turn() const
Helper functions for the object which operates in the context of AI for specific side this is part of...
const config * cfg
Standard logging facilities (interface).
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition actions.cpp:59
static lg::log_domain log_ai_stage("ai/stage")
::tod_manager * tod_manager
Definition resources.cpp:29
#define LOG_AI_STAGE
Definition stage.cpp:33
#define ERR_AI_STAGE
Definition stage.cpp:34
Composite AI stages.