1 // Copyright (C) 2004 John Farrell 2 // Copyright (C) 2004, 2005 Ulf Lorenz 3 // Copyright (C) 2005, 2006 Andrea Paternesi 4 // Copyright (C) 2006 Vibhu Rishi 5 // Copyright (C) 2007, 2008, 2009, 2010, 2014 Ben Asselstine 6 // Copyright (C) 2007, 2008 Ole Laursen 7 // 8 // This program is free software; you can redistribute it and/or modify 9 // it under the terms of the GNU General Public License as published by 10 // the Free Software Foundation; either version 3 of the License, or 11 // (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU Library General Public License for more details. 17 // 18 // You should have received a copy of the GNU General Public License 19 // along with this program; if not, write to the Free Software 20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 // 02110-1301, USA. 22 23 #pragma once 24 #ifndef AI_SMART_H 25 #define AI_SMART_H 26 27 #include <list> 28 #include <gtkmm.h> 29 30 #include "real_player.h" 31 32 class Threatlist; 33 class Threat; 34 class XML_Helper; 35 class ArmyProdBase; 36 class ArmyProto; 37 class City; 38 class Location; 39 40 //! A more complex artificial intelligence Player. 41 /** 42 * After examining if it buys additional production, this AI uses the classical 43 * strategy technique of: 44 * - analyse the game situation - this involves identifying stacks and cities as 45 * threats, and deciding which are the greatest threats to which cities. 46 * - allocate resources to deal with the threats to our best advantage. 47 * 48 * TODO: Ruins are also identified as threats, though they are not handled yet. 49 * TODO: The Ai only buys basic productions 50 * TODO: The AI doesn't rally make use of the multifight, and it cannot really 51 * handle the results (not checked) 52 * TODO: The Ai should be able to upgrade cities (Increases their income etc.) 53 * TODO: AI is way too defensive (in fact, the fast AI tends to win games) 54 * 55 * The code is split up in several classes. Be sure to read the comments there 56 * before trying to read the code. :) 57 * 58 * - AI_Analysis includes the code for the assessment of the game situation 59 * - AI_Allocation distributes the AI's ressources the engage threats 60 * - Threat/Threatlist contains the code for the definition of single threats 61 * and the container class for threats 62 * - AICityInfo is used to collect the threats and reinforcements etc. of a 63 * single city of the AI. 64 * 65 * Also see the Player class for the derivation scheme of players. 66 */ 67 68 class AI_Smart : public RealPlayer 69 { 70 public: 71 /** 72 * Make a new AI_Smart player. 73 * 74 * @param name The name of the player. 75 * @param armyset The Id of the player's Armyset. 76 * @param color The player's colour. 77 * @param width The width of the player's FogMap. 78 * @param height The height of the player's FogMap. 79 * @param player_no The Id of the player. If this value is -1, 80 * the next free Id it used. 81 */ 82 //! Default constructor. 83 AI_Smart(Glib::ustring name, guint32 armyset, Gdk::RGBA color, 84 int width, int height, int player_no = -1); 85 86 //! Copy constructor. 87 AI_Smart(const Player&); 88 //! Loading constructor. See XML_Helper for an explanation. 89 AI_Smart(XML_Helper* helper); 90 //! Destructor. ~AI_Smart()91 ~AI_Smart() {}; 92 isComputer()93 virtual bool isComputer() const {return true;}; 94 virtual void abortTurn(); 95 virtual bool startTurn(); 96 virtual void invadeCity(City* c); 97 virtual bool chooseHero(HeroProto *hero, City* c, int gold); 98 virtual Reward *chooseReward(Ruin *ruin, Sage *sage, Stack *stack); 99 virtual void heroGainsLevel(Hero * a); 100 virtual bool chooseTreachery (Stack *stack, Player *player, Vector <int> pos); 101 virtual Army::Stat chooseStat(Hero *hero); 102 virtual bool chooseQuest(Hero *hero); 103 virtual bool computerChooseVisitRuin(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns); 104 virtual bool computerChoosePickupBag(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns); 105 virtual bool computerChooseVisitTempleForBlessing(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns); 106 virtual bool computerChooseVisitTempleForQuest(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns); 107 virtual bool computerChooseContinueQuest(Stack *stack, Quest *quest, Vector<int> dest, guint32 moves, guint32 turns); 108 109 private: 110 // Choose a new type of army to buy production for. 111 int chooseArmyTypeToBuy(City *c, bool quick); 112 113 // Consider buying new production for this city 114 int maybeBuyProduction(City *c, bool quick); 115 116 // Set the city to produce the best armies possible 117 void setProduction(City *c); 118 int setBestProduction(City *c); 119 int setQuickProduction(City *c); 120 121 // assign a score to an army type to try to figure out which is best 122 // which is best for buying 123 int scoreBestArmyType(const ArmyProto *proto); 124 //which is best for producing 125 int scoreBestArmyType(const ArmyProdBase *a); 126 //which is quickest for producing. 127 int scoreQuickArmyType(const ArmyProdBase *proto); 128 //which is quickest for buying 129 int scoreQuickArmyType(const ArmyProto *proto); 130 131 // suggest somewhere that a hero stack might like to visit 132 Location *getAlternateHeroTarget(Stack *s); 133 134 // what is the biggest danger to this city? 135 Threat *getBiggestDangerTo(City *city, Threatlist *threats); 136 137 // examine cities to see if we need to change production 138 void examineCities(); 139 140 // buy a scout if we need to 141 void maybeBuyScout(); 142 143 bool cityNewlyTaken(City *city, guint32 turns = 2) const; 144 145 // DATA 146 int d_mustmakemoney; // used to avoid to buy new production 147 // and to reinforce cities to earn more money 148 149 }; 150 151 #endif // AI_SMART_H 152