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.28 by root, Sun Jul 1 05:00:19 2007 UTC vs.
Revision 1.49 by root, Sun Mar 14 18:19:59 2010 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT 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 <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <living.h> 26#include <living.h>
26#include <spells.h> 27#include <spells.h>
29#include <sproto.h> 30#include <sproto.h>
30 31
31/** 32/**
32 * Check if objects on a square interfere with building 33 * Check if objects on a square interfere with building
33 */ 34 */
34int 35static int
35can_build_over (maptile *map, object *tmp, short x, short y) 36can_build_over (maptile *map, object *tmp, int x, int y)
36{ 37{
37 object *ob; 38 object *ob;
38 39
39 ob = GET_MAP_OB (map, x, y); 40 ob = GET_MAP_OB (map, x, y);
40 while (ob) 41 while (ob)
41 { 42 {
42 /* if ob is not a marking rune or floor, then check special cases */ 43 /* if ob is not a marking rune or floor, then check special cases */
43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR) 44 if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR)
44 { 45 {
45 switch (tmp->type) 46 switch (tmp->type)
46 { 47 {
47 case SIGN: 48 case SIGN:
48 case MAGIC_EAR: 49 case MAGIC_EAR:
49 /* Allow signs and magic ears to be built on books */ 50 /* Allow signs and magic ears to be built on books */
50 if (ob->type != BOOK) 51 if (ob->type != BOOK)
51 {
52 return 0;
53 }
54 break;
55 case BUTTON:
56 case DETECTOR:
57 case PEDESTAL:
58 case CF_HANDLE:
59 /* Allow buttons and levers to be built under gates */
60 if (ob->type != GATE && ob->type != DOOR)
61 {
62 return 0;
63 }
64 break;
65 default:
66 return 0; 52 return 0;
53 break;
54 case BUTTON:
55 case DETECTOR:
56 case PEDESTAL:
57 case T_HANDLE:
58 /* Allow buttons and levers to be built under gates */
59 if (ob->type != GATE && ob->type != DOOR)
60 return 0;
61 break;
62 default:
63 return 0;
67 } 64 }
68 } 65 }
66
69 ob = ob->above; 67 ob = ob->above;
70 } 68 }
69
71 return 1; 70 return 1;
72} 71}
73 72
74/** 73/**
75 * Erases marking runes at specified location 74 * Erases marking runes at specified location
76 */ 75 */
77void 76static void
78remove_marking_runes (maptile *map, short x, short y) 77remove_marking_runes (maptile *map, int x, int y)
79{ 78{
80 object *rune; 79 object *rune;
81 object *next; 80 object *next;
82 81
83 rune = GET_MAP_OB (map, x, y); 82 rune = GET_MAP_OB (map, x, y);
84 while (rune) 83 while (rune)
85 { 84 {
86 next = rune->above; 85 next = rune->above;
87 86
88 if ((rune->type == SIGN) && (!strcmp (rune->arch->archname, "rune_mark"))) 87 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
89 rune->destroy (); 88 rune->destroy ();
90 89
91 rune = next; 90 rune = next;
92 } 91 }
93} 92}
97 * \param map: map for which to find a value 96 * \param map: map for which to find a value
98 * \return 'connected' value with no item, or -1 if failure. 97 * \return 'connected' value with no item, or -1 if failure.
99 * 98 *
100 * Tries 1000 random values, then returns -1. 99 * Tries 1000 random values, then returns -1.
101 */ 100 */
102int 101static shstr_tmp
103find_unused_connected_value (maptile *map) 102find_unused_connected_value (maptile *map)
104{ 103{
105 int connected = 0; 104 for (int i = 1000; --i; )
106 int itest = 0;
107 oblinkpt *obp;
108
109 while (itest++ < 1000)
110 {
111 connected = 1 + rand () % 20000;
112 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next);
113
114 if (!obp)
115 return connected;
116 } 105 {
106 char buf[64];
117 107
108 snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U);
109
110 shstr id (buf);
111
112 if (!map->find_link (id))
113 return id;
114 }
115
116 return shstr_tmp ();
117}
118
119/**
120 * Returns the marking rune on the square, for purposes of building connections
121 */
122static object *
123get_connection_rune (object *pl, int x, int y)
124{
125 object *rune = GET_MAP_OB (pl->map, x, y);
126
127 while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark))
128 rune = rune->above;
129
118 return -1; 130 return rune;
119} 131}
120
121 132
122/** 133/**
123 * Helper function for door/button/connected item building. 134 * Helper function for door/button/connected item building.
124 * 135 *
125 * Will search the specified spot for a marking rune. 136 * Will search the specified spot for a marking rune.
127 * Else, searches a force in op's inventory matching the map's name 138 * Else, searches a force in op's inventory matching the map's name
128 * and the rune's text. 139 * and the rune's text.
129 * If found, returns the connection value associated 140 * If found, returns the connection value associated
130 * else searches a new connection value, and adds the force to the player. 141 * else searches a new connection value, and adds the force to the player.
131 */ 142 */
132int 143static shstr_tmp
133find_or_create_connection_for_map (object *pl, short x, short y, object *rune) 144find_or_create_connection_for_map (object *pl, int x, int y, object *rune)
134{ 145{
135 object *force; 146 object *force;
136 int connected;
137 147
138 if (!rune) 148 if (!rune)
139 rune = get_connection_rune (pl, x, y); 149 rune = get_connection_rune (pl, x, y);
140 150
141 if (!rune) 151 if (!rune)
142 { 152 {
143 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); 153 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
144 return -1; 154 return shstr_tmp ();
145 } 155 }
146 156
147 /* Now, find force in player's inventory */ 157 /* Now, find force in player's inventory */
148 force = pl->inv; 158 force = pl->inv;
149 while (force 159 while (force
153 163
154 if (!force) 164 if (!force)
155 /* No force, need to create & insert one */ 165 /* No force, need to create & insert one */
156 { 166 {
157 /* Find unused value */ 167 /* Find unused value */
158 connected = find_unused_connected_value (pl->map); 168 shstr_tmp id = find_unused_connected_value (pl->map);
159 if (connected == -1) 169
170 if (!id)
160 { 171 {
161 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); 172 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
162 return -1; 173 return shstr_tmp ();
163 } 174 }
164 175
165 force = get_archetype (FORCE_NAME); 176 force = get_archetype (FORCE_NAME);
166 force->slaying = pl->map->path; 177 force->slaying = pl->map->path;
167 force->msg = rune->msg; 178 force->msg = rune->msg;
168 force->path_attuned = connected; 179 force->race = id;
169 force->set_speed (0); 180 force->set_speed (0);
181
170 insert_ob_in_ob (force, pl); 182 insert_ob_in_ob (force, pl);
171 183
172 return connected; 184 return id;
173 } 185 }
174 186
175 /* Found the force, everything's easy. */ 187 /* Found the force, everything's easy. */
176 return force->path_attuned; 188 return force->race;
177}
178
179/**
180 * Returns the marking rune on the square, for purposes of building connections
181 */
182object *
183get_connection_rune (object *pl, short x, short y)
184{
185 object *rune;
186
187 rune = GET_MAP_OB (pl->map, x, y);
188 while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark"))))
189 rune = rune->above;
190 return rune;
191} 189}
192 190
193/** 191/**
194 * Returns the book/scroll on the current square, for purposes of building 192 * Returns the book/scroll on the current square, for purposes of building
195 */ 193 */
196object * 194static object *
197get_msg_book (object *pl, short x, short y) 195get_msg_book (object *pl, int x, int y)
198{ 196{
199 object *book;
200
201 book = GET_MAP_OB (pl->map, x, y); 197 object *book = GET_MAP_OB (pl->map, x, y);
198
202 while (book && (book->type != BOOK)) 199 while (book && (book->type != BOOK))
203 book = book->above; 200 book = book->above;
201
204 return book; 202 return book;
205} 203}
206 204
207/** 205/**
206 * Make the built object inherit the msg of books that are used with it.
207 * For objects already invisible (i.e. magic mouths & ears), also make it
208 * it inherit the face and the name with "talking " prepended.
209 */
210static int
211adjust_sign_msg (object *pl, int x, int y, object *tmp)
212{
213 object *book;
214 char buf[MAX_BUF];
215 char buf2[MAX_BUF];
216
217 book = get_msg_book (pl, x, y);
218 if (!book)
219 {
220 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
221 return -1;
222 }
223
224 tmp->msg = book->msg;
225
226 if (tmp->invisible)
227 {
228 if (book->custom_name)
229 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
230 else
231 snprintf (buf, sizeof (buf), "talking %s", &book->name);
232
233 tmp->name = buf;
234
235 if (book->name_pl)
236 {
237 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
238 tmp->name_pl = buf2;
239 }
240
241 tmp->face = book->face;
242 tmp->invisible = 0;
243 }
244
245 book->destroy ();
246 return 0;
247}
248
249/**
208 * Returns first item of type BUILDABLE_WALL. 250 * Returns first item of type BUILDABLE_WALL.
209 */ 251 */
210object * 252static object *
211get_wall (maptile *map, int x, int y) 253get_wall (maptile *map, int x, int y)
212{ 254{
213 object *wall;
214
215 wall = GET_MAP_OB (map, x, y); 255 object *wall = GET_MAP_OB (map, x, y);
256
216 while (wall && (BUILDABLE_WALL != wall->type)) 257 while (wall && (BUILDABLE_WALL != wall->type))
217 wall = wall->above; 258 wall = wall->above;
218 259
219 return wall; 260 return wall;
220} 261}
228 * 269 *
229 * Basically it ensures the correct wall is put where needed. 270 * Basically it ensures the correct wall is put where needed.
230 * 271 *
231 * Note: x & y must be valid map coordinates. 272 * Note: x & y must be valid map coordinates.
232 */ 273 */
233void 274static void
234fix_walls (maptile *map, int x, int y) 275fix_walls (maptile *map, int x, int y)
235{ 276{
236 object *wall;
237 char archetype[MAX_BUF]; 277 char archetype[MAX_BUF];
238 char *underscore; 278 char *underscore;
239 struct archetype *new_arch; 279 struct archetype *new_arch;
240 280
241
242 /* First, find the wall on that spot */ 281 /* First, find the wall on that spot */
243 wall = get_wall (map, x, y); 282 object *wall = get_wall (map, x, y);
244 if (!wall) 283 if (!wall)
245 /* Nothing -> bail out */ 284 /* Nothing -> bail out */
246 return; 285 return;
247 286
248 /* Find base name */ 287 /* Find base name */
260 underscore++; 299 underscore++;
261 *underscore = '\0'; 300 *underscore = '\0';
262 301
263 int connect = 0; 302 int connect = 0;
264 303
265 if ((x > 0) && get_wall (map, x - 1, y)) 304 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
266 connect |= 1;
267 if ((x < map->width - 1) && get_wall (map, x + 1, y)) 305 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
268 connect |= 2; 306 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
269
270 if ((y > 0) && get_wall (map, x, y - 1))
271 connect |= 4;
272
273 if ((y < map->height - 1) && get_wall (map, x, y + 1)) 307 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
274 connect |= 8;
275 308
276 switch (connect) 309 // one bit per dir, 1 left, 2 right, 4 up, 8 down
277 { 310 static const char *walltype[16] = {
278 case 0: 311 "0",
279 strcat (archetype, "0"); 312 "1_3",
313 "1_4",
314 "2_1_2",
315 "1_2",
316 "2_2_4",
317 "2_2_1",
318 "3_1",
319 "1_1",
320 "2_2_3",
321 "2_2_2",
322 "3_3",
323 "2_1_1",
324 "3_4",
325 "3_2",
326 "4"
327 };
280 328
281 break; 329 strcat (archetype, walltype [connect]);
282 case 1:
283 strcat (archetype, "1_3");
284
285 break;
286 case 2:
287 strcat (archetype, "1_4");
288
289 break;
290 case 3:
291 strcat (archetype, "2_1_2");
292
293 break;
294 case 4:
295 strcat (archetype, "1_2");
296
297 break;
298 case 5:
299 strcat (archetype, "2_2_4");
300
301 break;
302 case 6:
303 strcat (archetype, "2_2_1");
304
305 break;
306 case 7:
307 strcat (archetype, "3_1");
308
309 break;
310 case 8:
311 strcat (archetype, "1_1");
312
313 break;
314 case 9:
315 strcat (archetype, "2_2_3");
316
317 break;
318 case 10:
319 strcat (archetype, "2_2_2");
320
321 break;
322 case 11:
323 strcat (archetype, "3_3");
324
325 break;
326 case 12:
327 strcat (archetype, "2_1_1");
328
329 break;
330 case 13:
331 strcat (archetype, "3_4");
332
333 break;
334 case 14:
335 strcat (archetype, "3_2");
336
337 break;
338 case 15:
339 strcat (archetype, "4");
340
341 break;
342 }
343 330
344 /* 331 /*
345 * Before anything, make sure the archetype does exist... 332 * Before anything, make sure the archetype does exist...
346 * If not, prolly an error... 333 * If not, prolly an error...
347 */ 334 */
355 */ 342 */
356 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off 343 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
357 344
358 wall->destroy (); 345 wall->destroy ();
359 346
360 wall = arch_to_object (new_arch); 347 wall = new_arch->instance ();
361 wall->type = BUILDABLE_WALL; 348 wall->type = BUILDABLE_WALL;
362 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); 349 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
363 wall->flag = old_flags; 350 wall->flag = old_flags;
364} 351}
365 352
371 * - on an existing wall, with or without a floor under it 358 * - on an existing wall, with or without a floor under it
372 * 359 *
373 * Note: this function will inconditionally change squares around (x, y) 360 * Note: this function will inconditionally change squares around (x, y)
374 * so don't call it with x == 0 for instance! 361 * so don't call it with x == 0 for instance!
375 */ 362 */
376void 363static void
377apply_builder_floor (object *pl, object *material, short x, short y) 364apply_builder_floor (object *pl, object *material, int x, int y)
378{ 365{
379 object *tmp, *above; 366 object *tmp, *above;
380 object *above_floor; /* Item above floor, if any */ 367 object *above_floor; /* Item above floor, if any */
381 struct archetype *new_floor; 368 struct archetype *new_floor;
382 struct archetype *new_wall; 369 struct archetype *new_wall;
411 floor_removed = 1; 398 floor_removed = 1;
412 } 399 }
413 else 400 else
414 { 401 {
415 if (floor_removed) 402 if (floor_removed)
403 {
404 /* This is the first item that was above the floor */
416 above_floor = tmp; 405 above_floor = tmp;
406 floor_removed = 0;
407 }
417 } 408 }
418 409
419 tmp = above; 410 tmp = above;
420 } 411 }
421 } 412 }
427 /* Not found, log & bail out */ 418 /* Not found, log & bail out */
428 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying); 419 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
429 return; 420 return;
430 } 421 }
431 422
432 tmp = arch_to_object (new_floor); 423 tmp = new_floor->instance ();
433 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 424 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
434 SET_FLAG (tmp, FLAG_UNIQUE); 425 SET_FLAG (tmp, FLAG_UNIQUE);
435 SET_FLAG (tmp, FLAG_IS_FLOOR); 426 SET_FLAG (tmp, FLAG_IS_FLOOR);
436 tmp->type = FLOOR; 427 tmp->type = FLOOR;
437 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y); 428 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
446 yt = y + freearr_y[i]; 437 yt = y + freearr_y[i];
447 tmp = GET_MAP_OB (pl->map, xt, yt); 438 tmp = GET_MAP_OB (pl->map, xt, yt);
448 if (!tmp) 439 if (!tmp)
449 { 440 {
450 /* Must insert floor & wall */ 441 /* Must insert floor & wall */
451 tmp = arch_to_object (new_floor); 442 tmp = new_floor->instance ();
452 /* Better make the floor unique */ 443 /* Better make the floor unique */
453 SET_FLAG (tmp, FLAG_UNIQUE); 444 SET_FLAG (tmp, FLAG_UNIQUE);
454 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 445 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
455 tmp->type = FLOOR; 446 tmp->type = FLOOR;
456 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 447 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... */ 448 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
458 if (new_wall) 449 if (new_wall)
459 { 450 {
460 tmp = arch_to_object (new_wall); 451 tmp = new_wall->instance ();
461 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 452 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
462 tmp->type = BUILDABLE_WALL; 453 tmp->type = BUILDABLE_WALL;
463 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 454 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
464 } 455 }
465 } 456 }
469 * Note: 2 squares around are checked, because potentially we added walls around the building 460 * 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 461 * spot, so need to check that those new walls connect correctly
471 */ 462 */
472 for (xt = x - 2; xt <= x + 2; xt++) 463 for (xt = x - 2; xt <= x + 2; xt++)
473 for (yt = y - 2; yt <= y + 2; yt++) 464 for (yt = y - 2; yt <= y + 2; yt++)
474 {
475 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 465 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
476 fix_walls (pl->map, xt, yt); 466 fix_walls (pl->map, xt, yt);
477 }
478 467
479 /* Now remove raw item from inventory */ 468 /* Now remove raw item from inventory */
480 decrease_ob (material); 469 material->decrease ();
481 470
482 /* And tell player about the fix */ 471 /* And tell player about the fix */
483 new_draw_info (NDI_UNIQUE, 0, pl, message); 472 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} 473}
500 474
501/** 475/**
502 * Wall building function 476 * Wall building function
503 * 477 *
504 * Walls can be build: 478 * Walls can be build:
505 * - on a floor without anything else 479 * - on a floor without anything else
506 * - on an existing wall, with or without a floor 480 * - on an existing wall, with or without a floor
507 */ 481 */
508void 482static void
509apply_builder_wall (object *pl, object *material, short x, short y) 483apply_builder_wall (object *pl, object *material, int x, int y)
510{ 484{
511 object *current_wall; 485 object *current_wall;
512 object *tmp; 486 object *tmp;
513 int xt, yt; 487 int xt, yt;
514 struct archetype *new_wall; 488 struct archetype *new_wall;
536 { 510 {
537 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); 511 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
538 return; 512 return;
539 } 513 }
540 514
541 tmp = arch_to_object (new_wall); 515 tmp = new_wall->instance ();
542 tmp->type = BUILDABLE_WALL; 516 tmp->type = BUILDABLE_WALL;
543 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 517 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
544 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); 518 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
545 519
546 /* If existing wall, remove it, no need to fix other walls */ 520 /* If existing wall, remove it, no need to fix other walls */
562 fix_walls (pl->map, xt, yt); 536 fix_walls (pl->map, xt, yt);
563 } 537 }
564 } 538 }
565 539
566 /* Now remove item from inventory */ 540 /* Now remove item from inventory */
567 decrease_ob (material); 541 material->decrease ();
568 542
569 /* And tell player what happened */ 543 /* And tell player what happened */
570 new_draw_info (NDI_UNIQUE, 0, pl, message); 544 new_draw_info (NDI_UNIQUE, 0, pl, message);
571} 545}
572 546
576 * Item must be put on a square with a floor, you can have something under. 550 * 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). 551 * Archetype of created object is item->slaying (raw material).
578 * Type of inserted item is tested for specific cases (doors & such). 552 * 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) 553 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
580 */ 554 */
581void 555static void
582apply_builder_item (object *pl, object *item, short x, short y) 556apply_builder_item (object *pl, object *item, int x, int y)
583{ 557{
584 object *tmp; 558 object *tmp;
585 struct archetype *arch; 559 struct archetype *arch;
586 int insert_flag; 560 int insert_flag;
587 object *floor; 561 object *floor;
588 object *con_rune; 562 object *con_rune;
589 int connected;
590 563
591 /* Find floor */ 564 /* Find floor */
592 floor = GET_MAP_OB (pl->map, x, y); 565 floor = GET_MAP_OB (pl->map, x, y);
593 if (!floor) 566 if (!floor)
594 { 567 {
607 /* Create item, set flag, insert in map */ 580 /* Create item, set flag, insert in map */
608 arch = archetype::find (item->slaying); 581 arch = archetype::find (item->slaying);
609 if (!arch) 582 if (!arch)
610 return; 583 return;
611 584
612 tmp = arch_to_object (arch); 585 tmp = arch->instance ();
613 586
614 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 587 if (!floor->flag[FLAG_IS_BUILDABLE] || floor->above && !can_build_over (pl->map, tmp, x, y))
615 /* Floor has something on top that interferes with building */ 588 /* Floor has something on top that interferes with building */
616 { 589 {
617 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 590 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
618 return; 591 return;
619 } 592 }
620 593
621 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 594 SET_FLAG (tmp, FLAG_IS_BUILDABLE);
622 SET_FLAG (tmp, FLAG_NO_PICK); 595 SET_FLAG (tmp, FLAG_NO_PICK);
623 596
624 /* 597 /*
625 * This doesn't work on non unique maps. pedestals under floor will not be saved... 598 * Str 1 is a flag that the item [pedestal] should go below the floor.
626 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; 599 * Items under the floor on non-unique maps will not be saved,
600 * so make the item itself unique in this situation.
627 */ 601 */
628 insert_flag = INS_ABOVE_FLOOR_ONLY; 602 insert_flag = item->stats.Str == 1 ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
603 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
604 SET_FLAG (tmp, FLAG_UNIQUE);
629 605
630 connected = 0; 606 shstr_tmp connected;
607
631 switch (tmp->type) 608 switch (tmp->type)
632 { 609 {
633 case DOOR: 610 case DOOR:
634 case GATE: 611 case GATE:
635 case BUTTON: 612 case BUTTON:
636 case DETECTOR: 613 case DETECTOR:
637 case TIMED_GATE: 614 case TIMED_GATE:
638 case PEDESTAL: 615 case PEDESTAL:
639 case CF_HANDLE: 616 case T_HANDLE:
640 case MAGIC_EAR: 617 case MAGIC_EAR:
641 case SIGN: 618 case SIGN:
642 /* Signs don't need a connection, but but magic mouths do. */ 619 /* Signs don't need a connection, but but magic mouths do. */
643 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) 620 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
644 break; 621 break;
622
645 con_rune = get_connection_rune (pl, x, y); 623 con_rune = get_connection_rune (pl, x, y);
646 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 624 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
647 if (connected == -1) 625 if (!connected)
648 { 626 {
649 /* Player already informed of failure by the previous function */ 627 /* Player already informed of failure by the previous function */
650 tmp->destroy (); 628 tmp->destroy ();
651 return; 629 return;
652 } 630 }
631
653 /* Remove marking rune */ 632 /* Remove marking rune */
654 con_rune->destroy (); 633 con_rune->destroy ();
655 } 634 }
656 635
657 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 636 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 637 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 {
660 if (adjust_sign_msg (pl, x, y, tmp) == -1) 638 if (adjust_sign_msg (pl, x, y, tmp) == -1)
661 { 639 {
662 tmp->destroy (); 640 tmp->destroy ();
663 return; 641 return;
664 } 642 }
665 }
666 643
667 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); 644 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
668 if (connected != 0) 645 if (connected)
669 add_button_link (tmp, pl->map, connected); 646 tmp->add_link (pl->map, connected);
670 647
671 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); 648 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
672 decrease_ob_nr (item, 1); 649 item->decrease ();
673} 650}
674 651
675/** 652/**
676 * Item remover. 653 * Item remover.
677 * 654 *
678 * Removes first buildable item, either under or above the floor 655 * Removes first buildable item, either under or above the floor
679 */ 656 */
680void 657static void
681apply_builder_remove (object *pl, int dir) 658apply_builder_remove (object *pl, int dir)
682{ 659{
683 object *item; 660 object *item;
684 short x, y; 661 int x, y;
685 662
686 x = pl->x + freearr_x[dir]; 663 x = pl->x + freearr_x[dir];
687 y = pl->y + freearr_y[dir]; 664 y = pl->y + freearr_y[dir];
688 665
689 /* Check square */ 666 /* Check square */
722apply_map_builder (object *pl, int dir) 699apply_map_builder (object *pl, int dir)
723{ 700{
724 object *builder; 701 object *builder;
725 object *tmp; 702 object *tmp;
726 object *tmp2; 703 object *tmp2;
727 short x, y; 704 int x, y;
728 705
729 if (!pl->type == PLAYER) 706 if (!pl->type == PLAYER)
730 return; 707 return;
731 708
732 /*if ( !player->map->unique ) 709 /*if ( !player->map->unique )
767 } 744 }
768 745
769 tmp2 = find_marked_object (pl); 746 tmp2 = find_marked_object (pl);
770 while (tmp) 747 while (tmp)
771 { 748 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) 749 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
773 { 750 {
774 /* The item building function already has it's own special 751 /* The item building function already has it's own special
775 * checks for this 752 * checks for this
776 */ 753 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 754 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM)
778 { 755 {
779 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 756 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
780 return; 757 return;
781 } 758 }
782 } 759 }
760
783 tmp = tmp->above; 761 tmp = tmp->above;
784 } 762 }
785 763
786 /* Now we know the square is ok */ 764 /* Now we know the square is ok */
787 builder = pl->contr->ranged_ob; 765 builder = pl->contr->ranged_ob;
836 /* Here, it means the builder has an invalid type */ 814 /* 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."); 815 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); 816 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
839} 817}
840 818
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 {
866 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
867 }
868 else
869 {
870 snprintf (buf, sizeof (buf), "talking %s", &book->name);
871 }
872 tmp->name = buf;
873
874 if (book->name_pl != NULL)
875 {
876 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
877 tmp->name_pl = buf2;
878 }
879
880 tmp->face = book->face;
881 tmp->invisible = 0;
882 }
883
884 book->destroy ();
885 return 0;
886}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines