1
// Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
2
// Copyright (C) 2003 Michael Bartl
3
// Copyright (C) 2004, 2006 Andrea Paternesi
4
// Copyright (C) 2004 John Farrell
5
// Copyright (C) 2006, 2007, 2008 Ben Asselstine
6
// Copyright (C) 2007, 2008 Ole Laursen
1
8
// This program is free software; you can redistribute it and/or modify
2
9
// it under the terms of the GNU General Public License as published by
3
10
// the Free Software Foundation; either version 2 of the License, or
11
18
// You should have received a copy of the GNU General Public License
12
19
// along with this program; if not, write to the Free Software
13
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
23
#include <stdlib.h>
16
24
#include <algorithm>
79
87
bool AI_Fast::startTurn()
89
// maniac AI's never recruit heroes, otherwise take everything we can get
81
93
debug(getName() << ": AI_Fast::start_turn")
82
94
debug("being in " <<(d_maniac?"maniac":"normal") <<" mode")
83
95
debug((d_join?"":"not ") <<"joining armies")
85
RealPlayer::startTurn();
87
97
d_analysis = new AI_Analysis(this);
88
98
d_diplomacy = new AI_Diplomacy(this);
100
d_diplomacy->considerCuspOfWar();
90
102
// this is a recursively-programmed quite staightforward AI,we just call:
103
bool AI_Fast::invadeCity(City* c)
105
debug("Invaded city " <<c->getName())
107
// There are two modes: maniac razes all cities, non-maniac just
112
bool retval = cityRaze(c);
113
sinvadingCity.emit(c);
117
debug("Occupying it")
118
bool retval = cityOccupy(c);
119
sinvadingCity.emit(c);
120
soccupyingCity.emit(c, getActivestack());
125
bool AI_Fast::recruitHero(Hero* hero, City *city, int cost)
127
debug("AI_Fast: hero offers service")
129
// maniac AI's never recruit heroes, otherwise take everything we can get
136
bool AI_Fast::levelArmy(Army* a)
138
if (!a->canGainLevel())
115
void AI_Fast::invadeCity(City* c)
117
debug("Invaded city " <<c->getName());
119
// There are two modes: maniac razes all cities, non-maniac just
128
debug("Occupying it");
133
void AI_Fast::levelArmy(Army* a)
141
135
debug("Army raised a level, id = " <<a->getId())
143
137
//advancing a level
144
138
// increase the strength attack (uninnovative, but enough here)
145
139
Army::Stat stat = Army::STRENGTH;
140
doLevelArmy(a, stat);
148
142
Action_Level* item = new Action_Level();
149
item->fillData(a->getId(), stat);
150
d_actions.push_back(item);
143
item->fillData(a, stat);
155
147
void AI_Fast::computerTurn()
262
254
target2 = cl->getNearestForeignCity(s->getPos());
264
256
target1_path->calculate (s, target1->getPos());
258
return; //it's game over and we're still moving
265
259
target2_path->calculate (s, target2->getPos());
267
261
target = target2;
364
358
City *friendly_city = cl->getNearestFriendlyCity(s->getPos());
365
359
s->getPath()->calculate(s, friendly_city->getPos());
367
//FIXME: again, we should be able to reach any city,
368
//but we can't reach this one. just go to the nearest city
369
//instead. this is an error in map generation
372
363
if (!d_stacklist->getActivestack())