ai/default/ai.hpp

Go to the documentation of this file.
00001 /* $Id: ai.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /** @file */
00017 
00018 #ifndef AI_DEFAULT_AI_HPP_INCLUDED
00019 #define AI_DEFAULT_AI_HPP_INCLUDED
00020 
00021 #include "../interface.hpp"
00022 #include "../composite/stage.hpp"
00023 
00024 #ifdef _MSC_VER
00025 #pragma warning(push)
00026 //silence "inherits via dominance" warnings
00027 #pragma warning(disable:4250)
00028 #endif
00029 
00030 
00031 namespace pathfind {
00032 
00033 struct plain_route;
00034 
00035 } // of namespace pathfind
00036 
00037 
00038 namespace ai {
00039 
00040 class formula_ai;
00041 
00042 /** A trivial ai that sits around doing absolutely nothing. */
00043 class idle_ai : public readwrite_context_proxy, public interface {
00044 public:
00045     idle_ai(readwrite_context &context, const config &cfg);
00046     void play_turn();
00047     void new_turn();
00048     std::string describe_self() const;
00049     void switch_side(side_number side);
00050     int get_recursion_count() const;
00051     virtual config to_config() const;
00052 private:
00053     const config &cfg_;
00054     recursion_counter recursion_counter_;
00055 };
00056 
00057 class ai_default_recruitment_stage : public stage {
00058 public:
00059     ai_default_recruitment_stage(ai_context &context, const config &cfg);
00060     virtual ~ai_default_recruitment_stage();
00061     void on_create();
00062     bool do_play_stage();
00063     config to_config() const;
00064     int get_combat_score(const unit_type& ut) const;
00065 
00066 private:
00067 
00068     void get_combat_score_vs(const unit_type& ut, const std::string &enemy_type_id, int &score, int &weighting, int hitpoints, int max_hitpoints) const;
00069 
00070     virtual bool recruit_usage(const std::string& usage);
00071 
00072 
00073     class recruit_situation_change_observer : public events::observer {
00074     public:
00075         recruit_situation_change_observer();
00076         ~recruit_situation_change_observer();
00077 
00078         void handle_generic_event(const std::string& /*event_name*/);
00079 
00080         bool get_valid();
00081         void set_valid(bool valid);
00082     private:
00083         bool valid_;
00084 
00085     };
00086 
00087     /**
00088      * initialize recruitment recommendations
00089      */
00090     void analyze_all();
00091 
00092     /**
00093      * Analyze all the units that this side can recruit
00094      * and rate their movement types.
00095      * Ratings will be placed in 'unit_movement_scores_',
00096      * with lower scores being better,
00097      * and the lowest possible rating being '10'.
00098      */
00099     virtual void analyze_potential_recruit_movements();
00100 
00101     std::string find_suitable_recall_id();
00102 
00103     std::map<std::string,int> best_usage_;
00104 
00105     config cfg_;
00106 
00107     std::map<std::string,int> maximum_counts_;
00108 
00109     std::set<std::string> not_recommended_units_;
00110 
00111     std::vector<std::pair<std::string,double> > recall_list_scores_;
00112 
00113     recruit_situation_change_observer recruit_situation_change_observer_;
00114 
00115     std::map<std::string,int> unit_combat_scores_;
00116 
00117     std::map<std::string,int> unit_movement_scores_;
00118 
00119     /**
00120      * Analyze all the units that this side can recruit
00121      * and rate their fighting suitability against enemy units.
00122      * Ratings will be placed in 'unit_combat_scores_',
00123      * with a '0' rating indicating that the unit is 'average' against enemy units,
00124      * negative ratings meaning they are poorly suited,
00125      * and positive ratings meaning they are well suited.
00126      */
00127     virtual void analyze_potential_recruit_combat();
00128 
00129 
00130     bool analyze_recall_list();
00131 
00132     /**
00133      * Rates two unit types for their suitability against each other.
00134      * Returns 0 if the units are equally matched,
00135      * a positive number if a is suited against b,
00136      * and a negative number if b is suited against a.
00137      */
00138     virtual int compare_unit_types(const unit_type& a, const unit_type& b) const;
00139 
00140     /**
00141      * calculates the average resistance unit type a has against the attacks of
00142      * unit type b.
00143      */
00144     virtual int average_resistance_against(const unit_type& a, const unit_type& b) const;
00145 
00146 
00147 };
00148 
00149 } //end of namespace ai
00150 
00151 #ifdef _MSC_VER
00152 #pragma warning(pop)
00153 #endif
00154 
00155 
00156 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:28 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs