Crossfire Server, Branches 1.12  R18729
door.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_door_c =
3  * "$Id: door.c 11578 2009-02-23 22:02:27Z lalo $";
4  */
5 
6 /*
7  CrossFire, A Multiplayer game for X-windows
8 
9  Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10  Copyright (C) 1992 Frank Tore Johansen
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 
26  The authors can be reached via e-mail at crossfire-devel@real-time.com
27 */
28 
34 #include <global.h>
35 #include <random_map.h>
36 #include <rproto.h>
37 
55 int surround_check2(char **layout, int i, int j, int Xsize, int Ysize) {
56  int surround_index = 0;
57 
58  if ((i > 0) && (layout[i-1][j] == 'D' || layout[i-1][j] == '#'))
59  surround_index += 1;
60  if ((i < Xsize-1) && (layout[i+1][j] == 'D' || layout[i+1][j] == '#'))
61  surround_index += 2;
62  if ((j > 0) && (layout[i][j-1] == 'D' || layout[i][j-1] == '#'))
63  surround_index += 4;
64  if ((j < Ysize-1) && (layout[i][j+1] == 'D' && layout[i][j+1] == '#'))
65  surround_index += 8;
66  return surround_index;
67 }
68 
80 void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP) {
81  int i, j;
82  mapstruct *vdoors;
83  mapstruct *hdoors;
84  char doorpath[128];
85 
86  if (!strcmp(doorstyle, "none"))
87  return;
88  vdoors = find_style("/styles/doorstyles", doorstyle, -1);
89  if (vdoors)
90  hdoors = vdoors;
91  else {
92  vdoors = find_style("/styles/doorstyles/vdoors", doorstyle, -1);
93  if (!vdoors)
94  return;
95  snprintf(doorpath, sizeof(doorpath), "/styles/doorstyles/hdoors%s", strrchr(vdoors->path, '/'));
96  hdoors = find_style(doorpath, NULL, -1);
97  }
98 
99  for (i = 0; i < RP->Xsize; i++)
100  for (j = 0; j < RP->Ysize; j++) {
101  if (maze[i][j] == 'D') {
102  int sindex;
103  object *this_door, *new_door;
104 
105  sindex = surround_check2(maze, i, j, RP->Xsize, RP->Ysize);
106  if (sindex == 3)
107  this_door = pick_random_object(hdoors);
108  else
109  this_door = pick_random_object(vdoors);
110  new_door = arch_to_object(this_door->arch);
111  copy_object(this_door, new_door);
112  new_door->x = i;
113  new_door->y = j;
114  insert_ob_in_map(new_door, the_map, NULL, 0);
115  }
116  }
117 }
char path[HUGE_BUF]
Definition: map.h:384
int surround_check2(char **layout, int i, int j, int Xsize, int Ysize)
Definition: door.c:55
sint16 x
Definition: object.h:179
object * pick_random_object(mapstruct *style)
Definition: style.c:275
sint16 y
Definition: object.h:179
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1992
int Ysize
Definition: random_map.h:60
int Xsize
Definition: random_map.h:59
int snprintf(char *dest, int max, const char *format,...)
Definition: porting.c:498
struct archt * arch
Definition: object.h:263
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.c:177
void copy_object(object *op2, object *op)
Definition: object.c:758
Definition: map.h:346
void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP)
Definition: door.c:80
object * arch_to_object(archetype *at)
Definition: arch.c:576