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.38 by sf-marcmagus, Fri Oct 9 21:21:49 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:
49 /* Allow signs and magic ears to be built on books */ 53 /* Allow signs and magic ears to be built on books */
50 if (ob->type != BOOK) 54 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; 55 return 0;
56 break;
57 case BUTTON:
58 case DETECTOR:
59 case PEDESTAL:
60 case T_HANDLE:
61 /* Allow buttons and levers to be built under gates */
62 if (ob->type != GATE && ob->type != DOOR)
63 return 0;
64 break;
65 default:
66 return 0;
67 } 67 }
68 } 68 }
69
69 ob = ob->above; 70 ob = ob->above;
70 } 71 }
72
71 return 1; 73 return 1;
72} 74}
73 75
74/** 76/**
75 * Erases marking runes at specified location 77 * Erases marking runes at specified location
76 */ 78 */
77void 79static void
78remove_marking_runes (maptile *map, short x, short y) 80remove_marking_runes (maptile *map, int x, int y)
79{ 81{
80 object *rune; 82 object *rune;
81 object *next; 83 object *next;
82 84
83 rune = GET_MAP_OB (map, x, y); 85 rune = GET_MAP_OB (map, x, y);
113 if (!map->find_link (id)) 115 if (!map->find_link (id))
114 return id; 116 return id;
115 } 117 }
116 118
117 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;
118} 134}
119 135
120/** 136/**
121 * Helper function for door/button/connected item building. 137 * Helper function for door/button/connected item building.
122 * 138 *
126 * and the rune's text. 142 * and the rune's text.
127 * If found, returns the connection value associated 143 * If found, returns the connection value associated
128 * 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.
129 */ 145 */
130static shstr_tmp 146static shstr_tmp
131find_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)
132{ 148{
133 object *force; 149 object *force;
134 150
135 if (!rune) 151 if (!rune)
136 rune = get_connection_rune (pl, x, y); 152 rune = get_connection_rune (pl, x, y);
158 { 174 {
159 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.");
160 return shstr_tmp (); 176 return shstr_tmp ();
161 } 177 }
162 178
163 force = get_archetype (FORCE_NAME); 179 force = archetype::get (FORCE_NAME);
164 force->slaying = pl->map->path; 180 force->slaying = pl->map->path;
165 force->msg = rune->msg; 181 force->msg = rune->msg;
166 force->race = id; 182 force->race = id;
167 force->set_speed (0); 183 force->set_speed (0);
168 184
174 /* Found the force, everything's easy. */ 190 /* Found the force, everything's easy. */
175 return force->race; 191 return force->race;
176} 192}
177 193
178/** 194/**
179 * Returns the marking rune on the square, for purposes of building connections
180 */
181object *
182get_connection_rune (object *pl, short x, short y)
183{
184 object *rune = GET_MAP_OB (pl->map, x, y);
185
186 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
187 rune = rune->above;
188
189 return rune;
190}
191
192/**
193 * 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
194 */ 196 */
195object * 197static object *
196get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, int x, int y)
197{ 199{
198 object *book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
199 201
200 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
201 book = book->above; 203 book = book->above;
202 204
203 return book; 205 return book;
204} 206}
205 207
206/** 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/**
207 * Returns first item of type BUILDABLE_WALL. 259 * Returns first item of type BUILDABLE_WALL.
208 */ 260 */
209object * 261static object *
210get_wall (maptile *map, int x, int y) 262get_wall (maptile *map, int x, int y)
211{ 263{
212 object *wall = GET_MAP_OB (map, x, y); 264 object *wall = GET_MAP_OB (map, x, y);
213 265
214 while (wall && (BUILDABLE_WALL != wall->type)) 266 while (wall && (BUILDABLE_WALL != wall->type))
226 * 278 *
227 * Basically it ensures the correct wall is put where needed. 279 * Basically it ensures the correct wall is put where needed.
228 * 280 *
229 * Note: x & y must be valid map coordinates. 281 * Note: x & y must be valid map coordinates.
230 */ 282 */
231void 283static void
232fix_walls (maptile *map, int x, int y) 284fix_walls (maptile *map, int x, int y)
233{ 285{
234 char archetype[MAX_BUF]; 286 char archetype[MAX_BUF];
235 char *underscore; 287 char *underscore;
236 struct archetype *new_arch; 288 struct archetype *new_arch;
256 underscore++; 308 underscore++;
257 *underscore = '\0'; 309 *underscore = '\0';
258 310
259 int connect = 0; 311 int connect = 0;
260 312
261 if ((x > 0) && get_wall (map, x - 1, y)) 313 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
262 connect |= 1;
263 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;
264 connect |= 2; 315 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
265
266 if ((y > 0) && get_wall (map, x, y - 1))
267 connect |= 4;
268
269 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;
270 connect |= 8;
271 317
272 switch (connect) 318 strcat (archetype, wall_suffix [connect]);
273 {
274 case 0:
275 strcat (archetype, "0");
276
277 break;
278 case 1:
279 strcat (archetype, "1_3");
280
281 break;
282 case 2:
283 strcat (archetype, "1_4");
284
285 break;
286 case 3:
287 strcat (archetype, "2_1_2");
288
289 break;
290 case 4:
291 strcat (archetype, "1_2");
292
293 break;
294 case 5:
295 strcat (archetype, "2_2_4");
296
297 break;
298 case 6:
299 strcat (archetype, "2_2_1");
300
301 break;
302 case 7:
303 strcat (archetype, "3_1");
304
305 break;
306 case 8:
307 strcat (archetype, "1_1");
308
309 break;
310 case 9:
311 strcat (archetype, "2_2_3");
312
313 break;
314 case 10:
315 strcat (archetype, "2_2_2");
316
317 break;
318 case 11:
319 strcat (archetype, "3_3");
320
321 break;
322 case 12:
323 strcat (archetype, "2_1_1");
324
325 break;
326 case 13:
327 strcat (archetype, "3_4");
328
329 break;
330 case 14:
331 strcat (archetype, "3_2");
332
333 break;
334 case 15:
335 strcat (archetype, "4");
336
337 break;
338 }
339 319
340 /* 320 /*
341 * Before anything, make sure the archetype does exist... 321 * Before anything, make sure the archetype does exist...
342 * If not, prolly an error... 322 * If not, prolly an error...
343 */ 323 */
351 */ 331 */
352 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
353 333
354 wall->destroy (); 334 wall->destroy ();
355 335
356 wall = arch_to_object (new_arch); 336 wall = new_arch->instance ();
357 wall->type = BUILDABLE_WALL; 337 wall->type = BUILDABLE_WALL;
358 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);
359 wall->flag = old_flags; 339 wall->flag = old_flags;
360} 340}
361 341
367 * - on an existing wall, with or without a floor under it 347 * - on an existing wall, with or without a floor under it
368 * 348 *
369 * Note: this function will inconditionally change squares around (x, y) 349 * Note: this function will inconditionally change squares around (x, y)
370 * so don't call it with x == 0 for instance! 350 * so don't call it with x == 0 for instance!
371 */ 351 */
372void 352static void
373apply_builder_floor (object *pl, object *material, short x, short y) 353apply_builder_floor (object *pl, object *material, int x, int y)
374{ 354{
375 object *tmp, *above; 355 object *tmp, *above;
376 object *above_floor; /* Item above floor, if any */ 356 object *above_floor; /* Item above floor, if any */
377 struct archetype *new_floor; 357 struct archetype *new_floor;
378 struct archetype *new_wall; 358 struct archetype *new_wall;
399 /* 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 */
400 new_wall = tmp->arch; 380 new_wall = tmp->arch;
401 tmp->destroy (); 381 tmp->destroy ();
402 sprintf (message, "You destroy the wall and redo the floor."); 382 sprintf (message, "You destroy the wall and redo the floor.");
403 } 383 }
404 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 384 else if (IS_FLOOR (tmp))
405 { 385 {
406 tmp->destroy (); 386 tmp->destroy ();
407 floor_removed = 1; 387 floor_removed = 1;
408 } 388 }
409 else 389 else
427 /* Not found, log & bail out */ 407 /* Not found, log & bail out */
428 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);
429 return; 409 return;
430 } 410 }
431 411
432 tmp = arch_to_object (new_floor); 412 tmp = new_floor->instance ();
433 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 413 tmp->set_flag (FLAG_IS_BUILDABLE);
434 SET_FLAG (tmp, FLAG_UNIQUE); 414 tmp->set_flag (FLAG_UNIQUE);
435 SET_FLAG (tmp, FLAG_IS_FLOOR); 415 tmp->set_flag (FLAG_IS_FLOOR);
436 tmp->type = FLOOR; 416 //tmp->type = FLOOR;
437 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);
438 418
439 /* 419 /*
440 * 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
441 * Since building, you can have: blocking view / floor / wall / nothing 421 * Since building, you can have: blocking view / floor / wall / nothing
446 yt = y + freearr_y[i]; 426 yt = y + freearr_y[i];
447 tmp = GET_MAP_OB (pl->map, xt, yt); 427 tmp = GET_MAP_OB (pl->map, xt, yt);
448 if (!tmp) 428 if (!tmp)
449 { 429 {
450 /* Must insert floor & wall */ 430 /* Must insert floor & wall */
451 tmp = arch_to_object (new_floor); 431 tmp = new_floor->instance ();
452 /* Better make the floor unique */ 432 /* Better make the floor unique */
453 SET_FLAG (tmp, FLAG_UNIQUE); 433 tmp->set_flag (FLAG_UNIQUE);
454 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 434 tmp->set_flag (FLAG_IS_BUILDABLE);
455 tmp->type = FLOOR; 435 //tmp->type = FLOOR;
456 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);
457 /* 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... */
458 if (new_wall) 438 if (new_wall)
459 { 439 {
460 tmp = arch_to_object (new_wall); 440 tmp = new_wall->instance ();
461 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 441 tmp->set_flag (FLAG_IS_BUILDABLE);
462 tmp->type = BUILDABLE_WALL; 442 tmp->type = BUILDABLE_WALL;
463 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);
464 } 444 }
465 } 445 }
466 } 446 }
469 * 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
470 * spot, so need to check that those new walls connect correctly 450 * spot, so need to check that those new walls connect correctly
471 */ 451 */
472 for (xt = x - 2; xt <= x + 2; xt++) 452 for (xt = x - 2; xt <= x + 2; xt++)
473 for (yt = y - 2; yt <= y + 2; yt++) 453 for (yt = y - 2; yt <= y + 2; yt++)
474 {
475 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 454 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
476 fix_walls (pl->map, xt, yt); 455 fix_walls (pl->map, xt, yt);
477 }
478 456
479 /* Now remove raw item from inventory */ 457 /* Now remove raw item from inventory */
480 material->decrease (); 458 material->decrease ();
481 459
482 /* And tell player about the fix */ 460 /* And tell player about the fix */
483 new_draw_info (NDI_UNIQUE, 0, pl, message); 461 new_draw_info (NDI_UNIQUE, 0, pl, message);
484}
485
486/**
487 * Wall radius fix function
488 */
489void fix_walls_around (maptile *map, int x, int y)
490{
491 for (int xt = x - 1; xt <= x + 1; xt++)
492 for (int yt = y - 1; yt <= y + 1; yt++)
493 {
494 if (OUT_OF_REAL_MAP (map, xt, yt))
495 continue;
496
497 fix_walls (map, xt, yt);
498 }
499} 462}
500 463
501/** 464/**
502 * Wall building function 465 * Wall building function
503 * 466 *
504 * Walls can be build: 467 * Walls can be build:
505 * - on a floor without anything else 468 * - on a floor without anything else
506 * - on an existing wall, with or without a floor 469 * - on an existing wall, with or without a floor
507 */ 470 */
508void 471static void
509apply_builder_wall (object *pl, object *material, short x, short y) 472apply_builder_wall (object *pl, object *material, int x, int y)
510{ 473{
511 object *current_wall; 474 object *current_wall;
512 object *tmp; 475 object *tmp;
513 int xt, yt; 476 int xt, yt;
514 struct archetype *new_wall; 477 struct archetype *new_wall;
536 { 499 {
537 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);
538 return; 501 return;
539 } 502 }
540 503
541 tmp = arch_to_object (new_wall); 504 tmp = new_wall->instance ();
542 tmp->type = BUILDABLE_WALL; 505 tmp->type = BUILDABLE_WALL;
543 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 506 tmp->set_flag (FLAG_IS_BUILDABLE);
544 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);
545 508
546 /* If existing wall, remove it, no need to fix other walls */ 509 /* If existing wall, remove it, no need to fix other walls */
547 if (current_wall) 510 if (current_wall)
548 { 511 {
576 * 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.
577 * Archetype of created object is item->slaying (raw material). 540 * Archetype of created object is item->slaying (raw material).
578 * Type of inserted item is tested for specific cases (doors & such). 541 * Type of inserted item is tested for specific cases (doors & such).
579 * 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)
580 */ 543 */
581void 544static void
582apply_builder_item (object *pl, object *item, short x, short y) 545apply_builder_item (object *pl, object *item, int x, int y)
583{ 546{
584 object *tmp; 547 object *tmp;
585 struct archetype *arch; 548 struct archetype *arch;
586 int insert_flag; 549 int insert_flag;
587 object *floor; 550 object *floor;
593 { 556 {
594 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 557 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
595 return; 558 return;
596 } 559 }
597 560
598 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) 561 while (floor && !IS_FLOOR (floor))
599 floor = floor->above; 562 floor = floor->above;
600 563
601 if (!floor) 564 if (!floor)
602 { 565 {
603 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.");
606 /* Create item, set flag, insert in map */ 569 /* Create item, set flag, insert in map */
607 arch = archetype::find (item->slaying); 570 arch = archetype::find (item->slaying);
608 if (!arch) 571 if (!arch)
609 return; 572 return;
610 573
611 tmp = arch_to_object (arch); 574 tmp = arch->instance ();
612 575
613 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))
614 /* Floor has something on top that interferes with building */ 577 /* Floor has something on top that interferes with building */
615 { 578 {
616 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.");
617 return; 580 return;
618 } 581 }
619 582
620 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 583 tmp->set_flag (FLAG_IS_BUILDABLE);
621 SET_FLAG (tmp, FLAG_NO_PICK); 584 tmp->set_flag (FLAG_NO_PICK);
622 585
623 /* 586 /*
624 * 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.
625 * 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,
626 * so make the item itself unique in this situation. 589 * so make the item itself unique in this situation.
627 */ 590 */
628 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;
629 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) 592 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
630 SET_FLAG (tmp, FLAG_UNIQUE); 593 tmp->set_flag (FLAG_UNIQUE);
631 594
632 shstr_tmp connected; 595 shstr_tmp connected;
633 596
634 switch (tmp->type) 597 switch (tmp->type)
635 { 598 {
637 case GATE: 600 case GATE:
638 case BUTTON: 601 case BUTTON:
639 case DETECTOR: 602 case DETECTOR:
640 case TIMED_GATE: 603 case TIMED_GATE:
641 case PEDESTAL: 604 case PEDESTAL:
642 case CF_HANDLE: 605 case T_HANDLE:
643 case MAGIC_EAR: 606 case MAGIC_EAR:
644 case SIGN: 607 case SIGN:
645 /* Signs don't need a connection, but but magic mouths do. */ 608 /* Signs don't need a connection, but but magic mouths do. */
646 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) 609 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
647 break; 610 break;
659 con_rune->destroy (); 622 con_rune->destroy ();
660 } 623 }
661 624
662 /* 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 */
663 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 626 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
664 {
665 if (adjust_sign_msg (pl, x, y, tmp) == -1) 627 if (adjust_sign_msg (pl, x, y, tmp) == -1)
666 { 628 {
667 tmp->destroy (); 629 tmp->destroy ();
668 return; 630 return;
669 } 631 }
670 }
671 632
672 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);
673 if (connected) 634 if (connected)
674 tmp->add_link (pl->map, connected); 635 tmp->add_link (pl->map, connected);
675 636
680/** 641/**
681 * Item remover. 642 * Item remover.
682 * 643 *
683 * Removes first buildable item, either under or above the floor 644 * Removes first buildable item, either under or above the floor
684 */ 645 */
685void 646static void
686apply_builder_remove (object *pl, int dir) 647apply_builder_remove (object *pl, int dir)
687{ 648{
688 object *item; 649 object *item;
689 short x, y; 650 int x, y;
690 651
691 x = pl->x + freearr_x[dir]; 652 x = pl->x + freearr_x[dir];
692 y = pl->y + freearr_y[dir]; 653 y = pl->y + freearr_y[dir];
693 654
694 /* Check square */ 655 /* Check square */
699 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 660 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
700 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);
701 return; 662 return;
702 } 663 }
703 664
704 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 665 if (IS_FLOOR (item))
705 item = item->above; 666 item = item->above;
706 667
707 if (!item) 668 if (!item)
708 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 669 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
709 else if (item->type == BUILDABLE_WALL) 670 else if (item->type == BUILDABLE_WALL)
715 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));
716 item->destroy (); 677 item->destroy ();
717 } 678 }
718} 679}
719 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
720/** 802/**
721 * Global building function 803 * Global building function
722 * 804 *
723 * 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
724 * or remover object. 806 * or remover object.
725 */ 807 */
726void 808void
727apply_map_builder (object *pl, int dir) 809apply_map_builder (object *pl, int dir)
728{ 810{
729 object *builder;
730 object *tmp;
731 object *tmp2;
732 short x, y;
733
734 if (!pl->type == PLAYER) 811 if (!pl->type == PLAYER)
735 return; 812 return;
736 813
737 /*if ( !player->map->unique )
738 {
739 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
740 return;
741 } */
742
743 if (dir == 0) 814 if (dir == 0)
744 { 815 {
745 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.");
746 return; 817 return;
747 } 818 }
748 819
749 x = pl->x + freearr_x[dir]; 820 mapxy pos (pl); pos.move (dir);
750 y = pl->y + freearr_y[dir];
751 821
752 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) 822 if (!pos.normalise ())
753 { 823 {
754 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.>");
755 return; 825 return;
756 } 826 }
757 827
758 /* 828 /*
759 * Check specified square 829 * Check specified square
760 * The square must have only buildable items 830 * The square must have only buildable items
761 * Exception: marking runes are all right, 831 * Exception: marking runes are all right,
762 * since they are used for special things like connecting doors / buttons 832 * since they are used for special things like connecting doors / buttons
763 */ 833 */
764 834
765 tmp = GET_MAP_OB (pl->map, x, y); 835 object *builder = pl->contr->ranged_ob;
766 if (!tmp) 836
767 { 837 object *tmp2 = pl->mark ();
768 /* Nothing, meaning player is standing next to an undefined square... */ 838
769 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 839 object *tmp = 0;
770 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)
771 return;
772 } 841 {
773 842 if (!tmp->flag [FLAG_IS_BUILDABLE]
774 tmp2 = find_marked_object (pl);
775 while (tmp)
776 {
777 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))
778 { 844 {
779 /* The item building function already has it's own special 845 /* The item building function already has it's own special
780 * checks for this 846 * checks for this. And so does the quad building function.
781 */ 847 */
782 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 848 if (!tmp2 || (tmp2->subtype != ST_MAT_ITEM && tmp2->subtype != ST_MAT_QUAD))
783 { 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)))
784 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
785 return; 856 return;
786 } 857 }
787 } 858 }
788 tmp = tmp->above;
789 } 859 }
790 860
791 /* Now we know the square is ok */ 861 /* Now we know the square is ok */
792 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;
793 865
794 if (builder->subtype == ST_BD_REMOVE) 866 if (builder->subtype == ST_BD_REMOVE)
795 /* Remover -> call specific function and bail out */ 867 /* Remover -> call specific function and bail out */
796 { 868 {
797 apply_builder_remove (pl, dir); 869 apply_builder_remove (pl, dir);
817 return; 889 return;
818 } 890 }
819 891
820 switch (tmp->subtype) 892 switch (tmp->subtype)
821 { 893 {
822 case ST_MAT_FLOOR: 894 case ST_MAT_FLOOR:
823 apply_builder_floor (pl, tmp, x, y); 895 apply_builder_floor (pl, tmp, pos.x, pos.y);
824 return; 896 return;
825 897
826 case ST_MAT_WALL: 898 case ST_MAT_WALL:
827 apply_builder_wall (pl, tmp, x, y); 899 apply_builder_wall (pl, tmp, pos.x, pos.y);
828 return; 900 return;
829 901
830 case ST_MAT_ITEM: 902 case ST_MAT_ITEM:
831 apply_builder_item (pl, tmp, x, y); 903 apply_builder_item (pl, tmp, pos.x, pos.y);
832 return; 904 return;
833 905
906 case ST_MAT_QUAD:
907 apply_builder_quad (pl, tmp, pos);
908 return;
909
834 default: 910 default:
835 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.");
836 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);
837 return; 913 return;
838 } 914 }
839 } 915 }
840 916
841 /* Here, it means the builder has an invalid type */ 917 /* Here, it means the builder has an invalid type */
842 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.");
843 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);
844} 920}
845 921
846/**
847 * Make the built object inherit the msg of books that are used with it.
848 * For objects already invisible (i.e. magic mouths & ears), also make it
849 * it inherit the face and the name with "talking " prepended.
850 */
851int
852adjust_sign_msg (object *pl, short x, short y, object *tmp)
853{
854 object *book;
855 char buf[MAX_BUF];
856 char buf2[MAX_BUF];
857
858 book = get_msg_book (pl, x, y);
859 if (!book)
860 {
861 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
862 return -1;
863 }
864
865 tmp->msg = book->msg;
866
867 if (tmp->invisible)
868 {
869 if (book->custom_name != NULL)
870 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
871 else
872 snprintf (buf, sizeof (buf), "talking %s", &book->name);
873
874 tmp->name = buf;
875
876 if (book->name_pl != NULL)
877 {
878 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
879 tmp->name_pl = buf2;
880 }
881
882 tmp->face = book->face;
883 tmp->invisible = 0;
884 }
885
886 book->destroy ();
887 return 0;
888}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines