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 it under |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | (at your option) any later version. |
11 | * 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 Affero GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
20 | |
21 | * |
21 | The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <living.h> |
26 | #include <living.h> |
26 | #include <spells.h> |
27 | #include <spells.h> |
27 | #include <skills.h> |
28 | #include <skills.h> |
… | |
… | |
38 | |
39 | |
39 | ob = GET_MAP_OB (map, x, y); |
40 | ob = GET_MAP_OB (map, x, y); |
40 | while (ob) |
41 | while (ob) |
41 | { |
42 | { |
42 | /* if ob is not a marking rune or floor, then check special cases */ |
43 | /* if ob is not a marking rune or floor, then check special cases */ |
43 | if (strcmp (ob->arch->name, "rune_mark") && ob->type != FLOOR) |
44 | if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR) |
44 | { |
45 | { |
45 | switch (tmp->type) |
46 | switch (tmp->type) |
46 | { |
47 | { |
47 | case SIGN: |
48 | case SIGN: |
48 | case MAGIC_EAR: |
49 | case MAGIC_EAR: |
49 | /* Allow signs and magic ears to be built on books */ |
50 | /* Allow signs and magic ears to be built on books */ |
50 | if (ob->type != BOOK) |
51 | 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; |
52 | return 0; |
|
|
53 | break; |
|
|
54 | case BUTTON: |
|
|
55 | case DETECTOR: |
|
|
56 | case PEDESTAL: |
|
|
57 | case T_HANDLE: |
|
|
58 | /* Allow buttons and levers to be built under gates */ |
|
|
59 | if (ob->type != GATE && ob->type != DOOR) |
|
|
60 | return 0; |
|
|
61 | break; |
|
|
62 | default: |
|
|
63 | return 0; |
67 | } |
64 | } |
68 | } |
65 | } |
|
|
66 | |
69 | ob = ob->above; |
67 | ob = ob->above; |
70 | } |
68 | } |
71 | return 1; |
69 | return 1; |
72 | } |
70 | } |
73 | |
71 | |
… | |
… | |
82 | |
80 | |
83 | rune = GET_MAP_OB (map, x, y); |
81 | rune = GET_MAP_OB (map, x, y); |
84 | while (rune) |
82 | while (rune) |
85 | { |
83 | { |
86 | next = rune->above; |
84 | next = rune->above; |
|
|
85 | |
87 | if ((rune->type == SIGN) && (!strcmp (rune->arch->name, "rune_mark"))) |
86 | if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark) |
88 | { |
|
|
89 | rune->remove (); |
|
|
90 | rune->destroy (0); |
87 | rune->destroy (); |
91 | } |
88 | |
92 | rune = next; |
89 | rune = next; |
93 | } |
90 | } |
94 | } |
91 | } |
95 | |
92 | |
96 | /** |
93 | /** |
… | |
… | |
98 | * \param map: map for which to find a value |
95 | * \param map: map for which to find a value |
99 | * \return 'connected' value with no item, or -1 if failure. |
96 | * \return 'connected' value with no item, or -1 if failure. |
100 | * |
97 | * |
101 | * Tries 1000 random values, then returns -1. |
98 | * Tries 1000 random values, then returns -1. |
102 | */ |
99 | */ |
103 | int |
100 | static shstr_tmp |
104 | find_unused_connected_value (maptile *map) |
101 | find_unused_connected_value (maptile *map) |
105 | { |
102 | { |
106 | int connected = 0; |
103 | 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 | } |
104 | { |
|
|
105 | char buf[64]; |
118 | |
106 | |
119 | return -1; |
107 | snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U); |
120 | } |
|
|
121 | |
108 | |
|
|
109 | shstr id (buf); |
|
|
110 | |
|
|
111 | if (!map->find_link (id)) |
|
|
112 | return id; |
|
|
113 | } |
|
|
114 | |
|
|
115 | return shstr_tmp (); |
|
|
116 | } |
122 | |
117 | |
123 | /** |
118 | /** |
124 | * Helper function for door/button/connected item building. |
119 | * Helper function for door/button/connected item building. |
125 | * |
120 | * |
126 | * Will search the specified spot for a marking rune. |
121 | * Will search the specified spot for a marking rune. |
… | |
… | |
128 | * Else, searches a force in op's inventory matching the map's name |
123 | * Else, searches a force in op's inventory matching the map's name |
129 | * and the rune's text. |
124 | * and the rune's text. |
130 | * If found, returns the connection value associated |
125 | * If found, returns the connection value associated |
131 | * else searches a new connection value, and adds the force to the player. |
126 | * else searches a new connection value, and adds the force to the player. |
132 | */ |
127 | */ |
133 | int |
128 | static shstr_tmp |
134 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
129 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
135 | { |
130 | { |
136 | object *force; |
131 | object *force; |
137 | int connected; |
|
|
138 | |
132 | |
139 | if (!rune) |
133 | if (!rune) |
140 | rune = get_connection_rune (pl, x, y); |
134 | rune = get_connection_rune (pl, x, y); |
141 | |
135 | |
142 | if (!rune) |
136 | if (!rune) |
143 | { |
137 | { |
144 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
138 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
145 | return -1; |
139 | return shstr_tmp (); |
146 | } |
140 | } |
147 | |
141 | |
148 | /* Now, find force in player's inventory */ |
142 | /* Now, find force in player's inventory */ |
149 | force = pl->inv; |
143 | force = pl->inv; |
150 | while (force |
144 | while (force |
151 | && ((force->type != FORCE) || (!force->slaying) || (strcmp (force->slaying, pl->map->path)) || (!force->msg) |
145 | && ((force->type != FORCE) || !force->slaying || force->slaying != pl->map->path || !force->msg |
152 | || (strcmp (force->msg, rune->msg)))) |
146 | || force->msg != rune->msg)) |
153 | force = force->below; |
147 | force = force->below; |
154 | |
148 | |
155 | if (!force) |
149 | if (!force) |
156 | /* No force, need to create & insert one */ |
150 | /* No force, need to create & insert one */ |
157 | { |
151 | { |
158 | /* Find unused value */ |
152 | /* Find unused value */ |
159 | connected = find_unused_connected_value (pl->map); |
153 | shstr_tmp id = find_unused_connected_value (pl->map); |
160 | if (connected == -1) |
154 | |
|
|
155 | if (!id) |
161 | { |
156 | { |
162 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
157 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
163 | return -1; |
158 | return shstr_tmp (); |
164 | } |
159 | } |
165 | |
160 | |
166 | force = get_archetype (FORCE_NAME); |
161 | force = get_archetype (FORCE_NAME); |
167 | force->speed = 0; |
|
|
168 | update_ob_speed (force); |
|
|
169 | force->slaying = pl->map->path; |
162 | force->slaying = pl->map->path; |
170 | force->msg = rune->msg; |
163 | force->msg = rune->msg; |
171 | force->path_attuned = connected; |
164 | force->race = id; |
|
|
165 | force->set_speed (0); |
|
|
166 | |
172 | insert_ob_in_ob (force, pl); |
167 | insert_ob_in_ob (force, pl); |
173 | |
168 | |
174 | return connected; |
169 | return id; |
175 | } |
170 | } |
176 | |
171 | |
177 | /* Found the force, everything's easy. */ |
172 | /* Found the force, everything's easy. */ |
178 | return force->path_attuned; |
173 | return force->race; |
179 | } |
174 | } |
180 | |
175 | |
181 | /** |
176 | /** |
182 | * Returns the marking rune on the square, for purposes of building connections |
177 | * Returns the marking rune on the square, for purposes of building connections |
183 | */ |
178 | */ |
184 | object * |
179 | object * |
185 | get_connection_rune (object *pl, short x, short y) |
180 | get_connection_rune (object *pl, short x, short y) |
186 | { |
181 | { |
187 | object *rune; |
|
|
188 | |
|
|
189 | rune = GET_MAP_OB (pl->map, x, y); |
182 | object *rune = GET_MAP_OB (pl->map, x, y); |
|
|
183 | |
190 | while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->name, "rune_mark")))) |
184 | while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark)) |
191 | rune = rune->above; |
185 | rune = rune->above; |
|
|
186 | |
192 | return rune; |
187 | return rune; |
193 | } |
188 | } |
194 | |
189 | |
195 | /** |
190 | /** |
196 | * Returns the book/scroll on the current square, for purposes of building |
191 | * Returns the book/scroll on the current square, for purposes of building |
197 | */ |
192 | */ |
198 | object * |
193 | object * |
199 | get_msg_book (object *pl, short x, short y) |
194 | get_msg_book (object *pl, short x, short y) |
200 | { |
195 | { |
201 | object *book; |
|
|
202 | |
|
|
203 | book = GET_MAP_OB (pl->map, x, y); |
196 | object *book = GET_MAP_OB (pl->map, x, y); |
|
|
197 | |
204 | while (book && (book->type != BOOK)) |
198 | while (book && (book->type != BOOK)) |
205 | book = book->above; |
199 | book = book->above; |
|
|
200 | |
206 | return book; |
201 | return book; |
207 | } |
202 | } |
208 | |
203 | |
209 | /** |
204 | /** |
210 | * Returns first item of type WALL. |
205 | * Returns first item of type BUILDABLE_WALL. |
211 | */ |
206 | */ |
212 | object * |
207 | object * |
213 | get_wall (maptile *map, int x, int y) |
208 | get_wall (maptile *map, int x, int y) |
214 | { |
209 | { |
215 | object *wall; |
|
|
216 | |
|
|
217 | wall = GET_MAP_OB (map, x, y); |
210 | object *wall = GET_MAP_OB (map, x, y); |
|
|
211 | |
218 | while (wall && (WALL != wall->type)) |
212 | while (wall && (BUILDABLE_WALL != wall->type)) |
219 | wall = wall->above; |
213 | wall = wall->above; |
220 | |
214 | |
221 | return wall; |
215 | return wall; |
222 | } |
216 | } |
223 | |
217 | |
… | |
… | |
233 | * Note: x & y must be valid map coordinates. |
227 | * Note: x & y must be valid map coordinates. |
234 | */ |
228 | */ |
235 | void |
229 | void |
236 | fix_walls (maptile *map, int x, int y) |
230 | fix_walls (maptile *map, int x, int y) |
237 | { |
231 | { |
238 | int connect; |
|
|
239 | object *wall; |
|
|
240 | char archetype[MAX_BUF]; |
232 | char archetype[MAX_BUF]; |
241 | char *underscore; |
233 | char *underscore; |
242 | uint32 old_flags[4]; |
|
|
243 | struct archetype *new_arch; |
234 | struct archetype *new_arch; |
244 | int flag; |
|
|
245 | |
|
|
246 | |
235 | |
247 | /* First, find the wall on that spot */ |
236 | /* First, find the wall on that spot */ |
248 | wall = get_wall (map, x, y); |
237 | object *wall = get_wall (map, x, y); |
249 | if (!wall) |
238 | if (!wall) |
250 | /* Nothing -> bail out */ |
239 | /* Nothing -> bail out */ |
251 | return; |
240 | return; |
252 | |
241 | |
253 | /* Find base name */ |
242 | /* Find base name */ |
254 | strcpy (archetype, wall->arch->name); |
243 | assign (archetype, wall->arch->archname); |
255 | underscore = strchr (archetype, '_'); |
244 | underscore = strchr (archetype, '_'); |
256 | |
245 | |
257 | /* search for the first _ before a number */ |
246 | /* search for the first _ before a number */ |
258 | while (underscore && !isdigit (*(underscore + 1))) |
247 | while (underscore && !isdigit (*(underscore + 1))) |
259 | underscore = strchr (underscore + 1, '_'); |
248 | underscore = strchr (underscore + 1, '_'); |
… | |
… | |
263 | return; |
252 | return; |
264 | |
253 | |
265 | underscore++; |
254 | underscore++; |
266 | *underscore = '\0'; |
255 | *underscore = '\0'; |
267 | |
256 | |
268 | connect = 0; |
257 | int connect = 0; |
269 | |
258 | |
270 | if ((x > 0) && get_wall (map, x - 1, y)) |
259 | if (x > 0 && get_wall (map, x - 1, y)) connect |= 1; |
271 | connect |= 1; |
260 | if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2; |
272 | if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) |
261 | if (y > 0 && get_wall (map, x, y - 1)) connect |= 4; |
273 | connect |= 2; |
262 | if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8; |
274 | |
263 | |
275 | if ((y > 0) && get_wall (map, x, y - 1)) |
264 | // one bit per dir, 1 left, 2 right, 4 up, 8 down |
276 | connect |= 4; |
265 | static const char *walltype[16] = { |
|
|
266 | "0", |
|
|
267 | "1_3", |
|
|
268 | "1_4", |
|
|
269 | "2_1_2", |
|
|
270 | "1_2", |
|
|
271 | "2_2_4", |
|
|
272 | "2_2_1", |
|
|
273 | "3_1", |
|
|
274 | "1_1", |
|
|
275 | "2_2_3", |
|
|
276 | "2_2_2", |
|
|
277 | "3_3", |
|
|
278 | "2_1_1", |
|
|
279 | "3_4", |
|
|
280 | "3_2", |
|
|
281 | "4" |
|
|
282 | }; |
277 | |
283 | |
278 | if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) |
284 | strcat (archetype, walltype [connect]); |
279 | connect |= 8; |
|
|
280 | |
|
|
281 | switch (connect) |
|
|
282 | { |
|
|
283 | case 0: |
|
|
284 | strcat (archetype, "0"); |
|
|
285 | |
|
|
286 | break; |
|
|
287 | case 1: |
|
|
288 | strcat (archetype, "1_3"); |
|
|
289 | |
|
|
290 | break; |
|
|
291 | case 2: |
|
|
292 | strcat (archetype, "1_4"); |
|
|
293 | |
|
|
294 | break; |
|
|
295 | case 3: |
|
|
296 | strcat (archetype, "2_1_2"); |
|
|
297 | |
|
|
298 | break; |
|
|
299 | case 4: |
|
|
300 | strcat (archetype, "1_2"); |
|
|
301 | |
|
|
302 | break; |
|
|
303 | case 5: |
|
|
304 | strcat (archetype, "2_2_4"); |
|
|
305 | |
|
|
306 | break; |
|
|
307 | case 6: |
|
|
308 | strcat (archetype, "2_2_1"); |
|
|
309 | |
|
|
310 | break; |
|
|
311 | case 7: |
|
|
312 | strcat (archetype, "3_1"); |
|
|
313 | |
|
|
314 | break; |
|
|
315 | case 8: |
|
|
316 | strcat (archetype, "1_1"); |
|
|
317 | |
|
|
318 | break; |
|
|
319 | case 9: |
|
|
320 | strcat (archetype, "2_2_3"); |
|
|
321 | |
|
|
322 | break; |
|
|
323 | case 10: |
|
|
324 | strcat (archetype, "2_2_2"); |
|
|
325 | |
|
|
326 | break; |
|
|
327 | case 11: |
|
|
328 | strcat (archetype, "3_3"); |
|
|
329 | |
|
|
330 | break; |
|
|
331 | case 12: |
|
|
332 | strcat (archetype, "2_1_1"); |
|
|
333 | |
|
|
334 | break; |
|
|
335 | case 13: |
|
|
336 | strcat (archetype, "3_4"); |
|
|
337 | |
|
|
338 | break; |
|
|
339 | case 14: |
|
|
340 | strcat (archetype, "3_2"); |
|
|
341 | |
|
|
342 | break; |
|
|
343 | case 15: |
|
|
344 | strcat (archetype, "4"); |
|
|
345 | |
|
|
346 | break; |
|
|
347 | } |
|
|
348 | |
285 | |
349 | /* |
286 | /* |
350 | * Before anything, make sure the archetype does exist... |
287 | * Before anything, make sure the archetype does exist... |
351 | * If not, prolly an error... |
288 | * If not, prolly an error... |
352 | */ |
289 | */ |
… | |
… | |
356 | return; |
293 | return; |
357 | |
294 | |
358 | /* Now delete current wall, and insert new one |
295 | /* Now delete current wall, and insert new one |
359 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
296 | * We save flags to avoid any trouble with buildable/non buildable, and so on |
360 | */ |
297 | */ |
361 | for (flag = 0; flag < 4; flag++) |
298 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
362 | old_flags[flag] = wall->flags[flag]; |
299 | |
363 | wall->remove (); |
|
|
364 | wall->destroy (0); |
300 | wall->destroy (); |
365 | |
301 | |
366 | wall = arch_to_object (new_arch); |
302 | wall = arch_to_object (new_arch); |
367 | wall->type = WALL; |
303 | wall->type = BUILDABLE_WALL; |
368 | insert_ob_in_map_at (wall, map, NULL, INS_ABOVE_FLOOR_ONLY, x, y); |
304 | 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]; |
305 | wall->flag = old_flags; |
371 | } |
306 | } |
372 | |
307 | |
373 | /** |
308 | /** |
374 | * \brief Floor building function |
309 | * \brief Floor building function |
375 | * |
310 | * |
… | |
… | |
403 | if (tmp) |
338 | if (tmp) |
404 | { |
339 | { |
405 | while (tmp) |
340 | while (tmp) |
406 | { |
341 | { |
407 | above = tmp->above; |
342 | above = tmp->above; |
408 | if (WALL == tmp->type) |
343 | if (BUILDABLE_WALL == tmp->type) |
409 | { |
344 | { |
410 | /* There was a wall, remove it & keep its archetype to make new walls */ |
345 | /* There was a wall, remove it & keep its archetype to make new walls */ |
411 | new_wall = tmp->arch; |
346 | new_wall = tmp->arch; |
412 | tmp->remove (); |
|
|
413 | tmp->destroy (0); |
347 | tmp->destroy (); |
414 | sprintf (message, "You destroy the wall and redo the floor."); |
348 | sprintf (message, "You destroy the wall and redo the floor."); |
415 | } |
349 | } |
416 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
350 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
417 | { |
351 | { |
418 | tmp->remove (); |
|
|
419 | tmp->destroy (0); |
352 | tmp->destroy (); |
420 | floor_removed = 1; |
353 | floor_removed = 1; |
421 | } |
354 | } |
422 | else |
355 | else |
423 | { |
356 | { |
424 | if (floor_removed) |
357 | if (floor_removed) |
|
|
358 | { |
|
|
359 | /* This is the first item that was above the floor */ |
425 | above_floor = tmp; |
360 | above_floor = tmp; |
|
|
361 | floor_removed = 0; |
|
|
362 | } |
426 | } |
363 | } |
427 | |
364 | |
428 | tmp = above; |
365 | tmp = above; |
429 | } |
366 | } |
430 | } |
367 | } |
… | |
… | |
466 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
403 | /* Insert wall if exists. Note: if it doesn't, the map is weird... */ |
467 | if (new_wall) |
404 | if (new_wall) |
468 | { |
405 | { |
469 | tmp = arch_to_object (new_wall); |
406 | tmp = arch_to_object (new_wall); |
470 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
407 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
471 | tmp->type = WALL; |
408 | tmp->type = BUILDABLE_WALL; |
472 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
409 | insert_ob_in_map_at (tmp, pl->map, 0, 0, xt, yt); |
473 | } |
410 | } |
474 | } |
411 | } |
475 | } |
412 | } |
476 | |
413 | |
… | |
… | |
484 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
421 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
485 | fix_walls (pl->map, xt, yt); |
422 | fix_walls (pl->map, xt, yt); |
486 | } |
423 | } |
487 | |
424 | |
488 | /* Now remove raw item from inventory */ |
425 | /* Now remove raw item from inventory */ |
489 | decrease_ob (material); |
426 | material->decrease (); |
490 | |
427 | |
491 | /* And tell player about the fix */ |
428 | /* And tell player about the fix */ |
492 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
429 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
493 | } |
430 | } |
494 | |
431 | |
… | |
… | |
528 | /* Grab existing wall, if any */ |
465 | /* Grab existing wall, if any */ |
529 | current_wall = NULL; |
466 | current_wall = NULL; |
530 | tmp = GET_MAP_OB (pl->map, x, y); |
467 | tmp = GET_MAP_OB (pl->map, x, y); |
531 | while (tmp && !current_wall) |
468 | while (tmp && !current_wall) |
532 | { |
469 | { |
533 | if (WALL == tmp->type) |
470 | if (BUILDABLE_WALL == tmp->type) |
534 | current_wall = tmp; |
471 | current_wall = tmp; |
535 | |
472 | |
536 | tmp = tmp->above; |
473 | tmp = tmp->above; |
537 | } |
474 | } |
538 | |
475 | |
… | |
… | |
546 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
483 | LOG (llevError, "apply_builder_wall: unable to find archetype %s\n", &material->slaying); |
547 | return; |
484 | return; |
548 | } |
485 | } |
549 | |
486 | |
550 | tmp = arch_to_object (new_wall); |
487 | tmp = arch_to_object (new_wall); |
551 | tmp->type = WALL; |
488 | tmp->type = BUILDABLE_WALL; |
552 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
489 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
553 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
490 | insert_ob_in_map_at (tmp, pl->map, 0, INS_ABOVE_FLOOR_ONLY, x, y); |
554 | |
491 | |
555 | /* If existing wall, remove it, no need to fix other walls */ |
492 | /* If existing wall, remove it, no need to fix other walls */ |
556 | if (current_wall) |
493 | if (current_wall) |
557 | { |
494 | { |
558 | current_wall->remove (); |
|
|
559 | current_wall->destroy (0); |
495 | current_wall->destroy (); |
560 | fix_walls (pl->map, x, y); |
496 | fix_walls (pl->map, x, y); |
561 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
497 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
562 | } |
498 | } |
563 | else |
499 | else |
564 | { |
500 | { |
… | |
… | |
572 | fix_walls (pl->map, xt, yt); |
508 | fix_walls (pl->map, xt, yt); |
573 | } |
509 | } |
574 | } |
510 | } |
575 | |
511 | |
576 | /* Now remove item from inventory */ |
512 | /* Now remove item from inventory */ |
577 | decrease_ob (material); |
513 | material->decrease (); |
578 | |
514 | |
579 | /* And tell player what happened */ |
515 | /* And tell player what happened */ |
580 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
516 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
581 | } |
517 | } |
582 | |
518 | |
… | |
… | |
594 | object *tmp; |
530 | object *tmp; |
595 | struct archetype *arch; |
531 | struct archetype *arch; |
596 | int insert_flag; |
532 | int insert_flag; |
597 | object *floor; |
533 | object *floor; |
598 | object *con_rune; |
534 | object *con_rune; |
599 | int connected; |
|
|
600 | |
535 | |
601 | /* Find floor */ |
536 | /* Find floor */ |
602 | floor = GET_MAP_OB (pl->map, x, y); |
537 | floor = GET_MAP_OB (pl->map, x, y); |
603 | if (!floor) |
538 | if (!floor) |
604 | { |
539 | { |
… | |
… | |
619 | if (!arch) |
554 | if (!arch) |
620 | return; |
555 | return; |
621 | |
556 | |
622 | tmp = arch_to_object (arch); |
557 | tmp = arch_to_object (arch); |
623 | |
558 | |
624 | if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) |
559 | 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 */ |
560 | /* Floor has something on top that interferes with building */ |
626 | { |
561 | { |
627 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
562 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
628 | return; |
563 | return; |
629 | } |
564 | } |
630 | |
565 | |
631 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
566 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
632 | SET_FLAG (tmp, FLAG_NO_PICK); |
567 | SET_FLAG (tmp, FLAG_NO_PICK); |
633 | |
568 | |
634 | /* |
569 | /* |
635 | * This doesn't work on non unique maps. pedestals under floor will not be saved... |
570 | * 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; |
571 | * Items under the floor on non-unique maps will not be saved, |
|
|
572 | * so make the item itself unique in this situation. |
637 | */ |
573 | */ |
638 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
574 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
|
|
575 | if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) |
|
|
576 | SET_FLAG (tmp, FLAG_UNIQUE); |
639 | |
577 | |
640 | connected = 0; |
578 | shstr_tmp connected; |
|
|
579 | |
641 | switch (tmp->type) |
580 | switch (tmp->type) |
642 | { |
581 | { |
643 | case DOOR: |
582 | case DOOR: |
644 | case GATE: |
583 | case GATE: |
645 | case BUTTON: |
584 | case BUTTON: |
646 | case DETECTOR: |
585 | case DETECTOR: |
647 | case TIMED_GATE: |
586 | case TIMED_GATE: |
648 | case PEDESTAL: |
587 | case PEDESTAL: |
649 | case CF_HANDLE: |
588 | case T_HANDLE: |
650 | case MAGIC_EAR: |
589 | case MAGIC_EAR: |
651 | case SIGN: |
590 | case SIGN: |
652 | /* Signs don't need a connection, but but magic mouths do. */ |
591 | /* Signs don't need a connection, but but magic mouths do. */ |
653 | if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) |
592 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
654 | break; |
593 | break; |
|
|
594 | |
655 | con_rune = get_connection_rune (pl, x, y); |
595 | con_rune = get_connection_rune (pl, x, y); |
656 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
596 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
657 | if (connected == -1) |
597 | if (!connected) |
658 | { |
598 | { |
659 | /* Player already informed of failure by the previous function */ |
599 | /* Player already informed of failure by the previous function */ |
660 | tmp->destroy (0); |
600 | tmp->destroy (); |
661 | return; |
601 | return; |
662 | } |
602 | } |
|
|
603 | |
663 | /* Remove marking rune */ |
604 | /* Remove marking rune */ |
664 | con_rune->remove (); |
|
|
665 | con_rune->destroy (0); |
605 | con_rune->destroy (); |
666 | } |
606 | } |
667 | |
607 | |
668 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
608 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
669 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
609 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
670 | { |
610 | { |
671 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
611 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
672 | { |
612 | { |
673 | tmp->destroy (0); |
613 | tmp->destroy (); |
674 | return; |
614 | return; |
675 | } |
615 | } |
676 | } |
616 | } |
677 | |
617 | |
678 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
618 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
679 | if (connected != 0) |
619 | if (connected) |
680 | add_button_link (tmp, pl->map, connected); |
620 | tmp->add_link (pl->map, connected); |
681 | |
621 | |
682 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
622 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
683 | decrease_ob_nr (item, 1); |
623 | item->decrease (); |
684 | } |
624 | } |
685 | |
625 | |
686 | /** |
626 | /** |
687 | * Item remover. |
627 | * Item remover. |
688 | * |
628 | * |
… | |
… | |
701 | item = GET_MAP_OB (pl->map, x, y); |
641 | item = GET_MAP_OB (pl->map, x, y); |
702 | if (!item) |
642 | if (!item) |
703 | { |
643 | { |
704 | /* Should not happen with previous tests, but we never know */ |
644 | /* Should not happen with previous tests, but we never know */ |
705 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
645 | 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); |
646 | LOG (llevError, "apply_builder_remove: (null) square at (%d, %d, %s)\n", x, y, &pl->map->path); |
707 | return; |
647 | return; |
708 | } |
648 | } |
709 | |
649 | |
710 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
650 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
711 | item = item->above; |
651 | item = item->above; |
712 | |
652 | |
713 | if (!item) |
653 | if (!item) |
714 | { |
|
|
715 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
654 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
716 | return; |
655 | 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."); |
656 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't remove a wall with that, build a floor."); |
724 | return; |
657 | else if (!item->flag [FLAG_IS_BUILDABLE]) |
725 | |
658 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); |
726 | case DOOR: |
659 | else |
727 | case BUTTON: |
660 | { |
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)); |
661 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You remove the %s", query_name (item)); |
744 | item->remove (); |
|
|
745 | item->destroy (0); |
662 | item->destroy (); |
746 | } |
663 | } |
747 | } |
664 | } |
748 | |
665 | |
749 | /** |
666 | /** |
750 | * Global building function |
667 | * Global building function |
… | |
… | |
776 | } |
693 | } |
777 | |
694 | |
778 | x = pl->x + freearr_x[dir]; |
695 | x = pl->x + freearr_x[dir]; |
779 | y = pl->y + freearr_y[dir]; |
696 | y = pl->y + freearr_y[dir]; |
780 | |
697 | |
781 | if ((1 > x) || (1 > y) || ((MAP_WIDTH (pl->map) - 2) < x) || ((MAP_HEIGHT (pl->map) - 2) < y)) |
698 | if ((1 > x) || (1 > y) || ((pl->map->width - 2) < x) || ((pl->map->height - 2) < y)) |
782 | { |
699 | { |
783 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
700 | new_draw_info (NDI_UNIQUE, 0, pl, "Can't build on map edge..."); |
784 | return; |
701 | return; |
785 | } |
702 | } |
786 | |
703 | |
… | |
… | |
793 | |
710 | |
794 | tmp = GET_MAP_OB (pl->map, x, y); |
711 | tmp = GET_MAP_OB (pl->map, x, y); |
795 | if (!tmp) |
712 | if (!tmp) |
796 | { |
713 | { |
797 | /* Nothing, meaning player is standing next to an undefined square... */ |
714 | /* 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); |
715 | 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."); |
716 | new_draw_info (NDI_UNIQUE, 0, pl, "You'd better not build here, it looks weird."); |
800 | return; |
717 | return; |
801 | } |
718 | } |
|
|
719 | |
802 | tmp2 = find_marked_object (pl); |
720 | tmp2 = find_marked_object (pl); |
803 | while (tmp) |
721 | while (tmp) |
804 | { |
722 | { |
805 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->name, "rune_mark")))) |
723 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
806 | { |
724 | { |
807 | /* The item building function already has it's own special |
725 | /* The item building function already has it's own special |
808 | * checks for this |
726 | * checks for this |
809 | */ |
727 | */ |
810 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
728 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
… | |
… | |
815 | } |
733 | } |
816 | tmp = tmp->above; |
734 | tmp = tmp->above; |
817 | } |
735 | } |
818 | |
736 | |
819 | /* Now we know the square is ok */ |
737 | /* Now we know the square is ok */ |
820 | builder = pl->contr->ranges[range_builder]; |
738 | builder = pl->contr->ranged_ob; |
821 | |
739 | |
822 | if (builder->subtype == ST_BD_REMOVE) |
740 | if (builder->subtype == ST_BD_REMOVE) |
823 | /* Remover -> call specific function and bail out */ |
741 | /* Remover -> call specific function and bail out */ |
824 | { |
742 | { |
825 | apply_builder_remove (pl, dir); |
743 | apply_builder_remove (pl, dir); |
… | |
… | |
893 | tmp->msg = book->msg; |
811 | tmp->msg = book->msg; |
894 | |
812 | |
895 | if (tmp->invisible) |
813 | if (tmp->invisible) |
896 | { |
814 | { |
897 | if (book->custom_name != NULL) |
815 | if (book->custom_name != NULL) |
898 | { |
|
|
899 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
816 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
900 | } |
|
|
901 | else |
817 | else |
902 | { |
|
|
903 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
818 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
904 | } |
819 | |
905 | tmp->name = buf; |
820 | tmp->name = buf; |
906 | |
821 | |
907 | if (book->name_pl != NULL) |
822 | if (book->name_pl != NULL) |
908 | { |
823 | { |
909 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
824 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
… | |
… | |
911 | } |
826 | } |
912 | |
827 | |
913 | tmp->face = book->face; |
828 | tmp->face = book->face; |
914 | tmp->invisible = 0; |
829 | tmp->invisible = 0; |
915 | } |
830 | } |
916 | book->remove (); |
831 | |
917 | book->destroy (0); |
832 | book->destroy (); |
918 | return 0; |
833 | return 0; |
919 | } |
834 | } |