Atrinik Server  4.0
door.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
30 #include <global.h>
31 #include <arch.h>
32 
52 int surround_check2(char **layout, int x, int y, int Xsize, int Ysize)
53 {
54  /* 1 = door or wall to left,
55  * 2 = door or wall to right,
56  * 4 = door or wall above
57  * 8 = door or wall below */
58  int surround_index = 0;
59 
60  if ((x > 0) && (layout[x - 1][y] == 'D' || layout[x - 1][y] == '#')) {
61  surround_index += 1;
62  }
63 
64  if ((x < Xsize - 1) && (layout[x + 1][y] == 'D' || layout[x + 1][y] == '#')) {
65  surround_index += 2;
66  }
67 
68  if ((y > 0) && (layout[x][y - 1] == 'D' || layout[x][y - 1] == '#')) {
69  surround_index += 4;
70  }
71 
72  if ((y < Ysize - 1) && (layout[x][y + 1] == 'D' || layout[x][y + 1] == '#')) {
73  surround_index += 8;
74  }
75 
76  return surround_index;
77 }
78 
90 void put_doors(mapstruct *the_map, char **maze, char *doorstyle, RMParms *RP)
91 {
92  int x, y;
93  mapstruct *vdoors, *hdoors;
94  char doorpath[128];
95 
96  if (!strcmp(doorstyle, "none")) {
97  return;
98  }
99 
100  vdoors = find_style("/styles/doorstyles/vdoors", doorstyle, -1);
101 
102  if (!vdoors) {
103  return;
104  }
105 
106  snprintf(doorpath, sizeof(doorpath), "/styles/doorstyles/hdoors%s", strrchr(vdoors->path, '/'));
107  hdoors = find_style(doorpath, 0, -1);
108 
109  for (x = 0; x < RP->Xsize; x++) {
110  for (y = 0; y < RP->Ysize; y++) {
111  if (maze[x][y] == 'D') {
112  int sindex = surround_check2(maze, x, y, RP->Xsize, RP->Ysize);
113  object *this_door, *new_door;
114 
115  if (sindex == 3) {
116  this_door = pick_random_object(hdoors);
117  } else {
118  this_door = pick_random_object(vdoors);
119  }
120 
121  new_door = arch_to_object(this_door->arch);
122  object_copy(new_door, this_door, false);
123  new_door->x = x;
124  new_door->y = y;
125 
126  object_insert_map(new_door, the_map, NULL, INS_NO_MERGE | INS_NO_WALK_ON);
127  }
128  }
129  }
130 }
shstr * path
Definition: map.h:568
void object_copy(object *op, const object *src, bool no_speed)
Definition: object.c:886
struct archetype * arch
Definition: object.h:225
int16_t y
Definition: object.h:276
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.c:169
int surround_check2(char **layout, int x, int y, int Xsize, int Ysize)
Definition: door.c:52
object * arch_to_object(archetype_t *at)
Definition: arch.c:446
#define INS_NO_WALK_ON
Definition: object.h:570
object * pick_random_object(mapstruct *style)
Definition: style.c:286
int16_t x
Definition: object.h:273
int Ysize
Definition: random_map.h:77
object * object_insert_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1741
int Xsize
Definition: random_map.h:74
void put_doors(mapstruct *the_map, char **maze, char *doorstyle, RMParms *RP)
Definition: door.c:90
#define INS_NO_MERGE
Definition: object.h:564
Definition: map.h:536