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.13 by elmex, Wed Dec 20 12:13:47 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>
145 } 146 }
146 147
147 /* Now, find force in player's inventory */ 148 /* Now, find force in player's inventory */
148 force = pl->inv; 149 force = pl->inv;
149 while (force 150 while (force
150 && ((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
151 || (strcmp (force->msg, rune->msg)))) 152 || force->msg != rune->msg))
152 force = force->below; 153 force = force->below;
153 154
154 if (!force) 155 if (!force)
155 /* No force, need to create & insert one */ 156 /* No force, need to create & insert one */
156 { 157 {
161 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.");
162 return -1; 163 return -1;
163 } 164 }
164 165
165 force = get_archetype (FORCE_NAME); 166 force = get_archetype (FORCE_NAME);
166 force->speed = 0;
167 update_ob_speed (force);
168 force->slaying = pl->map->path; 167 force->slaying = pl->map->path;
169 force->msg = rune->msg; 168 force->msg = rune->msg;
170 force->path_attuned = connected; 169 force->path_attuned = connected;
170 force->set_speed (0);
171 insert_ob_in_ob (force, pl); 171 insert_ob_in_ob (force, pl);
172 172
173 return connected; 173 return connected;
174 } 174 }
175 175
232 * Note: x & y must be valid map coordinates. 232 * Note: x & y must be valid map coordinates.
233 */ 233 */
234void 234void
235fix_walls (maptile *map, int x, int y) 235fix_walls (maptile *map, int x, int y)
236{ 236{
237 int connect;
238 object *wall; 237 object *wall;
239 char archetype[MAX_BUF]; 238 char archetype[MAX_BUF];
240 char *underscore; 239 char *underscore;
241 uint32 old_flags[4];
242 struct archetype *new_arch; 240 struct archetype *new_arch;
243 int flag;
244 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
256 /* search for the first _ before a number */ 253 /* search for the first _ before a number */
257 while (underscore && !isdigit (*(underscore + 1))) 254 while (underscore && !isdigit (*(underscore + 1)))
258 underscore = strchr (underscore + 1, '_'); 255 underscore = strchr (underscore + 1, '_');
262 return; 259 return;
263 260
264 underscore++; 261 underscore++;
265 *underscore = '\0'; 262 *underscore = '\0';
266 263
267 connect = 0; 264 int connect = 0;
268 265
269 if ((x > 0) && get_wall (map, x - 1, y)) 266 if ((x > 0) && get_wall (map, x - 1, y))
270 connect |= 1; 267 connect |= 1;
271 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 268 if ((x < map->width - 1) && get_wall (map, x + 1, y))
272 connect |= 2; 269 connect |= 2;
273 270
274 if ((y > 0) && get_wall (map, x, y - 1)) 271 if ((y > 0) && get_wall (map, x, y - 1))
275 connect |= 4; 272 connect |= 4;
276 273
277 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 274 if ((y < map->height - 1) && get_wall (map, x, y + 1))
278 connect |= 8; 275 connect |= 8;
279 276
280 switch (connect) 277 switch (connect)
281 { 278 {
282 case 0: 279 case 0:
355 return; 352 return;
356 353
357 /* Now delete current wall, and insert new one 354 /* Now delete current wall, and insert new one
358 * 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
359 */ 356 */
360 for (flag = 0; flag < 4; flag++) 357 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
361 old_flags[flag] = wall->flags[flag];
362 358
363 wall->destroy (); 359 wall->destroy ();
364 360
365 wall = arch_to_object (new_arch); 361 wall = arch_to_object (new_arch);
366 wall->type = BUILDABLE_WALL; 362 wall->type = BUILDABLE_WALL;
367 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);
368 for (flag = 0; flag < 4; flag++)
369 wall->flags[flag] = old_flags[flag]; 364 wall->flag = old_flags;
370} 365}
371 366
372/** 367/**
373 * \brief Floor building function 368 * \brief Floor building function
374 * 369 *
696 item = GET_MAP_OB (pl->map, x, y); 691 item = GET_MAP_OB (pl->map, x, y);
697 if (!item) 692 if (!item)
698 { 693 {
699 /* Should not happen with previous tests, but we never know */ 694 /* Should not happen with previous tests, but we never know */
700 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 695 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
701 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);
702 return; 697 return;
703 } 698 }
704 699
705 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 700 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
706 item = item->above; 701 item = item->above;
707 702
708 if (!item) 703 if (!item)
709 {
710 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 704 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
711 return; 705 else if (item->type == BUILDABLE_WALL)
712 }
713
714 /* Now remove object, with special cases (buttons & such) */
715 switch (item->type)
716 {
717 case BUILDABLE_WALL:
718 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.");
719 return; 707 else if (!item->flag [FLAG_IS_BUILDABLE])
720
721 case DOOR:
722 case BUTTON:
723 case GATE:
724 case TIMED_GATE:
725 case DETECTOR:
726 case PEDESTAL:
727 case CF_HANDLE:
728 case MAGIC_EAR:
729 case SIGN:
730 /* Special case: must unconnect */
731 if (QUERY_FLAG (item, FLAG_IS_LINKED))
732 remove_button_link (item);
733
734 /* Fall through */
735
736 default:
737 /* Remove generic item */
738 if (!QUERY_FLAG (item, FLAG_IS_BUILDABLE))
739 {
740 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); 708 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
741 return; 709 else
742 } 710 {
743
744 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));
745 item->destroy (); 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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines