Crossfire Server, Trunk  R20513
floor.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2013 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include <global.h>
20 #include <random_map.h>
21 #include <rproto.h>
22 
30 static int can_propagate(char item)
31 {
32  return (item == '\0' || item == '<' || item == '>') ? 1 : 0;
33 }
34 
47 static void put_floor(mapstruct *map, char **layout, int x, int y, object *floor_arch)
48 {
49  int dx, dy;
50  object *floor;
51 
52  floor = arch_to_object(floor_arch->arch);
53  object_insert_in_map_at(floor, map, floor, INS_NO_MERGE|INS_NO_WALK_ON, x, y);
54 
55  for (dx = -1; dx < 2; dx++) {
56  for (dy = -1; dy < 2; dy++) {
57  if (GET_MAP_OB(map, x+dx, y+dy) == NULL && can_propagate(layout[x+dx][y+dy])) {
58  put_floor(map, layout, x+dx, y+dy, floor_arch);
59  }
60  }
61  }
62 }
63 
75 mapstruct *make_map_floor(char **layout, char *floorstyle, RMParms *RP)
76 {
77  char styledirname[256];
78  mapstruct *style_map = NULL;
79  object *the_floor;
80  mapstruct *newMap = NULL;
81  int x, y;
82 
83  /* allocate the map */
84  newMap = get_empty_map(RP->Xsize, RP->Ysize);
85 
86  /* get the style map */
87  snprintf(styledirname, sizeof(styledirname), "%s", "/styles/floorstyles");
88  style_map = find_style(styledirname, floorstyle, -1);
89  if (style_map == NULL) {
90  return newMap;
91  }
92 
93  if (RP->multiple_floors) {
94  for (x = 0; x < RP->Xsize; x++) {
95  for (y = 0; y < RP->Ysize; y++) {
96  if (GET_MAP_OB(newMap, x, y) == NULL && layout[x][y] == '\0') {
97  put_floor(newMap, layout, x, y, pick_random_object(style_map));
98  }
99  }
100  }
101  }
102 
103  /* fill up the map with the given floor style */
104  if ((the_floor = pick_random_object(style_map)) != NULL) {
105  object *thisfloor;
106 
107  for (x = 0; x < RP->Xsize; x++)
108  for (y = 0; y < RP->Ysize; y++) {
109  if (GET_MAP_OB(newMap, x, y) != NULL) {
110  continue;
111  }
112  thisfloor = arch_to_object(the_floor->arch);
113  object_insert_in_map_at(thisfloor, newMap, thisfloor, INS_NO_MERGE|INS_NO_WALK_ON, x, y);
114  }
115  }
116  return newMap;
117 }
mapstruct * make_map_floor(char **layout, char *floorstyle, RMParms *RP)
Creates the Crossfire mapstruct object from the layout, and adds the floor.
Definition: floor.c:75
Random map parameters.
Definition: random_map.h:14
static int can_propagate(char item)
Checks if the tile &#39;propagates&#39; the floor.
Definition: floor.c:30
mapstruct * get_empty_map(int sizex, int sizey)
Creates and returns a map of the specific size.
Definition: map.c:874
Random map related variables.
Global type definitions and header inclusions.
object * pick_random_object(mapstruct *style)
Picks a random object from a style map.
Definition: style.c:286
int multiple_floors
If non zero, then the map will have multiple floors, else only one floor will be used.
Definition: random_map.h:96
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Same as object_insert_in_map() except it handle separate coordinates and do a clean job preparing mul...
Definition: object.c:1921
#define snprintf
Definition: win32.h:46
#define INS_NO_WALK_ON
Don&#39;t call check_walk_on against the originator.
Definition: object.h:570
static void put_floor(mapstruct *map, char **layout, int x, int y, object *floor_arch)
Put a floor at specified location, and then to adjacent tiles if applicable.
Definition: floor.c:47
int Ysize
Definition: random_map.h:70
int Xsize
Definition: random_map.h:69
#define INS_NO_MERGE
Don&#39;t try to merge with other items.
Definition: object.h:568
struct archt * arch
Pointer to archetype.
Definition: object.h:412
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
Definition: map.h:172
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Loads and returns the map requested.
Definition: style.c:180
This is a game-map.
Definition: map.h:325
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Definition: arch.c:571
Definition: main.c:88