Debian Codegraph @

random_maps/door.c

raw symbols SCIP
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 <[email protected]>.
12 */
13
14 /**
15 * @file
16 * door-related functions.
17 */
18
19 #include "global.h"
20
21 #include <string.h>
22
23 #include "random_map.h"
24 #include "rproto.h"
25
26 /**
27 * Serch for doors or walls around a spot.
28 * @param layout
29 * maze.
30 * @param i
31 * @param j
32 * coordinates to check.
33 * @param Xsize
34 * @param Ysize
35 * maze size.
36 * @return
37 * Combination of flags:
38 * - 1 = door or wall to left.
39 * - 2 = door or wall to right.
40 * - 4 = door or wall above.
41 * - 8 = door or wall below.
42 */
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
62 /**
63 * Add doors to a map.
64 * @param the_map
65 * map we're adding doors to.
66 * @param maze
67 * maze layout.
68 * @param doorstyle
69 * door style to be. If "none", won't do anything. If NULL, will choose one randomly.
70 * @param RP
71 * random map parameters.
72 */
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 }