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.24 by root, Mon Feb 5 02:07:40 2007 UTC vs.
Revision 1.44 by root, Mon Nov 2 07:41:48 2009 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <living.h> 26#include <living.h>
27#include <spells.h> 27#include <spells.h>
30#include <sproto.h> 30#include <sproto.h>
31 31
32/** 32/**
33 * Check if objects on a square interfere with building 33 * Check if objects on a square interfere with building
34 */ 34 */
35int 35static int
36can_build_over (maptile *map, object *tmp, short x, short y) 36can_build_over (maptile *map, object *tmp, int x, int y)
37{ 37{
38 object *ob; 38 object *ob;
39 39
40 ob = GET_MAP_OB (map, x, y); 40 ob = GET_MAP_OB (map, x, y);
41 while (ob) 41 while (ob)
42 { 42 {
43 /* 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 */
44 if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) 44 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
45 { 45 {
46 switch (tmp->type) 46 switch (tmp->type)
47 { 47 {
48 case SIGN: 48 case SIGN:
49 case MAGIC_EAR: 49 case MAGIC_EAR:
50 /* Allow signs and magic ears to be built on books */ 50 /* Allow signs and magic ears to be built on books */
51 if (ob->type != BOOK) 51 if (ob->type != BOOK)
52 {
53 return 0;
54 }
55 break;
56 case BUTTON:
57 case DETECTOR:
58 case PEDESTAL:
59 case CF_HANDLE:
60 /* Allow buttons and levers to be built under gates */
61 if (ob->type != GATE && ob->type != DOOR)
62 {
63 return 0;
64 }
65 break;
66 default:
67 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;
68 } 64 }
69 } 65 }
66
70 ob = ob->above; 67 ob = ob->above;
71 } 68 }
72 return 1; 69 return 1;
73} 70}
74 71
75/** 72/**
76 * Erases marking runes at specified location 73 * Erases marking runes at specified location
77 */ 74 */
78void 75static void
79remove_marking_runes (maptile *map, short x, short y) 76remove_marking_runes (maptile *map, int x, int y)
80{ 77{
81 object *rune; 78 object *rune;
82 object *next; 79 object *next;
83 80
84 rune = GET_MAP_OB (map, x, y); 81 rune = GET_MAP_OB (map, x, y);
85 while (rune) 82 while (rune)
86 { 83 {
87 next = rune->above; 84 next = rune->above;
88 85
89 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 86 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
90 rune->destroy (); 87 rune->destroy ();
91 88
92 rune = next; 89 rune = next;
93 } 90 }
94} 91}
98 * \param map: map for which to find a value 95 * \param map: map for which to find a value
99 * \return 'connected' value with no item, or -1 if failure. 96 * \return 'connected' value with no item, or -1 if failure.
100 * 97 *
101 * Tries 1000 random values, then returns -1. 98 * Tries 1000 random values, then returns -1.
102 */ 99 */
103int 100static shstr_tmp
104find_unused_connected_value (maptile *map) 101find_unused_connected_value (maptile *map)
105{ 102{
106 int connected = 0; 103 for (int i = 1000; --i; )
107 int itest = 0;
108 oblinkpt *obp;
109
110 while (itest++ < 1000)
111 {
112 connected = 1 + rand () % 20000;
113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next);
114
115 if (!obp)
116 return connected;
117 } 104 {
105 char buf[64];
118 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
119 return -1; 129 return rune;
120} 130}
121
122 131
123/** 132/**
124 * Helper function for door/button/connected item building. 133 * Helper function for door/button/connected item building.
125 * 134 *
126 * Will search the specified spot for a marking rune. 135 * Will search the specified spot for a marking rune.
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;
187
188 rune = GET_MAP_OB (pl->map, x, y);
189 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark"))))
190 rune = rune->above;
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;
201
202 book = GET_MAP_OB (pl->map, x, y); 196 object *book = GET_MAP_OB (pl->map, x, y);
197
203 while (book && (book->type != BOOK)) 198 while (book && (book->type != BOOK))
204 book = book->above; 199 book = book->above;
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;
215
216 wall = GET_MAP_OB (map, x, y); 254 object *wall = GET_MAP_OB (map, x, y);
255
217 while (wall && (BUILDABLE_WALL != wall->type)) 256 while (wall && (BUILDABLE_WALL != wall->type))
218 wall = wall->above; 257 wall = wall->above;
219 258
220 return wall; 259 return wall;
221} 260}
232 * Note: x & y must be valid map coordinates. 271 * Note: x & y must be valid map coordinates.
233 */ 272 */
234void 273void
235fix_walls (maptile *map, int x, int y) 274fix_walls (maptile *map, int x, int y)
236{ 275{
237 object *wall;
238 char archetype[MAX_BUF]; 276 char archetype[MAX_BUF];
239 char *underscore; 277 char *underscore;
240 struct archetype *new_arch; 278 struct archetype *new_arch;
241 279
242
243 /* First, find the wall on that spot */ 280 /* First, find the wall on that spot */
244 wall = get_wall (map, x, y); 281 object *wall = get_wall (map, x, y);
245 if (!wall) 282 if (!wall)
246 /* Nothing -> bail out */ 283 /* Nothing -> bail out */
247 return; 284 return;
248 285
249 /* Find base name */ 286 /* Find base name */
250 assign (archetype, wall->arch->name); 287 assign (archetype, wall->arch->archname);
251 underscore = strchr (archetype, '_'); 288 underscore = strchr (archetype, '_');
252 289
253 /* search for the first _ before a number */ 290 /* search for the first _ before a number */
254 while (underscore && !isdigit (*(underscore + 1))) 291 while (underscore && !isdigit (*(underscore + 1)))
255 underscore = strchr (underscore + 1, '_'); 292 underscore = strchr (underscore + 1, '_');
261 underscore++; 298 underscore++;
262 *underscore = '\0'; 299 *underscore = '\0';
263 300
264 int connect = 0; 301 int connect = 0;
265 302
266 if ((x > 0) && get_wall (map, x - 1, y)) 303 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
267 connect |= 1;
268 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;
269 connect |= 2; 305 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
270
271 if ((y > 0) && get_wall (map, x, y - 1))
272 connect |= 4;
273
274 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;
275 connect |= 8;
276 307
277 switch (connect) 308 // one bit per dir, 1 left, 2 right, 4 up, 8 down
278 { 309 static const char *walltype[16] = {
279 case 0: 310 "0",
280 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 };
281 327
282 break; 328 strcat (archetype, walltype [connect]);
283 case 1:
284 strcat (archetype, "1_3");
285
286 break;
287 case 2:
288 strcat (archetype, "1_4");
289
290 break;
291 case 3:
292 strcat (archetype, "2_1_2");
293
294 break;
295 case 4:
296 strcat (archetype, "1_2");
297
298 break;
299 case 5:
300 strcat (archetype, "2_2_4");
301
302 break;
303 case 6:
304 strcat (archetype, "2_2_1");
305
306 break;
307 case 7:
308 strcat (archetype, "3_1");
309
310 break;
311 case 8:
312 strcat (archetype, "1_1");
313
314 break;
315 case 9:
316 strcat (archetype, "2_2_3");
317
318 break;
319 case 10:
320 strcat (archetype, "2_2_2");
321
322 break;
323 case 11:
324 strcat (archetype, "3_3");
325
326 break;
327 case 12:
328 strcat (archetype, "2_1_1");
329
330 break;
331 case 13:
332 strcat (archetype, "3_4");
333
334 break;
335 case 14:
336 strcat (archetype, "3_2");
337
338 break;
339 case 15:
340 strcat (archetype, "4");
341
342 break;
343 }
344 329
345 /* 330 /*
346 * Before anything, make sure the archetype does exist... 331 * Before anything, make sure the archetype does exist...
347 * If not, prolly an error... 332 * If not, prolly an error...
348 */ 333 */
372 * - on an existing wall, with or without a floor under it 357 * - on an existing wall, with or without a floor under it
373 * 358 *
374 * Note: this function will inconditionally change squares around (x, y) 359 * Note: this function will inconditionally change squares around (x, y)
375 * so don't call it with x == 0 for instance! 360 * so don't call it with x == 0 for instance!
376 */ 361 */
377void 362static void
378apply_builder_floor (object *pl, object *material, short x, short y) 363apply_builder_floor (object *pl, object *material, int x, int y)
379{ 364{
380 object *tmp, *above; 365 object *tmp, *above;
381 object *above_floor; /* Item above floor, if any */ 366 object *above_floor; /* Item above floor, if any */
382 struct archetype *new_floor; 367 struct archetype *new_floor;
383 struct archetype *new_wall; 368 struct archetype *new_wall;
412 floor_removed = 1; 397 floor_removed = 1;
413 } 398 }
414 else 399 else
415 { 400 {
416 if (floor_removed) 401 if (floor_removed)
402 {
403 /* This is the first item that was above the floor */
417 above_floor = tmp; 404 above_floor = tmp;
405 floor_removed = 0;
406 }
418 } 407 }
419 408
420 tmp = above; 409 tmp = above;
421 } 410 }
422 } 411 }
470 * 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
471 * spot, so need to check that those new walls connect correctly 460 * spot, so need to check that those new walls connect correctly
472 */ 461 */
473 for (xt = x - 2; xt <= x + 2; xt++) 462 for (xt = x - 2; xt <= x + 2; xt++)
474 for (yt = y - 2; yt <= y + 2; yt++) 463 for (yt = y - 2; yt <= y + 2; yt++)
475 {
476 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 464 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
477 fix_walls (pl->map, xt, yt); 465 fix_walls (pl->map, xt, yt);
478 }
479 466
480 /* Now remove raw item from inventory */ 467 /* Now remove raw item from inventory */
481 decrease_ob (material); 468 material->decrease ();
482 469
483 /* And tell player about the fix */ 470 /* And tell player about the fix */
484 new_draw_info (NDI_UNIQUE, 0, pl, message); 471 new_draw_info (NDI_UNIQUE, 0, pl, message);
485} 472}
486 473
487/** 474/**
488 * Wall radius fix function 475 * Wall radius fix function
489 */ 476 */
477static void
490void fix_walls_around (maptile *map, int x, int y) 478fix_walls_around (maptile *map, int x, int y)
491{ 479{
492 for (int xt = x - 1; xt <= x + 1; xt++) 480 for (int xt = x - 1; xt <= x + 1; xt++)
493 for (int yt = y - 1; yt <= y + 1; yt++) 481 for (int yt = y - 1; yt <= y + 1; yt++)
494 {
495 if (OUT_OF_REAL_MAP (map, xt, yt)) 482 if (!OUT_OF_REAL_MAP (map, xt, yt))
496 continue;
497
498 fix_walls (map, xt, yt); 483 fix_walls (map, xt, yt);
499 }
500} 484}
501 485
502/** 486/**
503 * Wall building function 487 * Wall building function
504 * 488 *
505 * Walls can be build: 489 * Walls can be build:
506 * - on a floor without anything else 490 * - on a floor without anything else
507 * - on an existing wall, with or without a floor 491 * - on an existing wall, with or without a floor
508 */ 492 */
509void 493static void
510apply_builder_wall (object *pl, object *material, short x, short y) 494apply_builder_wall (object *pl, object *material, int x, int y)
511{ 495{
512 object *current_wall; 496 object *current_wall;
513 object *tmp; 497 object *tmp;
514 int xt, yt; 498 int xt, yt;
515 struct archetype *new_wall; 499 struct archetype *new_wall;
563 fix_walls (pl->map, xt, yt); 547 fix_walls (pl->map, xt, yt);
564 } 548 }
565 } 549 }
566 550
567 /* Now remove item from inventory */ 551 /* Now remove item from inventory */
568 decrease_ob (material); 552 material->decrease ();
569 553
570 /* And tell player what happened */ 554 /* And tell player what happened */
571 new_draw_info (NDI_UNIQUE, 0, pl, message); 555 new_draw_info (NDI_UNIQUE, 0, pl, message);
572} 556}
573 557
577 * 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.
578 * Archetype of created object is item->slaying (raw material). 562 * Archetype of created object is item->slaying (raw material).
579 * Type of inserted item is tested for specific cases (doors & such). 563 * Type of inserted item is tested for specific cases (doors & such).
580 * 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)
581 */ 565 */
582void 566static void
583apply_builder_item (object *pl, object *item, short x, short y) 567apply_builder_item (object *pl, object *item, int x, int y)
584{ 568{
585 object *tmp; 569 object *tmp;
586 struct archetype *arch; 570 struct archetype *arch;
587 int insert_flag; 571 int insert_flag;
588 object *floor; 572 object *floor;
589 object *con_rune; 573 object *con_rune;
590 int connected;
591 574
592 /* Find floor */ 575 /* Find floor */
593 floor = GET_MAP_OB (pl->map, x, y); 576 floor = GET_MAP_OB (pl->map, x, y);
594 if (!floor) 577 if (!floor)
595 { 578 {
610 if (!arch) 593 if (!arch)
611 return; 594 return;
612 595
613 tmp = arch_to_object (arch); 596 tmp = arch_to_object (arch);
614 597
615 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 598 if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y)))
616 /* Floor has something on top that interferes with building */ 599 /* Floor has something on top that interferes with building */
617 { 600 {
618 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 601 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
619 return; 602 return;
620 } 603 }
621 604
622 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 605 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
623 SET_FLAG (tmp, FLAG_NO_PICK); 606 SET_FLAG (tmp, FLAG_NO_PICK);
624 607
625 /* 608 /*
626 * 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.
627 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.
628 */ 612 */
629 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);
630 616
631 connected = 0; 617 shstr_tmp connected;
618
632 switch (tmp->type) 619 switch (tmp->type)
633 { 620 {
634 case DOOR: 621 case DOOR:
635 case GATE: 622 case GATE:
636 case BUTTON: 623 case BUTTON:
637 case DETECTOR: 624 case DETECTOR:
638 case TIMED_GATE: 625 case TIMED_GATE:
639 case PEDESTAL: 626 case PEDESTAL:
640 case CF_HANDLE: 627 case T_HANDLE:
641 case MAGIC_EAR: 628 case MAGIC_EAR:
642 case SIGN: 629 case SIGN:
643 /* Signs don't need a connection, but but magic mouths do. */ 630 /* Signs don't need a connection, but but magic mouths do. */
644 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 631 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
645 break; 632 break;
633
646 con_rune = get_connection_rune (pl, x, y); 634 con_rune = get_connection_rune (pl, x, y);
647 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);
648 if (connected == -1) 636 if (!connected)
649 { 637 {
650 /* Player already informed of failure by the previous function */ 638 /* Player already informed of failure by the previous function */
651 tmp->destroy (); 639 tmp->destroy ();
652 return; 640 return;
653 } 641 }
642
654 /* Remove marking rune */ 643 /* Remove marking rune */
655 con_rune->destroy (); 644 con_rune->destroy ();
656 } 645 }
657 646
658 /* 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 */
659 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 648 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
660 {
661 if (adjust_sign_msg (pl, x, y, tmp) == -1) 649 if (adjust_sign_msg (pl, x, y, tmp) == -1)
662 { 650 {
663 tmp->destroy (); 651 tmp->destroy ();
664 return; 652 return;
665 } 653 }
666 }
667 654
668 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);
669 if (connected != 0) 656 if (connected)
670 add_button_link (tmp, pl->map, connected); 657 tmp->add_link (pl->map, connected);
671 658
672 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));
673 decrease_ob_nr (item, 1); 660 item->decrease ();
674} 661}
675 662
676/** 663/**
677 * Item remover. 664 * Item remover.
678 * 665 *
679 * Removes first buildable item, either under or above the floor 666 * Removes first buildable item, either under or above the floor
680 */ 667 */
681void 668static void
682apply_builder_remove (object *pl, int dir) 669apply_builder_remove (object *pl, int dir)
683{ 670{
684 object *item; 671 object *item;
685 short x, y; 672 int x, y;
686 673
687 x = pl->x + freearr_x[dir]; 674 x = pl->x + freearr_x[dir];
688 y = pl->y + freearr_y[dir]; 675 y = pl->y + freearr_y[dir];
689 676
690 /* Check square */ 677 /* Check square */
723apply_map_builder (object *pl, int dir) 710apply_map_builder (object *pl, int dir)
724{ 711{
725 object *builder; 712 object *builder;
726 object *tmp; 713 object *tmp;
727 object *tmp2; 714 object *tmp2;
728 short x, y; 715 int x, y;
729 716
730 if (!pl->type == PLAYER) 717 if (!pl->type == PLAYER)
731 return; 718 return;
732 719
733 /*if ( !player->map->unique ) 720 /*if ( !player->map->unique )
764 /* Nothing, meaning player is standing next to an undefined square... */ 751 /* Nothing, meaning player is standing next to an undefined square... */
765 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 752 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
766 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 753 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
767 return; 754 return;
768 } 755 }
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->name, "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))
782 } 770 }
783 tmp = tmp->above; 771 tmp = tmp->above;
784 } 772 }
785 773
786 /* Now we know the square is ok */ 774 /* Now we know the square is ok */
787 builder = pl->contr->ranges[range_builder]; 775 builder = pl->contr->ranged_ob;
788 776
789 if (builder->subtype == ST_BD_REMOVE) 777 if (builder->subtype == ST_BD_REMOVE)
790 /* Remover -> call specific function and bail out */ 778 /* Remover -> call specific function and bail out */
791 { 779 {
792 apply_builder_remove (pl, dir); 780 apply_builder_remove (pl, dir);
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 {
866 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
867 }
868 else
869 {
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