The Battle for Wesnoth  1.19.7+dev
candidates.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Bartosz Waresiak <dragonking@o2.pl>
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  * @file
18  * Defines formula ai candidate actions - headers
19  * */
20 
21 #pragma once
22 
23 
24 class unit_map;
25 class config;
26 
27 namespace ai {
28 class formula_ai;
29 }
30 
31 namespace wfl {
32 
33 class base_candidate_action;
34 
35 typedef std::map< std::string, const_formula_ptr > candidate_action_filters;
36 typedef std::shared_ptr<base_candidate_action> candidate_action_ptr;
37 
38 //every new candidate action type should be derived from this class
39 //and should complete evaluate and update_callable_map methods
41 public:
42  base_candidate_action(const std::string& name, const std::string& type,const config& cfg, function_symbol_table* function_table);
43 
45 
46  //evaluate candidate action using eval_ formula
47  virtual void evaluate(ai::formula_ai* /*ai*/, unit_map& /*units*/) {}
48 
49  //adds needed callable objects to callable map
50  virtual void update_callable_map(map_formula_callable& /*callable*/) {}
51 
52  //return score of last evaluation
53  int get_score() const {return score_;}
54 
56 
57  const std::string& get_name() const { return name_;}
58  const std::string& get_type() const { return type_;}
59 
60 protected:
62  const formula_callable& callable, const ai::formula_ai* ai);
63 
64  std::string name_;
65  std::string type_;
68  int score_;
69 };
70 
72 public:
73  candidate_action_with_filters(const std::string& name, const std::string& type,const config& cfg, function_symbol_table* function_table);
74 protected:
76 
78 };
79 
81 public:
82  move_candidate_action(const std::string& name, const std::string& type,const config& cfg, function_symbol_table* function_table);
83 
84  virtual void evaluate(ai::formula_ai* ai, unit_map& units);
85 
86  virtual void update_callable_map(map_formula_callable& callable);
87 
88 protected:
90 };
91 
93 public:
94  attack_candidate_action(const std::string& name, const std::string& type,const config& cfg, function_symbol_table* function_table);
95 
96  virtual void evaluate(ai::formula_ai* ai, unit_map& units);
97 
98  virtual void update_callable_map(map_formula_callable& callable);
99 protected:
102 };
103 
104 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Container associating units to locations.
Definition: map.hpp:98
attack_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:142
virtual void evaluate(ai::formula_ai *ai, unit_map &units)
Definition: candidates.cpp:150
virtual void update_callable_map(map_formula_callable &callable)
Definition: candidates.cpp:245
const std::string & get_name() const
Definition: candidates.hpp:57
const_formula_ptr action_
Definition: candidates.hpp:67
virtual void update_callable_map(map_formula_callable &)
Definition: candidates.hpp:50
virtual void evaluate(ai::formula_ai *, unit_map &)
Definition: candidates.hpp:47
const_formula_ptr & get_action()
Definition: candidates.hpp:55
int execute_formula(const const_formula_ptr &formula, const formula_callable &callable, const ai::formula_ai *ai)
Definition: candidates.cpp:42
const std::string & get_type() const
Definition: candidates.hpp:58
const_formula_ptr eval_
Definition: candidates.hpp:66
base_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:32
variant do_filtering(ai::formula_ai *ai, variant &input, const const_formula_ptr &formula)
Definition: candidates.cpp:78
candidate_action_with_filters(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:59
candidate_action_filters filter_map_
Definition: candidates.hpp:77
move_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:87
virtual void update_callable_map(map_formula_callable &callable)
Definition: candidates.cpp:137
virtual void evaluate(ai::formula_ai *ai, unit_map &units)
Definition: candidates.cpp:94
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
Definition: contexts.hpp:43
std::shared_ptr< const formula > const_formula_ptr
Definition: formula_fwd.hpp:24
std::shared_ptr< base_candidate_action > candidate_action_ptr
Definition: candidates.hpp:36
std::map< std::string, const_formula_ptr > candidate_action_filters
Definition: candidates.hpp:33