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);
111 if (m_landscape->GetPolymapping(Get(x, y)) == -1)
115 sprintf(error_num,
"%d", Get(x, y));
116 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap():" " Unknown polygon ref number:", error_num);
126 m_landscape = a_landscape;
129 ifstream IFile(a_mapfile, ios::binary);
130 if (!IFile.is_open()) {
136 IFile.read((
char*)&m_width,
sizeof (
int));
137 IFile.read((
char*)&m_height,
sizeof (
int));
138 m_map =
new int[ m_width*m_height];
141 "RasterMap::RasterMap(): Out of memory.",
"");
144 IFile.read((
char*)m_map, m_width*m_height *
sizeof(
int));
149 int lastref = 99999999;
150 for (
int x = 0; x<m_x; x++)
152 for (
int y = 0; y<m_y; y++)
157 if (lastref>=0) Put(x, y, lastref);
159 sprintf(error_num,
"%d", Get(x, y));
160 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap(): Unknown polygon map number (could be a hole):", error_num);
167 if (m_landscape->GetPolymapping(Get(x, y)) == -1)
171 sprintf(error_num,
"%d", Get(x, y));
172 g_msg->
Warn(
WARN_FILE,
"RasterMap::RasterMap():" " Unknown polygon ref number:", error_num);
189 o1=fopen(
"RasterDump1.lsb",
"wb");
190 o2=fopen(
"RasterDump2.lsb",
"wb");
192 int new_height = m_height*2;
193 fwrite( l_id, 1, 12, o1 );
194 fwrite( & new_height, 1,
sizeof(
int ), o1 );
195 for (
int y=0; y< m_width; y++ ) {
196 for (
int x = 0; x < m_width ; x++ ) {
197 int l_poly = Get(x,y);
198 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
199 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
201 for (
int x = 0; x < m_width ; x++ ) {
202 int l_poly = Get(x,y);
203 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
204 fwrite( & l_poly, 1,
sizeof(
int ), o1 );
208 new_height = m_height*multiply;
209 fwrite( l_id, 1, 12, o2 );
210 fwrite( &new_height, 1,
sizeof(
int ), o2 );
211 for (
int m=0; m<multiply; m++) {
212 for (
int y=0; y< m_width; y++ ) {
213 for (
int mm=0; mm<multiply; mm++) {
214 for (
int x = 0; x < m_width ; x++ ) {
215 int l_poly = Get(x,y);
216 fwrite( & l_poly, 1,
sizeof(
int ), o2 );
233 if ((a_x < 1) || (a_x > m_width - 2) || (a_y < 1) || (a_y > m_height - 2))
return -1;
234 int toreplace = Get(a_x, a_y);
235 if (toreplace != a_polyref)
237 g_msg->
Warn(
"RasterMap::CellReplacementNeighbour: x,y pair does not match polyref ", a_polyref);
240 int surroundingcells[8];
241 surroundingcells[0] = Get(a_x - 1, a_y - 1);
242 surroundingcells[1] = Get(a_x , a_y - 1);
243 surroundingcells[2] = Get(a_x + 1, a_y - 1);
244 surroundingcells[3] = Get(a_x - 1, a_y);
245 surroundingcells[4] = Get(a_x + 1, a_y);
246 surroundingcells[5] = Get(a_x - 1, a_y + 1);
247 surroundingcells[6] = Get(a_x , a_y + 1);
248 surroundingcells[7] = Get(a_x + 1, a_y + 1);
251 for (
int i = 0; i < 8; i++)
254 for (
int j = 0; j < 8; j++)
256 if (surroundingcells[j] == surroundingcells[i]) count[i]++;
261 for (
int i = 0; i < 8; i++)
263 if (count[i]>found) index = i;
267 if (m_landscape->SupplyPolygonArea(surroundingcells[index]) < 2)
return -1;
269 Put(a_x, a_y, surroundingcells[index]);
275 int surroundingcells[8];
276 surroundingcells[0] = Get(a_x - 1, a_y - 1);
277 surroundingcells[1] = Get(a_x, a_y - 1);
278 surroundingcells[2] = Get(a_x + 1, a_y - 1);
279 surroundingcells[3] = Get(a_x - 1, a_y);
280 surroundingcells[4] = Get(a_x + 1, a_y);
281 surroundingcells[5] = Get(a_x - 1, a_y + 1);
282 surroundingcells[6] = Get(a_x, a_y + 1);
283 surroundingcells[7] = Get(a_x + 1, a_y + 1);
287 unsigned offset = (unsigned)(((
double)rand() / RAND_MAX + 1) * 8);
288 for (
unsigned i = 0; i < 8; i++)
290 if (m_landscape->IsFieldType(m_landscape->SupplyElementType(surroundingcells[(i + offset) % 8])))
293 Put(a_x, a_y, surroundingcells[(i + offset) % 8]);
304 int surroundingcells[8];
305 if (a_x >= 1 && a_y >= 1) surroundingcells[0] = Get(a_x - 1, a_y - 1);
else surroundingcells[0] = Get(a_x, a_y);
306 if (a_y >= 1) surroundingcells[1] = Get(a_x, a_y - 1);
else surroundingcells[1] = Get(a_x, a_y);
307 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);
308 if (a_x >= 1) surroundingcells[3] = Get(a_x - 1, a_y);
else surroundingcells[3] = Get(a_x, a_y);
309 if (a_x < m_width-1) surroundingcells[4] = Get(a_x + 1, a_y);
else surroundingcells[4] = Get(a_x, a_y);
310 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);
311 if (a_y < m_height-1) surroundingcells[6] = Get(a_x, a_y + 1);
else surroundingcells[6] = Get(a_x, a_y);
312 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);
316 unsigned offset = (unsigned)(((
double)rand() / RAND_MAX + 1) * 8);
317 for (
unsigned i = 0; i < 8; i++)
324 Put(a_x, a_y, surroundingcells[(i + offset) % 8]);