Crossfire Server, Trunk
door.cpp
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 }
global.h
random_map.h
layout
Definition: main.cpp:84
object::arch
struct archetype * arch
Definition: object.h:424
RMParms::Ysize
int Ysize
Definition: random_map.h:75
object_copy
void object_copy(const object *src_ob, object *dest_ob)
Definition: object.cpp:1192
find_style
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.cpp:180
mapstruct::path
char path[HUGE_BUF]
Definition: map.h:353
RMParms
Definition: random_map.h:14
rproto.h
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.cpp:2100
surround_check2
int surround_check2(char **layout, int i, int j, int Xsize, int Ysize)
Definition: door.cpp:43
mapstruct
Definition: map.h:313
pick_random_object
object * pick_random_object(mapstruct *style)
Definition: style.cpp:289
put_doors
void put_doors(mapstruct *the_map, char **maze, const char *doorstyle, RMParms *RP)
Definition: door.cpp:73
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:229
RMParms::Xsize
int Xsize
Definition: random_map.h:74