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.4 by root, Fri Sep 8 16:53:57 2006 UTC vs.
Revision 1.68 by root, Mon Oct 29 23:55:55 2012 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.4 2006/09/08 16:53:57 root Exp $";
4 */ 3 *
5/* 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
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)
44 { 45 {
45 /* 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 */
46 if ( strcmp( ob->arch->name, "rune_mark" ) && ob->type != FLOOR ) 47 if (ob->arch->archname != shstr_rune_mark && !IS_FLOOR (ob))
48 {
49 switch (tmp->type)
47 { 50 {
48 switch ( tmp->type )
49 {
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)
139 { 155 {
140 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.");
141 return -1; 157 return shstr_tmp ();
142 } 158 }
143 159
144 /* Now, find force in player's inventory */ 160 /* Now, find force in player's inventory */
145 force = pl->inv; 161 force = pl->inv;
146 while ( force && ( ( force->type != FORCE ) || ( !force->slaying ) || ( strcmp( force->slaying, pl->map->path ) ) || ( !force->msg ) || ( strcmp( force->msg, rune->msg ) ) ) ) 162 while (force
163 && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg
164 || force->msg != rune->msg))
147 force = force->below; 165 force = force->below;
148 166
149 if ( !force ) 167 if (!force)
150 /* No force, need to create & insert one */ 168 /* No force, need to create & insert one */
151 { 169 {
152 /* Find unused value */ 170 /* Find unused value */
153 connected = find_unused_connected_value( pl->map ); 171 shstr_tmp id = find_unused_connected_value (pl->map);
154 if ( connected == -1 ) 172
173 if (!id)
155 { 174 {
156 new_draw_info( NDI_UNIQUE, 0, pl, "Could not create more groups." ); 175 new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups.");
157 return -1; 176 return shstr_tmp ();
158 } 177 }
159 178
160 force = get_archetype( FORCE_NAME ); 179 force = archetype::get (FORCE_NAME);
161 force->speed = 0;
162 update_ob_speed( force );
163 force->slaying = pl->map->path; 180 force->slaying = pl->map->path;
164 force->msg = rune->msg; 181 force->msg = rune->msg;
165 force->path_attuned = connected; 182 force->race = id;
183 force->set_speed (0);
184
166 insert_ob_in_ob( force, pl ); 185 insert_ob_in_ob (force, pl);
167 186
168 return connected; 187 return id;
169 } 188 }
170 189
171 /* Found the force, everything's easy. */ 190 /* Found the force, everything's easy. */
172 return force->path_attuned; 191 return force->race;
173 } 192}
174 193
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/** 194/**
189 * 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
190 */ 196 */
191object* get_msg_book( object* pl, short x, short y ) 197static object *
192 { 198get_msg_book (object *pl, int x, int y)
193 object* book; 199{
194
195 book = GET_MAP_OB( pl->map, x, y ); 200 object *book = GET_MAP_OB (pl->map, x, y);
201
196 while ( book && ( book->type != BOOK ) ) 202 while (book && (book->type != BOOK))
197 book = book->above; 203 book = book->above;
204
198 return book; 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)
199 } 222 {
223 new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message.");
224 return -1;
225 }
200 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
201/** 258/**
202 * Returns first item of type WALL. 259 * Returns first item of type BUILDABLE_WALL.
203 */ 260 */
261static object *
204object* get_wall( mapstruct* map, int x, int y ) 262get_wall (maptile *map, int x, int y)
205 { 263{
206 object* wall;
207
208 wall = GET_MAP_OB( map, x, y ); 264 object *wall = GET_MAP_OB (map, x, y);
265
209 while ( wall && ( WALL != wall->type ) ) 266 while (wall && (BUILDABLE_WALL != wall->type))
210 wall = wall->above; 267 wall = wall->above;
211 268
212 return wall; 269 return wall;
213 } 270}
214 271
215/** 272/**
216 * Fixes walls around specified spot 273 * Fixes walls around specified spot
217 * 274 *
218 * \param map is the map 275 * \param map is the map
221 * 278 *
222 * Basically it ensures the correct wall is put where needed. 279 * Basically it ensures the correct wall is put where needed.
223 * 280 *
224 * Note: x & y must be valid map coordinates. 281 * Note: x & y must be valid map coordinates.
225 */ 282 */
283static void
226void fix_walls( mapstruct* map, int x, int y ) 284fix_walls (maptile *map, int x, int y)
227 { 285{
228 int connect;
229 object* wall;
230 char archetype[ MAX_BUF ]; 286 char archetype[MAX_BUF];
231 char* underscore; 287 char *underscore;
232 uint32 old_flags[ 4 ];
233 struct archetype* new_arch; 288 struct archetype *new_arch;
234 int flag;
235 289
236 /* First, find the wall on that spot */ 290 /* First, find the wall on that spot */
237 wall = get_wall( map, x, y ); 291 object *wall = get_wall (map, x, y);
238 if ( !wall ) 292 if (!wall)
239 /* Nothing -> bail out */ 293 /* Nothing -> bail out */
240 return; 294 return;
241 295
242 /* Find base name */ 296 /* Find base name */
243 strcpy( archetype, wall->arch->name ); 297 assign (archetype, wall->arch->archname);
244 underscore = strchr( archetype, '_' ); 298 underscore = strchr (archetype, '_');
299
300 /* search for the first _ before a number */
301 while (underscore && !isdigit (*(underscore + 1)))
302 underscore = strchr (underscore + 1, '_');
303
245 if ( !underscore || ( !isdigit( *( underscore + 1 ) ) ) ) 304 if (!underscore || !isdigit (*(underscore + 1)))
246 /* Not in a format we can change, bail out */ 305 /* Not in a format we can change, bail out */
247 return; 306 return;
248 307
249 underscore++; 308 underscore++;
250 *underscore = '\0'; 309 *underscore = '\0';
251 310
252 connect = 0; 311 int connect = 0;
253 312
254 if ( ( x > 0 ) && get_wall( map, x - 1, y ) ) 313 if (x > 0 && get_wall (map, x - 1, y)) connect |= 1;
255 connect |= 1; 314 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 ) ) 315 if (y > 0 && get_wall (map, x, y - 1)) connect |= 4;
257 connect |= 2; 316 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
258 317
259 if ( ( y > 0 ) && get_wall( map, x, y - 1 ) ) 318 strcat (archetype, wall_suffix [connect]);
260 connect |= 4;
261 319
262 if ( ( y < MAP_HEIGHT( map ) - 1 ) && get_wall( map, x, y + 1 ) )
263 connect |= 8;
264
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 /* 320 /*
318 * Before anything, make sure the archetype does exist... 321 * Before anything, make sure the archetype does exist...
319 * If not, prolly an error... 322 * If not, prolly an error...
320 */ 323 */
321 new_arch = find_archetype( archetype ); 324 new_arch = archetype::find (archetype);
325
322 if ( !new_arch ) 326 if (!new_arch)
323 return; 327 return;
324 328
325 /* Now delete current wall, and insert new one 329 /* Now delete current wall, and insert new one
326 * 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
327 */ 331 */
328 for ( flag = 0; flag < 4; flag++ ) 332 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 333
333 wall = arch_to_object( new_arch ); 334 wall->destroy ();
335
336 wall = new_arch->instance ();
334 wall->type = WALL; 337 wall->type = BUILDABLE_WALL;
335 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);
336 for ( flag = 0; flag < 4; flag++ ) 339 wall->flag = old_flags;
337 wall->flags[ flag ] = old_flags[ flag ]; 340}
338 }
339 341
340/** 342/**
341 * \brief Floor building function 343 * \brief Floor building function
342 * 344 *
343 * Floors can be build: 345 * Floors can be build:
345 * - on an existing wall, with or without a floor under it 347 * - on an existing wall, with or without a floor under it
346 * 348 *
347 * Note: this function will inconditionally change squares around (x, y) 349 * Note: this function will inconditionally change squares around (x, y)
348 * so don't call it with x == 0 for instance! 350 * so don't call it with x == 0 for instance!
349 */ 351 */
352static void
350void apply_builder_floor(object* pl, object* material, short x, short y ) 353apply_builder_floor (object *pl, object *material, int x, int y)
351 { 354{
352 object* tmp, *above; 355 object *tmp, *above;
353 object* above_floor; /* Item above floor, if any */ 356 object *above_floor; /* Item above floor, if any */
354 struct archetype* new_floor; 357 struct archetype *new_floor;
355 struct archetype* new_wall; 358 struct archetype *new_wall;
356 int i, xt, yt, floor_removed; 359 int i, xt, yt, floor_removed;
357 char message[ MAX_BUF ]; 360 char message[MAX_BUF];
358 361
359 sprintf( message, "You change the floor to better suit your tastes." ); 362 sprintf (message, "You change the floor to better suit your tastes.");
360 363
361 /* 364 /*
362 * Now the building part... 365 * Now the building part...
363 * First, remove wall(s) and floor(s) at position x, y 366 * First, remove wall(s) and floor(s) at position x, y
364 */ 367 */
365 above_floor = NULL; 368 above_floor = NULL;
366 new_wall = NULL; 369 new_wall = NULL;
367 floor_removed = 0; 370 floor_removed = 0;
368 tmp = GET_MAP_OB( pl->map, x, y ); 371 tmp = GET_MAP_OB (pl->map, x, y);
369 if ( tmp ) 372 if (tmp)
370 { 373 {
371 while ( tmp ) 374 while (tmp)
375 {
376 above = tmp->above;
377 if (BUILDABLE_WALL == tmp->type)
372 { 378 {
373 above = tmp->above; 379 /* There was a wall, remove it & keep its archetype to make new walls */
374 if ( WALL == tmp->type ) 380 new_wall = tmp->arch;
381 tmp->destroy ();
382 sprintf (message, "You destroy the wall and redo the floor.");
383 }
384 else if (IS_FLOOR (tmp))
385 {
386 tmp->destroy ();
387 floor_removed = 1;
388 }
389 else
390 {
391 if (floor_removed)
375 { 392 {
376 /* There was a wall, remove it & keep its archetype to make new walls */ 393 /* This is the first item that was above the floor */
377 new_wall = tmp->arch;
378 remove_ob( tmp );
379 free_object( tmp );
380 sprintf( message, "You destroy the wall and redo the floor." );
381 }
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 }
388 else
389 {
390 if ( floor_removed )
391 above_floor = tmp; 394 above_floor = tmp;
392 } 395 floor_removed = 0;
393
394 tmp = above;
395 }
396 }
397
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 } 396 }
440 } 397 }
398
399 tmp = above;
400 }
401 }
402
403 /* Now insert our floor */
404 new_floor = archetype::find (material->slaying);
405 if (!new_floor)
406 {
407 /* Not found, log & bail out */
408 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
409 return;
410 }
411
412 tmp = new_floor->instance ();
413 tmp->set_flag (FLAG_IS_BUILDABLE);
414 tmp->set_flag (FLAG_UNIQUE);
415 tmp->set_flag (FLAG_IS_FLOOR);
416 //tmp->type = FLOOR;
417 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
418
419 /*
420 * Next step: make sure there are either walls or floors around the new square
421 * Since building, you can have: blocking view / floor / wall / nothing
422 */
423 for (i = 1; i <= 8; i++)
424 {
425 xt = x + freearr_x[i];
426 yt = y + freearr_y[i];
427 tmp = GET_MAP_OB (pl->map, xt, yt);
428 if (!tmp)
441 } 429 {
442 430 /* Must insert floor & wall */
443 /* Finally fixing walls to ensure nice continuous walls 431 tmp = new_floor->instance ();
444 * Note: 2 squares around are checked, because potentially we added walls around the building 432 /* Better make the floor unique */
445 * spot, so need to check that those new walls connect correctly 433 tmp->set_flag (FLAG_UNIQUE);
446 */ 434 tmp->set_flag (FLAG_IS_BUILDABLE);
447 for ( xt = x - 2; xt <= x + 2; xt++ ) 435 //tmp->type = FLOOR;
448 for ( yt = y - 2; yt <= y + 2; yt++ ) 436 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
437 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
438 if (new_wall)
449 { 439 {
450 if ( !OUT_OF_REAL_MAP( pl->map, xt, yt ) ) 440 tmp = new_wall->instance ();
451 fix_walls( pl->map, xt, yt ); 441 tmp->set_flag (FLAG_IS_BUILDABLE);
442 tmp->type = BUILDABLE_WALL;
443 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
452 } 444 }
445 }
446 }
453 447
448 /* Finally fixing walls to ensure nice continuous walls
449 * Note: 2 squares around are checked, because potentially we added walls around the building
450 * spot, so need to check that those new walls connect correctly
451 */
452 for (xt = x - 2; xt <= x + 2; xt++)
453 for (yt = y - 2; yt <= y + 2; yt++)
454 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
455 fix_walls (pl->map, xt, yt);
456
454 /* Now remove raw item from inventory */ 457 /* Now remove raw item from inventory */
455 decrease_ob( material ); 458 material->decrease ();
456 459
457 /* And tell player about the fix */ 460 /* And tell player about the fix */
458 new_draw_info( NDI_UNIQUE, 0, pl, message ); 461 new_draw_info (NDI_UNIQUE, 0, pl, message);
459 } 462}
460 463
461/** 464/**
462 * Wall building function 465 * Wall building function
463 * 466 *
464 * Walls can be build: 467 * Walls can be build:
465 * - on a floor without anything else 468 * - on a floor without anything else
466 * - on an existing wall, with or without a floor 469 * - on an existing wall, with or without a floor
467 */ 470 */
471static void
468void apply_builder_wall( object* pl, object* material, short x, short y ) 472apply_builder_wall (object *pl, object *material, int x, int y)
469 { 473{
470 object* current_wall; 474 object *current_wall;
471 object* tmp; 475 object *tmp;
472 int xt, yt; 476 int xt, yt;
473 struct archetype* new_wall; 477 struct archetype *new_wall;
474 char message[ MAX_BUF ]; 478 char message[MAX_BUF];
475 479
476 remove_marking_runes( pl->map, x, y ); 480 remove_marking_runes (pl->map, x, y);
477 481
478 /* Grab existing wall, if any */ 482 /* Grab existing wall, if any */
479 current_wall = NULL; 483 current_wall = NULL;
480 tmp = GET_MAP_OB( pl->map, x, y ); 484 tmp = GET_MAP_OB (pl->map, x, y);
481 while ( tmp && !current_wall ) 485 while (tmp && !current_wall)
482 { 486 {
483 if ( WALL == tmp->type ) 487 if (BUILDABLE_WALL == tmp->type)
484 current_wall = tmp; 488 current_wall = tmp;
485 489
486 tmp = tmp->above; 490 tmp = tmp->above;
487 } 491 }
488 492
489 /* Find the raw wall in inventory */ 493 /* Find the raw wall in inventory */
490 sprintf( message, "You build a wall." ); 494 sprintf (message, "You build a wall.");
491 495
492 /* Now we can actually insert the wall */ 496 /* Now we can actually insert the wall */
493 new_wall = find_archetype( material->slaying ); 497 new_wall = archetype::find (material->slaying);
494 if ( !new_wall ) 498 if (!new_wall)
495 { 499 {
496 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);
497 return; 501 return;
498 } 502 }
499 503
500 tmp = arch_to_object( new_wall ); 504 tmp = new_wall->instance ();
501 tmp->type = WALL; 505 tmp->type = BUILDABLE_WALL;
502 SET_FLAG( tmp, FLAG_IS_BUILDABLE ); 506 tmp->set_flag (FLAG_IS_BUILDABLE);
503 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);
504 508
505 /* If existing wall, remove it, no need to fix other walls */ 509 /* If existing wall, remove it, no need to fix other walls */
506 if ( current_wall ) 510 if (current_wall)
507 { 511 {
508 remove_ob( current_wall ); 512 current_wall->destroy ();
509 free_object( current_wall );
510 fix_walls( pl->map, x, y ); 513 fix_walls (pl->map, x, y);
511 sprintf( message, "You redecorate the wall to better suit your tastes." ); 514 sprintf (message, "You redecorate the wall to better suit your tastes.");
512 } 515 }
513 else 516 else
514 { 517 {
515 /* Else fix all walls around */ 518 /* Else fix all walls around */
516 for ( xt = x - 1; xt <= x + 1; xt++ ) 519 for (xt = x - 1; xt <= x + 1; xt++)
517 for ( yt = y - 1; yt <= y + 1; yt++ ) 520 for (yt = y - 1; yt <= y + 1; yt++)
518 { 521 {
519 if ( OUT_OF_REAL_MAP( pl->map, xt, yt ) ) 522 if (OUT_OF_REAL_MAP (pl->map, xt, yt))
520 continue; 523 continue;
521 524
522 fix_walls( pl->map, xt, yt ); 525 fix_walls (pl->map, xt, yt);
523 }
524 } 526 }
527 }
525 528
526 /* Now remove item from inventory */ 529 /* Now remove item from inventory */
527 decrease_ob( material ); 530 material->decrease ();
528 531
529 /* And tell player what happened */ 532 /* And tell player what happened */
530 new_draw_info( NDI_UNIQUE, 0, pl, message ); 533 new_draw_info (NDI_UNIQUE, 0, pl, message);
531 } 534}
532 535
533/** 536/**
534 * Generic item builder. 537 * Generic item builder.
535 * 538 *
536 * 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.
537 * Archetype of created object is item->slaying (raw material). 540 * Archetype of created object is item->slaying (raw material).
538 * Type of inserted item is tested for specific cases (doors & such). 541 * 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) 542 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
540 */ 543 */
544static void
541void apply_builder_item( object* pl, object* item, short x, short y ) 545apply_builder_item (object *pl, object *item, int x, int y)
542 { 546{
543 object* tmp; 547 object *tmp;
544 struct archetype* arch; 548 struct archetype *arch;
545 int insert_flag; 549 int insert_flag;
546 object* floor; 550 object *floor;
547 object* con_rune; 551 object *con_rune;
548 int connected;
549 552
550 /* Find floor */ 553 /* Find floor */
551 floor = GET_MAP_OB( pl->map, x, y ); 554 floor = GET_MAP_OB (pl->map, x, y);
552 if ( !floor ) 555 if (!floor)
553 { 556 {
554 new_draw_info( NDI_UNIQUE, 0, pl, "Invalid square." ); 557 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
558 return;
559 }
560
561 while (floor && !IS_FLOOR (floor))
562 floor = floor->above;
563
564 if (!floor)
565 {
566 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
567 return;
568 }
569 /* Create item, set flag, insert in map */
570 arch = archetype::find (item->slaying);
571 if (!arch)
572 return;
573
574 tmp = arch->instance ();
575
576 if (!floor->flag[FLAG_IS_BUILDABLE] || floor->above && !can_build_over (pl->map, tmp, x, y))
577 /* Floor has something on top that interferes with building */
578 {
579 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
580 return;
581 }
582
583 tmp->set_flag (FLAG_IS_BUILDABLE);
584 tmp->set_flag (FLAG_NO_PICK);
585
586 /*
587 * Str 1 is a flag that the item [pedestal] should go below the floor.
588 * Items under the floor on non-unique maps will not be saved,
589 * so make the item itself unique in this situation.
590 */
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);
594
595 shstr_tmp connected;
596
597 switch (tmp->type)
598 {
599 case DOOR:
600 case GATE:
601 case BUTTON:
602 case DETECTOR:
603 case TIMED_GATE:
604 case PEDESTAL:
605 case T_HANDLE:
606 case MAGIC_EAR:
607 case SIGN:
608 /* Signs don't need a connection, but but magic mouths do. */
609 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
610 break;
611
612 con_rune = get_connection_rune (pl, x, y);
613 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
614 if (!connected)
615 {
616 /* Player already informed of failure by the previous function */
617 tmp->destroy ();
618 return;
619 }
620
621 /* Remove marking rune */
622 con_rune->destroy ();
623 }
624
625 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
626 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
627 if (adjust_sign_msg (pl, x, y, tmp) == -1)
628 {
629 tmp->destroy ();
555 return; 630 return;
631 }
632
633 insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y);
634 if (connected)
635 tmp->add_link (pl->map, connected);
636
637 new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp));
638 item->decrease ();
639}
640
641/**
642 * Item remover.
643 *
644 * Removes first buildable item, either under or above the floor
645 */
646static void
647apply_builder_remove (object *pl, int dir)
648{
649 object *item;
650 int x, y;
651
652 x = pl->x + freearr_x[dir];
653 y = pl->y + freearr_y[dir];
654
655 /* Check square */
656 item = GET_MAP_OB (pl->map, x, y);
657 if (!item)
658 {
659 /* Should not happen with previous tests, but we never know */
660 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
661 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
662 return;
663 }
664
665 if (IS_FLOOR (item))
666 item = item->above;
667
668 if (!item)
669 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
670 else if (item->type == BUILDABLE_WALL)
671 new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor.");
672 else if (!item->flag [FLAG_IS_BUILDABLE])
673 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item));
674 else
675 {
676 new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item));
677 item->destroy ();
678 }
679}
680
681
682static void
683replace_open_space_floor (object *os, object *material)
684{
685 object *new_floor = archetype::get (material->slaying);
686 insert_ob_in_map_at (new_floor, os->map, os,
687 INS_BELOW_ORIGINATOR, os->x, os->y);
688 os->destroy ();
689 material->decrease ();
690}
691
692/**
693 * Quad building.
694 */
695void
696apply_builder_quad (object *pl, object *material, mapxy &pos)
697{
698 object *open_space = 0;
699 object *floor = 0;
700
701 object *tmp = pos.ms ().bot;
702 bool floor_exists = false;
703 while (tmp)
704 {
705 if (floor_exists && tmp->flag [FLAG_IS_QUAD])
556 } 706 {
557 707 pl->failmsg (
558 while ( floor && ( floor->type != FLOOR ) && ( !QUERY_FLAG( floor, FLAG_IS_FLOOR ) ) ) 708 "You can't build there, there is a block in the way.");
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; 709 return;
710 }
711
712 if (IS_FLOOR (tmp))
565 } 713 {
566 /* Create item, set flag, insert in map */ 714 floor = tmp;
567 arch = find_archetype( item->slaying ); 715 floor_exists = true;
568 if ( !arch ) 716
717 if (floor->arch->archname == shstr_quad_open_space)
718 {
719 open_space = floor;
720 }
721 else if (!floor->flag [FLAG_IS_QUAD])
722 {
723 pl->failmsg (
724 "You can't build there, the floor is not suited.");
725 return;
726 }
727 }
728
729 tmp = tmp->above;
730 }
731
732 if (open_space)
733 {
734 if (!material->slaying)
735 {
736 pl->failmsg (
737 "The floor is open and you can't fill it with that material."
738 "H<Use another material to fill the ceiling.>");
569 return; 739 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 { 740 }
576 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build here." ); 741
742 replace_open_space_floor (open_space, material);
743 pl->contr->fire_on = 0; // TODO: stopgap, do not add more than one per keypress
744 return;
745 }
746 else if (floor)
747 {
748
749 maptile *upper_floor = pos.m->tile_available (TILE_UP);
750 if (!upper_floor)
751 {
752 pl->failmsg (
753 "Whoops, you can't see the ceiling.. H<You may try again.>");
577 return; 754 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 { 755 }
592 case DOOR: 756
593 case GATE: 757 mapxy above_pos (upper_floor, pos.x, pos.y);
594 case BUTTON: 758 if (!above_pos.normalise ())
595 case DETECTOR: 759 {
596 case TIMED_GATE: 760 pl->failmsg (
597 case PEDESTAL: 761 "Whoops, you can't access the ceiling. H<You may try again.>");
598 case CF_HANDLE: 762 return;
599 case MAGIC_EAR: 763 }
600 case SIGN: 764
601 /* Signs don't need a connection, but but magic mouths do. */ 765 mapspace &above_ms = above_pos.ms ();
602 if (tmp->type == SIGN && strcmp( tmp->arch->name, "magic_mouth" )) 766 for (object *quad_obj = above_ms.top; quad_obj; quad_obj = quad_obj->below)
603 break; 767 {
604 con_rune = get_connection_rune( pl, x, y ); 768 if (quad_obj->arch->archname == shstr_quad_open_space)
605 connected = find_or_create_connection_for_map( pl, x, y, con_rune ); 769 {
606 if ( connected == -1 ) 770 if (!material->slaying)
607 { 771 {
608 /* Player already informed of failure by the previous function */ 772 pl->failmsg (
609 free_object( tmp ); 773 "The ceiling is open and you can't fill it with that material."
774 "H<Use another material to fill the ceiling.>");
610 return; 775 return;
611 } 776 }
612 /* Remove marking rune */ 777
613 remove_ob( con_rune ); 778 replace_open_space_floor (quad_obj, material);
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; 779 break;
624 } 780 }
625 } 781 }
626 782
627 insert_ob_in_map_at( tmp, pl->map, floor, insert_flag, x, y ); 783 if (material->destroyed ())
628 if ( connected != 0 )
629 add_button_link( tmp, pl->map, connected );
630
631 new_draw_info_format( NDI_UNIQUE, 0, pl, "You build the %s", query_name( tmp ) );
632 decrease_ob_nr( item, 1 );
633 }
634
635/**
636 * Item remover.
637 *
638 * Removes first buildable item, either under or above the floor
639 */
640void apply_builder_remove( object* pl, int dir )
641 {
642 object* item;
643 short x, y;
644
645 x = pl->x + freearr_x[ dir ];
646 y = pl->y + freearr_y[ dir ];
647
648 /* Check square */
649 item = GET_MAP_OB( pl->map, x, y );
650 if ( !item )
651 {
652 /* Should not happen with previous tests, but we never know */
653 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 );
655 return;
656 } 784 {
657 785 pl->failmsg (
658 if ( item->type == FLOOR || QUERY_FLAG(item,FLAG_IS_FLOOR) ) 786 "You don't have enough build material to build a wall here.");
659 item = item->above;
660
661 if ( !item )
662 {
663 new_draw_info( NDI_UNIQUE, 0, pl, "Nothing to remove." );
664 return;
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." );
672 return; 787 return;
673
674 case DOOR:
675 case BUTTON:
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 ) );
692 remove_ob( item );
693 free_object( item );
694 } 788 }
789
790 object *quad_wall = material->other_arch->instance ();
791 material->decrease ();
792
793 insert_ob_in_map_at (quad_wall, floor->map, 0,
794 INS_ABOVE_FLOOR_ONLY, floor->x, floor->y);
795 }
796 else
695 } 797 {
798 pl->failmsg ("You can't build a quad block here.");
799 }
800}
696 801
697/** 802/**
698 * Global building function 803 * Global building function
699 * 804 *
700 * This is the general map building function. Called when the player 'fires' a builder 805 * This is the general map building function. Called when the player 'fires' a builder
701 * or remover object. 806 * or remover object.
702 */ 807 */
808void
703void apply_map_builder( object* pl, int dir ) 809apply_map_builder (object *pl, int dir)
704 { 810{
705 object* builder;
706 object* tmp;
707 object* tmp2;
708 short x, y;
709
710 if ( !pl->type == PLAYER ) 811 if (!pl->type == PLAYER)
812 return;
813
814 if (dir == 0)
815 {
816 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself.");
817 return;
818 }
819
820 mapxy pos (pl); pos.move (dir);
821
822 if (!pos.normalise ())
823 {
824 pl->failmsg ("You can't build here. H<There is nothing in this direction.>");
825 return;
826 }
827
828 /*
829 * Check specified square
830 * The square must have only buildable items
831 * Exception: marking runes are all right,
832 * since they are used for special things like connecting doors / buttons
833 */
834
835 object *builder = pl->contr->ranged_ob;
836
837 object *tmp2 = pl->mark ();
838
839 object *tmp = 0;
840 for (tmp = pos.ms ().bot; tmp; tmp = tmp->above)
841 {
842 if (!tmp->flag [FLAG_IS_BUILDABLE]
843 && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
844 {
845 /* The item building function already has it's own special
846 * checks for this. And so does the quad building function.
847 */
848 if (!tmp2 || (tmp2->subtype != ST_MAT_ITEM && tmp2->subtype != ST_MAT_QUAD))
849 {
850 if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
851 ARG_MAP (pl->map),
852 ARG_INT (pos.y), ARG_INT (pos.y),
853 ARG_INT (0)))
854 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
855
856 return;
857 }
858 }
859 }
860
861 /* Now we know the square is ok */
862 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder),
863 ARG_MAP (pl->map), ARG_INT (pos.x), ARG_INT (pos.y), ARG_INT (1)))
864 return;
865
866 if (builder->subtype == ST_BD_REMOVE)
867 /* Remover -> call specific function and bail out */
868 {
869 apply_builder_remove (pl, dir);
870 return;
871 }
872
873 if (builder->subtype == ST_BD_BUILD)
874 /*
875 * Builder.
876 * Find marked item to build, call specific function
877 */
878 {
879 tmp = tmp2;
880 if (!tmp)
881 {
882 new_draw_info (NDI_UNIQUE, 0, pl, "You need to mark raw materials to use.");
711 return; 883 return;
712
713 /*if ( !player->map->unique )
714 { 884 }
715 new_draw_info( NDI_UNIQUE, 0, player, "You can't build outside a unique map." ); 885
886 if (tmp->type != MATERIAL)
887 {
888 new_draw_info (NDI_UNIQUE, 0, pl, "You can't use the marked item to build.");
889 return;
890 }
891
892 switch (tmp->subtype)
893 {
894 case ST_MAT_FLOOR:
895 apply_builder_floor (pl, tmp, pos.x, pos.y);
716 return; 896 return;
717 }*/
718 897
719 if ( dir == 0 ) 898 case ST_MAT_WALL:
720 { 899 apply_builder_wall (pl, tmp, pos.x, pos.y);
721 new_draw_info( NDI_UNIQUE, 0, pl, "You can't build or destroy under yourself." );
722 return; 900 return;
723 }
724 901
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 {
755 /* The item building function already has it's own special
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." );
761 return;
762 }
763 }
764 tmp = tmp->above;
765 }
766
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;
801
802 case ST_MAT_WALL:
803 apply_builder_wall( pl, tmp, x, y );
804 return;
805
806 case ST_MAT_ITEM: 902 case ST_MAT_ITEM:
807 apply_builder_item( pl, tmp, x, y ); 903 apply_builder_item (pl, tmp, pos.x, pos.y);
808 return; 904 return;
809 905
906 case ST_MAT_QUAD:
907 apply_builder_quad (pl, tmp, pos);
908 return;
909
810 default: 910 default:
811 new_draw_info( NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry." ); 911 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
812 LOG( llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype ); 912 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
813 return; 913 return;
814 } 914 }
815 } 915 }
816 916
817 /* Here, it means the builder has an invalid type */ 917 /* Here, it means the builder has an invalid type */
818 new_draw_info( NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry." ); 918 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry.");
819 LOG( llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype ); 919 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
820 } 920}
821
822/**
823 * Make the built object inherit the msg of books that are used with it.
824 * For objects already invisible (i.e. magic mouths & ears), also make it
825 * it inherit the face and the name with "talking " prepended.
826 */
827int adjust_sign_msg( object* pl, short x, short y, object* tmp )
828 {
829 object* book;
830 char buf[MAX_BUF];
831 char buf2[MAX_BUF];
832 921
833 book = get_msg_book( pl, x, y );
834 if ( !book )
835 {
836 new_draw_info( NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message." );
837 return -1;
838 }
839
840 tmp->msg = book->msg;
841
842 if (tmp->invisible)
843 {
844 if(book->custom_name != NULL)
845 {
846 snprintf(buf, sizeof(buf), "talking %s", &book->custom_name);
847 } else {
848 snprintf(buf, sizeof(buf), "talking %s", &book->name);
849 }
850 tmp->name = buf;
851
852 if (book->name_pl != NULL)
853 {
854 snprintf(buf2, sizeof(buf2), "talking %s", &book->name_pl);
855 tmp->name_pl = buf2;
856 }
857
858 tmp->face = book->face;
859 tmp->invisible = 0;
860 }
861 remove_ob( book );
862 free_object( book );
863 return 0;
864 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines