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