1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * 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 |
9 | * 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 |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * 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, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * 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 |
19 | * 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 |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * 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> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <random_map.h> |
26 | #include <random_map.h> |
27 | #include <rproto.h> |
27 | #include <rproto.h> |
28 | |
28 | |
29 | /* Put in the walls and autojoin them. */ |
29 | /* Put in the walls and autojoin them. */ |
30 | |
30 | |
31 | |
|
|
32 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
31 | /* given a layout and a coordinate, tell me which squares up/down/right/left |
33 | are occupied. */ |
32 | are occupied. */ |
34 | |
|
|
35 | int |
33 | int |
36 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
34 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
37 | { |
35 | { |
38 | /* 1 = wall to left, |
36 | /* 1 = wall to left, |
39 | 2 = wall to right, |
37 | 2 = wall to right, |
… | |
… | |
93 | */ |
91 | */ |
94 | |
92 | |
95 | int surround_index = 0; |
93 | int surround_index = 0; |
96 | |
94 | |
97 | // don't forget to update the mapspace! |
95 | // don't forget to update the mapspace! |
98 | map->at (i - 1, j).update (); |
96 | if (i > 0) map->at (i - 1, j ).update (); |
99 | map->at (i + 1, j).update (); |
97 | if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); |
100 | map->at (i , j - 1).update (); |
98 | if (j > 0) map->at (i , j - 1).update (); |
101 | map->at (i , j + 1).update (); |
99 | if (j < RP->Ysize - 1) map->at (i , j + 1).update (); |
102 | |
100 | |
103 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) |
101 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) |
104 | surround_index |= 1; |
102 | surround_index |= 1; |
105 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) |
103 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) |
106 | surround_index |= 2; |
104 | surround_index |= 2; |
… | |
… | |
154 | style_map = find_style (styledirname, w_style, -1); |
152 | style_map = find_style (styledirname, w_style, -1); |
155 | if (!style_map) |
153 | if (!style_map) |
156 | return; |
154 | return; |
157 | |
155 | |
158 | /* fill up the map with the given floor style */ |
156 | /* fill up the map with the given floor style */ |
159 | if ((the_wall = style_map->pick_random_object ())) |
157 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
160 | { |
158 | { |
161 | int i, j; |
159 | int i, j; |
162 | char *cp; |
160 | char *cp; |
163 | int joinedwalls = 0; |
161 | int joinedwalls = 0; |
164 | object *thiswall; |
162 | object *thiswall; |
165 | |
163 | |
166 | sprintf (RP->wall_name, "%s", &the_wall->arch->name); |
164 | sprintf (RP->wall_name, "%s", &the_wall->arch->archname); |
167 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
165 | if ((cp = strchr (RP->wall_name, '_')) != NULL) |
168 | { |
166 | { |
169 | *cp = 0; |
167 | *cp = 0; |
170 | joinedwalls = 1; |
168 | joinedwalls = 1; |
171 | } |
169 | } |
… | |
… | |
202 | int surround_index = 0; |
200 | int surround_index = 0; |
203 | int l; |
201 | int l; |
204 | char wall_name[1024]; |
202 | char wall_name[1024]; |
205 | archetype *wall_arch = 0; |
203 | archetype *wall_arch = 0; |
206 | |
204 | |
207 | assign (wall_name, the_wall->arch->name); |
205 | assign (wall_name, the_wall->arch->archname); |
208 | |
206 | |
209 | /* conventionally, walls are named like this: |
207 | /* conventionally, walls are named like this: |
210 | wallname_wallcode, where wallcode indicates |
208 | wallname_wallcode, where wallcode indicates |
211 | a joinedness, and wallname is the wall. |
209 | a joinedness, and wallname is the wall. |
212 | this code depends on the convention for |
210 | this code depends on the convention for |
… | |
… | |
397 | new_wall = arch_to_object (wall_arch); |
395 | new_wall = arch_to_object (wall_arch); |
398 | new_wall->x = i; |
396 | new_wall->x = i; |
399 | new_wall->y = j; |
397 | new_wall->y = j; |
400 | |
398 | |
401 | if (the_wall && the_wall->map) |
399 | if (the_wall && the_wall->map) |
402 | { |
|
|
403 | the_wall->remove (); |
|
|
404 | the_wall->destroy (); |
400 | the_wall->destroy (); |
405 | } |
|
|
406 | |
401 | |
407 | the_wall->move_block = MOVE_ALL; |
402 | the_wall->move_block = MOVE_ALL; |
408 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
403 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
409 | } |
404 | } |
410 | |
405 | |