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
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.
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.
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
41 typedef map<guint32, AICityInfo *> AICityMap;
43 /** An AI's analysis of the game situation.
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
51 * See ai_smart.h for some more details about the smart AI.
57 // Initializes the object and examines the game situation.
58 AI_Analysis(Player *owner);
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.
66 static void deleteStack(Stack* s);
68 static void deleteStack(guint32 id);
70 // guess the strength of the given stack. Note: next to useless outside
72 static float assessStackStrength(const Stack *stack);
73 static float assessArmyStrength(const Army *army);
76 /** get an ordered list of threats (most dangerous first)
78 * @note The returned threatlist ist a pointer to the internal
79 * threatlist, so don't toy around with it!
81 const Threatlist* getThreatsInOrder();
83 /** get an ordered list of threats (closest first)
85 * @param pos the position around which the threats should be ordered
87 const Threatlist* getThreatsInOrder(Vector<int> pos);
89 // get the danger that this friendly city is in
90 float getCityDanger(City *city);
92 // get the number of army units in the city.
93 int getNumberOfDefendersInCity(City *city);
95 // returns the City that is in the higher
96 void getCityWorstDangers(float dangers[3]);
98 // notify the analysis that we are sending stack to reinforce city
99 void reinforce(City *city, Stack *stack, int movesToArrive);
101 // return an estimate of the amount of strength needed to reinforce
103 float reinforcementsNeeded(City *city);
105 static void changeOwnership (Player * old_player, Player * new_player);
107 // identifies and evaluates enemy cities in the citylist as threats
108 void examineCities();
110 // examine the stack list for potential threats
111 void examineStacks();
113 // examine the ruin list for potential threats
116 // calculate danger to all of our cities, populates cityInfo
117 void calculateDanger();
119 // the analysis currently in use
120 static AI_Analysis *instance;
123 // the threats to the AI
124 Threatlist *d_threats;
126 StackReflist *d_stacks;
127 AICityMap d_cityInfo;
130 #endif // AI_ANALYSIS_H