Atrinik Server  4.0
decor.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 <object.h>
32 
42 void put_decor(mapstruct *map, char **layout, RMParms *RP)
43 {
44  mapstruct *decor_map;
45  char style_name[256];
46  int i, j;
47  object *new_decor_object;
48 
49  if (RP->decorstyle[0] == '\0' || !strcmp(RP->decorstyle, "none")) {
50  return;
51  }
52 
53  snprintf(style_name, sizeof(style_name), "/styles/decorstyles");
54  decor_map = find_style(style_name, RP->decorstyle, -1);
55 
56  if (decor_map == NULL) {
57  return;
58  }
59 
60  for (i = 0; i < RP->Xsize - 1; i++) {
61  for (j = 0; j < RP->Ysize - 1; j++) {
62  if (RP->decorchance > 0 && !rndm_chance(RP->decorchance)) {
63  continue;
64  }
65 
66  new_decor_object = pick_random_object(decor_map);
67 
68  if (layout[i][j] == (new_decor_object->type == WALL && QUERY_FLAG(new_decor_object, FLAG_IS_TURNABLE) ? '#' : '\0')) {
69  object *this_object = object_get();
70 
71  object_copy(this_object, new_decor_object, false);
72  this_object->x = i;
73  this_object->y = j;
74 
75  if (new_decor_object->type == WALL && QUERY_FLAG(new_decor_object, FLAG_IS_TURNABLE) && surround_flag2(layout, i, j, RP) & (4 | 8)) {
76  this_object->direction = 7;
77  SET_ANIMATION(this_object, (NUM_ANIMATIONS(this_object) / NUM_FACINGS(this_object)) * this_object->direction);
78  }
79 
80  object_insert_map(this_object, map, NULL, INS_NO_MERGE | INS_NO_WALK_ON);
81  }
82  }
83  }
84 }
#define NUM_FACINGS(ob)
Definition: global.h:300
object * object_get(void)
Definition: object.c:993
#define SET_ANIMATION(ob, newanim)
Definition: global.h:282
void object_copy(object *op, const object *src, bool no_speed)
Definition: object.c:886
#define FLAG_IS_TURNABLE
Definition: define.h:960
#define QUERY_FLAG(xyz, p)
Definition: define.h:761
#define WALL
Definition: define.h:340
int16_t y
Definition: object.h:276
int8_t direction
Definition: object.h:350
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.c:169
int surround_flag2(char **layout, int i, int j, RMParms *RP)
Definition: wall.c:80
#define INS_NO_WALK_ON
Definition: object.h:570
int decorchance
Definition: random_map.h:107
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
#define INS_NO_MERGE
Definition: object.h:564
#define NUM_ANIMATIONS(ob)
Definition: global.h:298
uint8_t type
Definition: object.h:360
void put_decor(mapstruct *map, char **layout, RMParms *RP)
Definition: decor.c:42
Definition: map.h:536
char decorstyle[RM_SIZE]
Definition: random_map.h:56