Crossfire Server, Trunk
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);
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  mapstruct *style_map = NULL;
78  object *the_floor;
79  mapstruct *newMap = NULL;
80  int x, y;
81 
82  /* allocate the map */
83  newMap = get_empty_map(RP->Xsize, RP->Ysize);
84 
85  /* get the style map */
86  const char *styledirname = "/styles/floorstyles";
87  style_map = find_style(styledirname, floorstyle, -1);
88  if (style_map == NULL) {
89  return newMap;
90  }
91 
92  if (RP->multiple_floors) {
93  for (x = 0; x < RP->Xsize; x++) {
94  for (y = 0; y < RP->Ysize; y++) {
95  if (GET_MAP_OB(newMap, x, y) == NULL && layout[x][y] == '\0') {
96  put_floor(newMap, layout, x, y, pick_random_object(style_map));
97  }
98  }
99  }
100  }
101 
102  /* fill up the map with the given floor style */
103  if ((the_floor = pick_random_object(style_map)) != NULL) {
104  object *thisfloor;
105 
106  for (x = 0; x < RP->Xsize; x++)
107  for (y = 0; y < RP->Ysize; y++) {
108  if (GET_MAP_OB(newMap, x, y) != NULL) {
109  continue;
110  }
111  thisfloor = arch_to_object(the_floor->arch);
112  object_insert_in_map_at(thisfloor, newMap, thisfloor, INS_NO_MERGE|INS_NO_WALK_ON, x, y);
113  }
114  }
115  return newMap;
116 }
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
global.h
INS_NO_WALK_ON
#define INS_NO_WALK_ON
Definition: object.h:568
random_map.h
layout
Definition: main.c:85
make_map_floor
mapstruct * make_map_floor(char **layout, char *floorstyle, RMParms *RP)
Definition: floor.c:75
RMParms::multiple_floors
int multiple_floors
Definition: random_map.h:101
diamondslots.x
x
Definition: diamondslots.py:15
RMParms::Ysize
int Ysize
Definition: random_map.h:75
find_style
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.c:180
RMParms
Definition: random_map.h:14
disinfect.map
map
Definition: disinfect.py:4
INS_NO_MERGE
#define INS_NO_MERGE
Definition: object.h:566
put_floor
static void put_floor(mapstruct *map, char **layout, int x, int y, object *floor_arch)
Definition: floor.c:47
rproto.h
mapdef
Definition: map.h:317
obj::arch
struct archt * arch
Definition: object.h:417
can_propagate
static int can_propagate(char item)
Definition: floor.c:30
item
Definition: item.py:1
pick_random_object
object * pick_random_object(mapstruct *style)
Definition: style.c:289
diamondslots.y
y
Definition: diamondslots.py:16
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:2080
get_empty_map
mapstruct * get_empty_map(int sizex, int sizey)
Definition: map.c:869
RMParms::Xsize
int Xsize
Definition: random_map.h:74