1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
4 | |
3 | * |
5 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
6 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
7 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
8 | |
7 | * |
9 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
10 | it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
11 | the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
12 | (at your option) any later version. |
11 | * option) any later version. |
13 | |
12 | * |
14 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
18 | |
17 | * |
19 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
20 | along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
22 | |
21 | * |
23 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
24 | */ |
23 | */ |
25 | |
|
|
26 | |
24 | |
27 | #include <global.h> |
25 | #include <global.h> |
28 | #include <random_map.h> |
26 | #include <random_map.h> |
29 | #include <rproto.h> |
27 | #include <rproto.h> |
30 | |
28 | |
31 | #define NR_DECOR_OPTIONS 1 |
29 | #define NR_DECOR_OPTIONS 1 |
32 | |
30 | |
33 | /* return a simple count of objects in the map at x,y. */ |
31 | /* return a simple count of objects in the map at x,y. */ |
34 | |
32 | |
35 | int |
33 | static int |
36 | obj_count_in_map (maptile *map, int x, int y) |
34 | obj_count_in_map (maptile *map, int x, int y) |
37 | { |
35 | { |
38 | int count = 0; |
36 | int count = 0; |
39 | object *tmp; |
37 | object *tmp; |
40 | |
38 | |
41 | for (tmp = GET_MAP_OB (map, x, y); tmp != NULL; tmp = tmp->above) |
39 | for (tmp = map->at (x, y).bot; tmp; tmp = tmp->above) |
42 | count++; |
40 | ++count; |
|
|
41 | |
43 | return count; |
42 | return count; |
44 | } |
43 | } |
45 | |
44 | |
46 | /* 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. */ |
47 | |
46 | |
… | |
… | |
52 | char style_name[1024]; |
51 | char style_name[1024]; |
53 | |
52 | |
54 | sprintf (style_name, "/styles/decorstyles"); |
53 | sprintf (style_name, "/styles/decorstyles"); |
55 | |
54 | |
56 | decor_map = find_style (style_name, decorstyle, -1); |
55 | decor_map = find_style (style_name, decorstyle, -1); |
57 | if (decor_map == NULL) |
56 | if (!decor_map) |
58 | return; |
57 | return; |
|
|
58 | |
59 | /* pick a random option, only 1 option right now. */ |
59 | /* pick a random option, only 1 option right now. */ |
60 | if (decor_option == 0) |
60 | if (decor_option == 0) |
61 | decor_option = RANDOM () % NR_DECOR_OPTIONS + 1; |
61 | decor_option = rmg_rndm (NR_DECOR_OPTIONS) + 1; |
|
|
62 | |
62 | switch (decor_option) |
63 | switch (decor_option) |
63 | { |
64 | { |
64 | case 0: |
65 | case 0: |
65 | break; |
66 | break; |
|
|
67 | |
66 | case 1: |
68 | case 1: |
67 | { /* random placement of decor objects. */ |
69 | { /* random placement of decor objects. */ |
68 | int number_to_place = RANDOM () % ((RP->Xsize * RP->Ysize) / 5); |
70 | int number_to_place = rmg_rndm (RP->Xsize * RP->Ysize / 5); |
69 | int failures = 0; |
71 | int failures = 0; |
70 | object *new_decor_object; |
|
|
71 | |
72 | |
72 | while (failures < 100 && number_to_place > 0) |
73 | while (failures < 100 && number_to_place > 0) |
73 | { |
74 | { |
74 | int x, y; |
75 | coroapi::cede_to_tick (); |
75 | |
76 | |
76 | x = RANDOM () % (RP->Xsize - 2) + 1; |
77 | int x = rmg_rndm (RP->Xsize - 2) + 1; |
77 | y = RANDOM () % (RP->Ysize - 2) + 1; |
78 | int y = rmg_rndm (RP->Ysize - 2) + 1; |
|
|
79 | |
78 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
80 | if (maze[x][y] == 0 && obj_count_in_map (map, x, y) < 2) |
79 | { /* empty */ |
81 | { |
80 | object *this_object; |
82 | object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
|
|
83 | /* it screws things up if decor can stop people */ |
|
|
84 | this_object->move_block = 0; |
|
|
85 | map->insert (this_object, x, y, 0, 0); |
81 | |
86 | |
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--; |
87 | number_to_place--; |
91 | } |
88 | } |
92 | else |
89 | else |
93 | failures++; |
90 | failures++; |
94 | } |
91 | } |
95 | break; |
92 | break; |
96 | } |
93 | } |
|
|
94 | |
97 | default: |
95 | default: |
98 | { /* place decor objects everywhere: tile the map. */ |
96 | { /* place decor objects everywhere: tile the map. */ |
99 | int i, j; |
97 | int i, j; |
100 | |
98 | |
101 | for (i = 1; i < RP->Xsize - 1; i++) |
99 | for (i = 1; i < RP->Xsize - 1; i++) |
102 | for (j = 1; j < RP->Ysize - 1; j++) |
100 | for (j = 1; j < RP->Ysize - 1; j++) |
103 | { |
101 | { |
104 | if (maze[i][j] == 0) |
102 | if (maze[i][j] == 0) |
105 | { |
103 | { |
106 | object *new_decor_object, *this_object; |
104 | object *this_object = decor_map->pick_random_object (rmg_rndm)->clone (); |
107 | |
105 | |
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; |
106 | this_object->x = i; |
112 | this_object->y = j; |
107 | this_object->y = j; |
113 | /* it screws things up if decor can stop people */ |
108 | /* it screws things up if decor can stop people */ |
114 | this_object->move_block = MOVE_BLOCK_DEFAULT; |
109 | this_object->move_block = 0; |
|
|
110 | |
115 | insert_ob_in_map (this_object, map, NULL, 0); |
111 | insert_ob_in_map (this_object, map, NULL, 0); |
116 | } |
112 | } |
117 | } |
113 | } |
118 | break; |
114 | break; |
119 | } |
115 | } |
120 | } |
116 | } |
121 | } |
117 | } |
|
|
118 | |