Crossfire Server, Branches 1.12  R18729
decor.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_decor_ =
3  * "$Id: decor.c 11578 2009-02-23 22:02:27Z lalo $";
4  */
5 
6 /*
7  CrossFire, A Multiplayer game for X-windows
8 
9  Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10  Copyright (C) 1992 Frank Tore Johansen
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 
26  The authors can be reached via e-mail at crossfire-devel@real-time.com
27 */
28 
34 #include <global.h>
35 #include <random_map.h>
36 #include <rproto.h>
37 
39 #define NR_DECOR_OPTIONS 1
40 
51 int obj_count_in_map(mapstruct *map, int x, int y) {
52  int count = 0;
53  object *tmp;
54 
55  for (tmp = GET_MAP_OB(map, x, y); tmp != NULL; tmp = tmp->above)
56  count++;
57  return count;
58 }
59 
76 void put_decor(mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms *RP) {
77  mapstruct *decor_map;
78  char style_name[256];
79 
80  snprintf(style_name, sizeof(style_name), "/styles/decorstyles");
81 
82  decor_map = find_style(style_name, decorstyle, -1);
83  if (decor_map == NULL)
84  return;
85 
86  /* pick a random option, only 1 option right now. */
87  if (decor_option == 0)
88  decor_option = RANDOM()%NR_DECOR_OPTIONS+1;
89 
90  switch (decor_option) {
91  case 0:
92  break;
93 
94  case 1: { /* random placement of decor objects. */
95  int number_to_place = RANDOM()%((RP->Xsize*RP->Ysize)/5);
96  int failures = 0;
97  object *new_decor_object;
98 
99  while (failures < 100 && number_to_place > 0) {
100  int x, y;
101 
102  x = RANDOM()%(RP->Xsize-2)+1;
103  y = RANDOM()%(RP->Ysize-2)+1;
104  if (maze[x][y] == 0 && obj_count_in_map(map, x, y) < 2) { /* empty */
105  object *this_object;
106 
107  new_decor_object = pick_random_object(decor_map);
108  this_object = arch_to_object(new_decor_object->arch);
109  copy_object(new_decor_object, this_object);
110  this_object->x = x;
111  this_object->y = y;
112  /* it screws things up if decor can stop people */
113  this_object->move_block = MOVE_BLOCK_DEFAULT;
114  insert_ob_in_map(this_object, map, NULL, 0);
115  number_to_place--;
116  } else
117  failures++;
118  }
119  break;
120  }
121 
122  default: { /* place decor objects everywhere: tile the map. */
123  int i, j;
124 
125  for (i = 1; i < RP->Xsize-1; i++)
126  for (j = 1; j < RP->Ysize-1; j++) {
127  if (maze[i][j] == 0) {
128  object *new_decor_object, *this_object;
129 
130  new_decor_object = pick_random_object(decor_map);
131  this_object = arch_to_object(new_decor_object->arch);
132  copy_object(new_decor_object, this_object);
133  this_object->x = i;
134  this_object->y = j;
135  /* it screws things up if decor can stop people */
136  this_object->move_block = MOVE_BLOCK_DEFAULT;
137  insert_ob_in_map(this_object, map, NULL, 0);
138  }
139  }
140  break;
141  }
142  }
143 }
#define NR_DECOR_OPTIONS
Definition: decor.c:39
struct obj * above
Definition: object.h:146
sint16 x
Definition: object.h:179
object * pick_random_object(mapstruct *style)
Definition: style.c:275
void put_decor(mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms *RP)
Definition: decor.c:76
sint16 y
Definition: object.h:179
int obj_count_in_map(mapstruct *map, int x, int y)
Definition: decor.c:51
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1992
int Ysize
Definition: random_map.h:60
#define MOVE_BLOCK_DEFAULT
Definition: define.h:717
int Xsize
Definition: random_map.h:59
int snprintf(char *dest, int max, const char *format,...)
Definition: porting.c:498
struct archt * arch
Definition: object.h:263
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
MoveType move_block
Definition: object.h:278
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.c:177
void copy_object(object *op2, object *op)
Definition: object.c:758
Definition: map.h:346
object * arch_to_object(archetype *at)
Definition: arch.c:576