00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00027
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
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