28 #define _CRT_SECURE_NO_DEPRECATE 38 #include "../Landscape/ls.h" 48 m_landscape = a_landscape;
51 IFile = fopen(a_mapfile,
"rb");
57 fread(m_id, 1, 12, IFile);
59 if (strcmp(m_id,
"An LSB File") == 0 ) Init1(a_mapfile, a_landscape);
else Init2(a_mapfile, a_landscape);
68 m_landscape = a_landscape;
73 IFile = fopen(a_mapfile,
"rb");
79 fread(m_id, 1, 12, IFile);
80 fread(&m_width, 1,
sizeof(
int), IFile);
83 m_map = (
int*)malloc(
sizeof(
int)* m_width*m_height);
86 "RasterMap::RasterMap(): Out of memory.",
"");
90 fread(m_map, 1,
sizeof(
int)*m_width*m_height, IFile);
93 for (
int x = 0; x<m_x; x++) {
94 for (
int y = 0; y<m_y; y++) {
102 sprintf(error_num,
"%d", Get(x, y));
103 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap(): Unknown polygon map number (could be a hole):", error_num);
113 sprintf(error_num,
"%d", Get(x, y));
114 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap():" " Unknown polygon ref number:", error_num);
124 m_landscape = a_landscape;
127 ifstream IFile(a_mapfile, ios::binary);
128 if (!IFile.is_open()) {
134 IFile.read((
char*)&m_width,
sizeof (
int));
135 IFile.read((
char*)&m_height,
sizeof (
int));
136 m_map =
new int[ m_width*m_height];
139 "RasterMap::RasterMap(): Out of memory.",
"");
142 IFile.read((
char*)m_map, m_width*m_height *
sizeof(
int));
147 for (
int x = 0; x<m_x; x++)
149 for (
int y = 0; y<m_y; y++)
154 sprintf(error_num,
"%d", Get(x, y));
155 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap(): Unknown polygon map number (could be a hole):", error_num);
162 sprintf(error_num,
"%d", Get(x, y));
163 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap():" " Unknown polygon ref number:", error_num);
180 o1=fopen(
"RasterDump1.lsb",
"wb");
181 o2=fopen(
"RasterDump2.lsb",
"wb");
183 int new_height = m_height*2;
184 fwrite( l_id, 1, 12, o1 );
185 fwrite( & new_height, 1,
sizeof(
int ), o1 );
186 for (
int y=0; y< m_width; y++ ) {
187 for (
int x = 0; x < m_width ; x++ ) {
188 int l_poly = Get(x,y);
189 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
190 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
192 for (
int x = 0; x < m_width ; x++ ) {
193 int l_poly = Get(x,y);
194 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
195 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
199 new_height = m_height*multiply;
200 fwrite( l_id, 1, 12, o2 );
201 fwrite( &new_height, 1,
sizeof(
int ), o2 );
202 for (
int m=0; m<multiply; m++) {
203 for (
int y=0; y< m_width; y++ ) {
204 for (
int mm=0; mm<multiply; mm++) {
205 for (
int x = 0; x < m_width ; x++ ) {
206 int l_poly = Get(x,y);
207 fwrite( & l_poly, 1,
sizeof(
int ), o2 );
224 if ((a_x < 1) || (a_x > m_width - 2) || (a_y < 1) || (a_y > m_height - 2))
return -1;
225 int toreplace = Get(a_x, a_y);
226 if (toreplace != a_polyref)
228 g_msg->
Warn(
"RasterMap::CellReplacementNeighbour: x,y pair does not match polyref ", a_polyref);
231 int surroundingcells[8];
232 surroundingcells[0] = Get(a_x - 1, a_y - 1);
233 surroundingcells[1] = Get(a_x , a_y - 1);
234 surroundingcells[2] = Get(a_x + 1, a_y - 1);
235 surroundingcells[3] = Get(a_x - 1, a_y);
236 surroundingcells[4] = Get(a_x + 1, a_y);
237 surroundingcells[5] = Get(a_x - 1, a_y + 1);
238 surroundingcells[6] = Get(a_x , a_y + 1);
239 surroundingcells[7] = Get(a_x + 1, a_y + 1);
242 for (
int i = 0; i < 8; i++)
245 for (
int j = 0; j < 8; j++)
247 if (surroundingcells[j] == surroundingcells[i]) count[i]++;
252 for (
int i = 0; i < 8; i++)
254 if (count[i]>found) index = i;
256 return surroundingcells[index];
261 int surroundingcells[8];
262 surroundingcells[0] = Get(a_x - 1, a_y - 1);
263 surroundingcells[1] = Get(a_x, a_y - 1);
264 surroundingcells[2] = Get(a_x + 1, a_y - 1);
265 surroundingcells[3] = Get(a_x - 1, a_y);
266 surroundingcells[4] = Get(a_x + 1, a_y);
267 surroundingcells[5] = Get(a_x - 1, a_y + 1);
268 surroundingcells[6] = Get(a_x, a_y + 1);
269 surroundingcells[7] = Get(a_x + 1, a_y + 1);
273 unsigned offset = (unsigned)(((
double)rand() / RAND_MAX + 1) * 8);
274 for (
unsigned i = 0; i < 8; i++)
276 if (m_landscape->IsFieldType(m_landscape->SupplyElementType(surroundingcells[(i + offset) % 8])))
279 Put(a_x, a_y, surroundingcells[(i + offset) % 8]);
290 int surroundingcells[8];
291 if (a_x >= 1 && a_y >= 1) surroundingcells[0] = Get(a_x - 1, a_y - 1);
else surroundingcells[0] = Get(a_x, a_y);
292 if (a_y >= 1) surroundingcells[1] = Get(a_x, a_y - 1);
else surroundingcells[1] = Get(a_x, a_y);
293 if (a_x < m_width-1 && a_y >= 1) surroundingcells[2] = Get(a_x + 1, a_y - 1);
else surroundingcells[2] = Get(a_x, a_y);
294 if (a_x >= 1) surroundingcells[3] = Get(a_x - 1, a_y);
else surroundingcells[3] = Get(a_x, a_y);
295 if (a_x < m_width-1) surroundingcells[4] = Get(a_x + 1, a_y);
else surroundingcells[4] = Get(a_x, a_y);
296 if (a_x >= 1 && a_y < m_height-1) surroundingcells[5] = Get(a_x - 1, a_y + 1);
else surroundingcells[5] = Get(a_x, a_y);
297 if (a_y < m_height-1) surroundingcells[6] = Get(a_x, a_y + 1);
else surroundingcells[6] = Get(a_x, a_y);
298 if (a_x < m_width-1 && a_y < m_height-1) surroundingcells[7] = Get(a_x + 1, a_y + 1);
else surroundingcells[7] = Get(a_x, a_y);
302 unsigned offset = (unsigned)(((
double)rand() / RAND_MAX + 1) * 8);
303 for (
unsigned i = 0; i < 8; i++)
310 Put(a_x, a_y, surroundingcells[(i + offset) % 8]);
The landscape class containing all environmental and topographical data.
RasterMap(const char *a_mapfile, Landscape *m_landscape)
Integer configurator entry class.
CfgBool cfg_rectangularmaps_on("RASTER_RECTANGULARMAPS_ON", CFG_CUSTOM, true)
CfgBool cfg_manipulation1_on("RASTER_MANIPULATION_ONE_ON", CFG_CUSTOM, false)
class MapErrorMsg * g_msg
CfgInt cfg_rastermapmanipmultiply("RASTER_MANIPULATION_MULTIPLYFACTOR", CFG_CUSTOM, 2)
int * m_polymapping
m_polymapping is a mapping from polygon numbers into the list of landscape elements, m_elems. When using this it is important that it is the poly num and not the map index that is used in calling.
bool MissingCellReplace(int a_x, int a_y, bool a_fieldsonly)
A method for removing missing polygons.
Bool configurator entry class.
int CellReplacementNeighbour(int a_x, int a_y, int a_polyref)
A method for helping remove tiny polygons.
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
bool MissingCellReplaceWrap(int a_x, int a_y, bool a_fieldsonly)
A method for removing missing polygons - tests for edge conditions.
void Init2(const char *a_mapfile, Landscape *m_landscape)
void Init1(const char *a_mapfile, Landscape *m_landscape)