1 // Copyright (C) 2002, 2003, 2004, 2005 Ulf Lorenz
2 // Copyright (C) 2003 Michael Bartl
3 // Copyright (C) 2006 Andrea Paternesi
4 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
5 // Copyright (C) 2007, 2008 Ole Laursen
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.
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.
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
25 #include "playerlist.h"
26 #include "armysetlist.h"
27 #include "stacklist.h"
33 #include "xmlhelper.h"
35 #include "GameScenarioOptions.h"
38 #define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
43 AI_Dummy::AI_Dummy(std::string name, guint32 armyset, Gdk::Color color, int width, int height, int player_no)
44 :RealPlayer(name, armyset, color, width, height, Player::AI_DUMMY, player_no)
48 AI_Dummy::AI_Dummy(const Player& player)
54 AI_Dummy::AI_Dummy(XML_Helper* helper)
63 void AI_Dummy::abortTurn()
65 abort_requested = true;
70 void AI_Dummy::setDefensiveProduction(City *city)
72 if (city->getActiveProductionSlot() == -1 &&
73 city->countDefenders() < MAX_ARMIES_PRODUCED_IN_NEUTRAL_CITY)
77 int idx = rand() % city->getMaxNoOfProductionBases();
78 cityChangeProduction(city, idx);
83 std::list<Action_Produce *> actions = getUnitsProducedThisTurn();
84 std::list<Action_Produce *>::iterator it = actions.begin();
85 for (; it != actions.end(); it++)
87 if ((*it)->getCityId() == city->getId())
89 cityChangeProduction(city, -1);
94 //if production is stopped, then start it.
95 //if an army arrived this turn, stop production.
97 void AI_Dummy::examineCities()
99 debug("Examinating Cities to see what we can do")
100 Citylist* cl = Citylist::getInstance();
101 for (Citylist::iterator it = cl->begin(); it != cl->end(); ++it)
104 if ((city->isFriend(this)) && (city->isBurnt()==false))
105 setDefensiveProduction(city);
109 bool AI_Dummy::startTurn()
112 if (GameScenarioOptions::s_neutral_cities == GameParameters::DEFENSIVE)
114 //setup production defensive style.
120 Citylist* cl = Citylist::getInstance();
121 for (Citylist::iterator it = cl->begin(); it != cl->end(); ++it)
124 if ((city->isFriend(this)) && (city->isBurnt()==false))
125 city->setActiveProductionSlot(-1);
130 //this is a dummy AI (neutral player) so there is not much point in
137 void AI_Dummy::invadeCity(City* c)
139 //dummy ai player should never invade an enemy city, but if it happens, we
140 //make sure there is no inconsistency
144 void AI_Dummy::heroGainsLevel(Hero * a)
146 Army::Stat stat = Army::STRENGTH;
147 doHeroGainsLevel(a, stat);
149 Action_Level* item = new Action_Level();
150 item->fillData(a, stat);
154 bool AI_Dummy::chooseHero(HeroProto *hero, City *city, int gold)
156 //neutral players never accept heroes.
160 Reward *AI_Dummy::chooseReward(Ruin *ruin, Sage *sage, Stack *stack)
162 //neutrals don't search ruins, but let's not return null.
163 return sage->front();
166 bool AI_Dummy::chooseTreachery (Stack *stack, Player *player, Vector <int> pos)
168 //neutrals don't leave the castle.
169 bool performTreachery = true;
170 return performTreachery;
173 Army::Stat AI_Dummy::chooseStat(Hero *hero)
175 //neutrals don't have heroes.
176 return Army::STRENGTH;
179 bool AI_Dummy::chooseQuest(Hero *hero)
181 //neutrals don't have heroes.