initial commit, lordsawar source, slightly modified
[lordsawar] / src / AI_Allocation.h
1 // Copyright (C) 2004 John Farrell
2 // Copyright (C) 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2009 Ben Asselstine
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 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Library General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
18 //  02110-1301, USA.
19
20 #ifndef AI_ALLOCATION_H
21 #define AI_ALLOCATION_H
22
23 #include <gtkmm.h>
24 #include <string>
25
26 #include "MoveResult.h"
27 #include "stackreflist.h"
28
29 class AI_Analysis;
30 class Player;
31 class Ruin;
32 class Citylist;
33 class Stack;
34 class Threat;
35 class StackReflist;
36 class Threatlist;
37 class City;
38 class Quest;
39
40 using namespace std;
41
42 /** An AI's allocation of resources to goals identified in the analysis.
43   */
44
45 class AI_Allocation
46 {
47     public:
48         AI_Allocation(AI_Analysis *analysis, const Threatlist *threats, Player *owner);
49         ~AI_Allocation();
50
51         // make the player's moves - return the number of stacks which moved.
52         int move(City *first_city, bool build_capacity);
53
54         //! remove the stack from our consideration.
55         static void deleteStack(Stack* s);
56         static void deleteStack(guint32 id);
57         StackReflist::iterator eraseStack(StackReflist::iterator it);
58
59         //! Emitted whenever anything happens.
60         sigc::signal<void> sbusy;
61
62     private:
63         /** Assign stacks to defend cities
64           * 
65           * This function checks if each city is properly defended and assigns
66           * additional stacks from the environment as defenders if neccessary.
67           *
68           * @param allCities    list of cities to be checked
69           * @param stacks       list of stacks available for the task. The
70           *                     allocated stacks are removed from the list.
71           * @return number of stacks moved
72           */
73         int allocateDefensiveStacks(Citylist *allCities);
74
75         int allocateDefensiveStacksToCity(City *city);
76         
77         /** Allocate stacks to threats
78           * 
79           * @param stacks       the list of stacks which we can choose stacks from
80           *                     stacks we have dealt with are removed from the list.
81           * @return the number of stacks which moved
82           */
83         int allocateStacksToThreats();
84
85         int allocateStacksToThreat(Threat *threat);
86         
87
88         //! Target neutral cities and empty foreign cities.
89         int allocateStacksToCapacityBuilding(City *first_city, bool take_neutrals);
90
91         int allocateStackToCapacityBuilding(Threat *threat, City *first_city, bool take_neutrals);
92
93         // stack return to a safe city
94         bool stackReinforce(Stack *s);
95         
96         // search a ruin
97         void searchRuin(Stack *stack, Ruin *ruin);
98         
99         // move armies within a city to try to make full stacks
100         bool shuffleStacksWithinCity(City *city, Stack *stack, 
101                                      Vector<int> diff);
102         
103         // tell the stack to move to the point
104         //MoveResult *moveStack(Stack *stack, Vector<int> pos);
105
106
107         bool moveStack(Stack *stack, bool &stack_died);
108         bool moveStack(Stack *stack, Vector<int> dest, bool &stack_died);
109
110         bool shuffleStack(Stack *stack, Vector<int> dest, bool split_if_necessary);
111
112         bool groupStacks(Stack *stack);
113         
114         void setParked(Stack *stack, bool force_park = false);
115
116         // find the best attacker for the given threat
117         Stack *findBestAttackerFor(Threat *threat, guint32 &num_city_defenders);
118         
119         // find the closest stack to the given position, but 0 if none within
120         Stack *findClosestStackToCity(City *city);
121
122         Stack *findClosestStackToEnemyCity(City *city, bool try_harder);
123         
124         // find a position in the city that a stack can move to
125         Vector<int> getFreeSpotInCity(City *city, int stackSize);
126
127         // find a ANOTHER position in the city that the stack can move to
128         Vector<int> getFreeOtherSpotInCity(City *city, Stack *stack);
129         
130         // move stacks that we have no particular use for
131         int defaultStackMovements();
132
133         int continueAttacks();
134
135         int continueQuests();
136         bool continueQuest(Quest *quest, Stack *stack);
137
138         int attackNearbyEnemies();
139         
140         bool checkAmbiguities();
141
142         bool emptyOutCities();
143
144         int visitTemples(bool get_quests);
145
146         int pickupItems();
147
148         int visitRuins();
149
150         static AI_Allocation* s_instance;
151         
152         Player *d_owner;
153         AI_Analysis *d_analysis;
154         StackReflist *d_stacks;
155         const Threatlist *d_threats;
156         bool *abort_turn;
157 };
158
159 #endif // AI_ALLOCATION_H
160
161 // End of file