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 | */ |
35 | int |
38 | static int |
36 | can_build_over (maptile *map, object *tmp, short x, short y) |
39 | can_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: |
… | |
… | |
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 | */ |
75 | void |
79 | static void |
76 | remove_marking_runes (maptile *map, short x, short y) |
80 | remove_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 | */ |
|
|
125 | static object * |
|
|
126 | get_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 | */ |
128 | static shstr_tmp |
146 | static shstr_tmp |
129 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
147 | find_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 | */ |
|
|
179 | object * |
|
|
180 | get_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 | */ |
193 | object * |
197 | static object * |
194 | get_msg_book (object *pl, short x, short y) |
198 | get_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 | */ |
|
|
213 | static int |
|
|
214 | adjust_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 | */ |
207 | object * |
255 | static object * |
208 | get_wall (maptile *map, int x, int y) |
256 | get_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 | */ |
229 | void |
277 | static void |
230 | fix_walls (maptile *map, int x, int y) |
278 | fix_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; |
… | |
… | |
297 | */ |
345 | */ |
298 | 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 |
299 | |
347 | |
300 | wall->destroy (); |
348 | wall->destroy (); |
301 | |
349 | |
302 | wall = arch_to_object (new_arch); |
350 | wall = new_arch->instance (); |
303 | wall->type = BUILDABLE_WALL; |
351 | wall->type = BUILDABLE_WALL; |
304 | 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); |
305 | wall->flag = old_flags; |
353 | wall->flag = old_flags; |
306 | } |
354 | } |
307 | |
355 | |
… | |
… | |
313 | * - on an existing wall, with or without a floor under it |
361 | * - on an existing wall, with or without a floor under it |
314 | * |
362 | * |
315 | * Note: this function will inconditionally change squares around (x, y) |
363 | * Note: this function will inconditionally change squares around (x, y) |
316 | * so don't call it with x == 0 for instance! |
364 | * so don't call it with x == 0 for instance! |
317 | */ |
365 | */ |
318 | void |
366 | static void |
319 | apply_builder_floor (object *pl, object *material, short x, short y) |
367 | apply_builder_floor (object *pl, object *material, int x, int y) |
320 | { |
368 | { |
321 | object *tmp, *above; |
369 | object *tmp, *above; |
322 | object *above_floor; /* Item above floor, if any */ |
370 | object *above_floor; /* Item above floor, if any */ |
323 | struct archetype *new_floor; |
371 | struct archetype *new_floor; |
324 | struct archetype *new_wall; |
372 | struct archetype *new_wall; |
… | |
… | |
345 | /* 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 */ |
346 | new_wall = tmp->arch; |
394 | new_wall = tmp->arch; |
347 | tmp->destroy (); |
395 | tmp->destroy (); |
348 | sprintf (message, "You destroy the wall and redo the floor."); |
396 | sprintf (message, "You destroy the wall and redo the floor."); |
349 | } |
397 | } |
350 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
398 | else if (IS_FLOOR (tmp)) |
351 | { |
399 | { |
352 | tmp->destroy (); |
400 | tmp->destroy (); |
353 | floor_removed = 1; |
401 | floor_removed = 1; |
354 | } |
402 | } |
355 | else |
403 | else |
… | |
… | |
373 | /* Not found, log & bail out */ |
421 | /* Not found, log & bail out */ |
374 | 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); |
375 | return; |
423 | return; |
376 | } |
424 | } |
377 | |
425 | |
378 | tmp = arch_to_object (new_floor); |
426 | tmp = new_floor->instance (); |
379 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
427 | tmp->set_flag (FLAG_IS_BUILDABLE); |
380 | SET_FLAG (tmp, FLAG_UNIQUE); |
428 | tmp->set_flag (FLAG_UNIQUE); |
381 | SET_FLAG (tmp, FLAG_IS_FLOOR); |
429 | tmp->set_flag (FLAG_IS_FLOOR); |
382 | tmp->type = FLOOR; |
430 | //tmp->type = FLOOR; |
383 | 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); |
384 | |
432 | |
385 | /* |
433 | /* |
386 | * 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 |
387 | * Since building, you can have: blocking view / floor / wall / nothing |
435 | * Since building, you can have: blocking view / floor / wall / nothing |
… | |
… | |
392 | yt = y + freearr_y[i]; |
440 | yt = y + freearr_y[i]; |
393 | tmp = GET_MAP_OB (pl->map, xt, yt); |
441 | tmp = GET_MAP_OB (pl->map, xt, yt); |
394 | if (!tmp) |
442 | if (!tmp) |
395 | { |
443 | { |
396 | /* Must insert floor & wall */ |
444 | /* Must insert floor & wall */ |
397 | tmp = arch_to_object (new_floor); |
445 | tmp = new_floor->instance (); |
398 | /* Better make the floor unique */ |
446 | /* Better make the floor unique */ |
399 | SET_FLAG (tmp, FLAG_UNIQUE); |
447 | tmp->set_flag (FLAG_UNIQUE); |
400 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
448 | tmp->set_flag (FLAG_IS_BUILDABLE); |
401 | tmp->type = FLOOR; |
449 | //tmp->type = FLOOR; |
402 | 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); |
403 | /* 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... */ |
404 | if (new_wall) |
452 | if (new_wall) |
405 | { |
453 | { |
406 | tmp = arch_to_object (new_wall); |
454 | tmp = new_wall->instance (); |
407 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
455 | tmp->set_flag (FLAG_IS_BUILDABLE); |
408 | tmp->type = BUILDABLE_WALL; |
456 | tmp->type = BUILDABLE_WALL; |
409 | 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); |
410 | } |
458 | } |
411 | } |
459 | } |
412 | } |
460 | } |
… | |
… | |
415 | * 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 |
416 | * spot, so need to check that those new walls connect correctly |
464 | * spot, so need to check that those new walls connect correctly |
417 | */ |
465 | */ |
418 | for (xt = x - 2; xt <= x + 2; xt++) |
466 | for (xt = x - 2; xt <= x + 2; xt++) |
419 | for (yt = y - 2; yt <= y + 2; yt++) |
467 | for (yt = y - 2; yt <= y + 2; yt++) |
420 | { |
|
|
421 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
468 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
422 | fix_walls (pl->map, xt, yt); |
469 | fix_walls (pl->map, xt, yt); |
423 | } |
|
|
424 | |
470 | |
425 | /* Now remove raw item from inventory */ |
471 | /* Now remove raw item from inventory */ |
426 | material->decrease (); |
472 | material->decrease (); |
427 | |
473 | |
428 | /* And tell player about the fix */ |
474 | /* And tell player about the fix */ |
429 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
475 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
430 | } |
|
|
431 | |
|
|
432 | /** |
|
|
433 | * Wall radius fix function |
|
|
434 | */ |
|
|
435 | void fix_walls_around (maptile *map, int x, int y) |
|
|
436 | { |
|
|
437 | for (int xt = x - 1; xt <= x + 1; xt++) |
|
|
438 | for (int yt = y - 1; yt <= y + 1; yt++) |
|
|
439 | { |
|
|
440 | if (OUT_OF_REAL_MAP (map, xt, yt)) |
|
|
441 | continue; |
|
|
442 | |
|
|
443 | fix_walls (map, xt, yt); |
|
|
444 | } |
|
|
445 | } |
476 | } |
446 | |
477 | |
447 | /** |
478 | /** |
448 | * Wall building function |
479 | * Wall building function |
449 | * |
480 | * |
450 | * Walls can be build: |
481 | * Walls can be build: |
451 | * - on a floor without anything else |
482 | * - on a floor without anything else |
452 | * - on an existing wall, with or without a floor |
483 | * - on an existing wall, with or without a floor |
453 | */ |
484 | */ |
454 | void |
485 | static void |
455 | apply_builder_wall (object *pl, object *material, short x, short y) |
486 | apply_builder_wall (object *pl, object *material, int x, int y) |
456 | { |
487 | { |
457 | object *current_wall; |
488 | object *current_wall; |
458 | object *tmp; |
489 | object *tmp; |
459 | int xt, yt; |
490 | int xt, yt; |
460 | struct archetype *new_wall; |
491 | struct archetype *new_wall; |
… | |
… | |
482 | { |
513 | { |
483 | 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); |
484 | return; |
515 | return; |
485 | } |
516 | } |
486 | |
517 | |
487 | tmp = arch_to_object (new_wall); |
518 | tmp = new_wall->instance (); |
488 | tmp->type = BUILDABLE_WALL; |
519 | tmp->type = BUILDABLE_WALL; |
489 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
520 | tmp->set_flag (FLAG_IS_BUILDABLE); |
490 | 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); |
491 | |
522 | |
492 | /* If existing wall, remove it, no need to fix other walls */ |
523 | /* If existing wall, remove it, no need to fix other walls */ |
493 | if (current_wall) |
524 | if (current_wall) |
494 | { |
525 | { |
… | |
… | |
522 | * 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. |
523 | * Archetype of created object is item->slaying (raw material). |
554 | * Archetype of created object is item->slaying (raw material). |
524 | * Type of inserted item is tested for specific cases (doors & such). |
555 | * Type of inserted item is tested for specific cases (doors & such). |
525 | * 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) |
526 | */ |
557 | */ |
527 | void |
558 | static void |
528 | apply_builder_item (object *pl, object *item, short x, short y) |
559 | apply_builder_item (object *pl, object *item, int x, int y) |
529 | { |
560 | { |
530 | object *tmp; |
561 | object *tmp; |
531 | struct archetype *arch; |
562 | struct archetype *arch; |
532 | int insert_flag; |
563 | int insert_flag; |
533 | object *floor; |
564 | object *floor; |
… | |
… | |
539 | { |
570 | { |
540 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
571 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
541 | return; |
572 | return; |
542 | } |
573 | } |
543 | |
574 | |
544 | while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) |
575 | while (floor && !IS_FLOOR (floor)) |
545 | floor = floor->above; |
576 | floor = floor->above; |
546 | |
577 | |
547 | if (!floor) |
578 | if (!floor) |
548 | { |
579 | { |
549 | 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."); |
… | |
… | |
552 | /* Create item, set flag, insert in map */ |
583 | /* Create item, set flag, insert in map */ |
553 | arch = archetype::find (item->slaying); |
584 | arch = archetype::find (item->slaying); |
554 | if (!arch) |
585 | if (!arch) |
555 | return; |
586 | return; |
556 | |
587 | |
557 | tmp = arch_to_object (arch); |
588 | tmp = arch->instance (); |
558 | |
589 | |
559 | 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)) |
560 | /* Floor has something on top that interferes with building */ |
591 | /* Floor has something on top that interferes with building */ |
561 | { |
592 | { |
562 | 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."); |
563 | return; |
594 | return; |
564 | } |
595 | } |
565 | |
596 | |
566 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
597 | tmp->set_flag (FLAG_IS_BUILDABLE); |
567 | SET_FLAG (tmp, FLAG_NO_PICK); |
598 | tmp->set_flag (FLAG_NO_PICK); |
568 | |
599 | |
569 | /* |
600 | /* |
570 | * 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. |
571 | * 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, |
572 | * so make the item itself unique in this situation. |
603 | * so make the item itself unique in this situation. |
573 | */ |
604 | */ |
574 | 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; |
575 | if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) |
606 | if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) |
576 | SET_FLAG (tmp, FLAG_UNIQUE); |
607 | tmp->set_flag (FLAG_UNIQUE); |
577 | |
608 | |
578 | shstr_tmp connected; |
609 | shstr_tmp connected; |
579 | |
610 | |
580 | switch (tmp->type) |
611 | switch (tmp->type) |
581 | { |
612 | { |
… | |
… | |
605 | con_rune->destroy (); |
636 | con_rune->destroy (); |
606 | } |
637 | } |
607 | |
638 | |
608 | /* 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 */ |
609 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
640 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
610 | { |
|
|
611 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
641 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
612 | { |
642 | { |
613 | tmp->destroy (); |
643 | tmp->destroy (); |
614 | return; |
644 | return; |
615 | } |
645 | } |
616 | } |
|
|
617 | |
646 | |
618 | 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); |
619 | if (connected) |
648 | if (connected) |
620 | tmp->add_link (pl->map, connected); |
649 | tmp->add_link (pl->map, connected); |
621 | |
650 | |
… | |
… | |
626 | /** |
655 | /** |
627 | * Item remover. |
656 | * Item remover. |
628 | * |
657 | * |
629 | * Removes first buildable item, either under or above the floor |
658 | * Removes first buildable item, either under or above the floor |
630 | */ |
659 | */ |
631 | void |
660 | static void |
632 | apply_builder_remove (object *pl, int dir) |
661 | apply_builder_remove (object *pl, int dir) |
633 | { |
662 | { |
634 | object *item; |
663 | object *item; |
635 | short x, y; |
664 | int x, y; |
636 | |
665 | |
637 | x = pl->x + freearr_x[dir]; |
666 | x = pl->x + freearr_x[dir]; |
638 | y = pl->y + freearr_y[dir]; |
667 | y = pl->y + freearr_y[dir]; |
639 | |
668 | |
640 | /* Check square */ |
669 | /* Check square */ |
… | |
… | |
645 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
674 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
646 | 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); |
647 | return; |
676 | return; |
648 | } |
677 | } |
649 | |
678 | |
650 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
679 | if (IS_FLOOR (item)) |
651 | item = item->above; |
680 | item = item->above; |
652 | |
681 | |
653 | if (!item) |
682 | if (!item) |
654 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
683 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
655 | else if (item->type == BUILDABLE_WALL) |
684 | else if (item->type == BUILDABLE_WALL) |
… | |
… | |
670 | * or remover object. |
699 | * or remover object. |
671 | */ |
700 | */ |
672 | void |
701 | void |
673 | apply_map_builder (object *pl, int dir) |
702 | apply_map_builder (object *pl, int dir) |
674 | { |
703 | { |
675 | object *builder; |
704 | object *builder = 0; |
676 | object *tmp; |
705 | object *tmp = 0; |
677 | object *tmp2; |
706 | object *tmp2 = 0; |
678 | short x, y; |
707 | int x, y; |
679 | |
708 | |
680 | if (!pl->type == PLAYER) |
709 | if (!pl->type == PLAYER) |
681 | return; |
710 | return; |
682 | |
711 | |
683 | /*if ( !player->map->unique ) |
712 | /*if ( !player->map->unique ) |
… | |
… | |
715 | LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); |
744 | LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); |
716 | new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); |
745 | new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); |
717 | return; |
746 | return; |
718 | } |
747 | } |
719 | |
748 | |
|
|
749 | if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y))) |
|
|
750 | return; |
|
|
751 | |
720 | tmp2 = find_marked_object (pl); |
752 | tmp2 = find_marked_object (pl); |
721 | while (tmp) |
753 | while (tmp) |
722 | { |
754 | { |
723 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
755 | if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
724 | { |
756 | { |
725 | /* The item building function already has it's own special |
757 | /* The item building function already has it's own special |
726 | * checks for this |
758 | * checks for this |
727 | */ |
759 | */ |
728 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
760 | if (!tmp2 || tmp2->subtype != ST_MAT_ITEM) |
729 | { |
761 | { |
730 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
762 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
731 | return; |
763 | return; |
732 | } |
764 | } |
733 | } |
765 | } |
|
|
766 | |
734 | tmp = tmp->above; |
767 | tmp = tmp->above; |
735 | } |
768 | } |
736 | |
769 | |
737 | /* Now we know the square is ok */ |
770 | /* Now we know the square is ok */ |
738 | builder = pl->contr->ranged_ob; |
771 | builder = pl->contr->ranged_ob; |
… | |
… | |
763 | return; |
796 | return; |
764 | } |
797 | } |
765 | |
798 | |
766 | switch (tmp->subtype) |
799 | switch (tmp->subtype) |
767 | { |
800 | { |
768 | case ST_MAT_FLOOR: |
801 | case ST_MAT_FLOOR: |
769 | apply_builder_floor (pl, tmp, x, y); |
802 | apply_builder_floor (pl, tmp, x, y); |
770 | return; |
803 | return; |
771 | |
804 | |
772 | case ST_MAT_WALL: |
805 | case ST_MAT_WALL: |
773 | apply_builder_wall (pl, tmp, x, y); |
806 | apply_builder_wall (pl, tmp, x, y); |
774 | return; |
807 | return; |
775 | |
808 | |
776 | case ST_MAT_ITEM: |
809 | case ST_MAT_ITEM: |
777 | apply_builder_item (pl, tmp, x, y); |
810 | apply_builder_item (pl, tmp, x, y); |
778 | return; |
811 | return; |
779 | |
812 | |
780 | default: |
813 | default: |
781 | 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."); |
782 | 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); |
783 | return; |
816 | return; |
784 | } |
817 | } |
785 | } |
818 | } |
786 | |
819 | |
787 | /* Here, it means the builder has an invalid type */ |
820 | /* Here, it means the builder has an invalid type */ |
788 | 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."); |
789 | 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); |
790 | } |
823 | } |
791 | |
824 | |
792 | /** |
|
|
793 | * Make the built object inherit the msg of books that are used with it. |
|
|
794 | * For objects already invisible (i.e. magic mouths & ears), also make it |
|
|
795 | * it inherit the face and the name with "talking " prepended. |
|
|
796 | */ |
|
|
797 | int |
|
|
798 | adjust_sign_msg (object *pl, short x, short y, object *tmp) |
|
|
799 | { |
|
|
800 | object *book; |
|
|
801 | char buf[MAX_BUF]; |
|
|
802 | char buf2[MAX_BUF]; |
|
|
803 | |
|
|
804 | book = get_msg_book (pl, x, y); |
|
|
805 | if (!book) |
|
|
806 | { |
|
|
807 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message."); |
|
|
808 | return -1; |
|
|
809 | } |
|
|
810 | |
|
|
811 | tmp->msg = book->msg; |
|
|
812 | |
|
|
813 | if (tmp->invisible) |
|
|
814 | { |
|
|
815 | if (book->custom_name != NULL) |
|
|
816 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
|
|
817 | else |
|
|
818 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
|
|
819 | |
|
|
820 | tmp->name = buf; |
|
|
821 | |
|
|
822 | if (book->name_pl != NULL) |
|
|
823 | { |
|
|
824 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
|
|
825 | tmp->name_pl = buf2; |
|
|
826 | } |
|
|
827 | |
|
|
828 | tmp->face = book->face; |
|
|
829 | tmp->invisible = 0; |
|
|
830 | } |
|
|
831 | |
|
|
832 | book->destroy (); |
|
|
833 | return 0; |
|
|
834 | } |
|
|