Atrinik Server 2.5
random_maps/door.c
Go to the documentation of this file.
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 
00044 int surround_check2(char **layout, int x, int y, int Xsize, int Ysize)
00045 {
00046     /* 1 = door or wall to left,
00047         2 = door or wall to right,
00048         4 = door or wall above
00049         8 = door or wall below */
00050     int surround_index = 0;
00051 
00052     if ((x > 0) && (layout[x - 1][y] == 'D' || layout[x - 1][y] == '#'))
00053     {
00054         surround_index += 1;
00055     }
00056 
00057     if ((x < Xsize - 1) && (layout[x + 1][y] == 'D' || layout[x + 1][y] == '#'))
00058     {
00059         surround_index += 2;
00060     }
00061 
00062     if ((y > 0) && (layout[x][y - 1] == 'D' || layout[x][y - 1] == '#'))
00063     {
00064         surround_index += 4;
00065     }
00066 
00067     if ((y < Ysize - 1) && (layout[x][y + 1] == 'D' || layout[x][y + 1] == '#'))
00068     {
00069         surround_index += 8;
00070     }
00071 
00072     return surround_index;
00073 }
00074 
00081 void put_doors(mapstruct *the_map, char **maze, char *doorstyle, RMParms *RP)
00082 {
00083     int x, y;
00084     mapstruct *vdoors, *hdoors;
00085     char doorpath[128];
00086 
00087     if (!strcmp(doorstyle, "none"))
00088     {
00089         return;
00090     }
00091 
00092     vdoors = find_style("/styles/doorstyles/vdoors", doorstyle, -1);
00093 
00094     if (!vdoors)
00095     {
00096         return;
00097     }
00098 
00099     snprintf(doorpath, sizeof(doorpath), "/styles/doorstyles/hdoors%s", strrchr(vdoors->path, '/'));
00100     hdoors = find_style(doorpath, 0, -1);
00101 
00102     for (x = 0; x < RP->Xsize; x++)
00103     {
00104         for (y = 0; y < RP->Ysize; y++)
00105         {
00106             if (maze[x][y] == 'D')
00107             {
00108                 int sindex = surround_check2(maze, x, y, RP->Xsize, RP->Ysize);
00109                 object *this_door, *new_door;
00110 
00111                 if (sindex == 3)
00112                 {
00113                     this_door = pick_random_object(hdoors);
00114                 }
00115                 else
00116                 {
00117                     this_door = pick_random_object(vdoors);
00118                 }
00119 
00120                 new_door = arch_to_object(this_door->arch);
00121                 copy_object(this_door, new_door, 0);
00122                 new_door->x = x;
00123                 new_door->y = y;
00124 
00125                 insert_ob_in_map(new_door, the_map, NULL, INS_NO_MERGE | INS_NO_WALK_ON);
00126             }
00127         }
00128     }
00129 }