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