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.39 by root, Mon Oct 12 04:02:17 2009 UTC vs.
Revision 1.68 by root, Mon Oct 29 23:55:55 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 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 (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * 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
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * 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
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 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>
28#include <tod.h> 29#include <tod.h>
29#include <sproto.h> 30#include <sproto.h>
30 31
32// macro for this check, it had been inconsistent in this file.
33#define IS_FLOOR(x) x->flag [FLAG_IS_FLOOR]
34
31/** 35/**
32 * Check if objects on a square interfere with building 36 * Check if objects on a square interfere with building
33 */ 37 */
34int 38static int
35can_build_over (maptile *map, object *tmp, short x, short y) 39can_build_over (maptile *map, object *tmp, int x, int y)
36{ 40{
37 object *ob; 41 object *ob;
38 42
39 ob = GET_MAP_OB (map, x, y); 43 ob = GET_MAP_OB (map, x, y);
40 while (ob) 44 while (ob)
41 { 45 {
42 /* if ob is not a marking rune or floor, then check special cases */ 46 /* if ob is not a marking rune or floor, then check special cases */
43 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR) 47 if (ob->arch->archname != shstr_rune_mark && !IS_FLOOR (ob))
44 { 48 {
45 switch (tmp->type) 49 switch (tmp->type)
46 { 50 {
47 case SIGN: 51 case SIGN:
48 case MAGIC_EAR: 52 case MAGIC_EAR:
51 return 0; 55 return 0;
52 break; 56 break;
53 case BUTTON: 57 case BUTTON:
54 case DETECTOR: 58 case DETECTOR:
55 case PEDESTAL: 59 case PEDESTAL:
56 case CF_HANDLE: 60 case T_HANDLE:
57 /* Allow buttons and levers to be built under gates */ 61 /* Allow buttons and levers to be built under gates */
58 if (ob->type != GATE && ob->type != DOOR) 62 if (ob->type != GATE && ob->type != DOOR)
59 return 0; 63 return 0;
60 break; 64 break;
61 default: 65 default:
63 } 67 }
64 } 68 }
65 69
66 ob = ob->above; 70 ob = ob->above;
67 } 71 }
72
68 return 1; 73 return 1;
69} 74}
70 75
71/** 76/**
72 * Erases marking runes at specified location 77 * Erases marking runes at specified location
73 */ 78 */
74void 79static void
75remove_marking_runes (maptile *map, short x, short y) 80remove_marking_runes (maptile *map, int x, int y)
76{ 81{
77 object *rune; 82 object *rune;
78 object *next; 83 object *next;
79 84
80 rune = GET_MAP_OB (map, x, y); 85 rune = GET_MAP_OB (map, x, y);
110 if (!map->find_link (id)) 115 if (!map->find_link (id))
111 return id; 116 return id;
112 } 117 }
113 118
114 return shstr_tmp (); 119 return shstr_tmp ();
120}
121
122/**
123 * Returns the marking rune on the square, for purposes of building connections
124 */
125static object *
126get_connection_rune (object *pl, int x, int y)
127{
128 object *rune = GET_MAP_OB (pl->map, x, y);
129
130 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
131 rune = rune->above;
132
133 return rune;
115} 134}
116 135
117/** 136/**
118 * Helper function for door/button/connected item building. 137 * Helper function for door/button/connected item building.
119 * 138 *
123 * and the rune's text. 142 * and the rune's text.
124 * If found, returns the connection value associated 143 * If found, returns the connection value associated
125 * else searches a new connection value, and adds the force to the player. 144 * else searches a new connection value, and adds the force to the player.
126 */ 145 */
127static shstr_tmp 146static shstr_tmp
128find_or_create_connection_for_map (object *pl, short x, short y, object *rune) 147find_or_create_connection_for_map (object *pl, int x, int y, object *rune)
129{ 148{
130 object *force; 149 object *force;
131 150
132 if (!rune) 151 if (!rune)
133 rune = get_connection_rune (pl, x, y); 152 rune = get_connection_rune (pl, x, y);
155 { 174 {
156 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 175 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
157 return shstr_tmp (); 176 return shstr_tmp ();
158 } 177 }
159 178
160 force = get_archetype (FORCE_NAME); 179 force = archetype::get (FORCE_NAME);
161 force->slaying = pl->map->path; 180 force->slaying = pl->map->path;
162 force->msg = rune->msg; 181 force->msg = rune->msg;
163 force->race = id; 182 force->race = id;
164 force->set_speed (0); 183 force->set_speed (0);
165 184
171 /* Found the force, everything's easy. */ 190 /* Found the force, everything's easy. */
172 return force->race; 191 return force->race;
173} 192}
174 193
175/** 194/**
176 * Returns the marking rune on the square, for purposes of building connections
177 */
178object *
179get_connection_rune (object *pl, short x, short y)
180{
181 object *rune = GET_MAP_OB (pl->map, x, y);
182
183 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
184 rune = rune->above;
185
186 return rune;
187}
188
189/**
190 * Returns the book/scroll on the current square, for purposes of building 195 * Returns the book/scroll on the current square, for purposes of building
191 */ 196 */
192object * 197static object *
193get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, int x, int y)
194{ 199{
195 object *book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
196 201
197 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
198 book = book->above; 203 book = book->above;
199 204
200 return book; 205 return book;
201} 206}
202 207
203/** 208/**
209 * Make the built object inherit the msg of books that are used with it.
210 * For objects already invisible (i.e. magic mouths & ears), also make it
211 * it inherit the face and the name with "talking " prepended.
212 */
213static int
214adjust_sign_msg (object *pl, int x, int y, object *tmp)
215{
216 object *book;
217 char buf[MAX_BUF];
218 char buf2[MAX_BUF];
219
220 book = get_msg_book (pl, x, y);
221 if (!book)
222 {
223 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
224 return -1;
225 }
226
227 if (tmp->type == MAGIC_EAR)
228 {
229 snprintf (buf, sizeof (buf), "@match %s", &(book->msg));
230 tmp->msg = buf;
231 }
232 else
233 tmp->msg = book->msg;
234
235 if (tmp->invisible)
236 {
237 if (book->custom_name)
238 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
239 else
240 snprintf (buf, sizeof (buf), "talking %s", &book->name);
241
242 tmp->name = buf;
243
244 if (book->name_pl)
245 {
246 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
247 tmp->name_pl = buf2;
248 }
249
250 tmp->face = book->face;
251 tmp->invisible = 0;
252 }
253
254 book->destroy ();
255 return 0;
256}
257
258/**
204 * Returns first item of type BUILDABLE_WALL. 259 * Returns first item of type BUILDABLE_WALL.
205 */ 260 */
206object * 261static object *
207get_wall (maptile *map, int x, int y) 262get_wall (maptile *map, int x, int y)
208{ 263{
209 object *wall = GET_MAP_OB (map, x, y); 264 object *wall = GET_MAP_OB (map, x, y);
210 265
211 while (wall && (BUILDABLE_WALL != wall->type)) 266 while (wall && (BUILDABLE_WALL != wall->type))
223 * 278 *
224 * Basically it ensures the correct wall is put where needed. 279 * Basically it ensures the correct wall is put where needed.
225 * 280 *
226 * Note: x & y must be valid map coordinates. 281 * Note: x & y must be valid map coordinates.
227 */ 282 */
228void 283static void
229fix_walls (maptile *map, int x, int y) 284fix_walls (maptile *map, int x, int y)
230{ 285{
231 char archetype[MAX_BUF]; 286 char archetype[MAX_BUF];
232 char *underscore; 287 char *underscore;
233 struct archetype *new_arch; 288 struct archetype *new_arch;
253 underscore++; 308 underscore++;
254 *underscore = '\0'; 309 *underscore = '\0';
255 310
256 int connect = 0; 311 int connect = 0;
257 312
258 if ((x > 0) && get_wall (map, x - 1, y)) 313 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
259 connect |= 1;
260 if ((x < map->width - 1) && get_wall (map, x + 1, y)) 314 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
261 connect |= 2; 315 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
262
263 if ((y > 0) && get_wall (map, x, y - 1))
264 connect |= 4;
265
266 if ((y < map->height - 1) && get_wall (map, x, y + 1)) 316 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
267 connect |= 8;
268 317
269 switch (connect) 318 strcat (archetype, wall_suffix [connect]);
270 {
271 case 0:
272 strcat (archetype, "0");
273
274 break;
275 case 1:
276 strcat (archetype, "1_3");
277
278 break;
279 case 2:
280 strcat (archetype, "1_4");
281
282 break;
283 case 3:
284 strcat (archetype, "2_1_2");
285
286 break;
287 case 4:
288 strcat (archetype, "1_2");
289
290 break;
291 case 5:
292 strcat (archetype, "2_2_4");
293
294 break;
295 case 6:
296 strcat (archetype, "2_2_1");
297
298 break;
299 case 7:
300 strcat (archetype, "3_1");
301
302 break;
303 case 8:
304 strcat (archetype, "1_1");
305
306 break;
307 case 9:
308 strcat (archetype, "2_2_3");
309
310 break;
311 case 10:
312 strcat (archetype, "2_2_2");
313
314 break;
315 case 11:
316 strcat (archetype, "3_3");
317
318 break;
319 case 12:
320 strcat (archetype, "2_1_1");
321
322 break;
323 case 13:
324 strcat (archetype, "3_4");
325
326 break;
327 case 14:
328 strcat (archetype, "3_2");
329
330 break;
331 case 15:
332 strcat (archetype, "4");
333
334 break;
335 }
336 319
337 /* 320 /*
338 * Before anything, make sure the archetype does exist... 321 * Before anything, make sure the archetype does exist...
339 * If not, prolly an error... 322 * If not, prolly an error...
340 */ 323 */
348 */ 331 */
349 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off 332 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
350 333
351 wall->destroy (); 334 wall->destroy ();
352 335
353 wall = arch_to_object (new_arch); 336 wall = new_arch->instance ();
354 wall->type = BUILDABLE_WALL; 337 wall->type = BUILDABLE_WALL;
355 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 338 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
356 wall->flag = old_flags; 339 wall->flag = old_flags;
357} 340}
358 341
364 * - on an existing wall, with or without a floor under it 347 * - on an existing wall, with or without a floor under it
365 * 348 *
366 * Note: this function will inconditionally change squares around (x, y) 349 * Note: this function will inconditionally change squares around (x, y)
367 * so don't call it with x == 0 for instance! 350 * so don't call it with x == 0 for instance!
368 */ 351 */
369void 352static void
370apply_builder_floor (object *pl, object *material, short x, short y) 353apply_builder_floor (object *pl, object *material, int x, int y)
371{ 354{
372 object *tmp, *above; 355 object *tmp, *above;
373 object *above_floor; /* Item above floor, if any */ 356 object *above_floor; /* Item above floor, if any */
374 struct archetype *new_floor; 357 struct archetype *new_floor;
375 struct archetype *new_wall; 358 struct archetype *new_wall;
396 /* There was a wall, remove it & keep its archetype to make new walls */ 379 /* There was a wall, remove it & keep its archetype to make new walls */
397 new_wall = tmp->arch; 380 new_wall = tmp->arch;
398 tmp->destroy (); 381 tmp->destroy ();
399 sprintf (message, "You destroy the wall and redo the floor."); 382 sprintf (message, "You destroy the wall and redo the floor.");
400 } 383 }
401 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 384 else if (IS_FLOOR (tmp))
402 { 385 {
403 tmp->destroy (); 386 tmp->destroy ();
404 floor_removed = 1; 387 floor_removed = 1;
405 } 388 }
406 else 389 else
424 /* Not found, log & bail out */ 407 /* Not found, log & bail out */
425 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying); 408 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
426 return; 409 return;
427 } 410 }
428 411
429 tmp = arch_to_object (new_floor); 412 tmp = new_floor->instance ();
430 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 413 tmp->set_flag (FLAG_IS_BUILDABLE);
431 SET_FLAG (tmp, FLAG_UNIQUE); 414 tmp->set_flag (FLAG_UNIQUE);
432 SET_FLAG (tmp, FLAG_IS_FLOOR); 415 tmp->set_flag (FLAG_IS_FLOOR);
433 tmp->type = FLOOR; 416 //tmp->type = FLOOR;
434 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y); 417 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
435 418
436 /* 419 /*
437 * Next step: make sure there are either walls or floors around the new square 420 * Next step: make sure there are either walls or floors around the new square
438 * Since building, you can have: blocking view / floor / wall / nothing 421 * Since building, you can have: blocking view / floor / wall / nothing
443 yt = y + freearr_y[i]; 426 yt = y + freearr_y[i];
444 tmp = GET_MAP_OB (pl->map, xt, yt); 427 tmp = GET_MAP_OB (pl->map, xt, yt);
445 if (!tmp) 428 if (!tmp)
446 { 429 {
447 /* Must insert floor & wall */ 430 /* Must insert floor & wall */
448 tmp = arch_to_object (new_floor); 431 tmp = new_floor->instance ();
449 /* Better make the floor unique */ 432 /* Better make the floor unique */
450 SET_FLAG (tmp, FLAG_UNIQUE); 433 tmp->set_flag (FLAG_UNIQUE);
451 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 434 tmp->set_flag (FLAG_IS_BUILDABLE);
452 tmp->type = FLOOR; 435 //tmp->type = FLOOR;
453 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 436 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
454 /* Insert wall if exists. Note: if it doesn't, the map is weird... */ 437 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
455 if (new_wall) 438 if (new_wall)
456 { 439 {
457 tmp = arch_to_object (new_wall); 440 tmp = new_wall->instance ();
458 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 441 tmp->set_flag (FLAG_IS_BUILDABLE);
459 tmp->type = BUILDABLE_WALL; 442 tmp->type = BUILDABLE_WALL;
460 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 443 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
461 } 444 }
462 } 445 }
463 } 446 }
466 * Note: 2 squares around are checked, because potentially we added walls around the building 449 * Note: 2 squares around are checked, because potentially we added walls around the building
467 * spot, so need to check that those new walls connect correctly 450 * spot, so need to check that those new walls connect correctly
468 */ 451 */
469 for (xt = x - 2; xt <= x + 2; xt++) 452 for (xt = x - 2; xt <= x + 2; xt++)
470 for (yt = y - 2; yt <= y + 2; yt++) 453 for (yt = y - 2; yt <= y + 2; yt++)
471 {
472 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 454 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
473 fix_walls (pl->map, xt, yt); 455 fix_walls (pl->map, xt, yt);
474 }
475 456
476 /* Now remove raw item from inventory */ 457 /* Now remove raw item from inventory */
477 material->decrease (); 458 material->decrease ();
478 459
479 /* And tell player about the fix */ 460 /* And tell player about the fix */
480 new_draw_info (NDI_UNIQUE, 0, pl, message); 461 new_draw_info (NDI_UNIQUE, 0, pl, message);
481}
482
483/**
484 * Wall radius fix function
485 */
486void fix_walls_around (maptile *map, int x, int y)
487{
488 for (int xt = x - 1; xt <= x + 1; xt++)
489 for (int yt = y - 1; yt <= y + 1; yt++)
490 {
491 if (OUT_OF_REAL_MAP (map, xt, yt))
492 continue;
493
494 fix_walls (map, xt, yt);
495 }
496} 462}
497 463
498/** 464/**
499 * Wall building function 465 * Wall building function
500 * 466 *
501 * Walls can be build: 467 * Walls can be build:
502 * - on a floor without anything else 468 * - on a floor without anything else
503 * - on an existing wall, with or without a floor 469 * - on an existing wall, with or without a floor
504 */ 470 */
505void 471static void
506apply_builder_wall (object *pl, object *material, short x, short y) 472apply_builder_wall (object *pl, object *material, int x, int y)
507{ 473{
508 object *current_wall; 474 object *current_wall;
509 object *tmp; 475 object *tmp;
510 int xt, yt; 476 int xt, yt;
511 struct archetype *new_wall; 477 struct archetype *new_wall;
533 { 499 {
534 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); 500 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
535 return; 501 return;
536 } 502 }
537 503
538 tmp = arch_to_object (new_wall); 504 tmp = new_wall->instance ();
539 tmp->type = BUILDABLE_WALL; 505 tmp->type = BUILDABLE_WALL;
540 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 506 tmp->set_flag (FLAG_IS_BUILDABLE);
541 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 507 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
542 508
543 /* If existing wall, remove it, no need to fix other walls */ 509 /* If existing wall, remove it, no need to fix other walls */
544 if (current_wall) 510 if (current_wall)
545 { 511 {
573 * Item must be put on a square with a floor, you can have something under. 539 * Item must be put on a square with a floor, you can have something under.
574 * Archetype of created object is item->slaying (raw material). 540 * Archetype of created object is item->slaying (raw material).
575 * Type of inserted item is tested for specific cases (doors & such). 541 * Type of inserted item is tested for specific cases (doors & such).
576 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess) 542 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
577 */ 543 */
578void 544static void
579apply_builder_item (object *pl, object *item, short x, short y) 545apply_builder_item (object *pl, object *item, int x, int y)
580{ 546{
581 object *tmp; 547 object *tmp;
582 struct archetype *arch; 548 struct archetype *arch;
583 int insert_flag; 549 int insert_flag;
584 object *floor; 550 object *floor;
590 { 556 {
591 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 557 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
592 return; 558 return;
593 } 559 }
594 560
595 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) 561 while (floor && !IS_FLOOR (floor))
596 floor = floor->above; 562 floor = floor->above;
597 563
598 if (!floor) 564 if (!floor)
599 { 565 {
600 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here."); 566 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
603 /* Create item, set flag, insert in map */ 569 /* Create item, set flag, insert in map */
604 arch = archetype::find (item->slaying); 570 arch = archetype::find (item->slaying);
605 if (!arch) 571 if (!arch)
606 return; 572 return;
607 573
608 tmp = arch_to_object (arch); 574 tmp = arch->instance ();
609 575
610 if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y))) 576 if (!floor->flag[FLAG_IS_BUILDABLE] || floor->above && !can_build_over (pl->map, tmp, x, y))
611 /* Floor has something on top that interferes with building */ 577 /* Floor has something on top that interferes with building */
612 { 578 {
613 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 579 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
614 return; 580 return;
615 } 581 }
616 582
617 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 583 tmp->set_flag (FLAG_IS_BUILDABLE);
618 SET_FLAG (tmp, FLAG_NO_PICK); 584 tmp->set_flag (FLAG_NO_PICK);
619 585
620 /* 586 /*
621 * Str 1 is a flag that the item [pedestal] should go below the floor. 587 * Str 1 is a flag that the item [pedestal] should go below the floor.
622 * Items under the floor on non-unique maps will not be saved, 588 * Items under the floor on non-unique maps will not be saved,
623 * so make the item itself unique in this situation. 589 * so make the item itself unique in this situation.
624 */ 590 */
625 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 591 insert_flag = item->stats.Str == 1 ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
626 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) 592 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
627 SET_FLAG (tmp, FLAG_UNIQUE); 593 tmp->set_flag (FLAG_UNIQUE);
628 594
629 shstr_tmp connected; 595 shstr_tmp connected;
630 596
631 switch (tmp->type) 597 switch (tmp->type)
632 { 598 {
634 case GATE: 600 case GATE:
635 case BUTTON: 601 case BUTTON:
636 case DETECTOR: 602 case DETECTOR:
637 case TIMED_GATE: 603 case TIMED_GATE:
638 case PEDESTAL: 604 case PEDESTAL:
639 case CF_HANDLE: 605 case T_HANDLE:
640 case MAGIC_EAR: 606 case MAGIC_EAR:
641 case SIGN: 607 case SIGN:
642 /* Signs don't need a connection, but but magic mouths do. */ 608 /* Signs don't need a connection, but but magic mouths do. */
643 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) 609 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
644 break; 610 break;
656 con_rune->destroy (); 622 con_rune->destroy ();
657 } 623 }
658 624
659 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 625 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
660 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 626 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
661 {
662 if (adjust_sign_msg (pl, x, y, tmp) == -1) 627 if (adjust_sign_msg (pl, x, y, tmp) == -1)
663 { 628 {
664 tmp->destroy (); 629 tmp->destroy ();
665 return; 630 return;
666 } 631 }
667 }
668 632
669 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 633 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
670 if (connected) 634 if (connected)
671 tmp->add_link (pl->map, connected); 635 tmp->add_link (pl->map, connected);
672 636
677/** 641/**
678 * Item remover. 642 * Item remover.
679 * 643 *
680 * Removes first buildable item, either under or above the floor 644 * Removes first buildable item, either under or above the floor
681 */ 645 */
682void 646static void
683apply_builder_remove (object *pl, int dir) 647apply_builder_remove (object *pl, int dir)
684{ 648{
685 object *item; 649 object *item;
686 short x, y; 650 int x, y;
687 651
688 x = pl->x + freearr_x[dir]; 652 x = pl->x + freearr_x[dir];
689 y = pl->y + freearr_y[dir]; 653 y = pl->y + freearr_y[dir];
690 654
691 /* Check square */ 655 /* Check square */
696 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 660 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
697 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path); 661 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
698 return; 662 return;
699 } 663 }
700 664
701 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 665 if (IS_FLOOR (item))
702 item = item->above; 666 item = item->above;
703 667
704 if (!item) 668 if (!item)
705 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 669 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
706 else if (item->type == BUILDABLE_WALL) 670 else if (item->type == BUILDABLE_WALL)
712 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); 676 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
713 item->destroy (); 677 item->destroy ();
714 } 678 }
715} 679}
716 680
681
682static void
683replace_open_space_floor (object *os, object *material)
684{
685 object *new_floor = archetype::get (material->slaying);
686 insert_ob_in_map_at (new_floor, os->map, os,
687 INS_BELOW_ORIGINATOR, os->x, os->y);
688 os->destroy ();
689 material->decrease ();
690}
691
692/**
693 * Quad building.
694 */
695void
696apply_builder_quad (object *pl, object *material, mapxy &pos)
697{
698 object *open_space = 0;
699 object *floor = 0;
700
701 object *tmp = pos.ms ().bot;
702 bool floor_exists = false;
703 while (tmp)
704 {
705 if (floor_exists && tmp->flag [FLAG_IS_QUAD])
706 {
707 pl->failmsg (
708 "You can't build there, there is a block in the way.");
709 return;
710 }
711
712 if (IS_FLOOR (tmp))
713 {
714 floor = tmp;
715 floor_exists = true;
716
717 if (floor->arch->archname == shstr_quad_open_space)
718 {
719 open_space = floor;
720 }
721 else if (!floor->flag [FLAG_IS_QUAD])
722 {
723 pl->failmsg (
724 "You can't build there, the floor is not suited.");
725 return;
726 }
727 }
728
729 tmp = tmp->above;
730 }
731
732 if (open_space)
733 {
734 if (!material->slaying)
735 {
736 pl->failmsg (
737 "The floor is open and you can't fill it with that material."
738 "H<Use another material to fill the ceiling.>");
739 return;
740 }
741
742 replace_open_space_floor (open_space, material);
743 pl->contr->fire_on = 0; // TODO: stopgap, do not add more than one per keypress
744 return;
745 }
746 else if (floor)
747 {
748
749 maptile *upper_floor = pos.m->tile_available (TILE_UP);
750 if (!upper_floor)
751 {
752 pl->failmsg (
753 "Whoops, you can't see the ceiling.. H<You may try again.>");
754 return;
755 }
756
757 mapxy above_pos (upper_floor, pos.x, pos.y);
758 if (!above_pos.normalise ())
759 {
760 pl->failmsg (
761 "Whoops, you can't access the ceiling. H<You may try again.>");
762 return;
763 }
764
765 mapspace &above_ms = above_pos.ms ();
766 for (object *quad_obj = above_ms.top; quad_obj; quad_obj = quad_obj->below)
767 {
768 if (quad_obj->arch->archname == shstr_quad_open_space)
769 {
770 if (!material->slaying)
771 {
772 pl->failmsg (
773 "The ceiling is open and you can't fill it with that material."
774 "H<Use another material to fill the ceiling.>");
775 return;
776 }
777
778 replace_open_space_floor (quad_obj, material);
779 break;
780 }
781 }
782
783 if (material->destroyed ())
784 {
785 pl->failmsg (
786 "You don't have enough build material to build a wall here.");
787 return;
788 }
789
790 object *quad_wall = material->other_arch->instance ();
791 material->decrease ();
792
793 insert_ob_in_map_at (quad_wall, floor->map, 0,
794 INS_ABOVE_FLOOR_ONLY, floor->x, floor->y);
795 }
796 else
797 {
798 pl->failmsg ("You can't build a quad block here.");
799 }
800}
801
717/** 802/**
718 * Global building function 803 * Global building function
719 * 804 *
720 * This is the general map building function. Called when the player 'fires' a builder 805 * This is the general map building function. Called when the player 'fires' a builder
721 * or remover object. 806 * or remover object.
722 */ 807 */
723void 808void
724apply_map_builder (object *pl, int dir) 809apply_map_builder (object *pl, int dir)
725{ 810{
726 object *builder;
727 object *tmp;
728 object *tmp2;
729 short x, y;
730
731 if (!pl->type == PLAYER) 811 if (!pl->type == PLAYER)
732 return; 812 return;
733 813
734 /*if ( !player->map->unique )
735 {
736 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
737 return;
738 } */
739
740 if (dir == 0) 814 if (dir == 0)
741 { 815 {
742 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself."); 816 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
743 return; 817 return;
744 } 818 }
745 819
746 x = pl->x + freearr_x[dir]; 820 mapxy pos (pl); pos.move (dir);
747 y = pl->y + freearr_y[dir];
748 821
749 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) 822 if (!pos.normalise ())
750 { 823 {
751 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); 824 pl->failmsg ("You can't build here. H<There is nothing in this direction.>");
752 return; 825 return;
753 } 826 }
754 827
755 /* 828 /*
756 * Check specified square 829 * Check specified square
757 * The square must have only buildable items 830 * The square must have only buildable items
758 * Exception: marking runes are all right, 831 * Exception: marking runes are all right,
759 * since they are used for special things like connecting doors / buttons 832 * since they are used for special things like connecting doors / buttons
760 */ 833 */
761 834
762 tmp = GET_MAP_OB (pl->map, x, y); 835 object *builder = pl->contr->ranged_ob;
763 if (!tmp) 836
764 { 837 object *tmp2 = pl->mark ();
765 /* Nothing, meaning player is standing next to an undefined square... */ 838
766 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 839 object *tmp = 0;
767 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 840 for (tmp = pos.ms ().bot; tmp; tmp = tmp->above)
768 return;
769 } 841 {
770 842 if (!tmp->flag [FLAG_IS_BUILDABLE]
771 tmp2 = find_marked_object (pl);
772 while (tmp)
773 {
774 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) 843 && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
775 { 844 {
776 /* The item building function already has it's own special 845 /* The item building function already has it's own special
777 * checks for this 846 * checks for this. And so does the quad building function.
778 */ 847 */
779 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 848 if (!tmp2 || (tmp2->subtype != ST_MAT_ITEM && tmp2->subtype != ST_MAT_QUAD))
780 { 849 {
850 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
851 ARG_MAP (pl->map),
852 ARG_INT (pos.y), ARG_INT (pos.y),
853 ARG_INT (0)))
781 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 854 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
855
782 return; 856 return;
783 } 857 }
784 } 858 }
785 tmp = tmp->above;
786 } 859 }
787 860
788 /* Now we know the square is ok */ 861 /* Now we know the square is ok */
789 builder = pl->contr->ranged_ob; 862 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
863 ARG_MAP (pl->map), ARG_INT (pos.x), ARG_INT (pos.y), ARG_INT (1)))
864 return;
790 865
791 if (builder->subtype == ST_BD_REMOVE) 866 if (builder->subtype == ST_BD_REMOVE)
792 /* Remover -> call specific function and bail out */ 867 /* Remover -> call specific function and bail out */
793 { 868 {
794 apply_builder_remove (pl, dir); 869 apply_builder_remove (pl, dir);
814 return; 889 return;
815 } 890 }
816 891
817 switch (tmp->subtype) 892 switch (tmp->subtype)
818 { 893 {
819 case ST_MAT_FLOOR: 894 case ST_MAT_FLOOR:
820 apply_builder_floor (pl, tmp, x, y); 895 apply_builder_floor (pl, tmp, pos.x, pos.y);
821 return; 896 return;
822 897
823 case ST_MAT_WALL: 898 case ST_MAT_WALL:
824 apply_builder_wall (pl, tmp, x, y); 899 apply_builder_wall (pl, tmp, pos.x, pos.y);
825 return; 900 return;
826 901
827 case ST_MAT_ITEM: 902 case ST_MAT_ITEM:
828 apply_builder_item (pl, tmp, x, y); 903 apply_builder_item (pl, tmp, pos.x, pos.y);
829 return; 904 return;
830 905
906 case ST_MAT_QUAD:
907 apply_builder_quad (pl, tmp, pos);
908 return;
909
831 default: 910 default:
832 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry."); 911 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
833 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype); 912 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
834 return; 913 return;
835 } 914 }
836 } 915 }
837 916
838 /* Here, it means the builder has an invalid type */ 917 /* Here, it means the builder has an invalid type */
839 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry."); 918 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
840 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); 919 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
841} 920}
842 921
843/**
844 * Make the built object inherit the msg of books that are used with it.
845 * For objects already invisible (i.e. magic mouths & ears), also make it
846 * it inherit the face and the name with "talking " prepended.
847 */
848int
849adjust_sign_msg (object *pl, short x, short y, object *tmp)
850{
851 object *book;
852 char buf[MAX_BUF];
853 char buf2[MAX_BUF];
854
855 book = get_msg_book (pl, x, y);
856 if (!book)
857 {
858 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
859 return -1;
860 }
861
862 tmp->msg = book->msg;
863
864 if (tmp->invisible)
865 {
866 if (book->custom_name != NULL)
867 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
868 else
869 snprintf (buf, sizeof (buf), "talking %s", &book->name);
870
871 tmp->name = buf;
872
873 if (book->name_pl != NULL)
874 {
875 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
876 tmp->name_pl = buf2;
877 }
878
879 tmp->face = book->face;
880 tmp->invisible = 0;
881 }
882
883 book->destroy ();
884 return 0;
885}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines