Advanced Strategic Command
ai_common.h
Go to the documentation of this file.
1 /***************************************************************************
2  ai_common.h - description
3  -------------------
4  begin : Fri Mar 30 2001
5  copyright : (C) 2001 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef ai_common_h_included
19  #define ai_common_h_included
20 
21  #ifdef karteneditor
22  #error The mapeditor does not need any AI
23  #endif
24 
25 
26  // This header collects all other headers used by the various AI files so
27  // compilers that are able to use precompiled headers may do so.
28 
29 #include <stdio.h>
30 #include <string.h>
31 #include <cstdlib>
32 #include <math.h>
33 #include <algorithm>
34 #include <memory>
35 #include <float.h>
36 
37 #include "ai.h"
38 
39 #include "../typen.h"
40 #include "../vehicletype.h"
41 #include "../buildingtype.h"
42 #include "../misc.h"
43 #include "../events.h"
44 #include "../spfst.h"
45 #include "../dlg_box.h"
46 #include "../stack.h"
47 #include "../controls.h"
48 #include "../dialog.h"
49 // #include "../gamedlg.h"
50 #include "../attack.h"
51 #include "../gameoptions.h"
52 #include "../astar2.h"
53 #include "../resourcenet.h"
54 #include "../itemrepository.h"
55 #include "../containercontrols.h"
56 #include "../viewcalculation.h"
57 #include "../replay.h"
58 #include "../textfiletags.h"
59 
60 
61 extern const int currentServiceOrderVersion;
62 
64  class StratAStar3D : public AStar3D {
65  AI* ai;
66  protected:
67  virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& hasAttacked )
68  {
69  DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, hasAttacked );
70  if ( ai->getMap()->getField ( dest )->vehicle && beeline ( vehicle->xpos, vehicle->ypos, dest.x, dest.y) < vehicle->getMovement())
71  cost += 2;
72  return cost;
73  };
74  public:
75  StratAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
76  };
77 
79  class AntiMineAStar3D : public AStar3D {
80  AI* ai;
81  protected:
82  virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& hasAttacked )
83  {
84  DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, hasAttacked );
85  MapField* f = ai->getMap()->getField ( dest );
86  if ( f->mineattacks(vehicle) )
87  cost += 1;
88  return cost;
89  };
90  public:
91  AntiMineAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
92  };
93 
94 
96  class HiddenAStar3D : public AStar3D {
97  AI* ai;
98  protected:
99  virtual DistanceType getMoveCost ( const MapCoordinate3D& start, const MapCoordinate3D& dest, const Vehicle* vehicle, bool& hasAttacked )
100  {
101  DistanceType cost = AStar3D::getMoveCost ( start, dest, vehicle, hasAttacked );
102  int visibility = ai->getMap()->getField ( dest )->visible;
103  int visnum = 0;
104  int enemynum = 0;
105  for ( int i = 0; i< 8; i++ )
106  if ( ai->getMap()->player[i].diplomacy.isHostile( ai->getPlayerNum() ) ) {
107  enemynum++;
108  int v = (visibility >> ( 2*i)) & 3;
109  if ( v >= visible_now )
110  visnum++;
111  }
112  if ( enemynum )
113  cost += 12 * visnum / enemynum;
114 
115  return cost;
116  };
117  public:
118  HiddenAStar3D ( AI* _ai, Vehicle* veh, bool markTemps_ = true ) : AStar3D ( _ai->getMap(), veh, markTemps_ ), ai ( _ai ) {};
119  };
120 
121 
122 #endif
virtual DistanceType getMoveCost(const MapCoordinate3D &start, const MapCoordinate3D &dest, const Vehicle *vehicle, bool &hasAttacked)
Definition: ai_common.h:67
GameMap * getMap(void)
returns the map this AI runson
Definition: ai.h:486
Vehicle * vehicle
Definition: mapfield.h:89
bool isHostile(PlayerID towardsPlayer) const
Definition: player.h:80
A 3D path finding algorithm which tries to keep the units hidden from view.
Definition: ai_common.h:96
DiplomaticStateVector diplomacy
Definition: player.h:209
StratAStar3D(AI *_ai, Vehicle *veh, bool markTemps_=true)
Definition: ai_common.h:75
a single field of the map
Definition: mapfield.h:26
Definition: ai.h:44
int beeline(const Vehicle *a, const Vehicle *b)
returns the distance between the units a and b
int getPlayerNum(void)
returns the number of the player which is controlled by this ai
Definition: ai.h:490
A 3D path finding algorithm which avoids units to jam; used by the AI's strategy module.
Definition: ai_common.h:64
Uint16 visible
can this field be seen be the player. Variable is bitmapped; two bits for each player. These two bits can have the states defined in VisibilityStates
Definition: mapfield.h:63
virtual DistanceType getMoveCost(const MapCoordinate3D &start, const MapCoordinate3D &dest, const Vehicle *vehicle, bool &hasAttacked)
Definition: astar2.cpp:221
float DistanceType
Definition: astar2.h:21
Player player[9]
Definition: gamemap.h:253
HiddenAStar3D(AI *_ai, Vehicle *veh, bool markTemps_=true)
Definition: ai_common.h:118
virtual DistanceType getMoveCost(const MapCoordinate3D &start, const MapCoordinate3D &dest, const Vehicle *vehicle, bool &hasAttacked)
Definition: ai_common.h:82
AntiMineAStar3D(AI *_ai, Vehicle *veh, bool markTemps_=true)
Definition: ai_common.h:91
const int currentServiceOrderVersion
Definition: service.cpp:59
int xpos
the position on the map
Definition: vehicle.h:124
The interface for the artificial intelligence of ASC.
Coordinate on the map including height.
Definition: typen.h:238
A 3D path finding algorithm, based on the 2D algorithm by Amit J. Patel.
Definition: astar2.h:19
virtual DistanceType getMoveCost(const MapCoordinate3D &start, const MapCoordinate3D &dest, const Vehicle *vehicle, bool &hasAttacked)
Definition: ai_common.h:99
Vehicle * veh
Definition: astar2.h:79
int ypos
Definition: vehicle.h:124
int getMovement(bool checkFuel=true, bool checkRF=true) const
returns the movement points the unit has left for this turn. CheckFuel should almost always be true...
Definition: vehicle.cpp:558
A 3D path finding algorithm which avoids units to jam; used by the AI's strategy module.
Definition: ai_common.h:79
int mineattacks(const Vehicle *veh)
can any of the mines on this field attack this unit
Definition: mapfield.cpp:194
MapField * getField(int x, int y)
Definition: gamemap.h:465