1 |
root |
1.2 |
|
2 |
elmex |
1.1 |
/* |
3 |
|
|
* static char *rcsid_decor_ = |
4 |
root |
1.2 |
* "$Id: decor.C,v 1.1 2006-08-13 17:16:03 elmex Exp $"; |
5 |
elmex |
1.1 |
*/ |
6 |
|
|
|
7 |
|
|
/* |
8 |
|
|
CrossFire, A Multiplayer game for X-windows |
9 |
|
|
|
10 |
|
|
Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 |
|
|
Copyright (C) 1992 Frank Tore Johansen |
12 |
|
|
|
13 |
|
|
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 |
15 |
|
|
the Free Software Foundation; either version 2 of the License, or |
16 |
|
|
(at your option) any later version. |
17 |
|
|
|
18 |
|
|
This program is distributed in the hope that it will be useful, |
19 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 |
|
|
GNU General Public License for more details. |
22 |
|
|
|
23 |
|
|
You should have received a copy of the GNU General Public License |
24 |
|
|
along with this program; if not, write to the Free Software |
25 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 |
|
|
|
27 |
|
|
The authors can be reached via e-mail at crossfire-devel@real-time.com |
28 |
|
|
*/ |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
#include <global.h> |
32 |
|
|
#include <random_map.h> |
33 |
|
|
#include <rproto.h> |
34 |
|
|
|
35 |
|
|
#define NR_DECOR_OPTIONS 1 |
36 |
|
|
|
37 |
|
|
/* return a simple count of objects in the map at x,y. */ |
38 |
|
|
|
39 |
root |
1.2 |
int |
40 |
|
|
obj_count_in_map (mapstruct *map, int x, int y) |
41 |
|
|
{ |
42 |
|
|
int count = 0; |
43 |
elmex |
1.1 |
object *tmp; |
44 |
root |
1.2 |
|
45 |
|
|
for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) |
46 |
|
|
count++; |
47 |
elmex |
1.1 |
return count; |
48 |
|
|
} |
49 |
root |
1.2 |
|
50 |
elmex |
1.1 |
/* put the decor into the map. Right now, it's very primitive. */ |
51 |
|
|
|
52 |
root |
1.2 |
void |
53 |
|
|
put_decor (mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms * RP) |
54 |
|
|
{ |
55 |
elmex |
1.1 |
mapstruct *decor_map; |
56 |
|
|
char style_name[256]; |
57 |
|
|
|
58 |
root |
1.2 |
sprintf (style_name, "/styles/decorstyles"); |
59 |
elmex |
1.1 |
|
60 |
root |
1.2 |
decor_map = find_style (style_name, decorstyle, -1); |
61 |
|
|
if (decor_map == NULL) |
62 |
|
|
return; |
63 |
elmex |
1.1 |
/* pick a random option, only 1 option right now. */ |
64 |
root |
1.2 |
if (decor_option == 0) |
65 |
|
|
decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; |
66 |
|
|
switch (decor_option) |
67 |
|
|
{ |
68 |
|
|
case 0: |
69 |
|
|
break; |
70 |
|
|
case 1: |
71 |
|
|
{ /* random placement of decor objects. */ |
72 |
|
|
int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); |
73 |
|
|
int failures = 0; |
74 |
|
|
object *new_decor_object; |
75 |
|
|
|
76 |
|
|
while (failures < 100 && number_to_place > 0) |
77 |
|
|
{ |
78 |
|
|
int x, y; |
79 |
|
|
|
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; |
85 |
|
|
|
86 |
|
|
new_decor_object = pick_random_object (decor_map); |
87 |
|
|
this_object = arch_to_object (new_decor_object->arch); |
88 |
|
|
copy_object (new_decor_object, this_object); |
89 |
|
|
this_object->x = x; |
90 |
|
|
this_object->y = y; |
91 |
|
|
/* it screws things up if decor can stop people */ |
92 |
|
|
this_object->move_block = MOVE_BLOCK_DEFAULT; |
93 |
|
|
insert_ob_in_map (this_object, map, NULL, 0); |
94 |
|
|
number_to_place--; |
95 |
|
|
} |
96 |
|
|
else |
97 |
|
|
failures++; |
98 |
|
|
} |
99 |
|
|
break; |
100 |
|
|
} |
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 |
elmex |
1.1 |
} |
125 |
|
|
} |