1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT 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 3 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, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <random_map.h> |
26 | #include <random_map.h> |
26 | #include <rproto.h> |
27 | #include <rproto.h> |
27 | |
28 | |
28 | /* Put in the walls and autojoin them. */ |
29 | /* Put in the walls and autojoin them. */ |
29 | |
30 | |
30 | |
|
|
31 | /* 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 |
32 | are occupied. */ |
32 | are occupied. */ |
33 | |
|
|
34 | int |
33 | int |
35 | 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) |
36 | { |
35 | { |
37 | /* 1 = wall to left, |
36 | /* 1 = wall to left, |
38 | 2 = wall to right, |
37 | 2 = wall to right, |
39 | 4 = wall above |
38 | 4 = wall above |
40 | 8 = wall below */ |
39 | 8 = wall below */ |
41 | int surround_index = 0; |
40 | int surround_index = 0; |
42 | |
41 | |
43 | if ((i > 0) && layout[i - 1][j] != 0) |
42 | if (i > 0 && layout[i - 1][j] != 0) surround_index |= 1; |
44 | surround_index |= 1; |
|
|
45 | if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) |
43 | if (i < RP->Xsize - 1 && layout[i + 1][j] != 0) surround_index |= 2; |
46 | surround_index |= 2; |
44 | if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4; |
47 | if ((j > 0) && layout[i][j - 1] != 0) |
|
|
48 | surround_index |= 4; |
|
|
49 | if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0) |
45 | if (j < RP->Ysize - 1 && layout[i][j + 1] != 0) surround_index |= 8; |
50 | surround_index |= 8; |
46 | |
51 | return surround_index; |
47 | return surround_index; |
52 | } |
48 | } |
53 | |
49 | |
54 | |
50 | |
55 | /* like surround_flag, but only walls count. |
51 | /* like surround_flag, but only walls count. |
… | |
… | |
62 | 2 = wall to right, |
58 | 2 = wall to right, |
63 | 4 = wall above |
59 | 4 = wall above |
64 | 8 = wall below */ |
60 | 8 = wall below */ |
65 | int surround_index = 0; |
61 | int surround_index = 0; |
66 | |
62 | |
67 | if ((i > 0) && layout[i - 1][j] == '#') |
63 | if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1; |
68 | surround_index |= 1; |
|
|
69 | if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') |
64 | if (i < RP->Xsize - 1 && layout[i + 1][j] == '#') surround_index |= 2; |
70 | surround_index |= 2; |
65 | if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4; |
71 | if ((j > 0) && layout[i][j - 1] == '#') |
|
|
72 | surround_index |= 4; |
|
|
73 | if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#') |
66 | if (j < RP->Ysize - 1 && layout[i][j + 1] == '#') surround_index |= 8; |
74 | surround_index |= 8; |
67 | |
75 | return surround_index; |
68 | return surround_index; |
76 | } |
69 | } |
77 | |
70 | |
78 | |
71 | |
79 | /* like surround_flag, except it checks a map, not a layout. |
72 | /* like surround_flag, except it checks a map, not a layout. |
… | |
… | |
97 | if (i > 0) map->at (i - 1, j ).update (); |
90 | if (i > 0) map->at (i - 1, j ).update (); |
98 | if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); |
91 | if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); |
99 | if (j > 0) map->at (i , j - 1).update (); |
92 | if (j > 0) map->at (i , j - 1).update (); |
100 | if (j < RP->Ysize - 1) map->at (i , j + 1).update (); |
93 | if (j < RP->Ysize - 1) map->at (i , j + 1).update (); |
101 | |
94 | |
102 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) |
95 | if (i > 0 && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) surround_index |= 1; |
103 | surround_index |= 1; |
|
|
104 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) |
96 | if (i < RP->Xsize - 1 && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) surround_index |= 2; |
105 | surround_index |= 2; |
|
|
106 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) |
97 | if (j > 0 && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) surround_index |= 4; |
107 | surround_index |= 4; |
|
|
108 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) |
98 | if (j < RP->Ysize - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8; |
109 | surround_index |= 8; |
|
|
110 | |
99 | |
111 | return surround_index; |
100 | return surround_index; |
112 | } |
101 | } |
113 | |
102 | |
114 | /* like surround_flag2, except it checks a map, not a layout. */ |
103 | /* like surround_flag2, except it checks a map, not a layout. */ |
115 | |
104 | static int |
116 | int |
|
|
117 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
105 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
118 | { |
106 | { |
119 | /* 1 = blocked to left, |
107 | /* 1 = blocked to left, |
120 | 2 = blocked to right, |
108 | 2 = blocked to right, |
121 | 4 = blocked above |
109 | 4 = blocked above |
122 | 8 = blocked below */ |
110 | 8 = blocked below */ |
123 | int surround_index = 0; |
111 | int surround_index = 0; |
124 | |
112 | |
125 | if ((i > 0) && wall_blocked (map, i - 1, j)) |
113 | if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1; |
126 | surround_index |= 1; |
|
|
127 | if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) |
114 | if (i < RP->Xsize - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2; |
128 | surround_index |= 2; |
115 | if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4; |
129 | if ((j > 0) && wall_blocked (map, i, j - 1)) |
|
|
130 | surround_index |= 4; |
|
|
131 | if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1)) |
116 | if (j < RP->Ysize - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8; |
132 | surround_index |= 8; |
|
|
133 | |
117 | |
134 | return surround_index; |
118 | return surround_index; |
|
|
119 | } |
|
|
120 | |
|
|
121 | /* picks the right wall type for this square, to make it look nice, |
|
|
122 | and have everything nicely joined. It uses the layout. */ |
|
|
123 | static object * |
|
|
124 | pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) |
|
|
125 | { |
|
|
126 | /* 1 = wall to left, |
|
|
127 | 2 = wall to right, |
|
|
128 | 4 = wall above |
|
|
129 | 8 = wall below */ |
|
|
130 | int surround_index = 0; |
|
|
131 | int l; |
|
|
132 | char wall_name[1024]; |
|
|
133 | archetype *wall_arch = 0; |
|
|
134 | |
|
|
135 | assign (wall_name, the_wall->arch->archname); |
|
|
136 | |
|
|
137 | /* conventionally, walls are named like this: |
|
|
138 | wallname_wallcode, where wallcode indicates |
|
|
139 | a joinedness, and wallname is the wall. |
|
|
140 | this code depends on the convention for |
|
|
141 | finding the right wall. */ |
|
|
142 | |
|
|
143 | /* extract the wall name, which is the text up to the leading _ */ |
|
|
144 | for (l = 0; l < 64; l++) |
|
|
145 | { |
|
|
146 | if (wall_name[l] == '_') |
|
|
147 | { |
|
|
148 | wall_name[l] = 0; |
|
|
149 | break; |
|
|
150 | } |
|
|
151 | } |
|
|
152 | |
|
|
153 | surround_index = surround_flag2 (layout, i, j, RP); |
|
|
154 | |
|
|
155 | switch (surround_index) |
|
|
156 | { |
|
|
157 | case 0: |
|
|
158 | strcat (wall_name, "_0"); |
|
|
159 | break; |
|
|
160 | case 1: |
|
|
161 | strcat (wall_name, "_1_3"); |
|
|
162 | break; |
|
|
163 | case 2: |
|
|
164 | strcat (wall_name, "_1_4"); |
|
|
165 | break; |
|
|
166 | case 3: |
|
|
167 | strcat (wall_name, "_2_1_2"); |
|
|
168 | break; |
|
|
169 | case 4: |
|
|
170 | strcat (wall_name, "_1_2"); |
|
|
171 | break; |
|
|
172 | case 5: |
|
|
173 | strcat (wall_name, "_2_2_4"); |
|
|
174 | break; |
|
|
175 | case 6: |
|
|
176 | strcat (wall_name, "_2_2_1"); |
|
|
177 | break; |
|
|
178 | case 7: |
|
|
179 | strcat (wall_name, "_3_1"); |
|
|
180 | break; |
|
|
181 | case 8: |
|
|
182 | strcat (wall_name, "_1_1"); |
|
|
183 | break; |
|
|
184 | case 9: |
|
|
185 | strcat (wall_name, "_2_2_3"); |
|
|
186 | break; |
|
|
187 | case 10: |
|
|
188 | strcat (wall_name, "_2_2_2"); |
|
|
189 | break; |
|
|
190 | case 11: |
|
|
191 | strcat (wall_name, "_3_3"); |
|
|
192 | break; |
|
|
193 | case 12: |
|
|
194 | strcat (wall_name, "_2_1_1"); |
|
|
195 | break; |
|
|
196 | case 13: |
|
|
197 | strcat (wall_name, "_3_4"); |
|
|
198 | break; |
|
|
199 | case 14: |
|
|
200 | strcat (wall_name, "_3_2"); |
|
|
201 | break; |
|
|
202 | case 15: |
|
|
203 | strcat (wall_name, "_4"); |
|
|
204 | break; |
|
|
205 | } |
|
|
206 | wall_arch = archetype::find (wall_name); |
|
|
207 | |
|
|
208 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
135 | } |
209 | } |
136 | |
210 | |
137 | /* takes a map and a layout, and puts walls in the map (picked from |
211 | /* takes a map and a layout, and puts walls in the map (picked from |
138 | w_style) at '#' marks. */ |
212 | w_style) at '#' marks. */ |
139 | |
|
|
140 | void |
213 | void |
141 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
214 | make_map_walls (maptile *map, char **layout, const char *w_style, const char *m_style, random_map_params *RP) |
142 | { |
215 | { |
143 | char styledirname[1024]; |
|
|
144 | char stylefilepath[1024]; |
|
|
145 | maptile *style_map = 0; |
|
|
146 | object *the_wall; |
216 | object *the_wall; |
147 | |
217 | |
148 | /* get the style map */ |
218 | /* get the style map */ |
149 | if (!strcmp (w_style, "none")) |
219 | if (!strcmp (w_style, "none")) |
150 | return; |
220 | return; |
151 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
221 | |
152 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
222 | maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty); |
153 | style_map = find_style (styledirname, w_style, -1); |
|
|
154 | if (!style_map) |
223 | if (!style_map) |
155 | return; |
224 | return; |
156 | |
225 | |
157 | /* fill up the map with the given floor style */ |
226 | maptile *mining_map = m_style && *m_style |
|
|
227 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
|
|
228 | : 0; |
|
|
229 | |
158 | if ((the_wall = style_map->pick_random_object ())) |
230 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
159 | { |
231 | { |
160 | int i, j; |
232 | int i, j; |
161 | char *cp; |
233 | char *cp; |
162 | int joinedwalls = 0; |
234 | int joinedwalls = 0; |
163 | object *thiswall; |
235 | object *thiswall; |
… | |
… | |
175 | if (layout[i][j] == '#') |
247 | if (layout[i][j] == '#') |
176 | { |
248 | { |
177 | if (joinedwalls) |
249 | if (joinedwalls) |
178 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
250 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
179 | else |
251 | else |
180 | thiswall = arch_to_object (the_wall->arch); |
252 | thiswall = the_wall->arch->instance (); |
181 | thiswall->x = i; |
253 | |
182 | thiswall->y = j; |
|
|
183 | thiswall->move_block = MOVE_ALL; |
254 | thiswall->move_block = MOVE_ALL; |
184 | insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
255 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
256 | |
|
|
257 | if (mining_map) |
|
|
258 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
|
|
259 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
185 | } |
260 | } |
186 | } |
261 | } |
187 | } |
262 | } |
188 | } |
263 | } |
189 | |
|
|
190 | |
|
|
191 | /* picks the right wall type for this square, to make it look nice, |
|
|
192 | and have everything nicely joined. It uses the layout. */ |
|
|
193 | |
|
|
194 | object * |
|
|
195 | pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) |
|
|
196 | { |
|
|
197 | /* 1 = wall to left, |
|
|
198 | 2 = wall to right, |
|
|
199 | 4 = wall above |
|
|
200 | 8 = wall below */ |
|
|
201 | int surround_index = 0; |
|
|
202 | int l; |
|
|
203 | char wall_name[1024]; |
|
|
204 | archetype *wall_arch = 0; |
|
|
205 | |
|
|
206 | assign (wall_name, the_wall->arch->archname); |
|
|
207 | |
|
|
208 | /* conventionally, walls are named like this: |
|
|
209 | wallname_wallcode, where wallcode indicates |
|
|
210 | a joinedness, and wallname is the wall. |
|
|
211 | this code depends on the convention for |
|
|
212 | finding the right wall. */ |
|
|
213 | |
|
|
214 | /* extract the wall name, which is the text up to the leading _ */ |
|
|
215 | for (l = 0; l < 64; l++) |
|
|
216 | { |
|
|
217 | if (wall_name[l] == '_') |
|
|
218 | { |
|
|
219 | wall_name[l] = 0; |
|
|
220 | break; |
|
|
221 | } |
|
|
222 | } |
|
|
223 | |
|
|
224 | surround_index = surround_flag2 (layout, i, j, RP); |
|
|
225 | |
|
|
226 | switch (surround_index) |
|
|
227 | { |
|
|
228 | case 0: |
|
|
229 | strcat (wall_name, "_0"); |
|
|
230 | break; |
|
|
231 | case 1: |
|
|
232 | strcat (wall_name, "_1_3"); |
|
|
233 | break; |
|
|
234 | case 2: |
|
|
235 | strcat (wall_name, "_1_4"); |
|
|
236 | break; |
|
|
237 | case 3: |
|
|
238 | strcat (wall_name, "_2_1_2"); |
|
|
239 | break; |
|
|
240 | case 4: |
|
|
241 | strcat (wall_name, "_1_2"); |
|
|
242 | break; |
|
|
243 | case 5: |
|
|
244 | strcat (wall_name, "_2_2_4"); |
|
|
245 | break; |
|
|
246 | case 6: |
|
|
247 | strcat (wall_name, "_2_2_1"); |
|
|
248 | break; |
|
|
249 | case 7: |
|
|
250 | strcat (wall_name, "_3_1"); |
|
|
251 | break; |
|
|
252 | case 8: |
|
|
253 | strcat (wall_name, "_1_1"); |
|
|
254 | break; |
|
|
255 | case 9: |
|
|
256 | strcat (wall_name, "_2_2_3"); |
|
|
257 | break; |
|
|
258 | case 10: |
|
|
259 | strcat (wall_name, "_2_2_2"); |
|
|
260 | break; |
|
|
261 | case 11: |
|
|
262 | strcat (wall_name, "_3_3"); |
|
|
263 | break; |
|
|
264 | case 12: |
|
|
265 | strcat (wall_name, "_2_1_1"); |
|
|
266 | break; |
|
|
267 | case 13: |
|
|
268 | strcat (wall_name, "_3_4"); |
|
|
269 | break; |
|
|
270 | case 14: |
|
|
271 | strcat (wall_name, "_3_2"); |
|
|
272 | break; |
|
|
273 | case 15: |
|
|
274 | strcat (wall_name, "_4"); |
|
|
275 | break; |
|
|
276 | } |
|
|
277 | wall_arch = archetype::find (wall_name); |
|
|
278 | |
|
|
279 | return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); |
|
|
280 | } |
|
|
281 | |
|
|
282 | |
264 | |
283 | /* this takes a map, and changes an existing wall to match what's blocked |
265 | /* this takes a map, and changes an existing wall to match what's blocked |
284 | * around it, counting only doors and walls as blocked. If insert_flag is |
266 | * around it, counting only doors and walls as blocked. If insert_flag is |
285 | * 1, it will go ahead and insert the wall into the map. If not, it |
267 | * 1, it will go ahead and insert the wall into the map. If not, it |
286 | * will only return the wall which would belong there, and doesn't |
268 | * will only return the wall which would belong there, and doesn't |
287 | * remove anything. It depends on the |
269 | * remove anything. It depends on the |
288 | * global, previously-set variable, "wall_name" |
270 | * global, previously-set variable, "wall_name" |
289 | */ |
271 | */ |
290 | |
|
|
291 | object * |
272 | object * |
292 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
273 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
293 | { |
274 | { |
294 | /* 1 = wall to left, |
275 | /* 1 = wall to left, |
295 | * 2 = wall to right, |
276 | * 2 = wall to right, |
… | |
… | |
391 | |
372 | |
392 | wall_arch = archetype::find (RP->wall_name); |
373 | wall_arch = archetype::find (RP->wall_name); |
393 | |
374 | |
394 | if (!wall_arch) |
375 | if (!wall_arch) |
395 | { |
376 | { |
396 | new_wall = arch_to_object (wall_arch); |
377 | new_wall = wall_arch->instance (); |
397 | new_wall->x = i; |
378 | new_wall->x = i; |
398 | new_wall->y = j; |
379 | new_wall->y = j; |
399 | |
380 | |
400 | if (the_wall && the_wall->map) |
381 | if (the_wall && the_wall->map) |
401 | { |
|
|
402 | the_wall->remove (); |
|
|
403 | the_wall->destroy (); |
382 | the_wall->destroy (); |
404 | } |
|
|
405 | |
383 | |
406 | the_wall->move_block = MOVE_ALL; |
384 | the_wall->move_block = MOVE_ALL; |
407 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
385 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
408 | } |
386 | } |
409 | |
387 | |