ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/wall.C
(Generate patch)

Comparing deliantra/server/random_maps/wall.C (file contents):
Revision 1.29 by root, Mon Oct 12 14:00:58 2009 UTC vs.
Revision 1.36 by root, Sat Apr 10 01:54:07 2010 UTC

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.
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;
44 if ((i < RP->Xsize - 1) && layout[i + 1][j] != 0) 43 if (i < RP->Xsize - 1 && layout[i + 1][j] != 0) surround_index |= 2;
45 surround_index |= 2; 44 if (j > 0 && layout[i][j - 1] != 0) surround_index |= 4;
46 if ((j > 0) && layout[i][j - 1] != 0)
47 surround_index |= 4;
48 if ((j < RP->Ysize - 1) && layout[i][j + 1] != 0) 45 if (j < RP->Ysize - 1 && layout[i][j + 1] != 0) surround_index |= 8;
49 surround_index |= 8; 46
50 return surround_index; 47 return surround_index;
51} 48}
52 49
53 50
54/* like surround_flag, but only walls count. 51/* like surround_flag, but only walls count.
61 2 = wall to right, 58 2 = wall to right,
62 4 = wall above 59 4 = wall above
63 8 = wall below */ 60 8 = wall below */
64 int surround_index = 0; 61 int surround_index = 0;
65 62
66 if ((i > 0) && layout[i - 1][j] == '#') 63 if (i > 0 && layout[i - 1][j] == '#') surround_index |= 1;
67 surround_index |= 1;
68 if ((i < RP->Xsize - 1) && layout[i + 1][j] == '#') 64 if (i < RP->Xsize - 1 && layout[i + 1][j] == '#') surround_index |= 2;
69 surround_index |= 2; 65 if (j > 0 && layout[i][j - 1] == '#') surround_index |= 4;
70 if ((j > 0) && layout[i][j - 1] == '#')
71 surround_index |= 4;
72 if ((j < RP->Ysize - 1) && layout[i][j + 1] == '#') 66 if (j < RP->Ysize - 1 && layout[i][j + 1] == '#') surround_index |= 8;
73 surround_index |= 8; 67
74 return surround_index; 68 return surround_index;
75} 69}
76 70
77 71
78/* like surround_flag, except it checks a map, not a layout. 72/* like surround_flag, except it checks a map, not a layout.
96 if (i > 0) map->at (i - 1, j ).update (); 90 if (i > 0) map->at (i - 1, j ).update ();
97 if (i < RP->Xsize - 1) map->at (i + 1, j ).update (); 91 if (i < RP->Xsize - 1) map->at (i + 1, j ).update ();
98 if (j > 0) map->at (i , j - 1).update (); 92 if (j > 0) map->at (i , j - 1).update ();
99 if (j < RP->Ysize - 1) map->at (i , j + 1).update (); 93 if (j < RP->Ysize - 1) map->at (i , j + 1).update ();
100 94
101 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;
102 surround_index |= 1;
103 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;
104 surround_index |= 2;
105 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;
106 surround_index |= 4;
107 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;
108 surround_index |= 8;
109 99
110 return surround_index; 100 return surround_index;
111} 101}
112 102
113/* like surround_flag2, except it checks a map, not a layout. */ 103/* like surround_flag2, except it checks a map, not a layout. */
114 104static int
115int
116surround_flag4 (maptile *map, int i, int j, random_map_params *RP) 105surround_flag4 (maptile *map, int i, int j, random_map_params *RP)
117{ 106{
118 /* 1 = blocked to left, 107 /* 1 = blocked to left,
119 2 = blocked to right, 108 2 = blocked to right,
120 4 = blocked above 109 4 = blocked above
121 8 = blocked below */ 110 8 = blocked below */
122 int surround_index = 0; 111 int surround_index = 0;
123 112
124 if ((i > 0) && wall_blocked (map, i - 1, j)) 113 if (i > 0 && wall_blocked (map, i - 1, j)) surround_index |= 1;
125 surround_index |= 1;
126 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;
127 surround_index |= 2; 115 if (j > 0 && wall_blocked (map, i, j - 1)) surround_index |= 4;
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)) 116 if (j < RP->Ysize - 1 && wall_blocked (map, i, j + 1)) surround_index |= 8;
131 surround_index |= 8;
132 117
133 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. */
123static object *
124pick_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 ();
134} 209}
135 210
136/* 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
137 w_style) at '#' marks. */ 212 w_style) at '#' marks. */
138
139void 213void
140make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) 214make_map_walls (maptile *map, char **layout, const char *w_style, const char *m_style, random_map_params *RP)
141{ 215{
142 char styledirname[1024];
143 char stylefilepath[1024];
144 maptile *style_map = 0;
145 object *the_wall; 216 object *the_wall;
146 217
147 /* get the style map */ 218 /* get the style map */
148 if (!strcmp (w_style, "none")) 219 if (!strcmp (w_style, "none"))
149 return; 220 return;
150 sprintf (styledirname, "%s", "/styles/wallstyles"); 221
151 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 222 maptile *style_map = find_style ("/styles/wallstyles", w_style, RP->difficulty);
152 style_map = find_style (styledirname, w_style, -1);
153 if (!style_map) 223 if (!style_map)
154 return; 224 return;
155 225
156 /* 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
157 if ((the_wall = style_map->pick_random_object (rmg_rndm))) 230 if ((the_wall = style_map->pick_random_object (rmg_rndm)))
158 { 231 {
159 int i, j; 232 int i, j;
160 char *cp; 233 char *cp;
161 int joinedwalls = 0; 234 int joinedwalls = 0;
174 if (layout[i][j] == '#') 247 if (layout[i][j] == '#')
175 { 248 {
176 if (joinedwalls) 249 if (joinedwalls)
177 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 250 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
178 else 251 else
179 thiswall = arch_to_object (the_wall->arch); 252 thiswall = the_wall->arch->instance ();
180 thiswall->x = i; 253
181 thiswall->y = j;
182 thiswall->move_block = MOVE_ALL; 254 thiswall->move_block = MOVE_ALL;
183 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);
184 } 260 }
185 } 261 }
186 } 262 }
187} 263}
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
193object *
194pick_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 264
282/* 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
283 * 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
284 * 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
285 * 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
286 * remove anything. It depends on the 269 * remove anything. It depends on the
287 * global, previously-set variable, "wall_name" 270 * global, previously-set variable, "wall_name"
288 */ 271 */
289
290object * 272object *
291retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) 273retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP)
292{ 274{
293 /* 1 = wall to left, 275 /* 1 = wall to left,
294 * 2 = wall to right, 276 * 2 = wall to right,
390 372
391 wall_arch = archetype::find (RP->wall_name); 373 wall_arch = archetype::find (RP->wall_name);
392 374
393 if (!wall_arch) 375 if (!wall_arch)
394 { 376 {
395 new_wall = arch_to_object (wall_arch); 377 new_wall = wall_arch->instance ();
396 new_wall->x = i; 378 new_wall->x = i;
397 new_wall->y = j; 379 new_wall->y = j;
398 380
399 if (the_wall && the_wall->map) 381 if (the_wall && the_wall->map)
400 the_wall->destroy (); 382 the_wall->destroy ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines