Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ai_common.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           ai_common.h  -  description
00003                              -------------------
00004     begin                : Fri Mar 30 2001
00005     copyright            : (C) 2001 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef ai_common_h_included
00019  #define ai_common_h_included
00020 
00021  #ifdef karteneditor
00022  #error The mapeditor does not need any AI
00023  #endif
00024 
00025 
00026  // This header collects all other headers used by the various AI files so
00027  // compilers that are able to use precompiled headers may do so.
00028 
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <cstdlib>
00032 #include <math.h>
00033 #include <algorithm>
00034 #include <memory>
00035 #include <float.h>
00036 
00037 #include "ai.h"
00038 
00039 #include "../typen.h"
00040 #include "../vehicletype.h"
00041 #include "../buildingtype.h"
00042 #include "../misc.h"
00043 #include "../newfont.h"
00044 #include "../events.h"
00045 #include "../spfst.h"
00046 #include "../dlg_box.h"
00047 #include "../stack.h"
00048 #include "../controls.h"
00049 #include "../dialog.h"
00050 // #include "../gamedlg.h"
00051 #include "../attack.h"
00052 #include "../gameoptions.h"
00053 #include "../astar2.h"
00054 #include "../resourcenet.h"
00055 #include "../itemrepository.h"
00056 #include "../containercontrols.h"
00057 #include "../viewcalculation.h"
00058 #include "../replay.h"
00059 #include "../textfiletags.h"
00060 
00061 
00062 extern const int currentServiceOrderVersion;
00063 
00065   class StratAStar : public AStar {
00066        AI* ai;
00067     protected:
00068        virtual int getMoveCost ( int x1, int y1, int x2, int y2, const Vehicle* vehicle )
00069        {
00070           int cost = AStar::getMoveCost ( x1, y1, x2, y2, vehicle );
00071           if ( getfield ( x2, y2 )->vehicle && beeline ( vehicle->xpos, vehicle->ypos, x2, y2) < vehicle->getMovement())
00072              cost += 2;
00073           return cost;
00074        };
00075     public:
00076        StratAStar ( AI* _ai, Vehicle* veh ) : AStar ( _ai->getMap(), veh ), ai ( _ai ) {};
00077  };
00078 
00080   class StratAStar3D : public AStar3D {
00081        AI* ai;
00082     protected:
00083        virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& canStop, bool& hasAttacked )
00084        {
00085           DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, canStop, hasAttacked );
00086           if ( ai->getMap()->getField ( dest )->vehicle && beeline ( vehicle->xpos, vehicle->ypos, dest.x, dest.y) < vehicle->getMovement())
00087              cost += 2;
00088           return cost;
00089        };
00090     public:
00091        StratAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
00092  };
00093 
00094 
00096  class HiddenAStar : public AStar {
00097        AI* ai;
00098     protected:
00099        virtual int getMoveCost ( int x1, int y1, int x2, int y2, const Vehicle* vehicle )
00100        {
00101           int cost = AStar::getMoveCost ( x1, y1, x2, y2, vehicle );
00102           int visibility = getfield ( x2, y2 )->visible;
00103           int visnum = 0;
00104           int enemynum = 0;
00105           for ( int i = 0; i< 8; i++ )
00106              if ( actmap->player[i].diplomacy.isHostile( ai->getPlayerNum() ) ) {
00107                 enemynum++;
00108                 int v = (visibility >> ( 2*i)) & 3;
00109                 if ( v >= visible_now )
00110                    visnum++;
00111              }
00112           if ( enemynum )
00113              cost += 12 * visnum / enemynum;
00114 
00115           return cost;
00116        };
00117     public:
00118        HiddenAStar ( AI* _ai, Vehicle* veh ) : AStar ( _ai->getMap(), veh ), ai ( _ai ) {};
00119  };
00120 
00121 
00123  class HiddenAStar3D : public AStar3D {
00124        AI* ai;
00125     protected:
00126        virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& canStop, bool& hasAttacked )
00127        {
00128           DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, canStop, hasAttacked );
00129           int visibility = ai->getMap()->getField ( dest )->visible;
00130           int visnum = 0;
00131           int enemynum = 0;
00132           for ( int i = 0; i< 8; i++ )
00133              if ( actmap->player[i].diplomacy.isHostile( ai->getPlayerNum() ) ) {
00134                 enemynum++;
00135                 int v = (visibility >> ( 2*i)) & 3;
00136                 if ( v >= visible_now )
00137                    visnum++;
00138              }
00139           if ( enemynum )
00140              cost += 12 * visnum / enemynum;
00141 
00142           return cost;
00143        };
00144     public:
00145        HiddenAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
00146  };
00147 
00148 
00149 #endif

Generated on Tue Jun 24 01:27:34 2008 for Advanced Strategic Command by  doxygen 1.4.2