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.40 by root, Mon Oct 12 14:00:59 2009 UTC vs.
Revision 1.60 by root, Wed Apr 14 21:36:32 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 (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 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.
27#include <spells.h> 27#include <spells.h>
28#include <skills.h> 28#include <skills.h>
29#include <tod.h> 29#include <tod.h>
30#include <sproto.h> 30#include <sproto.h>
31 31
32// macro for this check, it had been inconsistent in this file.
33#define IS_FLOOR(x) x->flag [FLAG_IS_FLOOR]
34
32/** 35/**
33 * Check if objects on a square interfere with building 36 * Check if objects on a square interfere with building
34 */ 37 */
35int 38static int
36can_build_over (maptile *map, object *tmp, short x, short y) 39can_build_over (maptile *map, object *tmp, int x, int y)
37{ 40{
38 object *ob; 41 object *ob;
39 42
40 ob = GET_MAP_OB (map, x, y); 43 ob = GET_MAP_OB (map, x, y);
41 while (ob) 44 while (ob)
42 { 45 {
43 /* if ob is not a marking rune or floor, then check special cases */ 46 /* if ob is not a marking rune or floor, then check special cases */
44 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR) 47 if (ob->arch->archname != shstr_rune_mark && !IS_FLOOR (ob))
45 { 48 {
46 switch (tmp->type) 49 switch (tmp->type)
47 { 50 {
48 case SIGN: 51 case SIGN:
49 case MAGIC_EAR: 52 case MAGIC_EAR:
52 return 0; 55 return 0;
53 break; 56 break;
54 case BUTTON: 57 case BUTTON:
55 case DETECTOR: 58 case DETECTOR:
56 case PEDESTAL: 59 case PEDESTAL:
57 case CF_HANDLE: 60 case T_HANDLE:
58 /* Allow buttons and levers to be built under gates */ 61 /* Allow buttons and levers to be built under gates */
59 if (ob->type != GATE && ob->type != DOOR) 62 if (ob->type != GATE && ob->type != DOOR)
60 return 0; 63 return 0;
61 break; 64 break;
62 default: 65 default:
64 } 67 }
65 } 68 }
66 69
67 ob = ob->above; 70 ob = ob->above;
68 } 71 }
72
69 return 1; 73 return 1;
70} 74}
71 75
72/** 76/**
73 * Erases marking runes at specified location 77 * Erases marking runes at specified location
74 */ 78 */
75void 79static void
76remove_marking_runes (maptile *map, short x, short y) 80remove_marking_runes (maptile *map, int x, int y)
77{ 81{
78 object *rune; 82 object *rune;
79 object *next; 83 object *next;
80 84
81 rune = GET_MAP_OB (map, x, y); 85 rune = GET_MAP_OB (map, x, y);
111 if (!map->find_link (id)) 115 if (!map->find_link (id))
112 return id; 116 return id;
113 } 117 }
114 118
115 return shstr_tmp (); 119 return shstr_tmp ();
120}
121
122/**
123 * Returns the marking rune on the square, for purposes of building connections
124 */
125static object *
126get_connection_rune (object *pl, int x, int y)
127{
128 object *rune = GET_MAP_OB (pl->map, x, y);
129
130 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
131 rune = rune->above;
132
133 return rune;
116} 134}
117 135
118/** 136/**
119 * Helper function for door/button/connected item building. 137 * Helper function for door/button/connected item building.
120 * 138 *
124 * and the rune's text. 142 * and the rune's text.
125 * If found, returns the connection value associated 143 * If found, returns the connection value associated
126 * else searches a new connection value, and adds the force to the player. 144 * else searches a new connection value, and adds the force to the player.
127 */ 145 */
128static shstr_tmp 146static shstr_tmp
129find_or_create_connection_for_map (object *pl, short x, short y, object *rune) 147find_or_create_connection_for_map (object *pl, int x, int y, object *rune)
130{ 148{
131 object *force; 149 object *force;
132 150
133 if (!rune) 151 if (!rune)
134 rune = get_connection_rune (pl, x, y); 152 rune = get_connection_rune (pl, x, y);
172 /* Found the force, everything's easy. */ 190 /* Found the force, everything's easy. */
173 return force->race; 191 return force->race;
174} 192}
175 193
176/** 194/**
177 * Returns the marking rune on the square, for purposes of building connections
178 */
179object *
180get_connection_rune (object *pl, short x, short y)
181{
182 object *rune = GET_MAP_OB (pl->map, x, y);
183
184 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
185 rune = rune->above;
186
187 return rune;
188}
189
190/**
191 * Returns the book/scroll on the current square, for purposes of building 195 * Returns the book/scroll on the current square, for purposes of building
192 */ 196 */
193object * 197static object *
194get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, int x, int y)
195{ 199{
196 object *book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
197 201
198 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
199 book = book->above; 203 book = book->above;
200 204
201 return book; 205 return book;
202} 206}
203 207
204/** 208/**
209 * Make the built object inherit the msg of books that are used with it.
210 * For objects already invisible (i.e. magic mouths & ears), also make it
211 * it inherit the face and the name with "talking " prepended.
212 */
213static int
214adjust_sign_msg (object *pl, int x, int y, object *tmp)
215{
216 object *book;
217 char buf[MAX_BUF];
218 char buf2[MAX_BUF];
219
220 book = get_msg_book (pl, x, y);
221 if (!book)
222 {
223 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
224 return -1;
225 }
226
227 tmp->msg = book->msg;
228
229 if (tmp->invisible)
230 {
231 if (book->custom_name)
232 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
233 else
234 snprintf (buf, sizeof (buf), "talking %s", &book->name);
235
236 tmp->name = buf;
237
238 if (book->name_pl)
239 {
240 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
241 tmp->name_pl = buf2;
242 }
243
244 tmp->face = book->face;
245 tmp->invisible = 0;
246 }
247
248 book->destroy ();
249 return 0;
250}
251
252/**
205 * Returns first item of type BUILDABLE_WALL. 253 * Returns first item of type BUILDABLE_WALL.
206 */ 254 */
207object * 255static object *
208get_wall (maptile *map, int x, int y) 256get_wall (maptile *map, int x, int y)
209{ 257{
210 object *wall = GET_MAP_OB (map, x, y); 258 object *wall = GET_MAP_OB (map, x, y);
211 259
212 while (wall && (BUILDABLE_WALL != wall->type)) 260 while (wall && (BUILDABLE_WALL != wall->type))
224 * 272 *
225 * Basically it ensures the correct wall is put where needed. 273 * Basically it ensures the correct wall is put where needed.
226 * 274 *
227 * Note: x & y must be valid map coordinates. 275 * Note: x & y must be valid map coordinates.
228 */ 276 */
229void 277static void
230fix_walls (maptile *map, int x, int y) 278fix_walls (maptile *map, int x, int y)
231{ 279{
232 char archetype[MAX_BUF]; 280 char archetype[MAX_BUF];
233 char *underscore; 281 char *underscore;
234 struct archetype *new_arch; 282 struct archetype *new_arch;
254 underscore++; 302 underscore++;
255 *underscore = '\0'; 303 *underscore = '\0';
256 304
257 int connect = 0; 305 int connect = 0;
258 306
259 if ((x > 0) && get_wall (map, x - 1, y)) 307 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
260 connect |= 1;
261 if ((x < map->width - 1) && get_wall (map, x + 1, y)) 308 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
262 connect |= 2; 309 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
263
264 if ((y > 0) && get_wall (map, x, y - 1))
265 connect |= 4;
266
267 if ((y < map->height - 1) && get_wall (map, x, y + 1)) 310 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
268 connect |= 8;
269 311
270 switch (connect) 312 // one bit per dir, 1 left, 2 right, 4 up, 8 down
271 { 313 static const char *walltype[16] = {
272 case 0: 314 "0",
273 strcat (archetype, "0"); 315 "1_3",
316 "1_4",
317 "2_1_2",
318 "1_2",
319 "2_2_4",
320 "2_2_1",
321 "3_1",
322 "1_1",
323 "2_2_3",
324 "2_2_2",
325 "3_3",
326 "2_1_1",
327 "3_4",
328 "3_2",
329 "4"
330 };
274 331
275 break; 332 strcat (archetype, walltype [connect]);
276 case 1:
277 strcat (archetype, "1_3");
278
279 break;
280 case 2:
281 strcat (archetype, "1_4");
282
283 break;
284 case 3:
285 strcat (archetype, "2_1_2");
286
287 break;
288 case 4:
289 strcat (archetype, "1_2");
290
291 break;
292 case 5:
293 strcat (archetype, "2_2_4");
294
295 break;
296 case 6:
297 strcat (archetype, "2_2_1");
298
299 break;
300 case 7:
301 strcat (archetype, "3_1");
302
303 break;
304 case 8:
305 strcat (archetype, "1_1");
306
307 break;
308 case 9:
309 strcat (archetype, "2_2_3");
310
311 break;
312 case 10:
313 strcat (archetype, "2_2_2");
314
315 break;
316 case 11:
317 strcat (archetype, "3_3");
318
319 break;
320 case 12:
321 strcat (archetype, "2_1_1");
322
323 break;
324 case 13:
325 strcat (archetype, "3_4");
326
327 break;
328 case 14:
329 strcat (archetype, "3_2");
330
331 break;
332 case 15:
333 strcat (archetype, "4");
334
335 break;
336 }
337 333
338 /* 334 /*
339 * Before anything, make sure the archetype does exist... 335 * Before anything, make sure the archetype does exist...
340 * If not, prolly an error... 336 * If not, prolly an error...
341 */ 337 */
349 */ 345 */
350 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off 346 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
351 347
352 wall->destroy (); 348 wall->destroy ();
353 349
354 wall = arch_to_object (new_arch); 350 wall = new_arch->instance ();
355 wall->type = BUILDABLE_WALL; 351 wall->type = BUILDABLE_WALL;
356 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 352 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
357 wall->flag = old_flags; 353 wall->flag = old_flags;
358} 354}
359 355
365 * - on an existing wall, with or without a floor under it 361 * - on an existing wall, with or without a floor under it
366 * 362 *
367 * Note: this function will inconditionally change squares around (x, y) 363 * Note: this function will inconditionally change squares around (x, y)
368 * so don't call it with x == 0 for instance! 364 * so don't call it with x == 0 for instance!
369 */ 365 */
370void 366static void
371apply_builder_floor (object *pl, object *material, short x, short y) 367apply_builder_floor (object *pl, object *material, int x, int y)
372{ 368{
373 object *tmp, *above; 369 object *tmp, *above;
374 object *above_floor; /* Item above floor, if any */ 370 object *above_floor; /* Item above floor, if any */
375 struct archetype *new_floor; 371 struct archetype *new_floor;
376 struct archetype *new_wall; 372 struct archetype *new_wall;
397 /* There was a wall, remove it & keep its archetype to make new walls */ 393 /* There was a wall, remove it & keep its archetype to make new walls */
398 new_wall = tmp->arch; 394 new_wall = tmp->arch;
399 tmp->destroy (); 395 tmp->destroy ();
400 sprintf (message, "You destroy the wall and redo the floor."); 396 sprintf (message, "You destroy the wall and redo the floor.");
401 } 397 }
402 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 398 else if (IS_FLOOR (tmp))
403 { 399 {
404 tmp->destroy (); 400 tmp->destroy ();
405 floor_removed = 1; 401 floor_removed = 1;
406 } 402 }
407 else 403 else
425 /* Not found, log & bail out */ 421 /* Not found, log & bail out */
426 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying); 422 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
427 return; 423 return;
428 } 424 }
429 425
430 tmp = arch_to_object (new_floor); 426 tmp = new_floor->instance ();
431 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 427 tmp->set_flag (FLAG_IS_BUILDABLE);
432 SET_FLAG (tmp, FLAG_UNIQUE); 428 tmp->set_flag (FLAG_UNIQUE);
433 SET_FLAG (tmp, FLAG_IS_FLOOR); 429 tmp->set_flag (FLAG_IS_FLOOR);
434 tmp->type = FLOOR; 430 //tmp->type = FLOOR;
435 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y); 431 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
436 432
437 /* 433 /*
438 * Next step: make sure there are either walls or floors around the new square 434 * Next step: make sure there are either walls or floors around the new square
439 * Since building, you can have: blocking view / floor / wall / nothing 435 * Since building, you can have: blocking view / floor / wall / nothing
444 yt = y + freearr_y[i]; 440 yt = y + freearr_y[i];
445 tmp = GET_MAP_OB (pl->map, xt, yt); 441 tmp = GET_MAP_OB (pl->map, xt, yt);
446 if (!tmp) 442 if (!tmp)
447 { 443 {
448 /* Must insert floor & wall */ 444 /* Must insert floor & wall */
449 tmp = arch_to_object (new_floor); 445 tmp = new_floor->instance ();
450 /* Better make the floor unique */ 446 /* Better make the floor unique */
451 SET_FLAG (tmp, FLAG_UNIQUE); 447 tmp->set_flag (FLAG_UNIQUE);
452 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 448 tmp->set_flag (FLAG_IS_BUILDABLE);
453 tmp->type = FLOOR; 449 //tmp->type = FLOOR;
454 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 450 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
455 /* Insert wall if exists. Note: if it doesn't, the map is weird... */ 451 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
456 if (new_wall) 452 if (new_wall)
457 { 453 {
458 tmp = arch_to_object (new_wall); 454 tmp = new_wall->instance ();
459 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 455 tmp->set_flag (FLAG_IS_BUILDABLE);
460 tmp->type = BUILDABLE_WALL; 456 tmp->type = BUILDABLE_WALL;
461 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 457 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
462 } 458 }
463 } 459 }
464 } 460 }
467 * Note: 2 squares around are checked, because potentially we added walls around the building 463 * Note: 2 squares around are checked, because potentially we added walls around the building
468 * spot, so need to check that those new walls connect correctly 464 * spot, so need to check that those new walls connect correctly
469 */ 465 */
470 for (xt = x - 2; xt <= x + 2; xt++) 466 for (xt = x - 2; xt <= x + 2; xt++)
471 for (yt = y - 2; yt <= y + 2; yt++) 467 for (yt = y - 2; yt <= y + 2; yt++)
472 {
473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 468 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
474 fix_walls (pl->map, xt, yt); 469 fix_walls (pl->map, xt, yt);
475 }
476 470
477 /* Now remove raw item from inventory */ 471 /* Now remove raw item from inventory */
478 material->decrease (); 472 material->decrease ();
479 473
480 /* And tell player about the fix */ 474 /* And tell player about the fix */
481 new_draw_info (NDI_UNIQUE, 0, pl, message); 475 new_draw_info (NDI_UNIQUE, 0, pl, message);
482}
483
484/**
485 * Wall radius fix function
486 */
487void fix_walls_around (maptile *map, int x, int y)
488{
489 for (int xt = x - 1; xt <= x + 1; xt++)
490 for (int yt = y - 1; yt <= y + 1; yt++)
491 {
492 if (OUT_OF_REAL_MAP (map, xt, yt))
493 continue;
494
495 fix_walls (map, xt, yt);
496 }
497} 476}
498 477
499/** 478/**
500 * Wall building function 479 * Wall building function
501 * 480 *
502 * Walls can be build: 481 * Walls can be build:
503 * - on a floor without anything else 482 * - on a floor without anything else
504 * - on an existing wall, with or without a floor 483 * - on an existing wall, with or without a floor
505 */ 484 */
506void 485static void
507apply_builder_wall (object *pl, object *material, short x, short y) 486apply_builder_wall (object *pl, object *material, int x, int y)
508{ 487{
509 object *current_wall; 488 object *current_wall;
510 object *tmp; 489 object *tmp;
511 int xt, yt; 490 int xt, yt;
512 struct archetype *new_wall; 491 struct archetype *new_wall;
534 { 513 {
535 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); 514 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
536 return; 515 return;
537 } 516 }
538 517
539 tmp = arch_to_object (new_wall); 518 tmp = new_wall->instance ();
540 tmp->type = BUILDABLE_WALL; 519 tmp->type = BUILDABLE_WALL;
541 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 520 tmp->set_flag (FLAG_IS_BUILDABLE);
542 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 521 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
543 522
544 /* If existing wall, remove it, no need to fix other walls */ 523 /* If existing wall, remove it, no need to fix other walls */
545 if (current_wall) 524 if (current_wall)
546 { 525 {
574 * Item must be put on a square with a floor, you can have something under. 553 * Item must be put on a square with a floor, you can have something under.
575 * Archetype of created object is item->slaying (raw material). 554 * Archetype of created object is item->slaying (raw material).
576 * Type of inserted item is tested for specific cases (doors & such). 555 * Type of inserted item is tested for specific cases (doors & such).
577 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess) 556 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
578 */ 557 */
579void 558static void
580apply_builder_item (object *pl, object *item, short x, short y) 559apply_builder_item (object *pl, object *item, int x, int y)
581{ 560{
582 object *tmp; 561 object *tmp;
583 struct archetype *arch; 562 struct archetype *arch;
584 int insert_flag; 563 int insert_flag;
585 object *floor; 564 object *floor;
591 { 570 {
592 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 571 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
593 return; 572 return;
594 } 573 }
595 574
596 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) 575 while (floor && !IS_FLOOR (floor))
597 floor = floor->above; 576 floor = floor->above;
598 577
599 if (!floor) 578 if (!floor)
600 { 579 {
601 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here."); 580 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
604 /* Create item, set flag, insert in map */ 583 /* Create item, set flag, insert in map */
605 arch = archetype::find (item->slaying); 584 arch = archetype::find (item->slaying);
606 if (!arch) 585 if (!arch)
607 return; 586 return;
608 587
609 tmp = arch_to_object (arch); 588 tmp = arch->instance ();
610 589
611 if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y))) 590 if (!floor->flag[FLAG_IS_BUILDABLE] || floor->above && !can_build_over (pl->map, tmp, x, y))
612 /* Floor has something on top that interferes with building */ 591 /* Floor has something on top that interferes with building */
613 { 592 {
614 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 593 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
615 return; 594 return;
616 } 595 }
617 596
618 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 597 tmp->set_flag (FLAG_IS_BUILDABLE);
619 SET_FLAG (tmp, FLAG_NO_PICK); 598 tmp->set_flag (FLAG_NO_PICK);
620 599
621 /* 600 /*
622 * Str 1 is a flag that the item [pedestal] should go below the floor. 601 * Str 1 is a flag that the item [pedestal] should go below the floor.
623 * Items under the floor on non-unique maps will not be saved, 602 * Items under the floor on non-unique maps will not be saved,
624 * so make the item itself unique in this situation. 603 * so make the item itself unique in this situation.
625 */ 604 */
626 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 605 insert_flag = item->stats.Str == 1 ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
627 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) 606 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
628 SET_FLAG (tmp, FLAG_UNIQUE); 607 tmp->set_flag (FLAG_UNIQUE);
629 608
630 shstr_tmp connected; 609 shstr_tmp connected;
631 610
632 switch (tmp->type) 611 switch (tmp->type)
633 { 612 {
635 case GATE: 614 case GATE:
636 case BUTTON: 615 case BUTTON:
637 case DETECTOR: 616 case DETECTOR:
638 case TIMED_GATE: 617 case TIMED_GATE:
639 case PEDESTAL: 618 case PEDESTAL:
640 case CF_HANDLE: 619 case T_HANDLE:
641 case MAGIC_EAR: 620 case MAGIC_EAR:
642 case SIGN: 621 case SIGN:
643 /* Signs don't need a connection, but but magic mouths do. */ 622 /* Signs don't need a connection, but but magic mouths do. */
644 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) 623 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
645 break; 624 break;
657 con_rune->destroy (); 636 con_rune->destroy ();
658 } 637 }
659 638
660 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 639 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
661 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 640 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
662 {
663 if (adjust_sign_msg (pl, x, y, tmp) == -1) 641 if (adjust_sign_msg (pl, x, y, tmp) == -1)
664 { 642 {
665 tmp->destroy (); 643 tmp->destroy ();
666 return; 644 return;
667 } 645 }
668 }
669 646
670 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 647 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
671 if (connected) 648 if (connected)
672 tmp->add_link (pl->map, connected); 649 tmp->add_link (pl->map, connected);
673 650
678/** 655/**
679 * Item remover. 656 * Item remover.
680 * 657 *
681 * Removes first buildable item, either under or above the floor 658 * Removes first buildable item, either under or above the floor
682 */ 659 */
683void 660static void
684apply_builder_remove (object *pl, int dir) 661apply_builder_remove (object *pl, int dir)
685{ 662{
686 object *item; 663 object *item;
687 short x, y; 664 int x, y;
688 665
689 x = pl->x + freearr_x[dir]; 666 x = pl->x + freearr_x[dir];
690 y = pl->y + freearr_y[dir]; 667 y = pl->y + freearr_y[dir];
691 668
692 /* Check square */ 669 /* Check square */
697 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 674 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
698 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path); 675 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
699 return; 676 return;
700 } 677 }
701 678
702 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 679 if (IS_FLOOR (item))
703 item = item->above; 680 item = item->above;
704 681
705 if (!item) 682 if (!item)
706 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 683 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
707 else if (item->type == BUILDABLE_WALL) 684 else if (item->type == BUILDABLE_WALL)
722 * or remover object. 699 * or remover object.
723 */ 700 */
724void 701void
725apply_map_builder (object *pl, int dir) 702apply_map_builder (object *pl, int dir)
726{ 703{
727 object *builder;
728 object *tmp;
729 object *tmp2;
730 short x, y; 704 int x, y;
731 705
732 if (!pl->type == PLAYER) 706 if (!pl->type == PLAYER)
733 return; 707 return;
734 708
735 /*if ( !player->map->unique ) 709 /*if ( !player->map->unique )
758 * The square must have only buildable items 732 * The square must have only buildable items
759 * Exception: marking runes are all right, 733 * Exception: marking runes are all right,
760 * since they are used for special things like connecting doors / buttons 734 * since they are used for special things like connecting doors / buttons
761 */ 735 */
762 736
763 tmp = GET_MAP_OB (pl->map, x, y); 737 object *tmp = GET_MAP_OB (pl->map, x, y);
764 if (!tmp) 738 if (!tmp)
765 { 739 {
766 /* Nothing, meaning player is standing next to an undefined square... */ 740 /* Nothing, meaning player is standing next to an undefined square... */
767 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 741 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
768 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 742 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
769 return; 743 return;
770 } 744 }
771 745
772 tmp2 = find_marked_object (pl); 746 object *builder = pl->contr->ranged_ob;
747
748 object *tmp2 = pl->mark ();
749
773 while (tmp) 750 while (tmp)
774 { 751 {
775 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) 752 if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
776 { 753 {
777 /* The item building function already has it's own special 754 /* The item building function already has it's own special
778 * checks for this 755 * checks for this
779 */ 756 */
780 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 757 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM)
781 { 758 {
759 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (0)))
782 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 760 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
761
783 return; 762 return;
784 } 763 }
785 } 764 }
765
786 tmp = tmp->above; 766 tmp = tmp->above;
787 } 767 }
788 768
789 /* Now we know the square is ok */ 769 /* Now we know the square is ok */
790 builder = pl->contr->ranged_ob; 770 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (1)))
771 return;
791 772
792 if (builder->subtype == ST_BD_REMOVE) 773 if (builder->subtype == ST_BD_REMOVE)
793 /* Remover -> call specific function and bail out */ 774 /* Remover -> call specific function and bail out */
794 { 775 {
795 apply_builder_remove (pl, dir); 776 apply_builder_remove (pl, dir);
815 return; 796 return;
816 } 797 }
817 798
818 switch (tmp->subtype) 799 switch (tmp->subtype)
819 { 800 {
820 case ST_MAT_FLOOR: 801 case ST_MAT_FLOOR:
821 apply_builder_floor (pl, tmp, x, y); 802 apply_builder_floor (pl, tmp, x, y);
822 return; 803 return;
823 804
824 case ST_MAT_WALL: 805 case ST_MAT_WALL:
825 apply_builder_wall (pl, tmp, x, y); 806 apply_builder_wall (pl, tmp, x, y);
826 return; 807 return;
827 808
828 case ST_MAT_ITEM: 809 case ST_MAT_ITEM:
829 apply_builder_item (pl, tmp, x, y); 810 apply_builder_item (pl, tmp, x, y);
830 return; 811 return;
831 812
832 default: 813 default:
833 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry."); 814 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
834 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype); 815 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
835 return; 816 return;
836 } 817 }
837 } 818 }
838 819
839 /* Here, it means the builder has an invalid type */ 820 /* Here, it means the builder has an invalid type */
840 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry."); 821 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
841 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); 822 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
842} 823}
843 824
844/**
845 * Make the built object inherit the msg of books that are used with it.
846 * For objects already invisible (i.e. magic mouths & ears), also make it
847 * it inherit the face and the name with "talking " prepended.
848 */
849int
850adjust_sign_msg (object *pl, short x, short y, object *tmp)
851{
852 object *book;
853 char buf[MAX_BUF];
854 char buf2[MAX_BUF];
855
856 book = get_msg_book (pl, x, y);
857 if (!book)
858 {
859 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
860 return -1;
861 }
862
863 tmp->msg = book->msg;
864
865 if (tmp->invisible)
866 {
867 if (book->custom_name != NULL)
868 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
869 else
870 snprintf (buf, sizeof (buf), "talking %s", &book->name);
871
872 tmp->name = buf;
873
874 if (book->name_pl != NULL)
875 {
876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
877 tmp->name_pl = buf2;
878 }
879
880 tmp->face = book->face;
881 tmp->invisible = 0;
882 }
883
884 book->destroy ();
885 return 0;
886}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines