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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * |
20 | |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | The authors can be reached via e-mail to <crossfire@schmorp.de> |
|
|
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <living.h> |
25 | #include <living.h> |
26 | #include <spells.h> |
26 | #include <spells.h> |
27 | #include <skills.h> |
27 | #include <skills.h> |
… | |
… | |
38 | |
38 | |
39 | ob = GET_MAP_OB (map, x, y); |
39 | ob = GET_MAP_OB (map, x, y); |
40 | while (ob) |
40 | while (ob) |
41 | { |
41 | { |
42 | /* if ob is not a marking rune or floor, then check special cases */ |
42 | /* if ob is not a marking rune or floor, then check special cases */ |
43 | if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) |
43 | if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR) |
44 | { |
44 | { |
45 | switch (tmp->type) |
45 | switch (tmp->type) |
46 | { |
46 | { |
47 | case SIGN: |
47 | case SIGN: |
48 | case MAGIC_EAR: |
48 | case MAGIC_EAR: |
49 | /* Allow signs and magic ears to be built on books */ |
49 | /* Allow signs and magic ears to be built on books */ |
50 | if (ob->type != BOOK) |
50 | 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; |
51 | return 0; |
|
|
52 | break; |
|
|
53 | case BUTTON: |
|
|
54 | case DETECTOR: |
|
|
55 | case PEDESTAL: |
|
|
56 | case CF_HANDLE: |
|
|
57 | /* Allow buttons and levers to be built under gates */ |
|
|
58 | if (ob->type != GATE && ob->type != DOOR) |
|
|
59 | return 0; |
|
|
60 | break; |
|
|
61 | default: |
|
|
62 | return 0; |
67 | } |
63 | } |
68 | } |
64 | } |
|
|
65 | |
69 | ob = ob->above; |
66 | ob = ob->above; |
70 | } |
67 | } |
71 | return 1; |
68 | return 1; |
72 | } |
69 | } |
73 | |
70 | |
… | |
… | |
82 | |
79 | |
83 | rune = GET_MAP_OB (map, x, y); |
80 | rune = GET_MAP_OB (map, x, y); |
84 | while (rune) |
81 | while (rune) |
85 | { |
82 | { |
86 | next = rune->above; |
83 | next = rune->above; |
|
|
84 | |
87 | if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) |
85 | if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark) |
88 | { |
|
|
89 | rune->remove (); |
|
|
90 | rune->destroy (0); |
86 | rune->destroy (); |
91 | } |
87 | |
92 | rune = next; |
88 | rune = next; |
93 | } |
89 | } |
94 | } |
90 | } |
95 | |
91 | |
96 | /** |
92 | /** |
… | |
… | |
98 | * \param map: map for which to find a value |
94 | * \param map: map for which to find a value |
99 | * \return 'connected' value with no item, or -1 if failure. |
95 | * \return 'connected' value with no item, or -1 if failure. |
100 | * |
96 | * |
101 | * Tries 1000 random values, then returns -1. |
97 | * Tries 1000 random values, then returns -1. |
102 | */ |
98 | */ |
103 | int |
99 | static shstr_tmp |
104 | find_unused_connected_value (maptile *map) |
100 | find_unused_connected_value (maptile *map) |
105 | { |
101 | { |
106 | int connected = 0; |
102 | 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 | } |
103 | { |
|
|
104 | char buf[64]; |
118 | |
105 | |
119 | return -1; |
106 | snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U); |
120 | } |
|
|
121 | |
107 | |
|
|
108 | shstr id (buf); |
|
|
109 | |
|
|
110 | if (!map->find_link (id)) |
|
|
111 | return id; |
|
|
112 | } |
|
|
113 | |
|
|
114 | return shstr_tmp (); |
|
|
115 | } |
122 | |
116 | |
123 | /** |
117 | /** |
124 | * Helper function for door/button/connected item building. |
118 | * Helper function for door/button/connected item building. |
125 | * |
119 | * |
126 | * Will search the specified spot for a marking rune. |
120 | * Will search the specified spot for a marking rune. |
… | |
… | |
128 | * Else, searches a force in op's inventory matching the map's name |
122 | * Else, searches a force in op's inventory matching the map's name |
129 | * and the rune's text. |
123 | * and the rune's text. |
130 | * If found, returns the connection value associated |
124 | * If found, returns the connection value associated |
131 | * else searches a new connection value, and adds the force to the player. |
125 | * else searches a new connection value, and adds the force to the player. |
132 | */ |
126 | */ |
133 | int |
127 | static shstr_tmp |
134 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
128 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
135 | { |
129 | { |
136 | object *force; |
130 | object *force; |
137 | int connected; |
|
|
138 | |
131 | |
139 | if (!rune) |
132 | if (!rune) |
140 | rune = get_connection_rune (pl, x, y); |
133 | rune = get_connection_rune (pl, x, y); |
141 | |
134 | |
142 | if (!rune) |
135 | if (!rune) |
143 | { |
136 | { |
144 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
137 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
145 | return -1; |
138 | return shstr_tmp (); |
146 | } |
139 | } |
147 | |
140 | |
148 | /* Now, find force in player's inventory */ |
141 | /* Now, find force in player's inventory */ |
149 | force = pl->inv; |
142 | force = pl->inv; |
150 | while (force |
143 | while (force |
151 | && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) |
144 | && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg |
152 | || (strcmp (force->msg, rune->msg)))) |
145 | || force->msg != rune->msg)) |
153 | force = force->below; |
146 | force = force->below; |
154 | |
147 | |
155 | if (!force) |
148 | if (!force) |
156 | /* No force, need to create & insert one */ |
149 | /* No force, need to create & insert one */ |
157 | { |
150 | { |
158 | /* Find unused value */ |
151 | /* Find unused value */ |
159 | connected = find_unused_connected_value (pl->map); |
152 | shstr_tmp id = find_unused_connected_value (pl->map); |
160 | if (connected == -1) |
153 | |
|
|
154 | if (!id) |
161 | { |
155 | { |
162 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
156 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
163 | return -1; |
157 | return shstr_tmp (); |
164 | } |
158 | } |
165 | |
159 | |
166 | force = get_archetype (FORCE_NAME); |
160 | force = get_archetype (FORCE_NAME); |
167 | force->speed = 0; |
|
|
168 | update_ob_speed (force); |
|
|
169 | force->slaying = pl->map->path; |
161 | force->slaying = pl->map->path; |
170 | force->msg = rune->msg; |
162 | force->msg = rune->msg; |
171 | force->path_attuned = connected; |
163 | force->race = id; |
|
|
164 | force->set_speed (0); |
|
|
165 | |
172 | insert_ob_in_ob (force, pl); |
166 | insert_ob_in_ob (force, pl); |
173 | |
167 | |
174 | return connected; |
168 | return id; |
175 | } |
169 | } |
176 | |
170 | |
177 | /* Found the force, everything's easy. */ |
171 | /* Found the force, everything's easy. */ |
178 | return force->path_attuned; |
172 | return force->race; |
179 | } |
173 | } |
180 | |
174 | |
181 | /** |
175 | /** |
182 | * Returns the marking rune on the square, for purposes of building connections |
176 | * Returns the marking rune on the square, for purposes of building connections |
183 | */ |
177 | */ |
184 | object * |
178 | object * |
185 | get_connection_rune (object *pl, short x, short y) |
179 | get_connection_rune (object *pl, short x, short y) |
186 | { |
180 | { |
187 | object *rune; |
|
|
188 | |
|
|
189 | rune = GET_MAP_OB (pl->map, x, y); |
181 | object *rune = GET_MAP_OB (pl->map, x, y); |
|
|
182 | |
190 | while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) |
183 | while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark)) |
191 | rune = rune->above; |
184 | rune = rune->above; |
|
|
185 | |
192 | return rune; |
186 | return rune; |
193 | } |
187 | } |
194 | |
188 | |
195 | /** |
189 | /** |
196 | * Returns the book/scroll on the current square, for purposes of building |
190 | * Returns the book/scroll on the current square, for purposes of building |
197 | */ |
191 | */ |
198 | object * |
192 | object * |
199 | get_msg_book (object *pl, short x, short y) |
193 | get_msg_book (object *pl, short x, short y) |
200 | { |
194 | { |
201 | object *book; |
|
|
202 | |
|
|
203 | book = GET_MAP_OB (pl->map, x, y); |
195 | object *book = GET_MAP_OB (pl->map, x, y); |
|
|
196 | |
204 | while (book && (book->type != BOOK)) |
197 | while (book && (book->type != BOOK)) |
205 | book = book->above; |
198 | book = book->above; |
|
|
199 | |
206 | return book; |
200 | return book; |
207 | } |
201 | } |
208 | |
202 | |
209 | /** |
203 | /** |
210 | * Returns first item of type WALL. |
204 | * Returns first item of type BUILDABLE_WALL. |
211 | */ |
205 | */ |
212 | object * |
206 | object * |
213 | get_wall (maptile *map, int x, int y) |
207 | get_wall (maptile *map, int x, int y) |
214 | { |
208 | { |
215 | object *wall; |
|
|
216 | |
|
|
217 | wall = GET_MAP_OB (map, x, y); |
209 | object *wall = GET_MAP_OB (map, x, y); |
|
|
210 | |
218 | while (wall && (WALL != wall->type)) |
211 | while (wall && (BUILDABLE_WALL != wall->type)) |
219 | wall = wall->above; |
212 | wall = wall->above; |
220 | |
213 | |
221 | return wall; |
214 | return wall; |
222 | } |
215 | } |
223 | |
216 | |
… | |
… | |
233 | * Note: x & y must be valid map coordinates. |
226 | * Note: x & y must be valid map coordinates. |
234 | */ |
227 | */ |
235 | void |
228 | void |
236 | fix_walls (maptile *map, int x, int y) |
229 | fix_walls (maptile *map, int x, int y) |
237 | { |
230 | { |
238 | int connect; |
|
|
239 | object *wall; |
|
|
240 | char archetype[MAX_BUF]; |
231 | char archetype[MAX_BUF]; |
241 | char *underscore; |
232 | char *underscore; |
242 | uint32 old_flags[4]; |
|
|
243 | struct archetype *new_arch; |
233 | struct archetype *new_arch; |
244 | int flag; |
|
|
245 | |
|
|
246 | |
234 | |
247 | /* First, find the wall on that spot */ |
235 | /* First, find the wall on that spot */ |
248 | wall = get_wall (map, x, y); |
236 | object *wall = get_wall (map, x, y); |
249 | if (!wall) |
237 | if (!wall) |
250 | /* Nothing -> bail out */ |
238 | /* Nothing -> bail out */ |
251 | return; |
239 | return; |
252 | |
240 | |
253 | /* Find base name */ |
241 | /* Find base name */ |
254 | strcpy (archetype, wall->arch->name); |
242 | assign (archetype, wall->arch->archname); |
255 | underscore = strchr (archetype, '_'); |
243 | underscore = strchr (archetype, '_'); |
256 | |
244 | |
257 | /* search for the first _ before a number */ |
245 | /* search for the first _ before a number */ |
258 | while (underscore && !isdigit (*(underscore + 1))) |
246 | while (underscore && !isdigit (*(underscore + 1))) |
259 | underscore = strchr (underscore + 1, '_'); |
247 | underscore = strchr (underscore + 1, '_'); |
… | |
… | |
263 | return; |
251 | return; |
264 | |
252 | |
265 | underscore++; |
253 | underscore++; |
266 | *underscore = '\0'; |
254 | *underscore = '\0'; |
267 | |
255 | |
268 | connect = 0; |
256 | int connect = 0; |
269 | |
257 | |
270 | if ((x > 0) && get_wall (map, x - 1, y)) |
258 | if ((x > 0) && get_wall (map, x - 1, y)) |
271 | connect |= 1; |
259 | connect |= 1; |
272 | if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) |
260 | if ((x < map->width - 1) && get_wall (map, x + 1, y)) |
273 | connect |= 2; |
261 | connect |= 2; |
274 | |
262 | |
275 | if ((y > 0) && get_wall (map, x, y - 1)) |
263 | if ((y > 0) && get_wall (map, x, y - 1)) |
276 | connect |= 4; |
264 | connect |= 4; |
277 | |
265 | |
278 | if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) |
266 | if ((y < map->height - 1) && get_wall (map, x, y + 1)) |
279 | connect |= 8; |
267 | connect |= 8; |
280 | |
268 | |
281 | switch (connect) |
269 | switch (connect) |
282 | { |
270 | { |
283 | case 0: |
271 | case 0: |
… | |
… | |
356 | return; |
344 | return; |
357 | |
345 | |
358 | /* Now delete current wall, and insert new one |
346 | /* Now delete current wall, and insert new one |
359 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
347 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
360 | */ |
348 | */ |
361 | for (flag = 0; flag < 4; flag++) |
349 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
362 | old_flags[flag] = wall->flags[flag]; |
350 | |
363 | wall->remove (); |
|
|
364 | wall->destroy (0); |
351 | wall->destroy (); |
365 | |
352 | |
366 | wall = arch_to_object (new_arch); |
353 | wall = arch_to_object (new_arch); |
367 | wall->type = WALL; |
354 | wall->type = BUILDABLE_WALL; |
368 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
355 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
369 | for (flag = 0; flag < 4; flag++) |
|
|
370 | wall->flags[flag] = old_flags[flag]; |
356 | wall->flag = old_flags; |
371 | } |
357 | } |
372 | |
358 | |
373 | /** |
359 | /** |
374 | * \brief Floor building function |
360 | * \brief Floor building function |
375 | * |
361 | * |
… | |
… | |
403 | if (tmp) |
389 | if (tmp) |
404 | { |
390 | { |
405 | while (tmp) |
391 | while (tmp) |
406 | { |
392 | { |
407 | above = tmp->above; |
393 | above = tmp->above; |
408 | if (WALL == tmp->type) |
394 | if (BUILDABLE_WALL == tmp->type) |
409 | { |
395 | { |
410 | /* There was a wall, remove it & keep its archetype to make new walls */ |
396 | /* There was a wall, remove it & keep its archetype to make new walls */ |
411 | new_wall = tmp->arch; |
397 | new_wall = tmp->arch; |
412 | tmp->remove (); |
|
|
413 | tmp->destroy (0); |
398 | tmp->destroy (); |
414 | sprintf (message, "You destroy the wall and redo the floor."); |
399 | sprintf (message, "You destroy the wall and redo the floor."); |
415 | } |
400 | } |
416 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
401 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
417 | { |
402 | { |
418 | tmp->remove (); |
|
|
419 | tmp->destroy (0); |
403 | tmp->destroy (); |
420 | floor_removed = 1; |
404 | floor_removed = 1; |
421 | } |
405 | } |
422 | else |
406 | else |
423 | { |
407 | { |
424 | if (floor_removed) |
408 | if (floor_removed) |
|
|
409 | { |
|
|
410 | /* This is the first item that was above the floor */ |
425 | above_floor = tmp; |
411 | above_floor = tmp; |
|
|
412 | floor_removed = 0; |
|
|
413 | } |
426 | } |
414 | } |
427 | |
415 | |
428 | tmp = above; |
416 | tmp = above; |
429 | } |
417 | } |
430 | } |
418 | } |
… | |
… | |
466 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
454 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
467 | if (new_wall) |
455 | if (new_wall) |
468 | { |
456 | { |
469 | tmp = arch_to_object (new_wall); |
457 | tmp = arch_to_object (new_wall); |
470 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
458 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
471 | tmp->type = WALL; |
459 | tmp->type = BUILDABLE_WALL; |
472 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
460 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
473 | } |
461 | } |
474 | } |
462 | } |
475 | } |
463 | } |
476 | |
464 | |
… | |
… | |
484 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
472 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
485 | fix_walls (pl->map, xt, yt); |
473 | fix_walls (pl->map, xt, yt); |
486 | } |
474 | } |
487 | |
475 | |
488 | /* Now remove raw item from inventory */ |
476 | /* Now remove raw item from inventory */ |
489 | decrease_ob (material); |
477 | material->decrease (); |
490 | |
478 | |
491 | /* And tell player about the fix */ |
479 | /* And tell player about the fix */ |
492 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
480 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
493 | } |
481 | } |
494 | |
482 | |
… | |
… | |
528 | /* Grab existing wall, if any */ |
516 | /* Grab existing wall, if any */ |
529 | current_wall = NULL; |
517 | current_wall = NULL; |
530 | tmp = GET_MAP_OB (pl->map, x, y); |
518 | tmp = GET_MAP_OB (pl->map, x, y); |
531 | while (tmp && !current_wall) |
519 | while (tmp && !current_wall) |
532 | { |
520 | { |
533 | if (WALL == tmp->type) |
521 | if (BUILDABLE_WALL == tmp->type) |
534 | current_wall = tmp; |
522 | current_wall = tmp; |
535 | |
523 | |
536 | tmp = tmp->above; |
524 | tmp = tmp->above; |
537 | } |
525 | } |
538 | |
526 | |
… | |
… | |
546 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
534 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
547 | return; |
535 | return; |
548 | } |
536 | } |
549 | |
537 | |
550 | tmp = arch_to_object (new_wall); |
538 | tmp = arch_to_object (new_wall); |
551 | tmp->type = WALL; |
539 | tmp->type = BUILDABLE_WALL; |
552 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
540 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
553 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
541 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
554 | |
542 | |
555 | /* If existing wall, remove it, no need to fix other walls */ |
543 | /* If existing wall, remove it, no need to fix other walls */ |
556 | if (current_wall) |
544 | if (current_wall) |
557 | { |
545 | { |
558 | current_wall->remove (); |
|
|
559 | current_wall->destroy (0); |
546 | current_wall->destroy (); |
560 | fix_walls (pl->map, x, y); |
547 | fix_walls (pl->map, x, y); |
561 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
548 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
562 | } |
549 | } |
563 | else |
550 | else |
564 | { |
551 | { |
… | |
… | |
572 | fix_walls (pl->map, xt, yt); |
559 | fix_walls (pl->map, xt, yt); |
573 | } |
560 | } |
574 | } |
561 | } |
575 | |
562 | |
576 | /* Now remove item from inventory */ |
563 | /* Now remove item from inventory */ |
577 | decrease_ob (material); |
564 | material->decrease (); |
578 | |
565 | |
579 | /* And tell player what happened */ |
566 | /* And tell player what happened */ |
580 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
567 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
581 | } |
568 | } |
582 | |
569 | |
… | |
… | |
594 | object *tmp; |
581 | object *tmp; |
595 | struct archetype *arch; |
582 | struct archetype *arch; |
596 | int insert_flag; |
583 | int insert_flag; |
597 | object *floor; |
584 | object *floor; |
598 | object *con_rune; |
585 | object *con_rune; |
599 | int connected; |
|
|
600 | |
586 | |
601 | /* Find floor */ |
587 | /* Find floor */ |
602 | floor = GET_MAP_OB (pl->map, x, y); |
588 | floor = GET_MAP_OB (pl->map, x, y); |
603 | if (!floor) |
589 | if (!floor) |
604 | { |
590 | { |
… | |
… | |
619 | if (!arch) |
605 | if (!arch) |
620 | return; |
606 | return; |
621 | |
607 | |
622 | tmp = arch_to_object (arch); |
608 | tmp = arch_to_object (arch); |
623 | |
609 | |
624 | if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) |
610 | if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y))) |
625 | /* Floor has something on top that interferes with building */ |
611 | /* Floor has something on top that interferes with building */ |
626 | { |
612 | { |
627 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
613 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
628 | return; |
614 | return; |
629 | } |
615 | } |
630 | |
616 | |
631 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
617 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
632 | SET_FLAG (tmp, FLAG_NO_PICK); |
618 | SET_FLAG (tmp, FLAG_NO_PICK); |
633 | |
619 | |
634 | /* |
620 | /* |
635 | * This doesn't work on non unique maps. pedestals under floor will not be saved... |
621 | * Str 1 is a flag that the item [pedestal] should go below the floor. |
636 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
622 | * Items under the floor on non-unique maps will not be saved, |
|
|
623 | * so make the item itself unique in this situation. |
637 | */ |
624 | */ |
638 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
625 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
|
|
626 | if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) |
|
|
627 | SET_FLAG (tmp, FLAG_UNIQUE); |
639 | |
628 | |
640 | connected = 0; |
629 | shstr_tmp connected; |
|
|
630 | |
641 | switch (tmp->type) |
631 | switch (tmp->type) |
642 | { |
632 | { |
643 | case DOOR: |
633 | case DOOR: |
644 | case GATE: |
634 | case GATE: |
645 | case BUTTON: |
635 | case BUTTON: |
646 | case DETECTOR: |
636 | case DETECTOR: |
647 | case TIMED_GATE: |
637 | case TIMED_GATE: |
648 | case PEDESTAL: |
638 | case PEDESTAL: |
649 | case CF_HANDLE: |
639 | case CF_HANDLE: |
650 | case MAGIC_EAR: |
640 | case MAGIC_EAR: |
651 | case SIGN: |
641 | case SIGN: |
652 | /* Signs don't need a connection, but but magic mouths do. */ |
642 | /* Signs don't need a connection, but but magic mouths do. */ |
653 | if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) |
643 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
654 | break; |
644 | break; |
|
|
645 | |
655 | con_rune = get_connection_rune (pl, x, y); |
646 | con_rune = get_connection_rune (pl, x, y); |
656 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
647 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
657 | if (connected == -1) |
648 | if (!connected) |
658 | { |
649 | { |
659 | /* Player already informed of failure by the previous function */ |
650 | /* Player already informed of failure by the previous function */ |
660 | tmp->destroy (0); |
651 | tmp->destroy (); |
661 | return; |
652 | return; |
662 | } |
653 | } |
|
|
654 | |
663 | /* Remove marking rune */ |
655 | /* Remove marking rune */ |
664 | con_rune->remove (); |
|
|
665 | con_rune->destroy (0); |
656 | con_rune->destroy (); |
666 | } |
657 | } |
667 | |
658 | |
668 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
659 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
669 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
660 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
670 | { |
661 | { |
671 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
662 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
672 | { |
663 | { |
673 | tmp->destroy (0); |
664 | tmp->destroy (); |
674 | return; |
665 | return; |
675 | } |
666 | } |
676 | } |
667 | } |
677 | |
668 | |
678 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
669 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
679 | if (connected != 0) |
670 | if (connected) |
680 | add_button_link (tmp, pl->map, connected); |
671 | tmp->add_link (pl->map, connected); |
681 | |
672 | |
682 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
673 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
683 | decrease_ob_nr (item, 1); |
674 | item->decrease (); |
684 | } |
675 | } |
685 | |
676 | |
686 | /** |
677 | /** |
687 | * Item remover. |
678 | * Item remover. |
688 | * |
679 | * |
… | |
… | |
701 | item = GET_MAP_OB (pl->map, x, y); |
692 | item = GET_MAP_OB (pl->map, x, y); |
702 | if (!item) |
693 | if (!item) |
703 | { |
694 | { |
704 | /* Should not happen with previous tests, but we never know */ |
695 | /* Should not happen with previous tests, but we never know */ |
705 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
696 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
706 | LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, pl->map->path); |
697 | LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path); |
707 | return; |
698 | return; |
708 | } |
699 | } |
709 | |
700 | |
710 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
701 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
711 | item = item->above; |
702 | item = item->above; |
712 | |
703 | |
713 | if (!item) |
704 | if (!item) |
714 | { |
|
|
715 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
705 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
716 | return; |
706 | else if (item->type == BUILDABLE_WALL) |
717 | } |
|
|
718 | |
|
|
719 | /* Now remove object, with special cases (buttons & such) */ |
|
|
720 | switch (item->type) |
|
|
721 | { |
|
|
722 | case WALL: |
|
|
723 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); |
707 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); |
724 | return; |
708 | else if (!item->flag [FLAG_IS_BUILDABLE]) |
725 | |
709 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); |
726 | case DOOR: |
710 | else |
727 | case BUTTON: |
711 | { |
728 | case GATE: |
|
|
729 | case TIMED_GATE: |
|
|
730 | case DETECTOR: |
|
|
731 | case PEDESTAL: |
|
|
732 | case CF_HANDLE: |
|
|
733 | case MAGIC_EAR: |
|
|
734 | case SIGN: |
|
|
735 | /* Special case: must unconnect */ |
|
|
736 | if (QUERY_FLAG (item, FLAG_IS_LINKED)) |
|
|
737 | remove_button_link (item); |
|
|
738 | |
|
|
739 | /* Fall through */ |
|
|
740 | |
|
|
741 | default: |
|
|
742 | /* Remove generic item */ |
|
|
743 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
712 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
744 | item->remove (); |
|
|
745 | item->destroy (0); |
713 | item->destroy (); |
746 | } |
714 | } |
747 | } |
715 | } |
748 | |
716 | |
749 | /** |
717 | /** |
750 | * Global building function |
718 | * Global building function |
… | |
… | |
776 | } |
744 | } |
777 | |
745 | |
778 | x = pl->x + freearr_x[dir]; |
746 | x = pl->x + freearr_x[dir]; |
779 | y = pl->y + freearr_y[dir]; |
747 | y = pl->y + freearr_y[dir]; |
780 | |
748 | |
781 | if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) |
749 | if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) |
782 | { |
750 | { |
783 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
751 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
784 | return; |
752 | return; |
785 | } |
753 | } |
786 | |
754 | |
… | |
… | |
793 | |
761 | |
794 | tmp = GET_MAP_OB (pl->map, x, y); |
762 | tmp = GET_MAP_OB (pl->map, x, y); |
795 | if (!tmp) |
763 | if (!tmp) |
796 | { |
764 | { |
797 | /* Nothing, meaning player is standing next to an undefined square... */ |
765 | /* Nothing, meaning player is standing next to an undefined square... */ |
798 | LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, pl->map->path); |
766 | LOG (llevError, "apply_map_builder: undefined square at (%d, %d, %s)\n", x, y, &pl->map->path); |
799 | new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); |
767 | new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); |
800 | return; |
768 | return; |
801 | } |
769 | } |
|
|
770 | |
802 | tmp2 = find_marked_object (pl); |
771 | tmp2 = find_marked_object (pl); |
803 | while (tmp) |
772 | while (tmp) |
804 | { |
773 | { |
805 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->name, "rune_mark")))) |
774 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
806 | { |
775 | { |
807 | /* The item building function already has it's own special |
776 | /* The item building function already has it's own special |
808 | * checks for this |
777 | * checks for this |
809 | */ |
778 | */ |
810 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
779 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
… | |
… | |
815 | } |
784 | } |
816 | tmp = tmp->above; |
785 | tmp = tmp->above; |
817 | } |
786 | } |
818 | |
787 | |
819 | /* Now we know the square is ok */ |
788 | /* Now we know the square is ok */ |
820 | builder = pl->contr->ranges[range_builder]; |
789 | builder = pl->contr->ranged_ob; |
821 | |
790 | |
822 | if (builder->subtype == ST_BD_REMOVE) |
791 | if (builder->subtype == ST_BD_REMOVE) |
823 | /* Remover -> call specific function and bail out */ |
792 | /* Remover -> call specific function and bail out */ |
824 | { |
793 | { |
825 | apply_builder_remove (pl, dir); |
794 | apply_builder_remove (pl, dir); |
… | |
… | |
893 | tmp->msg = book->msg; |
862 | tmp->msg = book->msg; |
894 | |
863 | |
895 | if (tmp->invisible) |
864 | if (tmp->invisible) |
896 | { |
865 | { |
897 | if (book->custom_name != NULL) |
866 | if (book->custom_name != NULL) |
898 | { |
|
|
899 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
867 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
900 | } |
|
|
901 | else |
868 | else |
902 | { |
|
|
903 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
869 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
904 | } |
870 | |
905 | tmp->name = buf; |
871 | tmp->name = buf; |
906 | |
872 | |
907 | if (book->name_pl != NULL) |
873 | if (book->name_pl != NULL) |
908 | { |
874 | { |
909 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
875 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
… | |
… | |
911 | } |
877 | } |
912 | |
878 | |
913 | tmp->face = book->face; |
879 | tmp->face = book->face; |
914 | tmp->invisible = 0; |
880 | tmp->invisible = 0; |
915 | } |
881 | } |
916 | book->remove (); |
882 | |
917 | book->destroy (0); |
883 | book->destroy (); |
918 | return 0; |
884 | return 0; |
919 | } |
885 | } |