1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <living.h> |
26 | #include <living.h> |
26 | #include <spells.h> |
27 | #include <spells.h> |
27 | #include <skills.h> |
28 | #include <skills.h> |
… | |
… | |
82 | |
83 | |
83 | rune = GET_MAP_OB (map, x, y); |
84 | rune = GET_MAP_OB (map, x, y); |
84 | while (rune) |
85 | while (rune) |
85 | { |
86 | { |
86 | next = rune->above; |
87 | next = rune->above; |
|
|
88 | |
87 | if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) |
89 | if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) |
88 | { |
90 | rune->destroy (); |
89 | remove_ob (rune); |
91 | |
90 | free_object (rune); |
|
|
91 | } |
|
|
92 | rune = next; |
92 | rune = next; |
93 | } |
93 | } |
94 | } |
94 | } |
95 | |
95 | |
96 | /** |
96 | /** |
… | |
… | |
146 | } |
146 | } |
147 | |
147 | |
148 | /* Now, find force in player's inventory */ |
148 | /* Now, find force in player's inventory */ |
149 | force = pl->inv; |
149 | force = pl->inv; |
150 | while (force |
150 | while (force |
151 | && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) |
151 | && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg |
152 | || (strcmp (force->msg, rune->msg)))) |
152 | || force->msg != rune->msg)) |
153 | force = force->below; |
153 | force = force->below; |
154 | |
154 | |
155 | if (!force) |
155 | if (!force) |
156 | /* No force, need to create & insert one */ |
156 | /* No force, need to create & insert one */ |
157 | { |
157 | { |
… | |
… | |
162 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
162 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
163 | return -1; |
163 | return -1; |
164 | } |
164 | } |
165 | |
165 | |
166 | force = get_archetype (FORCE_NAME); |
166 | force = get_archetype (FORCE_NAME); |
167 | force->speed = 0; |
|
|
168 | update_ob_speed (force); |
|
|
169 | force->slaying = pl->map->path; |
167 | force->slaying = pl->map->path; |
170 | force->msg = rune->msg; |
168 | force->msg = rune->msg; |
171 | force->path_attuned = connected; |
169 | force->path_attuned = connected; |
|
|
170 | force->set_speed (0); |
172 | insert_ob_in_ob (force, pl); |
171 | insert_ob_in_ob (force, pl); |
173 | |
172 | |
174 | return connected; |
173 | return connected; |
175 | } |
174 | } |
176 | |
175 | |
… | |
… | |
205 | book = book->above; |
204 | book = book->above; |
206 | return book; |
205 | return book; |
207 | } |
206 | } |
208 | |
207 | |
209 | /** |
208 | /** |
210 | * Returns first item of type WALL. |
209 | * Returns first item of type BUILDABLE_WALL. |
211 | */ |
210 | */ |
212 | object * |
211 | object * |
213 | get_wall (maptile *map, int x, int y) |
212 | get_wall (maptile *map, int x, int y) |
214 | { |
213 | { |
215 | object *wall; |
214 | object *wall; |
216 | |
215 | |
217 | wall = GET_MAP_OB (map, x, y); |
216 | wall = GET_MAP_OB (map, x, y); |
218 | while (wall && (WALL != wall->type)) |
217 | while (wall && (BUILDABLE_WALL != wall->type)) |
219 | { |
|
|
220 | wall = wall->above; |
218 | wall = wall->above; |
221 | } |
|
|
222 | |
219 | |
223 | return wall; |
220 | return wall; |
224 | } |
221 | } |
225 | |
222 | |
226 | /** |
223 | /** |
… | |
… | |
235 | * Note: x & y must be valid map coordinates. |
232 | * Note: x & y must be valid map coordinates. |
236 | */ |
233 | */ |
237 | void |
234 | void |
238 | fix_walls (maptile *map, int x, int y) |
235 | fix_walls (maptile *map, int x, int y) |
239 | { |
236 | { |
240 | int connect; |
|
|
241 | object *wall; |
237 | object *wall; |
242 | char archetype[MAX_BUF]; |
238 | char archetype[MAX_BUF]; |
243 | char *underscore; |
239 | char *underscore; |
244 | uint32 old_flags[4]; |
|
|
245 | struct archetype *new_arch; |
240 | struct archetype *new_arch; |
246 | int flag; |
|
|
247 | |
241 | |
248 | |
242 | |
249 | /* First, find the wall on that spot */ |
243 | /* First, find the wall on that spot */ |
250 | wall = get_wall (map, x, y); |
244 | wall = get_wall (map, x, y); |
251 | if (!wall) |
245 | if (!wall) |
252 | /* Nothing -> bail out */ |
246 | /* Nothing -> bail out */ |
253 | return; |
247 | return; |
254 | |
248 | |
255 | /* Find base name */ |
249 | /* Find base name */ |
256 | strcpy (archetype, wall->arch->name); |
250 | assign (archetype, wall->arch->name); |
257 | underscore = strchr (archetype, '_'); |
251 | underscore = strchr (archetype, '_'); |
258 | |
252 | |
|
|
253 | /* search for the first _ before a number */ |
|
|
254 | while (underscore && !isdigit (*(underscore + 1))) |
|
|
255 | underscore = strchr (underscore + 1, '_'); |
|
|
256 | |
259 | if (!underscore || (!isdigit (*(underscore + 1)))) |
257 | if (!underscore || !isdigit (*(underscore + 1))) |
260 | /* Not in a format we can change, bail out */ |
258 | /* Not in a format we can change, bail out */ |
261 | return; |
259 | return; |
262 | |
260 | |
263 | underscore++; |
261 | underscore++; |
264 | *underscore = '\0'; |
262 | *underscore = '\0'; |
265 | |
263 | |
266 | connect = 0; |
264 | int connect = 0; |
267 | |
265 | |
268 | if ((x > 0) && get_wall (map, x - 1, y)) |
266 | if ((x > 0) && get_wall (map, x - 1, y)) |
269 | connect |= 1; |
267 | connect |= 1; |
270 | if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) |
268 | if ((x < map->width - 1) && get_wall (map, x + 1, y)) |
271 | connect |= 2; |
269 | connect |= 2; |
272 | |
270 | |
273 | if ((y > 0) && get_wall (map, x, y - 1)) |
271 | if ((y > 0) && get_wall (map, x, y - 1)) |
274 | connect |= 4; |
272 | connect |= 4; |
275 | |
273 | |
276 | if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) |
274 | if ((y < map->height - 1) && get_wall (map, x, y + 1)) |
277 | connect |= 8; |
275 | connect |= 8; |
278 | |
276 | |
279 | switch (connect) |
277 | switch (connect) |
280 | { |
278 | { |
281 | case 0: |
279 | case 0: |
… | |
… | |
354 | return; |
352 | return; |
355 | |
353 | |
356 | /* Now delete current wall, and insert new one |
354 | /* Now delete current wall, and insert new one |
357 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
355 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
358 | */ |
356 | */ |
359 | for (flag = 0; flag < 4; flag++) |
357 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
360 | old_flags[flag] = wall->flags[flag]; |
358 | |
361 | remove_ob (wall); |
359 | wall->destroy (); |
362 | free_object (wall); |
|
|
363 | |
360 | |
364 | wall = arch_to_object (new_arch); |
361 | wall = arch_to_object (new_arch); |
365 | wall->type = WALL; |
362 | wall->type = BUILDABLE_WALL; |
366 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
363 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
367 | for (flag = 0; flag < 4; flag++) |
|
|
368 | wall->flags[flag] = old_flags[flag]; |
364 | wall->flag = old_flags; |
369 | } |
365 | } |
370 | |
366 | |
371 | /** |
367 | /** |
372 | * \brief Floor building function |
368 | * \brief Floor building function |
373 | * |
369 | * |
… | |
… | |
401 | if (tmp) |
397 | if (tmp) |
402 | { |
398 | { |
403 | while (tmp) |
399 | while (tmp) |
404 | { |
400 | { |
405 | above = tmp->above; |
401 | above = tmp->above; |
406 | if (WALL == tmp->type) |
402 | if (BUILDABLE_WALL == tmp->type) |
407 | { |
403 | { |
408 | /* There was a wall, remove it & keep its archetype to make new walls */ |
404 | /* There was a wall, remove it & keep its archetype to make new walls */ |
409 | new_wall = tmp->arch; |
405 | new_wall = tmp->arch; |
410 | remove_ob (tmp); |
406 | tmp->destroy (); |
411 | free_object (tmp); |
|
|
412 | sprintf (message, "You destroy the wall and redo the floor."); |
407 | sprintf (message, "You destroy the wall and redo the floor."); |
413 | } |
408 | } |
414 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
409 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
415 | { |
410 | { |
416 | remove_ob (tmp); |
411 | tmp->destroy (); |
417 | free_object (tmp); |
|
|
418 | floor_removed = 1; |
412 | floor_removed = 1; |
419 | } |
413 | } |
420 | else |
414 | else |
421 | { |
415 | { |
422 | if (floor_removed) |
416 | if (floor_removed) |
… | |
… | |
464 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
458 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
465 | if (new_wall) |
459 | if (new_wall) |
466 | { |
460 | { |
467 | tmp = arch_to_object (new_wall); |
461 | tmp = arch_to_object (new_wall); |
468 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
462 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
469 | tmp->type = WALL; |
463 | tmp->type = BUILDABLE_WALL; |
470 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
464 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
471 | } |
465 | } |
472 | } |
466 | } |
473 | } |
467 | } |
474 | |
468 | |
… | |
… | |
526 | /* Grab existing wall, if any */ |
520 | /* Grab existing wall, if any */ |
527 | current_wall = NULL; |
521 | current_wall = NULL; |
528 | tmp = GET_MAP_OB (pl->map, x, y); |
522 | tmp = GET_MAP_OB (pl->map, x, y); |
529 | while (tmp && !current_wall) |
523 | while (tmp && !current_wall) |
530 | { |
524 | { |
531 | if (WALL == tmp->type) |
525 | if (BUILDABLE_WALL == tmp->type) |
532 | current_wall = tmp; |
526 | current_wall = tmp; |
533 | |
527 | |
534 | tmp = tmp->above; |
528 | tmp = tmp->above; |
535 | } |
529 | } |
536 | |
530 | |
… | |
… | |
544 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
538 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
545 | return; |
539 | return; |
546 | } |
540 | } |
547 | |
541 | |
548 | tmp = arch_to_object (new_wall); |
542 | tmp = arch_to_object (new_wall); |
549 | tmp->type = WALL; |
543 | tmp->type = BUILDABLE_WALL; |
550 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
544 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
551 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
545 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
552 | |
546 | |
553 | /* If existing wall, remove it, no need to fix other walls */ |
547 | /* If existing wall, remove it, no need to fix other walls */ |
554 | if (current_wall) |
548 | if (current_wall) |
555 | { |
549 | { |
556 | remove_ob (current_wall); |
550 | current_wall->destroy (); |
557 | free_object (current_wall); |
|
|
558 | fix_walls (pl->map, x, y); |
551 | fix_walls (pl->map, x, y); |
559 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
552 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
560 | } |
553 | } |
561 | else |
554 | else |
562 | { |
555 | { |
… | |
… | |
653 | con_rune = get_connection_rune (pl, x, y); |
646 | con_rune = get_connection_rune (pl, x, y); |
654 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
647 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
655 | if (connected == -1) |
648 | if (connected == -1) |
656 | { |
649 | { |
657 | /* Player already informed of failure by the previous function */ |
650 | /* Player already informed of failure by the previous function */ |
658 | free_object (tmp); |
651 | tmp->destroy (); |
659 | return; |
652 | return; |
660 | } |
653 | } |
661 | /* Remove marking rune */ |
654 | /* Remove marking rune */ |
662 | remove_ob (con_rune); |
655 | con_rune->destroy (); |
663 | free_object (con_rune); |
|
|
664 | } |
656 | } |
665 | |
657 | |
666 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
658 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
667 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
659 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
668 | { |
660 | { |
669 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
661 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
670 | { |
662 | { |
671 | free_object (tmp); |
663 | tmp->destroy (); |
672 | return; |
664 | return; |
673 | } |
665 | } |
674 | } |
666 | } |
675 | |
667 | |
676 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
668 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
… | |
… | |
699 | item = GET_MAP_OB (pl->map, x, y); |
691 | item = GET_MAP_OB (pl->map, x, y); |
700 | if (!item) |
692 | if (!item) |
701 | { |
693 | { |
702 | /* Should not happen with previous tests, but we never know */ |
694 | /* Should not happen with previous tests, but we never know */ |
703 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
695 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
704 | LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path); |
696 | LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path); |
705 | return; |
697 | return; |
706 | } |
698 | } |
707 | |
699 | |
708 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
700 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
709 | item = item->above; |
701 | item = item->above; |
710 | |
702 | |
711 | if (!item) |
703 | if (!item) |
712 | { |
|
|
713 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
704 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
714 | return; |
705 | else if (item->type == BUILDABLE_WALL) |
715 | } |
|
|
716 | |
|
|
717 | /* Now remove object, with special cases (buttons & such) */ |
|
|
718 | switch (item->type) |
|
|
719 | { |
|
|
720 | case WALL: |
|
|
721 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); |
706 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); |
722 | return; |
707 | else if (!item->flag [FLAG_IS_BUILDABLE]) |
723 | |
708 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); |
724 | case DOOR: |
709 | else |
725 | case BUTTON: |
710 | { |
726 | case GATE: |
|
|
727 | case TIMED_GATE: |
|
|
728 | case DETECTOR: |
|
|
729 | case PEDESTAL: |
|
|
730 | case CF_HANDLE: |
|
|
731 | case MAGIC_EAR: |
|
|
732 | case SIGN: |
|
|
733 | /* Special case: must unconnect */ |
|
|
734 | if (QUERY_FLAG (item, FLAG_IS_LINKED)) |
|
|
735 | remove_button_link (item); |
|
|
736 | |
|
|
737 | /* Fall through */ |
|
|
738 | |
|
|
739 | default: |
|
|
740 | /* Remove generic item */ |
|
|
741 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
711 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
742 | remove_ob (item); |
712 | item->destroy (); |
743 | free_object (item); |
|
|
744 | } |
713 | } |
745 | } |
714 | } |
746 | |
715 | |
747 | /** |
716 | /** |
748 | * Global building function |
717 | * Global building function |
… | |
… | |
774 | } |
743 | } |
775 | |
744 | |
776 | x = pl->x + freearr_x[dir]; |
745 | x = pl->x + freearr_x[dir]; |
777 | y = pl->y + freearr_y[dir]; |
746 | y = pl->y + freearr_y[dir]; |
778 | |
747 | |
779 | if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) |
748 | if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) |
780 | { |
749 | { |
781 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
750 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
782 | return; |
751 | return; |
783 | } |
752 | } |
784 | |
753 | |
… | |
… | |
791 | |
760 | |
792 | tmp = GET_MAP_OB (pl->map, x, y); |
761 | tmp = GET_MAP_OB (pl->map, x, y); |
793 | if (!tmp) |
762 | if (!tmp) |
794 | { |
763 | { |
795 | /* Nothing, meaning player is standing next to an undefined square... */ |
764 | /* Nothing, meaning player is standing next to an undefined square... */ |
796 | LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, pl->map->path); |
765 | LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); |
797 | new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); |
766 | new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); |
798 | return; |
767 | return; |
799 | } |
768 | } |
800 | tmp2 = find_marked_object (pl); |
769 | tmp2 = find_marked_object (pl); |
801 | while (tmp) |
770 | while (tmp) |
… | |
… | |
909 | } |
878 | } |
910 | |
879 | |
911 | tmp->face = book->face; |
880 | tmp->face = book->face; |
912 | tmp->invisible = 0; |
881 | tmp->invisible = 0; |
913 | } |
882 | } |
914 | remove_ob (book); |
883 | |
915 | free_object (book); |
884 | book->destroy (); |
916 | return 0; |
885 | return 0; |
917 | } |
886 | } |