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.11 by root, Tue Dec 12 20:53:03 2006 UTC vs.
Revision 1.29 by elmex, Sun Jul 29 06:46:39 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT 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 3 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, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20
21 The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <living.h> 25#include <living.h>
26#include <spells.h> 26#include <spells.h>
27#include <skills.h> 27#include <skills.h>
38 38
39 ob = GET_MAP_OB (map, x, y); 39 ob = GET_MAP_OB (map, x, y);
40 while (ob) 40 while (ob)
41 { 41 {
42 /* if ob is not a marking rune or floor, then check special cases */ 42 /* if ob is not a marking rune or floor, then check special cases */
43 if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) 43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR)
44 { 44 {
45 switch (tmp->type) 45 switch (tmp->type)
46 { 46 {
47 case SIGN: 47 case SIGN:
48 case MAGIC_EAR: 48 case MAGIC_EAR:
82 82
83 rune = GET_MAP_OB (map, x, y); 83 rune = GET_MAP_OB (map, x, y);
84 while (rune) 84 while (rune)
85 { 85 {
86 next = rune->above; 86 next = rune->above;
87
87 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 88 if ((rune->type == SIGN) && (!strcmp (rune->arch->archname, "rune_mark")))
88 {
89 rune->remove ();
90 rune->destroy (0); 89 rune->destroy ();
91 } 90
92 rune = next; 91 rune = next;
93 } 92 }
94} 93}
95 94
96/** 95/**
146 } 145 }
147 146
148 /* Now, find force in player's inventory */ 147 /* Now, find force in player's inventory */
149 force = pl->inv; 148 force = pl->inv;
150 while (force 149 while (force
151 && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) 150 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
152 || (strcmp (force->msg, rune->msg)))) 151 || force->msg != rune->msg))
153 force = force->below; 152 force = force->below;
154 153
155 if (!force) 154 if (!force)
156 /* No force, need to create & insert one */ 155 /* No force, need to create & insert one */
157 { 156 {
162 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 161 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
163 return -1; 162 return -1;
164 } 163 }
165 164
166 force = get_archetype (FORCE_NAME); 165 force = get_archetype (FORCE_NAME);
167 force->speed = 0;
168 update_ob_speed (force);
169 force->slaying = pl->map->path; 166 force->slaying = pl->map->path;
170 force->msg = rune->msg; 167 force->msg = rune->msg;
171 force->path_attuned = connected; 168 force->path_attuned = connected;
169 force->set_speed (0);
172 insert_ob_in_ob (force, pl); 170 insert_ob_in_ob (force, pl);
173 171
174 return connected; 172 return connected;
175 } 173 }
176 174
185get_connection_rune (object *pl, short x, short y) 183get_connection_rune (object *pl, short x, short y)
186{ 184{
187 object *rune; 185 object *rune;
188 186
189 rune = GET_MAP_OB (pl->map, x, y); 187 rune = GET_MAP_OB (pl->map, x, y);
190 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) 188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark"))))
191 rune = rune->above; 189 rune = rune->above;
192 return rune; 190 return rune;
193} 191}
194 192
195/** 193/**
205 book = book->above; 203 book = book->above;
206 return book; 204 return book;
207} 205}
208 206
209/** 207/**
210 * Returns first item of type WALL. 208 * Returns first item of type BUILDABLE_WALL.
211 */ 209 */
212object * 210object *
213get_wall (maptile *map, int x, int y) 211get_wall (maptile *map, int x, int y)
214{ 212{
215 object *wall; 213 object *wall;
216 214
217 wall = GET_MAP_OB (map, x, y); 215 wall = GET_MAP_OB (map, x, y);
218 while (wall && (WALL != wall->type)) 216 while (wall && (BUILDABLE_WALL != wall->type))
219 wall = wall->above; 217 wall = wall->above;
220 218
221 return wall; 219 return wall;
222} 220}
223 221
233 * Note: x & y must be valid map coordinates. 231 * Note: x & y must be valid map coordinates.
234 */ 232 */
235void 233void
236fix_walls (maptile *map, int x, int y) 234fix_walls (maptile *map, int x, int y)
237{ 235{
238 int connect;
239 object *wall; 236 object *wall;
240 char archetype[MAX_BUF]; 237 char archetype[MAX_BUF];
241 char *underscore; 238 char *underscore;
242 uint32 old_flags[4];
243 struct archetype *new_arch; 239 struct archetype *new_arch;
244 int flag;
245 240
246 241
247 /* First, find the wall on that spot */ 242 /* First, find the wall on that spot */
248 wall = get_wall (map, x, y); 243 wall = get_wall (map, x, y);
249 if (!wall) 244 if (!wall)
250 /* Nothing -> bail out */ 245 /* Nothing -> bail out */
251 return; 246 return;
252 247
253 /* Find base name */ 248 /* Find base name */
254 strcpy (archetype, wall->arch->name); 249 assign (archetype, wall->arch->archname);
255 underscore = strchr (archetype, '_'); 250 underscore = strchr (archetype, '_');
256 251
257 /* search for the first _ before a number */ 252 /* search for the first _ before a number */
258 while (underscore && !isdigit (*(underscore + 1))) 253 while (underscore && !isdigit (*(underscore + 1)))
259 underscore = strchr (underscore + 1, '_'); 254 underscore = strchr (underscore + 1, '_');
263 return; 258 return;
264 259
265 underscore++; 260 underscore++;
266 *underscore = '\0'; 261 *underscore = '\0';
267 262
268 connect = 0; 263 int connect = 0;
269 264
270 if ((x > 0) && get_wall (map, x - 1, y)) 265 if ((x > 0) && get_wall (map, x - 1, y))
271 connect |= 1; 266 connect |= 1;
272 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 267 if ((x < map->width - 1) && get_wall (map, x + 1, y))
273 connect |= 2; 268 connect |= 2;
274 269
275 if ((y > 0) && get_wall (map, x, y - 1)) 270 if ((y > 0) && get_wall (map, x, y - 1))
276 connect |= 4; 271 connect |= 4;
277 272
278 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 273 if ((y < map->height - 1) && get_wall (map, x, y + 1))
279 connect |= 8; 274 connect |= 8;
280 275
281 switch (connect) 276 switch (connect)
282 { 277 {
283 case 0: 278 case 0:
356 return; 351 return;
357 352
358 /* Now delete current wall, and insert new one 353 /* Now delete current wall, and insert new one
359 * We save flags to avoid any trouble with buildable/non buildable, and so on 354 * We save flags to avoid any trouble with buildable/non buildable, and so on
360 */ 355 */
361 for (flag = 0; flag < 4; flag++) 356 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
362 old_flags[flag] = wall->flags[flag]; 357
363 wall->remove ();
364 wall->destroy (0); 358 wall->destroy ();
365 359
366 wall = arch_to_object (new_arch); 360 wall = arch_to_object (new_arch);
367 wall->type = WALL; 361 wall->type = BUILDABLE_WALL;
368 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 362 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
369 for (flag = 0; flag < 4; flag++)
370 wall->flags[flag] = old_flags[flag]; 363 wall->flag = old_flags;
371} 364}
372 365
373/** 366/**
374 * \brief Floor building function 367 * \brief Floor building function
375 * 368 *
403 if (tmp) 396 if (tmp)
404 { 397 {
405 while (tmp) 398 while (tmp)
406 { 399 {
407 above = tmp->above; 400 above = tmp->above;
408 if (WALL == tmp->type) 401 if (BUILDABLE_WALL == tmp->type)
409 { 402 {
410 /* There was a wall, remove it & keep its archetype to make new walls */ 403 /* There was a wall, remove it & keep its archetype to make new walls */
411 new_wall = tmp->arch; 404 new_wall = tmp->arch;
412 tmp->remove ();
413 tmp->destroy (0); 405 tmp->destroy ();
414 sprintf (message, "You destroy the wall and redo the floor."); 406 sprintf (message, "You destroy the wall and redo the floor.");
415 } 407 }
416 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 408 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
417 { 409 {
418 tmp->remove ();
419 tmp->destroy (0); 410 tmp->destroy ();
420 floor_removed = 1; 411 floor_removed = 1;
421 } 412 }
422 else 413 else
423 { 414 {
424 if (floor_removed) 415 if (floor_removed)
466 /* Insert wall if exists. Note: if it doesn't, the map is weird... */ 457 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
467 if (new_wall) 458 if (new_wall)
468 { 459 {
469 tmp = arch_to_object (new_wall); 460 tmp = arch_to_object (new_wall);
470 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 461 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
471 tmp->type = WALL; 462 tmp->type = BUILDABLE_WALL;
472 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 463 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
473 } 464 }
474 } 465 }
475 } 466 }
476 467
528 /* Grab existing wall, if any */ 519 /* Grab existing wall, if any */
529 current_wall = NULL; 520 current_wall = NULL;
530 tmp = GET_MAP_OB (pl->map, x, y); 521 tmp = GET_MAP_OB (pl->map, x, y);
531 while (tmp && !current_wall) 522 while (tmp && !current_wall)
532 { 523 {
533 if (WALL == tmp->type) 524 if (BUILDABLE_WALL == tmp->type)
534 current_wall = tmp; 525 current_wall = tmp;
535 526
536 tmp = tmp->above; 527 tmp = tmp->above;
537 } 528 }
538 529
546 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); 537 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
547 return; 538 return;
548 } 539 }
549 540
550 tmp = arch_to_object (new_wall); 541 tmp = arch_to_object (new_wall);
551 tmp->type = WALL; 542 tmp->type = BUILDABLE_WALL;
552 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 543 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
553 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 544 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
554 545
555 /* If existing wall, remove it, no need to fix other walls */ 546 /* If existing wall, remove it, no need to fix other walls */
556 if (current_wall) 547 if (current_wall)
557 { 548 {
558 current_wall->remove ();
559 current_wall->destroy (0); 549 current_wall->destroy ();
560 fix_walls (pl->map, x, y); 550 fix_walls (pl->map, x, y);
561 sprintf (message, "You redecorate the wall to better suit your tastes."); 551 sprintf (message, "You redecorate the wall to better suit your tastes.");
562 } 552 }
563 else 553 else
564 { 554 {
619 if (!arch) 609 if (!arch)
620 return; 610 return;
621 611
622 tmp = arch_to_object (arch); 612 tmp = arch_to_object (arch);
623 613
624 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 614 if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y)))
625 /* Floor has something on top that interferes with building */ 615 /* Floor has something on top that interferes with building */
626 { 616 {
627 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 617 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
628 return; 618 return;
629 } 619 }
648 case PEDESTAL: 638 case PEDESTAL:
649 case CF_HANDLE: 639 case CF_HANDLE:
650 case MAGIC_EAR: 640 case MAGIC_EAR:
651 case SIGN: 641 case SIGN:
652 /* Signs don't need a connection, but but magic mouths do. */ 642 /* Signs don't need a connection, but but magic mouths do. */
653 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 643 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth"))
654 break; 644 break;
655 con_rune = get_connection_rune (pl, x, y); 645 con_rune = get_connection_rune (pl, x, y);
656 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 646 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
657 if (connected == -1) 647 if (connected == -1)
658 { 648 {
659 /* Player already informed of failure by the previous function */ 649 /* Player already informed of failure by the previous function */
660 tmp->destroy (0); 650 tmp->destroy ();
661 return; 651 return;
662 } 652 }
663 /* Remove marking rune */ 653 /* Remove marking rune */
664 con_rune->remove ();
665 con_rune->destroy (0); 654 con_rune->destroy ();
666 } 655 }
667 656
668 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 657 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
669 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
670 { 659 {
671 if (adjust_sign_msg (pl, x, y, tmp) == -1) 660 if (adjust_sign_msg (pl, x, y, tmp) == -1)
672 { 661 {
673 tmp->destroy (0); 662 tmp->destroy ();
674 return; 663 return;
675 } 664 }
676 } 665 }
677 666
678 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 667 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
701 item = GET_MAP_OB (pl->map, x, y); 690 item = GET_MAP_OB (pl->map, x, y);
702 if (!item) 691 if (!item)
703 { 692 {
704 /* Should not happen with previous tests, but we never know */ 693 /* Should not happen with previous tests, but we never know */
705 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 694 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
706 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path); 695 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
707 return; 696 return;
708 } 697 }
709 698
710 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 699 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
711 item = item->above; 700 item = item->above;
712 701
713 if (!item) 702 if (!item)
714 {
715 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 703 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
716 return; 704 else if (item->type == BUILDABLE_WALL)
717 }
718
719 /* Now remove object, with special cases (buttons & such) */
720 switch (item->type)
721 {
722 case WALL:
723 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); 705 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
724 return; 706 else if (!item->flag [FLAG_IS_BUILDABLE])
725 707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
726 case DOOR: 708 else
727 case BUTTON: 709 {
728 case GATE:
729 case TIMED_GATE:
730 case DETECTOR:
731 case PEDESTAL:
732 case CF_HANDLE:
733 case MAGIC_EAR:
734 case SIGN:
735 /* Special case: must unconnect */
736 if (QUERY_FLAG (item, FLAG_IS_LINKED))
737 remove_button_link (item);
738
739 /* Fall through */
740
741 default:
742 /* Remove generic item */
743 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); 710 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
744 item->remove ();
745 item->destroy (0); 711 item->destroy ();
746 } 712 }
747} 713}
748 714
749/** 715/**
750 * Global building function 716 * Global building function
776 } 742 }
777 743
778 x = pl->x + freearr_x[dir]; 744 x = pl->x + freearr_x[dir];
779 y = pl->y + freearr_y[dir]; 745 y = pl->y + freearr_y[dir];
780 746
781 if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) 747 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
782 { 748 {
783 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 749 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
784 return; 750 return;
785 } 751 }
786 752
793 759
794 tmp = GET_MAP_OB (pl->map, x, y); 760 tmp = GET_MAP_OB (pl->map, x, y);
795 if (!tmp) 761 if (!tmp)
796 { 762 {
797 /* Nothing, meaning player is standing next to an undefined square... */ 763 /* Nothing, meaning player is standing next to an undefined square... */
798 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, pl->map->path); 764 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
799 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 765 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
800 return; 766 return;
801 } 767 }
768
802 tmp2 = find_marked_object (pl); 769 tmp2 = find_marked_object (pl);
803 while (tmp) 770 while (tmp)
804 { 771 {
805 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->name, "rune_mark")))) 772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark"))))
806 { 773 {
807 /* The item building function already has it's own special 774 /* The item building function already has it's own special
808 * checks for this 775 * checks for this
809 */ 776 */
810 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
815 } 782 }
816 tmp = tmp->above; 783 tmp = tmp->above;
817 } 784 }
818 785
819 /* Now we know the square is ok */ 786 /* Now we know the square is ok */
820 builder = pl->contr->ranges[range_builder]; 787 builder = pl->contr->ranged_ob;
821 788
822 if (builder->subtype == ST_BD_REMOVE) 789 if (builder->subtype == ST_BD_REMOVE)
823 /* Remover -> call specific function and bail out */ 790 /* Remover -> call specific function and bail out */
824 { 791 {
825 apply_builder_remove (pl, dir); 792 apply_builder_remove (pl, dir);
911 } 878 }
912 879
913 tmp->face = book->face; 880 tmp->face = book->face;
914 tmp->invisible = 0; 881 tmp->invisible = 0;
915 } 882 }
916 book->remove (); 883
917 book->destroy (0); 884 book->destroy ();
918 return 0; 885 return 0;
919} 886}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines