/*
* This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
* Copyright (©) 1994 Mark Wedel
* Copyright (©) 1992 Frank Tore Johansen
*
* 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
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the Affero GNU General Public License
* and the GNU General Public License along with this program. If not, see
* .
*
* The authors can be reached via e-mail to
*/
/* The onion room generator:
Onion rooms are like this:
char **map_gen_spiral(int xsize, int ysize, int option);
*/
#include
#include
#include
#define RANDOM_OPTIONS 0 /* Pick random options below */
#define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly */
#define FINE_SPIRAL 2 /* uses the min. separation: most coiling */
#define FIT_SPIRAL 4 /* scale to a rectangular region, not square */
#define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */
#define MINDIST 3
#define MAX_FINE .454545
void
map_gen_spiral (layout &maze, int option)
{
float parm = 0;
float x = 0, y = 0;
int ic, jc;
float SizeX, SizeY;
float xscale, yscale;
/* slightly easier to fill and then cut */
maze.fill ('#');
int xsize = maze.w;
int ysize = maze.h;
ic = xsize / 2;
jc = ysize / 2;
SizeX = xsize / 2 - 2;
SizeY = ysize / 2 - 2;
/* select random options if necessary */
if (option == 0)
option = rmg_rndm (MAX_SPIRAL_OPT);
/* the order in which these are evaluated matters */
/* the following two are mutually exclusive.
pick one if they're both set. */
if ((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
{
/* unset REGULAR_SPIRAL half the time */
if (rmg_rndm (2) && (option & REGULAR_SPIRAL))
option -= REGULAR_SPIRAL;
else
option -= FIT_SPIRAL;
}
xscale = yscale = MAX_FINE; /* fine spiral */
/* choose the spiral pitch */
if (!(option & FINE_SPIRAL))
{
float pitch = (rmg_rndm (5)) / 10. + 10. / 22.;
xscale = yscale = pitch;
}
if ((option & FIT_SPIRAL) && (xsize != ysize))
{
if (xsize > ysize)
xscale *= (float) xsize / (float) ysize;
else
yscale *= (float) ysize / (float) xsize;
}
if (option & REGULAR_SPIRAL)
{
float scale = min (xscale, yscale);
xscale = yscale = scale;
}
/* cut out the spiral */
while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
{
x = parm * cos (parm) * xscale;
y = parm * sin (parm) * yscale;
maze[int (ic + x)][int (jc + y)] = '\0';
parm += 0.01;
}
maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
/* cut out the center in a 2x2 and place the center and downexit */
maze[ic][jc + 1] = '>';
maze[ic][jc] = 'C';
}