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.34 by root, Mon Sep 29 10:20:49 2008 UTC vs.
Revision 1.62 by root, Fri Jul 2 16:24:25 2010 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 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>
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 (strcmp (ob->arch->archname, "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);
84 while (rune) 86 while (rune)
85 { 87 {
86 next = rune->above; 88 next = rune->above;
87 89
88 if (rune->type == SIGN && !strcmp (rune->arch->archname, "rune_mark")) 90 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
89 rune->destroy (true); 91 rune->destroy ();
90 92
91 rune = next; 93 rune = next;
92 } 94 }
93} 95}
94 96
97 * \param map: map for which to find a value 99 * \param map: map for which to find a value
98 * \return 'connected' value with no item, or -1 if failure. 100 * \return 'connected' value with no item, or -1 if failure.
99 * 101 *
100 * Tries 1000 random values, then returns -1. 102 * Tries 1000 random values, then returns -1.
101 */ 103 */
102int 104static shstr_tmp
103find_unused_connected_value (maptile *map) 105find_unused_connected_value (maptile *map)
104{ 106{
105 int connected = 0; 107 for (int i = 1000; --i; )
106 int itest = 0;
107 oblinkpt *obp;
108
109 while (itest++ < 1000)
110 {
111 connected = rndm (0x20000000UL) + 0x60000000UL;
112
113 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next)
114 ;
115
116 if (!obp)
117 return connected;
118 } 108 {
109 char buf[64];
119 110
111 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
112
113 shstr id (buf);
114
115 if (!map->find_link (id))
116 return id;
117 }
118
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
120 return -1; 133 return rune;
121} 134}
122 135
123/** 136/**
124 * Helper function for door/button/connected item building. 137 * Helper function for door/button/connected item building.
125 * 138 *
128 * Else, searches a force in op's inventory matching the map's name 141 * Else, searches a force in op's inventory matching the map's name
129 * and the rune's text. 142 * and the rune's text.
130 * If found, returns the connection value associated 143 * If found, returns the connection value associated
131 * 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.
132 */ 145 */
133int 146static shstr_tmp
134find_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)
135{ 148{
136 object *force; 149 object *force;
137 int connected;
138 150
139 if (!rune) 151 if (!rune)
140 rune = get_connection_rune (pl, x, y); 152 rune = get_connection_rune (pl, x, y);
141 153
142 if (!rune) 154 if (!rune)
143 { 155 {
144 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); 156 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
145 return -1; 157 return shstr_tmp ();
146 } 158 }
147 159
148 /* Now, find force in player's inventory */ 160 /* Now, find force in player's inventory */
149 force = pl->inv; 161 force = pl->inv;
150 while (force 162 while (force
154 166
155 if (!force) 167 if (!force)
156 /* No force, need to create & insert one */ 168 /* No force, need to create & insert one */
157 { 169 {
158 /* Find unused value */ 170 /* Find unused value */
159 connected = find_unused_connected_value (pl->map); 171 shstr_tmp id = find_unused_connected_value (pl->map);
160 if (connected == -1) 172
173 if (!id)
161 { 174 {
162 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.");
163 return -1; 176 return shstr_tmp ();
164 } 177 }
165 178
166 force = get_archetype (FORCE_NAME); 179 force = get_archetype (FORCE_NAME);
167 force->slaying = pl->map->path; 180 force->slaying = pl->map->path;
168 force->msg = rune->msg; 181 force->msg = rune->msg;
169 force->path_attuned = connected; 182 force->race = id;
170 force->set_speed (0); 183 force->set_speed (0);
184
171 insert_ob_in_ob (force, pl); 185 insert_ob_in_ob (force, pl);
172 186
173 return connected; 187 return id;
174 } 188 }
175 189
176 /* Found the force, everything's easy. */ 190 /* Found the force, everything's easy. */
177 return force->path_attuned; 191 return force->race;
178}
179
180/**
181 * Returns the marking rune on the square, for purposes of building connections
182 */
183object *
184get_connection_rune (object *pl, short x, short y)
185{
186 object *rune = GET_MAP_OB (pl->map, x, y);
187
188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark"))))
189 rune = rune->above;
190
191 return rune;
192} 192}
193 193
194/** 194/**
195 * 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
196 */ 196 */
197object * 197static object *
198get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, int x, int y)
199{ 199{
200 object *book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
201 201
202 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
203 book = book->above; 203 book = book->above;
204 204
205 return book; 205 return book;
206} 206}
207 207
208/** 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/**
209 * Returns first item of type BUILDABLE_WALL. 259 * Returns first item of type BUILDABLE_WALL.
210 */ 260 */
211object * 261static object *
212get_wall (maptile *map, int x, int y) 262get_wall (maptile *map, int x, int y)
213{ 263{
214 object *wall = GET_MAP_OB (map, x, y); 264 object *wall = GET_MAP_OB (map, x, y);
215 265
216 while (wall && (BUILDABLE_WALL != wall->type)) 266 while (wall && (BUILDABLE_WALL != wall->type))
228 * 278 *
229 * Basically it ensures the correct wall is put where needed. 279 * Basically it ensures the correct wall is put where needed.
230 * 280 *
231 * Note: x & y must be valid map coordinates. 281 * Note: x & y must be valid map coordinates.
232 */ 282 */
233void 283static void
234fix_walls (maptile *map, int x, int y) 284fix_walls (maptile *map, int x, int y)
235{ 285{
236 char archetype[MAX_BUF]; 286 char archetype[MAX_BUF];
237 char *underscore; 287 char *underscore;
238 struct archetype *new_arch; 288 struct archetype *new_arch;
258 underscore++; 308 underscore++;
259 *underscore = '\0'; 309 *underscore = '\0';
260 310
261 int connect = 0; 311 int connect = 0;
262 312
263 if ((x > 0) && get_wall (map, x - 1, y)) 313 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
264 connect |= 1;
265 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;
266 connect |= 2; 315 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
267
268 if ((y > 0) && get_wall (map, x, y - 1))
269 connect |= 4;
270
271 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;
272 connect |= 8;
273 317
274 switch (connect) 318 strcat (archetype, wall_suffix [connect]);
275 {
276 case 0:
277 strcat (archetype, "0");
278
279 break;
280 case 1:
281 strcat (archetype, "1_3");
282
283 break;
284 case 2:
285 strcat (archetype, "1_4");
286
287 break;
288 case 3:
289 strcat (archetype, "2_1_2");
290
291 break;
292 case 4:
293 strcat (archetype, "1_2");
294
295 break;
296 case 5:
297 strcat (archetype, "2_2_4");
298
299 break;
300 case 6:
301 strcat (archetype, "2_2_1");
302
303 break;
304 case 7:
305 strcat (archetype, "3_1");
306
307 break;
308 case 8:
309 strcat (archetype, "1_1");
310
311 break;
312 case 9:
313 strcat (archetype, "2_2_3");
314
315 break;
316 case 10:
317 strcat (archetype, "2_2_2");
318
319 break;
320 case 11:
321 strcat (archetype, "3_3");
322
323 break;
324 case 12:
325 strcat (archetype, "2_1_1");
326
327 break;
328 case 13:
329 strcat (archetype, "3_4");
330
331 break;
332 case 14:
333 strcat (archetype, "3_2");
334
335 break;
336 case 15:
337 strcat (archetype, "4");
338
339 break;
340 }
341 319
342 /* 320 /*
343 * Before anything, make sure the archetype does exist... 321 * Before anything, make sure the archetype does exist...
344 * If not, prolly an error... 322 * If not, prolly an error...
345 */ 323 */
351 /* Now delete current wall, and insert new one 329 /* Now delete current wall, and insert new one
352 * We save flags to avoid any trouble with buildable/non buildable, and so on 330 * We save flags to avoid any trouble with buildable/non buildable, and so on
353 */ 331 */
354 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
355 333
356 wall->destroy (true); 334 wall->destroy ();
357 335
358 wall = arch_to_object (new_arch); 336 wall = new_arch->instance ();
359 wall->type = BUILDABLE_WALL; 337 wall->type = BUILDABLE_WALL;
360 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);
361 wall->flag = old_flags; 339 wall->flag = old_flags;
362} 340}
363 341
369 * - on an existing wall, with or without a floor under it 347 * - on an existing wall, with or without a floor under it
370 * 348 *
371 * Note: this function will inconditionally change squares around (x, y) 349 * Note: this function will inconditionally change squares around (x, y)
372 * so don't call it with x == 0 for instance! 350 * so don't call it with x == 0 for instance!
373 */ 351 */
374void 352static void
375apply_builder_floor (object *pl, object *material, short x, short y) 353apply_builder_floor (object *pl, object *material, int x, int y)
376{ 354{
377 object *tmp, *above; 355 object *tmp, *above;
378 object *above_floor; /* Item above floor, if any */ 356 object *above_floor; /* Item above floor, if any */
379 struct archetype *new_floor; 357 struct archetype *new_floor;
380 struct archetype *new_wall; 358 struct archetype *new_wall;
398 above = tmp->above; 376 above = tmp->above;
399 if (BUILDABLE_WALL == tmp->type) 377 if (BUILDABLE_WALL == tmp->type)
400 { 378 {
401 /* 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 */
402 new_wall = tmp->arch; 380 new_wall = tmp->arch;
403 tmp->destroy (true); 381 tmp->destroy ();
404 sprintf (message, "You destroy the wall and redo the floor."); 382 sprintf (message, "You destroy the wall and redo the floor.");
405 } 383 }
406 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 384 else if (IS_FLOOR (tmp))
407 { 385 {
408 tmp->destroy (true); 386 tmp->destroy ();
409 floor_removed = 1; 387 floor_removed = 1;
410 } 388 }
411 else 389 else
412 { 390 {
413 if (floor_removed) 391 if (floor_removed)
392 {
393 /* This is the first item that was above the floor */
414 above_floor = tmp; 394 above_floor = tmp;
395 floor_removed = 0;
396 }
415 } 397 }
416 398
417 tmp = above; 399 tmp = above;
418 } 400 }
419 } 401 }
425 /* Not found, log & bail out */ 407 /* Not found, log & bail out */
426 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);
427 return; 409 return;
428 } 410 }
429 411
430 tmp = arch_to_object (new_floor); 412 tmp = new_floor->instance ();
431 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 413 tmp->set_flag (FLAG_IS_BUILDABLE);
432 SET_FLAG (tmp, FLAG_UNIQUE); 414 tmp->set_flag (FLAG_UNIQUE);
433 SET_FLAG (tmp, FLAG_IS_FLOOR); 415 tmp->set_flag (FLAG_IS_FLOOR);
434 tmp->type = FLOOR; 416 //tmp->type = FLOOR;
435 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);
436 418
437 /* 419 /*
438 * 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
439 * Since building, you can have: blocking view / floor / wall / nothing 421 * Since building, you can have: blocking view / floor / wall / nothing
444 yt = y + freearr_y[i]; 426 yt = y + freearr_y[i];
445 tmp = GET_MAP_OB (pl->map, xt, yt); 427 tmp = GET_MAP_OB (pl->map, xt, yt);
446 if (!tmp) 428 if (!tmp)
447 { 429 {
448 /* Must insert floor & wall */ 430 /* Must insert floor & wall */
449 tmp = arch_to_object (new_floor); 431 tmp = new_floor->instance ();
450 /* Better make the floor unique */ 432 /* Better make the floor unique */
451 SET_FLAG (tmp, FLAG_UNIQUE); 433 tmp->set_flag (FLAG_UNIQUE);
452 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 434 tmp->set_flag (FLAG_IS_BUILDABLE);
453 tmp->type = FLOOR; 435 //tmp->type = FLOOR;
454 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);
455 /* 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... */
456 if (new_wall) 438 if (new_wall)
457 { 439 {
458 tmp = arch_to_object (new_wall); 440 tmp = new_wall->instance ();
459 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 441 tmp->set_flag (FLAG_IS_BUILDABLE);
460 tmp->type = BUILDABLE_WALL; 442 tmp->type = BUILDABLE_WALL;
461 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);
462 } 444 }
463 } 445 }
464 } 446 }
467 * 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
468 * spot, so need to check that those new walls connect correctly 450 * spot, so need to check that those new walls connect correctly
469 */ 451 */
470 for (xt = x - 2; xt <= x + 2; xt++) 452 for (xt = x - 2; xt <= x + 2; xt++)
471 for (yt = y - 2; yt <= y + 2; yt++) 453 for (yt = y - 2; yt <= y + 2; yt++)
472 {
473 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 454 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
474 fix_walls (pl->map, xt, yt); 455 fix_walls (pl->map, xt, yt);
475 }
476 456
477 /* Now remove raw item from inventory */ 457 /* Now remove raw item from inventory */
478 material->decrease (); 458 material->decrease ();
479 459
480 /* And tell player about the fix */ 460 /* And tell player about the fix */
481 new_draw_info (NDI_UNIQUE, 0, pl, message); 461 new_draw_info (NDI_UNIQUE, 0, pl, message);
482}
483
484/**
485 * Wall radius fix function
486 */
487void fix_walls_around (maptile *map, int x, int y)
488{
489 for (int xt = x - 1; xt <= x + 1; xt++)
490 for (int yt = y - 1; yt <= y + 1; yt++)
491 {
492 if (OUT_OF_REAL_MAP (map, xt, yt))
493 continue;
494
495 fix_walls (map, xt, yt);
496 }
497} 462}
498 463
499/** 464/**
500 * Wall building function 465 * Wall building function
501 * 466 *
502 * Walls can be build: 467 * Walls can be build:
503 * - on a floor without anything else 468 * - on a floor without anything else
504 * - on an existing wall, with or without a floor 469 * - on an existing wall, with or without a floor
505 */ 470 */
506void 471static void
507apply_builder_wall (object *pl, object *material, short x, short y) 472apply_builder_wall (object *pl, object *material, int x, int y)
508{ 473{
509 object *current_wall; 474 object *current_wall;
510 object *tmp; 475 object *tmp;
511 int xt, yt; 476 int xt, yt;
512 struct archetype *new_wall; 477 struct archetype *new_wall;
534 { 499 {
535 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);
536 return; 501 return;
537 } 502 }
538 503
539 tmp = arch_to_object (new_wall); 504 tmp = new_wall->instance ();
540 tmp->type = BUILDABLE_WALL; 505 tmp->type = BUILDABLE_WALL;
541 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 506 tmp->set_flag (FLAG_IS_BUILDABLE);
542 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);
543 508
544 /* If existing wall, remove it, no need to fix other walls */ 509 /* If existing wall, remove it, no need to fix other walls */
545 if (current_wall) 510 if (current_wall)
546 { 511 {
547 current_wall->destroy (true); 512 current_wall->destroy ();
548 fix_walls (pl->map, x, y); 513 fix_walls (pl->map, x, y);
549 sprintf (message, "You redecorate the wall to better suit your tastes."); 514 sprintf (message, "You redecorate the wall to better suit your tastes.");
550 } 515 }
551 else 516 else
552 { 517 {
574 * 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.
575 * Archetype of created object is item->slaying (raw material). 540 * Archetype of created object is item->slaying (raw material).
576 * Type of inserted item is tested for specific cases (doors & such). 541 * Type of inserted item is tested for specific cases (doors & such).
577 * 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)
578 */ 543 */
579void 544static void
580apply_builder_item (object *pl, object *item, short x, short y) 545apply_builder_item (object *pl, object *item, int x, int y)
581{ 546{
582 object *tmp; 547 object *tmp;
583 struct archetype *arch; 548 struct archetype *arch;
584 int insert_flag; 549 int insert_flag;
585 object *floor; 550 object *floor;
586 object *con_rune; 551 object *con_rune;
587 int connected;
588 552
589 /* Find floor */ 553 /* Find floor */
590 floor = GET_MAP_OB (pl->map, x, y); 554 floor = GET_MAP_OB (pl->map, x, y);
591 if (!floor) 555 if (!floor)
592 { 556 {
593 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 557 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
594 return; 558 return;
595 } 559 }
596 560
597 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) 561 while (floor && !IS_FLOOR (floor))
598 floor = floor->above; 562 floor = floor->above;
599 563
600 if (!floor) 564 if (!floor)
601 { 565 {
602 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.");
605 /* Create item, set flag, insert in map */ 569 /* Create item, set flag, insert in map */
606 arch = archetype::find (item->slaying); 570 arch = archetype::find (item->slaying);
607 if (!arch) 571 if (!arch)
608 return; 572 return;
609 573
610 tmp = arch_to_object (arch); 574 tmp = arch->instance ();
611 575
612 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))
613 /* Floor has something on top that interferes with building */ 577 /* Floor has something on top that interferes with building */
614 { 578 {
615 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.");
616 return; 580 return;
617 } 581 }
618 582
619 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 583 tmp->set_flag (FLAG_IS_BUILDABLE);
620 SET_FLAG (tmp, FLAG_NO_PICK); 584 tmp->set_flag (FLAG_NO_PICK);
621 585
622 /* 586 /*
623 * This doesn't work on non unique maps. pedestals under floor will not be saved... 587 * Str 1 is a flag that the item [pedestal] should go below the floor.
624 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 588 * Items under the floor on non-unique maps will not be saved,
589 * so make the item itself unique in this situation.
625 */ 590 */
626 insert_flag = INS_ABOVE_FLOOR_ONLY; 591 insert_flag = item->stats.Str == 1 ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
592 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
593 tmp->set_flag (FLAG_UNIQUE);
627 594
628 connected = 0; 595 shstr_tmp connected;
596
629 switch (tmp->type) 597 switch (tmp->type)
630 { 598 {
631 case DOOR: 599 case DOOR:
632 case GATE: 600 case GATE:
633 case BUTTON: 601 case BUTTON:
634 case DETECTOR: 602 case DETECTOR:
635 case TIMED_GATE: 603 case TIMED_GATE:
636 case PEDESTAL: 604 case PEDESTAL:
637 case CF_HANDLE: 605 case T_HANDLE:
638 case MAGIC_EAR: 606 case MAGIC_EAR:
639 case SIGN: 607 case SIGN:
640 /* Signs don't need a connection, but but magic mouths do. */ 608 /* Signs don't need a connection, but but magic mouths do. */
641 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) 609 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
642 break; 610 break;
643 611
644 con_rune = get_connection_rune (pl, x, y); 612 con_rune = get_connection_rune (pl, x, y);
645 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 613 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
646 if (connected == -1) 614 if (!connected)
647 { 615 {
648 /* Player already informed of failure by the previous function */ 616 /* Player already informed of failure by the previous function */
649 tmp->destroy (true); 617 tmp->destroy ();
650 return; 618 return;
651 } 619 }
652 620
653 /* Remove marking rune */ 621 /* Remove marking rune */
654 con_rune->destroy (true); 622 con_rune->destroy ();
655 } 623 }
656 624
657 /* 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 */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 626 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 {
660 if (adjust_sign_msg (pl, x, y, tmp) == -1) 627 if (adjust_sign_msg (pl, x, y, tmp) == -1)
661 { 628 {
662 tmp->destroy (true); 629 tmp->destroy ();
663 return; 630 return;
664 } 631 }
665 }
666 632
667 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);
668 if (connected != 0) 634 if (connected)
669 add_button_link (tmp, pl->map, connected); 635 tmp->add_link (pl->map, connected);
670 636
671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); 637 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
672 item->decrease (); 638 item->decrease ();
673} 639}
674 640
675/** 641/**
676 * Item remover. 642 * Item remover.
677 * 643 *
678 * Removes first buildable item, either under or above the floor 644 * Removes first buildable item, either under or above the floor
679 */ 645 */
680void 646static void
681apply_builder_remove (object *pl, int dir) 647apply_builder_remove (object *pl, int dir)
682{ 648{
683 object *item; 649 object *item;
684 short x, y; 650 int x, y;
685 651
686 x = pl->x + freearr_x[dir]; 652 x = pl->x + freearr_x[dir];
687 y = pl->y + freearr_y[dir]; 653 y = pl->y + freearr_y[dir];
688 654
689 /* Check square */ 655 /* Check square */
694 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 660 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
695 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);
696 return; 662 return;
697 } 663 }
698 664
699 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 665 if (IS_FLOOR (item))
700 item = item->above; 666 item = item->above;
701 667
702 if (!item) 668 if (!item)
703 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 669 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
704 else if (item->type == BUILDABLE_WALL) 670 else if (item->type == BUILDABLE_WALL)
706 else if (!item->flag [FLAG_IS_BUILDABLE]) 672 else if (!item->flag [FLAG_IS_BUILDABLE])
707 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); 673 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
708 else 674 else
709 { 675 {
710 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));
711 item->destroy (true); 677 item->destroy ();
712 } 678 }
713} 679}
714 680
715/** 681/**
716 * Global building function 682 * Global building function
719 * or remover object. 685 * or remover object.
720 */ 686 */
721void 687void
722apply_map_builder (object *pl, int dir) 688apply_map_builder (object *pl, int dir)
723{ 689{
724 object *builder;
725 object *tmp;
726 object *tmp2;
727 short x, y; 690 int x, y;
728 691
729 if (!pl->type == PLAYER) 692 if (!pl->type == PLAYER)
730 return; 693 return;
731 694
732 /*if ( !player->map->unique ) 695 /*if ( !player->map->unique )
755 * The square must have only buildable items 718 * The square must have only buildable items
756 * Exception: marking runes are all right, 719 * Exception: marking runes are all right,
757 * since they are used for special things like connecting doors / buttons 720 * since they are used for special things like connecting doors / buttons
758 */ 721 */
759 722
760 tmp = GET_MAP_OB (pl->map, x, y); 723 object *tmp = GET_MAP_OB (pl->map, x, y);
761 if (!tmp) 724 if (!tmp)
762 { 725 {
763 /* Nothing, meaning player is standing next to an undefined square... */ 726 /* Nothing, meaning player is standing next to an undefined square... */
764 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 727 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
765 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 728 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
766 return; 729 return;
767 } 730 }
768 731
769 tmp2 = find_marked_object (pl); 732 object *builder = pl->contr->ranged_ob;
733
734 object *tmp2 = pl->mark ();
735
770 while (tmp) 736 while (tmp)
771 { 737 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) 738 if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
773 { 739 {
774 /* The item building function already has it's own special 740 /* The item building function already has it's own special
775 * checks for this 741 * checks for this
776 */ 742 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 743 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM)
778 { 744 {
745 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (0)))
779 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 746 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
747
780 return; 748 return;
781 } 749 }
782 } 750 }
751
783 tmp = tmp->above; 752 tmp = tmp->above;
784 } 753 }
785 754
786 /* Now we know the square is ok */ 755 /* Now we know the square is ok */
787 builder = pl->contr->ranged_ob; 756 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (1)))
757 return;
788 758
789 if (builder->subtype == ST_BD_REMOVE) 759 if (builder->subtype == ST_BD_REMOVE)
790 /* Remover -> call specific function and bail out */ 760 /* Remover -> call specific function and bail out */
791 { 761 {
792 apply_builder_remove (pl, dir); 762 apply_builder_remove (pl, dir);
812 return; 782 return;
813 } 783 }
814 784
815 switch (tmp->subtype) 785 switch (tmp->subtype)
816 { 786 {
817 case ST_MAT_FLOOR: 787 case ST_MAT_FLOOR:
818 apply_builder_floor (pl, tmp, x, y); 788 apply_builder_floor (pl, tmp, x, y);
819 return; 789 return;
820 790
821 case ST_MAT_WALL: 791 case ST_MAT_WALL:
822 apply_builder_wall (pl, tmp, x, y); 792 apply_builder_wall (pl, tmp, x, y);
823 return; 793 return;
824 794
825 case ST_MAT_ITEM: 795 case ST_MAT_ITEM:
826 apply_builder_item (pl, tmp, x, y); 796 apply_builder_item (pl, tmp, x, y);
827 return; 797 return;
828 798
829 default: 799 default:
830 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry."); 800 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
831 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype); 801 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
832 return; 802 return;
833 } 803 }
834 } 804 }
835 805
836 /* Here, it means the builder has an invalid type */ 806 /* Here, it means the builder has an invalid type */
837 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry."); 807 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
838 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); 808 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
839} 809}
840 810
841/**
842 * Make the built object inherit the msg of books that are used with it.
843 * For objects already invisible (i.e. magic mouths & ears), also make it
844 * it inherit the face and the name with "talking " prepended.
845 */
846int
847adjust_sign_msg (object *pl, short x, short y, object *tmp)
848{
849 object *book;
850 char buf[MAX_BUF];
851 char buf2[MAX_BUF];
852
853 book = get_msg_book (pl, x, y);
854 if (!book)
855 {
856 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
857 return -1;
858 }
859
860 tmp->msg = book->msg;
861
862 if (tmp->invisible)
863 {
864 if (book->custom_name != NULL)
865 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
866 else
867 snprintf (buf, sizeof (buf), "talking %s", &book->name);
868
869 tmp->name = buf;
870
871 if (book->name_pl != NULL)
872 {
873 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
874 tmp->name_pl = buf2;
875 }
876
877 tmp->face = book->face;
878 tmp->invisible = 0;
879 }
880
881 book->destroy (true);
882 return 0;
883}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines