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