ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/room_gen_spiral.c
Revision: 1.2
Committed: Sun Aug 13 17:16:03 2006 UTC (17 years, 9 months ago) by elmex
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
State: FILE REMOVED
Log Message:
Made server compile with C++.
Removed cfanim plugin and crossedit.
C++ here we come.

File Contents

# Content
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 1994 Mark Wedel
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The author can be reached via e-mail to mark@pyramid.com
22 */
23
24
25 /* The onion room generator:
26 Onion rooms are like this:
27
28 char **map_gen_spiral(int xsize, int ysize, int option);
29
30
31 */
32 #include <global.h>
33 #include <random_map.h>
34
35 #define RANDOM_OPTIONS 0 /* Pick random options below */
36 #define REGULAR_SPIRAL 1 /* Regular spiral--distance increases constantly*/
37 #define FINE_SPIRAL 2 /* uses the min. separation: most coiling */
38 #define FIT_SPIRAL 4 /* scale to a rectangular region, not square */
39 #define MAX_SPIRAL_OPT 8 /* this should be 2x the last real option */
40 #include <math.h>
41
42 int *free_x_list;
43 int *free_y_list;
44
45 #ifndef MIN
46 #define MIN(x,y) (((x)<(y))? (x):(y))
47 #endif
48 #ifndef MAX
49 #define MAX(x,y) (((x)<(y))? (y):(x))
50 #endif
51
52 #define MINDIST 3
53
54 #define MAX_FINE .454545
55
56 extern int surround_check(char **maze,int i, int j, int xsize, int ysize);
57
58 char **map_gen_spiral(int xsize, int ysize, int option) {
59 int i,j;
60 float parm=0;
61 float x=0,y=0;
62 int ic,jc;
63 float SizeX,SizeY;
64 float xscale,yscale;
65
66 /* allocate that array, set it up */
67 char **maze = (char **)calloc(sizeof(char*),xsize);
68 for(i=0;i<xsize;i++) {
69 maze[i] = (char *) calloc(sizeof(char),ysize);
70 }
71
72 /* slightly easier to fill and then cut */
73 for(i=0;i<xsize;i++) for(j=0;j<ysize;j++) maze[i][j] = '#';
74
75 ic = xsize/2;
76 jc = ysize/2;
77 SizeX = xsize/2 - 2;
78 SizeY = ysize/2 -2;
79
80 /* select random options if necessary */
81 if(option==0) {
82 option=RANDOM()%MAX_SPIRAL_OPT;
83 }
84
85 /* the order in which these are evaluated matters*/
86
87 /* the following two are mutually exclusive.
88 pick one if they're both set. */
89 if((option & REGULAR_SPIRAL) && (option & FIT_SPIRAL))
90 {
91 /* unset REGULAR_SPIRAL half the time */
92 if(RANDOM()%2 && (option & REGULAR_SPIRAL))
93 option -= REGULAR_SPIRAL;
94 else
95 option -= FIT_SPIRAL;
96 }
97
98 xscale=yscale=MAX_FINE; /* fine spiral */
99
100 /* choose the spiral pitch */
101 if(! (option & FINE_SPIRAL) ) {
102 float pitch = (RANDOM() %5)/10. + 10./22.;
103 xscale=yscale=pitch;
104 }
105
106 if((option & FIT_SPIRAL) && (xsize!=ysize) ) {
107 if(xsize > ysize) xscale *= (float)xsize/(float)ysize;
108 else yscale *= (float)ysize/(float)xsize;
109 }
110
111 if(option & REGULAR_SPIRAL) {
112 float scale = MIN(xscale,yscale);
113 xscale=yscale=scale;
114 }
115
116 /* cut out the spiral */
117 while( (abs(x) < SizeX) && (abs(y) < SizeY) )
118 {
119 x = parm * cos(parm)*xscale;
120 y = parm * sin(parm)*yscale;
121 maze[(int)(ic + x )][(int)(jc + y )]='\0';
122 parm+=0.01;
123 };
124
125 maze[(int)(ic + x+0.5)][(int)(jc + y+0.5)]='<';
126
127
128 /* cut out the center in a 2x2 and place the center and downexit */
129 maze[ic][jc+1]='>';
130 maze[ic][jc]='C';
131
132
133 return maze;
134 }
135
136 /* the following function connects disjoint spirals which may
137 result from the symmetrization process. */
138 void connect_spirals(int xsize,int ysize,int sym, char **layout) {
139
140 int i,j,ic=xsize/2,jc=ysize/2;
141
142 if(sym==X_SYM) {
143 layout[ic][jc] = 0;
144 /* go left from map center */
145 for(i=ic-1,j=jc; i>0 && layout[i][j]=='#' ;i--)
146 layout[i][j]=0;
147 /* go right */
148 for(i=ic+1,j=jc; i<xsize-1 && layout[i][j]=='#' ;i++)
149 layout[i][j]=0;
150 }
151
152 if(sym==Y_SYM) {
153
154 layout[ic][jc] = 0;
155 /* go up */
156 for(i=ic,j=jc-1; j>0 && layout[i][j]=='#' ;j--)
157 layout[i][j]=0;
158 /* go down */
159 for(i=ic,j=jc+1; j<ysize-1 && layout[i][j]=='#' ;j++)
160 layout[i][j]=0;
161 }
162
163 if(sym==XY_SYM) {
164 /* go left from map center */
165 layout[ic][jc/2]=0;
166 layout[ic/2][jc]=0;
167 layout[ic][jc/2+jc]=0;
168 layout[ic/2+ic][jc]=0;
169 for(i=ic-1,j=jc/2; i>0 && layout[i][j]=='#' ;i--) {
170 layout[i][j + jc]=0;
171 layout[i][j]=0;
172 }
173 /* go right */
174 for(i=ic+1,j=jc/2; i<xsize-1 && layout[i][j]=='#' ;i++) {
175 layout[i][j+jc]=0;
176 layout[i][j]=0;
177 }
178 /* go up */
179 for(i=ic/2,j=jc-1; j>0 && layout[i][j]=='#' ;j--) {
180 layout[i][j]=0;
181 layout[i+ic][j]=0;
182 }
183 /* go down */
184 for(i=ic/2,j=jc+1; j<ysize-1 && layout[i][j]=='#' ;j++) {
185 layout[i][j]=0;
186 layout[i+ic][j]=0;
187 }
188
189 }
190
191 /* get rid of bad doors. */
192 for(i=0;i<xsize;i++)
193 for(j=0;j<ysize;j++) {
194 if(layout[i][j]=='D') { /* remove bad door. */
195 int si = surround_check(layout,i,j,xsize,ysize);
196 if(si!=3 && si!=12) {
197 layout[i][j]=0;
198 /* back up and recheck any nearby doors */
199 i=0;j=0;
200 }
201 }
202 }
203
204
205
206 }
207