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.24 by root, Mon Feb 5 02:07:40 2007 UTC vs.
Revision 1.59 by root, Tue Apr 13 18:56:00 2010 UTC

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