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.34 by root, Mon Sep 29 10:20:49 2008 UTC vs.
Revision 1.45 by root, Fri Nov 6 13:03:34 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
29#include <sproto.h> 30#include <sproto.h>
30 31
31/** 32/**
32 * Check if objects on a square interfere with building 33 * Check if objects on a square interfere with building
33 */ 34 */
34int 35static int
35can_build_over (maptile *map, object *tmp, short x, short y) 36can_build_over (maptile *map, object *tmp, int x, int y)
36{ 37{
37 object *ob; 38 object *ob;
38 39
39 ob = GET_MAP_OB (map, x, y); 40 ob = GET_MAP_OB (map, x, y);
40 while (ob) 41 while (ob)
41 { 42 {
42 /* if ob is not a marking rune or floor, then check special cases */ 43 /* if ob is not a marking rune or floor, then check special cases */
43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR) 44 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
44 { 45 {
45 switch (tmp->type) 46 switch (tmp->type)
46 { 47 {
47 case SIGN: 48 case SIGN:
48 case MAGIC_EAR: 49 case MAGIC_EAR:
49 /* Allow signs and magic ears to be built on books */ 50 /* Allow signs and magic ears to be built on books */
50 if (ob->type != BOOK) 51 if (ob->type != BOOK)
51 {
52 return 0;
53 }
54 break;
55 case BUTTON:
56 case DETECTOR:
57 case PEDESTAL:
58 case CF_HANDLE:
59 /* Allow buttons and levers to be built under gates */
60 if (ob->type != GATE && ob->type != DOOR)
61 {
62 return 0;
63 }
64 break;
65 default:
66 return 0; 52 return 0;
53 break;
54 case BUTTON:
55 case DETECTOR:
56 case PEDESTAL:
57 case T_HANDLE:
58 /* Allow buttons and levers to be built under gates */
59 if (ob->type != GATE && ob->type != DOOR)
60 return 0;
61 break;
62 default:
63 return 0;
67 } 64 }
68 } 65 }
66
69 ob = ob->above; 67 ob = ob->above;
70 } 68 }
71 return 1; 69 return 1;
72} 70}
73 71
74/** 72/**
75 * Erases marking runes at specified location 73 * Erases marking runes at specified location
76 */ 74 */
77void 75static void
78remove_marking_runes (maptile *map, short x, short y) 76remove_marking_runes (maptile *map, int x, int y)
79{ 77{
80 object *rune; 78 object *rune;
81 object *next; 79 object *next;
82 80
83 rune = GET_MAP_OB (map, x, y); 81 rune = GET_MAP_OB (map, x, y);
84 while (rune) 82 while (rune)
85 { 83 {
86 next = rune->above; 84 next = rune->above;
87 85
88 if (rune->type == SIGN && !strcmp (rune->arch->archname, "rune_mark")) 86 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
89 rune->destroy (true); 87 rune->destroy ();
90 88
91 rune = next; 89 rune = next;
92 } 90 }
93} 91}
94 92
97 * \param map: map for which to find a value 95 * \param map: map for which to find a value
98 * \return 'connected' value with no item, or -1 if failure. 96 * \return 'connected' value with no item, or -1 if failure.
99 * 97 *
100 * Tries 1000 random values, then returns -1. 98 * Tries 1000 random values, then returns -1.
101 */ 99 */
102int 100static shstr_tmp
103find_unused_connected_value (maptile *map) 101find_unused_connected_value (maptile *map)
104{ 102{
105 int connected = 0; 103 for (int i = 1000; --i; )
106 int itest = 0;
107 oblinkpt *obp;
108
109 while (itest++ < 1000)
110 {
111 connected = rndm (0x20000000UL) + 0x60000000UL;
112
113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next)
114 ;
115
116 if (!obp)
117 return connected;
118 } 104 {
105 char buf[64];
119 106
107 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
108
109 shstr id (buf);
110
111 if (!map->find_link (id))
112 return id;
113 }
114
115 return shstr_tmp ();
116}
117
118/**
119 * Returns the marking rune on the square, for purposes of building connections
120 */
121static object *
122get_connection_rune (object *pl, int x, int y)
123{
124 object *rune = GET_MAP_OB (pl->map, x, y);
125
126 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
127 rune = rune->above;
128
120 return -1; 129 return rune;
121} 130}
122 131
123/** 132/**
124 * Helper function for door/button/connected item building. 133 * Helper function for door/button/connected item building.
125 * 134 *
128 * Else, searches a force in op's inventory matching the map's name 137 * Else, searches a force in op's inventory matching the map's name
129 * and the rune's text. 138 * and the rune's text.
130 * If found, returns the connection value associated 139 * If found, returns the connection value associated
131 * else searches a new connection value, and adds the force to the player. 140 * else searches a new connection value, and adds the force to the player.
132 */ 141 */
133int 142static shstr_tmp
134find_or_create_connection_for_map (object *pl, short x, short y, object *rune) 143find_or_create_connection_for_map (object *pl, int x, int y, object *rune)
135{ 144{
136 object *force; 145 object *force;
137 int connected;
138 146
139 if (!rune) 147 if (!rune)
140 rune = get_connection_rune (pl, x, y); 148 rune = get_connection_rune (pl, x, y);
141 149
142 if (!rune) 150 if (!rune)
143 { 151 {
144 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); 152 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
145 return -1; 153 return shstr_tmp ();
146 } 154 }
147 155
148 /* Now, find force in player's inventory */ 156 /* Now, find force in player's inventory */
149 force = pl->inv; 157 force = pl->inv;
150 while (force 158 while (force
154 162
155 if (!force) 163 if (!force)
156 /* No force, need to create & insert one */ 164 /* No force, need to create & insert one */
157 { 165 {
158 /* Find unused value */ 166 /* Find unused value */
159 connected = find_unused_connected_value (pl->map); 167 shstr_tmp id = find_unused_connected_value (pl->map);
160 if (connected == -1) 168
169 if (!id)
161 { 170 {
162 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 171 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
163 return -1; 172 return shstr_tmp ();
164 } 173 }
165 174
166 force = get_archetype (FORCE_NAME); 175 force = get_archetype (FORCE_NAME);
167 force->slaying = pl->map->path; 176 force->slaying = pl->map->path;
168 force->msg = rune->msg; 177 force->msg = rune->msg;
169 force->path_attuned = connected; 178 force->race = id;
170 force->set_speed (0); 179 force->set_speed (0);
180
171 insert_ob_in_ob (force, pl); 181 insert_ob_in_ob (force, pl);
172 182
173 return connected; 183 return id;
174 } 184 }
175 185
176 /* Found the force, everything's easy. */ 186 /* Found the force, everything's easy. */
177 return force->path_attuned; 187 return force->race;
178}
179
180/**
181 * Returns the marking rune on the square, for purposes of building connections
182 */
183object *
184get_connection_rune (object *pl, short x, short y)
185{
186 object *rune = GET_MAP_OB (pl->map, x, y);
187
188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark"))))
189 rune = rune->above;
190
191 return rune;
192} 188}
193 189
194/** 190/**
195 * Returns the book/scroll on the current square, for purposes of building 191 * Returns the book/scroll on the current square, for purposes of building
196 */ 192 */
197object * 193static object *
198get_msg_book (object *pl, short x, short y) 194get_msg_book (object *pl, int x, int y)
199{ 195{
200 object *book = GET_MAP_OB (pl->map, x, y); 196 object *book = GET_MAP_OB (pl->map, x, y);
201 197
202 while (book && (book->type != BOOK)) 198 while (book && (book->type != BOOK))
203 book = book->above; 199 book = book->above;
204 200
205 return book; 201 return book;
206} 202}
207 203
208/** 204/**
205 * Make the built object inherit the msg of books that are used with it.
206 * For objects already invisible (i.e. magic mouths & ears), also make it
207 * it inherit the face and the name with "talking " prepended.
208 */
209static int
210adjust_sign_msg (object *pl, int x, int y, object *tmp)
211{
212 object *book;
213 char buf[MAX_BUF];
214 char buf2[MAX_BUF];
215
216 book = get_msg_book (pl, x, y);
217 if (!book)
218 {
219 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
220 return -1;
221 }
222
223 tmp->msg = book->msg;
224
225 if (tmp->invisible)
226 {
227 if (book->custom_name)
228 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
229 else
230 snprintf (buf, sizeof (buf), "talking %s", &book->name);
231
232 tmp->name = buf;
233
234 if (book->name_pl)
235 {
236 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
237 tmp->name_pl = buf2;
238 }
239
240 tmp->face = book->face;
241 tmp->invisible = 0;
242 }
243
244 book->destroy ();
245 return 0;
246}
247
248/**
209 * Returns first item of type BUILDABLE_WALL. 249 * Returns first item of type BUILDABLE_WALL.
210 */ 250 */
211object * 251static object *
212get_wall (maptile *map, int x, int y) 252get_wall (maptile *map, int x, int y)
213{ 253{
214 object *wall = GET_MAP_OB (map, x, y); 254 object *wall = GET_MAP_OB (map, x, y);
215 255
216 while (wall && (BUILDABLE_WALL != wall->type)) 256 while (wall && (BUILDABLE_WALL != wall->type))
228 * 268 *
229 * Basically it ensures the correct wall is put where needed. 269 * Basically it ensures the correct wall is put where needed.
230 * 270 *
231 * Note: x & y must be valid map coordinates. 271 * Note: x & y must be valid map coordinates.
232 */ 272 */
233void 273static void
234fix_walls (maptile *map, int x, int y) 274fix_walls (maptile *map, int x, int y)
235{ 275{
236 char archetype[MAX_BUF]; 276 char archetype[MAX_BUF];
237 char *underscore; 277 char *underscore;
238 struct archetype *new_arch; 278 struct archetype *new_arch;
258 underscore++; 298 underscore++;
259 *underscore = '\0'; 299 *underscore = '\0';
260 300
261 int connect = 0; 301 int connect = 0;
262 302
263 if ((x > 0) && get_wall (map, x - 1, y)) 303 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
264 connect |= 1;
265 if ((x < map->width - 1) && get_wall (map, x + 1, y)) 304 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
266 connect |= 2; 305 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
267
268 if ((y > 0) && get_wall (map, x, y - 1))
269 connect |= 4;
270
271 if ((y < map->height - 1) && get_wall (map, x, y + 1)) 306 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
272 connect |= 8;
273 307
274 switch (connect) 308 // one bit per dir, 1 left, 2 right, 4 up, 8 down
275 { 309 static const char *walltype[16] = {
276 case 0: 310 "0",
277 strcat (archetype, "0"); 311 "1_3",
312 "1_4",
313 "2_1_2",
314 "1_2",
315 "2_2_4",
316 "2_2_1",
317 "3_1",
318 "1_1",
319 "2_2_3",
320 "2_2_2",
321 "3_3",
322 "2_1_1",
323 "3_4",
324 "3_2",
325 "4"
326 };
278 327
279 break; 328 strcat (archetype, walltype [connect]);
280 case 1:
281 strcat (archetype, "1_3");
282
283 break;
284 case 2:
285 strcat (archetype, "1_4");
286
287 break;
288 case 3:
289 strcat (archetype, "2_1_2");
290
291 break;
292 case 4:
293 strcat (archetype, "1_2");
294
295 break;
296 case 5:
297 strcat (archetype, "2_2_4");
298
299 break;
300 case 6:
301 strcat (archetype, "2_2_1");
302
303 break;
304 case 7:
305 strcat (archetype, "3_1");
306
307 break;
308 case 8:
309 strcat (archetype, "1_1");
310
311 break;
312 case 9:
313 strcat (archetype, "2_2_3");
314
315 break;
316 case 10:
317 strcat (archetype, "2_2_2");
318
319 break;
320 case 11:
321 strcat (archetype, "3_3");
322
323 break;
324 case 12:
325 strcat (archetype, "2_1_1");
326
327 break;
328 case 13:
329 strcat (archetype, "3_4");
330
331 break;
332 case 14:
333 strcat (archetype, "3_2");
334
335 break;
336 case 15:
337 strcat (archetype, "4");
338
339 break;
340 }
341 329
342 /* 330 /*
343 * Before anything, make sure the archetype does exist... 331 * Before anything, make sure the archetype does exist...
344 * If not, prolly an error... 332 * If not, prolly an error...
345 */ 333 */
351 /* Now delete current wall, and insert new one 339 /* Now delete current wall, and insert new one
352 * We save flags to avoid any trouble with buildable/non buildable, and so on 340 * We save flags to avoid any trouble with buildable/non buildable, and so on
353 */ 341 */
354 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off 342 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
355 343
356 wall->destroy (true); 344 wall->destroy ();
357 345
358 wall = arch_to_object (new_arch); 346 wall = arch_to_object (new_arch);
359 wall->type = BUILDABLE_WALL; 347 wall->type = BUILDABLE_WALL;
360 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 348 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
361 wall->flag = old_flags; 349 wall->flag = old_flags;
369 * - on an existing wall, with or without a floor under it 357 * - on an existing wall, with or without a floor under it
370 * 358 *
371 * Note: this function will inconditionally change squares around (x, y) 359 * Note: this function will inconditionally change squares around (x, y)
372 * so don't call it with x == 0 for instance! 360 * so don't call it with x == 0 for instance!
373 */ 361 */
374void 362static void
375apply_builder_floor (object *pl, object *material, short x, short y) 363apply_builder_floor (object *pl, object *material, int x, int y)
376{ 364{
377 object *tmp, *above; 365 object *tmp, *above;
378 object *above_floor; /* Item above floor, if any */ 366 object *above_floor; /* Item above floor, if any */
379 struct archetype *new_floor; 367 struct archetype *new_floor;
380 struct archetype *new_wall; 368 struct archetype *new_wall;
398 above = tmp->above; 386 above = tmp->above;
399 if (BUILDABLE_WALL == tmp->type) 387 if (BUILDABLE_WALL == tmp->type)
400 { 388 {
401 /* There was a wall, remove it & keep its archetype to make new walls */ 389 /* There was a wall, remove it & keep its archetype to make new walls */
402 new_wall = tmp->arch; 390 new_wall = tmp->arch;
403 tmp->destroy (true); 391 tmp->destroy ();
404 sprintf (message, "You destroy the wall and redo the floor."); 392 sprintf (message, "You destroy the wall and redo the floor.");
405 } 393 }
406 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 394 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
407 { 395 {
408 tmp->destroy (true); 396 tmp->destroy ();
409 floor_removed = 1; 397 floor_removed = 1;
410 } 398 }
411 else 399 else
412 { 400 {
413 if (floor_removed) 401 if (floor_removed)
402 {
403 /* This is the first item that was above the floor */
414 above_floor = tmp; 404 above_floor = tmp;
405 floor_removed = 0;
406 }
415 } 407 }
416 408
417 tmp = above; 409 tmp = above;
418 } 410 }
419 } 411 }
467 * Note: 2 squares around are checked, because potentially we added walls around the building 459 * 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 460 * spot, so need to check that those new walls connect correctly
469 */ 461 */
470 for (xt = x - 2; xt <= x + 2; xt++) 462 for (xt = x - 2; xt <= x + 2; xt++)
471 for (yt = y - 2; yt <= y + 2; yt++) 463 for (yt = y - 2; yt <= y + 2; yt++)
472 {
473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 464 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
474 fix_walls (pl->map, xt, yt); 465 fix_walls (pl->map, xt, yt);
475 }
476 466
477 /* Now remove raw item from inventory */ 467 /* Now remove raw item from inventory */
478 material->decrease (); 468 material->decrease ();
479 469
480 /* And tell player about the fix */ 470 /* And tell player about the fix */
482} 472}
483 473
484/** 474/**
485 * Wall radius fix function 475 * Wall radius fix function
486 */ 476 */
477static void
487void fix_walls_around (maptile *map, int x, int y) 478fix_walls_around (maptile *map, int x, int y)
488{ 479{
489 for (int xt = x - 1; xt <= x + 1; xt++) 480 for (int xt = x - 1; xt <= x + 1; xt++)
490 for (int yt = y - 1; yt <= y + 1; yt++) 481 for (int yt = y - 1; yt <= y + 1; yt++)
491 {
492 if (OUT_OF_REAL_MAP (map, xt, yt)) 482 if (!OUT_OF_REAL_MAP (map, xt, yt))
493 continue;
494
495 fix_walls (map, xt, yt); 483 fix_walls (map, xt, yt);
496 }
497} 484}
498 485
499/** 486/**
500 * Wall building function 487 * Wall building function
501 * 488 *
502 * Walls can be build: 489 * Walls can be build:
503 * - on a floor without anything else 490 * - on a floor without anything else
504 * - on an existing wall, with or without a floor 491 * - on an existing wall, with or without a floor
505 */ 492 */
506void 493static void
507apply_builder_wall (object *pl, object *material, short x, short y) 494apply_builder_wall (object *pl, object *material, int x, int y)
508{ 495{
509 object *current_wall; 496 object *current_wall;
510 object *tmp; 497 object *tmp;
511 int xt, yt; 498 int xt, yt;
512 struct archetype *new_wall; 499 struct archetype *new_wall;
542 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 529 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
543 530
544 /* If existing wall, remove it, no need to fix other walls */ 531 /* If existing wall, remove it, no need to fix other walls */
545 if (current_wall) 532 if (current_wall)
546 { 533 {
547 current_wall->destroy (true); 534 current_wall->destroy ();
548 fix_walls (pl->map, x, y); 535 fix_walls (pl->map, x, y);
549 sprintf (message, "You redecorate the wall to better suit your tastes."); 536 sprintf (message, "You redecorate the wall to better suit your tastes.");
550 } 537 }
551 else 538 else
552 { 539 {
574 * Item must be put on a square with a floor, you can have something under. 561 * 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). 562 * Archetype of created object is item->slaying (raw material).
576 * Type of inserted item is tested for specific cases (doors & such). 563 * 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) 564 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
578 */ 565 */
579void 566static void
580apply_builder_item (object *pl, object *item, short x, short y) 567apply_builder_item (object *pl, object *item, int x, int y)
581{ 568{
582 object *tmp; 569 object *tmp;
583 struct archetype *arch; 570 struct archetype *arch;
584 int insert_flag; 571 int insert_flag;
585 object *floor; 572 object *floor;
586 object *con_rune; 573 object *con_rune;
587 int connected;
588 574
589 /* Find floor */ 575 /* Find floor */
590 floor = GET_MAP_OB (pl->map, x, y); 576 floor = GET_MAP_OB (pl->map, x, y);
591 if (!floor) 577 if (!floor)
592 { 578 {
618 604
619 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 605 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
620 SET_FLAG (tmp, FLAG_NO_PICK); 606 SET_FLAG (tmp, FLAG_NO_PICK);
621 607
622 /* 608 /*
623 * This doesn't work on non unique maps. pedestals under floor will not be saved... 609 * Str 1 is a flag that the item [pedestal] should go below the floor.
624 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 610 * Items under the floor on non-unique maps will not be saved,
611 * so make the item itself unique in this situation.
625 */ 612 */
626 insert_flag = INS_ABOVE_FLOOR_ONLY; 613 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
614 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
615 SET_FLAG (tmp, FLAG_UNIQUE);
627 616
628 connected = 0; 617 shstr_tmp connected;
618
629 switch (tmp->type) 619 switch (tmp->type)
630 { 620 {
631 case DOOR: 621 case DOOR:
632 case GATE: 622 case GATE:
633 case BUTTON: 623 case BUTTON:
634 case DETECTOR: 624 case DETECTOR:
635 case TIMED_GATE: 625 case TIMED_GATE:
636 case PEDESTAL: 626 case PEDESTAL:
637 case CF_HANDLE: 627 case T_HANDLE:
638 case MAGIC_EAR: 628 case MAGIC_EAR:
639 case SIGN: 629 case SIGN:
640 /* Signs don't need a connection, but but magic mouths do. */ 630 /* Signs don't need a connection, but but magic mouths do. */
641 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) 631 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
642 break; 632 break;
643 633
644 con_rune = get_connection_rune (pl, x, y); 634 con_rune = get_connection_rune (pl, x, y);
645 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 635 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
646 if (connected == -1) 636 if (!connected)
647 { 637 {
648 /* Player already informed of failure by the previous function */ 638 /* Player already informed of failure by the previous function */
649 tmp->destroy (true); 639 tmp->destroy ();
650 return; 640 return;
651 } 641 }
652 642
653 /* Remove marking rune */ 643 /* Remove marking rune */
654 con_rune->destroy (true); 644 con_rune->destroy ();
655 } 645 }
656 646
657 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 647 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 648 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 {
660 if (adjust_sign_msg (pl, x, y, tmp) == -1) 649 if (adjust_sign_msg (pl, x, y, tmp) == -1)
661 { 650 {
662 tmp->destroy (true); 651 tmp->destroy ();
663 return; 652 return;
664 } 653 }
665 }
666 654
667 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 655 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
668 if (connected != 0) 656 if (connected)
669 add_button_link (tmp, pl->map, connected); 657 tmp->add_link (pl->map, connected);
670 658
671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); 659 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
672 item->decrease (); 660 item->decrease ();
673} 661}
674 662
675/** 663/**
676 * Item remover. 664 * Item remover.
677 * 665 *
678 * Removes first buildable item, either under or above the floor 666 * Removes first buildable item, either under or above the floor
679 */ 667 */
680void 668static void
681apply_builder_remove (object *pl, int dir) 669apply_builder_remove (object *pl, int dir)
682{ 670{
683 object *item; 671 object *item;
684 short x, y; 672 int x, y;
685 673
686 x = pl->x + freearr_x[dir]; 674 x = pl->x + freearr_x[dir];
687 y = pl->y + freearr_y[dir]; 675 y = pl->y + freearr_y[dir];
688 676
689 /* Check square */ 677 /* Check square */
706 else if (!item->flag [FLAG_IS_BUILDABLE]) 694 else if (!item->flag [FLAG_IS_BUILDABLE])
707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); 695 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
708 else 696 else
709 { 697 {
710 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); 698 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
711 item->destroy (true); 699 item->destroy ();
712 } 700 }
713} 701}
714 702
715/** 703/**
716 * Global building function 704 * Global building function
722apply_map_builder (object *pl, int dir) 710apply_map_builder (object *pl, int dir)
723{ 711{
724 object *builder; 712 object *builder;
725 object *tmp; 713 object *tmp;
726 object *tmp2; 714 object *tmp2;
727 short x, y; 715 int x, y;
728 716
729 if (!pl->type == PLAYER) 717 if (!pl->type == PLAYER)
730 return; 718 return;
731 719
732 /*if ( !player->map->unique ) 720 /*if ( !player->map->unique )
767 } 755 }
768 756
769 tmp2 = find_marked_object (pl); 757 tmp2 = find_marked_object (pl);
770 while (tmp) 758 while (tmp)
771 { 759 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) 760 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
773 { 761 {
774 /* The item building function already has it's own special 762 /* The item building function already has it's own special
775 * checks for this 763 * checks for this
776 */ 764 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 765 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
836 /* Here, it means the builder has an invalid type */ 824 /* Here, it means the builder has an invalid type */
837 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry."); 825 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
838 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); 826 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
839} 827}
840 828
841/**
842 * Make the built object inherit the msg of books that are used with it.
843 * For objects already invisible (i.e. magic mouths & ears), also make it
844 * it inherit the face and the name with "talking " prepended.
845 */
846int
847adjust_sign_msg (object *pl, short x, short y, object *tmp)
848{
849 object *book;
850 char buf[MAX_BUF];
851 char buf2[MAX_BUF];
852
853 book = get_msg_book (pl, x, y);
854 if (!book)
855 {
856 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
857 return -1;
858 }
859
860 tmp->msg = book->msg;
861
862 if (tmp->invisible)
863 {
864 if (book->custom_name != NULL)
865 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
866 else
867 snprintf (buf, sizeof (buf), "talking %s", &book->name);
868
869 tmp->name = buf;
870
871 if (book->name_pl != NULL)
872 {
873 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
874 tmp->name_pl = buf2;
875 }
876
877 tmp->face = book->face;
878 tmp->invisible = 0;
879 }
880
881 book->destroy (true);
882 return 0;
883}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines