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.13 by root, Sun Dec 31 19:02:24 2006 UTC vs.
Revision 1.32 by root, Sun Nov 29 17:41:07 2009 UTC

1
2/* 1/*
3 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
4 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 7 *
8 This program 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 2 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, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23*/ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <random_map.h> 26#include <random_map.h>
27#include <rproto.h> 27#include <rproto.h>
28 28
29/* Put in the walls and autojoin them. */ 29/* Put in the walls and autojoin them. */
30 30
31
32/* 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
33 are occupied. */ 32 are occupied. */
34
35int 33int
36surround_flag (char **layout, int i, int j, random_map_params *RP) 34surround_flag (char **layout, int i, int j, random_map_params *RP)
37{ 35{
38 /* 1 = wall to left, 36 /* 1 = wall to left,
39 2 = wall to right, 37 2 = wall to right,
92 * 8 = blocked below 90 * 8 = blocked below
93 */ 91 */
94 92
95 int surround_index = 0; 93 int surround_index = 0;
96 94
95 // don't forget to update the mapspace!
96 if (i > 0) map->at (i - 1, j ).update ();
97 if (i < RP->Xsize - 1) map->at (i + 1, j ).update ();
98 if (j > 0) map->at (i , j - 1).update ();
99 if (j < RP->Ysize - 1) map->at (i , j + 1).update ();
100
97 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & ~MOVE_BLOCK_DEFAULT)) 101 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK))
98 surround_index |= 1; 102 surround_index |= 1;
99 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & ~MOVE_BLOCK_DEFAULT)) 103 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK))
100 surround_index |= 2; 104 surround_index |= 2;
101 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & ~MOVE_BLOCK_DEFAULT)) 105 if ((j > 0) && (GET_MAP_MOVE_BLOCK (map, i, j - 1) & MOVE_WALK))
102 surround_index |= 4; 106 surround_index |= 4;
103 if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & ~MOVE_BLOCK_DEFAULT)) 107 if ((j < RP->Ysize - 1) && (GET_MAP_MOVE_BLOCK (map, i, j + 1) & MOVE_WALK))
104 surround_index |= 8; 108 surround_index |= 8;
105 109
106 return surround_index; 110 return surround_index;
107} 111}
108 112
109/* like surround_flag2, except it checks a map, not a layout. */ 113/* like surround_flag2, except it checks a map, not a layout. */
110 114static int
111int
112surround_flag4 (maptile *map, int i, int j, random_map_params *RP) 115surround_flag4 (maptile *map, int i, int j, random_map_params *RP)
113{ 116{
114 /* 1 = blocked to left, 117 /* 1 = blocked to left,
115 2 = blocked to right, 118 2 = blocked to right,
116 4 = blocked above 119 4 = blocked above
127 surround_index |= 8; 130 surround_index |= 8;
128 131
129 return surround_index; 132 return surround_index;
130} 133}
131 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 ? wall_arch->instance () : the_wall->arch->instance ();
223}
224
132/* 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
133 w_style) at '#' marks. */ 226 w_style) at '#' marks. */
134
135void 227void
136make_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)
137{ 229{
138 char styledirname[256]; 230 char styledirname[1024];
139 char stylefilepath[256]; 231 char stylefilepath[1024];
140 maptile *style_map = 0; 232 maptile *style_map = 0;
141 object *the_wall; 233 object *the_wall;
142 234
143 /* get the style map */ 235 /* get the style map */
144 if (!strcmp (w_style, "none")) 236 if (!strcmp (w_style, "none"))
145 return; 237 return;
146 sprintf (styledirname, "%s", "/styles/wallstyles"); 238 sprintf (styledirname, "%s", "/styles/wallstyles");
147 sprintf (stylefilepath, "%s/%s", styledirname, w_style); 239 sprintf (stylefilepath, "%s/%s", styledirname, w_style);
148 style_map = find_style (styledirname, w_style, -1); 240 style_map = find_style (styledirname, w_style, -1);
149 if (style_map == 0) 241 if (!style_map)
150 return; 242 return;
151 243
152 /* fill up the map with the given floor style */ 244 /* fill up the map with the given floor style */
153 if ((the_wall = pick_random_object (style_map)) != NULL) 245 if ((the_wall = style_map->pick_random_object (rmg_rndm)))
154 { 246 {
155 int i, j; 247 int i, j;
156 char *cp; 248 char *cp;
157 int joinedwalls = 0; 249 int joinedwalls = 0;
158 object *thiswall; 250 object *thiswall;
159 251
160 sprintf (RP->wall_name, "%s", &the_wall->arch->name); 252 sprintf (RP->wall_name, "%s", &the_wall->arch->archname);
161 if ((cp = strchr (RP->wall_name, '_')) != NULL) 253 if ((cp = strchr (RP->wall_name, '_')) != NULL)
162 { 254 {
163 *cp = 0; 255 *cp = 0;
164 joinedwalls = 1; 256 joinedwalls = 1;
165 } 257 }
170 if (layout[i][j] == '#') 262 if (layout[i][j] == '#')
171 { 263 {
172 if (joinedwalls) 264 if (joinedwalls)
173 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 265 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
174 else 266 else
175 thiswall = arch_to_object (the_wall->arch); 267 thiswall = the_wall->arch->instance ();
268
176 thiswall->x = i; 269 thiswall->x = i;
177 thiswall->y = j; 270 thiswall->y = j;
178 thiswall->move_block = MOVE_ALL; 271 thiswall->move_block = MOVE_ALL;
179 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);
180 } 273 }
181 } 274 }
182 } 275 }
183} 276}
184
185
186/* picks the right wall type for this square, to make it look nice,
187 and have everything nicely joined. It uses the layout. */
188
189object *
190pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP)
191{
192 /* 1 = wall to left,
193 2 = wall to right,
194 4 = wall above
195 8 = wall below */
196 int surround_index = 0;
197 int l;
198 char wall_name[64];
199 archetype *wall_arch = 0;
200
201 strcpy (wall_name, the_wall->arch->name);
202
203 /* conventionally, walls are named like this:
204 wallname_wallcode, where wallcode indicates
205 a joinedness, and wallname is the wall.
206 this code depends on the convention for
207 finding the right wall. */
208
209 /* extract the wall name, which is the text up to the leading _ */
210 for (l = 0; l < 64; l++)
211 {
212 if (wall_name[l] == '_')
213 {
214 wall_name[l] = 0;
215 break;
216 }
217 }
218
219 surround_index = surround_flag2 (layout, i, j, RP);
220
221 switch (surround_index)
222 {
223 case 0:
224 strcat (wall_name, "_0");
225 break;
226 case 1:
227 strcat (wall_name, "_1_3");
228 break;
229 case 2:
230 strcat (wall_name, "_1_4");
231 break;
232 case 3:
233 strcat (wall_name, "_2_1_2");
234 break;
235 case 4:
236 strcat (wall_name, "_1_2");
237 break;
238 case 5:
239 strcat (wall_name, "_2_2_4");
240 break;
241 case 6:
242 strcat (wall_name, "_2_2_1");
243 break;
244 case 7:
245 strcat (wall_name, "_3_1");
246 break;
247 case 8:
248 strcat (wall_name, "_1_1");
249 break;
250 case 9:
251 strcat (wall_name, "_2_2_3");
252 break;
253 case 10:
254 strcat (wall_name, "_2_2_2");
255 break;
256 case 11:
257 strcat (wall_name, "_3_3");
258 break;
259 case 12:
260 strcat (wall_name, "_2_1_1");
261 break;
262 case 13:
263 strcat (wall_name, "_3_4");
264 break;
265 case 14:
266 strcat (wall_name, "_3_2");
267 break;
268 case 15:
269 strcat (wall_name, "_4");
270 break;
271 }
272 wall_arch = archetype::find (wall_name);
273
274 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
275}
276
277 277
278/* 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
279 * 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
280 * 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
281 * 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
282 * remove anything. It depends on the 282 * remove anything. It depends on the
283 * global, previously-set variable, "wall_name" 283 * global, previously-set variable, "wall_name"
284 */ 284 */
285
286object * 285object *
287retrofit_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)
288{ 287{
289 /* 1 = wall to left, 288 /* 1 = wall to left,
290 * 2 = wall to right, 289 * 2 = wall to right,
386 385
387 wall_arch = archetype::find (RP->wall_name); 386 wall_arch = archetype::find (RP->wall_name);
388 387
389 if (!wall_arch) 388 if (!wall_arch)
390 { 389 {
391 new_wall = arch_to_object (wall_arch); 390 new_wall = wall_arch->instance ();
392 new_wall->x = i; 391 new_wall->x = i;
393 new_wall->y = j; 392 new_wall->y = j;
394 393
395 if (the_wall && the_wall->map) 394 if (the_wall && the_wall->map)
396 {
397 the_wall->remove ();
398 the_wall->destroy (); 395 the_wall->destroy ();
399 }
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