1 // Copyright (C) 2004 John Farrell
2 // Copyright (C) 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2009 Ben Asselstine
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.
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.
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
20 #ifndef AI_ALLOCATION_H
21 #define AI_ALLOCATION_H
26 #include "MoveResult.h"
27 #include "stackreflist.h"
42 /** An AI's allocation of resources to goals identified in the analysis.
48 AI_Allocation(AI_Analysis *analysis, const Threatlist *threats, Player *owner);
51 // make the player's moves - return the number of stacks which moved.
52 int move(City *first_city, bool build_capacity);
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);
59 //! Emitted whenever anything happens.
60 sigc::signal<void> sbusy;
63 /** Assign stacks to defend cities
65 * This function checks if each city is properly defended and assigns
66 * additional stacks from the environment as defenders if neccessary.
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
73 int allocateDefensiveStacks(Citylist *allCities);
75 int allocateDefensiveStacksToCity(City *city);
77 /** Allocate stacks to threats
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
83 int allocateStacksToThreats();
85 int allocateStacksToThreat(Threat *threat);
88 //! Target neutral cities and empty foreign cities.
89 int allocateStacksToCapacityBuilding(City *first_city, bool take_neutrals);
91 int allocateStackToCapacityBuilding(Threat *threat, City *first_city, bool take_neutrals);
93 // stack return to a safe city
94 bool stackReinforce(Stack *s);
97 void searchRuin(Stack *stack, Ruin *ruin);
99 // move armies within a city to try to make full stacks
100 bool shuffleStacksWithinCity(City *city, Stack *stack,
103 // tell the stack to move to the point
104 //MoveResult *moveStack(Stack *stack, Vector<int> pos);
107 bool moveStack(Stack *stack, bool &stack_died);
108 bool moveStack(Stack *stack, Vector<int> dest, bool &stack_died);
110 bool shuffleStack(Stack *stack, Vector<int> dest, bool split_if_necessary);
112 bool groupStacks(Stack *stack);
114 void setParked(Stack *stack, bool force_park = false);
116 // find the best attacker for the given threat
117 Stack *findBestAttackerFor(Threat *threat, guint32 &num_city_defenders);
119 // find the closest stack to the given position, but 0 if none within
120 Stack *findClosestStackToCity(City *city);
122 Stack *findClosestStackToEnemyCity(City *city, bool try_harder);
124 // find a position in the city that a stack can move to
125 Vector<int> getFreeSpotInCity(City *city, int stackSize);
127 // find a ANOTHER position in the city that the stack can move to
128 Vector<int> getFreeOtherSpotInCity(City *city, Stack *stack);
130 // move stacks that we have no particular use for
131 int defaultStackMovements();
133 int continueAttacks();
135 int continueQuests();
136 bool continueQuest(Quest *quest, Stack *stack);
138 int attackNearbyEnemies();
140 bool checkAmbiguities();
142 bool emptyOutCities();
144 int visitTemples(bool get_quests);
150 static AI_Allocation* s_instance;
153 AI_Analysis *d_analysis;
154 StackReflist *d_stacks;
155 const Threatlist *d_threats;
159 #endif // AI_ALLOCATION_H