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.23 by root, Mon Feb 5 01:24:45 2007 UTC

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 {
89 rune->remove ();
90 rune->destroy (0); 90 rune->destroy ();
91 } 91
92 rune = next; 92 rune = next;
93 } 93 }
94} 94}
95 95
96/** 96/**
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 */
212object * 211object *
213get_wall (maptile *map, int x, int y) 212get_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 wall = wall->above; 218 wall = wall->above;
220 219
221 return wall; 220 return wall;
222} 221}
223 222
233 * Note: x & y must be valid map coordinates. 232 * Note: x & y must be valid map coordinates.
234 */ 233 */
235void 234void
236fix_walls (maptile *map, int x, int y) 235fix_walls (maptile *map, int x, int y)
237{ 236{
238 int connect;
239 object *wall; 237 object *wall;
240 char archetype[MAX_BUF]; 238 char archetype[MAX_BUF];
241 char *underscore; 239 char *underscore;
242 uint32 old_flags[4];
243 struct archetype *new_arch; 240 struct archetype *new_arch;
244 int flag;
245 241
246 242
247 /* First, find the wall on that spot */ 243 /* First, find the wall on that spot */
248 wall = get_wall (map, x, y); 244 wall = get_wall (map, x, y);
249 if (!wall) 245 if (!wall)
250 /* Nothing -> bail out */ 246 /* Nothing -> bail out */
251 return; 247 return;
252 248
253 /* Find base name */ 249 /* Find base name */
254 strcpy (archetype, wall->arch->name); 250 assign (archetype, wall->arch->name);
255 underscore = strchr (archetype, '_'); 251 underscore = strchr (archetype, '_');
256 252
257 /* search for the first _ before a number */ 253 /* search for the first _ before a number */
258 while (underscore && !isdigit (*(underscore + 1))) 254 while (underscore && !isdigit (*(underscore + 1)))
259 underscore = strchr (underscore + 1, '_'); 255 underscore = strchr (underscore + 1, '_');
263 return; 259 return;
264 260
265 underscore++; 261 underscore++;
266 *underscore = '\0'; 262 *underscore = '\0';
267 263
268 connect = 0; 264 int connect = 0;
269 265
270 if ((x > 0) && get_wall (map, x - 1, y)) 266 if ((x > 0) && get_wall (map, x - 1, y))
271 connect |= 1; 267 connect |= 1;
272 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 268 if ((x < map->width - 1) && get_wall (map, x + 1, y))
273 connect |= 2; 269 connect |= 2;
274 270
275 if ((y > 0) && get_wall (map, x, y - 1)) 271 if ((y > 0) && get_wall (map, x, y - 1))
276 connect |= 4; 272 connect |= 4;
277 273
278 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 274 if ((y < map->height - 1) && get_wall (map, x, y + 1))
279 connect |= 8; 275 connect |= 8;
280 276
281 switch (connect) 277 switch (connect)
282 { 278 {
283 case 0: 279 case 0:
356 return; 352 return;
357 353
358 /* Now delete current wall, and insert new one 354 /* Now delete current wall, and insert new one
359 * 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
360 */ 356 */
361 for (flag = 0; flag < 4; flag++) 357 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
362 old_flags[flag] = wall->flags[flag]; 358
363 wall->remove ();
364 wall->destroy (0); 359 wall->destroy ();
365 360
366 wall = arch_to_object (new_arch); 361 wall = arch_to_object (new_arch);
367 wall->type = WALL; 362 wall->type = BUILDABLE_WALL;
368 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);
369 for (flag = 0; flag < 4; flag++)
370 wall->flags[flag] = old_flags[flag]; 364 wall->flag = old_flags;
371} 365}
372 366
373/** 367/**
374 * \brief Floor building function 368 * \brief Floor building function
375 * 369 *
403 if (tmp) 397 if (tmp)
404 { 398 {
405 while (tmp) 399 while (tmp)
406 { 400 {
407 above = tmp->above; 401 above = tmp->above;
408 if (WALL == tmp->type) 402 if (BUILDABLE_WALL == tmp->type)
409 { 403 {
410 /* 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 */
411 new_wall = tmp->arch; 405 new_wall = tmp->arch;
412 tmp->remove ();
413 tmp->destroy (0); 406 tmp->destroy ();
414 sprintf (message, "You destroy the wall and redo the floor."); 407 sprintf (message, "You destroy the wall and redo the floor.");
415 } 408 }
416 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 409 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
417 { 410 {
418 tmp->remove ();
419 tmp->destroy (0); 411 tmp->destroy ();
420 floor_removed = 1; 412 floor_removed = 1;
421 } 413 }
422 else 414 else
423 { 415 {
424 if (floor_removed) 416 if (floor_removed)
466 /* 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... */
467 if (new_wall) 459 if (new_wall)
468 { 460 {
469 tmp = arch_to_object (new_wall); 461 tmp = arch_to_object (new_wall);
470 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 462 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
471 tmp->type = WALL; 463 tmp->type = BUILDABLE_WALL;
472 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);
473 } 465 }
474 } 466 }
475 } 467 }
476 468
528 /* Grab existing wall, if any */ 520 /* Grab existing wall, if any */
529 current_wall = NULL; 521 current_wall = NULL;
530 tmp = GET_MAP_OB (pl->map, x, y); 522 tmp = GET_MAP_OB (pl->map, x, y);
531 while (tmp && !current_wall) 523 while (tmp && !current_wall)
532 { 524 {
533 if (WALL == tmp->type) 525 if (BUILDABLE_WALL == tmp->type)
534 current_wall = tmp; 526 current_wall = tmp;
535 527
536 tmp = tmp->above; 528 tmp = tmp->above;
537 } 529 }
538 530
546 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);
547 return; 539 return;
548 } 540 }
549 541
550 tmp = arch_to_object (new_wall); 542 tmp = arch_to_object (new_wall);
551 tmp->type = WALL; 543 tmp->type = BUILDABLE_WALL;
552 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 544 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
553 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);
554 546
555 /* If existing wall, remove it, no need to fix other walls */ 547 /* If existing wall, remove it, no need to fix other walls */
556 if (current_wall) 548 if (current_wall)
557 { 549 {
558 current_wall->remove ();
559 current_wall->destroy (0); 550 current_wall->destroy ();
560 fix_walls (pl->map, x, y); 551 fix_walls (pl->map, x, y);
561 sprintf (message, "You redecorate the wall to better suit your tastes."); 552 sprintf (message, "You redecorate the wall to better suit your tastes.");
562 } 553 }
563 else 554 else
564 { 555 {
655 con_rune = get_connection_rune (pl, x, y); 646 con_rune = get_connection_rune (pl, x, y);
656 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);
657 if (connected == -1) 648 if (connected == -1)
658 { 649 {
659 /* Player already informed of failure by the previous function */ 650 /* Player already informed of failure by the previous function */
660 tmp->destroy (0); 651 tmp->destroy ();
661 return; 652 return;
662 } 653 }
663 /* Remove marking rune */ 654 /* Remove marking rune */
664 con_rune->remove ();
665 con_rune->destroy (0); 655 con_rune->destroy ();
666 } 656 }
667 657
668 /* 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 */
669 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 659 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
670 { 660 {
671 if (adjust_sign_msg (pl, x, y, tmp) == -1) 661 if (adjust_sign_msg (pl, x, y, tmp) == -1)
672 { 662 {
673 tmp->destroy (0); 663 tmp->destroy ();
674 return; 664 return;
675 } 665 }
676 } 666 }
677 667
678 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);
701 item = GET_MAP_OB (pl->map, x, y); 691 item = GET_MAP_OB (pl->map, x, y);
702 if (!item) 692 if (!item)
703 { 693 {
704 /* Should not happen with previous tests, but we never know */ 694 /* Should not happen with previous tests, but we never know */
705 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 695 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); 696 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
707 return; 697 return;
708 } 698 }
709 699
710 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 700 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
711 item = item->above; 701 item = item->above;
712 702
713 if (!item) 703 if (!item)
714 {
715 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 704 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
716 return; 705 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."); 706 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
724 return; 707 else if (!item->flag [FLAG_IS_BUILDABLE])
725 708 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
726 case DOOR: 709 else
727 case BUTTON: 710 {
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)); 711 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
744 item->remove ();
745 item->destroy (0); 712 item->destroy ();
746 } 713 }
747} 714}
748 715
749/** 716/**
750 * Global building function 717 * Global building function
776 } 743 }
777 744
778 x = pl->x + freearr_x[dir]; 745 x = pl->x + freearr_x[dir];
779 y = pl->y + freearr_y[dir]; 746 y = pl->y + freearr_y[dir];
780 747
781 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))
782 { 749 {
783 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...");
784 return; 751 return;
785 } 752 }
786 753
793 760
794 tmp = GET_MAP_OB (pl->map, x, y); 761 tmp = GET_MAP_OB (pl->map, x, y);
795 if (!tmp) 762 if (!tmp)
796 { 763 {
797 /* Nothing, meaning player is standing next to an undefined square... */ 764 /* 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); 765 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."); 766 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
800 return; 767 return;
801 } 768 }
802 tmp2 = find_marked_object (pl); 769 tmp2 = find_marked_object (pl);
803 while (tmp) 770 while (tmp)
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