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

Comparing deliantra/server/server/build_map.C (file contents):
Revision 1.3 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.28 by root, Sun Jul 1 05:00:19 2007 UTC

1/* 1/*
2 * static char *rcsid_build_map = 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * "$Id: build_map.C,v 1.3 2006/09/03 00:18:42 root Exp $"; 3 *
4 */ 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5/*
6 CrossFire, A Multiplayer game for X-windows
7
8 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
9 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
10 7 *
11 This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version. 11 * (at your option) any later version.
15 12 *
16 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,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 16 * GNU General Public License for more details.
20 17 *
21 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
24
25 The authors can be reached via e-mail to crossfire-devel@real-time.com 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
26*/ 22 */
27 23
28#include <global.h> 24#include <global.h>
29#include <living.h> 25#include <living.h>
30#include <spells.h> 26#include <spells.h>
31#include <skills.h> 27#include <skills.h>
33#include <sproto.h> 29#include <sproto.h>
34 30
35/** 31/**
36 * Check if objects on a square interfere with building 32 * Check if objects on a square interfere with building
37 */ 33 */
34int
38int can_build_over( mapstruct* map, object* tmp, short x, short y) 35can_build_over (maptile *map, object *tmp, short x, short y)
39 { 36{
40 object* ob; 37 object *ob;
41 38
42 ob = GET_MAP_OB( map, x, y ); 39 ob = GET_MAP_OB (map, x, y);
43 while ( ob ) 40 while (ob)
44 { 41 {
45 /* if ob is not a marking rune or floor, then check special cases */ 42 /* if ob is not a marking rune or floor, then check special cases */
46 if ( strcmp( ob->arch->name, "rune_mark" ) && ob->type != FLOOR ) 43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR)
44 {
45 switch (tmp->type)
47 { 46 {
48 switch ( tmp->type )
49 {
50 case SIGN: 47 case SIGN:
51 case MAGIC_EAR: 48 case MAGIC_EAR:
52 /* Allow signs and magic ears to be built on books */ 49 /* Allow signs and magic ears to be built on books */
53 if ( ob->type != BOOK ) { 50 if (ob->type != BOOK)
51 {
54 return 0; } 52 return 0;
53 }
55 break; 54 break;
56 case BUTTON: 55 case BUTTON:
57 case DETECTOR: 56 case DETECTOR:
58 case PEDESTAL: 57 case PEDESTAL:
59 case CF_HANDLE: 58 case CF_HANDLE:
60 /* Allow buttons and levers to be built under gates */ 59 /* Allow buttons and levers to be built under gates */
61 if ( ob->type != GATE && ob->type != DOOR ) { 60 if (ob->type != GATE && ob->type != DOOR)
61 {
62 return 0; } 62 return 0;
63 }
63 break; 64 break;
64 default: 65 default:
65 return 0; 66 return 0;
66 }
67 } 67 }
68 }
68 ob = ob->above; 69 ob = ob->above;
69 } 70 }
70 return 1; 71 return 1;
71 } 72}
72 73
73/** 74/**
74 * Erases marking runes at specified location 75 * Erases marking runes at specified location
75 */ 76 */
77void
76void remove_marking_runes( mapstruct* map, short x, short y ) 78remove_marking_runes (maptile *map, short x, short y)
77 { 79{
78 object* rune; 80 object *rune;
79 object* next; 81 object *next;
80 82
81 rune = GET_MAP_OB( map, x, y ); 83 rune = GET_MAP_OB (map, x, y);
82 while ( rune ) 84 while (rune)
83 { 85 {
84 next = rune->above; 86 next = rune->above;
87
85 if ( ( rune->type == SIGN ) && ( !strcmp( rune->arch->name, "rune_mark" ) ) ) 88 if ((rune->type == SIGN) && (!strcmp (rune->arch->archname, "rune_mark")))
86 { 89 rune->destroy ();
87 remove_ob( rune ); 90
88 free_object( rune );
89 }
90 rune = next; 91 rune = next;
91 }
92 } 92 }
93}
93 94
94/** 95/**
95 * Returns an unused value for 'connected'. 96 * Returns an unused value for 'connected'.
96 * \param map: map for which to find a value 97 * \param map: map for which to find a value
97 * \return 'connected' value with no item, or -1 if failure. 98 * \return 'connected' value with no item, or -1 if failure.
98 * 99 *
99 * Tries 1000 random values, then returns -1. 100 * Tries 1000 random values, then returns -1.
100 */ 101 */
102int
101int find_unused_connected_value( mapstruct* map ) 103find_unused_connected_value (maptile *map)
102 { 104{
103 int connected = 0; 105 int connected = 0;
104 int itest = 0; 106 int itest = 0;
105 oblinkpt* obp; 107 oblinkpt *obp;
106 108
107 while ( itest++ < 1000 ) 109 while (itest++ < 1000)
108 { 110 {
109 connected = 1 + rand( ) % 20000; 111 connected = 1 + rand () % 20000;
110 for ( obp = map->buttons; obp && ( obp->value != connected ); obp = obp->next ); 112 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next);
111 113
112 if ( !obp ) 114 if (!obp)
113 return connected; 115 return connected;
114 } 116 }
115 117
116 return -1; 118 return -1;
117 } 119}
118 120
119 121
120/** 122/**
121 * Helper function for door/button/connected item building. 123 * Helper function for door/button/connected item building.
122 * 124 *
125 * Else, searches a force in op's inventory matching the map's name 127 * Else, searches a force in op's inventory matching the map's name
126 * and the rune's text. 128 * and the rune's text.
127 * If found, returns the connection value associated 129 * If found, returns the connection value associated
128 * else searches a new connection value, and adds the force to the player. 130 * else searches a new connection value, and adds the force to the player.
129 */ 131 */
132int
130int find_or_create_connection_for_map( object* pl, short x, short y, object* rune ) 133find_or_create_connection_for_map (object *pl, short x, short y, object *rune)
131 { 134{
132 object* force; 135 object *force;
133 int connected; 136 int connected;
134 137
135 if ( !rune ) 138 if (!rune)
136 rune = get_connection_rune( pl, x, y ); 139 rune = get_connection_rune (pl, x, y);
137 140
138 if ( !rune ) 141 if (!rune)
139 { 142 {
140 new_draw_info( NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name." ); 143 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
141 return -1; 144 return -1;
142 } 145 }
143 146
144 /* Now, find force in player's inventory */ 147 /* Now, find force in player's inventory */
145 force = pl->inv; 148 force = pl->inv;
146 while ( force && ( ( force->type != FORCE ) || ( !force->slaying ) || ( strcmp( force->slaying, pl->map->path ) ) || ( !force->msg ) || ( strcmp( force->msg, rune->msg ) ) ) ) 149 while (force
150 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
151 || force->msg != rune->msg))
147 force = force->below; 152 force = force->below;
148 153
149 if ( !force ) 154 if (!force)
150 /* No force, need to create & insert one */ 155 /* No force, need to create & insert one */
151 { 156 {
152 /* Find unused value */ 157 /* Find unused value */
153 connected = find_unused_connected_value( pl->map ); 158 connected = find_unused_connected_value (pl->map);
154 if ( connected == -1 ) 159 if (connected == -1)
155 { 160 {
156 new_draw_info( NDI_UNIQUE, 0, pl, "Could not create more groups." ); 161 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
157 return -1; 162 return -1;
158 } 163 }
159 164
160 force = get_archetype( FORCE_NAME ); 165 force = get_archetype (FORCE_NAME);
161 force->speed = 0;
162 update_ob_speed( force );
163 force->slaying = pl->map->path; 166 force->slaying = pl->map->path;
164 force->msg = rune->msg; 167 force->msg = rune->msg;
165 force->path_attuned = connected; 168 force->path_attuned = connected;
169 force->set_speed (0);
166 insert_ob_in_ob( force, pl ); 170 insert_ob_in_ob (force, pl);
167 171
168 return connected; 172 return connected;
169 } 173 }
170 174
171 /* Found the force, everything's easy. */ 175 /* Found the force, everything's easy. */
172 return force->path_attuned; 176 return force->path_attuned;
173 } 177}
174 178
175/** 179/**
176 * Returns the marking rune on the square, for purposes of building connections 180 * Returns the marking rune on the square, for purposes of building connections
177 */ 181 */
182object *
178object* get_connection_rune( object* pl, short x, short y ) 183get_connection_rune (object *pl, short x, short y)
179 { 184{
180 object* rune; 185 object *rune;
181 186
182 rune = GET_MAP_OB( pl->map, x, y ); 187 rune = GET_MAP_OB (pl->map, x, y);
183 while ( rune && ( ( rune->type != SIGN ) || ( strcmp( rune->arch->name, "rune_mark" ) ) ) ) 188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark"))))
184 rune = rune->above; 189 rune = rune->above;
185 return rune; 190 return rune;
186 } 191}
187 192
188/** 193/**
189 * Returns the book/scroll on the current square, for purposes of building 194 * Returns the book/scroll on the current square, for purposes of building
190 */ 195 */
196object *
191object* get_msg_book( object* pl, short x, short y ) 197get_msg_book (object *pl, short x, short y)
192 { 198{
193 object* book; 199 object *book;
194 200
195 book = GET_MAP_OB( pl->map, x, y ); 201 book = GET_MAP_OB (pl->map, x, y);
196 while ( book && ( book->type != BOOK ) ) 202 while (book && (book->type != BOOK))
197 book = book->above; 203 book = book->above;
198 return book; 204 return book;
199 } 205}
200 206
201/** 207/**
202 * Returns first item of type WALL. 208 * Returns first item of type BUILDABLE_WALL.
203 */ 209 */
210object *
204object* get_wall( mapstruct* map, int x, int y ) 211get_wall (maptile *map, int x, int y)
205 { 212{
206 object* wall; 213 object *wall;
207 214
208 wall = GET_MAP_OB( map, x, y ); 215 wall = GET_MAP_OB (map, x, y);
209 while ( wall && ( WALL != wall->type ) ) 216 while (wall && (BUILDABLE_WALL != wall->type))
210 wall = wall->above; 217 wall = wall->above;
211 218
212 return wall; 219 return wall;
213 } 220}
214 221
215/** 222/**
216 * Fixes walls around specified spot 223 * Fixes walls around specified spot
217 * 224 *
218 * \param map is the map 225 * \param map is the map
221 * 228 *
222 * Basically it ensures the correct wall is put where needed. 229 * Basically it ensures the correct wall is put where needed.
223 * 230 *
224 * Note: x & y must be valid map coordinates. 231 * Note: x & y must be valid map coordinates.
225 */ 232 */
233void
226void fix_walls( mapstruct* map, int x, int y ) 234fix_walls (maptile *map, int x, int y)
227 { 235{
228 int connect;
229 object* wall; 236 object *wall;
230 char archetype[ MAX_BUF ]; 237 char archetype[MAX_BUF];
231 char* underscore; 238 char *underscore;
232 uint32 old_flags[ 4 ];
233 struct archt* new_arch; 239 struct archetype *new_arch;
234 int flag;
235 240
241
236 /* First, find the wall on that spot */ 242 /* First, find the wall on that spot */
237 wall = get_wall( map, x, y ); 243 wall = get_wall (map, x, y);
238 if ( !wall ) 244 if (!wall)
239 /* Nothing -> bail out */ 245 /* Nothing -> bail out */
240 return; 246 return;
241 247
242 /* Find base name */ 248 /* Find base name */
243 strcpy( archetype, wall->arch->name ); 249 assign (archetype, wall->arch->archname);
244 underscore = strchr( archetype, '_' ); 250 underscore = strchr (archetype, '_');
251
252 /* search for the first _ before a number */
253 while (underscore && !isdigit (*(underscore + 1)))
254 underscore = strchr (underscore + 1, '_');
255
245 if ( !underscore || ( !isdigit( *( underscore + 1 ) ) ) ) 256 if (!underscore || !isdigit (*(underscore + 1)))
246 /* Not in a format we can change, bail out */ 257 /* Not in a format we can change, bail out */
247 return; 258 return;
248 259
249 underscore++; 260 underscore++;
250 *underscore = '\0'; 261 *underscore = '\0';
251 262
263 int connect = 0;
264
265 if ((x > 0) && get_wall (map, x - 1, y))
252 connect = 0; 266 connect |= 1;
253 267 if ((x < map->width - 1) && get_wall (map, x + 1, y))
254 if ( ( x > 0 ) && get_wall( map, x - 1, y ) )
255 connect |= 1;
256 if ( ( x < MAP_WIDTH( map ) - 1 ) && get_wall( map, x + 1, y ) )
257 connect |= 2; 268 connect |= 2;
258 269
259 if ( ( y > 0 ) && get_wall( map, x, y - 1 ) ) 270 if ((y > 0) && get_wall (map, x, y - 1))
260 connect |= 4; 271 connect |= 4;
261 272
262 if ( ( y < MAP_HEIGHT( map ) - 1 ) && get_wall( map, x, y + 1 ) ) 273 if ((y < map->height - 1) && get_wall (map, x, y + 1))
263 connect |= 8; 274 connect |= 8;
264 275
265 switch( connect ) 276 switch (connect)
266 { 277 {
267 case 0: 278 case 0:
268 strcat( archetype, "0"); 279 strcat (archetype, "0");
280
269 break; 281 break;
270 case 1: 282 case 1:
271 strcat( archetype, "1_3"); 283 strcat (archetype, "1_3");
284
272 break; 285 break;
273 case 2: 286 case 2:
274 strcat( archetype, "1_4"); 287 strcat (archetype, "1_4");
288
275 break; 289 break;
276 case 3: 290 case 3:
277 strcat( archetype, "2_1_2"); 291 strcat (archetype, "2_1_2");
292
278 break; 293 break;
279 case 4: 294 case 4:
280 strcat( archetype, "1_2"); 295 strcat (archetype, "1_2");
296
281 break; 297 break;
282 case 5: 298 case 5:
283 strcat( archetype, "2_2_4"); 299 strcat (archetype, "2_2_4");
300
284 break; 301 break;
285 case 6: 302 case 6:
286 strcat( archetype, "2_2_1"); 303 strcat (archetype, "2_2_1");
304
287 break; 305 break;
288 case 7: 306 case 7:
289 strcat( archetype, "3_1"); 307 strcat (archetype, "3_1");
308
290 break; 309 break;
291 case 8: 310 case 8:
292 strcat( archetype, "1_1"); 311 strcat (archetype, "1_1");
312
293 break; 313 break;
294 case 9: 314 case 9:
295 strcat( archetype, "2_2_3"); 315 strcat (archetype, "2_2_3");
316
296 break; 317 break;
297 case 10: 318 case 10:
298 strcat( archetype, "2_2_2"); 319 strcat (archetype, "2_2_2");
320
299 break; 321 break;
300 case 11: 322 case 11:
301 strcat( archetype, "3_3"); 323 strcat (archetype, "3_3");
324
302 break; 325 break;
303 case 12: 326 case 12:
304 strcat( archetype, "2_1_1"); 327 strcat (archetype, "2_1_1");
328
305 break; 329 break;
306 case 13: 330 case 13:
307 strcat( archetype, "3_4"); 331 strcat (archetype, "3_4");
332
308 break; 333 break;
309 case 14: 334 case 14:
310 strcat( archetype, "3_2"); 335 strcat (archetype, "3_2");
336
311 break; 337 break;
312 case 15: 338 case 15:
313 strcat( archetype, "4"); 339 strcat (archetype, "4");
340
314 break; 341 break;
315 } 342 }
316 343
317 /* 344 /*
318 * Before anything, make sure the archetype does exist... 345 * Before anything, make sure the archetype does exist...
319 * If not, prolly an error... 346 * If not, prolly an error...
320 */ 347 */
321 new_arch = find_archetype( archetype ); 348 new_arch = archetype::find (archetype);
349
322 if ( !new_arch ) 350 if (!new_arch)
323 return; 351 return;
324 352
325 /* Now delete current wall, and insert new one 353 /* Now delete current wall, and insert new one
326 * We save flags to avoid any trouble with buildable/non buildable, and so on 354 * We save flags to avoid any trouble with buildable/non buildable, and so on
327 */ 355 */
328 for ( flag = 0; flag < 4; flag++ ) 356 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
329 old_flags[ flag ] = wall->flags[ flag ];
330 remove_ob( wall );
331 free_object( wall );
332 357
358 wall->destroy ();
359
333 wall = arch_to_object( new_arch ); 360 wall = arch_to_object (new_arch);
334 wall->type = WALL; 361 wall->type = BUILDABLE_WALL;
335 insert_ob_in_map_at( wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y ); 362 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
336 for ( flag = 0; flag < 4; flag++ ) 363 wall->flag = old_flags;
337 wall->flags[ flag ] = old_flags[ flag ]; 364}
338 }
339 365
340/** 366/**
341 * \brief Floor building function 367 * \brief Floor building function
342 * 368 *
343 * Floors can be build: 369 * Floors can be build:
345 * - on an existing wall, with or without a floor under it 371 * - on an existing wall, with or without a floor under it
346 * 372 *
347 * Note: this function will inconditionally change squares around (x, y) 373 * Note: this function will inconditionally change squares around (x, y)
348 * so don't call it with x == 0 for instance! 374 * so don't call it with x == 0 for instance!
349 */ 375 */
376void
350void apply_builder_floor(object* pl, object* material, short x, short y ) 377apply_builder_floor (object *pl, object *material, short x, short y)
351 { 378{
352 object* tmp, *above; 379 object *tmp, *above;
353 object* above_floor; /* Item above floor, if any */ 380 object *above_floor; /* Item above floor, if any */
354 struct archt* new_floor; 381 struct archetype *new_floor;
355 struct archt* new_wall; 382 struct archetype *new_wall;
356 int i, xt, yt, floor_removed; 383 int i, xt, yt, floor_removed;
357 char message[ MAX_BUF ]; 384 char message[MAX_BUF];
358 385
359 sprintf( message, "You change the floor to better suit your tastes." ); 386 sprintf (message, "You change the floor to better suit your tastes.");
360 387
361 /* 388 /*
362 * Now the building part... 389 * Now the building part...
363 * First, remove wall(s) and floor(s) at position x, y 390 * First, remove wall(s) and floor(s) at position x, y
364 */ 391 */
365 above_floor = NULL; 392 above_floor = NULL;
366 new_wall = NULL; 393 new_wall = NULL;
367 floor_removed = 0; 394 floor_removed = 0;
368 tmp = GET_MAP_OB( pl->map, x, y ); 395 tmp = GET_MAP_OB (pl->map, x, y);
369 if ( tmp ) 396 if (tmp)
370 { 397 {
371 while ( tmp ) 398 while (tmp)
399 {
400 above = tmp->above;
401 if (BUILDABLE_WALL == tmp->type)
372 { 402 {
373 above = tmp->above;
374 if ( WALL == tmp->type )
375 {
376 /* There was a wall, remove it & keep its archetype to make new walls */ 403 /* There was a wall, remove it & keep its archetype to make new walls */
377 new_wall = tmp->arch; 404 new_wall = tmp->arch;
378 remove_ob( tmp ); 405 tmp->destroy ();
379 free_object( tmp );
380 sprintf( message, "You destroy the wall and redo the floor." ); 406 sprintf (message, "You destroy the wall and redo the floor.");
381 }
382 else if ( ( FLOOR == tmp->type ) || ( QUERY_FLAG(tmp, FLAG_IS_FLOOR ) ) )
383 {
384 remove_ob( tmp );
385 free_object( tmp );
386 floor_removed = 1;
387 }
388 else
389 {
390 if ( floor_removed )
391 above_floor = tmp;
392 }
393
394 tmp = above;
395 } 407 }
396 } 408 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
397
398 /* Now insert our floor */
399 new_floor = find_archetype( material->slaying );
400 if ( !new_floor )
401 {
402 /* Not found, log & bail out */
403 LOG( llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying );
404 return;
405 }
406
407 tmp = arch_to_object( new_floor );
408 SET_FLAG( tmp, FLAG_IS_BUILDABLE );
409 SET_FLAG( tmp, FLAG_UNIQUE );
410 SET_FLAG( tmp, FLAG_IS_FLOOR );
411 tmp->type = FLOOR;
412 insert_ob_in_map_at( tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y );
413
414 /*
415 * Next step: make sure there are either walls or floors around the new square
416 * Since building, you can have: blocking view / floor / wall / nothing
417 */
418 for ( i = 1; i <= 8; i++ )
419 {
420 xt = x + freearr_x[ i ];
421 yt = y + freearr_y[ i ];
422 tmp = GET_MAP_OB( pl->map, xt, yt );
423 if ( !tmp )
424 { 409 {
425 /* Must insert floor & wall */ 410 tmp->destroy ();
426 tmp = arch_to_object( new_floor ); 411 floor_removed = 1;
427 /* Better make the floor unique */
428 SET_FLAG( tmp, FLAG_UNIQUE );
429 SET_FLAG( tmp, FLAG_IS_BUILDABLE );
430 tmp->type = FLOOR;
431 insert_ob_in_map_at( tmp, pl->map, 0, 0, xt, yt );
432 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
433 if ( new_wall )
434 {
435 tmp = arch_to_object( new_wall );
436 SET_FLAG( tmp, FLAG_IS_BUILDABLE );
437 tmp->type = WALL;
438 insert_ob_in_map_at( tmp, pl->map, 0, 0, xt, yt );
439 }
440 } 412 }
441 } 413 else
442
443 /* Finally fixing walls to ensure nice continuous walls
444 * Note: 2 squares around are checked, because potentially we added walls around the building
445 * spot, so need to check that those new walls connect correctly
446 */
447 for ( xt = x - 2; xt <= x + 2; xt++ )
448 for ( yt = y - 2; yt <= y + 2; yt++ )
449 { 414 {
450 if ( !OUT_OF_REAL_MAP( pl->map, xt, yt ) ) 415 if (floor_removed)
451 fix_walls( pl->map, xt, yt ); 416 above_floor = tmp;
452 } 417 }
453 418
419 tmp = above;
420 }
421 }
422
423 /* Now insert our floor */
424 new_floor = archetype::find (material->slaying);
425 if (!new_floor)
426 {
427 /* Not found, log & bail out */
428 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
429 return;
430 }
431
432 tmp = arch_to_object (new_floor);
433 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
434 SET_FLAG (tmp, FLAG_UNIQUE);
435 SET_FLAG (tmp, FLAG_IS_FLOOR);
436 tmp->type = FLOOR;
437 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
438
439 /*
440 * Next step: make sure there are either walls or floors around the new square
441 * Since building, you can have: blocking view / floor / wall / nothing
442 */
443 for (i = 1; i <= 8; i++)
444 {
445 xt = x + freearr_x[i];
446 yt = y + freearr_y[i];
447 tmp = GET_MAP_OB (pl->map, xt, yt);
448 if (!tmp)
449 {
450 /* Must insert floor & wall */
451 tmp = arch_to_object (new_floor);
452 /* Better make the floor unique */
453 SET_FLAG (tmp, FLAG_UNIQUE);
454 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
455 tmp->type = FLOOR;
456 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
457 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
458 if (new_wall)
459 {
460 tmp = arch_to_object (new_wall);
461 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
462 tmp->type = BUILDABLE_WALL;
463 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
464 }
465 }
466 }
467
468 /* Finally fixing walls to ensure nice continuous walls
469 * Note: 2 squares around are checked, because potentially we added walls around the building
470 * spot, so need to check that those new walls connect correctly
471 */
472 for (xt = x - 2; xt <= x + 2; xt++)
473 for (yt = y - 2; yt <= y + 2; yt++)
474 {
475 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
476 fix_walls (pl->map, xt, yt);
477 }
478
454 /* Now remove raw item from inventory */ 479 /* Now remove raw item from inventory */
455 decrease_ob( material ); 480 decrease_ob (material);
456 481
457 /* And tell player about the fix */ 482 /* And tell player about the fix */
458 new_draw_info( NDI_UNIQUE, 0, pl, message ); 483 new_draw_info (NDI_UNIQUE, 0, pl, message);
484}
485
486/**
487 * Wall radius fix function
488 */
489void fix_walls_around (maptile *map, int x, int y)
490{
491 for (int xt = x - 1; xt <= x + 1; xt++)
492 for (int yt = y - 1; yt <= y + 1; yt++)
493 {
494 if (OUT_OF_REAL_MAP (map, xt, yt))
495 continue;
496
497 fix_walls (map, xt, yt);
459 } 498 }
499}
460 500
461/** 501/**
462 * Wall building function 502 * Wall building function
463 * 503 *
464 * Walls can be build: 504 * Walls can be build:
465 * - on a floor without anything else 505 * - on a floor without anything else
466 * - on an existing wall, with or without a floor 506 * - on an existing wall, with or without a floor
467 */ 507 */
508void
468void apply_builder_wall( object* pl, object* material, short x, short y ) 509apply_builder_wall (object *pl, object *material, short x, short y)
469 { 510{
470 object* current_wall; 511 object *current_wall;
471 object* tmp; 512 object *tmp;
472 int xt, yt; 513 int xt, yt;
473 struct archt* new_wall; 514 struct archetype *new_wall;
474 char message[ MAX_BUF ]; 515 char message[MAX_BUF];
475 516
476 remove_marking_runes( pl->map, x, y ); 517 remove_marking_runes (pl->map, x, y);
477 518
478 /* Grab existing wall, if any */ 519 /* Grab existing wall, if any */
479 current_wall = NULL; 520 current_wall = NULL;
480 tmp = GET_MAP_OB( pl->map, x, y ); 521 tmp = GET_MAP_OB (pl->map, x, y);
481 while ( tmp && !current_wall ) 522 while (tmp && !current_wall)
482 { 523 {
483 if ( WALL == tmp->type ) 524 if (BUILDABLE_WALL == tmp->type)
484 current_wall = tmp; 525 current_wall = tmp;
485 526
486 tmp = tmp->above; 527 tmp = tmp->above;
487 } 528 }
488 529
489 /* Find the raw wall in inventory */ 530 /* Find the raw wall in inventory */
490 sprintf( message, "You build a wall." ); 531 sprintf (message, "You build a wall.");
491 532
492 /* Now we can actually insert the wall */ 533 /* Now we can actually insert the wall */
493 new_wall = find_archetype( material->slaying ); 534 new_wall = archetype::find (material->slaying);
494 if ( !new_wall ) 535 if (!new_wall)
495 { 536 {
496 LOG( llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying ); 537 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
497 return; 538 return;
498 } 539 }
499 540
500 tmp = arch_to_object( new_wall ); 541 tmp = arch_to_object (new_wall);
501 tmp->type = WALL; 542 tmp->type = BUILDABLE_WALL;
502 SET_FLAG( tmp, FLAG_IS_BUILDABLE ); 543 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
503 insert_ob_in_map_at( tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y ); 544 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
504 545
505 /* If existing wall, remove it, no need to fix other walls */ 546 /* If existing wall, remove it, no need to fix other walls */
506 if ( current_wall ) 547 if (current_wall)
507 { 548 {
508 remove_ob( current_wall ); 549 current_wall->destroy ();
509 free_object( current_wall );
510 fix_walls( pl->map, x, y ); 550 fix_walls (pl->map, x, y);
511 sprintf( message, "You redecorate the wall to better suit your tastes." ); 551 sprintf (message, "You redecorate the wall to better suit your tastes.");
512 } 552 }
513 else 553 else
514 { 554 {
515 /* Else fix all walls around */ 555 /* Else fix all walls around */
516 for ( xt = x - 1; xt <= x + 1; xt++ ) 556 for (xt = x - 1; xt <= x + 1; xt++)
517 for ( yt = y - 1; yt <= y + 1; yt++ ) 557 for (yt = y - 1; yt <= y + 1; yt++)
518 { 558 {
519 if ( OUT_OF_REAL_MAP( pl->map, xt, yt ) ) 559 if (OUT_OF_REAL_MAP (pl->map, xt, yt))
520 continue; 560 continue;
521 561
522 fix_walls( pl->map, xt, yt ); 562 fix_walls (pl->map, xt, yt);
523 }
524 } 563 }
564 }
525 565
526 /* Now remove item from inventory */ 566 /* Now remove item from inventory */
527 decrease_ob( material ); 567 decrease_ob (material);
528 568
529 /* And tell player what happened */ 569 /* And tell player what happened */
530 new_draw_info( NDI_UNIQUE, 0, pl, message ); 570 new_draw_info (NDI_UNIQUE, 0, pl, message);
531 } 571}
532 572
533/** 573/**
534 * Generic item builder. 574 * Generic item builder.
535 * 575 *
536 * Item must be put on a square with a floor, you can have something under. 576 * Item must be put on a square with a floor, you can have something under.
537 * Archetype of created object is item->slaying (raw material). 577 * Archetype of created object is item->slaying (raw material).
538 * Type of inserted item is tested for specific cases (doors & such). 578 * Type of inserted item is tested for specific cases (doors & such).
539 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess) 579 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
540 */ 580 */
581void
541void apply_builder_item( object* pl, object* item, short x, short y ) 582apply_builder_item (object *pl, object *item, short x, short y)
542 { 583{
543 object* tmp; 584 object *tmp;
544 struct archt* arch; 585 struct archetype *arch;
545 int insert_flag; 586 int insert_flag;
546 object* floor; 587 object *floor;
547 object* con_rune; 588 object *con_rune;
548 int connected; 589 int connected;
549 590
550 /* Find floor */ 591 /* Find floor */
551 floor = GET_MAP_OB( pl->map, x, y ); 592 floor = GET_MAP_OB (pl->map, x, y);
552 if ( !floor ) 593 if (!floor)
553 { 594 {
554 new_draw_info( NDI_UNIQUE, 0, pl, "Invalid square." ); 595 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
555 return; 596 return;
556 } 597 }
557 598
558 while ( floor && ( floor->type != FLOOR ) && ( !QUERY_FLAG( floor, FLAG_IS_FLOOR ) ) ) 599 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR)))
559 floor = floor->above; 600 floor = floor->above;
560 601
561 if ( !floor ) 602 if (!floor)
562 { 603 {
563 new_draw_info( NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here." ); 604 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
564 return; 605 return;
565 } 606 }
566 /* Create item, set flag, insert in map */ 607 /* Create item, set flag, insert in map */
567 arch = find_archetype( item->slaying ); 608 arch = archetype::find (item->slaying);
568 if ( !arch ) 609 if (!arch)
569 return; 610 return;
570 611
571 tmp = arch_to_object( arch ); 612 tmp = arch_to_object (arch);
572 613
573 if ( ( floor->above ) && ( !can_build_over(pl->map, tmp, x, y) ) ) 614 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y)))
574 /* Floor has something on top that interferes with building */ 615 /* Floor has something on top that interferes with building */
575 { 616 {
576 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build here." ); 617 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
577 return; 618 return;
578 }
579 619 }
620
580 SET_FLAG( tmp, FLAG_IS_BUILDABLE ); 621 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
581 SET_FLAG( tmp, FLAG_NO_PICK ); 622 SET_FLAG (tmp, FLAG_NO_PICK);
582 623
583 /* 624 /*
584 * This doesn't work on non unique maps. pedestals under floor will not be saved... 625 * This doesn't work on non unique maps. pedestals under floor will not be saved...
585 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 626 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
586 */ 627 */
587 insert_flag = INS_ABOVE_FLOOR_ONLY; 628 insert_flag = INS_ABOVE_FLOOR_ONLY;
588 629
589 connected = 0; 630 connected = 0;
590 switch( tmp->type ) 631 switch (tmp->type)
591 { 632 {
592 case DOOR: 633 case DOOR:
593 case GATE: 634 case GATE:
594 case BUTTON: 635 case BUTTON:
595 case DETECTOR: 636 case DETECTOR:
596 case TIMED_GATE: 637 case TIMED_GATE:
597 case PEDESTAL: 638 case PEDESTAL:
598 case CF_HANDLE: 639 case CF_HANDLE:
599 case MAGIC_EAR: 640 case MAGIC_EAR:
600 case SIGN: 641 case SIGN:
601 /* Signs don't need a connection, but but magic mouths do. */ 642 /* Signs don't need a connection, but but magic mouths do. */
602 if (tmp->type == SIGN && strcmp( tmp->arch->name, "magic_mouth" )) 643 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth"))
603 break; 644 break;
604 con_rune = get_connection_rune( pl, x, y ); 645 con_rune = get_connection_rune (pl, x, y);
605 connected = find_or_create_connection_for_map( pl, x, y, con_rune ); 646 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
606 if ( connected == -1 ) 647 if (connected == -1)
607 {
608 /* Player already informed of failure by the previous function */
609 free_object( tmp );
610 return;
611 }
612 /* Remove marking rune */
613 remove_ob( con_rune );
614 free_object( con_rune );
615 }
616
617 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
618 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
619 {
620 if (adjust_sign_msg( pl, x, y, tmp ) == -1)
621 { 648 {
622 free_object( tmp ); 649 /* Player already informed of failure by the previous function */
650 tmp->destroy ();
623 return; 651 return;
624 } 652 }
653 /* Remove marking rune */
654 con_rune->destroy ();
655 }
656
657 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 {
660 if (adjust_sign_msg (pl, x, y, tmp) == -1)
625 } 661 {
662 tmp->destroy ();
663 return;
664 }
665 }
626 666
627 insert_ob_in_map_at( tmp, pl->map, floor, insert_flag, x, y ); 667 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
628 if ( connected != 0 ) 668 if (connected != 0)
629 add_button_link( tmp, pl->map, connected ); 669 add_button_link (tmp, pl->map, connected);
630 670
631 new_draw_info_format( NDI_UNIQUE, 0, pl, "You build the %s", query_name( tmp ) ); 671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
632 decrease_ob_nr( item, 1 ); 672 decrease_ob_nr (item, 1);
633 } 673}
634 674
635/** 675/**
636 * Item remover. 676 * Item remover.
637 * 677 *
638 * Removes first buildable item, either under or above the floor 678 * Removes first buildable item, either under or above the floor
639 */ 679 */
680void
640void apply_builder_remove( object* pl, int dir ) 681apply_builder_remove (object *pl, int dir)
641 { 682{
642 object* item; 683 object *item;
643 short x, y; 684 short x, y;
644 685
645 x = pl->x + freearr_x[ dir ]; 686 x = pl->x + freearr_x[dir];
646 y = pl->y + freearr_y[ dir ]; 687 y = pl->y + freearr_y[dir];
647 688
648 /* Check square */ 689 /* Check square */
649 item = GET_MAP_OB( pl->map, x, y ); 690 item = GET_MAP_OB (pl->map, x, y);
650 if ( !item ) 691 if (!item)
651 { 692 {
652 /* Should not happen with previous tests, but we never know */ 693 /* Should not happen with previous tests, but we never know */
653 new_draw_info( NDI_UNIQUE, 0, pl, "Invalid square." ); 694 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
654 LOG( llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path ); 695 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
655 return; 696 return;
656 } 697 }
657 698
658 if ( item->type == FLOOR || QUERY_FLAG(item,FLAG_IS_FLOOR) ) 699 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
659 item = item->above; 700 item = item->above;
660 701
661 if ( !item ) 702 if (!item)
662 {
663 new_draw_info( NDI_UNIQUE, 0, pl, "Nothing to remove." ); 703 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
664 return; 704 else if (item->type == BUILDABLE_WALL)
665 }
666
667 /* Now remove object, with special cases (buttons & such) */
668 switch ( item->type )
669 {
670 case WALL:
671 new_draw_info( NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor." ); 705 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
672 return; 706 else if (!item->flag [FLAG_IS_BUILDABLE])
673 707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
674 case DOOR: 708 else
675 case BUTTON: 709 {
676 case GATE:
677 case TIMED_GATE:
678 case DETECTOR:
679 case PEDESTAL:
680 case CF_HANDLE:
681 case MAGIC_EAR:
682 case SIGN:
683 /* Special case: must unconnect */
684 if (QUERY_FLAG(item,FLAG_IS_LINKED))
685 remove_button_link( item );
686
687 /* Fall through */
688
689 default:
690 /* Remove generic item */
691 new_draw_info_format( NDI_UNIQUE, 0, pl, "You remove the %s", query_name( item ) ); 710 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
692 remove_ob( item ); 711 item->destroy ();
693 free_object( item );
694 }
695 } 712 }
713}
696 714
697/** 715/**
698 * Global building function 716 * Global building function
699 * 717 *
700 * This is the general map building function. Called when the player 'fires' a builder 718 * This is the general map building function. Called when the player 'fires' a builder
701 * or remover object. 719 * or remover object.
702 */ 720 */
721void
703void apply_map_builder( object* pl, int dir ) 722apply_map_builder (object *pl, int dir)
704 { 723{
705 object* builder; 724 object *builder;
706 object* tmp; 725 object *tmp;
707 object* tmp2; 726 object *tmp2;
708 short x, y; 727 short x, y;
709 728
710 if ( !pl->type == PLAYER ) 729 if (!pl->type == PLAYER)
711 return; 730 return;
712 731
713 /*if ( !player->map->unique ) 732 /*if ( !player->map->unique )
714 { 733 {
715 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." ); 734 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
716 return; 735 return;
717 }*/ 736 } */
718 737
719 if ( dir == 0 ) 738 if (dir == 0)
720 { 739 {
721 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself." ); 740 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
722 return; 741 return;
723 } 742 }
724 743
725 x = pl->x + freearr_x[ dir ]; 744 x = pl->x + freearr_x[dir];
726 y = pl->y + freearr_y[ dir ]; 745 y = pl->y + freearr_y[dir];
727 746
728 if ( ( 1 > x ) || ( 1 > y ) || ( ( MAP_WIDTH( pl->map ) - 2 ) < x ) || ( ( MAP_HEIGHT( pl->map ) - 2 ) < y ) ) 747 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
729 { 748 {
730 new_draw_info( NDI_UNIQUE, 0, pl, "Can't build on map edge..." ); 749 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
731 return; 750 return;
751 }
752
753 /*
754 * Check specified square
755 * The square must have only buildable items
756 * Exception: marking runes are all right,
757 * since they are used for special things like connecting doors / buttons
758 */
759
760 tmp = GET_MAP_OB (pl->map, x, y);
761 if (!tmp)
762 {
763 /* Nothing, meaning player is standing next to an undefined square... */
764 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
765 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
766 return;
767 }
768
769 tmp2 = find_marked_object (pl);
770 while (tmp)
771 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark"))))
732 } 773 {
774 /* The item building function already has it's own special
775 * checks for this
776 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
778 {
779 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
780 return;
781 }
782 }
783 tmp = tmp->above;
784 }
733 785
786 /* Now we know the square is ok */
787 builder = pl->contr->ranged_ob;
788
789 if (builder->subtype == ST_BD_REMOVE)
790 /* Remover -> call specific function and bail out */
791 {
792 apply_builder_remove (pl, dir);
793 return;
794 }
795
796 if (builder->subtype == ST_BD_BUILD)
734 /* 797 /*
735 * Check specified square 798 * Builder.
736 * The square must have only buildable items 799 * Find marked item to build, call specific function
737 * Exception: marking runes are all right,
738 * since they are used for special things like connecting doors / buttons
739 */ 800 */
740 801 {
741 tmp = GET_MAP_OB( pl->map, x, y );
742 if ( !tmp )
743 {
744 /* Nothing, meaning player is standing next to an undefined square... */
745 LOG( llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, pl->map->path );
746 new_draw_info( NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird." );
747 return;
748 }
749 tmp2 = find_marked_object( pl );
750 while ( tmp )
751 {
752 if ( !QUERY_FLAG( tmp, FLAG_IS_BUILDABLE ) && ( ( tmp->type != SIGN )
753 || ( strcmp( tmp->arch->name, "rune_mark" ) ) ) )
754 {
755 /* The item building function already has it's own special
756 * checks for this
757 */
758 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM ))
759 {
760 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build here." );
761 return;
762 }
763 }
764 tmp = tmp->above;
765 }
766
767 /* Now we know the square is ok */
768 builder = pl->contr->ranges[ range_builder ];
769
770 if ( builder->subtype == ST_BD_REMOVE )
771 /* Remover -> call specific function and bail out */
772 {
773 apply_builder_remove( pl, dir );
774 return;
775 }
776
777 if ( builder->subtype == ST_BD_BUILD )
778 /*
779 * Builder.
780 * Find marked item to build, call specific function
781 */
782 {
783 tmp = tmp2; 802 tmp = tmp2;
784 if ( !tmp ) 803 if (!tmp)
785 { 804 {
786 new_draw_info( NDI_UNIQUE, 0, pl, "You need to mark raw materials to use." ); 805 new_draw_info (NDI_UNIQUE, 0, pl, "You need to mark raw materials to use.");
787 return; 806 return;
788 } 807 }
789 808
790 if ( tmp->type != MATERIAL ) 809 if (tmp->type != MATERIAL)
791 { 810 {
792 new_draw_info( NDI_UNIQUE, 0, pl, "You can't use the marked item to build." ); 811 new_draw_info (NDI_UNIQUE, 0, pl, "You can't use the marked item to build.");
793 return; 812 return;
794 } 813 }
795 814
796 switch( tmp->subtype ) 815 switch (tmp->subtype)
797 { 816 {
798 case ST_MAT_FLOOR: 817 case ST_MAT_FLOOR:
799 apply_builder_floor( pl, tmp, x, y ); 818 apply_builder_floor (pl, tmp, x, y);
800 return; 819 return;
801 820
802 case ST_MAT_WALL: 821 case ST_MAT_WALL:
803 apply_builder_wall( pl, tmp, x, y ); 822 apply_builder_wall (pl, tmp, x, y);
804 return; 823 return;
805 824
806 case ST_MAT_ITEM: 825 case ST_MAT_ITEM:
807 apply_builder_item( pl, tmp, x, y ); 826 apply_builder_item (pl, tmp, x, y);
808 return; 827 return;
809 828
810 default: 829 default:
811 new_draw_info( NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry." ); 830 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
812 LOG( llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype ); 831 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
813 return; 832 return;
814 } 833 }
815 } 834 }
816 835
817 /* Here, it means the builder has an invalid type */ 836 /* Here, it means the builder has an invalid type */
818 new_draw_info( NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry." ); 837 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
819 LOG( llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype ); 838 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
820 } 839}
821 840
822/** 841/**
823 * Make the built object inherit the msg of books that are used with it. 842 * Make the built object inherit the msg of books that are used with it.
824 * For objects already invisible (i.e. magic mouths & ears), also make it 843 * For objects already invisible (i.e. magic mouths & ears), also make it
825 * it inherit the face and the name with "talking " prepended. 844 * it inherit the face and the name with "talking " prepended.
826 */ 845 */
846int
827int adjust_sign_msg( object* pl, short x, short y, object* tmp ) 847adjust_sign_msg (object *pl, short x, short y, object *tmp)
828 { 848{
829 object* book; 849 object *book;
830 char buf[MAX_BUF]; 850 char buf[MAX_BUF];
831 char buf2[MAX_BUF]; 851 char buf2[MAX_BUF];
832 852
833 book = get_msg_book( pl, x, y ); 853 book = get_msg_book (pl, x, y);
834 if ( !book ) 854 if (!book)
835 { 855 {
836 new_draw_info( NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message." ); 856 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
837 return -1; 857 return -1;
838 } 858 }
839 859
840 tmp->msg = book->msg; 860 tmp->msg = book->msg;
841 861
842 if (tmp->invisible) 862 if (tmp->invisible)
843 { 863 {
844 if(book->custom_name != NULL) 864 if (book->custom_name != NULL)
845 { 865 {
846 snprintf(buf, sizeof(buf), "talking %s", &book->custom_name); 866 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
847 } else { 867 }
868 else
869 {
848 snprintf(buf, sizeof(buf), "talking %s", &book->name); 870 snprintf (buf, sizeof (buf), "talking %s", &book->name);
849 } 871 }
850 tmp->name = buf; 872 tmp->name = buf;
851 873
852 if (book->name_pl != NULL) 874 if (book->name_pl != NULL)
853 { 875 {
854 snprintf(buf2, sizeof(buf2), "talking %s", &book->name_pl); 876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
855 tmp->name_pl = buf2; 877 tmp->name_pl = buf2;
856 }
857 878 }
879
858 tmp->face = book->face; 880 tmp->face = book->face;
859 tmp->invisible = 0; 881 tmp->invisible = 0;
860 } 882 }
861 remove_ob( book ); 883
862 free_object( book ); 884 book->destroy ();
863 return 0; 885 return 0;
864 } 886}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines