5602328edac66067d4f39ef0c881c1d589b72f88
[lordsawar] / src / ai_fast.h
1 // Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2003 Michael Bartl
3 // Copyright (C) 2004 Andrea Paternesi
4 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
5 // Copyright (C) 2007, 2008 Ole Laursen
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 3 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU Library General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
20 //  02110-1301, USA.
21
22 #ifndef AI_FAST_H
23 #define AI_FAST_H
24
25 #include <string>
26 #include <list>
27
28 #include "real_player.h"
29 #include "AI_Analysis.h"
30 #include "AI_Diplomacy.h"
31
32 class XML_Helper;
33 class City;
34
35
36 //! A simple artificial intelligence Player.
37 /** 
38  * This AI has two modes. In normal modes it basically assembles stacks of
39  * 8 units each and sends them to the next city, reinforcing them in own cities
40  * if neccessary. In maniac mode, however (meant for wandering monsters etc.),
41  * this AI will attack everything that is close up or take the nearest city if
42  * no enemies are close. When it takes over an enemy city, it razes it.
43  * 
44  */
45
46 class AI_Fast : public RealPlayer
47 {
48     public:
49         /** 
50          * Make a new AI_Fast player.
51          * 
52          * @param name         The name of the player.
53          * @param armyset      The Id of the player's Armyset.
54          * @param color        The player's colour.
55          * @param width        The width of the player's FogMap.
56          * @param height       The height of the player's FogMap.
57          * @param player_no    The Id of the player.  If this value is -1,
58          *                     the next free Id it used.
59          */
60         //! Default constructor.
61         AI_Fast(std::string name, guint32 armyset, Gdk::Color color, 
62                 int width, int height, int player_no = -1);
63
64         //! Copy constructor.
65         AI_Fast(const Player&);
66
67         //! Loading constructor. See XML_Helper for an explanation.
68         AI_Fast(XML_Helper* helper);
69
70         //! Destructor.
71         ~AI_Fast();
72         
73         virtual bool isComputer() const {return true;};
74
75         //! Saves data, the method is for saving additional data.
76         bool save(XML_Helper* helper) const;
77
78         //! Sets whether the ai joins close armies to make them stronger
79         void setJoin(bool join) {d_join = join;};
80
81         //! Returns the current behaviour regarding joining armies
82         bool getJoin() const {return d_join;};
83
84         //! Set maniac/normal mode
85         void setManiac(bool maniac) {d_maniac = maniac;};
86
87         //! Returns the current behaviour
88         bool getManiac() const {return d_maniac;};
89
90         virtual void abortTurn();
91         virtual bool startTurn();
92         virtual void invadeCity(City* c);
93         virtual bool chooseHero(HeroProto *hero, City* c, int gold);
94         virtual Reward *chooseReward(Ruin *ruin, Sage *sage, Stack *stack);
95         virtual void heroGainsLevel(Hero * a);
96         virtual bool chooseTreachery (Stack *stack, Player *player, Vector <int> pos);
97         virtual Army::Stat chooseStat(Hero *hero);
98         virtual bool chooseQuest(Hero *hero);
99
100     private:
101         //! The actual core function of the ai's logic.
102         bool computerTurn(); 
103
104         //! search through our stacklist for a stack we can join
105         Stack *findNearOwnStackToJoin(Stack *s, int max_distance);
106
107         //! produce the best low-turn high strength army unit.
108         int setBestProduction(City *c);
109
110         int scoreArmyType(const ArmyProdBase *a);
111
112         //! Determines whether to join units or move them separately.
113         bool d_join;
114
115         //! Maniac mode: kill and raze everything you encounter.
116         bool d_maniac;
117
118         AI_Analysis* d_analysis;
119         AI_Diplomacy* d_diplomacy;
120 };
121
122 #endif // AI_FAST_H