Crossfire Server, Branch 1.12  R12190
door.c
Go to the documentation of this file.
00001 /*
00002  * static char *rcsid_door_c =
00003  *   "$Id: door.c 11578 2009-02-23 22:02:27Z lalo $";
00004  */
00005 
00006 /*
00007     CrossFire, A Multiplayer game for X-windows
00008 
00009     Copyright (C) 2002 Mark Wedel & Crossfire Development Team
00010     Copyright (C) 1992 Frank Tore Johansen
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00025 
00026     The authors can be reached via e-mail at crossfire-devel@real-time.com
00027 */
00028 
00034 #include <global.h>
00035 #include <random_map.h>
00036 #include <rproto.h>
00037 
00055 int surround_check2(char **layout, int i, int j, int Xsize, int Ysize) {
00056     int surround_index = 0;
00057 
00058     if ((i > 0) && (layout[i-1][j] == 'D' || layout[i-1][j] == '#'))
00059         surround_index += 1;
00060     if ((i < Xsize-1) && (layout[i+1][j] == 'D' || layout[i+1][j] == '#'))
00061         surround_index += 2;
00062     if ((j > 0) && (layout[i][j-1] == 'D' || layout[i][j-1] == '#'))
00063         surround_index += 4;
00064     if ((j < Ysize-1) && (layout[i][j+1] == 'D' && layout[i][j+1] == '#'))
00065         surround_index += 8;
00066     return surround_index;
00067 }
00068 
00080 void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP) {
00081     int i, j;
00082     mapstruct *vdoors;
00083     mapstruct *hdoors;
00084     char doorpath[128];
00085 
00086     if (!strcmp(doorstyle, "none"))
00087         return;
00088     vdoors = find_style("/styles/doorstyles", doorstyle, -1);
00089     if (vdoors)
00090         hdoors = vdoors;
00091     else {
00092         vdoors = find_style("/styles/doorstyles/vdoors", doorstyle, -1);
00093         if (!vdoors)
00094             return;
00095         snprintf(doorpath, sizeof(doorpath), "/styles/doorstyles/hdoors%s", strrchr(vdoors->path, '/'));
00096         hdoors = find_style(doorpath, NULL, -1);
00097     }
00098 
00099     for (i = 0; i < RP->Xsize; i++)
00100         for (j = 0; j < RP->Ysize; j++) {
00101             if (maze[i][j] == 'D') {
00102                 int sindex;
00103                 object *this_door, *new_door;
00104 
00105                 sindex = surround_check2(maze, i, j, RP->Xsize, RP->Ysize);
00106                 if (sindex == 3)
00107                     this_door = pick_random_object(hdoors);
00108                 else
00109                     this_door = pick_random_object(vdoors);
00110                 new_door = arch_to_object(this_door->arch);
00111                 copy_object(this_door, new_door);
00112                 new_door->x = i;
00113                 new_door->y = j;
00114                 insert_ob_in_map(new_door, the_map, NULL, 0);
00115             }
00116         }
00117 }