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