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 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 | { |
91 | rune->destroy (); |
89 | remove_ob (rune); |
92 | |
90 | free_object (rune); |
|
|
91 | } |
|
|
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 = get_archetype (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 | 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 | /** |
210 | * Returns first item of type WALL. |
253 | * Returns first item of type BUILDABLE_WALL. |
211 | */ |
254 | */ |
212 | object * |
255 | static object * |
213 | get_wall (maptile *map, int x, int y) |
256 | get_wall (maptile *map, int x, int y) |
214 | { |
257 | { |
215 | object *wall; |
|
|
216 | |
|
|
217 | wall = GET_MAP_OB (map, x, y); |
258 | object *wall = GET_MAP_OB (map, x, y); |
|
|
259 | |
218 | while (wall && (WALL != wall->type)) |
260 | while (wall && (BUILDABLE_WALL != wall->type)) |
219 | wall = wall->above; |
261 | wall = wall->above; |
220 | |
262 | |
221 | return wall; |
263 | return wall; |
222 | } |
264 | } |
223 | |
265 | |
… | |
… | |
230 | * |
272 | * |
231 | * Basically it ensures the correct wall is put where needed. |
273 | * Basically it ensures the correct wall is put where needed. |
232 | * |
274 | * |
233 | * Note: x & y must be valid map coordinates. |
275 | * Note: x & y must be valid map coordinates. |
234 | */ |
276 | */ |
235 | void |
277 | static void |
236 | fix_walls (maptile *map, int x, int y) |
278 | fix_walls (maptile *map, int x, int y) |
237 | { |
279 | { |
238 | int connect; |
|
|
239 | object *wall; |
|
|
240 | char archetype[MAX_BUF]; |
280 | char archetype[MAX_BUF]; |
241 | char *underscore; |
281 | char *underscore; |
242 | uint32 old_flags[4]; |
|
|
243 | struct archetype *new_arch; |
282 | struct archetype *new_arch; |
244 | int flag; |
|
|
245 | |
283 | |
246 | /* First, find the wall on that spot */ |
284 | /* First, find the wall on that spot */ |
247 | wall = get_wall (map, x, y); |
285 | object *wall = get_wall (map, x, y); |
248 | if (!wall) |
286 | if (!wall) |
249 | /* Nothing -> bail out */ |
287 | /* Nothing -> bail out */ |
250 | return; |
288 | return; |
251 | |
289 | |
252 | /* Find base name */ |
290 | /* Find base name */ |
253 | strcpy (archetype, wall->arch->name); |
291 | assign (archetype, wall->arch->archname); |
254 | underscore = strchr (archetype, '_'); |
292 | underscore = strchr (archetype, '_'); |
255 | |
293 | |
|
|
294 | /* search for the first _ before a number */ |
|
|
295 | while (underscore && !isdigit (*(underscore + 1))) |
|
|
296 | underscore = strchr (underscore + 1, '_'); |
|
|
297 | |
256 | if (!underscore || (!isdigit (*(underscore + 1)))) |
298 | if (!underscore || !isdigit (*(underscore + 1))) |
257 | /* Not in a format we can change, bail out */ |
299 | /* Not in a format we can change, bail out */ |
258 | return; |
300 | return; |
259 | |
301 | |
260 | underscore++; |
302 | underscore++; |
261 | *underscore = '\0'; |
303 | *underscore = '\0'; |
262 | |
304 | |
263 | connect = 0; |
305 | int connect = 0; |
264 | |
306 | |
265 | if ((x > 0) && get_wall (map, x - 1, y)) |
307 | if (x > 0 && get_wall (map, x - 1, y)) connect |= 1; |
266 | connect |= 1; |
308 | if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2; |
267 | if ((x < MAP_WIDTH (map) - 1) && get_wall (map, x + 1, y)) |
309 | if (y > 0 && get_wall (map, x, y - 1)) connect |= 4; |
268 | connect |= 2; |
310 | if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8; |
269 | |
311 | |
270 | if ((y > 0) && get_wall (map, x, y - 1)) |
312 | // one bit per dir, 1 left, 2 right, 4 up, 8 down |
271 | 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 | }; |
272 | |
331 | |
273 | if ((y < MAP_HEIGHT (map) - 1) && get_wall (map, x, y + 1)) |
332 | strcat (archetype, walltype [connect]); |
274 | connect |= 8; |
|
|
275 | |
|
|
276 | switch (connect) |
|
|
277 | { |
|
|
278 | case 0: |
|
|
279 | strcat (archetype, "0"); |
|
|
280 | |
|
|
281 | break; |
|
|
282 | case 1: |
|
|
283 | strcat (archetype, "1_3"); |
|
|
284 | |
|
|
285 | break; |
|
|
286 | case 2: |
|
|
287 | strcat (archetype, "1_4"); |
|
|
288 | |
|
|
289 | break; |
|
|
290 | case 3: |
|
|
291 | strcat (archetype, "2_1_2"); |
|
|
292 | |
|
|
293 | break; |
|
|
294 | case 4: |
|
|
295 | strcat (archetype, "1_2"); |
|
|
296 | |
|
|
297 | break; |
|
|
298 | case 5: |
|
|
299 | strcat (archetype, "2_2_4"); |
|
|
300 | |
|
|
301 | break; |
|
|
302 | case 6: |
|
|
303 | strcat (archetype, "2_2_1"); |
|
|
304 | |
|
|
305 | break; |
|
|
306 | case 7: |
|
|
307 | strcat (archetype, "3_1"); |
|
|
308 | |
|
|
309 | break; |
|
|
310 | case 8: |
|
|
311 | strcat (archetype, "1_1"); |
|
|
312 | |
|
|
313 | break; |
|
|
314 | case 9: |
|
|
315 | strcat (archetype, "2_2_3"); |
|
|
316 | |
|
|
317 | break; |
|
|
318 | case 10: |
|
|
319 | strcat (archetype, "2_2_2"); |
|
|
320 | |
|
|
321 | break; |
|
|
322 | case 11: |
|
|
323 | strcat (archetype, "3_3"); |
|
|
324 | |
|
|
325 | break; |
|
|
326 | case 12: |
|
|
327 | strcat (archetype, "2_1_1"); |
|
|
328 | |
|
|
329 | break; |
|
|
330 | case 13: |
|
|
331 | strcat (archetype, "3_4"); |
|
|
332 | |
|
|
333 | break; |
|
|
334 | case 14: |
|
|
335 | strcat (archetype, "3_2"); |
|
|
336 | |
|
|
337 | break; |
|
|
338 | case 15: |
|
|
339 | strcat (archetype, "4"); |
|
|
340 | |
|
|
341 | break; |
|
|
342 | } |
|
|
343 | |
333 | |
344 | /* |
334 | /* |
345 | * Before anything, make sure the archetype does exist... |
335 | * Before anything, make sure the archetype does exist... |
346 | * If not, prolly an error... |
336 | * If not, prolly an error... |
347 | */ |
337 | */ |
… | |
… | |
351 | return; |
341 | return; |
352 | |
342 | |
353 | /* Now delete current wall, and insert new one |
343 | /* Now delete current wall, and insert new one |
354 | * 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 |
355 | */ |
345 | */ |
356 | for (flag = 0; flag < 4; flag++) |
346 | object::flags_t old_flags = wall->flag; // elmex: this is where C++ pays off |
357 | old_flags[flag] = wall->flags[flag]; |
|
|
358 | remove_ob (wall); |
|
|
359 | free_object (wall); |
|
|
360 | |
347 | |
361 | wall = arch_to_object (new_arch); |
348 | wall->destroy (); |
|
|
349 | |
|
|
350 | wall = new_arch->instance (); |
362 | wall->type = WALL; |
351 | wall->type = BUILDABLE_WALL; |
363 | 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); |
364 | for (flag = 0; flag < 4; flag++) |
|
|
365 | wall->flags[flag] = old_flags[flag]; |
353 | wall->flag = old_flags; |
366 | } |
354 | } |
367 | |
355 | |
368 | /** |
356 | /** |
369 | * \brief Floor building function |
357 | * \brief Floor building function |
370 | * |
358 | * |
… | |
… | |
373 | * - on an existing wall, with or without a floor under it |
361 | * - on an existing wall, with or without a floor under it |
374 | * |
362 | * |
375 | * Note: this function will inconditionally change squares around (x, y) |
363 | * Note: this function will inconditionally change squares around (x, y) |
376 | * so don't call it with x == 0 for instance! |
364 | * so don't call it with x == 0 for instance! |
377 | */ |
365 | */ |
378 | void |
366 | static void |
379 | apply_builder_floor (object *pl, object *material, short x, short y) |
367 | apply_builder_floor (object *pl, object *material, int x, int y) |
380 | { |
368 | { |
381 | object *tmp, *above; |
369 | object *tmp, *above; |
382 | object *above_floor; /* Item above floor, if any */ |
370 | object *above_floor; /* Item above floor, if any */ |
383 | struct archetype *new_floor; |
371 | struct archetype *new_floor; |
384 | struct archetype *new_wall; |
372 | struct archetype *new_wall; |
… | |
… | |
398 | if (tmp) |
386 | if (tmp) |
399 | { |
387 | { |
400 | while (tmp) |
388 | while (tmp) |
401 | { |
389 | { |
402 | above = tmp->above; |
390 | above = tmp->above; |
403 | if (WALL == tmp->type) |
391 | if (BUILDABLE_WALL == tmp->type) |
404 | { |
392 | { |
405 | /* 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 */ |
406 | new_wall = tmp->arch; |
394 | new_wall = tmp->arch; |
407 | remove_ob (tmp); |
395 | tmp->destroy (); |
408 | free_object (tmp); |
|
|
409 | sprintf (message, "You destroy the wall and redo the floor."); |
396 | sprintf (message, "You destroy the wall and redo the floor."); |
410 | } |
397 | } |
411 | else if ((FLOOR == tmp->type) || (QUERY_FLAG (tmp, FLAG_IS_FLOOR))) |
398 | else if (IS_FLOOR (tmp)) |
412 | { |
399 | { |
413 | remove_ob (tmp); |
400 | tmp->destroy (); |
414 | free_object (tmp); |
|
|
415 | floor_removed = 1; |
401 | floor_removed = 1; |
416 | } |
402 | } |
417 | else |
403 | else |
418 | { |
404 | { |
419 | if (floor_removed) |
405 | if (floor_removed) |
|
|
406 | { |
|
|
407 | /* This is the first item that was above the floor */ |
420 | above_floor = tmp; |
408 | above_floor = tmp; |
|
|
409 | floor_removed = 0; |
|
|
410 | } |
421 | } |
411 | } |
422 | |
412 | |
423 | tmp = above; |
413 | tmp = above; |
424 | } |
414 | } |
425 | } |
415 | } |
… | |
… | |
431 | /* Not found, log & bail out */ |
421 | /* Not found, log & bail out */ |
432 | 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); |
433 | return; |
423 | return; |
434 | } |
424 | } |
435 | |
425 | |
436 | tmp = arch_to_object (new_floor); |
426 | tmp = new_floor->instance (); |
437 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
427 | tmp->set_flag (FLAG_IS_BUILDABLE); |
438 | SET_FLAG (tmp, FLAG_UNIQUE); |
428 | tmp->set_flag (FLAG_UNIQUE); |
439 | SET_FLAG (tmp, FLAG_IS_FLOOR); |
429 | tmp->set_flag (FLAG_IS_FLOOR); |
440 | tmp->type = FLOOR; |
430 | //tmp->type = FLOOR; |
441 | 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); |
442 | |
432 | |
443 | /* |
433 | /* |
444 | * 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 |
445 | * Since building, you can have: blocking view / floor / wall / nothing |
435 | * Since building, you can have: blocking view / floor / wall / nothing |
… | |
… | |
450 | yt = y + freearr_y[i]; |
440 | yt = y + freearr_y[i]; |
451 | tmp = GET_MAP_OB (pl->map, xt, yt); |
441 | tmp = GET_MAP_OB (pl->map, xt, yt); |
452 | if (!tmp) |
442 | if (!tmp) |
453 | { |
443 | { |
454 | /* Must insert floor & wall */ |
444 | /* Must insert floor & wall */ |
455 | tmp = arch_to_object (new_floor); |
445 | tmp = new_floor->instance (); |
456 | /* Better make the floor unique */ |
446 | /* Better make the floor unique */ |
457 | SET_FLAG (tmp, FLAG_UNIQUE); |
447 | tmp->set_flag (FLAG_UNIQUE); |
458 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
448 | tmp->set_flag (FLAG_IS_BUILDABLE); |
459 | tmp->type = FLOOR; |
449 | //tmp->type = FLOOR; |
460 | 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); |
461 | /* 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... */ |
462 | if (new_wall) |
452 | if (new_wall) |
463 | { |
453 | { |
464 | tmp = arch_to_object (new_wall); |
454 | tmp = new_wall->instance (); |
465 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
455 | tmp->set_flag (FLAG_IS_BUILDABLE); |
466 | tmp->type = WALL; |
456 | tmp->type = BUILDABLE_WALL; |
467 | 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); |
468 | } |
458 | } |
469 | } |
459 | } |
470 | } |
460 | } |
471 | |
461 | |
… | |
… | |
473 | * 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 |
474 | * spot, so need to check that those new walls connect correctly |
464 | * spot, so need to check that those new walls connect correctly |
475 | */ |
465 | */ |
476 | for (xt = x - 2; xt <= x + 2; xt++) |
466 | for (xt = x - 2; xt <= x + 2; xt++) |
477 | for (yt = y - 2; yt <= y + 2; yt++) |
467 | for (yt = y - 2; yt <= y + 2; yt++) |
478 | { |
|
|
479 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
468 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
480 | fix_walls (pl->map, xt, yt); |
469 | fix_walls (pl->map, xt, yt); |
481 | } |
|
|
482 | |
470 | |
483 | /* Now remove raw item from inventory */ |
471 | /* Now remove raw item from inventory */ |
484 | decrease_ob (material); |
472 | material->decrease (); |
485 | |
473 | |
486 | /* And tell player about the fix */ |
474 | /* And tell player about the fix */ |
487 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
475 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
488 | } |
476 | } |
489 | |
477 | |
… | |
… | |
492 | * |
480 | * |
493 | * Walls can be build: |
481 | * Walls can be build: |
494 | * - on a floor without anything else |
482 | * - on a floor without anything else |
495 | * - on an existing wall, with or without a floor |
483 | * - on an existing wall, with or without a floor |
496 | */ |
484 | */ |
497 | void |
485 | static void |
498 | apply_builder_wall (object *pl, object *material, short x, short y) |
486 | apply_builder_wall (object *pl, object *material, int x, int y) |
499 | { |
487 | { |
500 | object *current_wall; |
488 | object *current_wall; |
501 | object *tmp; |
489 | object *tmp; |
502 | int xt, yt; |
490 | int xt, yt; |
503 | struct archetype *new_wall; |
491 | struct archetype *new_wall; |
… | |
… | |
508 | /* Grab existing wall, if any */ |
496 | /* Grab existing wall, if any */ |
509 | current_wall = NULL; |
497 | current_wall = NULL; |
510 | tmp = GET_MAP_OB (pl->map, x, y); |
498 | tmp = GET_MAP_OB (pl->map, x, y); |
511 | while (tmp && !current_wall) |
499 | while (tmp && !current_wall) |
512 | { |
500 | { |
513 | if (WALL == tmp->type) |
501 | if (BUILDABLE_WALL == tmp->type) |
514 | current_wall = tmp; |
502 | current_wall = tmp; |
515 | |
503 | |
516 | tmp = tmp->above; |
504 | tmp = tmp->above; |
517 | } |
505 | } |
518 | |
506 | |
… | |
… | |
525 | { |
513 | { |
526 | 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); |
527 | return; |
515 | return; |
528 | } |
516 | } |
529 | |
517 | |
530 | tmp = arch_to_object (new_wall); |
518 | tmp = new_wall->instance (); |
531 | tmp->type = WALL; |
519 | tmp->type = BUILDABLE_WALL; |
532 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
520 | tmp->set_flag (FLAG_IS_BUILDABLE); |
533 | 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); |
534 | |
522 | |
535 | /* If existing wall, remove it, no need to fix other walls */ |
523 | /* If existing wall, remove it, no need to fix other walls */ |
536 | if (current_wall) |
524 | if (current_wall) |
537 | { |
525 | { |
538 | remove_ob (current_wall); |
526 | current_wall->destroy (); |
539 | free_object (current_wall); |
|
|
540 | fix_walls (pl->map, x, y); |
527 | fix_walls (pl->map, x, y); |
541 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
528 | sprintf (message, "You redecorate the wall to better suit your tastes."); |
542 | } |
529 | } |
543 | else |
530 | else |
544 | { |
531 | { |
… | |
… | |
552 | fix_walls (pl->map, xt, yt); |
539 | fix_walls (pl->map, xt, yt); |
553 | } |
540 | } |
554 | } |
541 | } |
555 | |
542 | |
556 | /* Now remove item from inventory */ |
543 | /* Now remove item from inventory */ |
557 | decrease_ob (material); |
544 | material->decrease (); |
558 | |
545 | |
559 | /* And tell player what happened */ |
546 | /* And tell player what happened */ |
560 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
547 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
561 | } |
548 | } |
562 | |
549 | |
… | |
… | |
566 | * 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. |
567 | * Archetype of created object is item->slaying (raw material). |
554 | * Archetype of created object is item->slaying (raw material). |
568 | * Type of inserted item is tested for specific cases (doors & such). |
555 | * Type of inserted item is tested for specific cases (doors & such). |
569 | * 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) |
570 | */ |
557 | */ |
571 | void |
558 | static void |
572 | apply_builder_item (object *pl, object *item, short x, short y) |
559 | apply_builder_item (object *pl, object *item, int x, int y) |
573 | { |
560 | { |
574 | object *tmp; |
561 | object *tmp; |
575 | struct archetype *arch; |
562 | struct archetype *arch; |
576 | int insert_flag; |
563 | int insert_flag; |
577 | object *floor; |
564 | object *floor; |
578 | object *con_rune; |
565 | object *con_rune; |
579 | int connected; |
|
|
580 | |
566 | |
581 | /* Find floor */ |
567 | /* Find floor */ |
582 | floor = GET_MAP_OB (pl->map, x, y); |
568 | floor = GET_MAP_OB (pl->map, x, y); |
583 | if (!floor) |
569 | if (!floor) |
584 | { |
570 | { |
585 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
571 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
586 | return; |
572 | return; |
587 | } |
573 | } |
588 | |
574 | |
589 | while (floor && (floor->type != FLOOR) && (!QUERY_FLAG (floor, FLAG_IS_FLOOR))) |
575 | while (floor && !IS_FLOOR (floor)) |
590 | floor = floor->above; |
576 | floor = floor->above; |
591 | |
577 | |
592 | if (!floor) |
578 | if (!floor) |
593 | { |
579 | { |
594 | 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."); |
… | |
… | |
597 | /* Create item, set flag, insert in map */ |
583 | /* Create item, set flag, insert in map */ |
598 | arch = archetype::find (item->slaying); |
584 | arch = archetype::find (item->slaying); |
599 | if (!arch) |
585 | if (!arch) |
600 | return; |
586 | return; |
601 | |
587 | |
602 | tmp = arch_to_object (arch); |
588 | tmp = arch->instance (); |
603 | |
589 | |
604 | 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)) |
605 | /* Floor has something on top that interferes with building */ |
591 | /* Floor has something on top that interferes with building */ |
606 | { |
592 | { |
607 | 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."); |
608 | return; |
594 | return; |
609 | } |
595 | } |
610 | |
596 | |
611 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
597 | tmp->set_flag (FLAG_IS_BUILDABLE); |
612 | SET_FLAG (tmp, FLAG_NO_PICK); |
598 | tmp->set_flag (FLAG_NO_PICK); |
613 | |
599 | |
614 | /* |
600 | /* |
615 | * 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. |
616 | 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. |
617 | */ |
604 | */ |
618 | 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); |
619 | |
608 | |
620 | connected = 0; |
609 | shstr_tmp connected; |
|
|
610 | |
621 | switch (tmp->type) |
611 | switch (tmp->type) |
622 | { |
612 | { |
623 | case DOOR: |
613 | case DOOR: |
624 | case GATE: |
614 | case GATE: |
625 | case BUTTON: |
615 | case BUTTON: |
626 | case DETECTOR: |
616 | case DETECTOR: |
627 | case TIMED_GATE: |
617 | case TIMED_GATE: |
628 | case PEDESTAL: |
618 | case PEDESTAL: |
629 | case CF_HANDLE: |
619 | case T_HANDLE: |
630 | case MAGIC_EAR: |
620 | case MAGIC_EAR: |
631 | case SIGN: |
621 | case SIGN: |
632 | /* Signs don't need a connection, but but magic mouths do. */ |
622 | /* Signs don't need a connection, but but magic mouths do. */ |
633 | if (tmp->type == SIGN && strcmp (tmp->arch->name, "magic_mouth")) |
623 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
634 | break; |
624 | break; |
|
|
625 | |
635 | con_rune = get_connection_rune (pl, x, y); |
626 | con_rune = get_connection_rune (pl, x, y); |
636 | 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); |
637 | if (connected == -1) |
628 | if (!connected) |
638 | { |
629 | { |
639 | /* Player already informed of failure by the previous function */ |
630 | /* Player already informed of failure by the previous function */ |
640 | free_object (tmp); |
631 | tmp->destroy (); |
641 | return; |
632 | return; |
642 | } |
633 | } |
|
|
634 | |
643 | /* Remove marking rune */ |
635 | /* Remove marking rune */ |
644 | remove_ob (con_rune); |
636 | con_rune->destroy (); |
645 | free_object (con_rune); |
|
|
646 | } |
637 | } |
647 | |
638 | |
648 | /* 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 */ |
649 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
640 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
650 | { |
|
|
651 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
641 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
652 | { |
642 | { |
653 | free_object (tmp); |
643 | tmp->destroy (); |
654 | return; |
644 | return; |
655 | } |
645 | } |
656 | } |
|
|
657 | |
646 | |
658 | 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); |
659 | if (connected != 0) |
648 | if (connected) |
660 | add_button_link (tmp, pl->map, connected); |
649 | tmp->add_link (pl->map, connected); |
661 | |
650 | |
662 | 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)); |
663 | decrease_ob_nr (item, 1); |
652 | item->decrease (); |
664 | } |
653 | } |
665 | |
654 | |
666 | /** |
655 | /** |
667 | * Item remover. |
656 | * Item remover. |
668 | * |
657 | * |
669 | * Removes first buildable item, either under or above the floor |
658 | * Removes first buildable item, either under or above the floor |
670 | */ |
659 | */ |
671 | void |
660 | static void |
672 | apply_builder_remove (object *pl, int dir) |
661 | apply_builder_remove (object *pl, int dir) |
673 | { |
662 | { |
674 | object *item; |
663 | object *item; |
675 | short x, y; |
664 | int x, y; |
676 | |
665 | |
677 | x = pl->x + freearr_x[dir]; |
666 | x = pl->x + freearr_x[dir]; |
678 | y = pl->y + freearr_y[dir]; |
667 | y = pl->y + freearr_y[dir]; |
679 | |
668 | |
680 | /* Check square */ |
669 | /* Check square */ |
681 | item = GET_MAP_OB (pl->map, x, y); |
670 | item = GET_MAP_OB (pl->map, x, y); |
682 | if (!item) |
671 | if (!item) |
683 | { |
672 | { |
684 | /* Should not happen with previous tests, but we never know */ |
673 | /* Should not happen with previous tests, but we never know */ |
685 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
674 | new_draw_info (NDI_UNIQUE, 0, pl, "Invalid square."); |
686 | 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); |
687 | return; |
676 | return; |
688 | } |
677 | } |
689 | |
678 | |
690 | if (item->type == FLOOR || QUERY_FLAG (item, FLAG_IS_FLOOR)) |
679 | if (IS_FLOOR (item)) |
691 | item = item->above; |
680 | item = item->above; |
692 | |
681 | |
693 | if (!item) |
682 | if (!item) |
694 | { |
|
|
695 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
683 | new_draw_info (NDI_UNIQUE, 0, pl, "Nothing to remove."); |
696 | return; |
684 | else if (item->type == BUILDABLE_WALL) |
697 | } |
|
|
698 | |
|
|
699 | /* Now remove object, with special cases (buttons & such) */ |
|
|
700 | switch (item->type) |
|
|
701 | { |
|
|
702 | case WALL: |
|
|
703 | 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."); |
704 | return; |
686 | else if (!item->flag [FLAG_IS_BUILDABLE]) |
705 | |
687 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't remove the %s, it's not buildable!", query_name (item)); |
706 | case DOOR: |
688 | else |
707 | case BUTTON: |
689 | { |
708 | case GATE: |
|
|
709 | case TIMED_GATE: |
|
|
710 | case DETECTOR: |
|
|
711 | case PEDESTAL: |
|
|
712 | case CF_HANDLE: |
|
|
713 | case MAGIC_EAR: |
|
|
714 | case SIGN: |
|
|
715 | /* Special case: must unconnect */ |
|
|
716 | if (QUERY_FLAG (item, FLAG_IS_LINKED)) |
|
|
717 | remove_button_link (item); |
|
|
718 | |
|
|
719 | /* Fall through */ |
|
|
720 | |
|
|
721 | default: |
|
|
722 | /* Remove generic item */ |
|
|
723 | 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)); |
724 | remove_ob (item); |
691 | item->destroy (); |
725 | free_object (item); |
|
|
726 | } |
692 | } |
727 | } |
693 | } |
728 | |
694 | |
729 | /** |
695 | /** |
730 | * Global building function |
696 | * Global building function |
… | |
… | |
733 | * or remover object. |
699 | * or remover object. |
734 | */ |
700 | */ |
735 | void |
701 | void |
736 | apply_map_builder (object *pl, int dir) |
702 | apply_map_builder (object *pl, int dir) |
737 | { |
703 | { |
738 | object *builder; |
|
|
739 | object *tmp; |
|
|
740 | object *tmp2; |
|
|
741 | short x, y; |
704 | int x, y; |
742 | |
705 | |
743 | if (!pl->type == PLAYER) |
706 | if (!pl->type == PLAYER) |
744 | return; |
707 | return; |
745 | |
708 | |
746 | /*if ( !player->map->unique ) |
709 | /*if ( !player->map->unique ) |
… | |
… | |
756 | } |
719 | } |
757 | |
720 | |
758 | x = pl->x + freearr_x[dir]; |
721 | x = pl->x + freearr_x[dir]; |
759 | y = pl->y + freearr_y[dir]; |
722 | y = pl->y + freearr_y[dir]; |
760 | |
723 | |
761 | 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)) |
762 | { |
725 | { |
763 | 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..."); |
764 | return; |
727 | return; |
765 | } |
728 | } |
766 | |
729 | |
… | |
… | |
769 | * The square must have only buildable items |
732 | * The square must have only buildable items |
770 | * Exception: marking runes are all right, |
733 | * Exception: marking runes are all right, |
771 | * since they are used for special things like connecting doors / buttons |
734 | * since they are used for special things like connecting doors / buttons |
772 | */ |
735 | */ |
773 | |
736 | |
774 | tmp = GET_MAP_OB (pl->map, x, y); |
737 | object *tmp = GET_MAP_OB (pl->map, x, y); |
775 | if (!tmp) |
738 | if (!tmp) |
776 | { |
739 | { |
777 | /* Nothing, meaning player is standing next to an undefined square... */ |
740 | /* Nothing, meaning player is standing next to an undefined square... */ |
778 | 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); |
779 | 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."); |
780 | return; |
743 | return; |
781 | } |
744 | } |
782 | tmp2 = find_marked_object (pl); |
745 | |
|
|
746 | object *builder = pl->contr->ranged_ob; |
|
|
747 | |
|
|
748 | object *tmp2 = pl->mark (); |
|
|
749 | |
783 | while (tmp) |
750 | while (tmp) |
784 | { |
751 | { |
785 | 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)) |
786 | { |
753 | { |
787 | /* The item building function already has it's own special |
754 | /* The item building function already has it's own special |
788 | * checks for this |
755 | * checks for this |
789 | */ |
756 | */ |
790 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
757 | if (!tmp2 || tmp2->subtype != ST_MAT_ITEM) |
791 | { |
758 | { |
|
|
759 | if (!INVOKE_PLAYER (BUILD, pl->contr, ARG_OBJECT (builder), ARG_MAP (pl->map), ARG_INT (x), ARG_INT (y), ARG_INT (0))) |
792 | 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 | |
793 | return; |
762 | return; |
794 | } |
763 | } |
795 | } |
764 | } |
|
|
765 | |
796 | tmp = tmp->above; |
766 | tmp = tmp->above; |
797 | } |
767 | } |
798 | |
768 | |
799 | /* Now we know the square is ok */ |
769 | /* Now we know the square is ok */ |
800 | 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; |
801 | |
772 | |
802 | if (builder->subtype == ST_BD_REMOVE) |
773 | if (builder->subtype == ST_BD_REMOVE) |
803 | /* Remover -> call specific function and bail out */ |
774 | /* Remover -> call specific function and bail out */ |
804 | { |
775 | { |
805 | apply_builder_remove (pl, dir); |
776 | apply_builder_remove (pl, dir); |
… | |
… | |
825 | return; |
796 | return; |
826 | } |
797 | } |
827 | |
798 | |
828 | switch (tmp->subtype) |
799 | switch (tmp->subtype) |
829 | { |
800 | { |
830 | case ST_MAT_FLOOR: |
801 | case ST_MAT_FLOOR: |
831 | apply_builder_floor (pl, tmp, x, y); |
802 | apply_builder_floor (pl, tmp, x, y); |
832 | return; |
803 | return; |
833 | |
804 | |
834 | case ST_MAT_WALL: |
805 | case ST_MAT_WALL: |
835 | apply_builder_wall (pl, tmp, x, y); |
806 | apply_builder_wall (pl, tmp, x, y); |
836 | return; |
807 | return; |
837 | |
808 | |
838 | case ST_MAT_ITEM: |
809 | case ST_MAT_ITEM: |
839 | apply_builder_item (pl, tmp, x, y); |
810 | apply_builder_item (pl, tmp, x, y); |
840 | return; |
811 | return; |
841 | |
812 | |
842 | default: |
813 | default: |
843 | 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."); |
844 | 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); |
845 | return; |
816 | return; |
846 | } |
817 | } |
847 | } |
818 | } |
848 | |
819 | |
849 | /* Here, it means the builder has an invalid type */ |
820 | /* Here, it means the builder has an invalid type */ |
850 | 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."); |
851 | 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); |
852 | } |
823 | } |
853 | |
824 | |
854 | /** |
|
|
855 | * Make the built object inherit the msg of books that are used with it. |
|
|
856 | * For objects already invisible (i.e. magic mouths & ears), also make it |
|
|
857 | * it inherit the face and the name with "talking " prepended. |
|
|
858 | */ |
|
|
859 | int |
|
|
860 | adjust_sign_msg (object *pl, short x, short y, object *tmp) |
|
|
861 | { |
|
|
862 | object *book; |
|
|
863 | char buf[MAX_BUF]; |
|
|
864 | char buf2[MAX_BUF]; |
|
|
865 | |
|
|
866 | book = get_msg_book (pl, x, y); |
|
|
867 | if (!book) |
|
|
868 | { |
|
|
869 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message."); |
|
|
870 | return -1; |
|
|
871 | } |
|
|
872 | |
|
|
873 | tmp->msg = book->msg; |
|
|
874 | |
|
|
875 | if (tmp->invisible) |
|
|
876 | { |
|
|
877 | if (book->custom_name != NULL) |
|
|
878 | { |
|
|
879 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
|
|
880 | } |
|
|
881 | else |
|
|
882 | { |
|
|
883 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
|
|
884 | } |
|
|
885 | tmp->name = buf; |
|
|
886 | |
|
|
887 | if (book->name_pl != NULL) |
|
|
888 | { |
|
|
889 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
|
|
890 | tmp->name_pl = buf2; |
|
|
891 | } |
|
|
892 | |
|
|
893 | tmp->face = book->face; |
|
|
894 | tmp->invisible = 0; |
|
|
895 | } |
|
|
896 | remove_ob (book); |
|
|
897 | free_object (book); |
|
|
898 | return 0; |
|
|
899 | } |
|
|