|
Atrinik Server 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00030 #include <global.h> 00031 00037 char **make_snake_layout(int xsize, int ysize) 00038 { 00039 int i, j; 00040 /* Allocate that array, set it up */ 00041 char **maze = (char **) calloc(sizeof(char *), xsize); 00042 00043 for (i = 0; i < xsize; i++) 00044 { 00045 maze[i] = (char *) calloc(sizeof(char), ysize); 00046 } 00047 00048 /* Write the outer walls */ 00049 for (i = 0; i < xsize; i++) 00050 { 00051 maze[i][0] = maze[i][ysize - 1] = '#'; 00052 } 00053 00054 for (j = 0; j < ysize; j++) 00055 { 00056 maze[0][j] = maze[xsize - 1][j] = '#'; 00057 } 00058 00059 /* Bail out if the size is too small to make a snake. */ 00060 if (xsize < 8 || ysize < 8) 00061 { 00062 return maze; 00063 } 00064 00065 /* decide snake orientation--vertical or horizontal, and 00066 make the walls and place the doors. */ 00067 00068 /* vertical orientation */ 00069 if (RANDOM() % 2) 00070 { 00071 int n_walls = RANDOM() % ((xsize - 5) / 3) + 1; 00072 int spacing = xsize / (n_walls + 1); 00073 int orientation = 1; 00074 00075 for (i = spacing; i < xsize - 3; i += spacing) 00076 { 00077 if (orientation) 00078 { 00079 for (j = 1; j < ysize - 2; j++) 00080 { 00081 maze[i][j] = '#'; 00082 } 00083 00084 maze[i][j] = 'D'; 00085 } 00086 else 00087 { 00088 for (j = 2; j < ysize; j++) 00089 { 00090 maze[i][j] = '#'; 00091 } 00092 00093 maze[i][1] = 'D'; 00094 } 00095 00096 /* toggle the value of orientation */ 00097 orientation ^= 1; 00098 } 00099 } 00100 /* horizontal orientation */ 00101 else 00102 { 00103 int n_walls = RANDOM() % ((ysize - 5) / 3) + 1; 00104 int spacing = ysize / (n_walls + 1); 00105 int orientation = 1; 00106 00107 for (i = spacing; i < ysize - 3; i += spacing) 00108 { 00109 if (orientation) 00110 { 00111 for (j = 1; j < xsize - 2; j++) 00112 { 00113 maze[j][i] = '#'; 00114 } 00115 00116 maze[j][i] = 'D'; 00117 } 00118 else 00119 { 00120 for (j = 2; j < xsize; j++) 00121 { 00122 maze[j][i] = '#'; 00123 } 00124 00125 maze[1][i] = 'D'; 00126 } 00127 00128 /* toggle the value of orientation */ 00129 orientation ^= 1; 00130 } 00131 } 00132 00133 /* Place the exit up/down */ 00134 if (RANDOM() % 2) 00135 { 00136 maze[1][1] = '<'; 00137 maze[xsize - 2][ysize - 2] = '>'; 00138 } 00139 else 00140 { 00141 maze[1][1] = '>'; 00142 maze[xsize - 2][ysize - 2] = '<'; 00143 } 00144 00145 return maze; 00146 }
1.7.4