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.27 by root, Mon Sep 29 09:04:51 2008 UTC vs.
Revision 1.31 by root, Fri Nov 6 13:03:34 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra 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 <support@deliantra.net> 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>
108 109
109 return surround_index; 110 return surround_index;
110} 111}
111 112
112/* like surround_flag2, except it checks a map, not a layout. */ 113/* like surround_flag2, except it checks a map, not a layout. */
113 114static int
114int
115surround_flag4 (maptile *map, int i, int j, random_map_params *RP) 115surround_flag4 (maptile *map, int i, int j, random_map_params *RP)
116{ 116{
117 /* 1 = blocked to left, 117 /* 1 = blocked to left,
118 2 = blocked to right, 118 2 = blocked to right,
119 4 = blocked above 119 4 = blocked above
130 surround_index |= 8; 130 surround_index |= 8;
131 131
132 return surround_index; 132 return surround_index;
133} 133}
134 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. */
137static object *
138pick_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 ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
223}
224
135/* 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
136 w_style) at '#' marks. */ 226 w_style) at '#' marks. */
137
138void 227void
139make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP) 228make_map_walls (maptile *map, char **layout, char *w_style, random_map_params *RP)
140{ 229{
141 char styledirname[1024]; 230 char styledirname[1024];
142 char stylefilepath[1024]; 231 char stylefilepath[1024];
174 { 263 {
175 if (joinedwalls) 264 if (joinedwalls)
176 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 265 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
177 else 266 else
178 thiswall = arch_to_object (the_wall->arch); 267 thiswall = arch_to_object (the_wall->arch);
268
179 thiswall->x = i; 269 thiswall->x = i;
180 thiswall->y = j; 270 thiswall->y = j;
181 thiswall->move_block = MOVE_ALL; 271 thiswall->move_block = MOVE_ALL;
182 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);
183 } 273 }
184 } 274 }
185 } 275 }
186} 276}
187
188
189/* picks the right wall type for this square, to make it look nice,
190 and have everything nicely joined. It uses the layout. */
191
192object *
193pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP)
194{
195 /* 1 = wall to left,
196 2 = wall to right,
197 4 = wall above
198 8 = wall below */
199 int surround_index = 0;
200 int l;
201 char wall_name[1024];
202 archetype *wall_arch = 0;
203
204 assign (wall_name, the_wall->arch->archname);
205
206 /* conventionally, walls are named like this:
207 wallname_wallcode, where wallcode indicates
208 a joinedness, and wallname is the wall.
209 this code depends on the convention for
210 finding the right wall. */
211
212 /* extract the wall name, which is the text up to the leading _ */
213 for (l = 0; l < 64; l++)
214 {
215 if (wall_name[l] == '_')
216 {
217 wall_name[l] = 0;
218 break;
219 }
220 }
221
222 surround_index = surround_flag2 (layout, i, j, RP);
223
224 switch (surround_index)
225 {
226 case 0:
227 strcat (wall_name, "_0");
228 break;
229 case 1:
230 strcat (wall_name, "_1_3");
231 break;
232 case 2:
233 strcat (wall_name, "_1_4");
234 break;
235 case 3:
236 strcat (wall_name, "_2_1_2");
237 break;
238 case 4:
239 strcat (wall_name, "_1_2");
240 break;
241 case 5:
242 strcat (wall_name, "_2_2_4");
243 break;
244 case 6:
245 strcat (wall_name, "_2_2_1");
246 break;
247 case 7:
248 strcat (wall_name, "_3_1");
249 break;
250 case 8:
251 strcat (wall_name, "_1_1");
252 break;
253 case 9:
254 strcat (wall_name, "_2_2_3");
255 break;
256 case 10:
257 strcat (wall_name, "_2_2_2");
258 break;
259 case 11:
260 strcat (wall_name, "_3_3");
261 break;
262 case 12:
263 strcat (wall_name, "_2_1_1");
264 break;
265 case 13:
266 strcat (wall_name, "_3_4");
267 break;
268 case 14:
269 strcat (wall_name, "_3_2");
270 break;
271 case 15:
272 strcat (wall_name, "_4");
273 break;
274 }
275 wall_arch = archetype::find (wall_name);
276
277 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
278}
279
280 277
281/* 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
282 * 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
283 * 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
284 * 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
285 * remove anything. It depends on the 282 * remove anything. It depends on the
286 * global, previously-set variable, "wall_name" 283 * global, previously-set variable, "wall_name"
287 */ 284 */
288
289object * 285object *
290retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP) 286retrofit_joined_wall (maptile *the_map, int i, int j, int insert_flag, random_map_params *RP)
291{ 287{
292 /* 1 = wall to left, 288 /* 1 = wall to left,
293 * 2 = wall to right, 289 * 2 = wall to right,
394 new_wall = arch_to_object (wall_arch); 390 new_wall = arch_to_object (wall_arch);
395 new_wall->x = i; 391 new_wall->x = i;
396 new_wall->y = j; 392 new_wall->y = j;
397 393
398 if (the_wall && the_wall->map) 394 if (the_wall && the_wall->map)
399 the_wall->destroy (true); 395 the_wall->destroy ();
400 396
401 the_wall->move_block = MOVE_ALL; 397 the_wall->move_block = MOVE_ALL;
402 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);
403 } 399 }
404 400

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines