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 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, |
… | |
… | |
110 | |
109 | |
111 | return surround_index; |
110 | return surround_index; |
112 | } |
111 | } |
113 | |
112 | |
114 | /* like surround_flag2, except it checks a map, not a layout. */ |
113 | /* like surround_flag2, except it checks a map, not a layout. */ |
115 | |
114 | static int |
116 | int |
|
|
117 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
115 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
118 | { |
116 | { |
119 | /* 1 = blocked to left, |
117 | /* 1 = blocked to left, |
120 | 2 = blocked to right, |
118 | 2 = blocked to right, |
121 | 4 = blocked above |
119 | 4 = blocked above |
… | |
… | |
132 | surround_index |= 8; |
130 | surround_index |= 8; |
133 | |
131 | |
134 | return surround_index; |
132 | return surround_index; |
135 | } |
133 | } |
136 | |
134 | |
|
|
135 | /* picks the right wall type for this square, to make it look nice, |
|
|
136 | and have everything nicely joined. It uses the layout. */ |
|
|
137 | static object * |
|
|
138 | pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) |
|
|
139 | { |
|
|
140 | /* 1 = wall to left, |
|
|
141 | 2 = wall to right, |
|
|
142 | 4 = wall above |
|
|
143 | 8 = wall below */ |
|
|
144 | int surround_index = 0; |
|
|
145 | int l; |
|
|
146 | char wall_name[1024]; |
|
|
147 | archetype *wall_arch = 0; |
|
|
148 | |
|
|
149 | assign (wall_name, the_wall->arch->archname); |
|
|
150 | |
|
|
151 | /* conventionally, walls are named like this: |
|
|
152 | wallname_wallcode, where wallcode indicates |
|
|
153 | a joinedness, and wallname is the wall. |
|
|
154 | this code depends on the convention for |
|
|
155 | finding the right wall. */ |
|
|
156 | |
|
|
157 | /* extract the wall name, which is the text up to the leading _ */ |
|
|
158 | for (l = 0; l < 64; l++) |
|
|
159 | { |
|
|
160 | if (wall_name[l] == '_') |
|
|
161 | { |
|
|
162 | wall_name[l] = 0; |
|
|
163 | break; |
|
|
164 | } |
|
|
165 | } |
|
|
166 | |
|
|
167 | surround_index = surround_flag2 (layout, i, j, RP); |
|
|
168 | |
|
|
169 | switch (surround_index) |
|
|
170 | { |
|
|
171 | case 0: |
|
|
172 | strcat (wall_name, "_0"); |
|
|
173 | break; |
|
|
174 | case 1: |
|
|
175 | strcat (wall_name, "_1_3"); |
|
|
176 | break; |
|
|
177 | case 2: |
|
|
178 | strcat (wall_name, "_1_4"); |
|
|
179 | break; |
|
|
180 | case 3: |
|
|
181 | strcat (wall_name, "_2_1_2"); |
|
|
182 | break; |
|
|
183 | case 4: |
|
|
184 | strcat (wall_name, "_1_2"); |
|
|
185 | break; |
|
|
186 | case 5: |
|
|
187 | strcat (wall_name, "_2_2_4"); |
|
|
188 | break; |
|
|
189 | case 6: |
|
|
190 | strcat (wall_name, "_2_2_1"); |
|
|
191 | break; |
|
|
192 | case 7: |
|
|
193 | strcat (wall_name, "_3_1"); |
|
|
194 | break; |
|
|
195 | case 8: |
|
|
196 | strcat (wall_name, "_1_1"); |
|
|
197 | break; |
|
|
198 | case 9: |
|
|
199 | strcat (wall_name, "_2_2_3"); |
|
|
200 | break; |
|
|
201 | case 10: |
|
|
202 | strcat (wall_name, "_2_2_2"); |
|
|
203 | break; |
|
|
204 | case 11: |
|
|
205 | strcat (wall_name, "_3_3"); |
|
|
206 | break; |
|
|
207 | case 12: |
|
|
208 | strcat (wall_name, "_2_1_1"); |
|
|
209 | break; |
|
|
210 | case 13: |
|
|
211 | strcat (wall_name, "_3_4"); |
|
|
212 | break; |
|
|
213 | case 14: |
|
|
214 | strcat (wall_name, "_3_2"); |
|
|
215 | break; |
|
|
216 | case 15: |
|
|
217 | strcat (wall_name, "_4"); |
|
|
218 | break; |
|
|
219 | } |
|
|
220 | wall_arch = archetype::find (wall_name); |
|
|
221 | |
|
|
222 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
|
|
223 | } |
|
|
224 | |
137 | /* takes a map and a layout, and puts walls in the map (picked from |
225 | /* takes a map and a layout, and puts walls in the map (picked from |
138 | w_style) at '#' marks. */ |
226 | w_style) at '#' marks. */ |
139 | |
|
|
140 | void |
227 | void |
141 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
228 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
142 | { |
229 | { |
143 | char styledirname[1024]; |
230 | char styledirname[1024]; |
144 | char stylefilepath[1024]; |
231 | char stylefilepath[1024]; |
… | |
… | |
153 | style_map = find_style (styledirname, w_style, -1); |
240 | style_map = find_style (styledirname, w_style, -1); |
154 | if (!style_map) |
241 | if (!style_map) |
155 | return; |
242 | return; |
156 | |
243 | |
157 | /* fill up the map with the given floor style */ |
244 | /* fill up the map with the given floor style */ |
158 | if ((the_wall = style_map->pick_random_object ())) |
245 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
159 | { |
246 | { |
160 | int i, j; |
247 | int i, j; |
161 | char *cp; |
248 | char *cp; |
162 | int joinedwalls = 0; |
249 | int joinedwalls = 0; |
163 | object *thiswall; |
250 | object *thiswall; |
… | |
… | |
175 | if (layout[i][j] == '#') |
262 | if (layout[i][j] == '#') |
176 | { |
263 | { |
177 | if (joinedwalls) |
264 | if (joinedwalls) |
178 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
265 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
179 | else |
266 | else |
180 | thiswall = arch_to_object (the_wall->arch); |
267 | thiswall = the_wall->arch->instance (); |
|
|
268 | |
181 | thiswall->x = i; |
269 | thiswall->x = i; |
182 | thiswall->y = j; |
270 | thiswall->y = j; |
183 | thiswall->move_block = MOVE_ALL; |
271 | thiswall->move_block = MOVE_ALL; |
184 | insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
272 | insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
185 | } |
273 | } |
186 | } |
274 | } |
187 | } |
275 | } |
188 | } |
276 | } |
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 | |
277 | |
283 | /* this takes a map, and changes an existing wall to match what's blocked |
278 | /* 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 |
279 | * 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 |
280 | * 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 |
281 | * will only return the wall which would belong there, and doesn't |
287 | * remove anything. It depends on the |
282 | * remove anything. It depends on the |
288 | * global, previously-set variable, "wall_name" |
283 | * global, previously-set variable, "wall_name" |
289 | */ |
284 | */ |
290 | |
|
|
291 | object * |
285 | object * |
292 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
286 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
293 | { |
287 | { |
294 | /* 1 = wall to left, |
288 | /* 1 = wall to left, |
295 | * 2 = wall to right, |
289 | * 2 = wall to right, |
… | |
… | |
391 | |
385 | |
392 | wall_arch = archetype::find (RP->wall_name); |
386 | wall_arch = archetype::find (RP->wall_name); |
393 | |
387 | |
394 | if (!wall_arch) |
388 | if (!wall_arch) |
395 | { |
389 | { |
396 | new_wall = arch_to_object (wall_arch); |
390 | new_wall = wall_arch->instance (); |
397 | new_wall->x = i; |
391 | new_wall->x = i; |
398 | new_wall->y = j; |
392 | new_wall->y = j; |
399 | |
393 | |
400 | if (the_wall && the_wall->map) |
394 | if (the_wall && the_wall->map) |
401 | { |
|
|
402 | the_wall->remove (); |
|
|
403 | the_wall->destroy (); |
395 | the_wall->destroy (); |
404 | } |
|
|
405 | |
396 | |
406 | the_wall->move_block = MOVE_ALL; |
397 | the_wall->move_block = MOVE_ALL; |
407 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
398 | insert_ob_in_map (new_wall, the_map, new_wall, INS_NO_MERGE | INS_NO_WALK_ON); |
408 | } |
399 | } |
409 | |
400 | |