29 |
#include <Foundation/NSDebug.h> |
#include <Foundation/NSDebug.h> |
30 |
#include <AppKit/NSBitmapImageRep.h> |
#include <AppKit/NSBitmapImageRep.h> |
31 |
|
|
32 |
|
#include "Common/Coord.h" |
33 |
#include "Map/MapTerrain.h" |
#include "Map/MapTerrain.h" |
34 |
|
|
|
/** |
|
|
* returns a number n such as 0 <= n < max |
|
|
* aroundTheWorld(-1) = max - 1 |
|
|
* aroundTheWorld(max) = 0 |
|
|
* aroundTheWorld(max + 1) = 1 |
|
|
*/ |
|
|
int |
|
|
aroundTheWorld (int n, int max) |
|
|
{ |
|
|
NSCParameterAssert (max > 0); |
|
|
|
|
|
if (n < 0) |
|
|
return (max + ((n + 1) % max) - 1); |
|
|
else |
|
|
return (n % max); |
|
|
} |
|
|
|
|
35 |
|
|
36 |
/** |
/** |
37 |
* The terrain stores a heightField which can be displayed |
* The terrain stores a heightField which can be displayed |
143 |
/** |
/** |
144 |
* Returns a pointer to the tab, assuming position to be a valid one |
* Returns a pointer to the tab, assuming position to be a valid one |
145 |
*/ |
*/ |
146 |
- (u_int8_t *) _tabAtPosition: (map_coord_t)position |
- (u_int8_t *) _tabAtPosition: (coord2DInt_t)position |
147 |
{ |
{ |
148 |
NSParameterAssert (position.x >= 0); |
NSParameterAssert (position.x >= 0); |
149 |
NSParameterAssert (position.x < _xLength); |
NSParameterAssert (position.x < _xLength); |
159 |
* If the coordinates go beyond the edge of the map, |
* If the coordinates go beyond the edge of the map, |
160 |
* they pass on other side by modulo. |
* they pass on other side by modulo. |
161 |
*/ |
*/ |
162 |
- (u_int8_t *) _heightAtPosition: (map_coord_t)position |
- (u_int8_t *) _heightAtPosition: (coord2DInt_t)position |
163 |
{ |
{ |
164 |
return [self _tabAtPosition: |
return [self _tabAtPosition: |
165 |
MakeMapCoord (aroundTheWorld(position.x, _xLength), |
MakeCoord2DInt (aroundTheWorld(position.x, _xLength), |
166 |
aroundTheWorld(position.z, _zLength))]; |
aroundTheWorld(position.z, _zLength))]; |
167 |
} |
} |
168 |
|
|
169 |
/** |
/** |
171 |
* position may be any positive or negative coordinate: |
* position may be any positive or negative coordinate: |
172 |
* it turns around the toric map by modulo. |
* it turns around the toric map by modulo. |
173 |
*/ |
*/ |
174 |
- (u_int8_t) heightAtPosition: (map_coord_t)position |
- (u_int8_t) heightAtPosition: (coord2DInt_t)position |
175 |
{ |
{ |
176 |
return *[self _heightAtPosition: position]; |
return *[self _heightAtPosition: position]; |
177 |
} |
} |
198 |
* If the coordinates go beyond the edge of the map, |
* If the coordinates go beyond the edge of the map, |
199 |
* they pass on other side by modulo. |
* they pass on other side by modulo. |
200 |
*/ |
*/ |
201 |
- (void) setHeightAtPosition: (map_coord_t)position |
- (void) setHeightAtPosition: (coord2DInt_t)position |
202 |
toHeight: (u_int8_t)height |
toHeight: (u_int8_t)height |
203 |
{ |
{ |
204 |
*[self _heightAtPosition: position] = height; |
*[self _heightAtPosition: position] = height; |