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