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.7 by root, Thu Sep 14 22:34:03 2006 UTC vs.
Revision 1.24 by root, Mon Feb 5 02:07:40 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>
30 31
31/** 32/**
32 * Check if objects on a square interfere with building 33 * Check if objects on a square interfere with building
33 */ 34 */
34int 35int
35can_build_over (mapstruct *map, object *tmp, short x, short y) 36can_build_over (maptile *map, object *tmp, short x, short y)
36{ 37{
37 object *ob; 38 object *ob;
38 39
39 ob = GET_MAP_OB (map, x, y); 40 ob = GET_MAP_OB (map, x, y);
40 while (ob) 41 while (ob)
73 74
74/** 75/**
75 * Erases marking runes at specified location 76 * Erases marking runes at specified location
76 */ 77 */
77void 78void
78remove_marking_runes (mapstruct *map, short x, short y) 79remove_marking_runes (maptile *map, short x, short y)
79{ 80{
80 object *rune; 81 object *rune;
81 object *next; 82 object *next;
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/**
99 * \return 'connected' value with no item, or -1 if failure. 99 * \return 'connected' value with no item, or -1 if failure.
100 * 100 *
101 * Tries 1000 random values, then returns -1. 101 * Tries 1000 random values, then returns -1.
102 */ 102 */
103int 103int
104find_unused_connected_value (mapstruct *map) 104find_unused_connected_value (maptile *map)
105{ 105{
106 int connected = 0; 106 int connected = 0;
107 int itest = 0; 107 int itest = 0;
108 oblinkpt *obp; 108 oblinkpt *obp;
109 109
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 */
212object * 211object *
213get_wall (mapstruct *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
231 * Basically it ensures the correct wall is put where needed. 230 * Basically it ensures the correct wall is put where needed.
232 * 231 *
233 * Note: x & y must be valid map coordinates. 232 * Note: x & y must be valid map coordinates.
234 */ 233 */
235void 234void
236fix_walls (mapstruct *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; 241
245 242
246 /* First, find the wall on that spot */ 243 /* First, find the wall on that spot */
247 wall = get_wall (map, x, y); 244 wall = get_wall (map, x, y);
248 if (!wall) 245 if (!wall)
249 /* Nothing -> bail out */ 246 /* Nothing -> bail out */
250 return; 247 return;
251 248
252 /* Find base name */ 249 /* Find base name */
253 strcpy (archetype, wall->arch->name); 250 assign (archetype, wall->arch->name);
254 underscore = strchr (archetype, '_'); 251 underscore = strchr (archetype, '_');
255 252
253 /* search for the first _ before a number */
254 while (underscore && !isdigit (*(underscore + 1)))
255 underscore = strchr (underscore + 1, '_');
256
256 if (!underscore || (!isdigit (*(underscore + 1)))) 257 if (!underscore || !isdigit (*(underscore + 1)))
257 /* Not in a format we can change, bail out */ 258 /* Not in a format we can change, bail out */
258 return; 259 return;
259 260
260 underscore++; 261 underscore++;
261 *underscore = '\0'; 262 *underscore = '\0';
262 263
263 connect = 0; 264 int connect = 0;
264 265
265 if ((x > 0) && get_wall (map, x - 1, y)) 266 if ((x > 0) && get_wall (map, x - 1, y))
266 connect |= 1; 267 connect |= 1;
267 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 268 if ((x < map->width - 1) && get_wall (map, x + 1, y))
268 connect |= 2; 269 connect |= 2;
269 270
270 if ((y > 0) && get_wall (map, x, y - 1)) 271 if ((y > 0) && get_wall (map, x, y - 1))
271 connect |= 4; 272 connect |= 4;
272 273
273 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 274 if ((y < map->height - 1) && get_wall (map, x, y + 1))
274 connect |= 8; 275 connect |= 8;
275 276
276 switch (connect) 277 switch (connect)
277 { 278 {
278 case 0: 279 case 0:
351 return; 352 return;
352 353
353 /* Now delete current wall, and insert new one 354 /* Now delete current wall, and insert new one
354 * 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
355 */ 356 */
356 for (flag = 0; flag < 4; flag++) 357 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
357 old_flags[flag] = wall->flags[flag]; 358
358 remove_ob (wall); 359 wall->destroy ();
359 free_object (wall);
360 360
361 wall = arch_to_object (new_arch); 361 wall = arch_to_object (new_arch);
362 wall->type = WALL; 362 wall->type = BUILDABLE_WALL;
363 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);
364 for (flag = 0; flag < 4; flag++)
365 wall->flags[flag] = old_flags[flag]; 364 wall->flag = old_flags;
366} 365}
367 366
368/** 367/**
369 * \brief Floor building function 368 * \brief Floor building function
370 * 369 *
398 if (tmp) 397 if (tmp)
399 { 398 {
400 while (tmp) 399 while (tmp)
401 { 400 {
402 above = tmp->above; 401 above = tmp->above;
403 if (WALL == tmp->type) 402 if (BUILDABLE_WALL == tmp->type)
404 { 403 {
405 /* 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 */
406 new_wall = tmp->arch; 405 new_wall = tmp->arch;
407 remove_ob (tmp); 406 tmp->destroy ();
408 free_object (tmp);
409 sprintf (message, "You destroy the wall and redo the floor."); 407 sprintf (message, "You destroy the wall and redo the floor.");
410 } 408 }
411 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 409 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
412 { 410 {
413 remove_ob (tmp); 411 tmp->destroy ();
414 free_object (tmp);
415 floor_removed = 1; 412 floor_removed = 1;
416 } 413 }
417 else 414 else
418 { 415 {
419 if (floor_removed) 416 if (floor_removed)
461 /* 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... */
462 if (new_wall) 459 if (new_wall)
463 { 460 {
464 tmp = arch_to_object (new_wall); 461 tmp = arch_to_object (new_wall);
465 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 462 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
466 tmp->type = WALL; 463 tmp->type = BUILDABLE_WALL;
467 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);
468 } 465 }
469 } 466 }
470 } 467 }
471 468
486 /* And tell player about the fix */ 483 /* And tell player about the fix */
487 new_draw_info (NDI_UNIQUE, 0, pl, message); 484 new_draw_info (NDI_UNIQUE, 0, pl, message);
488} 485}
489 486
490/** 487/**
488 * Wall radius fix function
489 */
490void fix_walls_around (maptile *map, int x, int y)
491{
492 for (int xt = x - 1; xt <= x + 1; xt++)
493 for (int yt = y - 1; yt <= y + 1; yt++)
494 {
495 if (OUT_OF_REAL_MAP (map, xt, yt))
496 continue;
497
498 fix_walls (map, xt, yt);
499 }
500}
501
502/**
491 * Wall building function 503 * Wall building function
492 * 504 *
493 * Walls can be build: 505 * Walls can be build:
494 * - on a floor without anything else 506 * - on a floor without anything else
495 * - on an existing wall, with or without a floor 507 * - on an existing wall, with or without a floor
508 /* Grab existing wall, if any */ 520 /* Grab existing wall, if any */
509 current_wall = NULL; 521 current_wall = NULL;
510 tmp = GET_MAP_OB (pl->map, x, y); 522 tmp = GET_MAP_OB (pl->map, x, y);
511 while (tmp && !current_wall) 523 while (tmp && !current_wall)
512 { 524 {
513 if (WALL == tmp->type) 525 if (BUILDABLE_WALL == tmp->type)
514 current_wall = tmp; 526 current_wall = tmp;
515 527
516 tmp = tmp->above; 528 tmp = tmp->above;
517 } 529 }
518 530
526 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);
527 return; 539 return;
528 } 540 }
529 541
530 tmp = arch_to_object (new_wall); 542 tmp = arch_to_object (new_wall);
531 tmp->type = WALL; 543 tmp->type = BUILDABLE_WALL;
532 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 544 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
533 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);
534 546
535 /* If existing wall, remove it, no need to fix other walls */ 547 /* If existing wall, remove it, no need to fix other walls */
536 if (current_wall) 548 if (current_wall)
537 { 549 {
538 remove_ob (current_wall); 550 current_wall->destroy ();
539 free_object (current_wall);
540 fix_walls (pl->map, x, y); 551 fix_walls (pl->map, x, y);
541 sprintf (message, "You redecorate the wall to better suit your tastes."); 552 sprintf (message, "You redecorate the wall to better suit your tastes.");
542 } 553 }
543 else 554 else
544 { 555 {
635 con_rune = get_connection_rune (pl, x, y); 646 con_rune = get_connection_rune (pl, x, y);
636 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);
637 if (connected == -1) 648 if (connected == -1)
638 { 649 {
639 /* Player already informed of failure by the previous function */ 650 /* Player already informed of failure by the previous function */
640 free_object (tmp); 651 tmp->destroy ();
641 return; 652 return;
642 } 653 }
643 /* Remove marking rune */ 654 /* Remove marking rune */
644 remove_ob (con_rune); 655 con_rune->destroy ();
645 free_object (con_rune);
646 } 656 }
647 657
648 /* 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 */
649 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 659 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
650 { 660 {
651 if (adjust_sign_msg (pl, x, y, tmp) == -1) 661 if (adjust_sign_msg (pl, x, y, tmp) == -1)
652 { 662 {
653 free_object (tmp); 663 tmp->destroy ();
654 return; 664 return;
655 } 665 }
656 } 666 }
657 667
658 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);
681 item = GET_MAP_OB (pl->map, x, y); 691 item = GET_MAP_OB (pl->map, x, y);
682 if (!item) 692 if (!item)
683 { 693 {
684 /* Should not happen with previous tests, but we never know */ 694 /* Should not happen with previous tests, but we never know */
685 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 695 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
686 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);
687 return; 697 return;
688 } 698 }
689 699
690 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 700 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
691 item = item->above; 701 item = item->above;
692 702
693 if (!item) 703 if (!item)
694 {
695 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 704 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
696 return; 705 else if (item->type == BUILDABLE_WALL)
697 }
698
699 /* Now remove object, with special cases (buttons & such) */
700 switch (item->type)
701 {
702 case WALL:
703 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.");
704 return; 707 else if (!item->flag [FLAG_IS_BUILDABLE])
705 708 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
706 case DOOR: 709 else
707 case BUTTON: 710 {
708 case GATE:
709 case TIMED_GATE:
710 case DETECTOR:
711 case PEDESTAL:
712 case CF_HANDLE:
713 case MAGIC_EAR:
714 case SIGN:
715 /* Special case: must unconnect */
716 if (QUERY_FLAG (item, FLAG_IS_LINKED))
717 remove_button_link (item);
718
719 /* Fall through */
720
721 default:
722 /* Remove generic item */
723 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));
724 remove_ob (item); 712 item->destroy ();
725 free_object (item);
726 } 713 }
727} 714}
728 715
729/** 716/**
730 * Global building function 717 * Global building function
756 } 743 }
757 744
758 x = pl->x + freearr_x[dir]; 745 x = pl->x + freearr_x[dir];
759 y = pl->y + freearr_y[dir]; 746 y = pl->y + freearr_y[dir];
760 747
761 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))
762 { 749 {
763 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...");
764 return; 751 return;
765 } 752 }
766 753
773 760
774 tmp = GET_MAP_OB (pl->map, x, y); 761 tmp = GET_MAP_OB (pl->map, x, y);
775 if (!tmp) 762 if (!tmp)
776 { 763 {
777 /* Nothing, meaning player is standing next to an undefined square... */ 764 /* Nothing, meaning player is standing next to an undefined square... */
778 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);
779 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.");
780 return; 767 return;
781 } 768 }
782 tmp2 = find_marked_object (pl); 769 tmp2 = find_marked_object (pl);
783 while (tmp) 770 while (tmp)
891 } 878 }
892 879
893 tmp->face = book->face; 880 tmp->face = book->face;
894 tmp->invisible = 0; 881 tmp->invisible = 0;
895 } 882 }
896 remove_ob (book); 883
897 free_object (book); 884 book->destroy ();
898 return 0; 885 return 0;
899} 886}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines