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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines