--- deliantra/server/random_maps/expand2x.C 2006/12/31 19:02:24 1.5 +++ deliantra/server/random_maps/expand2x.C 2008/04/11 21:09:53 1.6 @@ -3,65 +3,47 @@ * Expands a layout by 2x in each dimension. * H. S. Teoh * -------------------------------------------------------------------------- - * $Id: expand2x.C,v 1.5 2006/12/31 19:02:24 root Exp $ + * $Id: expand2x.C,v 1.6 2008/04/11 21:09:53 root Exp $ * * ALGORITHM * * ... (TBW) */ -#include /* just in case */ -#include /* use compiler to do sanity check */ - +#include "global.h" +#include "random_map.h" +#include "rproto.h" /* PROTOTYPES */ - static void expand_misc (char **newlayout, int i, int j, char **layout, int xsize, int ysize); static void expand_wall (char **newlayout, int i, int j, char **layout, int xsize, int ysize); static void expand_door (char **newlayout, int i, int j, char **layout, int xsize, int ysize); - /* FUNCTIONS */ - -char ** -expand2x (char **layout, int xsize, int ysize) +Maze +expand2x (Maze layout, int xsize, int ysize) { int i, j; int nxsize = xsize * 2 - 1; int nysize = ysize * 2 - 1; - /* Allocate new layout */ - char **newlayout = (char **) calloc (sizeof (char *), nxsize); - - for (i = 0; i < nxsize; i++) - { - newlayout[i] = (char *) calloc (sizeof (char), nysize); - } + Maze newlayout (nxsize, nysize); for (i = 0; i < xsize; i++) - { - for (j = 0; j < ysize; j++) + for (j = 0; j < ysize; j++) + switch (layout[i][j]) { - switch (layout[i][j]) - { - case '#': - expand_wall (newlayout, i, j, layout, xsize, ysize); - break; - case 'D': - expand_door (newlayout, i, j, layout, xsize, ysize); - break; - default: - expand_misc (newlayout, i, j, layout, xsize, ysize); - } + case '#': + expand_wall (newlayout, i, j, layout, xsize, ysize); + break; + case 'D': + expand_door (newlayout, i, j, layout, xsize, ysize); + break; + default: + expand_misc (newlayout, i, j, layout, xsize, ysize); } - } - /* Dump old layout */ - for (i = 0; i < xsize; i++) - { - free (layout[i]); - } - free (layout); + layout.free (); return newlayout; } @@ -159,28 +141,19 @@ * a wall and another door, this door will connect to the wall and * disconnect from the other door. */ if (wall_pattern & 3) - { - join_pattern = wall_pattern; - } + join_pattern = wall_pattern; else - { - join_pattern = door_pattern; - } + join_pattern = door_pattern; newlayout[i * 2][j * 2] = 'D'; + if (i + 1 < xsize) - { - if (join_pattern & 1) - { /* there is a door/wall to the right */ - newlayout[i * 2 + 1][j * 2] = 'D'; - } - } + if (join_pattern & 1) + /* there is a door/wall to the right */ + newlayout[i * 2 + 1][j * 2] = 'D'; if (j + 1 < ysize) - { - if (join_pattern & 2) - { /* there is a door/wall below */ - newlayout[i * 2][j * 2 + 1] = 'D'; - } - } + if (join_pattern & 2) + /* there is a door/wall below */ + newlayout[i * 2][j * 2 + 1] = 'D'; }