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.1 by elmex, Sun Aug 13 17:16:03 2006 UTC vs.
Revision 1.60 by root, Wed Apr 14 21:36:32 2010 UTC

1/* 1/*
2 * static char *rcsid_build_map = 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * "$Id: build_map.C,v 1.1 2006/08/13 17:16:03 elmex Exp $"; 3 *
4 */ 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5/*
6 CrossFire, A Multiplayer game for X-windows
7
8 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
9 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
10 7 *
11 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
12 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
13 the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
14 (at your option) any later version. 11 * option) any later version.
15 12 *
16 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,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 16 * GNU General Public License for more details.
20 17 *
21 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
22 along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
24 21 *
25 The authors can be reached via e-mail to crossfire-devel@real-time.com 22 * The authors can be reached via e-mail to <support@deliantra.net>
26*/ 23 */
27 24
28#include <global.h> 25#include <global.h>
29#include <living.h> 26#include <living.h>
30#include <spells.h> 27#include <spells.h>
31#include <skills.h> 28#include <skills.h>
32#include <tod.h> 29#include <tod.h>
33#include <sproto.h> 30#include <sproto.h>
34 31
32// macro for this check, it had been inconsistent in this file.
33#define IS_FLOOR(x) x->flag [FLAG_IS_FLOOR]
34
35/** 35/**
36 * Check if objects on a square interfere with building 36 * Check if objects on a square interfere with building
37 */ 37 */
38static int
38int can_build_over( mapstruct* map, object* tmp, short x, short y) 39can_build_over (maptile *map, object *tmp, int x, int y)
39 { 40{
40 object* ob; 41 object *ob;
41 42
42 ob = GET_MAP_OB( map, x, y ); 43 ob = GET_MAP_OB (map, x, y);
43 while ( ob ) 44 while (ob)
45 {
46 /* if ob is not a marking rune or floor, then check special cases */
47 if (ob->arch->archname != shstr_rune_mark && !IS_FLOOR (ob))
44 { 48 {
45 /* if ob is not a marking rune or floor, then check special cases */
46 if ( strcmp( ob->arch->name, "rune_mark" ) && ob->type != FLOOR )
47 {
48 switch ( tmp->type ) 49 switch (tmp->type)
49 { 50 {
50 case SIGN: 51 case SIGN:
51 case MAGIC_EAR: 52 case MAGIC_EAR:
52 /* Allow signs and magic ears to be built on books */ 53 /* Allow signs and magic ears to be built on books */
53 if ( ob->type != BOOK ) { 54 if (ob->type != BOOK)
54 return 0; } 55 return 0;
55 break; 56 break;
56 case BUTTON: 57 case BUTTON:
57 case DETECTOR: 58 case DETECTOR:
58 case PEDESTAL: 59 case PEDESTAL:
59 case CF_HANDLE: 60 case T_HANDLE:
60 /* Allow buttons and levers to be built under gates */ 61 /* Allow buttons and levers to be built under gates */
61 if ( ob->type != GATE && ob->type != DOOR ) { 62 if (ob->type != GATE && ob->type != DOOR)
62 return 0; }
63 break;
64 default:
65 return 0; 63 return 0;
66 } 64 break;
65 default:
66 return 0;
67 } 67 }
68 }
69
68 ob = ob->above; 70 ob = ob->above;
69 } 71 }
72
70 return 1; 73 return 1;
71 } 74}
72 75
73/** 76/**
74 * Erases marking runes at specified location 77 * Erases marking runes at specified location
75 */ 78 */
76void remove_marking_runes( mapstruct* map, short x, short y ) 79static void
77 { 80remove_marking_runes (maptile *map, int x, int y)
81{
78 object* rune; 82 object *rune;
79 object* next; 83 object *next;
80 84
81 rune = GET_MAP_OB( map, x, y ); 85 rune = GET_MAP_OB (map, x, y);
82 while ( rune ) 86 while (rune)
83 { 87 {
84 next = rune->above; 88 next = rune->above;
85 if ( ( rune->type == SIGN ) && ( !strcmp( rune->arch->name, "rune_mark" ) ) ) 89
86 { 90 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
87 remove_ob( rune ); 91 rune->destroy ();
88 free_object( rune ); 92
89 }
90 rune = next; 93 rune = next;
91 }
92 } 94 }
95}
93 96
94/** 97/**
95 * Returns an unused value for 'connected'. 98 * Returns an unused value for 'connected'.
96 * \param map: map for which to find a value 99 * \param map: map for which to find a value
97 * \return 'connected' value with no item, or -1 if failure. 100 * \return 'connected' value with no item, or -1 if failure.
98 * 101 *
99 * Tries 1000 random values, then returns -1. 102 * Tries 1000 random values, then returns -1.
100 */ 103 */
104static shstr_tmp
101int find_unused_connected_value( mapstruct* map ) 105find_unused_connected_value (maptile *map)
102 { 106{
103 int connected = 0; 107 for (int i = 1000; --i; )
104 int itest = 0;
105 oblinkpt* obp;
106
107 while ( itest++ < 1000 )
108 {
109 connected = 1 + rand( ) % 20000;
110 for ( obp = map->buttons; obp && ( obp->value != connected ); obp = obp->next );
111
112 if ( !obp )
113 return connected;
114 }
115
116 return -1;
117 } 108 {
109 char buf[64];
118 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
133 return rune;
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 *
123 * Will search the specified spot for a marking rune. 139 * Will search the specified spot for a marking rune.
125 * 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
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 */
146static shstr_tmp
130int find_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)
131 { 148{
132 object* force; 149 object *force;
133 int connected;
134 150
135 if ( !rune ) 151 if (!rune)
136 rune = get_connection_rune( pl, x, y ); 152 rune = get_connection_rune (pl, x, y);
137 153
138 if ( !rune ) 154 if (!rune)
155 {
156 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name.");
157 return shstr_tmp ();
158 }
159
160 /* Now, find force in player's inventory */
161 force = pl->inv;
162 while (force
163 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
164 || force->msg != rune->msg))
165 force = force->below;
166
167 if (!force)
168 /* No force, need to create & insert one */
169 {
170 /* Find unused value */
171 shstr_tmp id = find_unused_connected_value (pl->map);
172
173 if (!id)
139 { 174 {
140 new_draw_info( NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name." ); 175 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
141 return -1; 176 return shstr_tmp ();
142 } 177 }
143 178
144 /* Now, find force in player's inventory */ 179 force = get_archetype (FORCE_NAME);
145 force = pl->inv; 180 force->slaying = pl->map->path;
146 while ( force && ( ( force->type != FORCE ) || ( !force->slaying ) || ( strcmp( force->slaying, pl->map->path ) ) || ( !force->msg ) || ( strcmp( force->msg, rune->msg ) ) ) ) 181 force->msg = rune->msg;
147 force = force->below; 182 force->race = id;
183 force->set_speed (0);
148 184
149 if ( !force ) 185 insert_ob_in_ob (force, pl);
150 /* No force, need to create & insert one */ 186
187 return id;
188 }
189
190 /* Found the force, everything's easy. */
191 return force->race;
192}
193
194/**
195 * Returns the book/scroll on the current square, for purposes of building
196 */
197static object *
198get_msg_book (object *pl, int x, int y)
199{
200 object *book = GET_MAP_OB (pl->map, x, y);
201
202 while (book && (book->type != BOOK))
203 book = book->above;
204
205 return book;
206}
207
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 tmp->msg = book->msg;
228
229 if (tmp->invisible)
230 {
231 if (book->custom_name)
232 snprintf (buf, sizeof (buf), "talking %s", &book->custom_name);
233 else
234 snprintf (buf, sizeof (buf), "talking %s", &book->name);
235
236 tmp->name = buf;
237
238 if (book->name_pl)
151 { 239 {
152 /* Find unused value */ 240 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
153 connected = find_unused_connected_value( pl->map ); 241 tmp->name_pl = buf2;
154 if ( connected == -1 )
155 {
156 new_draw_info( NDI_UNIQUE, 0, pl, "Could not create more groups." );
157 return -1;
158 }
159
160 force = get_archetype( FORCE_NAME );
161 force->speed = 0;
162 update_ob_speed( force );
163 force->slaying = add_string( pl->map->path );
164 force->msg = add_string( rune->msg );
165 force->path_attuned = connected;
166 insert_ob_in_ob( force, pl );
167
168 return connected;
169 } 242 }
170 243
171 /* Found the force, everything's easy. */ 244 tmp->face = book->face;
172 return force->path_attuned; 245 tmp->invisible = 0;
173 }
174 246 }
175/**
176 * Returns the marking rune on the square, for purposes of building connections
177 */
178object* get_connection_rune( object* pl, short x, short y )
179 {
180 object* rune;
181
182 rune = GET_MAP_OB( pl->map, x, y );
183 while ( rune && ( ( rune->type != SIGN ) || ( strcmp( rune->arch->name, "rune_mark" ) ) ) )
184 rune = rune->above;
185 return rune;
186 }
187
188/**
189 * Returns the book/scroll on the current square, for purposes of building
190 */
191object* get_msg_book( object* pl, short x, short y )
192 {
193 object* book;
194
195 book = GET_MAP_OB( pl->map, x, y );
196 while ( book && ( book->type != BOOK ) )
197 book = book->above;
198 return book;
199 }
200 247
248 book->destroy ();
249 return 0;
250}
251
201/** 252/**
202 * Returns first item of type WALL. 253 * Returns first item of type BUILDABLE_WALL.
203 */ 254 */
255static object *
204object* get_wall( mapstruct* map, int x, int y ) 256get_wall (maptile *map, int x, int y)
205 { 257{
206 object* wall;
207
208 wall = GET_MAP_OB( map, x, y ); 258 object *wall = GET_MAP_OB (map, x, y);
259
209 while ( wall && ( WALL != wall->type ) ) 260 while (wall && (BUILDABLE_WALL != wall->type))
210 wall = wall->above; 261 wall = wall->above;
211 262
212 return wall; 263 return wall;
213 } 264}
214 265
215/** 266/**
216 * Fixes walls around specified spot 267 * Fixes walls around specified spot
217 * 268 *
218 * \param map is the map 269 * \param map is the map
221 * 272 *
222 * Basically it ensures the correct wall is put where needed. 273 * Basically it ensures the correct wall is put where needed.
223 * 274 *
224 * Note: x & y must be valid map coordinates. 275 * Note: x & y must be valid map coordinates.
225 */ 276 */
277static void
226void fix_walls( mapstruct* map, int x, int y ) 278fix_walls (maptile *map, int x, int y)
227 { 279{
228 int connect;
229 object* wall;
230 char archetype[ MAX_BUF ]; 280 char archetype[MAX_BUF];
231 char* underscore; 281 char *underscore;
232 uint32 old_flags[ 4 ];
233 struct archt* new_arch; 282 struct archetype *new_arch;
234 int flag;
235 283
236 /* First, find the wall on that spot */ 284 /* First, find the wall on that spot */
237 wall = get_wall( map, x, y ); 285 object *wall = get_wall (map, x, y);
238 if ( !wall ) 286 if (!wall)
239 /* Nothing -> bail out */ 287 /* Nothing -> bail out */
240 return; 288 return;
241 289
242 /* Find base name */ 290 /* Find base name */
243 strcpy( archetype, wall->arch->name ); 291 assign (archetype, wall->arch->archname);
244 underscore = strchr( archetype, '_' ); 292 underscore = strchr (archetype, '_');
293
294 /* search for the first _ before a number */
295 while (underscore && !isdigit (*(underscore + 1)))
296 underscore = strchr (underscore + 1, '_');
297
245 if ( !underscore || ( !isdigit( *( underscore + 1 ) ) ) ) 298 if (!underscore || !isdigit (*(underscore + 1)))
246 /* Not in a format we can change, bail out */ 299 /* Not in a format we can change, bail out */
247 return; 300 return;
248 301
249 underscore++; 302 underscore++;
250 *underscore = '\0'; 303 *underscore = '\0';
251 304
252 connect = 0; 305 int connect = 0;
253 306
254 if ( ( x > 0 ) && get_wall( map, x - 1, y ) ) 307 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
255 connect |= 1; 308 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
256 if ( ( x < MAP_WIDTH( map ) - 1 ) && get_wall( map, x + 1, y ) ) 309 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
257 connect |= 2; 310 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
258 311
259 if ( ( y > 0 ) && get_wall( map, x, y - 1 ) ) 312 // one bit per dir, 1 left, 2 right, 4 up, 8 down
260 connect |= 4; 313 static const char *walltype[16] = {
314 "0",
315 "1_3",
316 "1_4",
317 "2_1_2",
318 "1_2",
319 "2_2_4",
320 "2_2_1",
321 "3_1",
322 "1_1",
323 "2_2_3",
324 "2_2_2",
325 "3_3",
326 "2_1_1",
327 "3_4",
328 "3_2",
329 "4"
330 };
261 331
262 if ( ( y < MAP_HEIGHT( map ) - 1 ) && get_wall( map, x, y + 1 ) ) 332 strcat (archetype, walltype [connect]);
263 connect |= 8;
264 333
265 switch( connect )
266 {
267 case 0:
268 strcat( archetype, "0");
269 break;
270 case 1:
271 strcat( archetype, "1_3");
272 break;
273 case 2:
274 strcat( archetype, "1_4");
275 break;
276 case 3:
277 strcat( archetype, "2_1_2");
278 break;
279 case 4:
280 strcat( archetype, "1_2");
281 break;
282 case 5:
283 strcat( archetype, "2_2_4");
284 break;
285 case 6:
286 strcat( archetype, "2_2_1");
287 break;
288 case 7:
289 strcat( archetype, "3_1");
290 break;
291 case 8:
292 strcat( archetype, "1_1");
293 break;
294 case 9:
295 strcat( archetype, "2_2_3");
296 break;
297 case 10:
298 strcat( archetype, "2_2_2");
299 break;
300 case 11:
301 strcat( archetype, "3_3");
302 break;
303 case 12:
304 strcat( archetype, "2_1_1");
305 break;
306 case 13:
307 strcat( archetype, "3_4");
308 break;
309 case 14:
310 strcat( archetype, "3_2");
311 break;
312 case 15:
313 strcat( archetype, "4");
314 break;
315 }
316
317 /* 334 /*
318 * Before anything, make sure the archetype does exist... 335 * Before anything, make sure the archetype does exist...
319 * If not, prolly an error... 336 * If not, prolly an error...
320 */ 337 */
321 new_arch = find_archetype( archetype ); 338 new_arch = archetype::find (archetype);
339
322 if ( !new_arch ) 340 if (!new_arch)
323 return; 341 return;
324 342
325 /* Now delete current wall, and insert new one 343 /* Now delete current wall, and insert new one
326 * We save flags to avoid any trouble with buildable/non buildable, and so on 344 * We save flags to avoid any trouble with buildable/non buildable, and so on
327 */ 345 */
328 for ( flag = 0; flag < 4; flag++ ) 346 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
329 old_flags[ flag ] = wall->flags[ flag ];
330 remove_ob( wall );
331 free_object( wall );
332 347
333 wall = arch_to_object( new_arch ); 348 wall->destroy ();
349
350 wall = new_arch->instance ();
334 wall->type = WALL; 351 wall->type = BUILDABLE_WALL;
335 insert_ob_in_map_at( wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y ); 352 insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y);
336 for ( flag = 0; flag < 4; flag++ ) 353 wall->flag = old_flags;
337 wall->flags[ flag ] = old_flags[ flag ]; 354}
338 }
339 355
340/** 356/**
341 * \brief Floor building function 357 * \brief Floor building function
342 * 358 *
343 * Floors can be build: 359 * Floors can be build:
345 * - on an existing wall, with or without a floor under it 361 * - on an existing wall, with or without a floor under it
346 * 362 *
347 * Note: this function will inconditionally change squares around (x, y) 363 * Note: this function will inconditionally change squares around (x, y)
348 * so don't call it with x == 0 for instance! 364 * so don't call it with x == 0 for instance!
349 */ 365 */
366static void
350void apply_builder_floor(object* pl, object* material, short x, short y ) 367apply_builder_floor (object *pl, object *material, int x, int y)
351 { 368{
352 object* tmp, *above; 369 object *tmp, *above;
353 object* above_floor; /* Item above floor, if any */ 370 object *above_floor; /* Item above floor, if any */
354 struct archt* new_floor; 371 struct archetype *new_floor;
355 struct archt* new_wall; 372 struct archetype *new_wall;
356 int i, xt, yt, floor_removed; 373 int i, xt, yt, floor_removed;
357 char message[ MAX_BUF ]; 374 char message[MAX_BUF];
358 375
359 sprintf( message, "You change the floor to better suit your tastes." ); 376 sprintf (message, "You change the floor to better suit your tastes.");
360 377
361 /* 378 /*
362 * Now the building part... 379 * Now the building part...
363 * First, remove wall(s) and floor(s) at position x, y 380 * First, remove wall(s) and floor(s) at position x, y
364 */ 381 */
365 above_floor = NULL; 382 above_floor = NULL;
366 new_wall = NULL; 383 new_wall = NULL;
367 floor_removed = 0; 384 floor_removed = 0;
368 tmp = GET_MAP_OB( pl->map, x, y ); 385 tmp = GET_MAP_OB (pl->map, x, y);
369 if ( tmp ) 386 if (tmp)
387 {
388 while (tmp)
370 { 389 {
371 while ( tmp ) 390 above = tmp->above;
391 if (BUILDABLE_WALL == tmp->type)
372 { 392 {
373 above = tmp->above; 393 /* There was a wall, remove it & keep its archetype to make new walls */
374 if ( WALL == tmp->type ) 394 new_wall = tmp->arch;
395 tmp->destroy ();
396 sprintf (message, "You destroy the wall and redo the floor.");
397 }
398 else if (IS_FLOOR (tmp))
399 {
400 tmp->destroy ();
401 floor_removed = 1;
402 }
403 else
404 {
405 if (floor_removed)
375 { 406 {
376 /* There was a wall, remove it & keep its archetype to make new walls */ 407 /* This is the first item that was above the floor */
377 new_wall = tmp->arch;
378 remove_ob( tmp ); 408 above_floor = tmp;
379 free_object( tmp ); 409 floor_removed = 0;
380 sprintf( message, "You destroy the wall and redo the floor." );
381 } 410 }
382 else if ( ( FLOOR == tmp->type ) || ( QUERY_FLAG(tmp, FLAG_IS_FLOOR ) ) )
383 {
384 remove_ob( tmp );
385 free_object( tmp );
386 floor_removed = 1;
387 } 411 }
388 else
389 {
390 if ( floor_removed )
391 above_floor = tmp;
392 }
393 412
394 tmp = above; 413 tmp = above;
414 }
415 }
416
417 /* Now insert our floor */
418 new_floor = archetype::find (material->slaying);
419 if (!new_floor)
420 {
421 /* Not found, log & bail out */
422 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
423 return;
424 }
425
426 tmp = new_floor->instance ();
427 tmp->set_flag (FLAG_IS_BUILDABLE);
428 tmp->set_flag (FLAG_UNIQUE);
429 tmp->set_flag (FLAG_IS_FLOOR);
430 //tmp->type = FLOOR;
431 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
432
433 /*
434 * Next step: make sure there are either walls or floors around the new square
435 * Since building, you can have: blocking view / floor / wall / nothing
436 */
437 for (i = 1; i <= 8; i++)
438 {
439 xt = x + freearr_x[i];
440 yt = y + freearr_y[i];
441 tmp = GET_MAP_OB (pl->map, xt, yt);
442 if (!tmp)
443 {
444 /* Must insert floor & wall */
445 tmp = new_floor->instance ();
446 /* Better make the floor unique */
447 tmp->set_flag (FLAG_UNIQUE);
448 tmp->set_flag (FLAG_IS_BUILDABLE);
449 //tmp->type = FLOOR;
450 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
451 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
452 if (new_wall)
453 {
454 tmp = new_wall->instance ();
455 tmp->set_flag (FLAG_IS_BUILDABLE);
456 tmp->type = BUILDABLE_WALL;
457 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
395 } 458 }
396 } 459 }
460 }
397 461
398 /* Now insert our floor */
399 new_floor = find_archetype( material->slaying );
400 if ( !new_floor )
401 {
402 /* Not found, log & bail out */
403 LOG( llevError, "apply_builder_floor: unable to find archetype %s.\n", material->slaying );
404 return;
405 }
406
407 tmp = arch_to_object( new_floor );
408 SET_FLAG( tmp, FLAG_IS_BUILDABLE );
409 SET_FLAG( tmp, FLAG_UNIQUE );
410 SET_FLAG( tmp, FLAG_IS_FLOOR );
411 tmp->type = FLOOR;
412 insert_ob_in_map_at( tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y );
413
414 /*
415 * Next step: make sure there are either walls or floors around the new square
416 * Since building, you can have: blocking view / floor / wall / nothing
417 */
418 for ( i = 1; i <= 8; i++ )
419 {
420 xt = x + freearr_x[ i ];
421 yt = y + freearr_y[ i ];
422 tmp = GET_MAP_OB( pl->map, xt, yt );
423 if ( !tmp )
424 {
425 /* Must insert floor & wall */
426 tmp = arch_to_object( new_floor );
427 /* Better make the floor unique */
428 SET_FLAG( tmp, FLAG_UNIQUE );
429 SET_FLAG( tmp, FLAG_IS_BUILDABLE );
430 tmp->type = FLOOR;
431 insert_ob_in_map_at( tmp, pl->map, 0, 0, xt, yt );
432 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
433 if ( new_wall )
434 {
435 tmp = arch_to_object( new_wall );
436 SET_FLAG( tmp, FLAG_IS_BUILDABLE );
437 tmp->type = WALL;
438 insert_ob_in_map_at( tmp, pl->map, 0, 0, xt, yt );
439 }
440 }
441 }
442
443 /* Finally fixing walls to ensure nice continuous walls 462 /* Finally fixing walls to ensure nice continuous walls
444 * Note: 2 squares around are checked, because potentially we added walls around the building 463 * Note: 2 squares around are checked, because potentially we added walls around the building
445 * spot, so need to check that those new walls connect correctly 464 * spot, so need to check that those new walls connect correctly
446 */ 465 */
447 for ( xt = x - 2; xt <= x + 2; xt++ ) 466 for (xt = x - 2; xt <= x + 2; xt++)
448 for ( yt = y - 2; yt <= y + 2; yt++ ) 467 for (yt = y - 2; yt <= y + 2; yt++)
449 {
450 if ( !OUT_OF_REAL_MAP( pl->map, xt, yt ) ) 468 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
451 fix_walls( pl->map, xt, yt ); 469 fix_walls (pl->map, xt, yt);
452 }
453 470
454 /* Now remove raw item from inventory */ 471 /* Now remove raw item from inventory */
455 decrease_ob( material ); 472 material->decrease ();
456 473
457 /* And tell player about the fix */ 474 /* And tell player about the fix */
458 new_draw_info( NDI_UNIQUE, 0, pl, message ); 475 new_draw_info (NDI_UNIQUE, 0, pl, message);
459 } 476}
460 477
461/** 478/**
462 * Wall building function 479 * Wall building function
463 * 480 *
464 * Walls can be build: 481 * Walls can be build:
465 * - on a floor without anything else 482 * - on a floor without anything else
466 * - on an existing wall, with or without a floor 483 * - on an existing wall, with or without a floor
467 */ 484 */
485static void
468void apply_builder_wall( object* pl, object* material, short x, short y ) 486apply_builder_wall (object *pl, object *material, int x, int y)
469 { 487{
470 object* current_wall; 488 object *current_wall;
471 object* tmp; 489 object *tmp;
472 int xt, yt; 490 int xt, yt;
473 struct archt* new_wall; 491 struct archetype *new_wall;
474 char message[ MAX_BUF ]; 492 char message[MAX_BUF];
475 493
476 remove_marking_runes( pl->map, x, y ); 494 remove_marking_runes (pl->map, x, y);
477 495
478 /* Grab existing wall, if any */ 496 /* Grab existing wall, if any */
479 current_wall = NULL; 497 current_wall = NULL;
480 tmp = GET_MAP_OB( pl->map, x, y ); 498 tmp = GET_MAP_OB (pl->map, x, y);
481 while ( tmp && !current_wall ) 499 while (tmp && !current_wall)
482 { 500 {
483 if ( WALL == tmp->type ) 501 if (BUILDABLE_WALL == tmp->type)
484 current_wall = tmp; 502 current_wall = tmp;
485 503
486 tmp = tmp->above; 504 tmp = tmp->above;
487 } 505 }
488 506
489 /* Find the raw wall in inventory */ 507 /* Find the raw wall in inventory */
490 sprintf( message, "You build a wall." ); 508 sprintf (message, "You build a wall.");
491 509
492 /* Now we can actually insert the wall */ 510 /* Now we can actually insert the wall */
493 new_wall = find_archetype( material->slaying ); 511 new_wall = archetype::find (material->slaying);
494 if ( !new_wall ) 512 if (!new_wall)
495 { 513 {
496 LOG( llevError, "apply_builder_wall: unable to find archetype %s\n", material->slaying ); 514 LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying);
497 return; 515 return;
498 } 516 }
499 517
500 tmp = arch_to_object( new_wall ); 518 tmp = new_wall->instance ();
501 tmp->type = WALL; 519 tmp->type = BUILDABLE_WALL;
502 SET_FLAG( tmp, FLAG_IS_BUILDABLE ); 520 tmp->set_flag (FLAG_IS_BUILDABLE);
503 insert_ob_in_map_at( tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y ); 521 insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y);
504 522
505 /* If existing wall, remove it, no need to fix other walls */ 523 /* If existing wall, remove it, no need to fix other walls */
506 if ( current_wall ) 524 if (current_wall)
507 { 525 {
508 remove_ob( current_wall ); 526 current_wall->destroy ();
509 free_object( current_wall );
510 fix_walls( pl->map, x, y ); 527 fix_walls (pl->map, x, y);
511 sprintf( message, "You redecorate the wall to better suit your tastes." ); 528 sprintf (message, "You redecorate the wall to better suit your tastes.");
512 } 529 }
513 else 530 else
514 { 531 {
515 /* Else fix all walls around */ 532 /* Else fix all walls around */
516 for ( xt = x - 1; xt <= x + 1; xt++ ) 533 for (xt = x - 1; xt <= x + 1; xt++)
517 for ( yt = y - 1; yt <= y + 1; yt++ ) 534 for (yt = y - 1; yt <= y + 1; yt++)
518 { 535 {
519 if ( OUT_OF_REAL_MAP( pl->map, xt, yt ) ) 536 if (OUT_OF_REAL_MAP (pl->map, xt, yt))
520 continue; 537 continue;
521 538
522 fix_walls( pl->map, xt, yt ); 539 fix_walls (pl->map, xt, yt);
523 }
524 } 540 }
541 }
525 542
526 /* Now remove item from inventory */ 543 /* Now remove item from inventory */
527 decrease_ob( material ); 544 material->decrease ();
528 545
529 /* And tell player what happened */ 546 /* And tell player what happened */
530 new_draw_info( NDI_UNIQUE, 0, pl, message ); 547 new_draw_info (NDI_UNIQUE, 0, pl, message);
531 } 548}
532 549
533/** 550/**
534 * Generic item builder. 551 * Generic item builder.
535 * 552 *
536 * Item must be put on a square with a floor, you can have something under. 553 * Item must be put on a square with a floor, you can have something under.
537 * Archetype of created object is item->slaying (raw material). 554 * Archetype of created object is item->slaying (raw material).
538 * Type of inserted item is tested for specific cases (doors & such). 555 * Type of inserted item is tested for specific cases (doors & such).
539 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess) 556 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
540 */ 557 */
558static void
541void apply_builder_item( object* pl, object* item, short x, short y ) 559apply_builder_item (object *pl, object *item, int x, int y)
542 { 560{
543 object* tmp; 561 object *tmp;
544 struct archt* arch; 562 struct archetype *arch;
545 int insert_flag; 563 int insert_flag;
546 object* floor; 564 object *floor;
547 object* con_rune; 565 object *con_rune;
548 int connected;
549 566
550 /* Find floor */ 567 /* Find floor */
551 floor = GET_MAP_OB( pl->map, x, y ); 568 floor = GET_MAP_OB (pl->map, x, y);
552 if ( !floor ) 569 if (!floor)
553 { 570 {
554 new_draw_info( NDI_UNIQUE, 0, pl, "Invalid square." ); 571 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
572 return;
573 }
574
575 while (floor && !IS_FLOOR (floor))
576 floor = floor->above;
577
578 if (!floor)
579 {
580 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
581 return;
582 }
583 /* Create item, set flag, insert in map */
584 arch = archetype::find (item->slaying);
585 if (!arch)
586 return;
587
588 tmp = arch->instance ();
589
590 if (!floor->flag[FLAG_IS_BUILDABLE] || floor->above && !can_build_over (pl->map, tmp, x, y))
591 /* Floor has something on top that interferes with building */
592 {
593 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
594 return;
595 }
596
597 tmp->set_flag (FLAG_IS_BUILDABLE);
598 tmp->set_flag (FLAG_NO_PICK);
599
600 /*
601 * Str 1 is a flag that the item [pedestal] should go below the floor.
602 * Items under the floor on non-unique maps will not be saved,
603 * so make the item itself unique in this situation.
604 */
605 insert_flag = item->stats.Str == 1 ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
606 if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset)
607 tmp->set_flag (FLAG_UNIQUE);
608
609 shstr_tmp connected;
610
611 switch (tmp->type)
612 {
613 case DOOR:
614 case GATE:
615 case BUTTON:
616 case DETECTOR:
617 case TIMED_GATE:
618 case PEDESTAL:
619 case T_HANDLE:
620 case MAGIC_EAR:
621 case SIGN:
622 /* Signs don't need a connection, but but magic mouths do. */
623 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
624 break;
625
626 con_rune = get_connection_rune (pl, x, y);
627 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
628 if (!connected)
629 {
630 /* Player already informed of failure by the previous function */
631 tmp->destroy ();
632 return;
633 }
634
635 /* Remove marking rune */
636 con_rune->destroy ();
637 }
638
639 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
640 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
641 if (adjust_sign_msg (pl, x, y, tmp) == -1)
642 {
643 tmp->destroy ();
555 return; 644 return;
556 } 645 }
557 646
558 while ( floor && ( floor->type != FLOOR ) && ( !QUERY_FLAG( floor, FLAG_IS_FLOOR ) ) )
559 floor = floor->above;
560
561 if ( !floor )
562 {
563 new_draw_info( NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here." );
564 return;
565 }
566 /* Create item, set flag, insert in map */
567 arch = find_archetype( item->slaying );
568 if ( !arch )
569 return;
570
571 tmp = arch_to_object( arch );
572
573 if ( ( floor->above ) && ( !can_build_over(pl->map, tmp, x, y) ) )
574 /* Floor has something on top that interferes with building */
575 {
576 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build here." );
577 return;
578 }
579
580 SET_FLAG( tmp, FLAG_IS_BUILDABLE );
581 SET_FLAG( tmp, FLAG_NO_PICK );
582
583 /*
584 * This doesn't work on non unique maps. pedestals under floor will not be saved...
585 insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY;
586 */
587 insert_flag = INS_ABOVE_FLOOR_ONLY;
588
589 connected = 0;
590 switch( tmp->type )
591 {
592 case DOOR:
593 case GATE:
594 case BUTTON:
595 case DETECTOR:
596 case TIMED_GATE:
597 case PEDESTAL:
598 case CF_HANDLE:
599 case MAGIC_EAR:
600 case SIGN:
601 /* Signs don't need a connection, but but magic mouths do. */
602 if (tmp->type == SIGN && strcmp( tmp->arch->name, "magic_mouth" ))
603 break;
604 con_rune = get_connection_rune( pl, x, y );
605 connected = find_or_create_connection_for_map( pl, x, y, con_rune );
606 if ( connected == -1 )
607 {
608 /* Player already informed of failure by the previous function */
609 free_object( tmp );
610 return;
611 }
612 /* Remove marking rune */
613 remove_ob( con_rune );
614 free_object( con_rune );
615 }
616
617 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
618 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
619 {
620 if (adjust_sign_msg( pl, x, y, tmp ) == -1)
621 {
622 free_object( tmp );
623 return;
624 }
625 }
626
627 insert_ob_in_map_at( tmp, pl->map, floor, insert_flag, x, y ); 647 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
628 if ( connected != 0 ) 648 if (connected)
629 add_button_link( tmp, pl->map, connected ); 649 tmp->add_link (pl->map, connected);
630 650
631 new_draw_info_format( NDI_UNIQUE, 0, pl, "You build the %s", query_name( tmp ) ); 651 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
632 decrease_ob_nr( item, 1 ); 652 item->decrease ();
633 } 653}
634 654
635/** 655/**
636 * Item remover. 656 * Item remover.
637 * 657 *
638 * Removes first buildable item, either under or above the floor 658 * Removes first buildable item, either under or above the floor
639 */ 659 */
660static void
640void apply_builder_remove( object* pl, int dir ) 661apply_builder_remove (object *pl, int dir)
641 { 662{
642 object* item; 663 object *item;
643 short x, y; 664 int x, y;
644 665
645 x = pl->x + freearr_x[ dir ]; 666 x = pl->x + freearr_x[dir];
646 y = pl->y + freearr_y[ dir ]; 667 y = pl->y + freearr_y[dir];
647 668
648 /* Check square */ 669 /* Check square */
649 item = GET_MAP_OB( pl->map, x, y ); 670 item = GET_MAP_OB (pl->map, x, y);
650 if ( !item ) 671 if (!item)
651 { 672 {
652 /* Should not happen with previous tests, but we never know */ 673 /* Should not happen with previous tests, but we never know */
653 new_draw_info( NDI_UNIQUE, 0, pl, "Invalid square." ); 674 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
654 LOG( llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path ); 675 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
655 return; 676 return;
656 } 677 }
657 678
658 if ( item->type == FLOOR || QUERY_FLAG(item,FLAG_IS_FLOOR) ) 679 if (IS_FLOOR (item))
659 item = item->above; 680 item = item->above;
660 681
661 if ( !item ) 682 if (!item)
662 {
663 new_draw_info( NDI_UNIQUE, 0, pl, "Nothing to remove." ); 683 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
664 return; 684 else if (item->type == BUILDABLE_WALL)
665 }
666
667 /* Now remove object, with special cases (buttons & such) */
668 switch ( item->type )
669 {
670 case WALL:
671 new_draw_info( NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor." ); 685 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
672 return; 686 else if (!item->flag [FLAG_IS_BUILDABLE])
673 687 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
674 case DOOR: 688 else
675 case BUTTON: 689 {
676 case GATE:
677 case TIMED_GATE:
678 case DETECTOR:
679 case PEDESTAL:
680 case CF_HANDLE:
681 case MAGIC_EAR:
682 case SIGN:
683 /* Special case: must unconnect */
684 if (QUERY_FLAG(item,FLAG_IS_LINKED))
685 remove_button_link( item );
686
687 /* Fall through */
688
689 default:
690 /* Remove generic item */
691 new_draw_info_format( NDI_UNIQUE, 0, pl, "You remove the %s", query_name( item ) ); 690 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
692 remove_ob( item ); 691 item->destroy ();
693 free_object( item );
694 }
695 } 692 }
693}
696 694
697/** 695/**
698 * Global building function 696 * Global building function
699 * 697 *
700 * This is the general map building function. Called when the player 'fires' a builder 698 * This is the general map building function. Called when the player 'fires' a builder
701 * or remover object. 699 * or remover object.
702 */ 700 */
701void
703void apply_map_builder( object* pl, int dir ) 702apply_map_builder (object *pl, int dir)
704 { 703{
705 object* builder; 704 int x, y;
706 object* tmp;
707 object* tmp2;
708 short x, y;
709 705
710 if ( !pl->type == PLAYER ) 706 if (!pl->type == PLAYER)
711 return; 707 return;
712 708
713 /*if ( !player->map->unique ) 709 /*if ( !player->map->unique )
710 {
711 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." );
712 return;
713 } */
714
715 if (dir == 0)
716 {
717 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
718 return;
719 }
720
721 x = pl->x + freearr_x[dir];
722 y = pl->y + freearr_y[dir];
723
724 if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y))
725 {
726 new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge...");
727 return;
728 }
729
730 /*
731 * Check specified square
732 * The square must have only buildable items
733 * Exception: marking runes are all right,
734 * since they are used for special things like connecting doors / buttons
735 */
736
737 object *tmp = GET_MAP_OB (pl->map, x, y);
738 if (!tmp)
739 {
740 /* Nothing, meaning player is standing next to an undefined square... */
741 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
742 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
743 return;
744 }
745
746 object *builder = pl->contr->ranged_ob;
747
748 object *tmp2 = pl->mark ();
749
750 while (tmp)
751 {
752 if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
714 { 753 {
715 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." ); 754 /* The item building function already has it's own special
716 return; 755 * checks for this
717 }*/ 756 */
718 757 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM)
719 if ( dir == 0 )
720 {
721 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself." );
722 return;
723 }
724
725 x = pl->x + freearr_x[ dir ];
726 y = pl->y + freearr_y[ dir ];
727
728 if ( ( 1 > x ) || ( 1 > y ) || ( ( MAP_WIDTH( pl->map ) - 2 ) < x ) || ( ( MAP_HEIGHT( pl->map ) - 2 ) < y ) )
729 {
730 new_draw_info( NDI_UNIQUE, 0, pl, "Can't build on map edge..." );
731 return;
732 }
733
734 /*
735 * Check specified square
736 * The square must have only buildable items
737 * Exception: marking runes are all right,
738 * since they are used for special things like connecting doors / buttons
739 */
740
741 tmp = GET_MAP_OB( pl->map, x, y );
742 if ( !tmp )
743 {
744 /* Nothing, meaning player is standing next to an undefined square... */
745 LOG( llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, pl->map->path );
746 new_draw_info( NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird." );
747 return;
748 }
749 tmp2 = find_marked_object( pl );
750 while ( tmp )
751 {
752 if ( !QUERY_FLAG( tmp, FLAG_IS_BUILDABLE ) && ( ( tmp->type != SIGN )
753 || ( strcmp( tmp->arch->name, "rune_mark" ) ) ) )
754 { 758 {
755 /* The item building function already has it's own special 759 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (0)))
756 * checks for this
757 */
758 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM ))
759 {
760 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build here." ); 760 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
761 return;
762 }
763 }
764 tmp = tmp->above;
765 }
766 761
767 /* Now we know the square is ok */
768 builder = pl->contr->ranges[ range_builder ];
769
770 if ( builder->subtype == ST_BD_REMOVE )
771 /* Remover -> call specific function and bail out */
772 {
773 apply_builder_remove( pl, dir );
774 return;
775 }
776
777 if ( builder->subtype == ST_BD_BUILD )
778 /*
779 * Builder.
780 * Find marked item to build, call specific function
781 */
782 {
783 tmp = tmp2;
784 if ( !tmp )
785 {
786 new_draw_info( NDI_UNIQUE, 0, pl, "You need to mark raw materials to use." );
787 return;
788 }
789
790 if ( tmp->type != MATERIAL )
791 {
792 new_draw_info( NDI_UNIQUE, 0, pl, "You can't use the marked item to build." );
793 return;
794 }
795
796 switch( tmp->subtype )
797 {
798 case ST_MAT_FLOOR:
799 apply_builder_floor( pl, tmp, x, y );
800 return; 762 return;
801
802 case ST_MAT_WALL:
803 apply_builder_wall( pl, tmp, x, y );
804 return;
805
806 case ST_MAT_ITEM:
807 apply_builder_item( pl, tmp, x, y );
808 return;
809
810 default:
811 new_draw_info( NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry." );
812 LOG( llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype );
813 return;
814 } 763 }
815 } 764 }
816 765
817 /* Here, it means the builder has an invalid type */ 766 tmp = tmp->above;
818 new_draw_info( NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry." );
819 LOG( llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype );
820 }
821 767 }
822/** 768
823 * Make the built object inherit the msg of books that are used with it. 769 /* Now we know the square is ok */
824 * For objects already invisible (i.e. magic mouths & ears), also make it 770 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (1)))
825 * it inherit the face and the name with "talking " prepended. 771 return;
826 */ 772
827int adjust_sign_msg( object* pl, short x, short y, object* tmp ) 773 if (builder->subtype == ST_BD_REMOVE)
774 /* Remover -> call specific function and bail out */
775 {
776 apply_builder_remove (pl, dir);
777 return;
828 { 778 }
829 object* book;
830 char buf[MAX_BUF];
831 char buf2[MAX_BUF];
832 779
833 book = get_msg_book( pl, x, y ); 780 if (builder->subtype == ST_BD_BUILD)
834 if ( !book ) 781 /*
782 * Builder.
783 * Find marked item to build, call specific function
784 */
785 {
786 tmp = tmp2;
787 if (!tmp)
835 { 788 {
836 new_draw_info( NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message." ); 789 new_draw_info (NDI_UNIQUE, 0, pl, "You need to mark raw materials to use.");
837 return -1; 790 return;
838 } 791 }
839 792
840 tmp->msg = book->msg; 793 if (tmp->type != MATERIAL)
841 add_refcount( tmp->msg );
842
843 if (tmp->invisible)
844 { 794 {
845 if(book->custom_name != NULL) 795 new_draw_info (NDI_UNIQUE, 0, pl, "You can't use the marked item to build.");
846 { 796 return;
847 snprintf(buf, sizeof(buf), "talking %s", book->custom_name);
848 } else {
849 snprintf(buf, sizeof(buf), "talking %s", book->name);
850 }
851 if ( tmp->name )
852 free_string( tmp->name );
853 tmp->name = add_string( buf );
854
855 if(book->name_pl != NULL)
856 {
857 snprintf(buf2, sizeof(buf2), "talking %s", book->name_pl);
858 if ( tmp->name_pl )
859 free_string( tmp->name_pl );
860 tmp->name_pl = add_string( buf2 );
861 }
862
863 tmp->face = book->face;
864 tmp->invisible = 0;
865 } 797 }
866 remove_ob( book ); 798
867 free_object( book ); 799 switch (tmp->subtype)
868 return 0; 800 {
801 case ST_MAT_FLOOR:
802 apply_builder_floor (pl, tmp, x, y);
803 return;
804
805 case ST_MAT_WALL:
806 apply_builder_wall (pl, tmp, x, y);
807 return;
808
809 case ST_MAT_ITEM:
810 apply_builder_item (pl, tmp, x, y);
811 return;
812
813 default:
814 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
815 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
816 return;
817 }
869 } 818 }
819
820 /* Here, it means the builder has an invalid type */
821 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
822 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
823}
824

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines