--- deliantra/server/random_maps/rogue_layout.C 2009/11/07 18:32:45 1.12 +++ deliantra/server/random_maps/rogue_layout.C 2012/01/03 11:25:34 1.20 @@ -1,8 +1,8 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * Copyright (©) Crossfire Development Team (restored, original file without copyright notice) + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 1994-2004 Crossfire Development Team (restored, original file without copyright notice) * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -21,9 +21,9 @@ * The authors can be reached via e-mail to */ -/* generate a rogue/nethack-like layout */ +/* generate a rogue/nethack-like maze */ #include -#include +#include #include typedef struct @@ -40,10 +40,10 @@ static int roguelike_place_room (Room *rooms, int xsize, int ysize, int nrooms); static void roguelike_make_rooms (Room *rooms, char **maze, int options); -static void roguelike_link_rooms (Room *rooms, char **maze, int xsize, int ysize); +static void roguelike_link_rooms (Room *rooms, layout &maze); int -surround_check (char **layout, int i, int j, int Xsize, int Ysize) +surround_check (layout &maze, int i, int j) { /* 1 = wall to left, 2 = wall to right, @@ -51,35 +51,35 @@ 8 = wall below */ int surround_index = 0; - if ((i > 0) && (layout[i - 1][j] != 0 && layout[i - 1][j] != '.')) surround_index |= 1; - if ((i < Xsize - 1) && (layout[i + 1][j] != 0 && layout[i + 1][j] != '.')) surround_index |= 2; - if ((j > 0) && (layout[i][j - 1] != 0 && layout[i][j - 1] != '.')) surround_index |= 4; - if ((j < Ysize - 1) && (layout[i][j + 1] != 0 && layout[i][j + 1] != '.')) surround_index |= 8; + if ((i > 0) && (maze[i - 1][j] != 0 && maze[i - 1][j] != '.')) surround_index |= 1; + if ((i < maze.w - 1) && (maze[i + 1][j] != 0 && maze[i + 1][j] != '.')) surround_index |= 2; + if ((j > 0) && (maze[i][j - 1] != 0 && maze[i][j - 1] != '.')) surround_index |= 4; + if ((j < maze.h - 1) && (maze[i][j + 1] != 0 && maze[i][j + 1] != '.')) surround_index |= 8; return surround_index; } -/* actually make the layout: we work by a reduction process: +/* actually make the maze: we work by a reduction process: * first we make everything a wall, then we remove areas to make rooms */ void -roguelike_layout_gen (Layout maze, int options) +roguelike_layout_gen (layout &maze, int options) { int i, j; Room *walk; int nrooms = 0; int tries = 0; - int xsize = maze->w; - int ysize = maze->h; + int xsize = maze.w; + int ysize = maze.h; /* minimum room size is basically 5x5: if xsize/ysize is less than 3x that then hollow things out, stick in a stairsup and stairs down, and exit */ if (xsize < 11 || ysize < 11) { - maze->clear (); - maze->border (); + maze.clear (); + maze.border (); maze[(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; maze[(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; @@ -87,7 +87,7 @@ return; } - maze->clear ('#'); + maze.fill ('#'); /* decide on the number of rooms */ nrooms = rmg_rndm (10) + 6; @@ -106,8 +106,8 @@ if (i == 0) /* no can do! */ { - maze->clear (); - maze->border (); + maze.clear (); + maze.border (); maze [(xsize - 1) / 2][(ysize - 1) / 2 ] = '>'; maze [(xsize - 1) / 2][(ysize - 1) / 2 + 1] = '<'; @@ -119,7 +119,7 @@ /* erase the areas occupied by the rooms */ roguelike_make_rooms (rooms, maze, options); - roguelike_link_rooms (rooms, maze, xsize, ysize); + roguelike_link_rooms (rooms, maze); /* put in the stairs */ @@ -156,7 +156,7 @@ if (maze[i][j] == 'D') { /* remove bad door. */ - int si = surround_check (maze, i, j, xsize, ysize); + int si = surround_check (maze, i, j); if (si != 3 && si != 12) { @@ -192,7 +192,7 @@ /* generate a distribution of sizes centered about basesize */ sx = rmg_rndm (x_basesize) + rmg_rndm (x_basesize) + rmg_rndm (x_basesize); sy = rmg_rndm (y_basesize) + rmg_rndm (y_basesize) + rmg_rndm (y_basesize); - sy = (int) (sy * .5); /* renormalize */ + sy >>= 1; /* renormalize */ /* find the corners */ ax = tx - sx / 2; @@ -222,11 +222,11 @@ /* if we've got here, presumably the room is OK. */ /* get a pointer to the first free room */ - for (walk = rooms; walk->x != 0; walk++) + for (walk = rooms; walk->x; walk++) ; - walk->x = tx; - walk->y = ty; + walk->x = tx; + walk->y = ty; walk->sx = sx; walk->sy = sy; walk->ax = ax; @@ -242,11 +242,10 @@ roguelike_make_rooms (Room *rooms, char **maze, int options) { int making_circle = 0; - int i, j; int R; Room *walk; - for (walk = rooms; walk->x != 0; walk++) + for (walk = rooms; walk->x; walk++) { /* first decide what shape to make */ switch (options) @@ -268,15 +267,15 @@ R = walk->sy / 2; /* enscribe a rectangle */ - for (i = walk->ax; i < walk->zx; i++) - for (j = walk->ay; j < walk->zy; j++) + for (int i = walk->ax; i < walk->zx; i++) + for (int j = walk->ay; j < walk->zy; j++) if (!making_circle || ((int) (0.5 + hypot (walk->x - i, walk->y - j))) <= R) maze[i][j] = '.'; } } static void -roguelike_link_rooms (Room *rooms, char **maze, int xsize, int ysize) +roguelike_link_rooms (Room *rooms, layout &maze) { Room *walk; int i, j;