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 "../events.h"
00044 #include "../spfst.h"
00045 #include "../dlg_box.h"
00046 #include "../stack.h"
00047 #include "../controls.h"
00048 #include "../dialog.h"
00049 // #include "../gamedlg.h"
00050 #include "../attack.h"
00051 #include "../gameoptions.h"
00052 #include "../astar2.h"
00053 #include "../resourcenet.h"
00054 #include "../itemrepository.h"
00055 #include "../containercontrols.h"
00056 #include "../viewcalculation.h"
00057 #include "../replay.h"
00058 #include "../textfiletags.h"
00059 
00060 
00061 extern const int currentServiceOrderVersion;
00062 
00064   class StratAStar : public AStar {
00065        AI* ai;
00066     protected:
00067        virtual int getMoveCost ( int x1, int y1, int x2, int y2, const Vehicle* vehicle )
00068        {
00069           int cost = AStar::getMoveCost ( x1, y1, x2, y2, vehicle );
00070           if ( ai->getMap()->getField ( x2, y2 )->vehicle && beeline ( vehicle->xpos, vehicle->ypos, x2, y2) < vehicle->getMovement())
00071              cost += 2;
00072           return cost;
00073        };
00074     public:
00075        StratAStar ( AI* _ai, Vehicle* veh ) : AStar ( _ai->getMap(), veh ), ai ( _ai ) {};
00076  };
00077 
00079   class StratAStar3D : public AStar3D {
00080        AI* ai;
00081     protected:
00082        virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& canStop, bool& hasAttacked )
00083        {
00084           DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, canStop, hasAttacked );
00085           if ( ai->getMap()->getField ( dest )->vehicle && beeline ( vehicle->xpos, vehicle->ypos, dest.x, dest.y) < vehicle->getMovement())
00086              cost += 2;
00087           return cost;
00088        };
00089     public:
00090        StratAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
00091  };
00092 
00094  class AntiMineAStar3D : public AStar3D {
00095     AI* ai;
00096     protected:
00097        virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& canStop, bool& hasAttacked )
00098        {
00099           DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, canStop, hasAttacked );
00100           MapField* f = ai->getMap()->getField ( dest );
00101           if ( f->mineattacks(vehicle) )
00102              cost += 1;
00103           return cost;
00104        };
00105     public:
00106        AntiMineAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
00107  };
00108  
00109 
00111  class HiddenAStar : public AStar {
00112        AI* ai;
00113     protected:
00114        virtual int getMoveCost ( int x1, int y1, int x2, int y2, const Vehicle* vehicle )
00115        {
00116           int cost = AStar::getMoveCost ( x1, y1, x2, y2, vehicle );
00117           int visibility = ai->getMap()->getField ( x2, y2 )->visible;
00118           int visnum = 0;
00119           int enemynum = 0;
00120           for ( int i = 0; i< 8; i++ )
00121              if ( ai->getMap()->player[i].diplomacy.isHostile( ai->getPlayerNum() ) ) {
00122                 enemynum++;
00123                 int v = (visibility >> ( 2*i)) & 3;
00124                 if ( v >= visible_now )
00125                    visnum++;
00126              }
00127           if ( enemynum )
00128              cost += 12 * visnum / enemynum;
00129 
00130           return cost;
00131        };
00132     public:
00133        HiddenAStar ( AI* _ai, Vehicle* veh ) : AStar ( _ai->getMap(), veh ), ai ( _ai ) {};
00134  };
00135 
00136 
00138  class HiddenAStar3D : public AStar3D {
00139        AI* ai;
00140     protected:
00141        virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& canStop, bool& hasAttacked )
00142        {
00143           DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, canStop, hasAttacked );
00144           int visibility = ai->getMap()->getField ( dest )->visible;
00145           int visnum = 0;
00146           int enemynum = 0;
00147           for ( int i = 0; i< 8; i++ )
00148              if ( ai->getMap()->player[i].diplomacy.isHostile( ai->getPlayerNum() ) ) {
00149                 enemynum++;
00150                 int v = (visibility >> ( 2*i)) & 3;
00151                 if ( v >= visible_now )
00152                    visnum++;
00153              }
00154           if ( enemynum )
00155              cost += 12 * visnum / enemynum;
00156 
00157           return cost;
00158        };
00159     public:
00160        HiddenAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
00161  };
00162 
00163 
00164 #endif

Generated on Mon May 14 01:31:39 2012 for Advanced Strategic Command by  doxygen 1.5.1