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 "../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
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