1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * 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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * 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, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * 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 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
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> |
… | |
… | |
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->archname, "rune_mark") && ob->type != FLOOR) |
44 | if (ob->arch->archname != shstr_rune_mark && ob->type != FLOOR) |
44 | { |
45 | { |
45 | switch (tmp->type) |
46 | switch (tmp->type) |
46 | { |
47 | { |
47 | case SIGN: |
48 | case SIGN: |
48 | case MAGIC_EAR: |
49 | case MAGIC_EAR: |
49 | /* Allow signs and magic ears to be built on books */ |
50 | /* Allow signs and magic ears to be built on books */ |
50 | if (ob->type != BOOK) |
51 | if (ob->type != BOOK) |
51 | { |
|
|
52 | return 0; |
|
|
53 | } |
|
|
54 | break; |
|
|
55 | case BUTTON: |
|
|
56 | case DETECTOR: |
|
|
57 | case PEDESTAL: |
|
|
58 | case CF_HANDLE: |
|
|
59 | /* Allow buttons and levers to be built under gates */ |
|
|
60 | if (ob->type != GATE && ob->type != DOOR) |
|
|
61 | { |
|
|
62 | return 0; |
|
|
63 | } |
|
|
64 | break; |
|
|
65 | default: |
|
|
66 | return 0; |
52 | return 0; |
|
|
53 | break; |
|
|
54 | case BUTTON: |
|
|
55 | case DETECTOR: |
|
|
56 | case PEDESTAL: |
|
|
57 | case T_HANDLE: |
|
|
58 | /* Allow buttons and levers to be built under gates */ |
|
|
59 | if (ob->type != GATE && ob->type != DOOR) |
|
|
60 | return 0; |
|
|
61 | break; |
|
|
62 | default: |
|
|
63 | return 0; |
67 | } |
64 | } |
68 | } |
65 | } |
|
|
66 | |
69 | ob = ob->above; |
67 | ob = ob->above; |
70 | } |
68 | } |
71 | return 1; |
69 | return 1; |
72 | } |
70 | } |
73 | |
71 | |
74 | /** |
72 | /** |
75 | * Erases marking runes at specified location |
73 | * Erases marking runes at specified location |
76 | */ |
74 | */ |
77 | void |
75 | static void |
78 | remove_marking_runes (maptile *map, short x, short y) |
76 | remove_marking_runes (maptile *map, int x, int y) |
79 | { |
77 | { |
80 | object *rune; |
78 | object *rune; |
81 | object *next; |
79 | object *next; |
82 | |
80 | |
83 | rune = GET_MAP_OB (map, x, y); |
81 | rune = GET_MAP_OB (map, x, y); |
84 | while (rune) |
82 | while (rune) |
85 | { |
83 | { |
86 | next = rune->above; |
84 | next = rune->above; |
87 | |
85 | |
88 | if ((rune->type == SIGN) && (!strcmp (rune->arch->archname, "rune_mark"))) |
86 | if (rune->type == SIGN && rune->arch->archname == shstr_rune_mark) |
89 | rune->destroy (); |
87 | rune->destroy (); |
90 | |
88 | |
91 | rune = next; |
89 | rune = next; |
92 | } |
90 | } |
93 | } |
91 | } |
… | |
… | |
97 | * \param map: map for which to find a value |
95 | * \param map: map for which to find a value |
98 | * \return 'connected' value with no item, or -1 if failure. |
96 | * \return 'connected' value with no item, or -1 if failure. |
99 | * |
97 | * |
100 | * Tries 1000 random values, then returns -1. |
98 | * Tries 1000 random values, then returns -1. |
101 | */ |
99 | */ |
102 | int |
100 | static shstr_tmp |
103 | find_unused_connected_value (maptile *map) |
101 | find_unused_connected_value (maptile *map) |
104 | { |
102 | { |
105 | int connected = 0; |
103 | for (int i = 1000; --i; ) |
106 | int itest = 0; |
|
|
107 | oblinkpt *obp; |
|
|
108 | |
|
|
109 | while (itest++ < 1000) |
|
|
110 | { |
|
|
111 | connected = 1 + rand () % 20000; |
|
|
112 | for (obp = map->buttons; obp && (obp->value != connected); obp = obp->next); |
|
|
113 | |
|
|
114 | if (!obp) |
|
|
115 | return connected; |
|
|
116 | } |
104 | { |
|
|
105 | char buf[64]; |
117 | |
106 | |
|
|
107 | snprintf (buf, sizeof (buf), "built-%x", rndm (0xf0000000U) + 0x10000000U); |
|
|
108 | |
|
|
109 | shstr id (buf); |
|
|
110 | |
|
|
111 | if (!map->find_link (id)) |
|
|
112 | return id; |
|
|
113 | } |
|
|
114 | |
|
|
115 | return shstr_tmp (); |
|
|
116 | } |
|
|
117 | |
|
|
118 | /** |
|
|
119 | * Returns the marking rune on the square, for purposes of building connections |
|
|
120 | */ |
|
|
121 | static object * |
|
|
122 | get_connection_rune (object *pl, int x, int y) |
|
|
123 | { |
|
|
124 | object *rune = GET_MAP_OB (pl->map, x, y); |
|
|
125 | |
|
|
126 | while (rune && (rune->type != SIGN || rune->arch->archname != shstr_rune_mark)) |
|
|
127 | rune = rune->above; |
|
|
128 | |
118 | return -1; |
129 | return rune; |
119 | } |
130 | } |
120 | |
|
|
121 | |
131 | |
122 | /** |
132 | /** |
123 | * Helper function for door/button/connected item building. |
133 | * Helper function for door/button/connected item building. |
124 | * |
134 | * |
125 | * Will search the specified spot for a marking rune. |
135 | * Will search the specified spot for a marking rune. |
… | |
… | |
127 | * Else, searches a force in op's inventory matching the map's name |
137 | * Else, searches a force in op's inventory matching the map's name |
128 | * and the rune's text. |
138 | * and the rune's text. |
129 | * If found, returns the connection value associated |
139 | * If found, returns the connection value associated |
130 | * else searches a new connection value, and adds the force to the player. |
140 | * else searches a new connection value, and adds the force to the player. |
131 | */ |
141 | */ |
132 | int |
142 | static shstr_tmp |
133 | find_or_create_connection_for_map (object *pl, short x, short y, object *rune) |
143 | find_or_create_connection_for_map (object *pl, int x, int y, object *rune) |
134 | { |
144 | { |
135 | object *force; |
145 | object *force; |
136 | int connected; |
|
|
137 | |
146 | |
138 | if (!rune) |
147 | if (!rune) |
139 | rune = get_connection_rune (pl, x, y); |
148 | rune = get_connection_rune (pl, x, y); |
140 | |
149 | |
141 | if (!rune) |
150 | if (!rune) |
142 | { |
151 | { |
143 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
152 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a marking rune with the group name."); |
144 | return -1; |
153 | return shstr_tmp (); |
145 | } |
154 | } |
146 | |
155 | |
147 | /* Now, find force in player's inventory */ |
156 | /* Now, find force in player's inventory */ |
148 | force = pl->inv; |
157 | force = pl->inv; |
149 | while (force |
158 | while (force |
… | |
… | |
153 | |
162 | |
154 | if (!force) |
163 | if (!force) |
155 | /* No force, need to create & insert one */ |
164 | /* No force, need to create & insert one */ |
156 | { |
165 | { |
157 | /* Find unused value */ |
166 | /* Find unused value */ |
158 | connected = find_unused_connected_value (pl->map); |
167 | shstr_tmp id = find_unused_connected_value (pl->map); |
159 | if (connected == -1) |
168 | |
|
|
169 | if (!id) |
160 | { |
170 | { |
161 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
171 | new_draw_info (NDI_UNIQUE, 0, pl, "Could not create more groups."); |
162 | return -1; |
172 | return shstr_tmp (); |
163 | } |
173 | } |
164 | |
174 | |
165 | force = get_archetype (FORCE_NAME); |
175 | force = get_archetype (FORCE_NAME); |
166 | force->slaying = pl->map->path; |
176 | force->slaying = pl->map->path; |
167 | force->msg = rune->msg; |
177 | force->msg = rune->msg; |
168 | force->path_attuned = connected; |
178 | force->race = id; |
169 | force->set_speed (0); |
179 | force->set_speed (0); |
|
|
180 | |
170 | insert_ob_in_ob (force, pl); |
181 | insert_ob_in_ob (force, pl); |
171 | |
182 | |
172 | return connected; |
183 | return id; |
173 | } |
184 | } |
174 | |
185 | |
175 | /* Found the force, everything's easy. */ |
186 | /* Found the force, everything's easy. */ |
176 | return force->path_attuned; |
187 | return force->race; |
177 | } |
|
|
178 | |
|
|
179 | /** |
|
|
180 | * Returns the marking rune on the square, for purposes of building connections |
|
|
181 | */ |
|
|
182 | object * |
|
|
183 | get_connection_rune (object *pl, short x, short y) |
|
|
184 | { |
|
|
185 | object *rune; |
|
|
186 | |
|
|
187 | rune = GET_MAP_OB (pl->map, x, y); |
|
|
188 | while (rune && ((rune->type != SIGN) || (strcmp (rune->arch->archname, "rune_mark")))) |
|
|
189 | rune = rune->above; |
|
|
190 | return rune; |
|
|
191 | } |
188 | } |
192 | |
189 | |
193 | /** |
190 | /** |
194 | * Returns the book/scroll on the current square, for purposes of building |
191 | * Returns the book/scroll on the current square, for purposes of building |
195 | */ |
192 | */ |
196 | object * |
193 | static object * |
197 | get_msg_book (object *pl, short x, short y) |
194 | get_msg_book (object *pl, int x, int y) |
198 | { |
195 | { |
199 | object *book; |
|
|
200 | |
|
|
201 | book = GET_MAP_OB (pl->map, x, y); |
196 | object *book = GET_MAP_OB (pl->map, x, y); |
|
|
197 | |
202 | while (book && (book->type != BOOK)) |
198 | while (book && (book->type != BOOK)) |
203 | book = book->above; |
199 | book = book->above; |
|
|
200 | |
204 | return book; |
201 | return book; |
205 | } |
202 | } |
206 | |
203 | |
207 | /** |
204 | /** |
|
|
205 | * Make the built object inherit the msg of books that are used with it. |
|
|
206 | * For objects already invisible (i.e. magic mouths & ears), also make it |
|
|
207 | * it inherit the face and the name with "talking " prepended. |
|
|
208 | */ |
|
|
209 | static int |
|
|
210 | adjust_sign_msg (object *pl, int x, int y, object *tmp) |
|
|
211 | { |
|
|
212 | object *book; |
|
|
213 | char buf[MAX_BUF]; |
|
|
214 | char buf2[MAX_BUF]; |
|
|
215 | |
|
|
216 | book = get_msg_book (pl, x, y); |
|
|
217 | if (!book) |
|
|
218 | { |
|
|
219 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message."); |
|
|
220 | return -1; |
|
|
221 | } |
|
|
222 | |
|
|
223 | tmp->msg = book->msg; |
|
|
224 | |
|
|
225 | if (tmp->invisible) |
|
|
226 | { |
|
|
227 | if (book->custom_name != NULL) |
|
|
228 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
|
|
229 | else |
|
|
230 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
|
|
231 | |
|
|
232 | tmp->name = buf; |
|
|
233 | |
|
|
234 | if (book->name_pl != NULL) |
|
|
235 | { |
|
|
236 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
|
|
237 | tmp->name_pl = buf2; |
|
|
238 | } |
|
|
239 | |
|
|
240 | tmp->face = book->face; |
|
|
241 | tmp->invisible = 0; |
|
|
242 | } |
|
|
243 | |
|
|
244 | book->destroy (); |
|
|
245 | return 0; |
|
|
246 | } |
|
|
247 | |
|
|
248 | /** |
208 | * Returns first item of type BUILDABLE_WALL. |
249 | * Returns first item of type BUILDABLE_WALL. |
209 | */ |
250 | */ |
210 | object * |
251 | static object * |
211 | get_wall (maptile *map, int x, int y) |
252 | get_wall (maptile *map, int x, int y) |
212 | { |
253 | { |
213 | object *wall; |
|
|
214 | |
|
|
215 | wall = GET_MAP_OB (map, x, y); |
254 | object *wall = GET_MAP_OB (map, x, y); |
|
|
255 | |
216 | while (wall && (BUILDABLE_WALL != wall->type)) |
256 | while (wall && (BUILDABLE_WALL != wall->type)) |
217 | wall = wall->above; |
257 | wall = wall->above; |
218 | |
258 | |
219 | return wall; |
259 | return wall; |
220 | } |
260 | } |
… | |
… | |
231 | * Note: x & y must be valid map coordinates. |
271 | * Note: x & y must be valid map coordinates. |
232 | */ |
272 | */ |
233 | void |
273 | void |
234 | fix_walls (maptile *map, int x, int y) |
274 | fix_walls (maptile *map, int x, int y) |
235 | { |
275 | { |
236 | object *wall; |
|
|
237 | char archetype[MAX_BUF]; |
276 | char archetype[MAX_BUF]; |
238 | char *underscore; |
277 | char *underscore; |
239 | struct archetype *new_arch; |
278 | struct archetype *new_arch; |
240 | |
279 | |
241 | |
|
|
242 | /* First, find the wall on that spot */ |
280 | /* First, find the wall on that spot */ |
243 | wall = get_wall (map, x, y); |
281 | object *wall = get_wall (map, x, y); |
244 | if (!wall) |
282 | if (!wall) |
245 | /* Nothing -> bail out */ |
283 | /* Nothing -> bail out */ |
246 | return; |
284 | return; |
247 | |
285 | |
248 | /* Find base name */ |
286 | /* Find base name */ |
… | |
… | |
260 | underscore++; |
298 | underscore++; |
261 | *underscore = '\0'; |
299 | *underscore = '\0'; |
262 | |
300 | |
263 | int connect = 0; |
301 | int connect = 0; |
264 | |
302 | |
265 | if ((x > 0) && get_wall (map, x - 1, y)) |
303 | if (x > 0 && get_wall (map, x - 1, y)) connect |= 1; |
266 | connect |= 1; |
|
|
267 | if ((x < map->width - 1) && get_wall (map, x + 1, y)) |
304 | if (x < map->width - 1 && get_wall (map, x + 1, y)) connect |= 2; |
268 | connect |= 2; |
305 | if (y > 0 && get_wall (map, x, y - 1)) connect |= 4; |
269 | |
|
|
270 | if ((y > 0) && get_wall (map, x, y - 1)) |
|
|
271 | connect |= 4; |
|
|
272 | |
|
|
273 | if ((y < map->height - 1) && get_wall (map, x, y + 1)) |
306 | if (y < map->height - 1 && get_wall (map, x, y + 1)) connect |= 8; |
274 | connect |= 8; |
|
|
275 | |
307 | |
276 | switch (connect) |
308 | // one bit per dir, 1 left, 2 right, 4 up, 8 down |
277 | { |
309 | static const char *walltype[16] = { |
278 | case 0: |
310 | "0", |
279 | strcat (archetype, "0"); |
311 | "1_3", |
|
|
312 | "1_4", |
|
|
313 | "2_1_2", |
|
|
314 | "1_2", |
|
|
315 | "2_2_4", |
|
|
316 | "2_2_1", |
|
|
317 | "3_1", |
|
|
318 | "1_1", |
|
|
319 | "2_2_3", |
|
|
320 | "2_2_2", |
|
|
321 | "3_3", |
|
|
322 | "2_1_1", |
|
|
323 | "3_4", |
|
|
324 | "3_2", |
|
|
325 | "4" |
|
|
326 | }; |
280 | |
327 | |
281 | break; |
328 | strcat (archetype, walltype [connect]); |
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 | |
329 | |
344 | /* |
330 | /* |
345 | * Before anything, make sure the archetype does exist... |
331 | * Before anything, make sure the archetype does exist... |
346 | * If not, prolly an error... |
332 | * If not, prolly an error... |
347 | */ |
333 | */ |
… | |
… | |
371 | * - on an existing wall, with or without a floor under it |
357 | * - on an existing wall, with or without a floor under it |
372 | * |
358 | * |
373 | * Note: this function will inconditionally change squares around (x, y) |
359 | * Note: this function will inconditionally change squares around (x, y) |
374 | * so don't call it with x == 0 for instance! |
360 | * so don't call it with x == 0 for instance! |
375 | */ |
361 | */ |
376 | void |
362 | static void |
377 | apply_builder_floor (object *pl, object *material, short x, short y) |
363 | apply_builder_floor (object *pl, object *material, int x, int y) |
378 | { |
364 | { |
379 | object *tmp, *above; |
365 | object *tmp, *above; |
380 | object *above_floor; /* Item above floor, if any */ |
366 | object *above_floor; /* Item above floor, if any */ |
381 | struct archetype *new_floor; |
367 | struct archetype *new_floor; |
382 | struct archetype *new_wall; |
368 | struct archetype *new_wall; |
… | |
… | |
411 | floor_removed = 1; |
397 | floor_removed = 1; |
412 | } |
398 | } |
413 | else |
399 | else |
414 | { |
400 | { |
415 | if (floor_removed) |
401 | if (floor_removed) |
|
|
402 | { |
|
|
403 | /* This is the first item that was above the floor */ |
416 | above_floor = tmp; |
404 | above_floor = tmp; |
|
|
405 | floor_removed = 0; |
|
|
406 | } |
417 | } |
407 | } |
418 | |
408 | |
419 | tmp = above; |
409 | tmp = above; |
420 | } |
410 | } |
421 | } |
411 | } |
… | |
… | |
475 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
465 | if (!OUT_OF_REAL_MAP (pl->map, xt, yt)) |
476 | fix_walls (pl->map, xt, yt); |
466 | fix_walls (pl->map, xt, yt); |
477 | } |
467 | } |
478 | |
468 | |
479 | /* Now remove raw item from inventory */ |
469 | /* Now remove raw item from inventory */ |
480 | decrease_ob (material); |
470 | material->decrease (); |
481 | |
471 | |
482 | /* And tell player about the fix */ |
472 | /* And tell player about the fix */ |
483 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
473 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
484 | } |
474 | } |
485 | |
475 | |
486 | /** |
476 | /** |
487 | * Wall radius fix function |
477 | * Wall radius fix function |
488 | */ |
478 | */ |
|
|
479 | static void |
489 | void fix_walls_around (maptile *map, int x, int y) |
480 | fix_walls_around (maptile *map, int x, int y) |
490 | { |
481 | { |
491 | for (int xt = x - 1; xt <= x + 1; xt++) |
482 | for (int xt = x - 1; xt <= x + 1; xt++) |
492 | for (int yt = y - 1; yt <= y + 1; yt++) |
483 | for (int yt = y - 1; yt <= y + 1; yt++) |
493 | { |
484 | { |
494 | if (OUT_OF_REAL_MAP (map, xt, yt)) |
485 | if (OUT_OF_REAL_MAP (map, xt, yt)) |
… | |
… | |
503 | * |
494 | * |
504 | * Walls can be build: |
495 | * Walls can be build: |
505 | * - on a floor without anything else |
496 | * - on a floor without anything else |
506 | * - on an existing wall, with or without a floor |
497 | * - on an existing wall, with or without a floor |
507 | */ |
498 | */ |
508 | void |
499 | static void |
509 | apply_builder_wall (object *pl, object *material, short x, short y) |
500 | apply_builder_wall (object *pl, object *material, int x, int y) |
510 | { |
501 | { |
511 | object *current_wall; |
502 | object *current_wall; |
512 | object *tmp; |
503 | object *tmp; |
513 | int xt, yt; |
504 | int xt, yt; |
514 | struct archetype *new_wall; |
505 | struct archetype *new_wall; |
… | |
… | |
562 | fix_walls (pl->map, xt, yt); |
553 | fix_walls (pl->map, xt, yt); |
563 | } |
554 | } |
564 | } |
555 | } |
565 | |
556 | |
566 | /* Now remove item from inventory */ |
557 | /* Now remove item from inventory */ |
567 | decrease_ob (material); |
558 | material->decrease (); |
568 | |
559 | |
569 | /* And tell player what happened */ |
560 | /* And tell player what happened */ |
570 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
561 | new_draw_info (NDI_UNIQUE, 0, pl, message); |
571 | } |
562 | } |
572 | |
563 | |
… | |
… | |
576 | * Item must be put on a square with a floor, you can have something under. |
567 | * Item must be put on a square with a floor, you can have something under. |
577 | * Archetype of created object is item->slaying (raw material). |
568 | * Archetype of created object is item->slaying (raw material). |
578 | * Type of inserted item is tested for specific cases (doors & such). |
569 | * Type of inserted item is tested for specific cases (doors & such). |
579 | * Item is inserted above the floor, unless Str == 1 (only for detectors i guess) |
570 | * Item is inserted above the floor, unless Str == 1 (only for detectors i guess) |
580 | */ |
571 | */ |
581 | void |
572 | static void |
582 | apply_builder_item (object *pl, object *item, short x, short y) |
573 | apply_builder_item (object *pl, object *item, int x, int y) |
583 | { |
574 | { |
584 | object *tmp; |
575 | object *tmp; |
585 | struct archetype *arch; |
576 | struct archetype *arch; |
586 | int insert_flag; |
577 | int insert_flag; |
587 | object *floor; |
578 | object *floor; |
588 | object *con_rune; |
579 | object *con_rune; |
589 | int connected; |
|
|
590 | |
580 | |
591 | /* Find floor */ |
581 | /* Find floor */ |
592 | floor = GET_MAP_OB (pl->map, x, y); |
582 | floor = GET_MAP_OB (pl->map, x, y); |
593 | if (!floor) |
583 | if (!floor) |
594 | { |
584 | { |
… | |
… | |
609 | if (!arch) |
599 | if (!arch) |
610 | return; |
600 | return; |
611 | |
601 | |
612 | tmp = arch_to_object (arch); |
602 | tmp = arch_to_object (arch); |
613 | |
603 | |
614 | if ((floor->above) && (!can_build_over (pl->map, tmp, x, y))) |
604 | if (!floor->flag[FLAG_IS_BUILDABLE] || (floor->above) && (!can_build_over (pl->map, tmp, x, y))) |
615 | /* Floor has something on top that interferes with building */ |
605 | /* Floor has something on top that interferes with building */ |
616 | { |
606 | { |
617 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
607 | new_draw_info (NDI_UNIQUE, 0, pl, "You can't build here."); |
618 | return; |
608 | return; |
619 | } |
609 | } |
620 | |
610 | |
621 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
611 | SET_FLAG (tmp, FLAG_IS_BUILDABLE); |
622 | SET_FLAG (tmp, FLAG_NO_PICK); |
612 | SET_FLAG (tmp, FLAG_NO_PICK); |
623 | |
613 | |
624 | /* |
614 | /* |
625 | * This doesn't work on non unique maps. pedestals under floor will not be saved... |
615 | * Str 1 is a flag that the item [pedestal] should go below the floor. |
626 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
616 | * Items under the floor on non-unique maps will not be saved, |
|
|
617 | * so make the item itself unique in this situation. |
627 | */ |
618 | */ |
628 | insert_flag = INS_ABOVE_FLOOR_ONLY; |
619 | insert_flag = ( item->stats.Str == 1 ) ? INS_BELOW_ORIGINATOR : INS_ABOVE_FLOOR_ONLY; |
|
|
620 | if (insert_flag == INS_BELOW_ORIGINATOR && !pl->map->no_reset) |
|
|
621 | SET_FLAG (tmp, FLAG_UNIQUE); |
629 | |
622 | |
630 | connected = 0; |
623 | shstr_tmp connected; |
|
|
624 | |
631 | switch (tmp->type) |
625 | switch (tmp->type) |
632 | { |
626 | { |
633 | case DOOR: |
627 | case DOOR: |
634 | case GATE: |
628 | case GATE: |
635 | case BUTTON: |
629 | case BUTTON: |
636 | case DETECTOR: |
630 | case DETECTOR: |
637 | case TIMED_GATE: |
631 | case TIMED_GATE: |
638 | case PEDESTAL: |
632 | case PEDESTAL: |
639 | case CF_HANDLE: |
633 | case T_HANDLE: |
640 | case MAGIC_EAR: |
634 | case MAGIC_EAR: |
641 | case SIGN: |
635 | case SIGN: |
642 | /* Signs don't need a connection, but but magic mouths do. */ |
636 | /* Signs don't need a connection, but but magic mouths do. */ |
643 | if (tmp->type == SIGN && strcmp (tmp->arch->archname, "magic_mouth")) |
637 | if (tmp->type == SIGN && tmp->arch->archname != shstr_magic_mouth) |
644 | break; |
638 | break; |
|
|
639 | |
645 | con_rune = get_connection_rune (pl, x, y); |
640 | con_rune = get_connection_rune (pl, x, y); |
646 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
641 | connected = find_or_create_connection_for_map (pl, x, y, con_rune); |
647 | if (connected == -1) |
642 | if (!connected) |
648 | { |
643 | { |
649 | /* Player already informed of failure by the previous function */ |
644 | /* Player already informed of failure by the previous function */ |
650 | tmp->destroy (); |
645 | tmp->destroy (); |
651 | return; |
646 | return; |
652 | } |
647 | } |
|
|
648 | |
653 | /* Remove marking rune */ |
649 | /* Remove marking rune */ |
654 | con_rune->destroy (); |
650 | con_rune->destroy (); |
655 | } |
651 | } |
656 | |
652 | |
657 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
653 | /* For magic mouths/ears, and signs, take the msg from a book of scroll */ |
658 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
654 | if ((tmp->type == SIGN) || (tmp->type == MAGIC_EAR)) |
659 | { |
|
|
660 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
655 | if (adjust_sign_msg (pl, x, y, tmp) == -1) |
661 | { |
656 | { |
662 | tmp->destroy (); |
657 | tmp->destroy (); |
663 | return; |
658 | return; |
664 | } |
659 | } |
665 | } |
|
|
666 | |
660 | |
667 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
661 | insert_ob_in_map_at (tmp, pl->map, floor, insert_flag, x, y); |
668 | if (connected != 0) |
662 | if (connected) |
669 | add_button_link (tmp, pl->map, connected); |
663 | tmp->add_link (pl->map, connected); |
670 | |
664 | |
671 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
665 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You build the %s", query_name (tmp)); |
672 | decrease_ob_nr (item, 1); |
666 | item->decrease (); |
673 | } |
667 | } |
674 | |
668 | |
675 | /** |
669 | /** |
676 | * Item remover. |
670 | * Item remover. |
677 | * |
671 | * |
678 | * Removes first buildable item, either under or above the floor |
672 | * Removes first buildable item, either under or above the floor |
679 | */ |
673 | */ |
680 | void |
674 | static void |
681 | apply_builder_remove (object *pl, int dir) |
675 | apply_builder_remove (object *pl, int dir) |
682 | { |
676 | { |
683 | object *item; |
677 | object *item; |
684 | short x, y; |
678 | int x, y; |
685 | |
679 | |
686 | x = pl->x + freearr_x[dir]; |
680 | x = pl->x + freearr_x[dir]; |
687 | y = pl->y + freearr_y[dir]; |
681 | y = pl->y + freearr_y[dir]; |
688 | |
682 | |
689 | /* Check square */ |
683 | /* Check square */ |
… | |
… | |
722 | apply_map_builder (object *pl, int dir) |
716 | apply_map_builder (object *pl, int dir) |
723 | { |
717 | { |
724 | object *builder; |
718 | object *builder; |
725 | object *tmp; |
719 | object *tmp; |
726 | object *tmp2; |
720 | object *tmp2; |
727 | short x, y; |
721 | int x, y; |
728 | |
722 | |
729 | if (!pl->type == PLAYER) |
723 | if (!pl->type == PLAYER) |
730 | return; |
724 | return; |
731 | |
725 | |
732 | /*if ( !player->map->unique ) |
726 | /*if ( !player->map->unique ) |
… | |
… | |
767 | } |
761 | } |
768 | |
762 | |
769 | tmp2 = find_marked_object (pl); |
763 | tmp2 = find_marked_object (pl); |
770 | while (tmp) |
764 | while (tmp) |
771 | { |
765 | { |
772 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && ((tmp->type != SIGN) || (strcmp (tmp->arch->archname, "rune_mark")))) |
766 | if (!QUERY_FLAG (tmp, FLAG_IS_BUILDABLE) && (tmp->type != SIGN || tmp->arch->archname != shstr_rune_mark)) |
773 | { |
767 | { |
774 | /* The item building function already has it's own special |
768 | /* The item building function already has it's own special |
775 | * checks for this |
769 | * checks for this |
776 | */ |
770 | */ |
777 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
771 | if ((!tmp2) || (tmp2->subtype != ST_MAT_ITEM)) |
… | |
… | |
836 | /* Here, it means the builder has an invalid type */ |
830 | /* Here, it means the builder has an invalid type */ |
837 | new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry."); |
831 | new_draw_info (NDI_UNIQUE, 0, pl, "Don't know how to apply this tool, sorry."); |
838 | LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); |
832 | LOG (llevError, "apply_map_builder: invalid builder subtype %d\n", builder->subtype); |
839 | } |
833 | } |
840 | |
834 | |
841 | /** |
|
|
842 | * Make the built object inherit the msg of books that are used with it. |
|
|
843 | * For objects already invisible (i.e. magic mouths & ears), also make it |
|
|
844 | * it inherit the face and the name with "talking " prepended. |
|
|
845 | */ |
|
|
846 | int |
|
|
847 | adjust_sign_msg (object *pl, short x, short y, object *tmp) |
|
|
848 | { |
|
|
849 | object *book; |
|
|
850 | char buf[MAX_BUF]; |
|
|
851 | char buf2[MAX_BUF]; |
|
|
852 | |
|
|
853 | book = get_msg_book (pl, x, y); |
|
|
854 | if (!book) |
|
|
855 | { |
|
|
856 | new_draw_info (NDI_UNIQUE, 0, pl, "You need to put a book or scroll with the message."); |
|
|
857 | return -1; |
|
|
858 | } |
|
|
859 | |
|
|
860 | tmp->msg = book->msg; |
|
|
861 | |
|
|
862 | if (tmp->invisible) |
|
|
863 | { |
|
|
864 | if (book->custom_name != NULL) |
|
|
865 | { |
|
|
866 | snprintf (buf, sizeof (buf), "talking %s", &book->custom_name); |
|
|
867 | } |
|
|
868 | else |
|
|
869 | { |
|
|
870 | snprintf (buf, sizeof (buf), "talking %s", &book->name); |
|
|
871 | } |
|
|
872 | tmp->name = buf; |
|
|
873 | |
|
|
874 | if (book->name_pl != NULL) |
|
|
875 | { |
|
|
876 | snprintf (buf2, sizeof (buf2), "talking %s", &book->name_pl); |
|
|
877 | tmp->name_pl = buf2; |
|
|
878 | } |
|
|
879 | |
|
|
880 | tmp->face = book->face; |
|
|
881 | tmp->invisible = 0; |
|
|
882 | } |
|
|
883 | |
|
|
884 | book->destroy (); |
|
|
885 | return 0; |
|
|
886 | } |
|
|