1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 | * Deliantra 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 <support@deliantra.net> |
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> |
… | |
… | |
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 | */ |
34 | int |
38 | static int |
35 | can_build_over (maptile *map, object *tmp, short x, short y) |
39 | can_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 (ob->arch->archname != shstr_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 | */ |
77 | void |
79 | static void |
78 | remove_marking_runes (maptile *map, short x, short y) |
80 | remove_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); |
… | |
… | |
113 | if (!map->find_link (id)) |
115 | if (!map->find_link (id)) |
114 | return id; |
116 | return id; |
115 | } |
117 | } |
116 | |
118 | |
117 | return shstr_tmp (); |
119 | return shstr_tmp (); |
|
|
120 | } |
|
|
121 | |
|
|
122 | /** |
|
|
123 | * Returns the marking rune on the square, for purposes of building connections |
|
|
124 | */ |
|
|
125 | static object * |
|
|
126 | get_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; |
118 | } |
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 | * |
… | |
… | |
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 | */ |
130 | static shstr_tmp |
146 | static shstr_tmp |
131 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
147 | find_or_create_connection_for_map (object *pl, int x, int y, object *rune) |
132 | { |
148 | { |
133 | object *force; |
149 | object *force; |
134 | |
150 | |
135 | if (!rune) |
151 | if (!rune) |
136 | rune = get_connection_rune (pl, x, y); |
152 | rune = get_connection_rune (pl, x, y); |
… | |
… | |
174 | /* Found the force, everything's easy. */ |
190 | /* Found the force, everything's easy. */ |
175 | return force->race; |
191 | return force->race; |
176 | } |
192 | } |
177 | |
193 | |
178 | /** |
194 | /** |
179 | * Returns the marking rune on the square, for purposes of building connections |
|
|
180 | */ |
|
|
181 | object * |
|
|
182 | get_connection_rune (object *pl, short x, short y) |
|
|
183 | { |
|
|
184 | object *rune = GET_MAP_OB (pl->map, x, y); |
|
|
185 | |
|
|
186 | while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark)) |
|
|
187 | rune = rune->above; |
|
|
188 | |
|
|
189 | return rune; |
|
|
190 | } |
|
|
191 | |
|
|
192 | /** |
|
|
193 | * 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 |
194 | */ |
196 | */ |
195 | object * |
197 | static object * |
196 | get_msg_book (object *pl, short x, short y) |
198 | get_msg_book (object *pl, int x, int y) |
197 | { |
199 | { |
198 | object *book = GET_MAP_OB (pl->map, x, y); |
200 | object *book = GET_MAP_OB (pl->map, x, y); |
199 | |
201 | |
200 | while (book && (book->type != BOOK)) |
202 | while (book && (book->type != BOOK)) |
201 | book = book->above; |
203 | book = book->above; |
202 | |
204 | |
203 | return book; |
205 | return book; |
204 | } |
206 | } |
205 | |
207 | |
206 | /** |
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 | */ |
|
|
213 | static int |
|
|
214 | adjust_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 | /** |
207 | * Returns first item of type BUILDABLE_WALL. |
253 | * Returns first item of type BUILDABLE_WALL. |
208 | */ |
254 | */ |
209 | object * |
255 | static object * |
210 | get_wall (maptile *map, int x, int y) |
256 | get_wall (maptile *map, int x, int y) |
211 | { |
257 | { |
212 | object *wall = GET_MAP_OB (map, x, y); |
258 | object *wall = GET_MAP_OB (map, x, y); |
213 | |
259 | |
214 | while (wall && (BUILDABLE_WALL != wall->type)) |
260 | while (wall && (BUILDABLE_WALL != wall->type)) |
… | |
… | |
226 | * |
272 | * |
227 | * Basically it ensures the correct wall is put where needed. |
273 | * Basically it ensures the correct wall is put where needed. |
228 | * |
274 | * |
229 | * Note: x & y must be valid map coordinates. |
275 | * Note: x & y must be valid map coordinates. |
230 | */ |
276 | */ |
231 | void |
277 | static void |
232 | fix_walls (maptile *map, int x, int y) |
278 | fix_walls (maptile *map, int x, int y) |
233 | { |
279 | { |
234 | char archetype[MAX_BUF]; |
280 | char archetype[MAX_BUF]; |
235 | char *underscore; |
281 | char *underscore; |
236 | struct archetype *new_arch; |
282 | struct archetype *new_arch; |
… | |
… | |
256 | underscore++; |
302 | underscore++; |
257 | *underscore = '\0'; |
303 | *underscore = '\0'; |
258 | |
304 | |
259 | int connect = 0; |
305 | int connect = 0; |
260 | |
306 | |
261 | if ((x > 0) && get_wall (map, x - 1, y)) |
307 | if (x > 0 && get_wall (map, x - 1, y)) connect |= 1; |
262 | connect |= 1; |
|
|
263 | 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; |
264 | connect |= 2; |
309 | if (y > 0 && get_wall (map, x, y - 1)) connect |= 4; |
265 | |
|
|
266 | if ((y > 0) && get_wall (map, x, y - 1)) |
|
|
267 | connect |= 4; |
|
|
268 | |
|
|
269 | 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; |
270 | connect |= 8; |
|
|
271 | |
311 | |
272 | switch (connect) |
312 | // one bit per dir, 1 left, 2 right, 4 up, 8 down |
273 | { |
313 | static const char *walltype[16] = { |
274 | case 0: |
314 | "0", |
275 | 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 | }; |
276 | |
331 | |
277 | break; |
332 | strcat (archetype, walltype [connect]); |
278 | case 1: |
|
|
279 | strcat (archetype, "1_3"); |
|
|
280 | |
|
|
281 | break; |
|
|
282 | case 2: |
|
|
283 | strcat (archetype, "1_4"); |
|
|
284 | |
|
|
285 | break; |
|
|
286 | case 3: |
|
|
287 | strcat (archetype, "2_1_2"); |
|
|
288 | |
|
|
289 | break; |
|
|
290 | case 4: |
|
|
291 | strcat (archetype, "1_2"); |
|
|
292 | |
|
|
293 | break; |
|
|
294 | case 5: |
|
|
295 | strcat (archetype, "2_2_4"); |
|
|
296 | |
|
|
297 | break; |
|
|
298 | case 6: |
|
|
299 | strcat (archetype, "2_2_1"); |
|
|
300 | |
|
|
301 | break; |
|
|
302 | case 7: |
|
|
303 | strcat (archetype, "3_1"); |
|
|
304 | |
|
|
305 | break; |
|
|
306 | case 8: |
|
|
307 | strcat (archetype, "1_1"); |
|
|
308 | |
|
|
309 | break; |
|
|
310 | case 9: |
|
|
311 | strcat (archetype, "2_2_3"); |
|
|
312 | |
|
|
313 | break; |
|
|
314 | case 10: |
|
|
315 | strcat (archetype, "2_2_2"); |
|
|
316 | |
|
|
317 | break; |
|
|
318 | case 11: |
|
|
319 | strcat (archetype, "3_3"); |
|
|
320 | |
|
|
321 | break; |
|
|
322 | case 12: |
|
|
323 | strcat (archetype, "2_1_1"); |
|
|
324 | |
|
|
325 | break; |
|
|
326 | case 13: |
|
|
327 | strcat (archetype, "3_4"); |
|
|
328 | |
|
|
329 | break; |
|
|
330 | case 14: |
|
|
331 | strcat (archetype, "3_2"); |
|
|
332 | |
|
|
333 | break; |
|
|
334 | case 15: |
|
|
335 | strcat (archetype, "4"); |
|
|
336 | |
|
|
337 | break; |
|
|
338 | } |
|
|
339 | |
333 | |
340 | /* |
334 | /* |
341 | * Before anything, make sure the archetype does exist... |
335 | * Before anything, make sure the archetype does exist... |
342 | * If not, prolly an error... |
336 | * If not, prolly an error... |
343 | */ |
337 | */ |
… | |
… | |
351 | */ |
345 | */ |
352 | 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 |
353 | |
347 | |
354 | wall->destroy (); |
348 | wall->destroy (); |
355 | |
349 | |
356 | wall = arch_to_object (new_arch); |
350 | wall = new_arch->instance (); |
357 | wall->type = BUILDABLE_WALL; |
351 | wall->type = BUILDABLE_WALL; |
358 | 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); |
359 | wall->flag = old_flags; |
353 | wall->flag = old_flags; |
360 | } |
354 | } |
361 | |
355 | |
… | |
… | |
367 | * - on an existing wall, with or without a floor under it |
361 | * - on an existing wall, with or without a floor under it |
368 | * |
362 | * |
369 | * Note: this function will inconditionally change squares around (x, y) |
363 | * Note: this function will inconditionally change squares around (x, y) |
370 | * so don't call it with x == 0 for instance! |
364 | * so don't call it with x == 0 for instance! |
371 | */ |
365 | */ |
372 | void |
366 | static void |
373 | apply_builder_floor (object *pl, object *material, short x, short y) |
367 | apply_builder_floor (object *pl, object *material, int x, int y) |
374 | { |
368 | { |
375 | object *tmp, *above; |
369 | object *tmp, *above; |
376 | object *above_floor; /* Item above floor, if any */ |
370 | object *above_floor; /* Item above floor, if any */ |
377 | struct archetype *new_floor; |
371 | struct archetype *new_floor; |
378 | struct archetype *new_wall; |
372 | struct archetype *new_wall; |
… | |
… | |
399 | /* 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 */ |
400 | new_wall = tmp->arch; |
394 | new_wall = tmp->arch; |
401 | tmp->destroy (); |
395 | tmp->destroy (); |
402 | sprintf (message, "You destroy the wall and redo the floor."); |
396 | sprintf (message, "You destroy the wall and redo the floor."); |
403 | } |
397 | } |
404 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
398 | else if (IS_FLOOR (tmp)) |
405 | { |
399 | { |
406 | tmp->destroy (); |
400 | tmp->destroy (); |
407 | floor_removed = 1; |
401 | floor_removed = 1; |
408 | } |
402 | } |
409 | else |
403 | else |
410 | { |
404 | { |
411 | if (floor_removed) |
405 | if (floor_removed) |
|
|
406 | { |
|
|
407 | /* This is the first item that was above the floor */ |
412 | above_floor = tmp; |
408 | above_floor = tmp; |
|
|
409 | floor_removed = 0; |
|
|
410 | } |
413 | } |
411 | } |
414 | |
412 | |
415 | tmp = above; |
413 | tmp = above; |
416 | } |
414 | } |
417 | } |
415 | } |
… | |
… | |
423 | /* Not found, log & bail out */ |
421 | /* Not found, log & bail out */ |
424 | 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); |
425 | return; |
423 | return; |
426 | } |
424 | } |
427 | |
425 | |
428 | tmp = arch_to_object (new_floor); |
426 | tmp = new_floor->instance (); |
429 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
427 | tmp->set_flag (FLAG_IS_BUILDABLE); |
430 | SET_FLAG (tmp, FLAG_UNIQUE); |
428 | tmp->set_flag (FLAG_UNIQUE); |
431 | SET_FLAG (tmp, FLAG_IS_FLOOR); |
429 | tmp->set_flag (FLAG_IS_FLOOR); |
432 | tmp->type = FLOOR; |
430 | //tmp->type = FLOOR; |
433 | 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); |
434 | |
432 | |
435 | /* |
433 | /* |
436 | * 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 |
437 | * Since building, you can have: blocking view / floor / wall / nothing |
435 | * Since building, you can have: blocking view / floor / wall / nothing |
… | |
… | |
442 | yt = y + freearr_y[i]; |
440 | yt = y + freearr_y[i]; |
443 | tmp = GET_MAP_OB (pl->map, xt, yt); |
441 | tmp = GET_MAP_OB (pl->map, xt, yt); |
444 | if (!tmp) |
442 | if (!tmp) |
445 | { |
443 | { |
446 | /* Must insert floor & wall */ |
444 | /* Must insert floor & wall */ |
447 | tmp = arch_to_object (new_floor); |
445 | tmp = new_floor->instance (); |
448 | /* Better make the floor unique */ |
446 | /* Better make the floor unique */ |
449 | SET_FLAG (tmp, FLAG_UNIQUE); |
447 | tmp->set_flag (FLAG_UNIQUE); |
450 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
448 | tmp->set_flag (FLAG_IS_BUILDABLE); |
451 | tmp->type = FLOOR; |
449 | //tmp->type = FLOOR; |
452 | 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); |
453 | /* 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... */ |
454 | if (new_wall) |
452 | if (new_wall) |
455 | { |
453 | { |
456 | tmp = arch_to_object (new_wall); |
454 | tmp = new_wall->instance (); |
457 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
455 | tmp->set_flag (FLAG_IS_BUILDABLE); |
458 | tmp->type = BUILDABLE_WALL; |
456 | tmp->type = BUILDABLE_WALL; |
459 | 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); |
460 | } |
458 | } |
461 | } |
459 | } |
462 | } |
460 | } |
… | |
… | |
465 | * 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 |
466 | * spot, so need to check that those new walls connect correctly |
464 | * spot, so need to check that those new walls connect correctly |
467 | */ |
465 | */ |
468 | for (xt = x - 2; xt <= x + 2; xt++) |
466 | for (xt = x - 2; xt <= x + 2; xt++) |
469 | for (yt = y - 2; yt <= y + 2; yt++) |
467 | for (yt = y - 2; yt <= y + 2; yt++) |
470 | { |
|
|
471 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
468 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
472 | fix_walls (pl->map, xt, yt); |
469 | fix_walls (pl->map, xt, yt); |
473 | } |
|
|
474 | |
470 | |
475 | /* Now remove raw item from inventory */ |
471 | /* Now remove raw item from inventory */ |
476 | material->decrease (); |
472 | material->decrease (); |
477 | |
473 | |
478 | /* And tell player about the fix */ |
474 | /* And tell player about the fix */ |
479 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
475 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
480 | } |
|
|
481 | |
|
|
482 | /** |
|
|
483 | * Wall radius fix function |
|
|
484 | */ |
|
|
485 | void fix_walls_around (maptile *map, int x, int y) |
|
|
486 | { |
|
|
487 | for (int xt = x - 1; xt <= x + 1; xt++) |
|
|
488 | for (int yt = y - 1; yt <= y + 1; yt++) |
|
|
489 | { |
|
|
490 | if (OUT_OF_REAL_MAP (map, xt, yt)) |
|
|
491 | continue; |
|
|
492 | |
|
|
493 | fix_walls (map, xt, yt); |
|
|
494 | } |
|
|
495 | } |
476 | } |
496 | |
477 | |
497 | /** |
478 | /** |
498 | * Wall building function |
479 | * Wall building function |
499 | * |
480 | * |
500 | * Walls can be build: |
481 | * Walls can be build: |
501 | * - on a floor without anything else |
482 | * - on a floor without anything else |
502 | * - on an existing wall, with or without a floor |
483 | * - on an existing wall, with or without a floor |
503 | */ |
484 | */ |
504 | void |
485 | static void |
505 | apply_builder_wall (object *pl, object *material, short x, short y) |
486 | apply_builder_wall (object *pl, object *material, int x, int y) |
506 | { |
487 | { |
507 | object *current_wall; |
488 | object *current_wall; |
508 | object *tmp; |
489 | object *tmp; |
509 | int xt, yt; |
490 | int xt, yt; |
510 | struct archetype *new_wall; |
491 | struct archetype *new_wall; |
… | |
… | |
532 | { |
513 | { |
533 | 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); |
534 | return; |
515 | return; |
535 | } |
516 | } |
536 | |
517 | |
537 | tmp = arch_to_object (new_wall); |
518 | tmp = new_wall->instance (); |
538 | tmp->type = BUILDABLE_WALL; |
519 | tmp->type = BUILDABLE_WALL; |
539 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
520 | tmp->set_flag (FLAG_IS_BUILDABLE); |
540 | 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); |
541 | |
522 | |
542 | /* If existing wall, remove it, no need to fix other walls */ |
523 | /* If existing wall, remove it, no need to fix other walls */ |
543 | if (current_wall) |
524 | if (current_wall) |
544 | { |
525 | { |
… | |
… | |
572 | * 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. |
573 | * Archetype of created object is item->slaying (raw material). |
554 | * Archetype of created object is item->slaying (raw material). |
574 | * Type of inserted item is tested for specific cases (doors & such). |
555 | * Type of inserted item is tested for specific cases (doors & such). |
575 | * 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) |
576 | */ |
557 | */ |
577 | void |
558 | static void |
578 | apply_builder_item (object *pl, object *item, short x, short y) |
559 | apply_builder_item (object *pl, object *item, int x, int y) |
579 | { |
560 | { |
580 | object *tmp; |
561 | object *tmp; |
581 | struct archetype *arch; |
562 | struct archetype *arch; |
582 | int insert_flag; |
563 | int insert_flag; |
583 | object *floor; |
564 | object *floor; |
… | |
… | |
589 | { |
570 | { |
590 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
571 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
591 | return; |
572 | return; |
592 | } |
573 | } |
593 | |
574 | |
594 | while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) |
575 | while (floor && !IS_FLOOR (floor)) |
595 | floor = floor->above; |
576 | floor = floor->above; |
596 | |
577 | |
597 | if (!floor) |
578 | if (!floor) |
598 | { |
579 | { |
599 | 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."); |
… | |
… | |
602 | /* Create item, set flag, insert in map */ |
583 | /* Create item, set flag, insert in map */ |
603 | arch = archetype::find (item->slaying); |
584 | arch = archetype::find (item->slaying); |
604 | if (!arch) |
585 | if (!arch) |
605 | return; |
586 | return; |
606 | |
587 | |
607 | tmp = arch_to_object (arch); |
588 | tmp = arch->instance (); |
608 | |
589 | |
609 | if (!floor->flag[FLAG_IS_BUILDABLE] || (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)) |
610 | /* Floor has something on top that interferes with building */ |
591 | /* Floor has something on top that interferes with building */ |
611 | { |
592 | { |
612 | 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."); |
613 | return; |
594 | return; |
614 | } |
595 | } |
615 | |
596 | |
616 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
597 | tmp->set_flag (FLAG_IS_BUILDABLE); |
617 | SET_FLAG (tmp, FLAG_NO_PICK); |
598 | tmp->set_flag (FLAG_NO_PICK); |
618 | |
599 | |
619 | /* |
600 | /* |
620 | * 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. |
621 | 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. |
622 | */ |
604 | */ |
623 | 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); |
624 | |
608 | |
625 | shstr_tmp connected; |
609 | shstr_tmp connected; |
626 | |
610 | |
627 | switch (tmp->type) |
611 | switch (tmp->type) |
628 | { |
612 | { |
… | |
… | |
630 | case GATE: |
614 | case GATE: |
631 | case BUTTON: |
615 | case BUTTON: |
632 | case DETECTOR: |
616 | case DETECTOR: |
633 | case TIMED_GATE: |
617 | case TIMED_GATE: |
634 | case PEDESTAL: |
618 | case PEDESTAL: |
635 | case CF_HANDLE: |
619 | case T_HANDLE: |
636 | case MAGIC_EAR: |
620 | case MAGIC_EAR: |
637 | case SIGN: |
621 | case SIGN: |
638 | /* Signs don't need a connection, but but magic mouths do. */ |
622 | /* Signs don't need a connection, but but magic mouths do. */ |
639 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
623 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
640 | break; |
624 | break; |
… | |
… | |
652 | con_rune->destroy (); |
636 | con_rune->destroy (); |
653 | } |
637 | } |
654 | |
638 | |
655 | /* 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 */ |
656 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
640 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
657 | { |
|
|
658 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
641 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
659 | { |
642 | { |
660 | tmp->destroy (); |
643 | tmp->destroy (); |
661 | return; |
644 | return; |
662 | } |
645 | } |
663 | } |
|
|
664 | |
646 | |
665 | 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); |
666 | if (connected) |
648 | if (connected) |
667 | tmp->add_link (pl->map, connected); |
649 | tmp->add_link (pl->map, connected); |
668 | |
650 | |
… | |
… | |
673 | /** |
655 | /** |
674 | * Item remover. |
656 | * Item remover. |
675 | * |
657 | * |
676 | * Removes first buildable item, either under or above the floor |
658 | * Removes first buildable item, either under or above the floor |
677 | */ |
659 | */ |
678 | void |
660 | static void |
679 | apply_builder_remove (object *pl, int dir) |
661 | apply_builder_remove (object *pl, int dir) |
680 | { |
662 | { |
681 | object *item; |
663 | object *item; |
682 | short x, y; |
664 | int x, y; |
683 | |
665 | |
684 | x = pl->x + freearr_x[dir]; |
666 | x = pl->x + freearr_x[dir]; |
685 | y = pl->y + freearr_y[dir]; |
667 | y = pl->y + freearr_y[dir]; |
686 | |
668 | |
687 | /* Check square */ |
669 | /* Check square */ |
… | |
… | |
692 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
674 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
693 | 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); |
694 | return; |
676 | return; |
695 | } |
677 | } |
696 | |
678 | |
697 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
679 | if (IS_FLOOR (item)) |
698 | item = item->above; |
680 | item = item->above; |
699 | |
681 | |
700 | if (!item) |
682 | if (!item) |
701 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
683 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
702 | else if (item->type == BUILDABLE_WALL) |
684 | else if (item->type == BUILDABLE_WALL) |
… | |
… | |
717 | * or remover object. |
699 | * or remover object. |
718 | */ |
700 | */ |
719 | void |
701 | void |
720 | apply_map_builder (object *pl, int dir) |
702 | apply_map_builder (object *pl, int dir) |
721 | { |
703 | { |
722 | object *builder; |
704 | object *builder = 0; |
723 | object *tmp; |
705 | object *tmp = 0; |
724 | object *tmp2; |
706 | object *tmp2 = 0; |
725 | short x, y; |
707 | int x, y; |
726 | |
708 | |
727 | if (!pl->type == PLAYER) |
709 | if (!pl->type == PLAYER) |
728 | return; |
710 | return; |
729 | |
711 | |
730 | /*if ( !player->map->unique ) |
712 | /*if ( !player->map->unique ) |
… | |
… | |
762 | 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); |
763 | 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."); |
764 | return; |
746 | return; |
765 | } |
747 | } |
766 | |
748 | |
|
|
749 | if (INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y))) |
|
|
750 | return; |
|
|
751 | |
767 | tmp2 = find_marked_object (pl); |
752 | tmp2 = find_marked_object (pl); |
768 | while (tmp) |
753 | while (tmp) |
769 | { |
754 | { |
770 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
755 | if (!tmp->flag [FLAG_IS_BUILDABLE] && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
771 | { |
756 | { |
772 | /* The item building function already has it's own special |
757 | /* The item building function already has it's own special |
773 | * checks for this |
758 | * checks for this |
774 | */ |
759 | */ |
775 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
760 | if (!tmp2 || tmp2->subtype != ST_MAT_ITEM) |
776 | { |
761 | { |
777 | 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."); |
778 | return; |
763 | return; |
779 | } |
764 | } |
780 | } |
765 | } |
|
|
766 | |
781 | tmp = tmp->above; |
767 | tmp = tmp->above; |
782 | } |
768 | } |
783 | |
769 | |
784 | /* Now we know the square is ok */ |
770 | /* Now we know the square is ok */ |
785 | builder = pl->contr->ranged_ob; |
771 | builder = pl->contr->ranged_ob; |
… | |
… | |
810 | return; |
796 | return; |
811 | } |
797 | } |
812 | |
798 | |
813 | switch (tmp->subtype) |
799 | switch (tmp->subtype) |
814 | { |
800 | { |
815 | case ST_MAT_FLOOR: |
801 | case ST_MAT_FLOOR: |
816 | apply_builder_floor (pl, tmp, x, y); |
802 | apply_builder_floor (pl, tmp, x, y); |
817 | return; |
803 | return; |
818 | |
804 | |
819 | case ST_MAT_WALL: |
805 | case ST_MAT_WALL: |
820 | apply_builder_wall (pl, tmp, x, y); |
806 | apply_builder_wall (pl, tmp, x, y); |
821 | return; |
807 | return; |
822 | |
808 | |
823 | case ST_MAT_ITEM: |
809 | case ST_MAT_ITEM: |
824 | apply_builder_item (pl, tmp, x, y); |
810 | apply_builder_item (pl, tmp, x, y); |
825 | return; |
811 | return; |
826 | |
812 | |
827 | default: |
813 | default: |
828 | 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."); |
829 | 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); |
830 | return; |
816 | return; |
831 | } |
817 | } |
832 | } |
818 | } |
833 | |
819 | |
834 | /* Here, it means the builder has an invalid type */ |
820 | /* Here, it means the builder has an invalid type */ |
835 | 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."); |
836 | 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); |
837 | } |
823 | } |
838 | |
824 | |
839 | /** |
|
|
840 | * Make the built object inherit the msg of books that are used with it. |
|
|
841 | * For objects already invisible (i.e. magic mouths & ears), also make it |
|
|
842 | * it inherit the face and the name with "talking " prepended. |
|
|
843 | */ |
|
|
844 | int |
|
|
845 | adjust_sign_msg (object *pl, short x, short y, object *tmp) |
|
|
846 | { |
|
|
847 | object *book; |
|
|
848 | char buf[MAX_BUF]; |
|
|
849 | char buf2[MAX_BUF]; |
|
|
850 | |
|
|
851 | book = get_msg_book (pl, x, y); |
|
|
852 | if (!book) |
|
|
853 | { |
|
|
854 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message."); |
|
|
855 | return -1; |
|
|
856 | } |
|
|
857 | |
|
|
858 | tmp->msg = book->msg; |
|
|
859 | |
|
|
860 | if (tmp->invisible) |
|
|
861 | { |
|
|
862 | if (book->custom_name != NULL) |
|
|
863 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
|
|
864 | else |
|
|
865 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
|
|
866 | |
|
|
867 | tmp->name = buf; |
|
|
868 | |
|
|
869 | if (book->name_pl != NULL) |
|
|
870 | { |
|
|
871 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
|
|
872 | tmp->name_pl = buf2; |
|
|
873 | } |
|
|
874 | |
|
|
875 | tmp->face = book->face; |
|
|
876 | tmp->invisible = 0; |
|
|
877 | } |
|
|
878 | |
|
|
879 | book->destroy (); |
|
|
880 | return 0; |
|
|
881 | } |
|
|