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.57 by elmex, Tue Apr 13 18:10:54 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,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * 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>
27#include <skills.h> 28#include <skills.h>
28#include <tod.h> 29#include <tod.h>
29#include <sproto.h> 30#include <sproto.h>
30 31
32// macro for this check, it had been inconsistent in this file.
33#define IS_FLOOR(x) x->flag [FLAG_IS_FLOOR]
34
31/** 35/**
32 * Check if objects on a square interfere with building 36 * Check if objects on a square interfere with building
33 */ 37 */
34int 38static int
35can_build_over (maptile *map, object *tmp, short x, short y) 39can_build_over (maptile *map, object *tmp, int x, int y)
36{ 40{
37 object *ob; 41 object *ob;
38 42
39 ob = GET_MAP_OB (map, x, y); 43 ob = GET_MAP_OB (map, x, y);
40 while (ob) 44 while (ob)
41 { 45 {
42 /* if ob is not a marking rune or floor, then check special cases */ 46 /* if ob is not a marking rune or floor, then check special cases */
43 if (strcmp (ob->arch->archname, "rune_mark") && ob->type != FLOOR) 47 if (ob->arch->archname != shstr_rune_mark && !IS_FLOOR (ob))
44 { 48 {
45 switch (tmp->type) 49 switch (tmp->type)
46 { 50 {
47 case SIGN: 51 case SIGN:
48 case MAGIC_EAR: 52 case MAGIC_EAR:
49 /* Allow signs and magic ears to be built on books */ 53 /* Allow signs and magic ears to be built on books */
50 if (ob->type != BOOK) 54 if (ob->type != BOOK)
51 {
52 return 0;
53 }
54 break;
55 case BUTTON:
56 case DETECTOR:
57 case PEDESTAL:
58 case CF_HANDLE:
59 /* Allow buttons and levers to be built under gates */
60 if (ob->type != GATE && ob->type != DOOR)
61 {
62 return 0;
63 }
64 break;
65 default:
66 return 0; 55 return 0;
56 break;
57 case BUTTON:
58 case DETECTOR:
59 case PEDESTAL:
60 case T_HANDLE:
61 /* Allow buttons and levers to be built under gates */
62 if (ob->type != GATE && ob->type != DOOR)
63 return 0;
64 break;
65 default:
66 return 0;
67 } 67 }
68 } 68 }
69
69 ob = ob->above; 70 ob = ob->above;
70 } 71 }
72
71 return 1; 73 return 1;
72} 74}
73 75
74/** 76/**
75 * Erases marking runes at specified location 77 * Erases marking runes at specified location
76 */ 78 */
77void 79static void
78remove_marking_runes (maptile *map, short x, short y) 80remove_marking_runes (maptile *map, int x, int y)
79{ 81{
80 object *rune; 82 object *rune;
81 object *next; 83 object *next;
82 84
83 rune = GET_MAP_OB (map, x, y); 85 rune = GET_MAP_OB (map, x, y);
84 while (rune) 86 while (rune)
85 { 87 {
86 next = rune->above; 88 next = rune->above;
87 89
88 if ((rune->type == SIGN) && (!strcmp (rune->arch->archname, "rune_mark"))) 90 if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark)
89 rune->destroy (); 91 rune->destroy ();
90 92
91 rune = next; 93 rune = next;
92 } 94 }
93} 95}
97 * \param map: map for which to find a value 99 * \param map: map for which to find a value
98 * \return 'connected' value with no item, or -1 if failure. 100 * \return 'connected' value with no item, or -1 if failure.
99 * 101 *
100 * Tries 1000 random values, then returns -1. 102 * Tries 1000 random values, then returns -1.
101 */ 103 */
102int 104static shstr_tmp
103find_unused_connected_value (maptile *map) 105find_unused_connected_value (maptile *map)
104{ 106{
105 int connected = 0; 107 for (int i = 1000; --i; )
106 int itest = 0;
107 oblinkpt *obp;
108
109 while (itest++ < 1000)
110 {
111 connected = 1 + rand () % 20000;
112 for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next);
113
114 if (!obp)
115 return connected;
116 } 108 {
109 char buf[64];
117 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
118 return -1; 133 return rune;
119} 134}
120
121 135
122/** 136/**
123 * Helper function for door/button/connected item building. 137 * Helper function for door/button/connected item building.
124 * 138 *
125 * Will search the specified spot for a marking rune. 139 * Will search the specified spot for a marking rune.
127 * 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
128 * and the rune's text. 142 * and the rune's text.
129 * If found, returns the connection value associated 143 * If found, returns the connection value associated
130 * 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.
131 */ 145 */
132int 146static shstr_tmp
133find_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)
134{ 148{
135 object *force; 149 object *force;
136 int connected;
137 150
138 if (!rune) 151 if (!rune)
139 rune = get_connection_rune (pl, x, y); 152 rune = get_connection_rune (pl, x, y);
140 153
141 if (!rune) 154 if (!rune)
142 { 155 {
143 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.");
144 return -1; 157 return shstr_tmp ();
145 } 158 }
146 159
147 /* Now, find force in player's inventory */ 160 /* Now, find force in player's inventory */
148 force = pl->inv; 161 force = pl->inv;
149 while (force 162 while (force
153 166
154 if (!force) 167 if (!force)
155 /* No force, need to create & insert one */ 168 /* No force, need to create & insert one */
156 { 169 {
157 /* Find unused value */ 170 /* Find unused value */
158 connected = find_unused_connected_value (pl->map); 171 shstr_tmp id = find_unused_connected_value (pl->map);
159 if (connected == -1) 172
173 if (!id)
160 { 174 {
161 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.");
162 return -1; 176 return shstr_tmp ();
163 } 177 }
164 178
165 force = get_archetype (FORCE_NAME); 179 force = get_archetype (FORCE_NAME);
166 force->slaying = pl->map->path; 180 force->slaying = pl->map->path;
167 force->msg = rune->msg; 181 force->msg = rune->msg;
168 force->path_attuned = connected; 182 force->race = id;
169 force->set_speed (0); 183 force->set_speed (0);
184
170 insert_ob_in_ob (force, pl); 185 insert_ob_in_ob (force, pl);
171 186
172 return connected; 187 return id;
173 } 188 }
174 189
175 /* Found the force, everything's easy. */ 190 /* Found the force, everything's easy. */
176 return force->path_attuned; 191 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} 192}
192 193
193/** 194/**
194 * 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
195 */ 196 */
196object * 197static object *
197get_msg_book (object *pl, short x, short y) 198get_msg_book (object *pl, int x, int y)
198{ 199{
199 object *book;
200
201 book = GET_MAP_OB (pl->map, x, y); 200 object *book = GET_MAP_OB (pl->map, x, y);
201
202 while (book && (book->type != BOOK)) 202 while (book && (book->type != BOOK))
203 book = book->above; 203 book = book->above;
204
204 return book; 205 return book;
205} 206}
206 207
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)
239 {
240 snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl);
241 tmp->name_pl = buf2;
242 }
243
244 tmp->face = book->face;
245 tmp->invisible = 0;
246 }
247
248 book->destroy ();
249 return 0;
250}
251
252/**
208 * Returns first item of type BUILDABLE_WALL. 253 * Returns first item of type BUILDABLE_WALL.
209 */ 254 */
210object * 255static object *
211get_wall (maptile *map, int x, int y) 256get_wall (maptile *map, int x, int y)
212{ 257{
213 object *wall;
214
215 wall = GET_MAP_OB (map, x, y); 258 object *wall = GET_MAP_OB (map, x, y);
259
216 while (wall && (BUILDABLE_WALL != wall->type)) 260 while (wall && (BUILDABLE_WALL != wall->type))
217 wall = wall->above; 261 wall = wall->above;
218 262
219 return wall; 263 return wall;
220} 264}
228 * 272 *
229 * Basically it ensures the correct wall is put where needed. 273 * Basically it ensures the correct wall is put where needed.
230 * 274 *
231 * Note: x & y must be valid map coordinates. 275 * Note: x & y must be valid map coordinates.
232 */ 276 */
233void 277static void
234fix_walls (maptile *map, int x, int y) 278fix_walls (maptile *map, int x, int y)
235{ 279{
236 object *wall;
237 char archetype[MAX_BUF]; 280 char archetype[MAX_BUF];
238 char *underscore; 281 char *underscore;
239 struct archetype *new_arch; 282 struct archetype *new_arch;
240 283
241
242 /* First, find the wall on that spot */ 284 /* First, find the wall on that spot */
243 wall = get_wall (map, x, y); 285 object *wall = get_wall (map, x, y);
244 if (!wall) 286 if (!wall)
245 /* Nothing -> bail out */ 287 /* Nothing -> bail out */
246 return; 288 return;
247 289
248 /* Find base name */ 290 /* Find base name */
260 underscore++; 302 underscore++;
261 *underscore = '\0'; 303 *underscore = '\0';
262 304
263 int connect = 0; 305 int connect = 0;
264 306
265 if ((x > 0) && get_wall (map, x - 1, y)) 307 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)) 308 if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2;
268 connect |= 2; 309 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)) 310 if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8;
274 connect |= 8;
275 311
276 switch (connect) 312 // one bit per dir, 1 left, 2 right, 4 up, 8 down
277 { 313 static const char *walltype[16] = {
278 case 0: 314 "0",
279 strcat (archetype, "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 };
280 331
281 break; 332 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 333
344 /* 334 /*
345 * Before anything, make sure the archetype does exist... 335 * Before anything, make sure the archetype does exist...
346 * If not, prolly an error... 336 * If not, prolly an error...
347 */ 337 */
355 */ 345 */
356 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off 346 object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off
357 347
358 wall->destroy (); 348 wall->destroy ();
359 349
360 wall = arch_to_object (new_arch); 350 wall = new_arch->instance ();
361 wall->type = BUILDABLE_WALL; 351 wall->type = BUILDABLE_WALL;
362 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);
363 wall->flag = old_flags; 353 wall->flag = old_flags;
364} 354}
365 355
371 * - on an existing wall, with or without a floor under it 361 * - on an existing wall, with or without a floor under it
372 * 362 *
373 * Note: this function will inconditionally change squares around (x, y) 363 * Note: this function will inconditionally change squares around (x, y)
374 * so don't call it with x == 0 for instance! 364 * so don't call it with x == 0 for instance!
375 */ 365 */
376void 366static void
377apply_builder_floor (object *pl, object *material, short x, short y) 367apply_builder_floor (object *pl, object *material, int x, int y)
378{ 368{
379 object *tmp, *above; 369 object *tmp, *above;
380 object *above_floor; /* Item above floor, if any */ 370 object *above_floor; /* Item above floor, if any */
381 struct archetype *new_floor; 371 struct archetype *new_floor;
382 struct archetype *new_wall; 372 struct archetype *new_wall;
403 /* There was a wall, remove it & keep its archetype to make new walls */ 393 /* There was a wall, remove it & keep its archetype to make new walls */
404 new_wall = tmp->arch; 394 new_wall = tmp->arch;
405 tmp->destroy (); 395 tmp->destroy ();
406 sprintf (message, "You destroy the wall and redo the floor."); 396 sprintf (message, "You destroy the wall and redo the floor.");
407 } 397 }
408 else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) 398 else if (IS_FLOOR (tmp))
409 { 399 {
410 tmp->destroy (); 400 tmp->destroy ();
411 floor_removed = 1; 401 floor_removed = 1;
412 } 402 }
413 else 403 else
414 { 404 {
415 if (floor_removed) 405 if (floor_removed)
406 {
407 /* This is the first item that was above the floor */
416 above_floor = tmp; 408 above_floor = tmp;
409 floor_removed = 0;
410 }
417 } 411 }
418 412
419 tmp = above; 413 tmp = above;
420 } 414 }
421 } 415 }
427 /* Not found, log & bail out */ 421 /* Not found, log & bail out */
428 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying); 422 LOG (llevError, "apply_builder_floor: unable to find archetype %s.\n", &material->slaying);
429 return; 423 return;
430 } 424 }
431 425
432 tmp = arch_to_object (new_floor); 426 tmp = new_floor->instance ();
433 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 427 tmp->set_flag (FLAG_IS_BUILDABLE);
434 SET_FLAG (tmp, FLAG_UNIQUE); 428 tmp->set_flag (FLAG_UNIQUE);
435 SET_FLAG (tmp, FLAG_IS_FLOOR); 429 tmp->set_flag (FLAG_IS_FLOOR);
436 tmp->type = FLOOR; 430 //tmp->type = FLOOR;
437 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y); 431 insert_ob_in_map_at (tmp, pl->map, above_floor, above_floor ? INS_BELOW_ORIGINATOR : INS_ON_TOP, x, y);
438 432
439 /* 433 /*
440 * Next step: make sure there are either walls or floors around the new square 434 * Next step: make sure there are either walls or floors around the new square
441 * Since building, you can have: blocking view / floor / wall / nothing 435 * Since building, you can have: blocking view / floor / wall / nothing
446 yt = y + freearr_y[i]; 440 yt = y + freearr_y[i];
447 tmp = GET_MAP_OB (pl->map, xt, yt); 441 tmp = GET_MAP_OB (pl->map, xt, yt);
448 if (!tmp) 442 if (!tmp)
449 { 443 {
450 /* Must insert floor & wall */ 444 /* Must insert floor & wall */
451 tmp = arch_to_object (new_floor); 445 tmp = new_floor->instance ();
452 /* Better make the floor unique */ 446 /* Better make the floor unique */
453 SET_FLAG (tmp, FLAG_UNIQUE); 447 tmp->set_flag (FLAG_UNIQUE);
454 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 448 tmp->set_flag (FLAG_IS_BUILDABLE);
455 tmp->type = FLOOR; 449 //tmp->type = FLOOR;
456 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 450 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... */ 451 /* Insert wall if exists. Note: if it doesn't, the map is weird... */
458 if (new_wall) 452 if (new_wall)
459 { 453 {
460 tmp = arch_to_object (new_wall); 454 tmp = new_wall->instance ();
461 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 455 tmp->set_flag (FLAG_IS_BUILDABLE);
462 tmp->type = BUILDABLE_WALL; 456 tmp->type = BUILDABLE_WALL;
463 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); 457 insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt);
464 } 458 }
465 } 459 }
466 } 460 }
469 * 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
470 * spot, so need to check that those new walls connect correctly 464 * spot, so need to check that those new walls connect correctly
471 */ 465 */
472 for (xt = x - 2; xt <= x + 2; xt++) 466 for (xt = x - 2; xt <= x + 2; xt++)
473 for (yt = y - 2; yt <= y + 2; yt++) 467 for (yt = y - 2; yt <= y + 2; yt++)
474 {
475 if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) 468 if (!OUT_OF_REAL_MAP (pl->map, xt, yt))
476 fix_walls (pl->map, xt, yt); 469 fix_walls (pl->map, xt, yt);
477 }
478 470
479 /* Now remove raw item from inventory */ 471 /* Now remove raw item from inventory */
480 decrease_ob (material); 472 material->decrease ();
481 473
482 /* And tell player about the fix */ 474 /* And tell player about the fix */
483 new_draw_info (NDI_UNIQUE, 0, pl, message); 475 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} 476}
500 477
501/** 478/**
502 * Wall building function 479 * Wall building function
503 * 480 *
504 * Walls can be build: 481 * Walls can be build:
505 * - on a floor without anything else 482 * - on a floor without anything else
506 * - on an existing wall, with or without a floor 483 * - on an existing wall, with or without a floor
507 */ 484 */
508void 485static void
509apply_builder_wall (object *pl, object *material, short x, short y) 486apply_builder_wall (object *pl, object *material, int x, int y)
510{ 487{
511 object *current_wall; 488 object *current_wall;
512 object *tmp; 489 object *tmp;
513 int xt, yt; 490 int xt, yt;
514 struct archetype *new_wall; 491 struct archetype *new_wall;
536 { 513 {
537 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);
538 return; 515 return;
539 } 516 }
540 517
541 tmp = arch_to_object (new_wall); 518 tmp = new_wall->instance ();
542 tmp->type = BUILDABLE_WALL; 519 tmp->type = BUILDABLE_WALL;
543 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 520 tmp->set_flag (FLAG_IS_BUILDABLE);
544 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);
545 522
546 /* If existing wall, remove it, no need to fix other walls */ 523 /* If existing wall, remove it, no need to fix other walls */
547 if (current_wall) 524 if (current_wall)
548 { 525 {
562 fix_walls (pl->map, xt, yt); 539 fix_walls (pl->map, xt, yt);
563 } 540 }
564 } 541 }
565 542
566 /* Now remove item from inventory */ 543 /* Now remove item from inventory */
567 decrease_ob (material); 544 material->decrease ();
568 545
569 /* And tell player what happened */ 546 /* And tell player what happened */
570 new_draw_info (NDI_UNIQUE, 0, pl, message); 547 new_draw_info (NDI_UNIQUE, 0, pl, message);
571} 548}
572 549
576 * 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.
577 * Archetype of created object is item->slaying (raw material). 554 * Archetype of created object is item->slaying (raw material).
578 * Type of inserted item is tested for specific cases (doors & such). 555 * 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) 556 * Item is inserted above the floor, unless Str == 1 (only for detectors i guess)
580 */ 557 */
581void 558static void
582apply_builder_item (object *pl, object *item, short x, short y) 559apply_builder_item (object *pl, object *item, int x, int y)
583{ 560{
584 object *tmp; 561 object *tmp;
585 struct archetype *arch; 562 struct archetype *arch;
586 int insert_flag; 563 int insert_flag;
587 object *floor; 564 object *floor;
588 object *con_rune; 565 object *con_rune;
589 int connected;
590 566
591 /* Find floor */ 567 /* Find floor */
592 floor = GET_MAP_OB (pl->map, x, y); 568 floor = GET_MAP_OB (pl->map, x, y);
593 if (!floor) 569 if (!floor)
594 { 570 {
595 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 571 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
596 return; 572 return;
597 } 573 }
598 574
599 while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) 575 while (floor && !IS_FLOOR (floor))
600 floor = floor->above; 576 floor = floor->above;
601 577
602 if (!floor) 578 if (!floor)
603 { 579 {
604 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here."); 580 new_draw_info (NDI_UNIQUE, 0, pl, "This square has no floor, you can't build here.");
607 /* Create item, set flag, insert in map */ 583 /* Create item, set flag, insert in map */
608 arch = archetype::find (item->slaying); 584 arch = archetype::find (item->slaying);
609 if (!arch) 585 if (!arch)
610 return; 586 return;
611 587
612 tmp = arch_to_object (arch); 588 tmp = arch->instance ();
613 589
614 if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) 590 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 */ 591 /* Floor has something on top that interferes with building */
616 { 592 {
617 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 593 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
618 return; 594 return;
619 } 595 }
620 596
621 SET_FLAG (tmp, FLAG_IS_BUILDABLE); 597 tmp->set_flag (FLAG_IS_BUILDABLE);
622 SET_FLAG (tmp, FLAG_NO_PICK); 598 tmp->set_flag (FLAG_NO_PICK);
623 599
624 /* 600 /*
625 * This doesn't work on non unique maps. pedestals under floor will not be saved... 601 * 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; 602 * Items under the floor on non-unique maps will not be saved,
603 * so make the item itself unique in this situation.
627 */ 604 */
628 insert_flag = INS_ABOVE_FLOOR_ONLY; 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);
629 608
630 connected = 0; 609 shstr_tmp connected;
610
631 switch (tmp->type) 611 switch (tmp->type)
632 { 612 {
633 case DOOR: 613 case DOOR:
634 case GATE: 614 case GATE:
635 case BUTTON: 615 case BUTTON:
636 case DETECTOR: 616 case DETECTOR:
637 case TIMED_GATE: 617 case TIMED_GATE:
638 case PEDESTAL: 618 case PEDESTAL:
639 case CF_HANDLE: 619 case T_HANDLE:
640 case MAGIC_EAR: 620 case MAGIC_EAR:
641 case SIGN: 621 case SIGN:
642 /* Signs don't need a connection, but but magic mouths do. */ 622 /* Signs don't need a connection, but but magic mouths do. */
643 if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) 623 if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth)
644 break; 624 break;
625
645 con_rune = get_connection_rune (pl, x, y); 626 con_rune = get_connection_rune (pl, x, y);
646 connected = find_or_create_connection_for_map (pl, x, y, con_rune); 627 connected = find_or_create_connection_for_map (pl, x, y, con_rune);
647 if (connected == -1) 628 if (!connected)
648 { 629 {
649 /* Player already informed of failure by the previous function */ 630 /* Player already informed of failure by the previous function */
650 tmp->destroy (); 631 tmp->destroy ();
651 return; 632 return;
652 } 633 }
634
653 /* Remove marking rune */ 635 /* Remove marking rune */
654 con_rune->destroy (); 636 con_rune->destroy ();
655 } 637 }
656 638
657 /* For magic mouths/ears, and signs, take the msg from a book of scroll */ 639 /* For magic mouths/ears, and signs, take the msg from a book of scroll */
658 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) 640 if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR))
659 {
660 if (adjust_sign_msg (pl, x, y, tmp) == -1) 641 if (adjust_sign_msg (pl, x, y, tmp) == -1)
661 { 642 {
662 tmp->destroy (); 643 tmp->destroy ();
663 return; 644 return;
664 } 645 }
665 }
666 646
667 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);
668 if (connected != 0) 648 if (connected)
669 add_button_link (tmp, pl->map, connected); 649 tmp->add_link (pl->map, connected);
670 650
671 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));
672 decrease_ob_nr (item, 1); 652 item->decrease ();
673} 653}
674 654
675/** 655/**
676 * Item remover. 656 * Item remover.
677 * 657 *
678 * Removes first buildable item, either under or above the floor 658 * Removes first buildable item, either under or above the floor
679 */ 659 */
680void 660static void
681apply_builder_remove (object *pl, int dir) 661apply_builder_remove (object *pl, int dir)
682{ 662{
683 object *item; 663 object *item;
684 short x, y; 664 int x, y;
685 665
686 x = pl->x + freearr_x[dir]; 666 x = pl->x + freearr_x[dir];
687 y = pl->y + freearr_y[dir]; 667 y = pl->y + freearr_y[dir];
688 668
689 /* Check square */ 669 /* Check square */
694 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); 674 new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square.");
695 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path); 675 LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path);
696 return; 676 return;
697 } 677 }
698 678
699 if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) 679 if (IS_FLOOR (item))
700 item = item->above; 680 item = item->above;
701 681
702 if (!item) 682 if (!item)
703 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); 683 new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove.");
704 else if (item->type == BUILDABLE_WALL) 684 else if (item->type == BUILDABLE_WALL)
719 * or remover object. 699 * or remover object.
720 */ 700 */
721void 701void
722apply_map_builder (object *pl, int dir) 702apply_map_builder (object *pl, int dir)
723{ 703{
724 object *builder; 704 object *builder = 0;
725 object *tmp; 705 object *tmp = 0;
726 object *tmp2; 706 object *tmp2 = 0;
727 short x, y; 707 int x, y;
728 708
729 if (!pl->type == PLAYER) 709 if (!pl->type == PLAYER)
730 return; 710 return;
731 711
732 /*if ( !player->map->unique ) 712 /*if ( !player->map->unique )
764 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); 744 LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path);
765 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); 745 new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird.");
766 return; 746 return;
767 } 747 }
768 748
749 if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y)))
750 return;
751
769 tmp2 = find_marked_object (pl); 752 tmp2 = find_marked_object (pl);
770 while (tmp) 753 while (tmp)
771 { 754 {
772 if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) 755 if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark))
773 { 756 {
774 /* The item building function already has it's own special 757 /* The item building function already has it's own special
775 * checks for this 758 * checks for this
776 */ 759 */
777 if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) 760 if (!tmp2 || tmp2->subtype != ST_MAT_ITEM)
778 { 761 {
779 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); 762 new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here.");
780 return; 763 return;
781 } 764 }
782 } 765 }
766
783 tmp = tmp->above; 767 tmp = tmp->above;
784 } 768 }
785 769
786 /* Now we know the square is ok */ 770 /* Now we know the square is ok */
787 builder = pl->contr->ranged_ob; 771 builder = pl->contr->ranged_ob;
812 return; 796 return;
813 } 797 }
814 798
815 switch (tmp->subtype) 799 switch (tmp->subtype)
816 { 800 {
817 case ST_MAT_FLOOR: 801 case ST_MAT_FLOOR:
818 apply_builder_floor (pl, tmp, x, y); 802 apply_builder_floor (pl, tmp, x, y);
819 return; 803 return;
820 804
821 case ST_MAT_WALL: 805 case ST_MAT_WALL:
822 apply_builder_wall (pl, tmp, x, y); 806 apply_builder_wall (pl, tmp, x, y);
823 return; 807 return;
824 808
825 case ST_MAT_ITEM: 809 case ST_MAT_ITEM:
826 apply_builder_item (pl, tmp, x, y); 810 apply_builder_item (pl, tmp, x, y);
827 return; 811 return;
828 812
829 default: 813 default:
830 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry."); 814 new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this material, sorry.");
831 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype); 815 LOG (llevError, "apply_map_builder: invalid material subtype %d\n", tmp->subtype);
832 return; 816 return;
833 } 817 }
834 } 818 }
835 819
836 /* Here, it means the builder has an invalid type */ 820 /* 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."); 821 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); 822 LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype);
839} 823}
840 824
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