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