ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/decor.C
Revision: 1.10
Committed: Sat Jan 6 14:42:30 2007 UTC (17 years, 5 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.9: +1 -0 lines
Log Message:
added some copyrights

File Contents

# Content
1
2 /*
3 CrossFire, A Multiplayer game for X-windows
4
5 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
6 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
7 Copyright (C) 1992 Frank Tore Johansen
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 The authors can be reached via e-mail at <crossfire@schmorp.de>
24 */
25
26
27 #include <global.h>
28 #include <random_map.h>
29 #include <rproto.h>
30
31 #define NR_DECOR_OPTIONS 1
32
33 /* return a simple count of objects in the map at x,y. */
34
35 int
36 obj_count_in_map (maptile *map, int x, int y)
37 {
38 int count = 0;
39 object *tmp;
40
41 for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above)
42 count++;
43 return count;
44 }
45
46 /* put the decor into the map. Right now, it's very primitive. */
47
48 void
49 put_decor (maptile *map, char **maze, char *decorstyle, int decor_option, random_map_params *RP)
50 {
51 maptile *decor_map;
52 char style_name[1024];
53
54 sprintf (style_name, "/styles/decorstyles");
55
56 decor_map = find_style (style_name, decorstyle, -1);
57 if (decor_map == NULL)
58 return;
59 /* pick a random option, only 1 option right now. */
60 if (decor_option == 0)
61 decor_option = RANDOM () % NR_DECOR_OPTIONS + 1;
62 switch (decor_option)
63 {
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 }
95 break;
96 }
97 default:
98 { /* place decor objects everywhere: tile the map. */
99 int i, j;
100
101 for (i = 1; i < RP->Xsize - 1; i++)
102 for (j = 1; j < RP->Ysize - 1; j++)
103 {
104 if (maze[i][j] == 0)
105 {
106 object *new_decor_object, *this_object;
107
108 new_decor_object = pick_random_object (decor_map);
109 this_object = arch_to_object (new_decor_object->arch);
110 new_decor_object->copy_to (this_object);
111 this_object->x = i;
112 this_object->y = j;
113 /* it screws things up if decor can stop people */
114 this_object->move_block = MOVE_BLOCK_DEFAULT;
115 insert_ob_in_map (this_object, map, NULL, 0);
116 }
117 }
118 break;
119 }
120 }
121 }