Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MovementMap.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2011, Christopher John Topping, Aarhus University
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12 the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
17 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
19 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 ********************************************************************************************************
23 */
36 //---------------------------------------------------------------------------
37 #ifndef MovementMapH
38 #define MovementMapH
39 
40 //------------------------------------------------------------------------------
41 //
42 
43 //------------------------------------------------------------------------------
44 class TAnimal;
45 
53 {
54 public:
55  vector<unsigned> m_TheMap;
56  unsigned GetMapValue(unsigned a_x, unsigned a_y) const {
57  return m_TheMap[a_x + a_y * m_Maxx];
58  }
59  void SetMapValue(unsigned a_x, unsigned a_y, unsigned a_value) {
60  m_TheMap[a_x + a_y * m_Maxx] = a_value;
61  }
62  void SetMapValue0(unsigned a_x, unsigned a_y) {
63  m_TheMap[a_x + a_y * m_Maxx] = 0;
64  }
65  void SetMapValue1(unsigned a_x, unsigned a_y) {
66  m_TheMap[a_x + a_y * m_Maxx] = 1;
67  }
68  void SetMapValue2(unsigned a_x, unsigned a_y) {
69  m_TheMap[a_x + a_y * m_Maxx] = 2;
70  }
71  void SetMapValue3(unsigned a_x, unsigned a_y) {
72  m_TheMap[a_x + a_y * m_Maxx] = 3;
73  }
74  MovementMapUnsigned(Landscape* a_L, int a_spref);
76 protected:
78  void Init(int spref);
79  unsigned m_Maxx;
80  unsigned m_Maxy;
81 };
82 //------------------------------------------------------------------------------
83 
89 {
90 public:
94  int GetMapValue(unsigned x, unsigned y);
95  void SetMapValue(unsigned x, unsigned y, unsigned value);
96  void SetMapValue0(unsigned x, unsigned y);
97  void SetMapValue1(unsigned x, unsigned y);
98  void SetMapValue2(unsigned x, unsigned y);
99  void SetMapValue3(unsigned x, unsigned y);
100  MovementMap(Landscape* L, int spref);
101  ~MovementMap();
102 protected:
104  void Init(int spref);
105 };
106 //------------------------------------------------------------------------------
107 
113 {
114 public:
118  int GetMapValue(unsigned x, unsigned y);
119  void SetMapValue(unsigned x, unsigned y, unsigned value);
120  void ClearMapValue(unsigned x, unsigned y);
122  ~MovementMap16();
123 protected:
125  void Init();
126 };
127 //------------------------------------------------------------------------------
128 
129 
134 template <class a_type> class IDMap
135 {
136 public:
137  vector<a_type> m_TheMap;
138  int maxx;
139  int maxy;
140  a_type GetMapValue(unsigned x, unsigned y) {
141  return m_TheMap[x + (maxx*y)];
142  }
143  void SetMapValue(unsigned x, unsigned y, a_type p) {
144  m_TheMap[x + (maxx*y)] = p;
145  }
146  void ClearMapValue(unsigned x, unsigned y) {
147  m_TheMap[x + (maxx*y)] = NULL;
148  }
150  maxx = L->SupplySimAreaWidth();
151  maxy = L->SupplySimAreaHeight();
152  m_TheMap.resize(maxx*maxy);
153  for (int y = 0; y<maxy; y++) {
154  for (int x = 0; x<maxx; x++) {
155  SetMapValue(x, y, NULL);
156  }
157  }
158  }
159  ~IDMap() {
160  ;
161  }
162 };
163 //------------------------------------------------------------------------------
164 
165 
170 class IDMapScaled : public IDMap<TAnimal*>
171 {
172 public:
173  int m_scale;
174  TAnimal* GetMapValue(unsigned a_x, unsigned a_y) {
176  a_x /= m_scale;
177  a_y /= m_scale;
178  return m_TheMap[a_x + (maxx*a_y)];
179  }
180  void SetMapValue(unsigned a_x, unsigned a_y, TAnimal* p) {
182  a_x /= m_scale;
183  a_y /= m_scale;
184  m_TheMap[a_x + (maxx*a_y)] = p;
185  }
186  void ClearMapValue(unsigned a_x, unsigned a_y){
188  a_x /= m_scale;
189  a_y /= m_scale;
190  m_TheMap[a_x + (maxx*a_y)] = NULL;
191  }
192  IDMapScaled(Landscape * L, int a_gridsize);
193  ~IDMapScaled();
194 };
195 //------------------------------------------------------------------------------
196 
197 
198 //---------------------------------------------------------------------------
199 #endif
spider_tole_movemap_init_Oedothorax
unsigned spider_tole_movemap_init_Oedothorax(Landscape *m_OurLandscape, int a_x, int a_y)
Definition: Spider_toletoc.cpp:246
MovementMapUnsigned::SetMapValue
void SetMapValue(unsigned a_x, unsigned a_y, unsigned a_value)
Definition: MovementMap.h:59
MovementMap16::MovementMap16
MovementMap16(Landscape *L)
Definition: MovementMap.cpp:211
IDMapScaled::m_scale
int m_scale
Definition: MovementMap.h:173
beetle_tole_movemap_init
int beetle_tole_movemap_init(Landscape *m_OurLandscape, int x, int y)
Definition: Beetle_toletov.cpp:21
MovementMap16::GetMapValue
int GetMapValue(unsigned x, unsigned y)
Definition: MovementMap.cpp:274
MovementMapUnsigned::SetMapValue2
void SetMapValue2(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:68
MovementMapUnsigned::MovementMapUnsigned
MovementMapUnsigned(Landscape *a_L, int a_spref)
Definition: MovementMap.cpp:47
uint32
unsigned int uint32
Definition: ALMaSS_Setup.h:34
MovementMap::m_TheMap
uint32 * m_TheMap
Definition: MovementMap.h:91
MovementMap::~MovementMap
~MovementMap()
Definition: MovementMap.cpp:97
MovementMap16::ClearMapValue
void ClearMapValue(unsigned x, unsigned y)
Definition: MovementMap.cpp:264
MovementMap::SetMapValue
void SetMapValue(unsigned x, unsigned y, unsigned value)
Definition: MovementMap.cpp:129
IDMap< TAnimal * >::m_TheMap
vector< TAnimal * > m_TheMap
Definition: MovementMap.h:137
MovementMap16::Init
void Init()
Definition: MovementMap.cpp:230
MovementMap::SetMapValue0
void SetMapValue0(unsigned x, unsigned y)
Definition: MovementMap.cpp:149
MovementMapUnsigned::GetMapValue
unsigned GetMapValue(unsigned a_x, unsigned a_y) const
Definition: MovementMap.h:56
IDMap< TAnimal * >::maxx
int maxx
Definition: MovementMap.h:138
Landscape
The landscape class containing all environmental and topographical data.
Definition: Landscape.h:142
MovementMapUnsigned::m_Maxx
unsigned m_Maxx
Definition: MovementMap.h:79
IDMapScaled
Used to map locations of animals in space.
Definition: MovementMap.h:170
MovementMap::SetMapValue3
void SetMapValue3(unsigned x, unsigned y)
Definition: MovementMap.cpp:185
IDMap::SetMapValue
void SetMapValue(unsigned x, unsigned y, a_type p)
Definition: MovementMap.h:143
MovementMapUnsigned::m_ALandscape
Landscape * m_ALandscape
Definition: MovementMap.h:77
IDMapScaled::~IDMapScaled
~IDMapScaled()
Definition: MovementMap.cpp:301
MovementMapUnsigned::SetMapValue3
void SetMapValue3(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:71
IDMap::GetMapValue
a_type GetMapValue(unsigned x, unsigned y)
Definition: MovementMap.h:140
Landscape::SupplySimAreaHeight
int SupplySimAreaHeight(void)
Gets the simulation landscape height.
Definition: Landscape.h:2302
Landscape::SupplySimAreaWidth
int SupplySimAreaWidth(void)
Gets the simulation landscape width.
Definition: Landscape.h:2297
MovementMapUnsigned::m_TheMap
vector< unsigned > m_TheMap
Definition: MovementMap.h:55
MovementMapUnsigned::Init
void Init(int spref)
Definition: MovementMap.cpp:63
TAnimal
The base class for all ALMaSS animal classes. Includes all the functionality required to be handled b...
Definition: PopulationManager.h:200
MovementMap16::~MovementMap16
~MovementMap16()
Definition: MovementMap.cpp:223
MovementMap16::m_TheMap
uint32 * m_TheMap
Definition: MovementMap.h:115
MovementMap
Movement maps are used for rapid computing of animal movement. This version uses values of 0-3 only.
Definition: MovementMap.h:88
MovementMap::maxy
uint32 maxy
Definition: MovementMap.h:93
IDMap::~IDMap
~IDMap()
Definition: MovementMap.h:159
MovementMapUnsigned::SetMapValue1
void SetMapValue1(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:65
IDMapScaled::GetMapValue
TAnimal * GetMapValue(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:174
IDMap
Used to map locations of animals in space.
Definition: MovementMap.h:134
IDMap::ClearMapValue
void ClearMapValue(unsigned x, unsigned y)
Definition: MovementMap.h:146
MovementMap::SetMapValue2
void SetMapValue2(unsigned x, unsigned y)
Definition: MovementMap.cpp:172
MovementMap16::maxy
uint32 maxy
Definition: MovementMap.h:117
MovementMap::SetMapValue1
void SetMapValue1(unsigned x, unsigned y)
Definition: MovementMap.cpp:160
IDMap::IDMap
IDMap(Landscape *L)
Definition: MovementMap.h:149
MovementMap16
Movement maps are used for rapid computing of animal movement. This version uses values of 0-15 only.
Definition: MovementMap.h:112
MovementMapUnsigned::m_Maxy
unsigned m_Maxy
Definition: MovementMap.h:80
MovementMap::MovementMap
MovementMap(Landscape *L, int spref)
Definition: MovementMap.cpp:85
MovementMap::GetMapValue
int GetMapValue(unsigned x, unsigned y)
Definition: MovementMap.cpp:197
MovementMap16::maxx
uint32 maxx
Definition: MovementMap.h:116
MovementMap16::SetMapValue
void SetMapValue(unsigned x, unsigned y, unsigned value)
Definition: MovementMap.cpp:244
MovementMapUnsigned::SetMapValue0
void SetMapValue0(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:62
spider_tole_movemap_init_Erigone
unsigned spider_tole_movemap_init_Erigone(Landscape *m_OurLandscape, int a_x, int a_y)
Definition: Spider_toletoc.cpp:89
IDMapScaled::ClearMapValue
void ClearMapValue(unsigned a_x, unsigned a_y)
Definition: MovementMap.h:186
MovementMap::Init
void Init(int spref)
Definition: MovementMap.cpp:104
IDMapScaled::SetMapValue
void SetMapValue(unsigned a_x, unsigned a_y, TAnimal *p)
Definition: MovementMap.h:180
IDMapScaled::IDMapScaled
IDMapScaled(Landscape *L, int a_gridsize)
Definition: MovementMap.cpp:285
MovementMapUnsigned::~MovementMapUnsigned
~MovementMapUnsigned()
Definition: MovementMap.cpp:57
MovementMap::m_ALandscape
Landscape * m_ALandscape
Definition: MovementMap.h:103
IDMap< TAnimal * >::maxy
int maxy
Definition: MovementMap.h:139
MovementMap16::m_ALandscape
Landscape * m_ALandscape
Definition: MovementMap.h:124
ALMaSS_Setup.h
MovementMap::maxx
uint32 maxx
Definition: MovementMap.h:92
MovementMapUnsigned
Movement maps are used for rapid computing of animal movement. This version uses values of 0 to max i...
Definition: MovementMap.h:52