Crossfire Server, Trunk  R20513
door.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 
21 #include <string.h>
22 
23 #include "random_map.h"
24 #include "rproto.h"
25 
43 int surround_check2(char **layout, int i, int j, int Xsize, int Ysize)
44 {
45  int surround_index = 0;
46 
47  if ((i > 0) && (layout[i-1][j] == 'D' || layout[i-1][j] == '#')) {
48  surround_index += 1;
49  }
50  if ((i < Xsize-1) && (layout[i+1][j] == 'D' || layout[i+1][j] == '#')) {
51  surround_index += 2;
52  }
53  if ((j > 0) && (layout[i][j-1] == 'D' || layout[i][j-1] == '#')) {
54  surround_index += 4;
55  }
56  if ((j < Ysize-1) && (layout[i][j+1] == 'D' || layout[i][j+1] == '#')) {
57  surround_index += 8;
58  }
59  return surround_index;
60 }
61 
73 void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP)
74 {
75  int i, j;
76  mapstruct *vdoors;
77  mapstruct *hdoors;
78  char doorpath[128];
79 
80  if (!strcmp(doorstyle, "none")) {
81  return;
82  }
83  vdoors = find_style("/styles/doorstyles", doorstyle, -1);
84  if (vdoors) {
85  hdoors = vdoors;
86  } else {
87  vdoors = find_style("/styles/doorstyles/vdoors", doorstyle, -1);
88  if (!vdoors) {
89  return;
90  }
91  snprintf(doorpath, sizeof(doorpath), "/styles/doorstyles/hdoors%s", strrchr(vdoors->path, '/'));
92  hdoors = find_style(doorpath, NULL, -1);
93  }
94 
95  for (i = 0; i < RP->Xsize; i++)
96  for (j = 0; j < RP->Ysize; j++) {
97  if (maze[i][j] == 'D') {
98  int sindex;
99  object *this_door, *new_door;
100 
101  sindex = surround_check2(maze, i, j, RP->Xsize, RP->Ysize);
102  if (sindex == 3) {
103  this_door = pick_random_object(hdoors);
104  } else {
105  this_door = pick_random_object(vdoors);
106  }
107  new_door = arch_to_object(this_door->arch);
108  object_copy(this_door, new_door);
109  object_insert_in_map_at(new_door, the_map, NULL, 0, i, j);
110  }
111  }
112 }
char path[HUGE_BUF]
Filename of the map.
Definition: map.h:365
Random map parameters.
Definition: random_map.h:14
Random map related variables.
int surround_check2(char **layout, int i, int j, int Xsize, int Ysize)
Serch for doors or walls around a spot.
Definition: door.c:43
Global type definitions and header inclusions.
object * pick_random_object(mapstruct *style)
Picks a random object from a style map.
Definition: style.c:286
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
int Ysize
Definition: random_map.h:70
int Xsize
Definition: random_map.h:69
struct archt * arch
Pointer to archetype.
Definition: object.h:412
void object_copy(const object *src_ob, object *dest_ob)
Copy object first frees everything allocated by the second object, and then copies the contents of th...
Definition: object.c:838
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
void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP)
Add doors to a map.
Definition: door.c:73
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