ALMaSS Rabbit ODdox  1.1
The rabbit model description following ODdox protocol
rastermap.h
Go to the documentation of this file.
1 //
2 // rastermap.h
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2011, Christopher John Topping, University of Aarhus
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without modification, are permitted provided
10 that the following conditions are met:
11 
12 Redistributions of source code must retain the above copyright notice, this list of conditions and the
13 following disclaimer.
14 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
15 the following disclaimer in the documentation and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
20 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ********************************************************************************************************
26 */
27 
28 #ifndef RASTERMAP_H
29 #define RASTERMAP_H
30 
31 #include <cstdlib>
32 using namespace std;
33 
34 class Landscape;
35 
36 // #define to enable range checking of map coordinates.
37 //#define RASTERMAP_XY_RANGE
38 // Currently unused.
39 
40 class RasterMap
41 {
42  char m_id[12];
43  int *m_map;
44  int m_width;
45  int m_height;
46  int m_x;
47  int m_y;
49 
50 public:
51  // We want to force these to be inline functions.
52  int MapWidth( void ) { return m_width; }
53  int MapHeight( void ) { return m_height; }
54  int Get( int a_x, int a_y );
55  char* GetID( void ) { return m_id; }
56  int* GetMagicP( int a_x, int a_y );
57  void Put( int a_x, int a_y, int a_elem ) { m_map[ a_y * m_width + a_x ] = a_elem; }
58  RasterMap(const char* a_mapfile, Landscape * m_landscape);
59  ~RasterMap( void );
60  void Manipulation1();
62  int CellReplacementNeighbour(int a_x, int a_y, int a_polyref);
64  bool MissingCellReplace(int a_x, int a_y, bool a_fieldsonly);
66  bool MissingCellReplaceWrap(int a_x, int a_y, bool a_fieldsonly);
67 protected:
68  void Init1(const char* a_mapfile, Landscape * m_landscape);
69  void Init2(const char* a_mapfile, Landscape * m_landscape);
70 };
71 
72 
73 
74 inline int* RasterMap::GetMagicP( int a_x, int a_y )
75 {
76  return &m_map[ a_y * m_width + a_x ];
77 }
78 
79 
80 
81 inline int RasterMap::Get( int a_x, int a_y ) {
82  if (a_x<0 || a_x>=m_width ||
83  a_y<0 || a_y>=m_height ) {
84  g_msg->Warn( WARN_BUG, "RasterMap::Get(): Coordinates out of range!", "" );
85  g_msg->WarnAddInfo(WARN_BUG, "X Coord ", a_x);
86  g_msg->WarnAddInfo(WARN_BUG, "Y Coord ", a_y);
87  g_msg->WarnAddInfo(WARN_BUG, "X max ", m_width);
88  g_msg->WarnAddInfo(WARN_BUG, "Y max ", m_height);
89  exit(1);
90  }
91  return m_map[ a_y * m_width + a_x ];
92 }
93 
94 #endif // RASTERMAP_H
95 
96 
97 
RasterMap::GetID
char * GetID(void)
Definition: rastermap.h:55
RasterMap::m_landscape
Landscape * m_landscape
Definition: rastermap.h:48
RasterMap::MapHeight
int MapHeight(void)
Definition: rastermap.h:53
MapErrorMsg::WarnAddInfo
void WarnAddInfo(MapErrorState a_level, std::string a_add1, std::string a_add2)
Definition: maperrormsg.cpp:149
RasterMap::Get
int Get(int a_x, int a_y)
Definition: rastermap.h:81
RasterMap::m_x
int m_x
Definition: rastermap.h:46
WARN_BUG
Definition: maperrormsg.h:34
RasterMap::Put
void Put(int a_x, int a_y, int a_elem)
Definition: rastermap.h:57
RasterMap::GetMagicP
int * GetMagicP(int a_x, int a_y)
Definition: rastermap.h:74
g_msg
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:41
Landscape
The landscape class containing all environmental and topographical data.
Definition: landscape.h:112
RasterMap::m_height
int m_height
Definition: rastermap.h:45
RasterMap::m_y
int m_y
Definition: rastermap.h:47
RasterMap::m_map
int * m_map
Definition: rastermap.h:43
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
RasterMap::m_width
int m_width
Definition: rastermap.h:44
RasterMap
Definition: rastermap.h:40
RasterMap::MapWidth
int MapWidth(void)
Definition: rastermap.h:52