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.20 by elmex, Sun Apr 15 14:15:14 2007 UTC vs.
Revision 1.31 by root, Fri Nov 6 13:03:34 2009 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 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,
93 */ 91 */
94 92
95 int surround_index = 0; 93 int surround_index = 0;
96 94
97 // don't forget to update the mapspace! 95 // don't forget to update the mapspace!
98 map->at (i - 1, j).update (); 96 if (i > 0) map->at (i - 1, j ).update ();
99 map->at (i + 1, j).update (); 97 if (i < RP->Xsize - 1) map->at (i + 1, j ).update ();
100 map->at (i , j - 1).update (); 98 if (j > 0) map->at (i , j - 1).update ();
101 map->at (i , j + 1).update (); 99 if (j < RP->Ysize - 1) map->at (i , j + 1).update ();
102 100
103 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK)) 101 if ((i > 0) && (GET_MAP_MOVE_BLOCK (map, i - 1, j) & MOVE_WALK))
104 surround_index |= 1; 102 surround_index |= 1;
105 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK)) 103 if ((i < RP->Xsize - 1) && (GET_MAP_MOVE_BLOCK (map, i + 1, j) & MOVE_WALK))
106 surround_index |= 2; 104 surround_index |= 2;
111 109
112 return surround_index; 110 return surround_index;
113} 111}
114 112
115/* like surround_flag2, except it checks a map, not a layout. */ 113/* like surround_flag2, except it checks a map, not a layout. */
116 114static int
117int
118surround_flag4 (maptile *map, int i, int j, random_map_params *RP) 115surround_flag4 (maptile *map, int i, int j, random_map_params *RP)
119{ 116{
120 /* 1 = blocked to left, 117 /* 1 = blocked to left,
121 2 = blocked to right, 118 2 = blocked to right,
122 4 = blocked above 119 4 = blocked above
133 surround_index |= 8; 130 surround_index |= 8;
134 131
135 return surround_index; 132 return surround_index;
136} 133}
137 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
138/* 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
139 w_style) at '#' marks. */ 226 w_style) at '#' marks. */
140
141void 227void
142make_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)
143{ 229{
144 char styledirname[1024]; 230 char styledirname[1024];
145 char stylefilepath[1024]; 231 char stylefilepath[1024];
154 style_map = find_style (styledirname, w_style, -1); 240 style_map = find_style (styledirname, w_style, -1);
155 if (!style_map) 241 if (!style_map)
156 return; 242 return;
157 243
158 /* fill up the map with the given floor style */ 244 /* fill up the map with the given floor style */
159 if ((the_wall = style_map->pick_random_object ())) 245 if ((the_wall = style_map->pick_random_object (rmg_rndm)))
160 { 246 {
161 int i, j; 247 int i, j;
162 char *cp; 248 char *cp;
163 int joinedwalls = 0; 249 int joinedwalls = 0;
164 object *thiswall; 250 object *thiswall;
165 251
166 sprintf (RP->wall_name, "%s", &the_wall->arch->name); 252 sprintf (RP->wall_name, "%s", &the_wall->arch->archname);
167 if ((cp = strchr (RP->wall_name, '_')) != NULL) 253 if ((cp = strchr (RP->wall_name, '_')) != NULL)
168 { 254 {
169 *cp = 0; 255 *cp = 0;
170 joinedwalls = 1; 256 joinedwalls = 1;
171 } 257 }
177 { 263 {
178 if (joinedwalls) 264 if (joinedwalls)
179 thiswall = pick_joined_wall (the_wall, layout, i, j, RP); 265 thiswall = pick_joined_wall (the_wall, layout, i, j, RP);
180 else 266 else
181 thiswall = arch_to_object (the_wall->arch); 267 thiswall = arch_to_object (the_wall->arch);
268
182 thiswall->x = i; 269 thiswall->x = i;
183 thiswall->y = j; 270 thiswall->y = j;
184 thiswall->move_block = MOVE_ALL; 271 thiswall->move_block = MOVE_ALL;
185 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);
186 } 273 }
187 } 274 }
188 } 275 }
189} 276}
190
191
192/* picks the right wall type for this square, to make it look nice,
193 and have everything nicely joined. It uses the layout. */
194
195object *
196pick_joined_wall (object *the_wall, char **layout, int i, int j, random_map_params *RP)
197{
198 /* 1 = wall to left,
199 2 = wall to right,
200 4 = wall above
201 8 = wall below */
202 int surround_index = 0;
203 int l;
204 char wall_name[1024];
205 archetype *wall_arch = 0;
206
207 assign (wall_name, the_wall->arch->name);
208
209 /* conventionally, walls are named like this:
210 wallname_wallcode, where wallcode indicates
211 a joinedness, and wallname is the wall.
212 this code depends on the convention for
213 finding the right wall. */
214
215 /* extract the wall name, which is the text up to the leading _ */
216 for (l = 0; l < 64; l++)
217 {
218 if (wall_name[l] == '_')
219 {
220 wall_name[l] = 0;
221 break;
222 }
223 }
224
225 surround_index = surround_flag2 (layout, i, j, RP);
226
227 switch (surround_index)
228 {
229 case 0:
230 strcat (wall_name, "_0");
231 break;
232 case 1:
233 strcat (wall_name, "_1_3");
234 break;
235 case 2:
236 strcat (wall_name, "_1_4");
237 break;
238 case 3:
239 strcat (wall_name, "_2_1_2");
240 break;
241 case 4:
242 strcat (wall_name, "_1_2");
243 break;
244 case 5:
245 strcat (wall_name, "_2_2_4");
246 break;
247 case 6:
248 strcat (wall_name, "_2_2_1");
249 break;
250 case 7:
251 strcat (wall_name, "_3_1");
252 break;
253 case 8:
254 strcat (wall_name, "_1_1");
255 break;
256 case 9:
257 strcat (wall_name, "_2_2_3");
258 break;
259 case 10:
260 strcat (wall_name, "_2_2_2");
261 break;
262 case 11:
263 strcat (wall_name, "_3_3");
264 break;
265 case 12:
266 strcat (wall_name, "_2_1_1");
267 break;
268 case 13:
269 strcat (wall_name, "_3_4");
270 break;
271 case 14:
272 strcat (wall_name, "_3_2");
273 break;
274 case 15:
275 strcat (wall_name, "_4");
276 break;
277 }
278 wall_arch = archetype::find (wall_name);
279
280 return wall_arch ? arch_to_object (wall_arch) : arch_to_object (the_wall->arch);
281}
282
283 277
284/* 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
285 * 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
286 * 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
287 * 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
288 * remove anything. It depends on the 282 * remove anything. It depends on the
289 * global, previously-set variable, "wall_name" 283 * global, previously-set variable, "wall_name"
290 */ 284 */
291
292object * 285object *
293retrofit_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)
294{ 287{
295 /* 1 = wall to left, 288 /* 1 = wall to left,
296 * 2 = wall to right, 289 * 2 = wall to right,
397 new_wall = arch_to_object (wall_arch); 390 new_wall = arch_to_object (wall_arch);
398 new_wall->x = i; 391 new_wall->x = i;
399 new_wall->y = j; 392 new_wall->y = j;
400 393
401 if (the_wall && the_wall->map) 394 if (the_wall && the_wall->map)
402 {
403 the_wall->remove ();
404 the_wall->destroy (); 395 the_wall->destroy ();
405 }
406 396
407 the_wall->move_block = MOVE_ALL; 397 the_wall->move_block = MOVE_ALL;
408 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);
409 } 399 }
410 400

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines