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