1 // Copyright (C) 2004 John Farrell
2 // Copyright (C) 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2006 Andrea Paternesi
4 // Copyright (C) 2009, 2014 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 #pragma once
22 #ifndef AI_ANALYSIS_H
23 #define AI_ANALYSIS_H
24 
25 #include <gtkmm.h>
26 #include <map>
27 #include "vector.h"
28 #include "AICityInfo.h"
29 
30 class Threatlist;
31 class Player;
32 class City;
33 class Stack;
34 class Army;
35 class StackReflist;
36 
37 typedef std::map<guint32, AICityInfo *> AICityMap;
38 
39 //! Artificial intelligence for determining goals.
40 /** An AI's analysis of the game situation.
41   *
42   * The class has an active part as it identifies enemy stacks, cities and ruins
43   * as threats to the AI's cities, categorizes them and assigns them attributes
44   * (namely a rough estimate of the stack strength). Later, it is used by
45   * AI_Allocation (which does the allocation of the AI's troops) as a kind of
46   * container.
47   *
48   * See ai_smart.h for some more details about the smart AI.
49   */
50 
51 class AI_Analysis
52 {
53     public:
54         // Initializes the object and examines the game situation.
55         AI_Analysis(Player *owner);
56         ~AI_Analysis();
57 
58 
59         /** Since during the AI's turn it may battle and defeat enemy stacks, it
60           * neccessary to remove destroyed stacks as threats. This is done by this
61           * more or less callback.
62           */
63         static void deleteStack(Stack* s);
64 
65 	static void deleteStack(guint32 id);
66 
67         // guess the strength of the given stack. Note: next to useless outside
68         // of computer turn.
69         static float assessStackStrength(const Stack *stack);
70         static float assessArmyStrength(const Army *army);
71 
72 
73         /** get an ordered list of threats (most dangerous first)
74           *
75           * @note The returned threatlist ist a pointer to the internal
76           * threatlist, so don't toy around with it!
77           */
78         const Threatlist* getThreatsInOrder();
79 
80         /** get an ordered list of threats (closest first)
81           *
82           * @param pos  the position around which the threats should be ordered
83           */
84         const Threatlist* getThreatsInOrder(Vector<int> pos);
85 
86         // get the danger that this friendly city is in
87         float getCityDanger(City *city);
88 
89         // get the number of army units in the city.
90         int getNumberOfDefendersInCity(City *city);
91 
92         // returns the City that is in the higher
93         void getCityWorstDangers(float dangers[3]);
94 
95         // notify the analysis that we are sending stack to reinforce city
96         void reinforce(City *city, Stack *stack, int movesToArrive);
97 
98         // return an estimate of the amount of strength needed to reinforce
99         // city properly
100         float reinforcementsNeeded(City *city);
101 
102         static void changeOwnership (Player * old_player, Player * new_player);
103     private:
104         // identifies and evaluates enemy cities in the citylist as threats
105         void examineCities();
106 
107         // examine the stack list for potential threats
108         void examineStacks();
109 
110         // examine the ruin list for potential threats
111         void examineRuins();
112 
113         // calculate danger to all of our cities, populates cityInfo
114         void calculateDanger();
115 
116         // the analysis currently in use
117         static AI_Analysis *instance;
118 
119         // DATA
120         // the threats to the AI
121         Threatlist *d_threats;
122         Player *d_owner;
123         StackReflist *d_stacks;
124         AICityMap d_cityInfo;
125 };
126 
127 #endif // AI_ANALYSIS_H
128 
129 // End of file
130