The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
candidates.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2017 by Bartosz Waresiak <dragonking@o2.pl>
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  * @file
17  * Defines formula ai candidate actions - headers
18  * */
19 
20 #pragma once
21 
22 #include <set>
23 
24 class unit_map;
25 class config;
26 
27 namespace ai {
28 class formula_ai;
29 }
30 
31 namespace wfl {
32 
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 
53  //return score of last evaluation
54  int get_score() const {return score_;}
55 
57 
58  const std::string& get_name() const { return name_;}
59  const std::string& get_type() const { return type_;}
60 
61 protected:
63  const formula_callable& callable, const ai::formula_ai* ai);
64 
69  int score_;
70 };
71 
72 
74 public:
76 protected:
78 
79  candidate_action_filters filter_map_;
80 };
81 
83 public:
84  move_candidate_action(const std::string& name, const std::string& type,const config& cfg, function_symbol_table* function_table);
85 
86  virtual void evaluate(ai::formula_ai* ai, unit_map& units);
87 
88  virtual void update_callable_map(map_formula_callable& callable);
89 
90 protected:
92 };
93 
95 public:
96  attack_candidate_action(const std::string& name, const std::string& type,const config& cfg, function_symbol_table* function_table);
97 
98  virtual void evaluate(ai::formula_ai* ai, unit_map& units);
99 
100  virtual void update_callable_map(map_formula_callable& callable);
101 protected:
104 };
105 
106 }
std::vector< char_t > string
const std::string & get_type() const
Definition: candidates.hpp:59
virtual void evaluate(ai::formula_ai *ai, unit_map &units)
Definition: candidates.cpp:94
candidate_action_with_filters(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:59
const_formula_ptr action_
Definition: candidates.hpp:68
virtual void update_callable_map(map_formula_callable &callable)
Definition: candidates.cpp:137
std::map< std::string, const_formula_ptr > candidate_action_filters
Definition: candidates.hpp:33
virtual void evaluate(ai::formula_ai *, unit_map &)
Definition: candidates.hpp:47
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:58
move_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:87
variant do_filtering(ai::formula_ai *ai, variant &input, const_formula_ptr formula)
Definition: candidates.cpp:78
virtual void evaluate(ai::formula_ai *ai, unit_map &units)
Definition: candidates.cpp:150
std::shared_ptr< const formula > const_formula_ptr
Definition: formula_fwd.hpp:23
virtual void update_callable_map(map_formula_callable &callable)
Definition: candidates.cpp:245
std::shared_ptr< base_candidate_action > candidate_action_ptr
Definition: candidates.hpp:36
Definition: contexts.hpp:42
Container associating units to locations.
Definition: map.hpp:99
candidate_action_filters filter_map_
Definition: candidates.hpp:79
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
const_formula_ptr eval_
Definition: candidates.hpp:67
attack_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:142
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
base_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Definition: candidates.cpp:32
const std::string & get_name() const
Definition: candidates.hpp:58
unit_map * units
Definition: resources.cpp:34
const_formula_ptr & get_action()
Definition: candidates.hpp:56
int execute_formula(const const_formula_ptr &formula, const formula_callable &callable, const ai::formula_ai *ai)
Definition: candidates.cpp:42
virtual void update_callable_map(map_formula_callable &)
Definition: candidates.hpp:50