File: mapalgorithms.h

package info (click to toggle)
asc 2.6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 82,860 kB
  • ctags: 26,395
  • sloc: cpp: 158,660; sh: 11,274; ansic: 6,878; makefile: 604; perl: 138
file content (116 lines) | stat: -rw-r--r-- 4,749 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
                          mapalgorithms.h  -  description
                             -------------------
    begin                : Thu Oct 5 2000
    copyright            : (C) 2000 by Martin Bickel
    email                : bickel@asc-hq.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef mapalgorithmsH
 #define mapalgorithmsH

 #include "typen.h"
 #include "vehicle.h"
 #include "loki/Functor.h"
 #include "loki/Typelist.h"

  /** searches fields in hexagonal "circles" around a field and calls testfield for each field
  */
  class   SearchFields {
                protected:
                    GameMap* gamemap;
                    MapCoordinate startPos;
                    bool        cancelSearch;
                    int         firstDistance, lastDistance;
                    int         dist;
                    virtual void testfield ( const MapCoordinate& pos ) = 0;
                public:
                    SearchFields ( GameMap* _gamemap );
                    void initsearch ( const MapCoordinate& startPosition, int _firstDistance, int _lastDistance );
                    virtual void startsearch ( void );
                    virtual ~SearchFields() {};
                 };

  typedef Loki::Functor<void, LOKI_TYPELIST_1(const MapCoordinate&) > FieldIterationFunctor;
  extern void circularFieldIterator( GameMap* gamemap, const MapCoordinate& center, int startDist, int stopDist, FieldIterationFunctor functor ); 

                 
  /** draws a straight line on the hexagonal map and calls putpix8 for each field.
      Awfully unoptimized!
  */
  class tdrawgettempline  {
                  int freefields;
                  int num;
                  int sx, sy;

                  static int initialized;
                  static double dirs[ sidenum ];
                  static double offset;

                  void init ( void );

               protected:
                  GameMap* gamemap;

               public:
                   int tempsum;
                   tdrawgettempline ( int _freefields, GameMap* _gamemap );

                   void start ( int x1, int y1, int x2, int y2 );

                   virtual void putpix8 ( int x, int y );
                   double winkel ( int x, int y );
                   int winkelcomp ( double w1, double w2 );
                   virtual ~tdrawgettempline() {};
              };

static const int dxLookup [] = { 0, 1, 1, 0, -1, -1 };
extern inline int getnextdx( int dir, int y ){ return ((y & 1) == (dir <= 2)) * dxLookup[dir]; }

static const int dyLookup [] = { -2, -1, 1, 2, 1, -1 };
extern inline int getnextdy( int dir) { return dyLookup[dir]; }

//! returns the coordinate of the field that is adjecent to the given field in the direction of direc
extern MapCoordinate3D  getNeighbouringFieldCoordinate( const MapCoordinate3D& pos, int direc);
extern MapCoordinate    getNeighbouringFieldCoordinate( const MapCoordinate  & pos, int direc);


/** gets the direction from x1/y1 to x2/y2
  \returns -1 if the fields are identical
*/
extern int   getdirection(    int      x1,
                              int      y1,
                              int      x2,
                              int      y2);
extern int   getdirection( const MapCoordinate& start, const MapCoordinate& dest );

//! returns the distance between (x1/y1) and (x2/y2)
extern int beeline ( int x1, int y1, int x2, int y2 );

//! returns the distance between the units a and b
extern int beeline ( const Vehicle* a, const Vehicle* b );

//! returns the distance between map positions a and b
extern int beeline ( const MapCoordinate& a, const MapCoordinate& b );

//! caches some calculations for the effects that wind has on the movement of units
class WindMovement {
      int wm[6];
   public:
      WindMovement ( const Vehicle* vehicle );
      inline int getDist ( int dir ) { assert( dir >= 0 && dir <= 5 ); return wm[dir]; };
      inline int getDist ( int dir ) const { assert( dir >= 0 && dir <= 5 ); return wm[dir]; };
};


#endif