--- cf.schmorp.de/server/random_maps/room_gen_onion.C 2006/12/30 18:45:28 1.5 +++ cf.schmorp.de/server/random_maps/room_gen_onion.C 2007/01/27 02:19:37 1.10 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2001 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 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 GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The authors can be reached via e-mail at -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2001 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The authors can be reached via e-mail at + */ /* The onion room generator: @@ -80,21 +81,21 @@ /* pick some random options if option = 0 */ if (option == 0) { - switch (RANDOM () % 3) + switch (rndm (3)) { - case 0: - option |= RMOPT_CENTERED; - break; - case 1: - option |= RMOPT_BOTTOM_C; - break; - case 2: - option |= RMOPT_BOTTOM_R; - break; + case 0: + option |= RMOPT_CENTERED; + break; + case 1: + option |= RMOPT_BOTTOM_C; + break; + case 2: + option |= RMOPT_BOTTOM_R; + break; } - if (RANDOM () % 2) + if (rndm (2)) option |= RMOPT_LINEAR; - if (RANDOM () % 2) + if (rndm (2)) option |= RMOPT_IRR_SPACE; } @@ -131,16 +132,18 @@ maxlayers = (MIN (xsize, ysize) - 2) / 5; if (!maxlayers) return; /* map too small to onionize */ + if (layers > maxlayers) layers = maxlayers; + if (layers == 0) - layers = (RANDOM () % maxlayers) + 1; + layers = rndm (maxlayers) + 1; + xlocations = (float *) calloc (sizeof (float), 2 * layers); ylocations = (float *) calloc (sizeof (float), 2 * layers); - /* place all the walls */ - if (option & RMOPT_IRR_SPACE) /* randomly spaced */ + if (option & RMOPT_IRR_SPACE) /* randomly spaced */ { int x_spaces_available, y_spaces_available; @@ -155,10 +158,11 @@ float xpitch = 2, ypitch = 2; if (x_spaces_available > 0) - xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; + xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; if (y_spaces_available > 0) - ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; + ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; + xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; x_spaces_available -= (int) (xpitch - 2); @@ -201,13 +205,13 @@ if (layers > maxlayers) layers = maxlayers; if (layers == 0) - layers = (RANDOM () % maxlayers) + 1; + layers = rndm (maxlayers) + 1; xlocations = (float *) calloc (sizeof (float), 2 * layers); ylocations = (float *) calloc (sizeof (float), 2 * layers); /* place all the walls */ - if (option & RMOPT_IRR_SPACE) /* randomly spaced */ + if (option & RMOPT_IRR_SPACE) /* randomly spaced */ { int x_spaces_available, y_spaces_available; @@ -222,15 +226,17 @@ float xpitch = 2, ypitch = 2; if (x_spaces_available > 0) - xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; + xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; if (y_spaces_available > 0) - ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; + ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; + xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; if (i < layers) ylocations[i] = ((i > 0) ? ylocations[i - 1] : 0) + ypitch; else ylocations[i] = ysize - 1; + x_spaces_available -= (int) (xpitch - 2); y_spaces_available -= (int) (ypitch - 2); } @@ -308,86 +314,87 @@ freedoms = 2; if (layers <= 0) return; + /* pick which wall will have a door. */ - which_wall = RANDOM () % freedoms + 1; + which_wall = rndm (freedoms) + 1; for (l = 0; l < layers; l++) { if (options & RMOPT_LINEAR) { /* linear door placement. */ switch (which_wall) { - case 1: - { /* left hand wall */ - x1 = (int) xlocations[l]; - y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); - break; - } - case 2: - { /* top wall placement */ - x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); - y1 = (int) ylocations[l]; - break; - } - case 3: - { /* right wall placement */ - x1 = (int) xlocations[2 * layers - l - 1]; - y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); - break; - } - case 4: - { /* bottom wall placement */ - x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); - y1 = (int) ylocations[2 * layers - l - 1]; - break; - } + case 1: + { /* left hand wall */ + x1 = (int) xlocations[l]; + y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); + break; + } + case 2: + { /* top wall placement */ + x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); + y1 = (int) ylocations[l]; + break; + } + case 3: + { /* right wall placement */ + x1 = (int) xlocations[2 * layers - l - 1]; + y1 = (int) ((ylocations[l] + ylocations[2 * layers - l - 1]) / 2); + break; + } + case 4: + { /* bottom wall placement */ + x1 = (int) ((xlocations[l] + xlocations[2 * layers - l - 1]) / 2); + y1 = (int) ylocations[2 * layers - l - 1]; + break; + } } } else { /* random door placement. */ - which_wall = RANDOM () % freedoms + 1; + which_wall = rndm (freedoms) + 1; switch (which_wall) { - case 1: - { /* left hand wall */ - x1 = (int) xlocations[l]; - y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); - if (y2 > 0) - y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); - else - y1 = (int) (ylocations[l] + 1); - break; - } - case 2: - { /* top wall placement */ - x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; - if (x2 > 0) - x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); - else - x1 = (int) (xlocations[l] + 1); - y1 = (int) ylocations[l]; - break; - } - case 3: - { /* right wall placement */ - x1 = (int) xlocations[2 * layers - l - 1]; - y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; - if (y2 > 0) - y1 = (int) (ylocations[l] + RANDOM () % y2 + 1); - else - y1 = (int) (ylocations[l] + 1); - - break; - } - case 4: - { /* bottom wall placement */ - x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; - if (x2 > 0) - x1 = (int) (xlocations[l] + RANDOM () % x2 + 1); - else - x1 = (int) (xlocations[l] + 1); - y1 = (int) ylocations[2 * layers - l - 1]; - break; - } + case 1: + { /* left hand wall */ + x1 = (int) xlocations[l]; + y2 = (int) (ylocations[2 * layers - l - 1] - ylocations[l] - 1); + if (y2 > 0) + y1 = (int) (ylocations[l] + rndm (y2) + 1); + else + y1 = (int) (ylocations[l] + 1); + break; + } + case 2: + { /* top wall placement */ + x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; + if (x2 > 0) + x1 = (int) (xlocations[l] + rndm (x2) + 1); + else + x1 = (int) (xlocations[l] + 1); + y1 = (int) ylocations[l]; + break; + } + case 3: + { /* right wall placement */ + x1 = (int) xlocations[2 * layers - l - 1]; + y2 = (int) ((-ylocations[l] + ylocations[2 * layers - l - 1])) - 1; + if (y2 > 0) + y1 = (int) (ylocations[l] + rndm (y2) + 1); + else + y1 = (int) (ylocations[l] + 1); + + break; + } + case 4: + { /* bottom wall placement */ + x2 = (int) ((-xlocations[l] + xlocations[2 * layers - l - 1])) - 1; + if (x2 > 0) + x1 = (int) (xlocations[l] + rndm (x2) + 1); + else + x1 = (int) (xlocations[l] + 1); + y1 = (int) ylocations[2 * layers - l - 1]; + break; + } } } @@ -422,13 +429,13 @@ if (layers > maxlayers) layers = maxlayers; if (layers == 0) - layers = (RANDOM () % maxlayers) + 1; + layers = rndm (maxlayers) + 1; + xlocations = (float *) calloc (sizeof (float), 2 * layers); ylocations = (float *) calloc (sizeof (float), 2 * layers); - /* place all the walls */ - if (option & RMOPT_IRR_SPACE) /* randomly spaced */ + if (option & RMOPT_IRR_SPACE) /* randomly spaced */ { int x_spaces_available, y_spaces_available; @@ -443,10 +450,11 @@ float xpitch = 2, ypitch = 2; if (x_spaces_available > 0) - xpitch = 2 + (RANDOM () % x_spaces_available + RANDOM () % x_spaces_available + RANDOM () % x_spaces_available) / 3; + xpitch = 2 + (rndm (x_spaces_available) + rndm (x_spaces_available) + rndm (x_spaces_available)) / 3; if (y_spaces_available > 0) - ypitch = 2 + (RANDOM () % y_spaces_available + RANDOM () % y_spaces_available + RANDOM () % y_spaces_available) / 3; + ypitch = 2 + (rndm (y_spaces_available) + rndm (y_spaces_available) + rndm (y_spaces_available)) / 3; + if (i < layers) xlocations[i] = ((i > 0) ? xlocations[i - 1] : 0) + xpitch; else