diff options
author | Adam Borowski <kilobyte@angband.pl> | 2013-06-25 02:40:24 +0200 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2013-06-25 02:40:24 +0200 |
commit | be96d22e0966c529ff03595edd2e95ce18ebcddf (patch) | |
tree | ef7afb0744d560c5c9ef9852d67e62108e52301c /crawl-ref/source/dgn-irregular-box.cc | |
parent | 15ad2c855d16293b7520601629c6ad73963de007 (diff) | |
download | crawl-ref-be96d22e0966c529ff03595edd2e95ce18ebcddf.tar.gz crawl-ref-be96d22e0966c529ff03595edd2e95ce18ebcddf.zip |
Formatting fixes.
Diffstat (limited to 'crawl-ref/source/dgn-irregular-box.cc')
-rw-r--r-- | crawl-ref/source/dgn-irregular-box.cc | 157 |
1 files changed, 77 insertions, 80 deletions
diff --git a/crawl-ref/source/dgn-irregular-box.cc b/crawl-ref/source/dgn-irregular-box.cc index 4e6d4d8467..bca91e57b8 100644 --- a/crawl-ref/source/dgn-irregular-box.cc +++ b/crawl-ref/source/dgn-irregular-box.cc @@ -12,7 +12,6 @@ #include "dgn-irregular-box.h" - // Adds a simple hollow box to the map with the specified // coordinates, glyphs, and number of doors. This is the // fallback if we can't place a irregular box. @@ -21,38 +20,38 @@ static void _make_simple_box(map_lines& map, int x1, int y1, int x2, int y2, char door_glyph, int door_count) { // inside - for(int x = x1 + 1; x < x2; x++) - for(int y = y1 + 1; y < y2; y++) + for (int x = x1 + 1; x < x2; x++) + for (int y = y1 + 1; y < y2; y++) map(x, y) = floor_glyph; // walls - for(int x = x1; x <= x2; x++) + for (int x = x1; x <= x2; x++) { map(x, y1) = wall_glyph; map(x, y2) = wall_glyph; } - for(int y = y1 + 1; y < y2; y++) + for (int y = y1 + 1; y < y2; y++) { map(x1, y) = wall_glyph; map(x2, y) = wall_glyph; } // doors - if(door_count > 0) + if (door_count > 0) { vector<coord_def> cells; - for(int x = x1; x <= x2; x++) + for (int x = x1; x <= x2; x++) { cells.push_back(coord_def(x, y1)); cells.push_back(coord_def(x, y2)); } - for(int y = y1 + 1; y < y2; y++) + for (int y = y1 + 1; y < y2; y++) { cells.push_back(coord_def(x1, y)); cells.push_back(coord_def(x2, y)); } - for(int i = 0; i < door_count && !cells.empty(); i++) + for (int i = 0; i < door_count && !cells.empty(); i++) { unsigned int index = random2(cells.size()); map(cells[index].x, cells[index].y) = door_glyph; @@ -66,12 +65,12 @@ static void _make_simple_box(map_lines& map, int x1, int y1, int x2, int y2, // equal to a third value static void _randomly_force_sum_below(int& a, int& b, int sum) { - if(sum <= 0) + if (sum <= 0) return; while (a + b >= sum) { - if(random2(2) == 0) + if (random2(2) == 0) a = random2(a); else b = random2(b); @@ -92,18 +91,18 @@ static vector<int> _calculate_random_values(int min_value, int max_value, values.push_back(min_value); values.push_back(max_value); - for(int i = 0; i < max_count; i++) + for (int i = 0; i < max_count; i++) { int chosen = random_range(min_value, max_value); // modified insertion sort - for(unsigned int j = 0; j < values.size(); j++) + for (unsigned int j = 0; j < values.size(); j++) { int permitted_below = values[j] - min_seperation; int permitted_above = values[j] + min_seperation; - if(chosen < permitted_above) + if (chosen < permitted_above) { - if(chosen > permitted_below) + if (chosen > permitted_below) { // too close to an existing value, so do not insert break; @@ -113,7 +112,7 @@ static vector<int> _calculate_random_values(int min_value, int max_value, // insert before values.push_back(values.back()); // not that by here, values.size() is always >= 3 - for(unsigned int k = values.size() - 2; k > j; k--) + for (unsigned int k = values.size() - 2; k > j; k--) values[k] = values[k - 1]; values[j] = chosen; break; @@ -136,13 +135,13 @@ static vector<int> _calculate_random_wall_distances(int first_value, int max_value, int count) { - if(count < 1) + if (count < 1) count = 1; vector<int> values(count, 0); values[0] = first_value; - for(int i = 1; i < count; i++) + for (int i = 1; i < count; i++) values[i] = random2(max_value); values[count - 1] = (last_value); @@ -174,17 +173,17 @@ static void _draw_wall_t(vector<vector<char> >& map, const vector<int>& in_t, char wall_glyph) { - for(unsigned int i = 0; i < in_t.size(); i++) + for (unsigned int i = 0; i < in_t.size(); i++) { - if(i > 0) + if (i > 0) { // connect to previous division int x = di_t[i]; int ym = in_t[i]; int yp = in_t[i - 1]; - if(ym > yp) + if (ym > yp) swap(ym, yp); - for(int y = ym + 1; y < yp; y++) + for (int y = ym + 1; y < yp; y++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -195,7 +194,7 @@ static void _draw_wall_t(vector<vector<char> >& map, int y = in_t[i]; map[di_t[i ]][y] = wall_glyph; map[di_t[i + 1]][y] = wall_glyph; - for(int x = di_t[i] + 1; x < di_t[i + 1]; x++) + for (int x = di_t[i] + 1; x < di_t[i + 1]; x++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -210,17 +209,17 @@ static void _draw_wall_b(vector<vector<char> >& map, char wall_glyph, int size_y) { - for(unsigned int i = 0; i < in_b.size(); i++) + for (unsigned int i = 0; i < in_b.size(); i++) { - if(i > 0) + if (i > 0) { // connect to previous division int x = di_b[i]; int ym = size_y - 1 - in_b[i]; int yp = size_y - 1 - in_b[i - 1]; - if(ym > yp) + if (ym > yp) swap(ym, yp); - for(int y = ym + 1; y < yp; y++) + for (int y = ym + 1; y < yp; y++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -231,7 +230,7 @@ static void _draw_wall_b(vector<vector<char> >& map, int y = size_y - 1 - in_b[i]; map[di_b[i ]][y] = wall_glyph; map[di_b[i + 1]][y] = wall_glyph; - for(int x = di_b[i] + 1; x < di_b[i + 1]; x++) + for (int x = di_b[i] + 1; x < di_b[i + 1]; x++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -245,17 +244,17 @@ static void _draw_wall_l(vector<vector<char> >& map, const vector<int>& in_l, char wall_glyph) { - for(unsigned int i = 0; i < in_l.size(); i++) + for (unsigned int i = 0; i < in_l.size(); i++) { - if(i > 0) + if (i > 0) { // connect to previous division int y = di_l[i]; int xm = in_l[i]; int xp = in_l[i - 1]; - if(xm > xp) + if (xm > xp) swap(xm, xp); - for(int x = xm + 1; x < xp; x++) + for (int x = xm + 1; x < xp; x++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -266,7 +265,7 @@ static void _draw_wall_l(vector<vector<char> >& map, int x = in_l[i]; map[x][di_l[i ]] = wall_glyph; map[x][di_l[i + 1]] = wall_glyph; - for(int y = di_l[i] + 1; y < di_l[i + 1]; y++) + for (int y = di_l[i] + 1; y < di_l[i + 1]; y++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -281,17 +280,17 @@ static void _draw_wall_r(vector<vector<char> >& map, char wall_glyph, int size_x) { - for(unsigned int i = 0; i < in_r.size(); i++) + for (unsigned int i = 0; i < in_r.size(); i++) { - if(i > 0) + if (i > 0) { // connect to previous division int y = di_r[i]; int xm = size_x - 1 - in_r[i]; int xp = size_x - 1 - in_r[i - 1]; - if(xm > xp) + if (xm > xp) swap(xm, xp); - for(int x = xm + 1; x < xp; x++) + for (int x = xm + 1; x < xp; x++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -302,7 +301,7 @@ static void _draw_wall_r(vector<vector<char> >& map, int x = size_x - 1 - in_r[i]; map[x][di_r[i ]] = wall_glyph; map[x][di_r[i + 1]] = wall_glyph; - for(int y = di_r[i] + 1; y < di_r[i + 1]; y++) + for (int y = di_r[i] + 1; y < di_r[i + 1]; y++) { map[x][y] = wall_glyph; wall_cells.push_back(coord_def(x, y)); @@ -317,11 +316,11 @@ static void _draw_wall_r(vector<vector<char> >& map, static void _flood_fill(vector<vector<char> >& map, int start_x, int start_y, char old_glyph, char new_glyph) { - if(map.empty() || map[0].empty()) + if (map.empty() || map[0].empty()) return; - if(map[start_x][start_y] != old_glyph) + if (map[start_x][start_y] != old_glyph) return; - if(old_glyph == new_glyph) + if (old_glyph == new_glyph) return; // We will use a stack for the glyphs still to replace. We @@ -338,22 +337,22 @@ static void _flood_fill(vector<vector<char> >& map, int start_x, int start_y, stack.pop_back(); // add neighbours - if(x > 0 && map[x - 1][y] == old_glyph) + if (x > 0 && map[x - 1][y] == old_glyph) { map[x - 1][y] = new_glyph; stack.push_back(coord_def(x - 1, y)); } - if(x + 1 < (int)(map.size()) && map[x + 1][y] == old_glyph) + if (x + 1 < (int)(map.size()) && map[x + 1][y] == old_glyph) { map[x + 1][y] = new_glyph; stack.push_back(coord_def(x + 1, y)); } - if(y > 0 && map[x][y - 1] == old_glyph) + if (y > 0 && map[x][y - 1] == old_glyph) { map[x][y - 1] = new_glyph; stack.push_back(coord_def(x, y - 1)); } - if(y + 1 < (int)(map[0].size()) && map[x][y + 1] == old_glyph) + if (y + 1 < (int)(map[0].size()) && map[x][y + 1] == old_glyph) { map[x][y + 1] = new_glyph; stack.push_back(coord_def(x, y + 1)); @@ -380,18 +379,18 @@ static void _fill_outside(vector<vector<char> >& map, int max_y = map[0].size() - 1; // top and bottom - for(int x = 0; x <= max_x; x++) + for (int x = 0; x <= max_x; x++) { - for(int y = 0; y <= max_y; y++) + for (int y = 0; y <= max_y; y++) { - if(map[x][y] == old_glyph || map[x][y] == outside_glyph) + if (map[x][y] == old_glyph || map[x][y] == outside_glyph) map[x][y] = outside_glyph; else break; } - for(int y = max_y; y >= 0; y--) + for (int y = max_y; y >= 0; y--) { - if(map[x][y] == old_glyph || map[x][y] == outside_glyph) + if (map[x][y] == old_glyph || map[x][y] == outside_glyph) map[x][y] = outside_glyph; else break; @@ -399,18 +398,18 @@ static void _fill_outside(vector<vector<char> >& map, } // left and right - for(int y = 0; y <= max_y; y++) + for (int y = 0; y <= max_y; y++) { - for(int x = 0; x <= max_x; x++) + for (int x = 0; x <= max_x; x++) { - if(map[x][y] == old_glyph || map[x][y] == outside_glyph) + if (map[x][y] == old_glyph || map[x][y] == outside_glyph) map[x][y] = outside_glyph; else break; } - for(int x = max_x; x >= 0; x--) + for (int x = max_x; x >= 0; x--) { - if(map[x][y] == old_glyph || map[x][y] == outside_glyph) + if (map[x][y] == old_glyph || map[x][y] == outside_glyph) map[x][y] = outside_glyph; else break; @@ -432,31 +431,31 @@ void make_irregular_box(map_lines& map, int x1, int y1, int x2, int y2, const char OUTSIDE_GLYPH = '\a'; // if we have no map, just give up - if(map.width() <= 0 || map.height() <= 0) + if (map.width() <= 0 || map.height() <= 0) return; // enforce preconditions - if(x1 < 0) + if (x1 < 0) x1 = 0; - if(x2 < x1) + if (x2 < x1) x2 = x1; - if(x2 >= map.width()) + if (x2 >= map.width()) x2 = map.width() - 1; - if(y1 < 0) + if (y1 < 0) y1 = 0; - if(y2 < y1) + if (y2 < y1) y2 = y1; - if(y2 >= map.height()) + if (y2 >= map.height()) y2 = map.height() - 1; - if(di_x < 0) + if (di_x < 0) di_x = 0; - if(di_y < 0) + if (di_y < 0) di_y = 0; - if(in_x < 0) + if (in_x < 0) in_x = 0; - if(in_y < 0) + if (in_y < 0) in_y = 0; - if(door_count < 0) + if (door_count < 0) door_count = 0; // calculate box size @@ -465,13 +464,13 @@ void make_irregular_box(map_lines& map, int x1, int y1, int x2, int y2, // limit in_??? values to half box size minus some for inside // -> There must be enough room left for 2 walls and one floor - if(in_x > (size_x - 1) / 2 - 1) + if (in_x > (size_x - 1) / 2 - 1) in_x = (size_x - 1) / 2 - 1; - if(in_y > (size_y - 1) / 2 - 1) + if (in_y > (size_y - 1) / 2 - 1) in_y = (size_y - 1) / 2 - 1; // irregular boxes do not work if too small - if(size_x < MIN_IRREGULAR_SIZE || size_y < MIN_IRREGULAR_SIZE) + if (size_x < MIN_IRREGULAR_SIZE || size_y < MIN_IRREGULAR_SIZE) { _make_simple_box(map, x1, y1, x2, y2, floor_glyph, wall_glyph, door_glyph, door_count); @@ -577,7 +576,7 @@ void make_irregular_box(map_lines& map, int x1, int y1, int x2, int y2, _draw_wall_r(new_glyphs, wall_cells, di_r, in_r, wall_glyph, size_x); // add doors - for(int i = 0; i < door_count && !wall_cells.empty(); i++) + for (int i = 0; i < door_count && !wall_cells.empty(); i++) { unsigned int index = random2(wall_cells.size()); new_glyphs[wall_cells[index].x][wall_cells[index].y] = '+'; @@ -597,9 +596,9 @@ void make_irregular_box(map_lines& map, int x1, int y1, int x2, int y2, _fill_outside(new_glyphs, UNSET_GLYPH, OUTSIDE_GLYPH); regenerate_needed = false; - for(int x = 0; x < size_x && !regenerate_needed; x++) - for(int y = 0; y < size_y; y++) - if(new_glyphs[x][y] == UNSET_GLYPH) + for (int x = 0; x < size_x && !regenerate_needed; x++) + for (int y = 0; y < size_y; y++) + if (new_glyphs[x][y] == UNSET_GLYPH) { regenerate_needed = true; break; @@ -613,14 +612,12 @@ void make_irregular_box(map_lines& map, int x1, int y1, int x2, int y2, // -> we are finally finished! // - for(int x = 0; x < size_x; x++) - for(int y = 0; y < size_y; y++) + for (int x = 0; x < size_x; x++) + for (int y = 0; y < size_y; y++) { - if(new_glyphs[x][y] == UNSET_GLYPH) + if (new_glyphs[x][y] == UNSET_GLYPH) dprf("Error in make_irregular_box: UNSET_GLYPH in final box"); - else if(new_glyphs[x][y] != OUTSIDE_GLYPH) + else if (new_glyphs[x][y] != OUTSIDE_GLYPH) map(x1 + x, y1 + y) = new_glyphs[x][y]; } - - return; } |