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