ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/server/random_maps/decor.C
(Generate patch)

Comparing cf.schmorp.de/server/random_maps/decor.C (file contents):
Revision 1.2 by root, Sun Sep 10 16:06:37 2006 UTC vs.
Revision 1.9 by root, Sun Dec 31 20:46:17 2006 UTC

1
2/*
3 * static char *rcsid_decor_ =
4 * "$Id: decor.C,v 1.2 2006/09/10 16:06:37 root Exp $";
5 */
6 1
7/* 2/*
8 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
9 4
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
22 17
23 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 21
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 22 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 23*/
29 24
30 25
31#include <global.h> 26#include <global.h>
32#include <random_map.h> 27#include <random_map.h>
35#define NR_DECOR_OPTIONS 1 30#define NR_DECOR_OPTIONS 1
36 31
37/* return a simple count of objects in the map at x,y. */ 32/* return a simple count of objects in the map at x,y. */
38 33
39int 34int
40obj_count_in_map (mapstruct *map, int x, int y) 35obj_count_in_map (maptile *map, int x, int y)
41{ 36{
42 int count = 0; 37 int count = 0;
43 object *tmp; 38 object *tmp;
44 39
45 for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) 40 for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above)
46 count++; 41 count++;
47 return count; 42 return count;
48} 43}
49 44
50/* put the decor into the map. Right now, it's very primitive. */ 45/* put the decor into the map. Right now, it's very primitive. */
51 46
52void 47void
53put_decor (mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms * RP) 48put_decor (maptile *map, char **maze, char *decorstyle, int decor_option, random_map_params *RP)
54{ 49{
55 mapstruct *decor_map; 50 maptile *decor_map;
56 char style_name[256]; 51 char style_name[1024];
57 52
58 sprintf (style_name, "/styles/decorstyles"); 53 sprintf (style_name, "/styles/decorstyles");
59 54
60 decor_map = find_style (style_name, decorstyle, -1); 55 decor_map = find_style (style_name, decorstyle, -1);
61 if (decor_map == NULL) 56 if (decor_map == NULL)
63 /* pick a random option, only 1 option right now. */ 58 /* pick a random option, only 1 option right now. */
64 if (decor_option == 0) 59 if (decor_option == 0)
65 decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; 60 decor_option = RANDOM () % NR_DECOR_OPTIONS + 1;
66 switch (decor_option) 61 switch (decor_option)
67 { 62 {
68 case 0: 63 case 0:
64 break;
65 case 1:
66 { /* random placement of decor objects. */
67 int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5);
68 int failures = 0;
69 object *new_decor_object;
70
71 while (failures < 100 && number_to_place > 0)
72 {
73 int x, y;
74
75 x = RANDOM () % (RP->Xsize - 2) + 1;
76 y = RANDOM () % (RP->Ysize - 2) + 1;
77 if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2)
78 { /* empty */
79 object *this_object;
80
81 new_decor_object = pick_random_object (decor_map);
82 this_object = arch_to_object (new_decor_object->arch);
83 new_decor_object->copy_to (this_object);
84 this_object->x = x;
85 this_object->y = y;
86 /* it screws things up if decor can stop people */
87 this_object->move_block = MOVE_BLOCK_DEFAULT;
88 insert_ob_in_map (this_object, map, NULL, 0);
89 number_to_place--;
90 }
91 else
92 failures++;
93 }
69 break; 94 break;
70 case 1: 95 }
71 { /* random placement of decor objects. */ 96 default:
72 int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); 97 { /* place decor objects everywhere: tile the map. */
73 int failures = 0; 98 int i, j;
74 object *new_decor_object;
75 99
76 while (failures < 100 && number_to_place > 0) 100 for (i = 1; i < RP->Xsize - 1; i++)
101 for (j = 1; j < RP->Ysize - 1; j++)
77 { 102 {
78 int x, y; 103 if (maze[i][j] == 0)
79 104 {
80 x = RANDOM () % (RP->Xsize - 2) + 1;
81 y = RANDOM () % (RP->Ysize - 2) + 1;
82 if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2)
83 { /* empty */
84 object *this_object; 105 object *new_decor_object, *this_object;
85 106
86 new_decor_object = pick_random_object (decor_map); 107 new_decor_object = pick_random_object (decor_map);
87 this_object = arch_to_object (new_decor_object->arch); 108 this_object = arch_to_object (new_decor_object->arch);
88 copy_object (new_decor_object, this_object); 109 new_decor_object->copy_to (this_object);
89 this_object->x = x; 110 this_object->x = i;
90 this_object->y = y; 111 this_object->y = j;
91 /* it screws things up if decor can stop people */ 112 /* it screws things up if decor can stop people */
92 this_object->move_block = MOVE_BLOCK_DEFAULT; 113 this_object->move_block = MOVE_BLOCK_DEFAULT;
93 insert_ob_in_map (this_object, map, NULL, 0); 114 insert_ob_in_map (this_object, map, NULL, 0);
94 number_to_place--;
95 } 115 }
96 else
97 failures++;
98 } 116 }
99 break; 117 break;
100 } 118 }
101 default:
102 { /* place decor objects everywhere: tile the map. */
103 int i, j;
104
105 for (i = 1; i < RP->Xsize - 1; i++)
106 for (j = 1; j < RP->Ysize - 1; j++)
107 {
108 if (maze[i][j] == 0)
109 {
110 object *new_decor_object, *this_object;
111
112 new_decor_object = pick_random_object (decor_map);
113 this_object = arch_to_object (new_decor_object->arch);
114 copy_object (new_decor_object, this_object);
115 this_object->x = i;
116 this_object->y = j;
117 /* it screws things up if decor can stop people */
118 this_object->move_block = MOVE_BLOCK_DEFAULT;
119 insert_ob_in_map (this_object, map, NULL, 0);
120 }
121 }
122 break;
123 }
124 } 119 }
125} 120}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines