… | |
… | |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <funcpoint.h> |
26 | #include <funcpoint.h> |
27 | |
27 | |
28 | #include <loader.h> |
28 | #include <loader.h> |
29 | #ifndef WIN32 /* ---win32 exclude header */ |
|
|
30 | # include <unistd.h> |
29 | #include <unistd.h> |
31 | #endif /* win32 */ |
|
|
32 | |
30 | |
33 | #include "path.h" |
31 | #include "path.h" |
34 | |
32 | |
35 | |
|
|
36 | extern int nrofallocobjects, nroffreeobjects; |
|
|
37 | |
|
|
38 | /* |
33 | /* |
39 | * Returns the mapstruct which has a name matching the given argument. |
34 | * Returns the maptile which has a name matching the given argument. |
40 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
41 | */ |
36 | */ |
42 | |
37 | maptile * |
43 | mapstruct * |
|
|
44 | has_been_loaded (const char *name) |
38 | has_been_loaded (const char *name) |
45 | { |
39 | { |
46 | mapstruct *map; |
40 | maptile *map; |
47 | |
41 | |
48 | if (!name || !*name) |
42 | if (!name || !*name) |
49 | return 0; |
43 | return 0; |
|
|
44 | |
50 | for (map = first_map; map; map = map->next) |
45 | for (map = first_map; map; map = map->next) |
51 | if (!strcmp (name, map->path)) |
46 | if (!strcmp (name, map->path)) |
52 | break; |
47 | break; |
|
|
48 | |
53 | return (map); |
49 | return (map); |
54 | } |
50 | } |
55 | |
51 | |
56 | /* |
52 | /* |
57 | * This makes a path absolute outside the world of Crossfire. |
53 | * This makes a path absolute outside the world of Crossfire. |
… | |
… | |
159 | int |
155 | int |
160 | check_path (const char *name, int prepend_dir) |
156 | check_path (const char *name, int prepend_dir) |
161 | { |
157 | { |
162 | char buf[MAX_BUF]; |
158 | char buf[MAX_BUF]; |
163 | |
159 | |
164 | #ifndef WIN32 |
|
|
165 | char *endbuf; |
160 | char *endbuf; |
166 | struct stat statbuf; |
161 | struct stat statbuf; |
167 | int mode = 0; |
162 | int mode = 0; |
168 | #endif |
|
|
169 | |
163 | |
170 | if (prepend_dir) |
164 | if (prepend_dir) |
171 | strcpy (buf, create_pathname (name)); |
165 | strcpy (buf, create_pathname (name)); |
172 | else |
166 | else |
173 | strcpy (buf, name); |
167 | strcpy (buf, name); |
174 | #ifdef WIN32 /* ***win32: check this sucker in windows style. */ |
|
|
175 | return (_access (buf, 0)); |
|
|
176 | #else |
|
|
177 | |
168 | |
178 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
169 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
179 | * this method should be equivalant and is clearer. |
170 | * this method should be equivalant and is clearer. |
180 | * Can not use strcat because we need to cycle through |
171 | * Can not use strcat because we need to cycle through |
181 | * all the names. |
172 | * all the names. |
… | |
… | |
194 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
185 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
195 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
186 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
196 | mode |= 2; |
187 | mode |= 2; |
197 | |
188 | |
198 | return (mode); |
189 | return (mode); |
199 | #endif |
|
|
200 | } |
190 | } |
201 | |
191 | |
202 | /* |
192 | /* |
203 | * Prints out debug-information about a map. |
193 | * Prints out debug-information about a map. |
204 | * Dumping these at llevError doesn't seem right, but is |
194 | * Dumping these at llevError doesn't seem right, but is |
205 | * necessary to make sure the information is in fact logged. |
195 | * necessary to make sure the information is in fact logged. |
206 | */ |
196 | */ |
207 | |
197 | |
208 | void |
198 | void |
209 | dump_map (const mapstruct *m) |
199 | dump_map (const maptile *m) |
210 | { |
200 | { |
211 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
201 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
212 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); |
202 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", m->width, m->height, m->enter_x, m->enter_y); |
213 | |
203 | |
214 | if (m->msg != NULL) |
204 | if (m->msg != NULL) |
215 | LOG (llevError, "Message:\n%s", m->msg); |
205 | LOG (llevError, "Message:\n%s", m->msg); |
216 | |
206 | |
217 | if (m->maplore != NULL) |
207 | if (m->maplore != NULL) |
… | |
… | |
231 | */ |
221 | */ |
232 | |
222 | |
233 | void |
223 | void |
234 | dump_all_maps (void) |
224 | dump_all_maps (void) |
235 | { |
225 | { |
236 | mapstruct *m; |
226 | maptile *m; |
237 | |
227 | |
238 | for (m = first_map; m != NULL; m = m->next) |
228 | for (m = first_map; m; m = m->next) |
239 | { |
|
|
240 | dump_map (m); |
229 | dump_map (m); |
241 | } |
|
|
242 | } |
230 | } |
243 | |
231 | |
244 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
232 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
245 | * one function that just returns a P_.. value (see map.h) |
233 | * one function that just returns a P_.. value (see map.h) |
246 | * it will also do map translation for tiled maps, returning |
234 | * it will also do map translation for tiled maps, returning |
… | |
… | |
250 | * is needed. The case of not passing values is if we're just |
238 | * is needed. The case of not passing values is if we're just |
251 | * checking for the existence of something on those spaces, but |
239 | * checking for the existence of something on those spaces, but |
252 | * don't expect to insert/remove anything from those spaces. |
240 | * don't expect to insert/remove anything from those spaces. |
253 | */ |
241 | */ |
254 | int |
242 | int |
255 | get_map_flags (mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) |
243 | get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny) |
256 | { |
244 | { |
257 | sint16 newx, newy; |
245 | sint16 newx, newy; |
258 | int retval = 0; |
246 | int retval = 0; |
259 | mapstruct *mp; |
247 | maptile *mp; |
260 | |
248 | |
261 | if (out_of_map (oldmap, x, y)) |
|
|
262 | return P_OUT_OF_MAP; |
|
|
263 | newx = x; |
249 | newx = x; |
264 | newy = y; |
250 | newy = y; |
|
|
251 | |
265 | mp = get_map_from_coord (oldmap, &newx, &newy); |
252 | mp = get_map_from_coord (oldmap, &newx, &newy); |
|
|
253 | |
|
|
254 | if (!mp) |
|
|
255 | return P_OUT_OF_MAP; |
|
|
256 | |
266 | if (mp != oldmap) |
257 | if (mp != oldmap) |
267 | retval |= P_NEW_MAP; |
258 | retval |= P_NEW_MAP; |
268 | if (newmap) |
|
|
269 | *newmap = mp; |
|
|
270 | if (nx) |
|
|
271 | *nx = newx; |
|
|
272 | if (ny) |
|
|
273 | *ny = newy; |
|
|
274 | |
259 | |
275 | retval |= mp->spaces[newx + mp->width * newy].flags; |
260 | if (newmap) *newmap = mp; |
|
|
261 | if (nx) *nx = newx; |
|
|
262 | if (ny) *ny = newy; |
276 | |
263 | |
277 | return retval; |
264 | return retval | mp->at (newx, newy).flags (); |
278 | } |
265 | } |
279 | |
|
|
280 | |
266 | |
281 | /* |
267 | /* |
282 | * Returns true if the given coordinate is blocked except by the |
268 | * Returns true if the given coordinate is blocked except by the |
283 | * object passed is not blocking. This is used with |
269 | * object passed is not blocking. This is used with |
284 | * multipart monsters - if we want to see if a 2x2 monster |
270 | * multipart monsters - if we want to see if a 2x2 monster |
… | |
… | |
288 | * monster. |
274 | * monster. |
289 | * m, x, y are the target map/coordinates - needed for map tiling. |
275 | * m, x, y are the target map/coordinates - needed for map tiling. |
290 | * the coordinates & map passed in should have been updated for tiling |
276 | * the coordinates & map passed in should have been updated for tiling |
291 | * by the caller. |
277 | * by the caller. |
292 | */ |
278 | */ |
293 | |
|
|
294 | int |
279 | int |
295 | blocked_link (object *ob, mapstruct *m, int sx, int sy) |
280 | blocked_link (object *ob, maptile *m, int sx, int sy) |
296 | { |
281 | { |
297 | object *tmp; |
282 | object *tmp; |
298 | int mflags, blocked; |
283 | int mflags, blocked; |
299 | |
284 | |
300 | /* Make sure the coordinates are valid - they should be, as caller should |
285 | /* Make sure the coordinates are valid - they should be, as caller should |
… | |
… | |
307 | } |
292 | } |
308 | |
293 | |
309 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
294 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
310 | * directly. |
295 | * directly. |
311 | */ |
296 | */ |
312 | mflags = m->spaces[sx + m->width * sy].flags; |
297 | mflags = m->at (sx, sy).flags (); |
313 | |
298 | |
314 | blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); |
299 | blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); |
315 | |
300 | |
316 | /* If space is currently not blocked by anything, no need to |
301 | /* If space is currently not blocked by anything, no need to |
317 | * go further. Not true for players - all sorts of special |
302 | * go further. Not true for players - all sorts of special |
… | |
… | |
336 | /* We basically go through the stack of objects, and if there is |
321 | /* We basically go through the stack of objects, and if there is |
337 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
322 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
338 | * true. If we get through the entire stack, that must mean |
323 | * true. If we get through the entire stack, that must mean |
339 | * ob is blocking it, so return 0. |
324 | * ob is blocking it, so return 0. |
340 | */ |
325 | */ |
341 | for (tmp = GET_MAP_OB (m, sx, sy); tmp != NULL; tmp = tmp->above) |
326 | for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) |
342 | { |
327 | { |
343 | |
328 | |
344 | /* This must be before the checks below. Code for inventory checkers. */ |
329 | /* This must be before the checks below. Code for inventory checkers. */ |
345 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
330 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
346 | { |
331 | { |
… | |
… | |
410 | * |
395 | * |
411 | * Note this used to be arch_blocked, but with new movement |
396 | * Note this used to be arch_blocked, but with new movement |
412 | * code, we need to have actual object to check its move_type |
397 | * code, we need to have actual object to check its move_type |
413 | * against the move_block values. |
398 | * against the move_block values. |
414 | */ |
399 | */ |
415 | |
|
|
416 | int |
400 | int |
417 | ob_blocked (const object *ob, mapstruct *m, sint16 x, sint16 y) |
401 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
418 | { |
402 | { |
419 | archetype *tmp; |
403 | archetype *tmp; |
420 | int flag; |
404 | int flag; |
421 | mapstruct *m1; |
405 | maptile *m1; |
422 | sint16 sx, sy; |
406 | sint16 sx, sy; |
423 | |
407 | |
424 | if (ob == NULL) |
408 | if (ob == NULL) |
425 | { |
409 | { |
426 | flag = get_map_flags (m, &m1, x, y, &sx, &sy); |
410 | flag = get_map_flags (m, &m1, x, y, &sx, &sy); |
427 | if (flag & P_OUT_OF_MAP) |
411 | if (flag & P_OUT_OF_MAP) |
428 | return P_OUT_OF_MAP; |
412 | return P_OUT_OF_MAP; |
429 | |
413 | |
430 | /* don't have object, so don't know what types would block */ |
414 | /* don't have object, so don't know what types would block */ |
431 | return (GET_MAP_MOVE_BLOCK (m1, sx, sy)); |
415 | return m1->at (sx, sy).move_block; |
432 | } |
416 | } |
433 | |
417 | |
434 | for (tmp = ob->arch; tmp != NULL; tmp = tmp->more) |
418 | for (tmp = ob->arch; tmp; tmp = tmp->more) |
435 | { |
419 | { |
436 | flag = get_map_flags (m, &m1, x + tmp->clone.x, y + tmp->clone.y, &sx, &sy); |
420 | flag = get_map_flags (m, &m1, x + tmp->clone.x, y + tmp->clone.y, &sx, &sy); |
437 | |
421 | |
438 | if (flag & P_OUT_OF_MAP) |
422 | if (flag & P_OUT_OF_MAP) |
439 | return P_OUT_OF_MAP; |
423 | return P_OUT_OF_MAP; |
440 | if (flag & P_IS_ALIVE) |
424 | if (flag & P_IS_ALIVE) |
441 | return P_IS_ALIVE; |
425 | return P_IS_ALIVE; |
442 | |
426 | |
|
|
427 | mapspace &ms = m1->at (sx, sy); |
|
|
428 | |
|
|
429 | |
443 | /* find_first_free_spot() calls this function. However, often |
430 | /* find_first_free_spot() calls this function. However, often |
444 | * ob doesn't have any move type (when used to place exits) |
431 | * ob doesn't have any move type (when used to place exits) |
445 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
432 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
446 | */ |
433 | */ |
447 | |
434 | |
448 | if (ob->move_type == 0 && GET_MAP_MOVE_BLOCK (m1, sx, sy) != MOVE_ALL) |
435 | if (ob->move_type == 0 && ms.move_block != MOVE_ALL) |
449 | continue; |
436 | continue; |
450 | |
437 | |
451 | /* Note it is intentional that we check ob - the movement type of the |
438 | /* Note it is intentional that we check ob - the movement type of the |
452 | * head of the object should correspond for the entire object. |
439 | * head of the object should correspond for the entire object. |
453 | */ |
440 | */ |
454 | if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) |
441 | if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) |
455 | return AB_NO_PASS; |
442 | return P_NO_PASS; |
456 | |
|
|
457 | } |
443 | } |
|
|
444 | |
458 | return 0; |
445 | return 0; |
459 | } |
446 | } |
460 | |
447 | |
461 | /* When the map is loaded, load_object does not actually insert objects |
448 | /* When the map is loaded, load_object does not actually insert objects |
462 | * into inventory, but just links them. What this does is go through |
449 | * into inventory, but just links them. What this does is go through |
… | |
… | |
491 | * they are saved). We do have to look for the old maps that did save |
478 | * they are saved). We do have to look for the old maps that did save |
492 | * the more sections and not re-add sections for them. |
479 | * the more sections and not re-add sections for them. |
493 | */ |
480 | */ |
494 | |
481 | |
495 | static void |
482 | static void |
496 | link_multipart_objects (mapstruct *m) |
483 | link_multipart_objects (maptile *m) |
497 | { |
484 | { |
498 | int x, y; |
485 | int x, y; |
499 | object *tmp, *op, *last, *above; |
486 | object *tmp, *op, *last, *above; |
500 | archetype *at; |
487 | archetype *at; |
501 | |
488 | |
502 | for (x = 0; x < MAP_WIDTH (m); x++) |
489 | for (x = 0; x < m->width; x++) |
503 | for (y = 0; y < MAP_HEIGHT (m); y++) |
490 | for (y = 0; y < m->height; y++) |
504 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) |
491 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) |
505 | { |
492 | { |
506 | above = tmp->above; |
493 | above = tmp->above; |
507 | |
494 | |
508 | /* already multipart - don't do anything more */ |
495 | /* already multipart - don't do anything more */ |
509 | if (tmp->head || tmp->more) |
496 | if (tmp->head || tmp->more) |
… | |
… | |
538 | * Loads (ands parses) the objects into a given map from the specified |
525 | * Loads (ands parses) the objects into a given map from the specified |
539 | * file pointer. |
526 | * file pointer. |
540 | * mapflags is the same as we get with load_original_map |
527 | * mapflags is the same as we get with load_original_map |
541 | */ |
528 | */ |
542 | void |
529 | void |
543 | load_objects (mapstruct *m, object_thawer & fp, int mapflags) |
530 | load_objects (maptile *m, object_thawer & fp, int mapflags) |
544 | { |
531 | { |
545 | int i, j; |
532 | int i, j; |
546 | int unique; |
533 | int unique; |
547 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
534 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
548 | |
535 | |
549 | op = get_object (); |
536 | op = object::create (); |
550 | op->map = m; /* To handle buttons correctly */ |
537 | op->map = m; /* To handle buttons correctly */ |
551 | |
538 | |
552 | while ((i = load_object (fp, op, mapflags))) |
539 | while ((i = load_object (fp, op, mapflags))) |
553 | { |
540 | { |
554 | /* if the archetype for the object is null, means that we |
541 | /* if the archetype for the object is null, means that we |
… | |
… | |
559 | { |
546 | { |
560 | LOG (llevDebug, "Discarding object without arch: %s\n", op->name ? (const char *) op->name : "(null)"); |
547 | LOG (llevDebug, "Discarding object without arch: %s\n", op->name ? (const char *) op->name : "(null)"); |
561 | continue; |
548 | continue; |
562 | } |
549 | } |
563 | |
550 | |
564 | |
|
|
565 | switch (i) |
551 | switch (i) |
566 | { |
552 | { |
567 | case LL_NORMAL: |
553 | case LL_NORMAL: |
568 | /* if we are loading an overlay, put the floors on the bottom */ |
554 | /* if we are loading an overlay, put the floors on the bottom */ |
569 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
555 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
570 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
556 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
571 | else |
557 | else |
572 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
558 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
573 | |
559 | |
574 | if (op->inv) |
560 | if (op->inv) |
575 | sum_weight (op); |
561 | sum_weight (op); |
576 | |
562 | |
577 | prev = op, last_more = op; |
563 | prev = op, last_more = op; |
578 | break; |
564 | break; |
579 | |
565 | |
580 | case LL_MORE: |
566 | case LL_MORE: |
581 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
567 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
582 | op->head = prev, last_more->more = op, last_more = op; |
568 | op->head = prev, last_more->more = op, last_more = op; |
583 | break; |
569 | break; |
584 | } |
570 | } |
585 | |
571 | |
586 | if (mapflags & MAP_STYLE) |
572 | if (mapflags & MAP_STYLE) |
587 | remove_from_active_list (op); |
573 | remove_from_active_list (op); |
588 | |
574 | |
589 | op = get_object (); |
575 | op = object::create (); |
590 | op->map = m; |
576 | op->map = m; |
591 | } |
577 | } |
592 | |
578 | |
593 | for (i = 0; i < m->width; i++) |
579 | for (i = 0; i < m->width; i++) |
594 | { |
580 | { |
595 | for (j = 0; j < m->height; j++) |
581 | for (j = 0; j < m->height; j++) |
596 | { |
582 | { |
597 | unique = 0; |
583 | unique = 0; |
598 | /* check for unique items, or unique squares */ |
584 | /* check for unique items, or unique squares */ |
599 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
585 | for (otmp = GET_MAP_OB (m, i, j); otmp; otmp = otmp->above) |
600 | { |
586 | { |
601 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
587 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
602 | unique = 1; |
588 | unique = 1; |
|
|
589 | |
603 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
590 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
604 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
591 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
605 | } |
592 | } |
606 | } |
593 | } |
607 | } |
594 | } |
608 | |
595 | |
609 | free_object (op); |
596 | op->destroy (); |
610 | link_multipart_objects (m); |
597 | link_multipart_objects (m); |
611 | } |
598 | } |
612 | |
599 | |
613 | /* This saves all the objects on the map in a non destructive fashion. |
600 | /* This saves all the objects on the map in a non destructive fashion. |
614 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
601 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
615 | * and we only save the head of multi part objects - this is needed |
602 | * and we only save the head of multi part objects - this is needed |
616 | * in order to do map tiling properly. |
603 | * in order to do map tiling properly. |
617 | */ |
604 | */ |
618 | void |
605 | void |
619 | save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) |
606 | save_objects (maptile *m, object_freezer &fp, object_freezer &fp2, int flag) |
620 | { |
607 | { |
621 | int i, j = 0, unique = 0; |
608 | int i, j = 0, unique = 0; |
622 | object *op; |
609 | object *op; |
623 | |
610 | |
624 | /* first pass - save one-part objects */ |
611 | /* first pass - save one-part objects */ |
625 | for (i = 0; i < MAP_WIDTH (m); i++) |
612 | for (i = 0; i < m->width; i++) |
626 | for (j = 0; j < MAP_HEIGHT (m); j++) |
613 | for (j = 0; j < m->height; j++) |
627 | { |
614 | { |
628 | unique = 0; |
615 | unique = 0; |
|
|
616 | |
629 | for (op = get_map_ob (m, i, j); op; op = op->above) |
617 | for (op = m->at (i, j).bot; op; op = op->above) |
630 | { |
618 | { |
631 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
619 | if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) |
632 | unique = 1; |
620 | unique = 1; |
633 | |
621 | |
634 | if (op->type == PLAYER) |
622 | if (op->type == PLAYER) |
635 | { |
|
|
636 | LOG (llevDebug, "Player on map that is being saved\n"); |
|
|
637 | continue; |
623 | continue; |
638 | } |
|
|
639 | |
624 | |
640 | if (op->head || op->owner) |
625 | if (op->head || op->owner) |
641 | continue; |
626 | continue; |
642 | |
627 | |
643 | if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) |
628 | if (unique || op->flag [FLAG_UNIQUE]) |
644 | save_object (fp2, op, 3); |
629 | save_object (fp2, op, 1); |
645 | else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) |
630 | else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) |
646 | save_object (fp, op, 3); |
631 | save_object (fp, op, 1); |
|
|
632 | } |
|
|
633 | } |
|
|
634 | } |
647 | |
635 | |
648 | } /* for this space */ |
636 | maptile::maptile () |
649 | } /* for this j */ |
637 | { |
|
|
638 | in_memory = MAP_SWAPPED; |
|
|
639 | /* The maps used to pick up default x and y values from the |
|
|
640 | * map archetype. Mimic that behaviour. |
|
|
641 | */ |
|
|
642 | this->width = 16; |
|
|
643 | this->height = 16; |
|
|
644 | this->reset_timeout = 0; |
|
|
645 | this->timeout = 300; |
|
|
646 | this->enter_x = 0; |
|
|
647 | this->enter_y = 0; |
|
|
648 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
649 | this->worldpartx = -1; |
|
|
650 | this->worldparty = -1; |
650 | } |
651 | } |
651 | |
652 | |
652 | /* |
653 | /* |
653 | * Allocates, initialises, and returns a pointer to a mapstruct. |
654 | * Allocates, initialises, and returns a pointer to a maptile. |
654 | * Modified to no longer take a path option which was not being |
655 | * Modified to no longer take a path option which was not being |
655 | * used anyways. MSW 2001-07-01 |
656 | * used anyways. MSW 2001-07-01 |
656 | */ |
657 | */ |
657 | |
658 | maptile * |
658 | mapstruct * |
|
|
659 | get_linked_map (void) |
659 | get_linked_map (void) |
660 | { |
660 | { |
661 | mapstruct *map = new mapstruct; |
661 | maptile *mp, *map = new maptile; |
662 | mapstruct *mp; |
|
|
663 | |
662 | |
664 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
663 | for (mp = first_map; mp && mp->next; mp = mp->next); |
|
|
664 | |
665 | if (mp == NULL) |
665 | if (mp == NULL) |
666 | first_map = map; |
666 | first_map = map; |
667 | else |
667 | else |
668 | mp->next = map; |
668 | mp->next = map; |
669 | |
669 | |
670 | map->in_memory = MAP_SWAPPED; |
|
|
671 | /* The maps used to pick up default x and y values from the |
|
|
672 | * map archetype. Mimic that behaviour. |
|
|
673 | */ |
|
|
674 | MAP_WIDTH (map) = 16; |
|
|
675 | MAP_HEIGHT (map) = 16; |
|
|
676 | MAP_RESET_TIMEOUT (map) = 0; |
|
|
677 | MAP_TIMEOUT (map) = 300; |
|
|
678 | MAP_ENTER_X (map) = 0; |
|
|
679 | MAP_ENTER_Y (map) = 0; |
|
|
680 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
681 | MAP_WORLDPARTX (map) = -1; |
|
|
682 | MAP_WORLDPARTY (map) = -1; |
|
|
683 | return map; |
670 | return map; |
684 | } |
671 | } |
685 | |
672 | |
686 | /* |
673 | /* |
687 | * Allocates the arrays contained in a mapstruct. |
674 | * Allocates the arrays contained in a maptile. |
688 | * This basically allocates the dynamic array of spaces for the |
675 | * This basically allocates the dynamic array of spaces for the |
689 | * map. |
676 | * map. |
690 | */ |
677 | */ |
691 | |
|
|
692 | void |
678 | void |
693 | allocate_map (mapstruct *m) |
679 | maptile::allocate () |
694 | { |
680 | { |
695 | m->in_memory = MAP_IN_MEMORY; |
681 | in_memory = MAP_IN_MEMORY; |
|
|
682 | |
696 | /* Log this condition and free the storage. We could I suppose |
683 | /* Log this condition and free the storage. We could I suppose |
697 | * realloc, but if the caller is presuming the data will be intact, |
684 | * realloc, but if the caller is presuming the data will be intact, |
698 | * that is their poor assumption. |
685 | * that is their poor assumption. |
699 | */ |
686 | */ |
700 | if (m->spaces) |
687 | if (spaces) |
701 | { |
688 | { |
702 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); |
689 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
703 | free (m->spaces); |
690 | free (spaces); |
704 | } |
691 | } |
705 | |
692 | |
706 | m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); |
693 | spaces = (mapspace *) |
|
|
694 | calloc (1, width * height * sizeof (mapspace)); |
707 | |
695 | |
708 | if (m->spaces == NULL) |
696 | if (!spaces) |
709 | fatal (OUT_OF_MEMORY); |
697 | fatal (OUT_OF_MEMORY); |
710 | } |
698 | } |
711 | |
699 | |
712 | /* Create and returns a map of the specific size. Used |
700 | /* Create and returns a map of the specific size. Used |
713 | * in random map code and the editor. |
701 | * in random map code and the editor. |
714 | */ |
702 | */ |
715 | mapstruct * |
703 | maptile * |
716 | get_empty_map (int sizex, int sizey) |
704 | get_empty_map (int sizex, int sizey) |
717 | { |
705 | { |
718 | mapstruct *m = get_linked_map (); |
706 | maptile *m = get_linked_map (); |
719 | |
707 | |
720 | m->width = sizex; |
708 | m->width = sizex; |
721 | m->height = sizey; |
709 | m->height = sizey; |
722 | m->in_memory = MAP_SWAPPED; |
710 | m->in_memory = MAP_SWAPPED; |
723 | allocate_map (m); |
711 | m->allocate (); |
|
|
712 | |
724 | return m; |
713 | return m; |
725 | } |
714 | } |
726 | |
715 | |
727 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
716 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
728 | * corresponding to that string. Memory is allocated for this, it must be freed |
717 | * corresponding to that string. Memory is allocated for this, it must be freed |
… | |
… | |
736 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
725 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
737 | shopitems *items = NULL; |
726 | shopitems *items = NULL; |
738 | int i = 0, number_of_entries = 0; |
727 | int i = 0, number_of_entries = 0; |
739 | const typedata *current_type; |
728 | const typedata *current_type; |
740 | |
729 | |
741 | shop_string = strdup_local (input_string); |
730 | shop_string = strdup (input_string); |
742 | p = shop_string; |
731 | p = shop_string; |
743 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
732 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
744 | while (p) |
733 | while (p) |
745 | { |
734 | { |
746 | p = strchr (p, ';'); |
735 | p = strchr (p, ';'); |
… | |
… | |
805 | } |
794 | } |
806 | |
795 | |
807 | /* opposite of parse string, this puts the string that was originally fed in to |
796 | /* opposite of parse string, this puts the string that was originally fed in to |
808 | * the map (or something equivilent) into output_string. */ |
797 | * the map (or something equivilent) into output_string. */ |
809 | static void |
798 | static void |
810 | print_shop_string (mapstruct *m, char *output_string) |
799 | print_shop_string (maptile *m, char *output_string) |
811 | { |
800 | { |
812 | int i; |
801 | int i; |
813 | char tmp[MAX_BUF]; |
802 | char tmp[MAX_BUF]; |
814 | |
803 | |
815 | strcpy (output_string, ""); |
804 | strcpy (output_string, ""); |
… | |
… | |
849 | * MSW 2001-07-01 |
838 | * MSW 2001-07-01 |
850 | * return 0 on success, 1 on failure. |
839 | * return 0 on success, 1 on failure. |
851 | */ |
840 | */ |
852 | |
841 | |
853 | static int |
842 | static int |
854 | load_map_header (object_thawer & fp, mapstruct *m) |
843 | load_map_header (object_thawer & fp, maptile *m) |
855 | { |
844 | { |
856 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
845 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
857 | int msgpos = 0; |
846 | int msgpos = 0; |
858 | int maplorepos = 0; |
847 | int maplorepos = 0; |
859 | |
848 | |
860 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
849 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
861 | { |
850 | { |
862 | buf[HUGE_BUF - 1] = 0; |
851 | buf[HUGE_BUF - 1] = 0; |
863 | key = buf; |
852 | key = buf; |
|
|
853 | |
864 | while (isspace (*key)) |
854 | while (isspace (*key)) |
865 | key++; |
855 | key++; |
|
|
856 | |
866 | if (*key == 0) |
857 | if (*key == 0) |
867 | continue; /* empty line */ |
858 | continue; /* empty line */ |
|
|
859 | |
868 | value = strchr (key, ' '); |
860 | value = strchr (key, ' '); |
|
|
861 | |
869 | if (!value) |
862 | if (!value) |
870 | { |
863 | { |
871 | end = strchr (key, '\n'); |
864 | if ((end = strchr (key, '\n'))) |
872 | if (end != NULL) |
|
|
873 | { |
|
|
874 | *end = 0; |
865 | *end = 0; |
875 | } |
|
|
876 | } |
866 | } |
877 | else |
867 | else |
878 | { |
868 | { |
879 | *value = 0; |
869 | *value = 0; |
880 | value++; |
870 | value++; |
881 | end = strchr (value, '\n'); |
871 | end = strchr (value, '\n'); |
|
|
872 | |
882 | while (isspace (*value)) |
873 | while (isspace (*value)) |
883 | { |
874 | { |
884 | value++; |
875 | value++; |
|
|
876 | |
885 | if (*value == '\0' || value == end) |
877 | if (*value == '\0' || value == end) |
886 | { |
878 | { |
887 | /* Nothing but spaces. */ |
879 | /* Nothing but spaces. */ |
888 | value = NULL; |
880 | value = NULL; |
889 | break; |
881 | break; |
… | |
… | |
912 | * that use the parameter. |
904 | * that use the parameter. |
913 | */ |
905 | */ |
914 | |
906 | |
915 | if (!strcmp (key, "msg")) |
907 | if (!strcmp (key, "msg")) |
916 | { |
908 | { |
917 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
909 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
918 | { |
910 | { |
919 | if (!strcmp (buf, "endmsg\n")) |
911 | if (!strcmp (buf, "endmsg\n")) |
920 | break; |
912 | break; |
921 | else |
913 | else |
922 | { |
914 | { |
… | |
… | |
929 | * with nothing between). There is no reason in those cases to |
921 | * with nothing between). There is no reason in those cases to |
930 | * keep the empty message. Also, msgbuf contains garbage data |
922 | * keep the empty message. Also, msgbuf contains garbage data |
931 | * when msgpos is zero, so copying it results in crashes |
923 | * when msgpos is zero, so copying it results in crashes |
932 | */ |
924 | */ |
933 | if (msgpos != 0) |
925 | if (msgpos != 0) |
934 | m->msg = strdup_local (msgbuf); |
926 | m->msg = strdup (msgbuf); |
935 | } |
927 | } |
936 | else if (!strcmp (key, "maplore")) |
928 | else if (!strcmp (key, "maplore")) |
937 | { |
929 | { |
938 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
930 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
939 | { |
931 | { |
940 | if (!strcmp (buf, "endmaplore\n")) |
932 | if (!strcmp (buf, "endmaplore\n")) |
941 | break; |
933 | break; |
942 | else |
934 | else |
943 | { |
935 | { |
… | |
… | |
945 | strcpy (maplorebuf + maplorepos, buf); |
937 | strcpy (maplorebuf + maplorepos, buf); |
946 | maplorepos += strlen (buf); |
938 | maplorepos += strlen (buf); |
947 | } |
939 | } |
948 | } |
940 | } |
949 | if (maplorepos != 0) |
941 | if (maplorepos != 0) |
950 | m->maplore = strdup_local (maplorebuf); |
942 | m->maplore = strdup (maplorebuf); |
951 | } |
943 | } |
952 | else if (!strcmp (key, "end")) |
944 | else if (!strcmp (key, "end")) |
953 | { |
945 | { |
954 | break; |
946 | break; |
955 | } |
947 | } |
… | |
… | |
964 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
956 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
965 | } |
957 | } |
966 | else if (!strcmp (key, "name")) |
958 | else if (!strcmp (key, "name")) |
967 | { |
959 | { |
968 | *end = 0; |
960 | *end = 0; |
969 | m->name = strdup_local (value); |
961 | m->name = strdup (value); |
970 | } |
962 | } |
971 | /* first strcmp value on these are old names supported |
963 | /* first strcmp value on these are old names supported |
972 | * for compatibility reasons. The new values (second) are |
964 | * for compatibility reasons. The new values (second) are |
973 | * what really should be used. |
965 | * what really should be used. |
974 | */ |
966 | */ |
975 | else if (!strcmp (key, "oid")) |
967 | else if (!strcmp (key, "oid")) |
976 | { |
|
|
977 | fp.get (m, atoi (value)); |
968 | fp.get (m, atoi (value)); |
978 | } |
|
|
979 | else if (!strcmp (key, "attach")) |
969 | else if (!strcmp (key, "attach")) |
980 | { |
|
|
981 | m->attach = value; |
970 | m->attach = value; |
982 | } |
|
|
983 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
971 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
984 | { |
|
|
985 | m->enter_x = atoi (value); |
972 | m->enter_x = atoi (value); |
986 | } |
|
|
987 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
973 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
988 | { |
|
|
989 | m->enter_y = atoi (value); |
974 | m->enter_y = atoi (value); |
990 | } |
|
|
991 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
975 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
992 | { |
|
|
993 | m->width = atoi (value); |
976 | m->width = atoi (value); |
994 | } |
|
|
995 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
977 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
996 | { |
|
|
997 | m->height = atoi (value); |
978 | m->height = atoi (value); |
998 | } |
|
|
999 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
979 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
1000 | { |
|
|
1001 | m->reset_timeout = atoi (value); |
980 | m->reset_timeout = atoi (value); |
1002 | } |
|
|
1003 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
981 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
1004 | { |
|
|
1005 | m->timeout = atoi (value); |
982 | m->timeout = atoi (value); |
1006 | } |
|
|
1007 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
983 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
1008 | { |
984 | m->difficulty = clamp (atoi (value), 1, settings.max_level); |
1009 | m->difficulty = atoi (value); |
|
|
1010 | } |
|
|
1011 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
985 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
1012 | { |
|
|
1013 | m->darkness = atoi (value); |
986 | m->darkness = atoi (value); |
1014 | } |
|
|
1015 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
987 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
1016 | { |
|
|
1017 | m->fixed_resettime = atoi (value); |
988 | m->fixed_resettime = atoi (value); |
1018 | } |
|
|
1019 | else if (!strcmp (key, "unique")) |
989 | else if (!strcmp (key, "unique")) |
1020 | { |
|
|
1021 | m->unique = atoi (value); |
990 | m->unique = atoi (value); |
1022 | } |
|
|
1023 | else if (!strcmp (key, "template")) |
991 | else if (!strcmp (key, "template")) |
1024 | { |
|
|
1025 | m->templatemap = atoi (value); |
992 | m->templatemap = atoi (value); |
1026 | } |
|
|
1027 | else if (!strcmp (key, "region")) |
993 | else if (!strcmp (key, "region")) |
1028 | { |
|
|
1029 | m->region = get_region_by_name (value); |
994 | m->region = get_region_by_name (value); |
1030 | } |
|
|
1031 | else if (!strcmp (key, "shopitems")) |
995 | else if (!strcmp (key, "shopitems")) |
1032 | { |
996 | { |
1033 | *end = 0; |
997 | *end = 0; |
1034 | m->shopitems = parse_shop_string (value); |
998 | m->shopitems = parse_shop_string (value); |
1035 | } |
999 | } |
1036 | else if (!strcmp (key, "shopgreed")) |
1000 | else if (!strcmp (key, "shopgreed")) |
1037 | { |
|
|
1038 | m->shopgreed = atof (value); |
1001 | m->shopgreed = atof (value); |
1039 | } |
|
|
1040 | else if (!strcmp (key, "shopmin")) |
1002 | else if (!strcmp (key, "shopmin")) |
1041 | { |
|
|
1042 | m->shopmin = atol (value); |
1003 | m->shopmin = atol (value); |
1043 | } |
|
|
1044 | else if (!strcmp (key, "shopmax")) |
1004 | else if (!strcmp (key, "shopmax")) |
1045 | { |
|
|
1046 | m->shopmax = atol (value); |
1005 | m->shopmax = atol (value); |
1047 | } |
|
|
1048 | else if (!strcmp (key, "shoprace")) |
1006 | else if (!strcmp (key, "shoprace")) |
1049 | { |
1007 | { |
1050 | *end = 0; |
1008 | *end = 0; |
1051 | m->shoprace = strdup_local (value); |
1009 | m->shoprace = strdup (value); |
1052 | } |
1010 | } |
1053 | else if (!strcmp (key, "outdoor")) |
1011 | else if (!strcmp (key, "outdoor")) |
1054 | { |
|
|
1055 | m->outdoor = atoi (value); |
1012 | m->outdoor = atoi (value); |
1056 | } |
|
|
1057 | else if (!strcmp (key, "temp")) |
1013 | else if (!strcmp (key, "temp")) |
1058 | { |
|
|
1059 | m->temp = atoi (value); |
1014 | m->temp = atoi (value); |
1060 | } |
|
|
1061 | else if (!strcmp (key, "pressure")) |
1015 | else if (!strcmp (key, "pressure")) |
1062 | { |
|
|
1063 | m->pressure = atoi (value); |
1016 | m->pressure = atoi (value); |
1064 | } |
|
|
1065 | else if (!strcmp (key, "humid")) |
1017 | else if (!strcmp (key, "humid")) |
1066 | { |
|
|
1067 | m->humid = atoi (value); |
1018 | m->humid = atoi (value); |
1068 | } |
|
|
1069 | else if (!strcmp (key, "windspeed")) |
1019 | else if (!strcmp (key, "windspeed")) |
1070 | { |
|
|
1071 | m->windspeed = atoi (value); |
1020 | m->windspeed = atoi (value); |
1072 | } |
|
|
1073 | else if (!strcmp (key, "winddir")) |
1021 | else if (!strcmp (key, "winddir")) |
1074 | { |
|
|
1075 | m->winddir = atoi (value); |
1022 | m->winddir = atoi (value); |
1076 | } |
|
|
1077 | else if (!strcmp (key, "sky")) |
1023 | else if (!strcmp (key, "sky")) |
1078 | { |
|
|
1079 | m->sky = atoi (value); |
1024 | m->sky = atoi (value); |
1080 | } |
|
|
1081 | else if (!strcmp (key, "nosmooth")) |
1025 | else if (!strcmp (key, "nosmooth")) |
1082 | { |
|
|
1083 | m->nosmooth = atoi (value); |
1026 | m->nosmooth = atoi (value); |
1084 | } |
|
|
1085 | else if (!strncmp (key, "tile_path_", 10)) |
1027 | else if (!strncmp (key, "tile_path_", 10)) |
1086 | { |
1028 | { |
1087 | int tile = atoi (key + 10); |
1029 | int tile = atoi (key + 10); |
1088 | |
1030 | |
1089 | if (tile < 1 || tile > 4) |
1031 | if (tile < 1 || tile > 4) |
… | |
… | |
1122 | } |
1064 | } |
1123 | |
1065 | |
1124 | if (editor) |
1066 | if (editor) |
1125 | { |
1067 | { |
1126 | /* Use the value as in the file. */ |
1068 | /* Use the value as in the file. */ |
1127 | m->tile_path[tile - 1] = strdup_local (value); |
1069 | m->tile_path[tile - 1] = strdup (value); |
1128 | } |
1070 | } |
1129 | else if (path != NULL) |
1071 | else if (path != NULL) |
1130 | { |
1072 | { |
1131 | /* Use the normalized value. */ |
1073 | /* Use the normalized value. */ |
1132 | m->tile_path[tile - 1] = strdup_local (path); |
1074 | m->tile_path[tile - 1] = strdup (path); |
1133 | } |
1075 | } |
1134 | } /* end if tile direction (in)valid */ |
1076 | } /* end if tile direction (in)valid */ |
1135 | } |
1077 | } |
1136 | else |
1078 | else |
1137 | { |
|
|
1138 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1079 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1139 | } |
|
|
1140 | } |
1080 | } |
|
|
1081 | |
1141 | if (!key || strcmp (key, "end")) |
1082 | if (!key || strcmp (key, "end")) |
1142 | { |
1083 | { |
1143 | LOG (llevError, "Got premature eof on map header!\n"); |
1084 | LOG (llevError, "Got premature eof on map header!\n"); |
1144 | return 1; |
1085 | return 1; |
1145 | } |
1086 | } |
|
|
1087 | |
1146 | return 0; |
1088 | return 0; |
1147 | } |
1089 | } |
1148 | |
1090 | |
1149 | /* |
1091 | /* |
1150 | * Opens the file "filename" and reads information about the map |
1092 | * Opens the file "filename" and reads information about the map |
1151 | * from the given file, and stores it in a newly allocated |
1093 | * from the given file, and stores it in a newly allocated |
1152 | * mapstruct. A pointer to this structure is returned, or NULL on failure. |
1094 | * maptile. A pointer to this structure is returned, or NULL on failure. |
1153 | * flags correspond to those in map.h. Main ones used are |
1095 | * flags correspond to those in map.h. Main ones used are |
1154 | * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and |
1096 | * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and |
1155 | * MAP_BLOCK, in which case we block on this load. This happens in all |
1097 | * MAP_BLOCK, in which case we block on this load. This happens in all |
1156 | * cases, no matter if this flag is set or not. |
1098 | * cases, no matter if this flag is set or not. |
1157 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1099 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1158 | * managed map list. |
1100 | * managed map list. |
1159 | */ |
1101 | */ |
1160 | |
1102 | |
1161 | mapstruct * |
1103 | maptile * |
1162 | load_original_map (const char *filename, int flags) |
1104 | load_original_map (const char *filename, int flags) |
1163 | { |
1105 | { |
1164 | mapstruct *m; |
1106 | maptile *m; |
1165 | char pathname[MAX_BUF]; |
1107 | char pathname[MAX_BUF]; |
1166 | |
1108 | |
1167 | if (flags & MAP_PLAYER_UNIQUE) |
1109 | if (flags & MAP_PLAYER_UNIQUE) |
1168 | strcpy (pathname, filename); |
1110 | strcpy (pathname, filename); |
1169 | else if (flags & MAP_OVERLAY) |
1111 | else if (flags & MAP_OVERLAY) |
… | |
… | |
1183 | strcpy (m->path, filename); |
1125 | strcpy (m->path, filename); |
1184 | if (load_map_header (thawer, m)) |
1126 | if (load_map_header (thawer, m)) |
1185 | { |
1127 | { |
1186 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1128 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1187 | delete_map (m); |
1129 | delete_map (m); |
1188 | return NULL; |
1130 | return 0; |
1189 | } |
1131 | } |
1190 | |
1132 | |
1191 | allocate_map (m); |
1133 | m->allocate (); |
1192 | |
1134 | |
1193 | m->in_memory = MAP_LOADING; |
1135 | m->in_memory = MAP_LOADING; |
1194 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1136 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1195 | |
1137 | |
1196 | m->in_memory = MAP_IN_MEMORY; |
1138 | m->in_memory = MAP_IN_MEMORY; |
1197 | if (!MAP_DIFFICULTY (m)) |
1139 | if (!m->difficulty) |
1198 | MAP_DIFFICULTY (m) = calculate_difficulty (m); |
1140 | m->difficulty = calculate_difficulty (m); |
1199 | set_map_reset_time (m); |
1141 | set_map_reset_time (m); |
1200 | m->instantiate (); |
1142 | m->instantiate (); |
1201 | return (m); |
1143 | return (m); |
1202 | } |
1144 | } |
1203 | |
1145 | |
… | |
… | |
1205 | * Loads a map, which has been loaded earlier, from file. |
1147 | * Loads a map, which has been loaded earlier, from file. |
1206 | * Return the map object we load into (this can change from the passed |
1148 | * Return the map object we load into (this can change from the passed |
1207 | * option if we can't find the original map) |
1149 | * option if we can't find the original map) |
1208 | */ |
1150 | */ |
1209 | |
1151 | |
1210 | static mapstruct * |
1152 | static maptile * |
1211 | load_temporary_map (mapstruct *m) |
1153 | load_temporary_map (maptile *m) |
1212 | { |
1154 | { |
1213 | char buf[MAX_BUF]; |
1155 | char buf[MAX_BUF]; |
1214 | |
1156 | |
1215 | if (!m->tmpname) |
1157 | if (!m->tmpname) |
1216 | { |
1158 | { |
… | |
… | |
1242 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1184 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1243 | delete_map (m); |
1185 | delete_map (m); |
1244 | m = load_original_map (m->path, 0); |
1186 | m = load_original_map (m->path, 0); |
1245 | return NULL; |
1187 | return NULL; |
1246 | } |
1188 | } |
|
|
1189 | |
1247 | allocate_map (m); |
1190 | m->allocate (); |
1248 | |
1191 | |
1249 | m->in_memory = MAP_LOADING; |
1192 | m->in_memory = MAP_LOADING; |
1250 | load_objects (m, thawer, 0); |
1193 | load_objects (m, thawer, 0); |
1251 | |
1194 | |
1252 | m->in_memory = MAP_IN_MEMORY; |
1195 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1258 | * Loads a map, which has been loaded earlier, from file. |
1201 | * Loads a map, which has been loaded earlier, from file. |
1259 | * Return the map object we load into (this can change from the passed |
1202 | * Return the map object we load into (this can change from the passed |
1260 | * option if we can't find the original map) |
1203 | * option if we can't find the original map) |
1261 | */ |
1204 | */ |
1262 | |
1205 | |
1263 | mapstruct * |
1206 | maptile * |
1264 | load_overlay_map (const char *filename, mapstruct *m) |
1207 | load_overlay_map (const char *filename, maptile *m) |
1265 | { |
1208 | { |
1266 | char pathname[MAX_BUF]; |
1209 | char pathname[MAX_BUF]; |
1267 | |
1210 | |
1268 | strcpy (pathname, create_overlay_pathname (filename)); |
1211 | strcpy (pathname, create_overlay_pathname (filename)); |
1269 | |
1212 | |
… | |
… | |
1275 | if (load_map_header (thawer, m)) |
1218 | if (load_map_header (thawer, m)) |
1276 | { |
1219 | { |
1277 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1220 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1278 | delete_map (m); |
1221 | delete_map (m); |
1279 | m = load_original_map (m->path, 0); |
1222 | m = load_original_map (m->path, 0); |
1280 | return NULL; |
1223 | return 0; |
1281 | } |
1224 | } |
1282 | /*allocate_map(m); */ |
1225 | /*m->allocate ();*/ |
1283 | |
1226 | |
1284 | m->in_memory = MAP_LOADING; |
1227 | m->in_memory = MAP_LOADING; |
1285 | load_objects (m, thawer, MAP_OVERLAY); |
1228 | load_objects (m, thawer, MAP_OVERLAY); |
1286 | |
1229 | |
1287 | m->in_memory = MAP_IN_MEMORY; |
1230 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1292 | * This is the start of unique map handling code |
1235 | * This is the start of unique map handling code |
1293 | *****************************************************************************/ |
1236 | *****************************************************************************/ |
1294 | |
1237 | |
1295 | /* This goes through map 'm' and removed any unique items on the map. */ |
1238 | /* This goes through map 'm' and removed any unique items on the map. */ |
1296 | static void |
1239 | static void |
1297 | delete_unique_items (mapstruct *m) |
1240 | delete_unique_items (maptile *m) |
1298 | { |
1241 | { |
1299 | int i, j, unique; |
1242 | int i, j, unique; |
1300 | object *op, *next; |
1243 | object *op, *next; |
1301 | |
1244 | |
1302 | for (i = 0; i < MAP_WIDTH (m); i++) |
1245 | for (i = 0; i < m->width; i++) |
1303 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1246 | for (j = 0; j < m->height; j++) |
1304 | { |
1247 | { |
1305 | unique = 0; |
1248 | unique = 0; |
|
|
1249 | |
1306 | for (op = get_map_ob (m, i, j); op; op = next) |
1250 | for (op = GET_MAP_OB (m, i, j); op; op = next) |
1307 | { |
1251 | { |
1308 | next = op->above; |
1252 | next = op->above; |
|
|
1253 | |
1309 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1254 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1310 | unique = 1; |
1255 | unique = 1; |
|
|
1256 | |
1311 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1257 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1312 | { |
1258 | { |
1313 | clean_object (op); |
1259 | op->destroy_inv (false); |
1314 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1260 | op->destroy (); |
1315 | remove_button_link (op); |
|
|
1316 | remove_ob (op); |
|
|
1317 | free_object (op); |
|
|
1318 | } |
1261 | } |
1319 | } |
1262 | } |
1320 | } |
1263 | } |
1321 | } |
1264 | } |
1322 | |
1265 | |
… | |
… | |
1324 | /* |
1267 | /* |
1325 | * Loads unique objects from file(s) into the map which is in memory |
1268 | * Loads unique objects from file(s) into the map which is in memory |
1326 | * m is the map to load unique items into. |
1269 | * m is the map to load unique items into. |
1327 | */ |
1270 | */ |
1328 | static void |
1271 | static void |
1329 | load_unique_objects (mapstruct *m) |
1272 | load_unique_objects (maptile *m) |
1330 | { |
1273 | { |
1331 | int count; |
1274 | int count; |
1332 | char firstname[MAX_BUF]; |
1275 | char firstname[MAX_BUF]; |
1333 | |
1276 | |
1334 | for (count = 0; count < 10; count++) |
1277 | for (count = 0; count < 10; count++) |
… | |
… | |
1347 | return; |
1290 | return; |
1348 | |
1291 | |
1349 | m->in_memory = MAP_LOADING; |
1292 | m->in_memory = MAP_LOADING; |
1350 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1293 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1351 | delete_unique_items (m); /* original map before, don't duplicate them */ |
1294 | delete_unique_items (m); /* original map before, don't duplicate them */ |
|
|
1295 | |
1352 | load_objects (m, thawer, 0); |
1296 | load_objects (m, thawer, 0); |
1353 | |
1297 | |
1354 | m->in_memory = MAP_IN_MEMORY; |
1298 | m->in_memory = MAP_IN_MEMORY; |
1355 | } |
1299 | } |
1356 | |
|
|
1357 | |
1300 | |
1358 | /* |
1301 | /* |
1359 | * Saves a map to file. If flag is set, it is saved into the same |
1302 | * Saves a map to file. If flag is set, it is saved into the same |
1360 | * file it was (originally) loaded from. Otherwise a temporary |
1303 | * file it was (originally) loaded from. Otherwise a temporary |
1361 | * filename will be genarated, and the file will be stored there. |
1304 | * filename will be genarated, and the file will be stored there. |
1362 | * The temporary filename will be stored in the mapstructure. |
1305 | * The temporary filename will be stored in the maptileure. |
1363 | * If the map is unique, we also save to the filename in the map |
1306 | * If the map is unique, we also save to the filename in the map |
1364 | * (this should have been updated when first loaded) |
1307 | * (this should have been updated when first loaded) |
1365 | */ |
1308 | */ |
1366 | |
|
|
1367 | int |
1309 | int |
1368 | new_save_map (mapstruct *m, int flag) |
1310 | new_save_map (maptile *m, int flag) |
1369 | { |
1311 | { |
1370 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1312 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1371 | int i; |
1313 | int i; |
1372 | |
1314 | |
1373 | if (flag && !*m->path) |
1315 | if (flag && !*m->path) |
… | |
… | |
1391 | make_path_to_file (filename); |
1333 | make_path_to_file (filename); |
1392 | } |
1334 | } |
1393 | else |
1335 | else |
1394 | { |
1336 | { |
1395 | if (!m->tmpname) |
1337 | if (!m->tmpname) |
1396 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1338 | m->tmpname = tempnam (settings.tmpdir, NULL); |
1397 | |
1339 | |
1398 | strcpy (filename, m->tmpname); |
1340 | strcpy (filename, m->tmpname); |
1399 | } |
1341 | } |
1400 | |
1342 | |
1401 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1343 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
… | |
… | |
1425 | print_shop_string (m, shop); |
1367 | print_shop_string (m, shop); |
1426 | fprintf (freezer, "shopitems %s\n", shop); |
1368 | fprintf (freezer, "shopitems %s\n", shop); |
1427 | } |
1369 | } |
1428 | if (m->shopgreed) |
1370 | if (m->shopgreed) |
1429 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1371 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1430 | #ifndef WIN32 |
|
|
1431 | if (m->shopmin) |
1372 | if (m->shopmin) |
1432 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1373 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1433 | if (m->shopmax) |
1374 | if (m->shopmax) |
1434 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1375 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1435 | #else |
|
|
1436 | if (m->shopmin) |
|
|
1437 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
|
|
1438 | if (m->shopmax) |
|
|
1439 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
|
|
1440 | #endif |
|
|
1441 | if (m->shoprace) |
1376 | if (m->shoprace) |
1442 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1377 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1443 | if (m->darkness) |
1378 | if (m->darkness) |
1444 | fprintf (freezer, "darkness %d\n", m->darkness); |
1379 | fprintf (freezer, "darkness %d\n", m->darkness); |
1445 | if (m->width) |
1380 | if (m->width) |
… | |
… | |
1510 | freezer.save (filename); |
1445 | freezer.save (filename); |
1511 | |
1446 | |
1512 | return 0; |
1447 | return 0; |
1513 | } |
1448 | } |
1514 | |
1449 | |
1515 | |
|
|
1516 | /* |
|
|
1517 | * Remove and free all objects in the inventory of the given object. |
|
|
1518 | * object.c ? |
|
|
1519 | */ |
|
|
1520 | |
|
|
1521 | void |
|
|
1522 | clean_object (object *op) |
|
|
1523 | { |
|
|
1524 | object *tmp, *next; |
|
|
1525 | |
|
|
1526 | for (tmp = op->inv; tmp; tmp = next) |
|
|
1527 | { |
|
|
1528 | next = tmp->below; |
|
|
1529 | clean_object (tmp); |
|
|
1530 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
|
|
1531 | remove_button_link (tmp); |
|
|
1532 | remove_ob (tmp); |
|
|
1533 | free_object (tmp); |
|
|
1534 | } |
|
|
1535 | } |
|
|
1536 | |
|
|
1537 | /* |
1450 | /* |
1538 | * Remove and free all objects in the given map. |
1451 | * Remove and free all objects in the given map. |
1539 | */ |
1452 | */ |
1540 | |
|
|
1541 | void |
1453 | void |
1542 | free_all_objects (mapstruct *m) |
1454 | free_all_objects (maptile *m) |
1543 | { |
1455 | { |
1544 | int i, j; |
1456 | if (!m->spaces) |
1545 | object *op; |
1457 | return; |
1546 | |
1458 | |
1547 | for (i = 0; i < MAP_WIDTH (m); i++) |
1459 | for (int i = 0; i < m->width; i++) |
1548 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1460 | for (int j = 0; j < m->height; j++) |
1549 | { |
1461 | { |
1550 | object *previous_obj = NULL; |
1462 | mapspace &ms = m->at (i, j); |
1551 | |
1463 | |
1552 | while ((op = GET_MAP_OB (m, i, j)) != NULL) |
1464 | while (object *op = ms.bot) |
1553 | { |
1465 | { |
1554 | if (op == previous_obj) |
|
|
1555 | { |
|
|
1556 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
|
|
1557 | break; |
|
|
1558 | } |
|
|
1559 | previous_obj = op; |
|
|
1560 | if (op->head != NULL) |
1466 | if (op->head) |
1561 | op = op->head; |
1467 | op = op->head; |
1562 | |
1468 | |
1563 | /* If the map isn't in memory, free_object will remove and |
1469 | op->destroy_inv (false); |
1564 | * free objects in op's inventory. So let it do the job. |
1470 | op->destroy (); |
1565 | */ |
|
|
1566 | if (m->in_memory == MAP_IN_MEMORY) |
|
|
1567 | clean_object (op); |
|
|
1568 | remove_ob (op); |
|
|
1569 | free_object (op); |
|
|
1570 | } |
1471 | } |
1571 | } |
1472 | } |
1572 | } |
1473 | } |
1573 | |
1474 | |
1574 | /* |
1475 | /* |
1575 | * Frees everything allocated by the given mapstructure. |
1476 | * Frees everything allocated by the given maptileure. |
1576 | * don't free tmpname - our caller is left to do that |
1477 | * don't free tmpname - our caller is left to do that |
1577 | */ |
1478 | */ |
1578 | |
|
|
1579 | void |
1479 | void |
1580 | free_map (mapstruct *m, int flag) |
1480 | free_map (maptile *m, int flag) |
1581 | { |
1481 | { |
1582 | int i; |
1482 | if (!m->in_memory) //TODO: makes no sense to me? |
1583 | |
|
|
1584 | if (!m->in_memory) |
|
|
1585 | { |
|
|
1586 | LOG (llevError, "Trying to free freed map.\n"); |
|
|
1587 | return; |
1483 | return; |
1588 | } |
1484 | |
|
|
1485 | m->in_memory = MAP_SAVING; |
|
|
1486 | |
|
|
1487 | // TODO: use new/delete |
|
|
1488 | |
1589 | if (flag && m->spaces) |
1489 | if (flag && m->spaces) |
1590 | free_all_objects (m); |
1490 | free_all_objects (m); |
1591 | if (m->name) |
1491 | |
1592 | FREE_AND_CLEAR (m->name); |
1492 | free (m->name), m->name = 0; |
1593 | if (m->spaces) |
1493 | free (m->spaces), m->spaces = 0; |
1594 | FREE_AND_CLEAR (m->spaces); |
1494 | free (m->msg), m->msg = 0; |
1595 | if (m->msg) |
1495 | free (m->maplore), m->maplore = 0; |
1596 | FREE_AND_CLEAR (m->msg); |
1496 | free (m->shoprace), m->shoprace = 0; |
1597 | if (m->maplore) |
1497 | delete [] m->shopitems, m->shopitems = 0; |
1598 | FREE_AND_CLEAR (m->maplore); |
1498 | |
1599 | if (m->shopitems) |
|
|
1600 | delete[]m->shopitems; |
|
|
1601 | m->shopitems = 0; |
|
|
1602 | if (m->shoprace) |
|
|
1603 | FREE_AND_CLEAR (m->shoprace); |
|
|
1604 | if (m->buttons) |
1499 | if (m->buttons) |
1605 | free_objectlinkpt (m->buttons); |
1500 | free_objectlinkpt (m->buttons), m->buttons = 0; |
1606 | m->buttons = NULL; |
1501 | |
1607 | for (i = 0; i < 4; i++) |
1502 | for (int i = 0; i < 4; i++) |
1608 | { |
1503 | { |
1609 | if (m->tile_path[i]) |
1504 | if (m->tile_path[i]) |
1610 | FREE_AND_CLEAR (m->tile_path[i]); |
1505 | free (m->tile_path[i]), m->tile_path[i] = 0; |
|
|
1506 | |
1611 | m->tile_map[i] = NULL; |
1507 | m->tile_map[i] = 0; |
1612 | } |
1508 | } |
|
|
1509 | |
1613 | m->in_memory = MAP_SWAPPED; |
1510 | m->in_memory = MAP_SWAPPED; |
1614 | } |
1511 | } |
1615 | |
1512 | |
1616 | /* |
1513 | maptile::~maptile () |
1617 | * function: vanish mapstruct |
1514 | { |
1618 | * m : pointer to mapstruct, if NULL no action |
1515 | free_map (this, 1); |
1619 | * this deletes all the data on the map (freeing pointers) |
1516 | free (tmpname); |
1620 | * and then removes this map from the global linked list of maps. |
1517 | } |
1621 | */ |
|
|
1622 | |
1518 | |
1623 | void |
1519 | void |
1624 | delete_map (mapstruct *m) |
1520 | maptile::do_destroy () |
1625 | { |
1521 | { |
1626 | mapstruct *tmp, *last; |
1522 | attachable::do_destroy (); |
1627 | int i; |
|
|
1628 | |
1523 | |
1629 | if (!m) |
1524 | free_all_objects (this); |
1630 | return; |
|
|
1631 | |
1525 | |
1632 | m->clear (); |
|
|
1633 | |
|
|
1634 | if (m->in_memory == MAP_IN_MEMORY) |
|
|
1635 | { |
|
|
1636 | /* change to MAP_SAVING, even though we are not, |
|
|
1637 | * so that remove_ob doesn't do as much work. |
|
|
1638 | */ |
|
|
1639 | m->in_memory = MAP_SAVING; |
|
|
1640 | free_map (m, 1); |
|
|
1641 | } |
|
|
1642 | /* move this out of free_map, since tmpname can still be needed if |
|
|
1643 | * the map is swapped out. |
|
|
1644 | */ |
|
|
1645 | if (m->tmpname) |
|
|
1646 | { |
|
|
1647 | free (m->tmpname); |
|
|
1648 | m->tmpname = NULL; |
|
|
1649 | } |
|
|
1650 | last = NULL; |
|
|
1651 | /* We need to look through all the maps and see if any maps |
1526 | /* We need to look through all the maps and see if any maps |
1652 | * are pointing at this one for tiling information. Since |
1527 | * are pointing at this one for tiling information. Since |
1653 | * tiling can be assymetric, we just can not look to see which |
1528 | * tiling can be asymetric, we just can not look to see which |
1654 | * maps this map tiles with and clears those. |
1529 | * maps this map tiles with and clears those. |
1655 | */ |
1530 | */ |
1656 | for (tmp = first_map; tmp != NULL; tmp = tmp->next) |
1531 | //TODO: non-euclidean-tiling MUST GO |
1657 | { |
1532 | for (maptile *m = first_map; m; m = m->next) |
1658 | if (tmp->next == m) |
|
|
1659 | last = tmp; |
|
|
1660 | |
|
|
1661 | /* This should hopefully get unrolled on a decent compiler */ |
|
|
1662 | for (i = 0; i < 4; i++) |
1533 | for (int i = 0; i < 4; i++) |
1663 | if (tmp->tile_map[i] == m) |
1534 | if (m->tile_map[i] == this) |
1664 | tmp->tile_map[i] = NULL; |
1535 | m->tile_map[i] = 0; |
1665 | } |
|
|
1666 | |
1536 | |
1667 | /* If last is null, then this should be the first map in the list */ |
1537 | if (first_map == this) |
1668 | if (!last) |
|
|
1669 | { |
|
|
1670 | if (m == first_map) |
|
|
1671 | first_map = m->next; |
1538 | first_map = next; |
1672 | else |
|
|
1673 | /* m->path is a static char, so should hopefully still have |
|
|
1674 | * some useful data in it. |
|
|
1675 | */ |
|
|
1676 | LOG (llevError, "delete_map: Unable to find map %s in list\n", m->path); |
|
|
1677 | } |
|
|
1678 | else |
1539 | else |
1679 | last->next = m->next; |
1540 | for (maptile *m = first_map; m; m = m->next) |
1680 | |
1541 | if (m->next = this) |
1681 | delete m; |
1542 | { |
|
|
1543 | m->next = next; |
|
|
1544 | break; |
|
|
1545 | } |
1682 | } |
1546 | } |
1683 | |
1547 | |
1684 | |
1548 | //TODO: must go |
|
|
1549 | void |
|
|
1550 | delete_map (maptile *m) |
|
|
1551 | { |
|
|
1552 | if (m) |
|
|
1553 | m->destroy (); |
|
|
1554 | } |
1685 | |
1555 | |
1686 | /* |
1556 | /* |
1687 | * Makes sure the given map is loaded and swapped in. |
1557 | * Makes sure the given map is loaded and swapped in. |
1688 | * name is path name of the map. |
1558 | * name is path name of the map. |
1689 | * flags meaning: |
1559 | * flags meaning: |
… | |
… | |
1692 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1562 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1693 | * dont do any more name translation on it. |
1563 | * dont do any more name translation on it. |
1694 | * |
1564 | * |
1695 | * Returns a pointer to the given map. |
1565 | * Returns a pointer to the given map. |
1696 | */ |
1566 | */ |
1697 | |
1567 | maptile * |
1698 | mapstruct * |
|
|
1699 | ready_map_name (const char *name, int flags) |
1568 | ready_map_name (const char *name, int flags) |
1700 | { |
1569 | { |
1701 | mapstruct *m; |
|
|
1702 | |
|
|
1703 | if (!name) |
1570 | if (!name) |
1704 | return (NULL); |
1571 | return 0; |
1705 | |
1572 | |
1706 | /* Have we been at this level before? */ |
1573 | /* Have we been at this level before? */ |
1707 | m = has_been_loaded (name); |
1574 | maptile *m = has_been_loaded (name); |
1708 | |
1575 | |
1709 | /* Map is good to go, so just return it */ |
1576 | /* Map is good to go, so just return it */ |
1710 | if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) |
1577 | if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) |
1711 | { |
|
|
1712 | return m; |
1578 | return m; |
1713 | } |
|
|
1714 | |
1579 | |
1715 | /* unique maps always get loaded from their original location, and never |
1580 | /* unique maps always get loaded from their original location, and never |
1716 | * a temp location. Likewise, if map_flush is set, or we have never loaded |
1581 | * a temp location. Likewise, if map_flush is set, or we have never loaded |
1717 | * this map, load it now. I removed the reset checking from here - |
1582 | * this map, load it now. I removed the reset checking from here - |
1718 | * it seems the probability of a player trying to enter a map that should |
1583 | * it seems the probability of a player trying to enter a map that should |
… | |
… | |
1720 | * a bit cleaner (and players probably shouldn't rely on exact timing for |
1585 | * a bit cleaner (and players probably shouldn't rely on exact timing for |
1721 | * resets in any case - if they really care, they should use the 'maps command. |
1586 | * resets in any case - if they really care, they should use the 'maps command. |
1722 | */ |
1587 | */ |
1723 | if ((flags & (MAP_FLUSH | MAP_PLAYER_UNIQUE)) || !m) |
1588 | if ((flags & (MAP_FLUSH | MAP_PLAYER_UNIQUE)) || !m) |
1724 | { |
1589 | { |
1725 | |
|
|
1726 | /* first visit or time to reset */ |
1590 | /* first visit or time to reset */ |
1727 | if (m) |
1591 | if (m) |
1728 | { |
1592 | { |
1729 | clean_tmp_map (m); /* Doesn't make much difference */ |
1593 | clean_tmp_map (m); /* Doesn't make much difference */ |
1730 | delete_map (m); |
1594 | delete_map (m); |
… | |
… | |
1808 | * have a difficulty set than using this function - human calculation |
1672 | * have a difficulty set than using this function - human calculation |
1809 | * is much better than this functions guesswork. |
1673 | * is much better than this functions guesswork. |
1810 | */ |
1674 | */ |
1811 | |
1675 | |
1812 | int |
1676 | int |
1813 | calculate_difficulty (mapstruct *m) |
1677 | calculate_difficulty (maptile *m) |
1814 | { |
1678 | { |
1815 | object *op; |
1679 | object *op; |
1816 | archetype *at; |
1680 | archetype *at; |
1817 | int x, y, i; |
1681 | int x, y, i; |
1818 | long monster_cnt = 0; |
1682 | long monster_cnt = 0; |
1819 | double avgexp = 0; |
1683 | double avgexp = 0; |
1820 | sint64 total_exp = 0; |
1684 | sint64 total_exp = 0; |
1821 | |
1685 | |
1822 | if (MAP_DIFFICULTY (m)) |
1686 | if (m->difficulty) |
1823 | { |
1687 | { |
1824 | LOG (llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); |
1688 | LOG (llevDebug, "Using stored map difficulty: %d\n", m->difficulty); |
1825 | return MAP_DIFFICULTY (m); |
1689 | return m->difficulty; |
1826 | } |
1690 | } |
1827 | |
1691 | |
1828 | for (x = 0; x < MAP_WIDTH (m); x++) |
1692 | for (x = 0; x < m->width; x++) |
1829 | for (y = 0; y < MAP_HEIGHT (m); y++) |
1693 | for (y = 0; y < m->height; y++) |
1830 | for (op = get_map_ob (m, x, y); op != NULL; op = op->above) |
1694 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
1831 | { |
1695 | { |
1832 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1696 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1833 | { |
1697 | { |
1834 | total_exp += op->stats.exp; |
1698 | total_exp += op->stats.exp; |
1835 | monster_cnt++; |
1699 | monster_cnt++; |
… | |
… | |
1860 | |
1724 | |
1861 | return 1; |
1725 | return 1; |
1862 | } |
1726 | } |
1863 | |
1727 | |
1864 | void |
1728 | void |
1865 | clean_tmp_map (mapstruct *m) |
1729 | clean_tmp_map (maptile *m) |
1866 | { |
1730 | { |
1867 | if (m->tmpname == NULL) |
1731 | if (m->tmpname == NULL) |
1868 | return; |
1732 | return; |
1869 | INVOKE_MAP (CLEAN, m); |
1733 | INVOKE_MAP (CLEAN, m); |
1870 | (void) unlink (m->tmpname); |
1734 | (void) unlink (m->tmpname); |
… | |
… | |
1895 | * to maps than los. |
1759 | * to maps than los. |
1896 | * postive values make it darker, negative make it brighter |
1760 | * postive values make it darker, negative make it brighter |
1897 | */ |
1761 | */ |
1898 | |
1762 | |
1899 | int |
1763 | int |
1900 | change_map_light (mapstruct *m, int change) |
1764 | change_map_light (maptile *m, int change) |
1901 | { |
1765 | { |
1902 | int new_level = m->darkness + change; |
1766 | int new_level = m->darkness + change; |
1903 | |
1767 | |
1904 | /* Nothing to do */ |
1768 | /* Nothing to do */ |
1905 | if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) |
1769 | if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) |
… | |
… | |
1928 | /* All clients need to get re-updated for the change */ |
1792 | /* All clients need to get re-updated for the change */ |
1929 | update_all_map_los (m); |
1793 | update_all_map_los (m); |
1930 | return 1; |
1794 | return 1; |
1931 | } |
1795 | } |
1932 | |
1796 | |
1933 | |
|
|
1934 | /* |
1797 | /* |
1935 | * This function updates various attributes about a specific space |
1798 | * This function updates various attributes about a specific space |
1936 | * on the map (what it looks like, whether it blocks magic, |
1799 | * on the map (what it looks like, whether it blocks magic, |
1937 | * has a living creatures, prevents people from passing |
1800 | * has a living creatures, prevents people from passing |
1938 | * through, etc) |
1801 | * through, etc) |
1939 | */ |
1802 | */ |
1940 | void |
1803 | void |
1941 | update_position (mapstruct *m, int x, int y) |
1804 | mapspace::update_ () |
1942 | { |
1805 | { |
1943 | object *tmp, *last = NULL; |
1806 | object *tmp, *last = 0; |
1944 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1807 | uint8 flags = 0, light = 0, anywhere = 0; |
1945 | New_Face *top, *floor, *middle; |
1808 | New_Face *top, *floor, *middle; |
1946 | object *top_obj, *floor_obj, *middle_obj; |
1809 | object *top_obj, *floor_obj, *middle_obj; |
1947 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1810 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1948 | |
1811 | |
1949 | oldflags = GET_MAP_FLAGS (m, x, y); |
|
|
1950 | if (!(oldflags & P_NEED_UPDATE)) |
|
|
1951 | { |
|
|
1952 | LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); |
|
|
1953 | return; |
|
|
1954 | } |
|
|
1955 | |
|
|
1956 | middle = blank_face; |
1812 | middle = blank_face; |
1957 | top = blank_face; |
1813 | top = blank_face; |
1958 | floor = blank_face; |
1814 | floor = blank_face; |
1959 | |
1815 | |
1960 | middle_obj = NULL; |
1816 | middle_obj = 0; |
1961 | top_obj = NULL; |
1817 | top_obj = 0; |
1962 | floor_obj = NULL; |
1818 | floor_obj = 0; |
1963 | |
1819 | |
1964 | for (tmp = get_map_ob (m, x, y); tmp; last = tmp, tmp = tmp->above) |
1820 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1965 | { |
1821 | { |
1966 | |
|
|
1967 | /* This could be made additive I guess (two lights better than |
1822 | /* This could be made additive I guess (two lights better than |
1968 | * one). But if so, it shouldn't be a simple additive - 2 |
1823 | * one). But if so, it shouldn't be a simple additive - 2 |
1969 | * light bulbs do not illuminate twice as far as once since |
1824 | * light bulbs do not illuminate twice as far as once since |
1970 | * it is a disapation factor that is squared (or is it cubed?) |
1825 | * it is a dissapation factor that is cubed. |
1971 | */ |
1826 | */ |
1972 | if (tmp->glow_radius > light) |
1827 | if (tmp->glow_radius > light) |
1973 | light = tmp->glow_radius; |
1828 | light = tmp->glow_radius; |
1974 | |
1829 | |
1975 | /* This call is needed in order to update objects the player |
1830 | /* This call is needed in order to update objects the player |
… | |
… | |
2013 | { |
1868 | { |
2014 | middle = tmp->face; |
1869 | middle = tmp->face; |
2015 | middle_obj = tmp; |
1870 | middle_obj = tmp; |
2016 | } |
1871 | } |
2017 | } |
1872 | } |
|
|
1873 | |
2018 | if (tmp == tmp->above) |
1874 | if (tmp == tmp->above) |
2019 | { |
1875 | { |
2020 | LOG (llevError, "Error in structure of map\n"); |
1876 | LOG (llevError, "Error in structure of map\n"); |
2021 | exit (-1); |
1877 | exit (-1); |
2022 | } |
1878 | } |
2023 | |
1879 | |
2024 | move_slow |= tmp->move_slow; |
1880 | move_slow |= tmp->move_slow; |
2025 | move_block |= tmp->move_block; |
1881 | move_block |= tmp->move_block; |
2026 | move_on |= tmp->move_on; |
1882 | move_on |= tmp->move_on; |
2027 | move_off |= tmp->move_off; |
1883 | move_off |= tmp->move_off; |
2028 | move_allow |= tmp->move_allow; |
1884 | move_allow |= tmp->move_allow; |
2029 | |
1885 | |
2030 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
|
|
2031 | flags |= P_IS_ALIVE; |
|
|
2032 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) |
|
|
2033 | flags |= P_NO_MAGIC; |
|
|
2034 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) |
|
|
2035 | flags |= P_NO_CLERIC; |
|
|
2036 | if (tmp->type == SAFE_GROUND) |
|
|
2037 | flags |= P_SAFE; |
|
|
2038 | |
|
|
2039 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) |
1886 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; |
2040 | flags |= P_BLOCKSVIEW; |
1887 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; |
2041 | } /* for stack of objects */ |
1888 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
2042 | |
1889 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
2043 | /* we don't want to rely on this function to have accurate flags, but |
1890 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
2044 | * since we're already doing the work, we calculate them here. |
1891 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
2045 | * if they don't match, logic is broken someplace. |
|
|
2046 | */ |
|
|
2047 | if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) |
|
|
2048 | { |
1892 | } |
2049 | LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", |
1893 | |
2050 | m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); |
1894 | this->light = light; |
2051 | } |
1895 | this->flags_ = flags; |
2052 | SET_MAP_FLAGS (m, x, y, flags); |
1896 | this->move_block = move_block & ~move_allow; |
2053 | SET_MAP_MOVE_BLOCK (m, x, y, move_block & ~move_allow); |
1897 | this->move_on = move_on; |
2054 | SET_MAP_MOVE_ON (m, x, y, move_on); |
1898 | this->move_off = move_off; |
2055 | SET_MAP_MOVE_OFF (m, x, y, move_off); |
1899 | this->move_slow = move_slow; |
2056 | SET_MAP_MOVE_SLOW (m, x, y, move_slow); |
|
|
2057 | |
1900 | |
2058 | /* At this point, we have a floor face (if there is a floor), |
1901 | /* At this point, we have a floor face (if there is a floor), |
2059 | * and the floor is set - we are not going to touch it at |
1902 | * and the floor is set - we are not going to touch it at |
2060 | * this point. |
1903 | * this point. |
2061 | * middle contains the highest visibility face. |
1904 | * middle contains the highest visibility face. |
… | |
… | |
2115 | break; |
1958 | break; |
2116 | } |
1959 | } |
2117 | } |
1960 | } |
2118 | } |
1961 | } |
2119 | } |
1962 | } |
|
|
1963 | |
2120 | if (middle == floor) |
1964 | if (middle == floor) |
2121 | middle = blank_face; |
1965 | middle = blank_face; |
|
|
1966 | |
2122 | if (top == middle) |
1967 | if (top == middle) |
2123 | middle = blank_face; |
1968 | middle = blank_face; |
2124 | SET_MAP_FACE (m, x, y, top, 0); |
|
|
2125 | if (top != blank_face) |
|
|
2126 | SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); |
|
|
2127 | else |
|
|
2128 | SET_MAP_FACE_OBJ (m, x, y, NULL, 0); |
|
|
2129 | SET_MAP_FACE (m, x, y, middle, 1); |
|
|
2130 | if (middle != blank_face) |
|
|
2131 | SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); |
|
|
2132 | else |
|
|
2133 | SET_MAP_FACE_OBJ (m, x, y, NULL, 1); |
|
|
2134 | SET_MAP_FACE (m, x, y, floor, 2); |
|
|
2135 | if (floor != blank_face) |
|
|
2136 | SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); |
|
|
2137 | else |
|
|
2138 | SET_MAP_FACE_OBJ (m, x, y, NULL, 2); |
|
|
2139 | SET_MAP_LIGHT (m, x, y, light); |
|
|
2140 | } |
|
|
2141 | |
1969 | |
|
|
1970 | faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; |
|
|
1971 | faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; |
|
|
1972 | faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; |
|
|
1973 | } |
2142 | |
1974 | |
2143 | void |
1975 | void |
2144 | set_map_reset_time (mapstruct *map) |
1976 | set_map_reset_time (maptile *map) |
2145 | { |
1977 | { |
2146 | int timeout; |
1978 | int timeout; |
2147 | |
1979 | |
2148 | timeout = MAP_RESET_TIMEOUT (map); |
1980 | timeout = map->reset_timeout; |
2149 | if (timeout <= 0) |
1981 | if (timeout <= 0) |
2150 | timeout = MAP_DEFAULTRESET; |
1982 | timeout = MAP_DEFAULTRESET; |
2151 | if (timeout >= MAP_MAXRESET) |
1983 | if (timeout >= MAP_MAXRESET) |
2152 | timeout = MAP_MAXRESET; |
1984 | timeout = MAP_MAXRESET; |
2153 | MAP_WHEN_RESET (map) = seconds () + timeout; |
1985 | map->reset_time = time (0) + timeout; |
2154 | } |
1986 | } |
2155 | |
1987 | |
2156 | /* this updates the orig_map->tile_map[tile_num] value after loading |
1988 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2157 | * the map. It also takes care of linking back the freshly loaded |
1989 | * the map. It also takes care of linking back the freshly loaded |
2158 | * maps tile_map values if it tiles back to this one. It returns |
1990 | * maps tile_map values if it tiles back to this one. It returns |
2159 | * the value of orig_map->tile_map[tile_num]. It really only does this |
1991 | * the value of orig_map->tile_map[tile_num]. It really only does this |
2160 | * so that it is easier for calling functions to verify success. |
1992 | * so that it is easier for calling functions to verify success. |
2161 | */ |
1993 | */ |
2162 | |
1994 | |
2163 | static mapstruct * |
1995 | static maptile * |
2164 | load_and_link_tiled_map (mapstruct *orig_map, int tile_num) |
1996 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
2165 | { |
1997 | { |
2166 | int dest_tile = (tile_num + 2) % 4; |
1998 | int dest_tile = (tile_num + 2) % 4; |
2167 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
1999 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
2168 | |
2000 | |
2169 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
2001 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
… | |
… | |
2184 | * tiled maps. |
2016 | * tiled maps. |
2185 | * |
2017 | * |
2186 | * |
2018 | * |
2187 | */ |
2019 | */ |
2188 | int |
2020 | int |
2189 | out_of_map (mapstruct *m, int x, int y) |
2021 | out_of_map (maptile *m, int x, int y) |
2190 | { |
2022 | { |
2191 | |
|
|
2192 | /* If we get passed a null map, this is obviously the |
2023 | /* If we get passed a null map, this is obviously the |
2193 | * case. This generally shouldn't happen, but if the |
2024 | * case. This generally shouldn't happen, but if the |
2194 | * map loads fail below, it could happen. |
2025 | * map loads fail below, it could happen. |
2195 | */ |
2026 | */ |
2196 | if (!m) |
2027 | if (!m) |
… | |
… | |
2198 | |
2029 | |
2199 | if (x < 0) |
2030 | if (x < 0) |
2200 | { |
2031 | { |
2201 | if (!m->tile_path[3]) |
2032 | if (!m->tile_path[3]) |
2202 | return 1; |
2033 | return 1; |
|
|
2034 | |
2203 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2035 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2204 | { |
|
|
2205 | load_and_link_tiled_map (m, 3); |
2036 | load_and_link_tiled_map (m, 3); |
2206 | } |
2037 | |
2207 | return (out_of_map (m->tile_map[3], x + MAP_WIDTH (m->tile_map[3]), y)); |
2038 | return (out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y)); |
2208 | } |
2039 | } |
2209 | if (x >= MAP_WIDTH (m)) |
2040 | |
|
|
2041 | if (x >= m->width) |
2210 | { |
2042 | { |
2211 | if (!m->tile_path[1]) |
2043 | if (!m->tile_path[1]) |
2212 | return 1; |
2044 | return 1; |
|
|
2045 | |
2213 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2046 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2214 | { |
|
|
2215 | load_and_link_tiled_map (m, 1); |
2047 | load_and_link_tiled_map (m, 1); |
2216 | } |
2048 | |
2217 | return (out_of_map (m->tile_map[1], x - MAP_WIDTH (m), y)); |
2049 | return (out_of_map (m->tile_map[1], x - m->width, y)); |
2218 | } |
2050 | } |
|
|
2051 | |
2219 | if (y < 0) |
2052 | if (y < 0) |
2220 | { |
2053 | { |
2221 | if (!m->tile_path[0]) |
2054 | if (!m->tile_path[0]) |
2222 | return 1; |
2055 | return 1; |
|
|
2056 | |
2223 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2057 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2224 | { |
|
|
2225 | load_and_link_tiled_map (m, 0); |
2058 | load_and_link_tiled_map (m, 0); |
2226 | } |
2059 | |
2227 | return (out_of_map (m->tile_map[0], x, y + MAP_HEIGHT (m->tile_map[0]))); |
2060 | return (out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height)); |
2228 | } |
2061 | } |
2229 | if (y >= MAP_HEIGHT (m)) |
2062 | |
|
|
2063 | if (y >= m->height) |
2230 | { |
2064 | { |
2231 | if (!m->tile_path[2]) |
2065 | if (!m->tile_path[2]) |
2232 | return 1; |
2066 | return 1; |
|
|
2067 | |
2233 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2068 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2234 | { |
|
|
2235 | load_and_link_tiled_map (m, 2); |
2069 | load_and_link_tiled_map (m, 2); |
2236 | } |
2070 | |
2237 | return (out_of_map (m->tile_map[2], x, y - MAP_HEIGHT (m))); |
2071 | return (out_of_map (m->tile_map[2], x, y - m->height)); |
2238 | } |
2072 | } |
2239 | |
2073 | |
2240 | /* Simple case - coordinates are within this local |
2074 | /* Simple case - coordinates are within this local |
2241 | * map. |
2075 | * map. |
2242 | */ |
2076 | */ |
… | |
… | |
2249 | * the map as that the coordinates are really on, and |
2083 | * the map as that the coordinates are really on, and |
2250 | * updates x and y to be the localized coordinates. |
2084 | * updates x and y to be the localized coordinates. |
2251 | * Using this is more efficient of calling out_of_map |
2085 | * Using this is more efficient of calling out_of_map |
2252 | * and then figuring out what the real map is |
2086 | * and then figuring out what the real map is |
2253 | */ |
2087 | */ |
2254 | mapstruct * |
2088 | maptile * |
2255 | get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) |
2089 | get_map_from_coord (maptile *m, sint16 * x, sint16 * y) |
2256 | { |
2090 | { |
2257 | |
2091 | |
2258 | if (*x < 0) |
2092 | if (*x < 0) |
2259 | { |
2093 | { |
2260 | if (!m->tile_path[3]) |
2094 | if (!m->tile_path[3]) |
2261 | return NULL; |
2095 | return 0; |
2262 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2096 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2263 | load_and_link_tiled_map (m, 3); |
2097 | load_and_link_tiled_map (m, 3); |
2264 | |
2098 | |
2265 | *x += MAP_WIDTH (m->tile_map[3]); |
2099 | *x += m->tile_map[3]->width; |
2266 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2100 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2267 | } |
2101 | } |
2268 | if (*x >= MAP_WIDTH (m)) |
2102 | |
|
|
2103 | if (*x >= m->width) |
2269 | { |
2104 | { |
2270 | if (!m->tile_path[1]) |
2105 | if (!m->tile_path[1]) |
2271 | return NULL; |
2106 | return 0; |
|
|
2107 | |
2272 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2108 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2273 | load_and_link_tiled_map (m, 1); |
2109 | load_and_link_tiled_map (m, 1); |
2274 | |
2110 | |
2275 | *x -= MAP_WIDTH (m); |
2111 | *x -= m->width; |
2276 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2112 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2277 | } |
2113 | } |
|
|
2114 | |
2278 | if (*y < 0) |
2115 | if (*y < 0) |
2279 | { |
2116 | { |
2280 | if (!m->tile_path[0]) |
2117 | if (!m->tile_path[0]) |
2281 | return NULL; |
2118 | return 0; |
|
|
2119 | |
2282 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2120 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2283 | load_and_link_tiled_map (m, 0); |
2121 | load_and_link_tiled_map (m, 0); |
2284 | |
2122 | |
2285 | *y += MAP_HEIGHT (m->tile_map[0]); |
2123 | *y += m->tile_map[0]->height; |
2286 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2124 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2287 | } |
2125 | } |
2288 | if (*y >= MAP_HEIGHT (m)) |
2126 | |
|
|
2127 | if (*y >= m->height) |
2289 | { |
2128 | { |
2290 | if (!m->tile_path[2]) |
2129 | if (!m->tile_path[2]) |
2291 | return NULL; |
2130 | return 0; |
|
|
2131 | |
2292 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2132 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2293 | load_and_link_tiled_map (m, 2); |
2133 | load_and_link_tiled_map (m, 2); |
2294 | |
2134 | |
2295 | *y -= MAP_HEIGHT (m); |
2135 | *y -= m->height; |
2296 | return (get_map_from_coord (m->tile_map[2], x, y)); |
2136 | return (get_map_from_coord (m->tile_map[2], x, y)); |
2297 | } |
2137 | } |
2298 | |
2138 | |
2299 | /* Simple case - coordinates are within this local |
2139 | /* Simple case - coordinates are within this local |
2300 | * map. |
2140 | * map. |
… | |
… | |
2306 | /** |
2146 | /** |
2307 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2147 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2308 | * map1 to map2 in dx/dy. |
2148 | * map1 to map2 in dx/dy. |
2309 | */ |
2149 | */ |
2310 | static int |
2150 | static int |
2311 | adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) |
2151 | adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) |
2312 | { |
2152 | { |
2313 | if (!map1 || !map2) |
2153 | if (!map1 || !map2) |
2314 | return 0; |
2154 | return 0; |
2315 | |
2155 | |
2316 | if (map1 == map2) |
2156 | if (map1 == map2) |
… | |
… | |
2320 | |
2160 | |
2321 | } |
2161 | } |
2322 | else if (map1->tile_map[0] == map2) |
2162 | else if (map1->tile_map[0] == map2) |
2323 | { /* up */ |
2163 | { /* up */ |
2324 | *dx = 0; |
2164 | *dx = 0; |
2325 | *dy = -MAP_HEIGHT (map2); |
2165 | *dy = -map2->height; |
2326 | } |
2166 | } |
2327 | else if (map1->tile_map[1] == map2) |
2167 | else if (map1->tile_map[1] == map2) |
2328 | { /* right */ |
2168 | { /* right */ |
2329 | *dx = MAP_WIDTH (map1); |
2169 | *dx = map1->width; |
2330 | *dy = 0; |
2170 | *dy = 0; |
2331 | } |
2171 | } |
2332 | else if (map1->tile_map[2] == map2) |
2172 | else if (map1->tile_map[2] == map2) |
2333 | { /* down */ |
2173 | { /* down */ |
2334 | *dx = 0; |
2174 | *dx = 0; |
2335 | *dy = MAP_HEIGHT (map1); |
2175 | *dy = map1->height; |
2336 | } |
2176 | } |
2337 | else if (map1->tile_map[3] == map2) |
2177 | else if (map1->tile_map[3] == map2) |
2338 | { /* left */ |
2178 | { /* left */ |
2339 | *dx = -MAP_WIDTH (map2); |
2179 | *dx = -map2->width; |
2340 | *dy = 0; |
2180 | *dy = 0; |
2341 | |
2181 | |
2342 | } |
2182 | } |
2343 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) |
2183 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) |
2344 | { /* up right */ |
2184 | { /* up right */ |
2345 | *dx = MAP_WIDTH (map1->tile_map[0]); |
2185 | *dx = map1->tile_map[0]->width; |
2346 | *dy = -MAP_HEIGHT (map1->tile_map[0]); |
2186 | *dy = -map1->tile_map[0]->height; |
2347 | } |
2187 | } |
2348 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) |
2188 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) |
2349 | { /* up left */ |
2189 | { /* up left */ |
2350 | *dx = -MAP_WIDTH (map2); |
2190 | *dx = -map2->width; |
2351 | *dy = -MAP_HEIGHT (map1->tile_map[0]); |
2191 | *dy = -map1->tile_map[0]->height; |
2352 | } |
2192 | } |
2353 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) |
2193 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) |
2354 | { /* right up */ |
2194 | { /* right up */ |
2355 | *dx = MAP_WIDTH (map1); |
2195 | *dx = map1->width; |
2356 | *dy = -MAP_HEIGHT (map2); |
2196 | *dy = -map2->height; |
2357 | } |
2197 | } |
2358 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) |
2198 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) |
2359 | { /* right down */ |
2199 | { /* right down */ |
2360 | *dx = MAP_WIDTH (map1); |
2200 | *dx = map1->width; |
2361 | *dy = MAP_HEIGHT (map1->tile_map[1]); |
2201 | *dy = map1->tile_map[1]->height; |
2362 | } |
2202 | } |
2363 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) |
2203 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) |
2364 | { /* down right */ |
2204 | { /* down right */ |
2365 | *dx = MAP_WIDTH (map1->tile_map[2]); |
2205 | *dx = map1->tile_map[2]->width; |
2366 | *dy = MAP_HEIGHT (map1); |
2206 | *dy = map1->height; |
2367 | } |
2207 | } |
2368 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) |
2208 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) |
2369 | { /* down left */ |
2209 | { /* down left */ |
2370 | *dx = -MAP_WIDTH (map2); |
2210 | *dx = -map2->width; |
2371 | *dy = MAP_HEIGHT (map1); |
2211 | *dy = map1->height; |
2372 | } |
2212 | } |
2373 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) |
2213 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) |
2374 | { /* left up */ |
2214 | { /* left up */ |
2375 | *dx = -MAP_WIDTH (map1->tile_map[3]); |
2215 | *dx = -map1->tile_map[3]->width; |
2376 | *dy = -MAP_HEIGHT (map2); |
2216 | *dy = -map2->height; |
2377 | } |
2217 | } |
2378 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) |
2218 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) |
2379 | { /* left down */ |
2219 | { /* left down */ |
2380 | *dx = -MAP_WIDTH (map1->tile_map[3]); |
2220 | *dx = -map1->tile_map[3]->width; |
2381 | *dy = MAP_HEIGHT (map1->tile_map[3]); |
2221 | *dy = map1->tile_map[3]->height; |
2382 | |
2222 | |
2383 | } |
2223 | } |
2384 | else |
2224 | else |
2385 | { /* not "adjacent" enough */ |
2225 | { /* not "adjacent" enough */ |
2386 | return 0; |
2226 | return 0; |
… | |
… | |
2474 | * for something in the future. Also, since no object is pasted, the best |
2314 | * for something in the future. Also, since no object is pasted, the best |
2475 | * field of the rv_vector is set to NULL. |
2315 | * field of the rv_vector is set to NULL. |
2476 | */ |
2316 | */ |
2477 | |
2317 | |
2478 | void |
2318 | void |
2479 | get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2319 | get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2480 | { |
2320 | { |
2481 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2321 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2482 | { |
2322 | { |
2483 | /* be conservative and fill in _some_ data */ |
2323 | /* be conservative and fill in _some_ data */ |
2484 | retval->distance = 100000; |
2324 | retval->distance = 100000; |