1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
29 | /* Put in the walls and autojoin them. */ |
29 | /* Put in the walls and autojoin them. */ |
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 | int |
33 | int |
34 | surround_flag (char **layout, int i, int j, random_map_params *RP) |
34 | surround_flag (const Layout &layout, int i, int j) |
35 | { |
35 | { |
36 | /* 1 = wall to left, |
36 | /* 1 = wall to left, |
37 | 2 = wall to right, |
37 | 2 = wall to right, |
38 | 4 = wall above |
38 | 4 = wall above |
39 | 8 = wall below */ |
39 | 8 = wall below */ |
40 | int surround_index = 0; |
40 | int surround_index = 0; |
41 | |
41 | |
42 | if ((i > 0) && layout[i - 1][j] != 0) |
42 | if (i > 0 && layout[i - 1][j] != 0) surround_index |= 1; |
43 | surround_index |= 1; |
43 | if (i < layout.w - 1 && layout[i + 1][j] != 0) surround_index |= 2; |
44 | if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) |
44 | if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4; |
45 | surround_index |= 2; |
45 | if (j < layout.h - 1 && layout[i][j + 1] != 0) surround_index |= 8; |
46 | if ((j > 0) && layout[i][j - 1] != 0) |
46 | |
47 | surround_index |= 4; |
|
|
48 | if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0) |
|
|
49 | surround_index |= 8; |
|
|
50 | return surround_index; |
47 | return surround_index; |
51 | } |
48 | } |
52 | |
49 | |
53 | |
|
|
54 | /* like surround_flag, but only walls count. |
50 | /* like surround_flag, but only walls count. */ |
55 | */ |
|
|
56 | |
|
|
57 | int |
51 | int |
58 | surround_flag2 (char **layout, int i, int j, random_map_params *RP) |
52 | surround_flag2 (const Layout &layout, int i, int j) |
59 | { |
53 | { |
60 | /* 1 = wall to left, |
54 | /* 1 = wall to left, |
61 | 2 = wall to right, |
55 | 2 = wall to right, |
62 | 4 = wall above |
56 | 4 = wall above |
63 | 8 = wall below */ |
57 | 8 = wall below */ |
64 | int surround_index = 0; |
58 | int surround_index = 0; |
65 | |
59 | |
66 | if ((i > 0) && layout[i - 1][j] == '#') |
60 | if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1; |
67 | surround_index |= 1; |
61 | if (i < layout.w - 1 && layout[i + 1][j] == '#') surround_index |= 2; |
68 | if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') |
62 | if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4; |
69 | surround_index |= 2; |
63 | if (j < layout.h - 1 && layout[i][j + 1] == '#') surround_index |= 8; |
70 | if ((j > 0) && layout[i][j - 1] == '#') |
64 | |
71 | surround_index |= 4; |
|
|
72 | if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#') |
|
|
73 | surround_index |= 8; |
|
|
74 | return surround_index; |
65 | return surround_index; |
75 | } |
66 | } |
76 | |
|
|
77 | |
67 | |
78 | /* like surround_flag, except it checks a map, not a layout. |
68 | /* like surround_flag, except it checks a map, not a layout. |
79 | * Since this is part of the random map code, presumption |
69 | * Since this is part of the random map code, presumption |
80 | * is that this is not a tiled map. |
70 | * is that this is not a tiled map. |
81 | * What is considered blocking and not is somewhat hard coded. |
71 | * What is considered blocking and not is somewhat hard coded. |
82 | */ |
72 | */ |
83 | int |
73 | int |
84 | surround_flag3 (maptile *map, sint16 i, sint16 j, random_map_params *RP) |
74 | surround_flag3 (maptile *map, int i, int j) |
85 | { |
75 | { |
86 | /* |
76 | /* |
87 | * 1 = blocked to left, |
77 | * 1 = blocked to left, |
88 | * 2 = blocked to right, |
78 | * 2 = blocked to right, |
89 | * 4 = blocked above |
79 | * 4 = blocked above |
90 | * 8 = blocked below |
80 | * 8 = blocked below |
91 | */ |
81 | */ |
92 | |
|
|
93 | int surround_index = 0; |
82 | int surround_index = 0; |
94 | |
83 | |
95 | // don't forget to update the mapspace! |
84 | // don't forget to update the mapspace! |
96 | if (i > 0) map->at (i - 1, j ).update (); |
85 | if (i > 0) map->at (i - 1, j ).update (); |
97 | if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); |
86 | if (i < map->width - 1) map->at (i + 1, j ).update (); |
98 | if (j > 0) map->at (i , j - 1).update (); |
87 | if (j > 0) map->at (i , j - 1).update (); |
99 | if (j < RP->Ysize - 1) map->at (i , j + 1).update (); |
88 | if (j < map->height - 1) map->at (i , j + 1).update (); |
100 | |
89 | |
101 | if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) |
90 | if (i > 0 && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) surround_index |= 1; |
102 | surround_index |= 1; |
|
|
103 | if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) |
91 | if (i < map->width - 1 && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) surround_index |= 2; |
104 | surround_index |= 2; |
|
|
105 | if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) |
92 | if (j > 0 && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK)) surround_index |= 4; |
106 | surround_index |= 4; |
|
|
107 | if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) |
93 | if (j < map->height - 1 && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK)) surround_index |= 8; |
108 | surround_index |= 8; |
|
|
109 | |
94 | |
110 | return surround_index; |
95 | return surround_index; |
111 | } |
96 | } |
112 | |
97 | |
113 | /* like surround_flag2, except it checks a map, not a layout. */ |
98 | /* like surround_flag2, except it checks a map, not a layout. */ |
114 | |
99 | static int |
115 | int |
|
|
116 | surround_flag4 (maptile *map, int i, int j, random_map_params *RP) |
100 | surround_flag4 (maptile *map, int i, int j) |
117 | { |
101 | { |
118 | /* 1 = blocked to left, |
102 | /* 1 = blocked to left, |
119 | 2 = blocked to right, |
103 | 2 = blocked to right, |
120 | 4 = blocked above |
104 | 4 = blocked above |
121 | 8 = blocked below */ |
105 | 8 = blocked below */ |
122 | int surround_index = 0; |
106 | int surround_index = 0; |
123 | |
107 | |
124 | if ((i > 0) && wall_blocked (map, i - 1, j)) |
108 | if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1; |
125 | surround_index |= 1; |
109 | if (i < map->width - 1 && wall_blocked (map, i + 1, j)) surround_index |= 2; |
126 | if ((i < RP->Xsize - 1) && wall_blocked (map, i + 1, j)) |
110 | if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4; |
127 | surround_index |= 2; |
111 | if (j < map->height - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8; |
128 | if ((j > 0) && wall_blocked (map, i, j - 1)) |
|
|
129 | surround_index |= 4; |
|
|
130 | if ((j < RP->Ysize - 1) && wall_blocked (map, i, j + 1)) |
|
|
131 | surround_index |= 8; |
|
|
132 | |
112 | |
133 | return surround_index; |
113 | return surround_index; |
|
|
114 | } |
|
|
115 | |
|
|
116 | /* picks the right wall type for this square, to make it look nice, |
|
|
117 | and have everything nicely joined. It uses the layout. */ |
|
|
118 | static object * |
|
|
119 | pick_joined_wall (object *the_wall, const Layout &layout, int i, int j, random_map_params *RP) |
|
|
120 | { |
|
|
121 | /* 1 = wall to left, |
|
|
122 | 2 = wall to right, |
|
|
123 | 4 = wall above |
|
|
124 | 8 = wall below */ |
|
|
125 | int surround_index = 0; |
|
|
126 | int l; |
|
|
127 | char wall_name[1024]; |
|
|
128 | archetype *wall_arch = 0; |
|
|
129 | |
|
|
130 | assign (wall_name, the_wall->arch->archname); |
|
|
131 | |
|
|
132 | /* conventionally, walls are named like this: |
|
|
133 | wallname_wallcode, where wallcode indicates |
|
|
134 | a joinedness, and wallname is the wall. |
|
|
135 | this code depends on the convention for |
|
|
136 | finding the right wall. */ |
|
|
137 | |
|
|
138 | /* extract the wall name, which is the text up to the leading _ */ |
|
|
139 | for (l = 0; l < 64; l++) |
|
|
140 | { |
|
|
141 | if (wall_name[l] == '_') |
|
|
142 | { |
|
|
143 | wall_name[l] = 0; |
|
|
144 | break; |
|
|
145 | } |
|
|
146 | } |
|
|
147 | |
|
|
148 | surround_index = surround_flag2 (layout, i, j); |
|
|
149 | |
|
|
150 | switch (surround_index) |
|
|
151 | { |
|
|
152 | case 0: |
|
|
153 | strcat (wall_name, "_0"); |
|
|
154 | break; |
|
|
155 | case 1: |
|
|
156 | strcat (wall_name, "_1_3"); |
|
|
157 | break; |
|
|
158 | case 2: |
|
|
159 | strcat (wall_name, "_1_4"); |
|
|
160 | break; |
|
|
161 | case 3: |
|
|
162 | strcat (wall_name, "_2_1_2"); |
|
|
163 | break; |
|
|
164 | case 4: |
|
|
165 | strcat (wall_name, "_1_2"); |
|
|
166 | break; |
|
|
167 | case 5: |
|
|
168 | strcat (wall_name, "_2_2_4"); |
|
|
169 | break; |
|
|
170 | case 6: |
|
|
171 | strcat (wall_name, "_2_2_1"); |
|
|
172 | break; |
|
|
173 | case 7: |
|
|
174 | strcat (wall_name, "_3_1"); |
|
|
175 | break; |
|
|
176 | case 8: |
|
|
177 | strcat (wall_name, "_1_1"); |
|
|
178 | break; |
|
|
179 | case 9: |
|
|
180 | strcat (wall_name, "_2_2_3"); |
|
|
181 | break; |
|
|
182 | case 10: |
|
|
183 | strcat (wall_name, "_2_2_2"); |
|
|
184 | break; |
|
|
185 | case 11: |
|
|
186 | strcat (wall_name, "_3_3"); |
|
|
187 | break; |
|
|
188 | case 12: |
|
|
189 | strcat (wall_name, "_2_1_1"); |
|
|
190 | break; |
|
|
191 | case 13: |
|
|
192 | strcat (wall_name, "_3_4"); |
|
|
193 | break; |
|
|
194 | case 14: |
|
|
195 | strcat (wall_name, "_3_2"); |
|
|
196 | break; |
|
|
197 | case 15: |
|
|
198 | strcat (wall_name, "_4"); |
|
|
199 | break; |
|
|
200 | } |
|
|
201 | wall_arch = archetype::find (wall_name); |
|
|
202 | |
|
|
203 | return wall_arch ? wall_arch->instance () : the_wall->arch->instance (); |
134 | } |
204 | } |
135 | |
205 | |
136 | /* takes a map and a layout, and puts walls in the map (picked from |
206 | /* takes a map and a layout, and puts walls in the map (picked from |
137 | w_style) at '#' marks. */ |
207 | w_style) at '#' marks. */ |
138 | |
|
|
139 | void |
208 | void |
140 | make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) |
209 | make_map_walls (maptile *map, Layout &layout, const char *w_style, const char *m_style, random_map_params *RP) |
141 | { |
210 | { |
142 | char styledirname[1024]; |
|
|
143 | char stylefilepath[1024]; |
|
|
144 | maptile *style_map = 0; |
|
|
145 | object *the_wall; |
211 | object *the_wall; |
146 | |
212 | |
147 | /* get the style map */ |
213 | /* get the style map */ |
148 | if (!strcmp (w_style, "none")) |
214 | if (!strcmp (w_style, "none")) |
149 | return; |
215 | return; |
150 | sprintf (styledirname, "%s", "/styles/wallstyles"); |
216 | |
151 | sprintf (stylefilepath, "%s/%s", styledirname, w_style); |
217 | maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty); |
152 | style_map = find_style (styledirname, w_style, -1); |
|
|
153 | if (!style_map) |
218 | if (!style_map) |
154 | return; |
219 | return; |
155 | |
220 | |
156 | /* fill up the map with the given floor style */ |
221 | maptile *mining_map = m_style && *m_style |
|
|
222 | ? find_style ("/styles/miningstyles", m_style, RP->difficulty) |
|
|
223 | : 0; |
|
|
224 | |
157 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
225 | if ((the_wall = style_map->pick_random_object (rmg_rndm))) |
158 | { |
226 | { |
159 | int i, j; |
227 | int i, j; |
160 | char *cp; |
228 | char *cp; |
161 | int joinedwalls = 0; |
229 | int joinedwalls = 0; |
… | |
… | |
174 | if (layout[i][j] == '#') |
242 | if (layout[i][j] == '#') |
175 | { |
243 | { |
176 | if (joinedwalls) |
244 | if (joinedwalls) |
177 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
245 | thiswall = pick_joined_wall (the_wall, layout, i, j, RP); |
178 | else |
246 | else |
179 | thiswall = arch_to_object (the_wall->arch); |
247 | thiswall = the_wall->arch->instance (); |
180 | thiswall->x = i; |
248 | |
181 | thiswall->y = j; |
|
|
182 | thiswall->move_block = MOVE_ALL; |
249 | thiswall->move_block = MOVE_ALL; |
183 | insert_ob_in_map (thiswall, map, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
250 | map->insert (thiswall, i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
251 | |
|
|
252 | if (mining_map) |
|
|
253 | if (object *vein = mining_map->at (rmg_rndm (mining_map->width), rmg_rndm (mining_map->height)).bot) |
|
|
254 | map->insert (vein->clone (), i, j, thiswall, INS_NO_MERGE | INS_NO_WALK_ON); |
184 | } |
255 | } |
185 | } |
256 | } |
186 | } |
257 | } |
187 | } |
258 | } |
188 | |
|
|
189 | |
|
|
190 | /* picks the right wall type for this square, to make it look nice, |
|
|
191 | and have everything nicely joined. It uses the layout. */ |
|
|
192 | |
|
|
193 | object * |
|
|
194 | pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP) |
|
|
195 | { |
|
|
196 | /* 1 = wall to left, |
|
|
197 | 2 = wall to right, |
|
|
198 | 4 = wall above |
|
|
199 | 8 = wall below */ |
|
|
200 | int surround_index = 0; |
|
|
201 | int l; |
|
|
202 | char wall_name[1024]; |
|
|
203 | archetype *wall_arch = 0; |
|
|
204 | |
|
|
205 | assign (wall_name, the_wall->arch->archname); |
|
|
206 | |
|
|
207 | /* conventionally, walls are named like this: |
|
|
208 | wallname_wallcode, where wallcode indicates |
|
|
209 | a joinedness, and wallname is the wall. |
|
|
210 | this code depends on the convention for |
|
|
211 | finding the right wall. */ |
|
|
212 | |
|
|
213 | /* extract the wall name, which is the text up to the leading _ */ |
|
|
214 | for (l = 0; l < 64; l++) |
|
|
215 | { |
|
|
216 | if (wall_name[l] == '_') |
|
|
217 | { |
|
|
218 | wall_name[l] = 0; |
|
|
219 | break; |
|
|
220 | } |
|
|
221 | } |
|
|
222 | |
|
|
223 | surround_index = surround_flag2 (layout, i, j, RP); |
|
|
224 | |
|
|
225 | switch (surround_index) |
|
|
226 | { |
|
|
227 | case 0: |
|
|
228 | strcat (wall_name, "_0"); |
|
|
229 | break; |
|
|
230 | case 1: |
|
|
231 | strcat (wall_name, "_1_3"); |
|
|
232 | break; |
|
|
233 | case 2: |
|
|
234 | strcat (wall_name, "_1_4"); |
|
|
235 | break; |
|
|
236 | case 3: |
|
|
237 | strcat (wall_name, "_2_1_2"); |
|
|
238 | break; |
|
|
239 | case 4: |
|
|
240 | strcat (wall_name, "_1_2"); |
|
|
241 | break; |
|
|
242 | case 5: |
|
|
243 | strcat (wall_name, "_2_2_4"); |
|
|
244 | break; |
|
|
245 | case 6: |
|
|
246 | strcat (wall_name, "_2_2_1"); |
|
|
247 | break; |
|
|
248 | case 7: |
|
|
249 | strcat (wall_name, "_3_1"); |
|
|
250 | break; |
|
|
251 | case 8: |
|
|
252 | strcat (wall_name, "_1_1"); |
|
|
253 | break; |
|
|
254 | case 9: |
|
|
255 | strcat (wall_name, "_2_2_3"); |
|
|
256 | break; |
|
|
257 | case 10: |
|
|
258 | strcat (wall_name, "_2_2_2"); |
|
|
259 | break; |
|
|
260 | case 11: |
|
|
261 | strcat (wall_name, "_3_3"); |
|
|
262 | break; |
|
|
263 | case 12: |
|
|
264 | strcat (wall_name, "_2_1_1"); |
|
|
265 | break; |
|
|
266 | case 13: |
|
|
267 | strcat (wall_name, "_3_4"); |
|
|
268 | break; |
|
|
269 | case 14: |
|
|
270 | strcat (wall_name, "_3_2"); |
|
|
271 | break; |
|
|
272 | case 15: |
|
|
273 | strcat (wall_name, "_4"); |
|
|
274 | break; |
|
|
275 | } |
|
|
276 | wall_arch = archetype::find (wall_name); |
|
|
277 | |
|
|
278 | return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch); |
|
|
279 | } |
|
|
280 | |
|
|
281 | |
259 | |
282 | /* this takes a map, and changes an existing wall to match what's blocked |
260 | /* this takes a map, and changes an existing wall to match what's blocked |
283 | * around it, counting only doors and walls as blocked. If insert_flag is |
261 | * around it, counting only doors and walls as blocked. If insert_flag is |
284 | * 1, it will go ahead and insert the wall into the map. If not, it |
262 | * 1, it will go ahead and insert the wall into the map. If not, it |
285 | * will only return the wall which would belong there, and doesn't |
263 | * will only return the wall which would belong there, and doesn't |
286 | * remove anything. It depends on the |
264 | * remove anything. It depends on the |
287 | * global, previously-set variable, "wall_name" |
265 | * global, previously-set variable, "wall_name" |
288 | */ |
266 | */ |
289 | |
|
|
290 | object * |
267 | object * |
291 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
268 | retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) |
292 | { |
269 | { |
293 | /* 1 = wall to left, |
270 | /* 1 = wall to left, |
294 | * 2 = wall to right, |
271 | * 2 = wall to right, |
… | |
… | |
330 | RP->wall_name[l] = 0; |
307 | RP->wall_name[l] = 0; |
331 | break; |
308 | break; |
332 | } |
309 | } |
333 | } |
310 | } |
334 | |
311 | |
335 | surround_index = surround_flag4 (the_map, i, j, RP); |
312 | surround_index = surround_flag4 (the_map, i, j); |
336 | /* This would be a lot cleaner to just us a lookup table, |
313 | /* This would be a lot cleaner to just us a lookup table, |
337 | * eg, wall_suffix[surround_index] |
314 | * eg, wall_suffix[surround_index] |
338 | */ |
315 | */ |
339 | switch (surround_index) |
316 | switch (surround_index) |
340 | { |
317 | { |
… | |
… | |
390 | |
367 | |
391 | wall_arch = archetype::find (RP->wall_name); |
368 | wall_arch = archetype::find (RP->wall_name); |
392 | |
369 | |
393 | if (!wall_arch) |
370 | if (!wall_arch) |
394 | { |
371 | { |
395 | new_wall = arch_to_object (wall_arch); |
372 | new_wall = wall_arch->instance (); |
396 | new_wall->x = i; |
373 | new_wall->x = i; |
397 | new_wall->y = j; |
374 | new_wall->y = j; |
398 | |
375 | |
399 | if (the_wall && the_wall->map) |
376 | if (the_wall && the_wall->map) |
400 | the_wall->destroy (); |
377 | the_wall->destroy (); |