~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/ai_fast.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
//
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
10
17
//
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 
 
21
//  02110-1301, USA.
14
22
 
15
23
#include <stdlib.h>
16
24
#include <algorithm>
78
86
 
79
87
bool AI_Fast::startTurn()
80
88
{
 
89
    // maniac AI's never recruit heroes, otherwise take everything we can get
 
90
    if (!d_maniac)
 
91
      maybeRecruitHero();
 
92
    
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")
84
96
 
85
 
    RealPlayer::startTurn();
86
 
 
87
97
    d_analysis = new AI_Analysis(this);
88
98
    d_diplomacy = new AI_Diplomacy(this);
 
99
 
 
100
    d_diplomacy->considerCuspOfWar();
89
101
    
90
102
    // this is a recursively-programmed quite staightforward AI,we just call:
91
103
    computerTurn();
100
112
    return true;
101
113
}
102
114
 
103
 
bool AI_Fast::invadeCity(City* c)
104
 
{
105
 
    debug("Invaded city " <<c->getName())
106
 
 
107
 
    // There are two modes: maniac razes all cities, non-maniac just
108
 
    // occupies them
109
 
    if (d_maniac)
110
 
    {
111
 
        debug ("Razing it")
112
 
        bool retval = cityRaze(c);
113
 
        sinvadingCity.emit(c);
114
 
        return retval;
115
 
    }
116
 
 
117
 
    debug("Occupying it")
118
 
    bool retval = cityOccupy(c);
119
 
    sinvadingCity.emit(c);
120
 
    soccupyingCity.emit(c, getActivestack());
121
 
 
122
 
    return retval;
123
 
}
124
 
 
125
 
bool AI_Fast::recruitHero(Hero* hero, City *city, int cost)
126
 
{
127
 
    debug("AI_Fast: hero offers service")
128
 
 
129
 
    // maniac AI's never recruit heroes, otherwise take everything we can get
130
 
    if (d_maniac)
131
 
        return false;
132
 
 
133
 
    return true;
134
 
}
135
 
 
136
 
bool AI_Fast::levelArmy(Army* a)
137
 
{
138
 
    if (!a->canGainLevel())
139
 
        return false;
140
 
 
 
115
void AI_Fast::invadeCity(City* c)
 
116
{
 
117
  debug("Invaded city " <<c->getName());
 
118
 
 
119
  // There are two modes: maniac razes all cities, non-maniac just
 
120
  // occupies them
 
121
  if (d_maniac)
 
122
  {
 
123
    debug ("Razing it");
 
124
    cityRaze(c);
 
125
  }
 
126
  else
 
127
  {
 
128
    debug("Occupying it");
 
129
    cityOccupy(c);
 
130
  }
 
131
}
 
132
 
 
133
void AI_Fast::levelArmy(Army* a)
 
134
{
141
135
    debug("Army raised a level, id = " <<a->getId())
142
136
    
143
137
    //advancing a level
144
138
    // increase the strength attack (uninnovative, but enough here)
145
139
    Army::Stat stat = Army::STRENGTH;
146
 
    a->gainLevel(stat);
 
140
    doLevelArmy(a, stat);
147
141
 
148
142
    Action_Level* item = new Action_Level();
149
 
    item->fillData(a->getId(), stat);
150
 
    d_actions.push_back(item);
151
 
 
152
 
    return true;
 
143
    item->fillData(a, stat);
 
144
    addAction(item);
153
145
}
154
146
 
155
147
void AI_Fast::computerTurn()
262
254
                target2 = cl->getNearestForeignCity(s->getPos());
263
255
                if (target1)
264
256
                  target1_path->calculate (s, target1->getPos());
 
257
                if (!target2)
 
258
                  return; //it's game over and we're still moving
265
259
                target2_path->calculate (s, target2->getPos());
266
260
                if (!target1)
267
261
                  target = target2;
272
266
 
273
267
                if (target == target2)
274
268
                  {
275
 
                    d_diplomacy->needNewEnemy(target->getPlayer());
 
269
                    d_diplomacy->needNewEnemy(target->getOwner());
276
270
                    // try to wait a turn until we're at war
277
271
                    if (target1)
278
272
                      target = target1;
364
358
                City *friendly_city = cl->getNearestFriendlyCity(s->getPos());
365
359
                s->getPath()->calculate(s, friendly_city->getPos());
366
360
                stackMove(s);
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
370
361
              }
371
362
 
372
363
            if (!d_stacklist->getActivestack())