Crossfire Server, Trunk
decor.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 <assert.h>
20 #include <stdlib.h>
21 
22 #include "global.h"
23 #include "random_map.h"
24 #include "rproto.h"
25 
27 #define NR_DECOR_OPTIONS 1
28 
39 int obj_count_in_map(mapstruct *map, int x, int y)
40 {
41  int count = 0;
42 
44  count++;
46  return count;
47 }
48 
65 void put_decor(mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms *RP)
66 {
67  mapstruct *decor_map;
68 
69  decor_map = find_style("/styles/decorstyles", decorstyle, -1);
70  if (decor_map == NULL) {
71  return;
72  }
73 
74  /* pick a random option, only 1 option right now. */
75  if (decor_option == 0) {
76  decor_option = RANDOM()%NR_DECOR_OPTIONS+1;
77  }
78 
79  assert(decor_option != 0);
80 
81  switch (decor_option) {
82  case 1: { /* random placement of decor objects. */
83  int number_to_place = RANDOM()%((RP->Xsize*RP->Ysize)/5);
84  int failures = 0;
85  object *new_decor_object;
86 
87  while (failures < 100 && number_to_place > 0) {
88  int x, y;
89 
90  x = RANDOM()%(RP->Xsize-2)+1;
91  y = RANDOM()%(RP->Ysize-2)+1;
92  if (maze[x][y] == 0 && obj_count_in_map(map, x, y) < 2) { /* empty */
93  object *this_object;
94 
95  new_decor_object = pick_random_object(decor_map);
96  this_object = arch_to_object(new_decor_object->arch);
97  object_copy(new_decor_object, this_object);
98  /*
99  * Don't change move_block, this prevents item merging.
100  * Instead, fix the item on the style map if blocking
101  * is bad.
102  */
103  /*this_object->move_block = MOVE_BLOCK_DEFAULT;*/
104  object_insert_in_map_at(this_object, map, NULL, 0, x, y);
105  number_to_place--;
106  } else {
107  failures++;
108  }
109  }
110  break;
111  }
112 
113  default: { /* place decor objects everywhere: tile the map. */
114  int i, j;
115 
116  for (i = 1; i < RP->Xsize-1; i++)
117  for (j = 1; j < RP->Ysize-1; j++) {
118  if (maze[i][j] == 0) {
119  object *new_decor_object, *this_object;
120 
121  new_decor_object = pick_random_object(decor_map);
122  this_object = arch_to_object(new_decor_object->arch);
123  object_copy(new_decor_object, this_object);
124  /*
125  * Don't change move_block, this prevents item merging.
126  * Instead, fix the item on the style map if blocking
127  * is bad.
128  */
129  /*this_object->move_block = MOVE_BLOCK_DEFAULT;*/
130  object_insert_in_map_at(this_object, map, NULL, 0, i, j);
131  }
132  }
133  break;
134  }
135  }
136 }
global.h
random_map.h
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
diamondslots.x
x
Definition: diamondslots.py:15
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
Ice.tmp
int tmp
Definition: Ice.py:207
find_style
mapstruct * find_style(const char *dirname, const char *stylename, int difficulty)
Definition: style.cpp:180
RMParms
Definition: random_map.h:14
disinfect.map
map
Definition: disinfect.py:4
put_decor
void put_decor(mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms *RP)
Definition: decor.cpp:65
obj_count_in_map
int obj_count_in_map(mapstruct *map, int x, int y)
Definition: decor.cpp:39
disinfect.count
int count
Definition: disinfect.py:7
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
RANDOM
#define RANDOM()
Definition: define.h:644
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:723
mapstruct
Definition: map.h:313
pick_random_object
object * pick_random_object(mapstruct *style)
Definition: style.cpp:289
diamondslots.y
y
Definition: diamondslots.py:16
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:229
NR_DECOR_OPTIONS
#define NR_DECOR_OPTIONS
Definition: decor.cpp:27
RMParms::Xsize
int Xsize
Definition: random_map.h:74