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