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.43 by root, Mon Nov 2 07:21:50 2009 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 * Deliantra is free software: you can redistribute it and/or modify it under
8 it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
9 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
10 (at your option) any later version. 11 * 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 Affero GNU General Public License
18 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
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 <support@deliantra.net>
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>
29#include <sproto.h> 30#include <sproto.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 35static int
35can_build_over (maptile *map, object *tmp, short x, short y) 36can_build_over (maptile *map, object *tmp, int x, int 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)
41 { 42 {
42 /* if ob is not a marking rune or floor, then check special cases */ 43 /* if ob is not a marking rune or floor, then check special cases */
43 if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) 44 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
44 { 45 {
45 switch (tmp->type) 46 switch (tmp->type)
46 { 47 {
47 case SIGN: 48 case SIGN:
48 case MAGIC_EAR: 49 case MAGIC_EAR:
49 /* Allow signs and magic ears to be built on books */ 50 /* Allow signs and magic ears to be built on books */
50 if (ob->type != BOOK) 51 if (ob->type != BOOK)
51 {
52 return 0;
53 }
54 break;
55 case BUTTON:
56 case DETECTOR:
57 case PEDESTAL:
58 case CF_HANDLE:
59 /* Allow buttons and levers to be built under gates */
60 if (ob->type != GATE && ob->type != DOOR)
61 {
62 return 0;
63 }
64 break;
65 default:
66 return 0; 52 return 0;
53 break;
54 case BUTTON:
55 case DETECTOR:
56 case PEDESTAL:
57 case T_HANDLE:
58 /* Allow buttons and levers to be built under gates */
59 if (ob->type != GATE && ob->type != DOOR)
60 return 0;
61 break;
62 default:
63 return 0;
67 } 64 }
68 } 65 }
66
69 ob = ob->above; 67 ob = ob->above;
70 } 68 }
71 return 1; 69 return 1;
72} 70}
73 71
74/** 72/**
75 * Erases marking runes at specified location 73 * Erases marking runes at specified location
76 */ 74 */
77void 75static void
78remove_marking_runes (maptile *map, short x, short y) 76remove_marking_runes (maptile *map, int x, int y)
79{ 77{
80 object *rune; 78 object *rune;
81 object *next; 79 object *next;
82 80
83 rune = GET_MAP_OB (map, x, y); 81 rune = GET_MAP_OB (map, x, y);
84 while (rune) 82 while (rune)
85 { 83 {
86 next = rune->above; 84 next = rune->above;
85
87 if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) 86 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
88 {
89 rune->remove ();
90 rune->destroy (0); 87 rune->destroy ();
91 } 88
92 rune = next; 89 rune = next;
93 } 90 }
94} 91}
95 92
96/** 93/**
98 * \param map: map for which to find a value 95 * \param map: map for which to find a value
99 * \return 'connected' value with no item, or -1 if failure. 96 * \return 'connected' value with no item, or -1 if failure.
100 * 97 *
101 * Tries 1000 random values, then returns -1. 98 * Tries 1000 random values, then returns -1.
102 */ 99 */
103int 100static shstr_tmp
104find_unused_connected_value (maptile *map) 101find_unused_connected_value (maptile *map)
105{ 102{
106 int connected = 0; 103 for (int i = 1000; --i; )
107 int itest = 0;
108 oblinkpt *obp;
109
110 while (itest++ < 1000)
111 {
112 connected = 1 + rand () % 20000;
113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next);
114
115 if (!obp)
116 return connected;
117 } 104 {
105 char buf[64];
118 106
107 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
108
109 shstr id (buf);
110
111 if (!map->find_link (id))
112 return id;
113 }
114
115 return shstr_tmp ();
116}
117
118/**
119 * Returns the marking rune on the square, for purposes of building connections
120 */
121static object *
122get_connection_rune (object *pl, int x, int y)
123{
124 object *rune = GET_MAP_OB (pl->map, x, y);
125
126 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
127 rune = rune->above;
128
119 return -1; 129 return rune;
120} 130}
121
122 131
123/** 132/**
124 * Helper function for door/button/connected item building. 133 * Helper function for door/button/connected item building.
125 * 134 *
126 * Will search the specified spot for a marking rune. 135 * Will search the specified spot for a marking rune.
128 * Else, searches a force in op's inventory matching the map's name 137 * Else, searches a force in op's inventory matching the map's name
129 * and the rune's text. 138 * and the rune's text.
130 * If found, returns the connection value associated 139 * If found, returns the connection value associated
131 * else searches a new connection value, and adds the force to the player. 140 * else searches a new connection value, and adds the force to the player.
132 */ 141 */
133int 142static shstr_tmp
134find_or_create_connection_for_map (object *pl, short x, short y, object *rune) 143find_or_create_connection_for_map (object *pl, int x, int y, object *rune)
135{ 144{
136 object *force; 145 object *force;
137 int connected;
138 146
139 if (!rune) 147 if (!rune)
140 rune = get_connection_rune (pl, x, y); 148 rune = get_connection_rune (pl, x, y);
141 149
142 if (!rune) 150 if (!rune)
143 { 151 {
144 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); 152 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
145 return -1; 153 return shstr_tmp ();
146 } 154 }
147 155
148 /* Now, find force in player's inventory */ 156 /* Now, find force in player's inventory */
149 force = pl->inv; 157 force = pl->inv;
150 while (force 158 while (force
151 && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) 159 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
152 || (strcmp (force->msg, rune->msg)))) 160 || force->msg != rune->msg))
153 force = force->below; 161 force = force->below;
154 162
155 if (!force) 163 if (!force)
156 /* No force, need to create & insert one */ 164 /* No force, need to create & insert one */
157 { 165 {
158 /* Find unused value */ 166 /* Find unused value */
159 connected = find_unused_connected_value (pl->map); 167 shstr_tmp id = find_unused_connected_value (pl->map);
160 if (connected == -1) 168
169 if (!id)
161 { 170 {
162 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 171 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
163 return -1; 172 return shstr_tmp ();
164 } 173 }
165 174
166 force = get_archetype (FORCE_NAME); 175 force = get_archetype (FORCE_NAME);
167 force->speed = 0;
168 update_ob_speed (force);
169 force->slaying = pl->map->path; 176 force->slaying = pl->map->path;
170 force->msg = rune->msg; 177 force->msg = rune->msg;
171 force->path_attuned = connected; 178 force->race = id;
179 force->set_speed (0);
180
172 insert_ob_in_ob (force, pl); 181 insert_ob_in_ob (force, pl);
173 182
174 return connected; 183 return id;
175 } 184 }
176 185
177 /* Found the force, everything's easy. */ 186 /* Found the force, everything's easy. */
178 return force->path_attuned; 187 return force->race;
179}
180
181/**
182 * Returns the marking rune on the square, for purposes of building connections
183 */
184object *
185get_connection_rune (object *pl, short x, short y)
186{
187 object *rune;
188
189 rune = GET_MAP_OB (pl->map, x, y);
190 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark"))))
191 rune = rune->above;
192 return rune;
193} 188}
194 189
195/** 190/**
196 * Returns the book/scroll on the current square, for purposes of building 191 * Returns the book/scroll on the current square, for purposes of building
197 */ 192 */
198object * 193static object *
199get_msg_book (object *pl, short x, short y) 194get_msg_book (object *pl, int x, int y)
200{ 195{
201 object *book;
202
203 book = GET_MAP_OB (pl->map, x, y); 196 object *book = GET_MAP_OB (pl->map, x, y);
197
204 while (book && (book->type != BOOK)) 198 while (book && (book->type != BOOK))
205 book = book->above; 199 book = book->above;
200
206 return book; 201 return book;
207} 202}
208 203
209/** 204/**
205 * Make the built object inherit the msg of books that are used with it.
206 * For objects already invisible (i.e. magic mouths & ears), also make it
207 * it inherit the face and the name with "talking " prepended.
208 */
209static int
210adjust_sign_msg (object *pl, int x, int y, object *tmp)
211{
212 object *book;
213 char buf[MAX_BUF];
214 char buf2[MAX_BUF];
215
216 book = get_msg_book (pl, x, y);
217 if (!book)
218 {
219 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
220 return -1;
221 }
222
223 tmp->msg = book->msg;
224
225 if (tmp->invisible)
226 {
227 if (book->custom_name != NULL)
228 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
229 else
230 snprintf (buf, sizeof (buf), "talking %s", &book->name);
231
232 tmp->name = buf;
233
234 if (book->name_pl != NULL)
235 {
236 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
237 tmp->name_pl = buf2;
238 }
239
240 tmp->face = book->face;
241 tmp->invisible = 0;
242 }
243
244 book->destroy ();
245 return 0;
246}
247
248/**
210 * Returns first item of type WALL. 249 * Returns first item of type BUILDABLE_WALL.
211 */ 250 */
212object * 251static object *
213get_wall (maptile *map, int x, int y) 252get_wall (maptile *map, int x, int y)
214{ 253{
215 object *wall;
216
217 wall = GET_MAP_OB (map, x, y); 254 object *wall = GET_MAP_OB (map, x, y);
255
218 while (wall && (WALL != wall->type)) 256 while (wall && (BUILDABLE_WALL != wall->type))
219 wall = wall->above; 257 wall = wall->above;
220 258
221 return wall; 259 return wall;
222} 260}
223 261
233 * Note: x & y must be valid map coordinates. 271 * Note: x & y must be valid map coordinates.
234 */ 272 */
235void 273void
236fix_walls (maptile *map, int x, int y) 274fix_walls (maptile *map, int x, int y)
237{ 275{
238 int connect;
239 object *wall;
240 char archetype[MAX_BUF]; 276 char archetype[MAX_BUF];
241 char *underscore; 277 char *underscore;
242 uint32 old_flags[4];
243 struct archetype *new_arch; 278 struct archetype *new_arch;
244 int flag;
245
246 279
247 /* First, find the wall on that spot */ 280 /* First, find the wall on that spot */
248 wall = get_wall (map, x, y); 281 object *wall = get_wall (map, x, y);
249 if (!wall) 282 if (!wall)
250 /* Nothing -> bail out */ 283 /* Nothing -> bail out */
251 return; 284 return;
252 285
253 /* Find base name */ 286 /* Find base name */
254 strcpy (archetype, wall->arch->name); 287 assign (archetype, wall->arch->archname);
255 underscore = strchr (archetype, '_'); 288 underscore = strchr (archetype, '_');
256 289
257 /* search for the first _ before a number */ 290 /* search for the first _ before a number */
258 while (underscore && !isdigit (*(underscore + 1))) 291 while (underscore && !isdigit (*(underscore + 1)))
259 underscore = strchr (underscore + 1, '_'); 292 underscore = strchr (underscore + 1, '_');
263 return; 296 return;
264 297
265 underscore++; 298 underscore++;
266 *underscore = '\0'; 299 *underscore = '\0';
267 300
268 connect = 0; 301 int connect = 0;
269 302
270 if ((x > 0) && get_wall (map, x - 1, y)) 303 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
271 connect |= 1; 304 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
272 if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) 305 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
273 connect |= 2; 306 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
274 307
275 if ((y > 0) && get_wall (map, x, y - 1)) 308 // one bit per dir, 1 left, 2 right, 4 up, 8 down
276 connect |= 4; 309 static const char *walltype[16] = {
310 "0",
311 "1_3",
312 "1_4",
313 "2_1_2",
314 "1_2",
315 "2_2_4",
316 "2_2_1",
317 "3_1",
318 "1_1",
319 "2_2_3",
320 "2_2_2",
321 "3_3",
322 "2_1_1",
323 "3_4",
324 "3_2",
325 "4"
326 };
277 327
278 if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) 328 strcat (archetype, walltype [connect]);
279 connect |= 8;
280
281 switch (connect)
282 {
283 case 0:
284 strcat (archetype, "0");
285
286 break;
287 case 1:
288 strcat (archetype, "1_3");
289
290 break;
291 case 2:
292 strcat (archetype, "1_4");
293
294 break;
295 case 3:
296 strcat (archetype, "2_1_2");
297
298 break;
299 case 4:
300 strcat (archetype, "1_2");
301
302 break;
303 case 5:
304 strcat (archetype, "2_2_4");
305
306 break;
307 case 6:
308 strcat (archetype, "2_2_1");
309
310 break;
311 case 7:
312 strcat (archetype, "3_1");
313
314 break;
315 case 8:
316 strcat (archetype, "1_1");
317
318 break;
319 case 9:
320 strcat (archetype, "2_2_3");
321
322 break;
323 case 10:
324 strcat (archetype, "2_2_2");
325
326 break;
327 case 11:
328 strcat (archetype, "3_3");
329
330 break;
331 case 12:
332 strcat (archetype, "2_1_1");
333
334 break;
335 case 13:
336 strcat (archetype, "3_4");
337
338 break;
339 case 14:
340 strcat (archetype, "3_2");
341
342 break;
343 case 15:
344 strcat (archetype, "4");
345
346 break;
347 }
348 329
349 /* 330 /*
350 * Before anything, make sure the archetype does exist... 331 * Before anything, make sure the archetype does exist...
351 * If not, prolly an error... 332 * If not, prolly an error...
352 */ 333 */
356 return; 337 return;
357 338
358 /* Now delete current wall, and insert new one 339 /* Now delete current wall, and insert new one
359 * We save flags to avoid any trouble with buildable/non buildable, and so on 340 * We save flags to avoid any trouble with buildable/non buildable, and so on
360 */ 341 */
361 for (flag = 0; flag < 4; flag++) 342 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
362 old_flags[flag] = wall->flags[flag]; 343
363 wall->remove ();
364 wall->destroy (0); 344 wall->destroy ();
365 345
366 wall = arch_to_object (new_arch); 346 wall = arch_to_object (new_arch);
367 wall->type = WALL; 347 wall->type = BUILDABLE_WALL;
368 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 348 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]; 349 wall->flag = old_flags;
371} 350}
372 351
373/** 352/**
374 * \brief Floor building function 353 * \brief Floor building function
375 * 354 *
378 * - on an existing wall, with or without a floor under it 357 * - on an existing wall, with or without a floor under it
379 * 358 *
380 * Note: this function will inconditionally change squares around (x, y) 359 * Note: this function will inconditionally change squares around (x, y)
381 * so don't call it with x == 0 for instance! 360 * so don't call it with x == 0 for instance!
382 */ 361 */
383void 362static void
384apply_builder_floor (object *pl, object *material, short x, short y) 363apply_builder_floor (object *pl, object *material, int x, int y)
385{ 364{
386 object *tmp, *above; 365 object *tmp, *above;
387 object *above_floor; /* Item above floor, if any */ 366 object *above_floor; /* Item above floor, if any */
388 struct archetype *new_floor; 367 struct archetype *new_floor;
389 struct archetype *new_wall; 368 struct archetype *new_wall;
403 if (tmp) 382 if (tmp)
404 { 383 {
405 while (tmp) 384 while (tmp)
406 { 385 {
407 above = tmp->above; 386 above = tmp->above;
408 if (WALL == tmp->type) 387 if (BUILDABLE_WALL == tmp->type)
409 { 388 {
410 /* There was a wall, remove it & keep its archetype to make new walls */ 389 /* There was a wall, remove it & keep its archetype to make new walls */
411 new_wall = tmp->arch; 390 new_wall = tmp->arch;
412 tmp->remove ();
413 tmp->destroy (0); 391 tmp->destroy ();
414 sprintf (message, "You destroy the wall and redo the floor."); 392 sprintf (message, "You destroy the wall and redo the floor.");
415 } 393 }
416 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 394 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR)))
417 { 395 {
418 tmp->remove ();
419 tmp->destroy (0); 396 tmp->destroy ();
420 floor_removed = 1; 397 floor_removed = 1;
421 } 398 }
422 else 399 else
423 { 400 {
424 if (floor_removed) 401 if (floor_removed)
402 {
403 /* This is the first item that was above the floor */
425 above_floor = tmp; 404 above_floor = tmp;
405 floor_removed = 0;
406 }
426 } 407 }
427 408
428 tmp = above; 409 tmp = above;
429 } 410 }
430 } 411 }
466 /* Insert wall if exists. Note: if it doesn't, the map is weird... */ 447 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
467 if (new_wall) 448 if (new_wall)
468 { 449 {
469 tmp = arch_to_object (new_wall); 450 tmp = arch_to_object (new_wall);
470 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 451 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
471 tmp->type = WALL; 452 tmp->type = BUILDABLE_WALL;
472 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 453 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
473 } 454 }
474 } 455 }
475 } 456 }
476 457
484 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 465 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
485 fix_walls (pl->map, xt, yt); 466 fix_walls (pl->map, xt, yt);
486 } 467 }
487 468
488 /* Now remove raw item from inventory */ 469 /* Now remove raw item from inventory */
489 decrease_ob (material); 470 material->decrease ();
490 471
491 /* And tell player about the fix */ 472 /* And tell player about the fix */
492 new_draw_info (NDI_UNIQUE, 0, pl, message); 473 new_draw_info (NDI_UNIQUE, 0, pl, message);
493} 474}
494 475
495/** 476/**
496 * Wall radius fix function 477 * Wall radius fix function
497 */ 478 */
479static void
498void fix_walls_around (maptile *map, int x, int y) 480fix_walls_around (maptile *map, int x, int y)
499{ 481{
500 for (int xt = x - 1; xt <= x + 1; xt++) 482 for (int xt = x - 1; xt <= x + 1; xt++)
501 for (int yt = y - 1; yt <= y + 1; yt++) 483 for (int yt = y - 1; yt <= y + 1; yt++)
502 { 484 {
503 if (OUT_OF_REAL_MAP (map, xt, yt)) 485 if (OUT_OF_REAL_MAP (map, xt, yt))
512 * 494 *
513 * Walls can be build: 495 * Walls can be build:
514 * - on a floor without anything else 496 * - on a floor without anything else
515 * - on an existing wall, with or without a floor 497 * - on an existing wall, with or without a floor
516 */ 498 */
517void 499static void
518apply_builder_wall (object *pl, object *material, short x, short y) 500apply_builder_wall (object *pl, object *material, int x, int y)
519{ 501{
520 object *current_wall; 502 object *current_wall;
521 object *tmp; 503 object *tmp;
522 int xt, yt; 504 int xt, yt;
523 struct archetype *new_wall; 505 struct archetype *new_wall;
528 /* Grab existing wall, if any */ 510 /* Grab existing wall, if any */
529 current_wall = NULL; 511 current_wall = NULL;
530 tmp = GET_MAP_OB (pl->map, x, y); 512 tmp = GET_MAP_OB (pl->map, x, y);
531 while (tmp && !current_wall) 513 while (tmp && !current_wall)
532 { 514 {
533 if (WALL == tmp->type) 515 if (BUILDABLE_WALL == tmp->type)
534 current_wall = tmp; 516 current_wall = tmp;
535 517
536 tmp = tmp->above; 518 tmp = tmp->above;
537 } 519 }
538 520
546 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); 528 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
547 return; 529 return;
548 } 530 }
549 531
550 tmp = arch_to_object (new_wall); 532 tmp = arch_to_object (new_wall);
551 tmp->type = WALL; 533 tmp->type = BUILDABLE_WALL;
552 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 534 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
553 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 535 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
554 536
555 /* If existing wall, remove it, no need to fix other walls */ 537 /* If existing wall, remove it, no need to fix other walls */
556 if (current_wall) 538 if (current_wall)
557 { 539 {
558 current_wall->remove ();
559 current_wall->destroy (0); 540 current_wall->destroy ();
560 fix_walls (pl->map, x, y); 541 fix_walls (pl->map, x, y);
561 sprintf (message, "You redecorate the wall to better suit your tastes."); 542 sprintf (message, "You redecorate the wall to better suit your tastes.");
562 } 543 }
563 else 544 else
564 { 545 {
572 fix_walls (pl->map, xt, yt); 553 fix_walls (pl->map, xt, yt);
573 } 554 }
574 } 555 }
575 556
576 /* Now remove item from inventory */ 557 /* Now remove item from inventory */
577 decrease_ob (material); 558 material->decrease ();
578 559
579 /* And tell player what happened */ 560 /* And tell player what happened */
580 new_draw_info (NDI_UNIQUE, 0, pl, message); 561 new_draw_info (NDI_UNIQUE, 0, pl, message);
581} 562}
582 563
586 * Item must be put on a square with a floor, you can have something under. 567 * Item must be put on a square with a floor, you can have something under.
587 * Archetype of created object is item->slaying (raw material). 568 * Archetype of created object is item->slaying (raw material).
588 * Type of inserted item is tested for specific cases (doors & such). 569 * Type of inserted item is tested for specific cases (doors & such).
589 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess) 570 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
590 */ 571 */
591void 572static void
592apply_builder_item (object *pl, object *item, short x, short y) 573apply_builder_item (object *pl, object *item, int x, int y)
593{ 574{
594 object *tmp; 575 object *tmp;
595 struct archetype *arch; 576 struct archetype *arch;
596 int insert_flag; 577 int insert_flag;
597 object *floor; 578 object *floor;
598 object *con_rune; 579 object *con_rune;
599 int connected;
600 580
601 /* Find floor */ 581 /* Find floor */
602 floor = GET_MAP_OB (pl->map, x, y); 582 floor = GET_MAP_OB (pl->map, x, y);
603 if (!floor) 583 if (!floor)
604 { 584 {
619 if (!arch) 599 if (!arch)
620 return; 600 return;
621 601
622 tmp = arch_to_object (arch); 602 tmp = arch_to_object (arch);
623 603
624 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 604 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 */ 605 /* Floor has something on top that interferes with building */
626 { 606 {
627 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 607 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
628 return; 608 return;
629 } 609 }
630 610
631 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 611 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
632 SET_FLAG (tmp, FLAG_NO_PICK); 612 SET_FLAG (tmp, FLAG_NO_PICK);
633 613
634 /* 614 /*
635 * This doesn't work on non unique maps. pedestals under floor will not be saved... 615 * Str 1 is a flag that the item [pedestal] should go below the floor.
636 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 616 * Items under the floor on non-unique maps will not be saved,
617 * so make the item itself unique in this situation.
637 */ 618 */
638 insert_flag = INS_ABOVE_FLOOR_ONLY; 619 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
620 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
621 SET_FLAG (tmp, FLAG_UNIQUE);
639 622
640 connected = 0; 623 shstr_tmp connected;
624
641 switch (tmp->type) 625 switch (tmp->type)
642 { 626 {
643 case DOOR: 627 case DOOR:
644 case GATE: 628 case GATE:
645 case BUTTON: 629 case BUTTON:
646 case DETECTOR: 630 case DETECTOR:
647 case TIMED_GATE: 631 case TIMED_GATE:
648 case PEDESTAL: 632 case PEDESTAL:
649 case CF_HANDLE: 633 case T_HANDLE:
650 case MAGIC_EAR: 634 case MAGIC_EAR:
651 case SIGN: 635 case SIGN:
652 /* Signs don't need a connection, but but magic mouths do. */ 636 /* Signs don't need a connection, but but magic mouths do. */
653 if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) 637 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
654 break; 638 break;
639
655 con_rune = get_connection_rune (pl, x, y); 640 con_rune = get_connection_rune (pl, x, y);
656 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 641 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
657 if (connected == -1) 642 if (!connected)
658 { 643 {
659 /* Player already informed of failure by the previous function */ 644 /* Player already informed of failure by the previous function */
660 tmp->destroy (0); 645 tmp->destroy ();
661 return; 646 return;
662 } 647 }
648
663 /* Remove marking rune */ 649 /* Remove marking rune */
664 con_rune->remove ();
665 con_rune->destroy (0); 650 con_rune->destroy ();
666 } 651 }
667 652
668 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 653 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
669 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 654 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
670 {
671 if (adjust_sign_msg (pl, x, y, tmp) == -1) 655 if (adjust_sign_msg (pl, x, y, tmp) == -1)
672 { 656 {
673 tmp->destroy (0); 657 tmp->destroy ();
674 return; 658 return;
675 } 659 }
676 }
677 660
678 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 661 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
679 if (connected != 0) 662 if (connected)
680 add_button_link (tmp, pl->map, connected); 663 tmp->add_link (pl->map, connected);
681 664
682 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); 665 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
683 decrease_ob_nr (item, 1); 666 item->decrease ();
684} 667}
685 668
686/** 669/**
687 * Item remover. 670 * Item remover.
688 * 671 *
689 * Removes first buildable item, either under or above the floor 672 * Removes first buildable item, either under or above the floor
690 */ 673 */
691void 674static void
692apply_builder_remove (object *pl, int dir) 675apply_builder_remove (object *pl, int dir)
693{ 676{
694 object *item; 677 object *item;
695 short x, y; 678 int x, y;
696 679
697 x = pl->x + freearr_x[dir]; 680 x = pl->x + freearr_x[dir];
698 y = pl->y + freearr_y[dir]; 681 y = pl->y + freearr_y[dir];
699 682
700 /* Check square */ 683 /* Check square */
701 item = GET_MAP_OB (pl->map, x, y); 684 item = GET_MAP_OB (pl->map, x, y);
702 if (!item) 685 if (!item)
703 { 686 {
704 /* Should not happen with previous tests, but we never know */ 687 /* Should not happen with previous tests, but we never know */
705 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 688 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); 689 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
707 return; 690 return;
708 } 691 }
709 692
710 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 693 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR))
711 item = item->above; 694 item = item->above;
712 695
713 if (!item) 696 if (!item)
714 {
715 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 697 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
716 return; 698 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."); 699 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
724 return; 700 else if (!item->flag [FLAG_IS_BUILDABLE])
725 701 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
726 case DOOR: 702 else
727 case BUTTON: 703 {
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)); 704 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
744 item->remove ();
745 item->destroy (0); 705 item->destroy ();
746 } 706 }
747} 707}
748 708
749/** 709/**
750 * Global building function 710 * Global building function
756apply_map_builder (object *pl, int dir) 716apply_map_builder (object *pl, int dir)
757{ 717{
758 object *builder; 718 object *builder;
759 object *tmp; 719 object *tmp;
760 object *tmp2; 720 object *tmp2;
761 short x, y; 721 int x, y;
762 722
763 if (!pl->type == PLAYER) 723 if (!pl->type == PLAYER)
764 return; 724 return;
765 725
766 /*if ( !player->map->unique ) 726 /*if ( !player->map->unique )
776 } 736 }
777 737
778 x = pl->x + freearr_x[dir]; 738 x = pl->x + freearr_x[dir];
779 y = pl->y + freearr_y[dir]; 739 y = pl->y + freearr_y[dir];
780 740
781 if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) 741 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
782 { 742 {
783 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 743 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
784 return; 744 return;
785 } 745 }
786 746
793 753
794 tmp = GET_MAP_OB (pl->map, x, y); 754 tmp = GET_MAP_OB (pl->map, x, y);
795 if (!tmp) 755 if (!tmp)
796 { 756 {
797 /* Nothing, meaning player is standing next to an undefined square... */ 757 /* 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); 758 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."); 759 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
800 return; 760 return;
801 } 761 }
762
802 tmp2 = find_marked_object (pl); 763 tmp2 = find_marked_object (pl);
803 while (tmp) 764 while (tmp)
804 { 765 {
805 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->name, "rune_mark")))) 766 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
806 { 767 {
807 /* The item building function already has it's own special 768 /* The item building function already has it's own special
808 * checks for this 769 * checks for this
809 */ 770 */
810 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 771 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM))
815 } 776 }
816 tmp = tmp->above; 777 tmp = tmp->above;
817 } 778 }
818 779
819 /* Now we know the square is ok */ 780 /* Now we know the square is ok */
820 builder = pl->contr->ranges[range_builder]; 781 builder = pl->contr->ranged_ob;
821 782
822 if (builder->subtype == ST_BD_REMOVE) 783 if (builder->subtype == ST_BD_REMOVE)
823 /* Remover -> call specific function and bail out */ 784 /* Remover -> call specific function and bail out */
824 { 785 {
825 apply_builder_remove (pl, dir); 786 apply_builder_remove (pl, dir);
869 /* Here, it means the builder has an invalid type */ 830 /* Here, it means the builder has an invalid type */
870 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry."); 831 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
871 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); 832 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
872} 833}
873 834
874/**
875 * Make the built object inherit the msg of books that are used with it.
876 * For objects already invisible (i.e. magic mouths & ears), also make it
877 * it inherit the face and the name with "talking " prepended.
878 */
879int
880adjust_sign_msg (object *pl, short x, short y, object *tmp)
881{
882 object *book;
883 char buf[MAX_BUF];
884 char buf2[MAX_BUF];
885
886 book = get_msg_book (pl, x, y);
887 if (!book)
888 {
889 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
890 return -1;
891 }
892
893 tmp->msg = book->msg;
894
895 if (tmp->invisible)
896 {
897 if (book->custom_name != NULL)
898 {
899 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
900 }
901 else
902 {
903 snprintf (buf, sizeof (buf), "talking %s", &book->name);
904 }
905 tmp->name = buf;
906
907 if (book->name_pl != NULL)
908 {
909 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
910 tmp->name_pl = buf2;
911 }
912
913 tmp->face = book->face;
914 tmp->invisible = 0;
915 }
916 book->remove ();
917 book->destroy (0);
918 return 0;
919}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines