ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.C
(Generate patch)

Comparing deliantra/server/random_maps/room_gen_spiral.C (file contents):
Revision 1.11 by root, Thu Nov 8 19:43:25 2007 UTC vs.
Revision 1.12 by root, Fri Apr 11 21:09:53 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 1994,2007 Mark Wedel 5 * Copyright (©) 1994,2007 Mark Wedel
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
49 49
50#define MAX_FINE .454545 50#define MAX_FINE .454545
51 51
52extern int surround_check (char **maze, int i, int j, int xsize, int ysize); 52extern int surround_check (char **maze, int i, int j, int xsize, int ysize);
53 53
54char ** 54Maze
55map_gen_spiral (int xsize, int ysize, int option) 55map_gen_spiral (int xsize, int ysize, int option)
56{ 56{
57 int i, j; 57 int i, j;
58 float parm = 0; 58 float parm = 0;
59 float x = 0, y = 0; 59 float x = 0, y = 0;
60 int ic, jc; 60 int ic, jc;
61 float SizeX, SizeY; 61 float SizeX, SizeY;
62 float xscale, yscale; 62 float xscale, yscale;
63 63
64 /* allocate that array, set it up */ 64 Maze maze (xsize, ysize);
65 char **maze = (char **) calloc (sizeof (char *), xsize);
66
67 for (i = 0; i < xsize; i++)
68 {
69 maze[i] = (char *) calloc (sizeof (char), ysize);
70 }
71 65
72 /* slightly easier to fill and then cut */ 66 /* slightly easier to fill and then cut */
73 for (i = 0; i < xsize; i++) 67 for (i = 0; i < xsize; i++)
74 for (j = 0; j < ysize; j++) 68 for (j = 0; j < ysize; j++)
75 maze[i][j] = '#'; 69 maze[i][j] = '#';
79 SizeX = xsize / 2 - 2; 73 SizeX = xsize / 2 - 2;
80 SizeY = ysize / 2 - 2; 74 SizeY = ysize / 2 - 2;
81 75
82 /* select random options if necessary */ 76 /* select random options if necessary */
83 if (option == 0) 77 if (option == 0)
84 {
85 option = rndm (MAX_SPIRAL_OPT); 78 option = rndm (MAX_SPIRAL_OPT);
86 }
87 79
88 /* the order in which these are evaluated matters */ 80 /* the order in which these are evaluated matters */
89 81
90 /* the following two are mutually exclusive. 82 /* the following two are mutually exclusive.
91 pick one if they're both set. */ 83 pick one if they're both set. */
126 /* cut out the spiral */ 118 /* cut out the spiral */
127 while ((fabs (x) < SizeX) && (fabs (y) < SizeY)) 119 while ((fabs (x) < SizeX) && (fabs (y) < SizeY))
128 { 120 {
129 x = parm * cos (parm) * xscale; 121 x = parm * cos (parm) * xscale;
130 y = parm * sin (parm) * yscale; 122 y = parm * sin (parm) * yscale;
131 maze[(int) (ic + x)][(int) (jc + y)] = '\0'; 123 maze[int (ic + x)][int (jc + y)] = '\0';
132 parm += 0.01; 124 parm += 0.01;
133 }; 125 };
134 126
135 maze[(int) (ic + x + 0.5)][(int) (jc + y + 0.5)] = '<'; 127 maze[int (ic + x + 0.5)][int (jc + y + 0.5)] = '<';
136
137 128
138 /* cut out the center in a 2x2 and place the center and downexit */ 129 /* cut out the center in a 2x2 and place the center and downexit */
139 maze[ic][jc + 1] = '>'; 130 maze[ic][jc + 1] = '>';
140 maze[ic][jc] = 'C'; 131 maze[ic][jc] = 'C';
141
142 132
143 return maze; 133 return maze;
144} 134}
145 135
146/* the following function connects disjoint spirals which may 136/* the following function connects disjoint spirals which may
222 i = 0; 212 i = 0;
223 j = 0; 213 j = 0;
224 } 214 }
225 } 215 }
226 } 216 }
227
228
229
230} 217}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines