1 | |
|
|
2 | /* |
1 | /* |
3 | * static char *rcsid_decor_ = |
2 | * CrossFire, A Multiplayer game for X-windows |
4 | * "$Id: decor.C,v 1.2 2006/09/10 16:06:37 root Exp $"; |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
|
|
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (C) 1992 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * This program is free software; you can redistribute it and/or modify |
|
|
9 | * it under the terms of the GNU General Public License as published by |
|
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
|
11 | * (at your option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License |
|
|
19 | * along with this program; if not, write to the Free Software |
|
|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
5 | */ |
23 | */ |
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 | |
24 | |
30 | |
25 | |
31 | #include <global.h> |
26 | #include <global.h> |
32 | #include <random_map.h> |
27 | #include <random_map.h> |
33 | #include <rproto.h> |
28 | #include <rproto.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 | |
39 | int |
34 | int |
40 | obj_count_in_map (mapstruct *map, int x, int y) |
35 | obj_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 | |
52 | void |
47 | void |
53 | put_decor (mapstruct *map, char **maze, char *decorstyle, int decor_option, RMParms * RP) |
48 | put_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) |
62 | return; |
57 | return; |
|
|
58 | |
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 = rndm (NR_DECOR_OPTIONS) + 1; |
|
|
62 | |
66 | switch (decor_option) |
63 | switch (decor_option) |
67 | { |
64 | { |
68 | case 0: |
65 | case 0: |
|
|
66 | break; |
|
|
67 | case 1: |
|
|
68 | { /* random placement of decor objects. */ |
|
|
69 | int number_to_place = rndm (RP->Xsize * RP->Ysize / 5); |
|
|
70 | int failures = 0; |
|
|
71 | object *new_decor_object; |
|
|
72 | |
|
|
73 | while (failures < 100 && number_to_place > 0) |
|
|
74 | { |
|
|
75 | int x, y; |
|
|
76 | |
|
|
77 | x = rndm (RP->Xsize - 2) + 1; |
|
|
78 | y = rndm (RP->Ysize - 2) + 1; |
|
|
79 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
|
|
80 | { /* empty */ |
|
|
81 | object *this_object; |
|
|
82 | |
|
|
83 | new_decor_object = decor_map->pick_random_object (); |
|
|
84 | this_object = arch_to_object (new_decor_object->arch); |
|
|
85 | new_decor_object->copy_to (this_object); |
|
|
86 | this_object->x = x; |
|
|
87 | this_object->y = y; |
|
|
88 | /* it screws things up if decor can stop people */ |
|
|
89 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
|
|
90 | insert_ob_in_map (this_object, map, NULL, 0); |
|
|
91 | number_to_place--; |
|
|
92 | } |
|
|
93 | else |
|
|
94 | failures++; |
|
|
95 | } |
69 | break; |
96 | break; |
70 | case 1: |
97 | } |
71 | { /* random placement of decor objects. */ |
98 | default: |
72 | int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); |
99 | { /* place decor objects everywhere: tile the map. */ |
73 | int failures = 0; |
100 | int i, j; |
74 | object *new_decor_object; |
|
|
75 | |
101 | |
76 | while (failures < 100 && number_to_place > 0) |
102 | for (i = 1; i < RP->Xsize - 1; i++) |
|
|
103 | for (j = 1; j < RP->Ysize - 1; j++) |
77 | { |
104 | { |
78 | int x, y; |
105 | if (maze[i][j] == 0) |
|
|
106 | { |
|
|
107 | object *new_decor_object, *this_object; |
79 | |
108 | |
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); |
109 | new_decor_object = decor_map->pick_random_object (); |
87 | this_object = arch_to_object (new_decor_object->arch); |
110 | this_object = arch_to_object (new_decor_object->arch); |
88 | copy_object (new_decor_object, this_object); |
111 | new_decor_object->copy_to (this_object); |
89 | this_object->x = x; |
112 | this_object->x = i; |
90 | this_object->y = y; |
113 | this_object->y = j; |
91 | /* it screws things up if decor can stop people */ |
114 | /* it screws things up if decor can stop people */ |
92 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
115 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
93 | insert_ob_in_map (this_object, map, NULL, 0); |
116 | insert_ob_in_map (this_object, map, NULL, 0); |
94 | number_to_place--; |
|
|
95 | } |
117 | } |
96 | else |
|
|
97 | failures++; |
|
|
98 | } |
118 | } |
99 | break; |
119 | break; |
100 | } |
120 | } |
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 | } |
121 | } |
125 | } |
122 | } |