Advanced Strategic Command
mapalgorithms.h
Go to the documentation of this file.
1 /***************************************************************************
2  mapalgorithms.h - description
3  -------------------
4  begin : Thu Oct 5 2000
5  copyright : (C) 2000 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 mapalgorithmsH
19  #define mapalgorithmsH
20 
21  #include "typen.h"
22  #include "vehicle.h"
23  #include "loki/Functor.h"
24  #include "loki/Typelist.h"
25 
28  class SearchFields {
29  protected:
34  int dist;
35  virtual void testfield ( const MapCoordinate& pos ) = 0;
36  public:
37  SearchFields ( GameMap* _gamemap );
38  void initsearch ( const MapCoordinate& startPosition, int _firstDistance, int _lastDistance );
39  virtual void startsearch ( void );
40  virtual ~SearchFields() {};
41  };
42 
43  typedef Loki::Functor<void, LOKI_TYPELIST_1(const MapCoordinate&) > FieldIterationFunctor;
44  extern void circularFieldIterator( GameMap* gamemap, const MapCoordinate& center, int startDist, int stopDist, FieldIterationFunctor functor );
45 
46 
51  int freefields;
52  int num;
53  int sx, sy;
54 
55  static int initialized;
56  static double dirs[ sidenum ];
57  static double offset;
58 
59  void init ( void );
60 
61  protected:
63 
64  public:
65  int tempsum;
66  tdrawgettempline ( int _freefields, GameMap* _gamemap );
67 
68  void start ( int x1, int y1, int x2, int y2 );
69 
70  virtual void putpix8 ( int x, int y );
71  double winkel ( int x, int y );
72  int winkelcomp ( double w1, double w2 );
73  virtual ~tdrawgettempline() {};
74  };
75 
76 static const int dxLookup [] = { 0, 1, 1, 0, -1, -1 };
77 extern inline int getnextdx( int dir, int y ){ return ((y & 1) == (dir <= 2)) * dxLookup[dir]; }
78 
79 static const int dyLookup [] = { -2, -1, 1, 2, 1, -1 };
80 extern inline int getnextdy( int dir) { return dyLookup[dir]; }
81 
84 extern MapCoordinate getNeighbouringFieldCoordinate( const MapCoordinate & pos, int direc);
85 
86 
90 extern int getdirection( int x1,
91  int y1,
92  int x2,
93  int y2);
94 extern int getdirection( const MapCoordinate& start, const MapCoordinate& dest );
95 
97 extern int beeline ( int x1, int y1, int x2, int y2 );
98 
100 extern int beeline ( const Vehicle* a, const Vehicle* b );
101 
103 extern int beeline ( const MapCoordinate& a, const MapCoordinate& b );
104 
107  int wm[6];
108  public:
109  WindMovement ( const Vehicle* vehicle );
110  inline int getDist ( int dir ) { assert( dir >= 0 && dir <= 5 ); return wm[dir]; };
111  inline int getDist ( int dir ) const { assert( dir >= 0 && dir <= 5 ); return wm[dir]; };
112 };
113 
114 
115 #endif
116 
static const int dyLookup[]
Definition: mapalgorithms.h:79
MapCoordinate3D getNeighbouringFieldCoordinate(const MapCoordinate3D &pos, int direc)
returns the coordinate of the field that is adjecent to the given field in the direction of direc ...
int winkelcomp(double w1, double w2)
void start(int x1, int y1, int x2, int y2)
int getDist(int dir)
static const int dxLookup[]
Definition: mapalgorithms.h:76
const int sidenum
the number of sides that a field has; is now fixed at 6;
Definition: typen.h:438
void circularFieldIterator(GameMap *gamemap, const MapCoordinate &center, int startDist, int stopDist, FieldIterationFunctor functor)
int getdirection(int x1, int y1, int x2, int y2)
gets the direction from x1/y1 to x2/y2
GameMap * gamemap
Definition: mapalgorithms.h:62
SearchFields(GameMap *_gamemap)
void initsearch(const MapCoordinate &startPosition, int _firstDistance, int _lastDistance)
Coordinate on the twodimensional map.
Definition: typen.h:202
double winkel(int x, int y)
searches fields in hexagonal "circles" around a field and calls testfield for each field ...
Definition: mapalgorithms.h:28
draws a straight line on the hexagonal map and calls putpix8 for each field.
Definition: mapalgorithms.h:50
int getnextdx(int dir, int y)
Definition: mapalgorithms.h:77
virtual void startsearch(void)
MapCoordinate startPos
Definition: mapalgorithms.h:31
tdrawgettempline(int _freefields, GameMap *_gamemap)
int getnextdy(int dir)
Definition: mapalgorithms.h:80
caches some calculations for the effects that wind has on the movement of units
int beeline(int x1, int y1, int x2, int y2)
returns the distance between (x1/y1) and (x2/y2)
virtual ~tdrawgettempline()
Definition: mapalgorithms.h:73
virtual ~SearchFields()
Definition: mapalgorithms.h:40
Coordinate on the map including height.
Definition: typen.h:238
virtual void testfield(const MapCoordinate &pos)=0
int getDist(int dir) const
virtual void putpix8(int x, int y)
GameMap * gamemap
Definition: mapalgorithms.h:30
WindMovement(const Vehicle *vehicle)
Loki::Functor< void, LOKI_TYPELIST_1(const MapCoordinate &) > FieldIterationFunctor
Definition: mapalgorithms.h:43
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182