initial commit, lordsawar source, slightly modified
[lordsawar] / src / AI_Analysis.h
1 // Copyright (C) 2004 John Farrell
2 // Copyright (C) 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2006 Andrea Paternesi
4 // Copyright (C) 2009 Ben Asselstine
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 3 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU Library General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
19 //  02110-1301, USA.
20
21 #ifndef AI_ANALYSIS_H
22 #define AI_ANALYSIS_H
23
24 #include <gtkmm.h>
25 #include <string>
26 #include <map>
27 #include "vector.h"
28
29 class Threatlist;
30 class Player;
31 class City;
32 class Citylist;
33 class Threat;
34 class Stack;
35 class Army;
36 class StackReflist;
37 class AICityInfo;
38
39 using namespace std;
40
41 typedef map<guint32, AICityInfo *> AICityMap;
42
43 /** An AI's analysis of the game situation.
44   *
45   * The class has an active part as it identifies enemy stacks, cities and ruins
46   * as threats to the AI's cities, categorizes them and assigns them attributes
47   * (namely a rough estimate of the stack strength). Later, it is used by
48   * AI_Allocation (which does the allocation of the AI's troops) as a kind of
49   * container.
50   *
51   * See ai_smart.h for some more details about the smart AI.
52   */
53
54 class AI_Analysis
55 {
56     public:
57         // Initializes the object and examines the game situation.
58         AI_Analysis(Player *owner);
59         ~AI_Analysis();
60
61         
62         /** Since during the AI's turn it may battle and defeat enemy stacks, it
63           * neccessary to remove destroyed stacks as threats. This is done by this
64           * more or less callback.
65           */
66         static void deleteStack(Stack* s);
67
68         static void deleteStack(guint32 id);
69
70         // guess the strength of the given stack. Note: next to useless outside
71         // of computer turn.
72         static float assessStackStrength(const Stack *stack);
73         static float assessArmyStrength(const Army *army);
74
75         
76         /** get an ordered list of threats (most dangerous first)
77           * 
78           * @note The returned threatlist ist a pointer to the internal
79           * threatlist, so don't toy around with it!
80           */
81         const Threatlist* getThreatsInOrder();
82
83         /** get an ordered list of threats (closest first)
84           * 
85           * @param pos  the position around which the threats should be ordered
86           */
87         const Threatlist* getThreatsInOrder(Vector<int> pos);
88
89         // get the danger that this friendly city is in
90         float getCityDanger(City *city);
91
92         // get the number of army units in the city.
93         int getNumberOfDefendersInCity(City *city);
94
95         // returns the City that is in the higher 
96         void getCityWorstDangers(float dangers[3]);
97
98         // notify the analysis that we are sending stack to reinforce city
99         void reinforce(City *city, Stack *stack, int movesToArrive);
100
101         // return an estimate of the amount of strength needed to reinforce
102         // city properly
103         float reinforcementsNeeded(City *city);
104         
105         static void changeOwnership (Player * old_player, Player * new_player);
106     private:
107         // identifies and evaluates enemy cities in the citylist as threats
108         void examineCities();
109         
110         // examine the stack list for potential threats
111         void examineStacks();
112         
113         // examine the ruin list for potential threats
114         void examineRuins();
115         
116         // calculate danger to all of our cities, populates cityInfo
117         void calculateDanger();
118
119         // the analysis currently in use
120         static AI_Analysis *instance;
121        
122         // DATA
123         // the threats to the AI
124         Threatlist *d_threats;
125         Player *d_owner;
126         StackReflist *d_stacks;
127         AICityMap d_cityInfo;
128 };
129
130 #endif // AI_ANALYSIS_H
131
132 // End of file