--- deliantra/server/random_maps/expand2x.C 2009/11/07 18:32:45 1.9 +++ deliantra/server/random_maps/expand2x.C 2010/07/01 01:22:44 1.10 @@ -25,7 +25,7 @@ * Expands a layout by 2x in each dimension. * H. S. Teoh * -------------------------------------------------------------------------- - * $Id: expand2x.C,v 1.9 2009/11/07 18:32:45 root Exp $ + * $Id: expand2x.C,v 1.10 2010/07/01 01:22:44 root Exp $ * * ALGORITHM * @@ -42,7 +42,7 @@ * \0 \0 */ static void -expand_misc (Layout newlayout, int i, int j, Layout layout) +expand_misc (Layout &newlayout, int i, int j, Layout &layout) { newlayout[i * 2][j * 2] = layout[i][j]; /* (Note: no need to reset rest of 2x2 area to \0 because calloc does that @@ -57,19 +57,19 @@ * and the possible combinations thereof. */ static int -calc_pattern (char ch, Layout layout, int i, int j) +calc_pattern (char ch, Layout &layout, int i, int j) { int pattern = 0; - if (i + 1 < layout->w && layout[i + 1][j] == ch) + if (i + 1 < layout.w && layout[i + 1][j] == ch) pattern |= 1; - if (j + 1 < layout->h) + if (j + 1 < layout.h) { if (layout[i][j + 1] == ch) pattern |= 2; - if (i + 1 < layout->w && layout[i + 1][j + 1] == ch) + if (i + 1 < layout.w && layout[i + 1][j + 1] == ch) pattern |= 4; } @@ -81,7 +81,7 @@ * walls. */ static void -expand_wall (Layout newlayout, int i, int j, Layout layout) +expand_wall (Layout &newlayout, int i, int j, Layout &layout) { int wall_pattern = calc_pattern ('#', layout, i, j); int door_pattern = calc_pattern ('D', layout, i, j); @@ -89,7 +89,7 @@ newlayout[i * 2][j * 2] = '#'; - if (i + 1 < layout->w) + if (i + 1 < layout.w) { if (both_pattern & 1) { /* join walls/doors to the right */ @@ -98,7 +98,7 @@ } } - if (j + 1 < layout->h) + if (j + 1 < layout.h) { if (both_pattern & 2) { /* join walls/doors to the bottom */ @@ -119,7 +119,7 @@ * that it doesn't know how to correctly expand. */ static void -expand_door (Layout newlayout, int i, int j, Layout layout) +expand_door (Layout &newlayout, int i, int j, Layout &layout) { int wall_pattern = calc_pattern ('#', layout, i, j); int door_pattern = calc_pattern ('D', layout, i, j); @@ -135,33 +135,33 @@ newlayout[i * 2][j * 2] = 'D'; - if (i + 1 < layout->w) + if (i + 1 < layout.w) if (join_pattern & 1) /* there is a door/wall to the right */ newlayout[i * 2 + 1][j * 2] = 'D'; - if (j + 1 < layout->h) + if (j + 1 < layout.h) if (join_pattern & 2) /* there is a door/wall below */ newlayout[i * 2][j * 2 + 1] = 'D'; } void -expand2x (Layout layout) +expand2x (Layout &layout) { - Layout newlayout (layout->w * 2 - 1, layout->h * 2 - 1); - newlayout->clear (); + Layout new_layout (layout.w * 2 - 1, layout.h * 2 - 1); - for (int i = 0; i < layout->w; i++) - for (int j = 0; j < layout->h; j++) + new_layout.clear (); + + for (int i = 0; i < layout.w; i++) + for (int j = 0; j < layout.h; j++) switch (layout[i][j]) { - case '#': expand_wall (newlayout, i, j, layout); break; - case 'D': expand_door (newlayout, i, j, layout); break; - default: expand_misc (newlayout, i, j, layout); break; + case '#': expand_wall (new_layout, i, j, layout); break; + case 'D': expand_door (new_layout, i, j, layout); break; + default: expand_misc (new_layout, i, j, layout); break; } - layout.swap (newlayout); - newlayout.free (); + layout.swap (new_layout); }