Crossfire Server, Branches 1.12  R18729
floor.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_floor_c =
3  * "$Id: floor.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 
45 static int can_propagate(char item) {
46  return (item == '\0' || item == '<' || item == '>') ? 1 : 0;
47 }
48 
61 static void put_floor(mapstruct *map, char **layout, int x, int y, object *floor_arch) {
62  int dx, dy;
63  object *floor;
64 
65  floor = arch_to_object(floor_arch->arch);
66  floor->x = x;
67  floor->y = y;
68  insert_ob_in_map(floor, map, floor, INS_NO_MERGE|INS_NO_WALK_ON);
69 
70  for (dx = -1; dx < 2; dx++) {
71  for (dy = -1; dy < 2; dy++) {
72  if (GET_MAP_OB(map, x+dx, y+dy) == NULL && can_propagate(layout[x+dx][y+dy]))
73  put_floor(map, layout, x+dx, y+dy, floor_arch);
74  }
75  }
76 }
77 
89 mapstruct *make_map_floor(char **layout, char *floorstyle, RMParms *RP) {
90  char styledirname[256];
91  char stylefilepath[256];
92  mapstruct *style_map = NULL;
93  object *the_floor;
94  mapstruct *newMap = NULL;
95  int x, y;
96 
97  /* allocate the map */
98  newMap = get_empty_map(RP->Xsize, RP->Ysize);
99 
100  /* get the style map */
101  snprintf(styledirname, sizeof(styledirname), "%s", "/styles/floorstyles");
102  snprintf(stylefilepath, sizeof(stylefilepath), "%s/%s", styledirname, floorstyle);
103  style_map = find_style(styledirname, floorstyle, -1);
104  if (style_map == NULL)
105  return newMap;
106 
107  if (RP->multiple_floors) {
108  for (x = 0; x < RP->Xsize; x++) {
109  for (y = 0; y < RP->Ysize; y++) {
110  if (GET_MAP_OB(newMap, x, y) == NULL && layout[x][y] == '\0')
111  put_floor(newMap, layout, x, y, pick_random_object(style_map));
112  }
113  }
114  }
115 
116  /* fill up the map with the given floor style */
117  if ((the_floor = pick_random_object(style_map)) != NULL) {
118  object *thisfloor;
119 
120  for (x = 0; x < RP->Xsize; x++)
121  for (y = 0; y < RP->Ysize; y++) {
122  if (GET_MAP_OB(newMap, x, y) != NULL)
123  continue;
124  thisfloor = arch_to_object(the_floor->arch);
125  thisfloor->x = x;
126  thisfloor->y = y;
127  insert_ob_in_map(thisfloor, newMap, thisfloor, INS_NO_MERGE|INS_NO_WALK_ON);
128  }
129  }
130  return newMap;
131 }
mapstruct * make_map_floor(char **layout, char *floorstyle, RMParms *RP)
Definition: floor.c:89
static int can_propagate(char item)
Definition: floor.c:45
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.c:884
sint16 x
Definition: object.h:179
object * pick_random_object(mapstruct *style)
Definition: style.c:275
int multiple_floors
Definition: random_map.h:81
#define INS_NO_WALK_ON
Definition: object.h:396
static void put_floor(mapstruct *map, char **layout, int x, int y, object *floor_arch)
Definition: floor.c:61
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
#define INS_NO_MERGE
Definition: object.h:394
struct archt * arch
Definition: object.h:263
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.c:177
Definition: map.h:346
object * arch_to_object(archetype *at)
Definition: arch.c:576