… | |
… | |
27 | |
27 | |
28 | #include <loader.h> |
28 | #include <loader.h> |
29 | #include <unistd.h> |
29 | #include <unistd.h> |
30 | |
30 | |
31 | #include "path.h" |
31 | #include "path.h" |
32 | |
|
|
33 | |
32 | |
34 | /* |
33 | /* |
35 | * Returns the maptile which has a name matching the given argument. |
34 | * Returns the maptile which has a name matching the given argument. |
36 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
37 | */ |
36 | */ |
… | |
… | |
324 | /* We basically go through the stack of objects, and if there is |
323 | /* We basically go through the stack of objects, and if there is |
325 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
324 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
326 | * true. If we get through the entire stack, that must mean |
325 | * true. If we get through the entire stack, that must mean |
327 | * ob is blocking it, so return 0. |
326 | * ob is blocking it, so return 0. |
328 | */ |
327 | */ |
329 | for (tmp = GET_MAP_OB (m, sx, sy); tmp != NULL; tmp = tmp->above) |
328 | for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) |
330 | { |
329 | { |
331 | |
330 | |
332 | /* This must be before the checks below. Code for inventory checkers. */ |
331 | /* This must be before the checks below. Code for inventory checkers. */ |
333 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
332 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
334 | { |
333 | { |
… | |
… | |
398 | * |
397 | * |
399 | * Note this used to be arch_blocked, but with new movement |
398 | * Note this used to be arch_blocked, but with new movement |
400 | * code, we need to have actual object to check its move_type |
399 | * code, we need to have actual object to check its move_type |
401 | * against the move_block values. |
400 | * against the move_block values. |
402 | */ |
401 | */ |
403 | |
|
|
404 | int |
402 | int |
405 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
403 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
406 | { |
404 | { |
407 | archetype *tmp; |
405 | archetype *tmp; |
408 | int flag; |
406 | int flag; |
… | |
… | |
438 | |
436 | |
439 | /* Note it is intentional that we check ob - the movement type of the |
437 | /* Note it is intentional that we check ob - the movement type of the |
440 | * head of the object should correspond for the entire object. |
438 | * head of the object should correspond for the entire object. |
441 | */ |
439 | */ |
442 | if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) |
440 | if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) |
443 | return AB_NO_PASS; |
441 | return P_NO_PASS; |
444 | |
|
|
445 | } |
442 | } |
|
|
443 | |
446 | return 0; |
444 | return 0; |
447 | } |
445 | } |
448 | |
446 | |
449 | /* When the map is loaded, load_object does not actually insert objects |
447 | /* When the map is loaded, load_object does not actually insert objects |
450 | * into inventory, but just links them. What this does is go through |
448 | * into inventory, but just links them. What this does is go through |
… | |
… | |
487 | object *tmp, *op, *last, *above; |
485 | object *tmp, *op, *last, *above; |
488 | archetype *at; |
486 | archetype *at; |
489 | |
487 | |
490 | for (x = 0; x < MAP_WIDTH (m); x++) |
488 | for (x = 0; x < MAP_WIDTH (m); x++) |
491 | for (y = 0; y < MAP_HEIGHT (m); y++) |
489 | for (y = 0; y < MAP_HEIGHT (m); y++) |
492 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) |
490 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) |
493 | { |
491 | { |
494 | above = tmp->above; |
492 | above = tmp->above; |
495 | |
493 | |
496 | /* already multipart - don't do anything more */ |
494 | /* already multipart - don't do anything more */ |
497 | if (tmp->head || tmp->more) |
495 | if (tmp->head || tmp->more) |
… | |
… | |
582 | { |
580 | { |
583 | for (j = 0; j < m->height; j++) |
581 | for (j = 0; j < m->height; j++) |
584 | { |
582 | { |
585 | unique = 0; |
583 | unique = 0; |
586 | /* check for unique items, or unique squares */ |
584 | /* check for unique items, or unique squares */ |
587 | 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) |
588 | { |
586 | { |
589 | 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)) |
590 | unique = 1; |
588 | unique = 1; |
591 | |
589 | |
592 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
590 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
… | |
… | |
613 | /* first pass - save one-part objects */ |
611 | /* first pass - save one-part objects */ |
614 | for (i = 0; i < MAP_WIDTH (m); i++) |
612 | for (i = 0; i < MAP_WIDTH (m); i++) |
615 | for (j = 0; j < MAP_HEIGHT (m); j++) |
613 | for (j = 0; j < MAP_HEIGHT (m); j++) |
616 | { |
614 | { |
617 | unique = 0; |
615 | unique = 0; |
618 | for (op = get_map_ob (m, i, j); op; op = op->above) |
616 | for (op = GET_MAP_OB (m, i, j); op; op = op->above) |
619 | { |
617 | { |
620 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
618 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
621 | unique = 1; |
619 | unique = 1; |
622 | |
620 | |
623 | if (op->type == PLAYER) |
621 | if (op->type == PLAYER) |
624 | { |
|
|
625 | LOG (llevDebug, "Player on map that is being saved\n"); |
|
|
626 | continue; |
622 | continue; |
627 | } |
|
|
628 | |
623 | |
629 | if (op->head || op->owner) |
624 | if (op->head || op->owner) |
630 | continue; |
625 | continue; |
631 | |
626 | |
632 | if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) |
627 | if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) |
633 | save_object (fp2, op, 3); |
628 | save_object (fp2, op, 3); |
634 | else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) |
629 | else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) |
635 | save_object (fp, op, 3); |
630 | save_object (fp, op, 3); |
636 | |
631 | } |
637 | } /* for this space */ |
632 | } |
638 | } /* for this j */ |
|
|
639 | } |
633 | } |
640 | |
634 | |
641 | maptile::maptile () |
635 | maptile::maptile () |
642 | { |
636 | { |
643 | in_memory = MAP_SWAPPED; |
637 | in_memory = MAP_SWAPPED; |
… | |
… | |
693 | { |
687 | { |
694 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
688 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
695 | free (spaces); |
689 | free (spaces); |
696 | } |
690 | } |
697 | |
691 | |
698 | spaces = (MapSpace *) |
692 | spaces = (mapspace *) |
699 | calloc (1, width * height * sizeof (MapSpace)); |
693 | calloc (1, width * height * sizeof (mapspace)); |
700 | |
694 | |
701 | if (!spaces) |
695 | if (!spaces) |
702 | fatal (OUT_OF_MEMORY); |
696 | fatal (OUT_OF_MEMORY); |
703 | } |
697 | } |
704 | |
698 | |
… | |
… | |
730 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
724 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
731 | shopitems *items = NULL; |
725 | shopitems *items = NULL; |
732 | int i = 0, number_of_entries = 0; |
726 | int i = 0, number_of_entries = 0; |
733 | const typedata *current_type; |
727 | const typedata *current_type; |
734 | |
728 | |
735 | shop_string = strdup_local (input_string); |
729 | shop_string = strdup (input_string); |
736 | p = shop_string; |
730 | p = shop_string; |
737 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
731 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
738 | while (p) |
732 | while (p) |
739 | { |
733 | { |
740 | p = strchr (p, ';'); |
734 | p = strchr (p, ';'); |
… | |
… | |
926 | * with nothing between). There is no reason in those cases to |
920 | * with nothing between). There is no reason in those cases to |
927 | * keep the empty message. Also, msgbuf contains garbage data |
921 | * keep the empty message. Also, msgbuf contains garbage data |
928 | * when msgpos is zero, so copying it results in crashes |
922 | * when msgpos is zero, so copying it results in crashes |
929 | */ |
923 | */ |
930 | if (msgpos != 0) |
924 | if (msgpos != 0) |
931 | m->msg = strdup_local (msgbuf); |
925 | m->msg = strdup (msgbuf); |
932 | } |
926 | } |
933 | else if (!strcmp (key, "maplore")) |
927 | else if (!strcmp (key, "maplore")) |
934 | { |
928 | { |
935 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
929 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
936 | { |
930 | { |
… | |
… | |
942 | strcpy (maplorebuf + maplorepos, buf); |
936 | strcpy (maplorebuf + maplorepos, buf); |
943 | maplorepos += strlen (buf); |
937 | maplorepos += strlen (buf); |
944 | } |
938 | } |
945 | } |
939 | } |
946 | if (maplorepos != 0) |
940 | if (maplorepos != 0) |
947 | m->maplore = strdup_local (maplorebuf); |
941 | m->maplore = strdup (maplorebuf); |
948 | } |
942 | } |
949 | else if (!strcmp (key, "end")) |
943 | else if (!strcmp (key, "end")) |
950 | { |
944 | { |
951 | break; |
945 | break; |
952 | } |
946 | } |
… | |
… | |
961 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
955 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
962 | } |
956 | } |
963 | else if (!strcmp (key, "name")) |
957 | else if (!strcmp (key, "name")) |
964 | { |
958 | { |
965 | *end = 0; |
959 | *end = 0; |
966 | m->name = strdup_local (value); |
960 | m->name = strdup (value); |
967 | } |
961 | } |
968 | /* first strcmp value on these are old names supported |
962 | /* first strcmp value on these are old names supported |
969 | * for compatibility reasons. The new values (second) are |
963 | * for compatibility reasons. The new values (second) are |
970 | * what really should be used. |
964 | * what really should be used. |
971 | */ |
965 | */ |
… | |
… | |
1009 | else if (!strcmp (key, "shopmax")) |
1003 | else if (!strcmp (key, "shopmax")) |
1010 | m->shopmax = atol (value); |
1004 | m->shopmax = atol (value); |
1011 | else if (!strcmp (key, "shoprace")) |
1005 | else if (!strcmp (key, "shoprace")) |
1012 | { |
1006 | { |
1013 | *end = 0; |
1007 | *end = 0; |
1014 | m->shoprace = strdup_local (value); |
1008 | m->shoprace = strdup (value); |
1015 | } |
1009 | } |
1016 | else if (!strcmp (key, "outdoor")) |
1010 | else if (!strcmp (key, "outdoor")) |
1017 | m->outdoor = atoi (value); |
1011 | m->outdoor = atoi (value); |
1018 | else if (!strcmp (key, "temp")) |
1012 | else if (!strcmp (key, "temp")) |
1019 | m->temp = atoi (value); |
1013 | m->temp = atoi (value); |
… | |
… | |
1069 | } |
1063 | } |
1070 | |
1064 | |
1071 | if (editor) |
1065 | if (editor) |
1072 | { |
1066 | { |
1073 | /* Use the value as in the file. */ |
1067 | /* Use the value as in the file. */ |
1074 | m->tile_path[tile - 1] = strdup_local (value); |
1068 | m->tile_path[tile - 1] = strdup (value); |
1075 | } |
1069 | } |
1076 | else if (path != NULL) |
1070 | else if (path != NULL) |
1077 | { |
1071 | { |
1078 | /* Use the normalized value. */ |
1072 | /* Use the normalized value. */ |
1079 | m->tile_path[tile - 1] = strdup_local (path); |
1073 | m->tile_path[tile - 1] = strdup (path); |
1080 | } |
1074 | } |
1081 | } /* end if tile direction (in)valid */ |
1075 | } /* end if tile direction (in)valid */ |
1082 | } |
1076 | } |
1083 | else |
1077 | else |
1084 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1078 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
… | |
… | |
1250 | for (i = 0; i < MAP_WIDTH (m); i++) |
1244 | for (i = 0; i < MAP_WIDTH (m); i++) |
1251 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1245 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1252 | { |
1246 | { |
1253 | unique = 0; |
1247 | unique = 0; |
1254 | |
1248 | |
1255 | for (op = get_map_ob (m, i, j); op; op = next) |
1249 | for (op = GET_MAP_OB (m, i, j); op; op = next) |
1256 | { |
1250 | { |
1257 | next = op->above; |
1251 | next = op->above; |
1258 | |
1252 | |
1259 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1253 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1260 | unique = 1; |
1254 | unique = 1; |
… | |
… | |
1343 | make_path_to_file (filename); |
1337 | make_path_to_file (filename); |
1344 | } |
1338 | } |
1345 | else |
1339 | else |
1346 | { |
1340 | { |
1347 | if (!m->tmpname) |
1341 | if (!m->tmpname) |
1348 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1342 | m->tmpname = tempnam (settings.tmpdir, NULL); |
1349 | |
1343 | |
1350 | strcpy (filename, m->tmpname); |
1344 | strcpy (filename, m->tmpname); |
1351 | } |
1345 | } |
1352 | |
1346 | |
1353 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1347 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
… | |
… | |
1532 | if (!m->in_memory) |
1526 | if (!m->in_memory) |
1533 | { |
1527 | { |
1534 | LOG (llevError, "Trying to free freed map.\n"); |
1528 | LOG (llevError, "Trying to free freed map.\n"); |
1535 | return; |
1529 | return; |
1536 | } |
1530 | } |
|
|
1531 | |
|
|
1532 | // TODO: use new/delete |
|
|
1533 | #define FREE_AND_CLEAR(p) { free (p); p = NULL; } |
|
|
1534 | |
1537 | if (flag && m->spaces) |
1535 | if (flag && m->spaces) |
1538 | free_all_objects (m); |
1536 | free_all_objects (m); |
1539 | if (m->name) |
1537 | if (m->name) |
1540 | FREE_AND_CLEAR (m->name); |
1538 | FREE_AND_CLEAR (m->name); |
1541 | if (m->spaces) |
1539 | if (m->spaces) |
1542 | FREE_AND_CLEAR (m->spaces); |
1540 | FREE_AND_CLEAR (m->spaces); |
1543 | if (m->msg) |
1541 | if (m->msg) |
1544 | FREE_AND_CLEAR (m->msg); |
1542 | FREE_AND_CLEAR (m->msg); |
1545 | if (m->maplore) |
1543 | if (m->maplore) |
1546 | FREE_AND_CLEAR (m->maplore); |
1544 | FREE_AND_CLEAR (m->maplore); |
1547 | if (m->shopitems) |
1545 | |
1548 | delete[]m->shopitems; |
1546 | delete [] m->shopitems; |
1549 | m->shopitems = 0; |
1547 | m->shopitems = 0; |
|
|
1548 | |
1550 | if (m->shoprace) |
1549 | if (m->shoprace) |
1551 | FREE_AND_CLEAR (m->shoprace); |
1550 | FREE_AND_CLEAR (m->shoprace); |
|
|
1551 | |
1552 | if (m->buttons) |
1552 | if (m->buttons) |
1553 | free_objectlinkpt (m->buttons); |
1553 | free_objectlinkpt (m->buttons); |
|
|
1554 | |
1554 | m->buttons = NULL; |
1555 | m->buttons = NULL; |
|
|
1556 | |
1555 | for (i = 0; i < 4; i++) |
1557 | for (i = 0; i < 4; i++) |
1556 | { |
1558 | { |
1557 | if (m->tile_path[i]) |
1559 | if (m->tile_path[i]) |
1558 | FREE_AND_CLEAR (m->tile_path[i]); |
1560 | FREE_AND_CLEAR (m->tile_path[i]); |
1559 | m->tile_map[i] = NULL; |
1561 | m->tile_map[i] = NULL; |
1560 | } |
1562 | } |
|
|
1563 | |
1561 | m->in_memory = MAP_SWAPPED; |
1564 | m->in_memory = MAP_SWAPPED; |
|
|
1565 | |
|
|
1566 | #undef FREE_AND_CLEAR |
|
|
1567 | |
1562 | } |
1568 | } |
1563 | |
1569 | |
1564 | /* |
1570 | /* |
1565 | * function: vanish maptile |
1571 | * function: vanish maptile |
1566 | * m : pointer to maptile, if NULL no action |
1572 | * m : pointer to maptile, if NULL no action |
… | |
… | |
1626 | else |
1632 | else |
1627 | last->next = m->next; |
1633 | last->next = m->next; |
1628 | |
1634 | |
1629 | delete m; |
1635 | delete m; |
1630 | } |
1636 | } |
1631 | |
|
|
1632 | |
|
|
1633 | |
1637 | |
1634 | /* |
1638 | /* |
1635 | * Makes sure the given map is loaded and swapped in. |
1639 | * Makes sure the given map is loaded and swapped in. |
1636 | * name is path name of the map. |
1640 | * name is path name of the map. |
1637 | * flags meaning: |
1641 | * flags meaning: |
… | |
… | |
1640 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1644 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1641 | * dont do any more name translation on it. |
1645 | * dont do any more name translation on it. |
1642 | * |
1646 | * |
1643 | * Returns a pointer to the given map. |
1647 | * Returns a pointer to the given map. |
1644 | */ |
1648 | */ |
1645 | |
|
|
1646 | maptile * |
1649 | maptile * |
1647 | ready_map_name (const char *name, int flags) |
1650 | ready_map_name (const char *name, int flags) |
1648 | { |
1651 | { |
1649 | maptile *m; |
1652 | maptile *m; |
1650 | |
1653 | |
… | |
… | |
1773 | return MAP_DIFFICULTY (m); |
1776 | return MAP_DIFFICULTY (m); |
1774 | } |
1777 | } |
1775 | |
1778 | |
1776 | for (x = 0; x < MAP_WIDTH (m); x++) |
1779 | for (x = 0; x < MAP_WIDTH (m); x++) |
1777 | for (y = 0; y < MAP_HEIGHT (m); y++) |
1780 | for (y = 0; y < MAP_HEIGHT (m); y++) |
1778 | for (op = get_map_ob (m, x, y); op != NULL; op = op->above) |
1781 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
1779 | { |
1782 | { |
1780 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1783 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1781 | { |
1784 | { |
1782 | total_exp += op->stats.exp; |
1785 | total_exp += op->stats.exp; |
1783 | monster_cnt++; |
1786 | monster_cnt++; |
… | |
… | |
1876 | /* All clients need to get re-updated for the change */ |
1879 | /* All clients need to get re-updated for the change */ |
1877 | update_all_map_los (m); |
1880 | update_all_map_los (m); |
1878 | return 1; |
1881 | return 1; |
1879 | } |
1882 | } |
1880 | |
1883 | |
1881 | |
|
|
1882 | /* |
1884 | /* |
1883 | * This function updates various attributes about a specific space |
1885 | * This function updates various attributes about a specific space |
1884 | * on the map (what it looks like, whether it blocks magic, |
1886 | * on the map (what it looks like, whether it blocks magic, |
1885 | * has a living creatures, prevents people from passing |
1887 | * has a living creatures, prevents people from passing |
1886 | * through, etc) |
1888 | * through, etc) |
1887 | */ |
1889 | */ |
1888 | void |
1890 | void |
1889 | update_position (maptile *m, int x, int y) |
1891 | update_position (maptile *m, int x, int y) |
1890 | { |
1892 | { |
1891 | object *tmp, *last = NULL; |
1893 | object *tmp, *last = 0; |
1892 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1894 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1893 | New_Face *top, *floor, *middle; |
1895 | New_Face *top, *floor, *middle; |
1894 | object *top_obj, *floor_obj, *middle_obj; |
1896 | object *top_obj, *floor_obj, *middle_obj; |
1895 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1897 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1896 | |
1898 | |
… | |
… | |
1900 | LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); |
1902 | LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); |
1901 | return; |
1903 | return; |
1902 | } |
1904 | } |
1903 | |
1905 | |
1904 | middle = blank_face; |
1906 | middle = blank_face; |
1905 | top = blank_face; |
1907 | top = blank_face; |
1906 | floor = blank_face; |
1908 | floor = blank_face; |
1907 | |
1909 | |
1908 | middle_obj = NULL; |
1910 | middle_obj = 0; |
1909 | top_obj = NULL; |
1911 | top_obj = 0; |
1910 | floor_obj = NULL; |
1912 | floor_obj = 0; |
1911 | |
1913 | |
1912 | for (tmp = get_map_ob (m, x, y); tmp; last = tmp, tmp = tmp->above) |
1914 | for (tmp = GET_MAP_OB (m, x, y); tmp; last = tmp, tmp = tmp->above) |
1913 | { |
1915 | { |
1914 | |
|
|
1915 | /* This could be made additive I guess (two lights better than |
1916 | /* This could be made additive I guess (two lights better than |
1916 | * one). But if so, it shouldn't be a simple additive - 2 |
1917 | * one). But if so, it shouldn't be a simple additive - 2 |
1917 | * light bulbs do not illuminate twice as far as once since |
1918 | * light bulbs do not illuminate twice as far as once since |
1918 | * it is a disapation factor that is squared (or is it cubed?) |
1919 | * it is a dissapation factor that is cubed. |
1919 | */ |
1920 | */ |
1920 | if (tmp->glow_radius > light) |
1921 | if (tmp->glow_radius > light) |
1921 | light = tmp->glow_radius; |
1922 | light = tmp->glow_radius; |
1922 | |
1923 | |
1923 | /* This call is needed in order to update objects the player |
1924 | /* This call is needed in order to update objects the player |
… | |
… | |
1961 | { |
1962 | { |
1962 | middle = tmp->face; |
1963 | middle = tmp->face; |
1963 | middle_obj = tmp; |
1964 | middle_obj = tmp; |
1964 | } |
1965 | } |
1965 | } |
1966 | } |
|
|
1967 | |
1966 | if (tmp == tmp->above) |
1968 | if (tmp == tmp->above) |
1967 | { |
1969 | { |
1968 | LOG (llevError, "Error in structure of map\n"); |
1970 | LOG (llevError, "Error in structure of map\n"); |
1969 | exit (-1); |
1971 | exit (-1); |
1970 | } |
1972 | } |
1971 | |
1973 | |
1972 | move_slow |= tmp->move_slow; |
1974 | move_slow |= tmp->move_slow; |
1973 | move_block |= tmp->move_block; |
1975 | move_block |= tmp->move_block; |
1974 | move_on |= tmp->move_on; |
1976 | move_on |= tmp->move_on; |
1975 | move_off |= tmp->move_off; |
1977 | move_off |= tmp->move_off; |
1976 | move_allow |= tmp->move_allow; |
1978 | move_allow |= tmp->move_allow; |
1977 | |
1979 | |
1978 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
|
|
1979 | flags |= P_IS_ALIVE; |
|
|
1980 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) |
|
|
1981 | flags |= P_NO_MAGIC; |
|
|
1982 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) |
|
|
1983 | flags |= P_NO_CLERIC; |
|
|
1984 | if (tmp->type == SAFE_GROUND) |
|
|
1985 | flags |= P_SAFE; |
|
|
1986 | |
|
|
1987 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) |
1980 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; |
1988 | flags |= P_BLOCKSVIEW; |
1981 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; |
1989 | } /* for stack of objects */ |
1982 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
|
|
1983 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
|
|
1984 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
|
|
1985 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
|
|
1986 | } |
1990 | |
1987 | |
1991 | /* we don't want to rely on this function to have accurate flags, but |
1988 | /* we don't want to rely on this function to have accurate flags, but |
1992 | * since we're already doing the work, we calculate them here. |
1989 | * since we're already doing the work, we calculate them here. |
1993 | * if they don't match, logic is broken someplace. |
1990 | * if they don't match, logic is broken someplace. |
1994 | */ |
1991 | */ |
1995 | if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) |
1992 | if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) |
1996 | { |
|
|
1997 | LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", |
1993 | LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", |
1998 | m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); |
1994 | m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); |
1999 | } |
1995 | |
2000 | SET_MAP_FLAGS (m, x, y, flags); |
1996 | mapspace &s = m->at (x, y); |
2001 | SET_MAP_MOVE_BLOCK (m, x, y, move_block & ~move_allow); |
1997 | |
2002 | SET_MAP_MOVE_ON (m, x, y, move_on); |
1998 | s.flags = flags; |
2003 | SET_MAP_MOVE_OFF (m, x, y, move_off); |
1999 | s.move_block = move_block & ~move_allow; |
2004 | SET_MAP_MOVE_SLOW (m, x, y, move_slow); |
2000 | s.move_on = move_on; |
|
|
2001 | s.move_off = move_off; |
|
|
2002 | s.move_slow = move_slow; |
2005 | |
2003 | |
2006 | /* At this point, we have a floor face (if there is a floor), |
2004 | /* At this point, we have a floor face (if there is a floor), |
2007 | * and the floor is set - we are not going to touch it at |
2005 | * and the floor is set - we are not going to touch it at |
2008 | * this point. |
2006 | * this point. |
2009 | * middle contains the highest visibility face. |
2007 | * middle contains the highest visibility face. |
… | |
… | |
2063 | break; |
2061 | break; |
2064 | } |
2062 | } |
2065 | } |
2063 | } |
2066 | } |
2064 | } |
2067 | } |
2065 | } |
|
|
2066 | |
2068 | if (middle == floor) |
2067 | if (middle == floor) |
2069 | middle = blank_face; |
2068 | middle = blank_face; |
|
|
2069 | |
2070 | if (top == middle) |
2070 | if (top == middle) |
2071 | middle = blank_face; |
2071 | middle = blank_face; |
|
|
2072 | |
2072 | SET_MAP_FACE (m, x, y, top, 0); |
2073 | SET_MAP_FACE (m, x, y, top, 0); |
2073 | if (top != blank_face) |
2074 | if (top != blank_face) |
2074 | SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); |
2075 | SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); |
2075 | else |
2076 | else |
2076 | SET_MAP_FACE_OBJ (m, x, y, NULL, 0); |
2077 | SET_MAP_FACE_OBJ (m, x, y, NULL, 0); |
|
|
2078 | |
2077 | SET_MAP_FACE (m, x, y, middle, 1); |
2079 | SET_MAP_FACE (m, x, y, middle, 1); |
2078 | if (middle != blank_face) |
2080 | if (middle != blank_face) |
2079 | SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); |
2081 | SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); |
2080 | else |
2082 | else |
2081 | SET_MAP_FACE_OBJ (m, x, y, NULL, 1); |
2083 | SET_MAP_FACE_OBJ (m, x, y, NULL, 1); |
|
|
2084 | |
2082 | SET_MAP_FACE (m, x, y, floor, 2); |
2085 | SET_MAP_FACE (m, x, y, floor, 2); |
2083 | if (floor != blank_face) |
2086 | if (floor != blank_face) |
2084 | SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); |
2087 | SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); |
2085 | else |
2088 | else |
2086 | SET_MAP_FACE_OBJ (m, x, y, NULL, 2); |
2089 | SET_MAP_FACE_OBJ (m, x, y, NULL, 2); |
|
|
2090 | |
2087 | SET_MAP_LIGHT (m, x, y, light); |
2091 | SET_MAP_LIGHT (m, x, y, light); |
2088 | } |
2092 | } |
2089 | |
2093 | |
2090 | |
2094 | |
2091 | void |
2095 | void |
… | |
… | |
2096 | timeout = MAP_RESET_TIMEOUT (map); |
2100 | timeout = MAP_RESET_TIMEOUT (map); |
2097 | if (timeout <= 0) |
2101 | if (timeout <= 0) |
2098 | timeout = MAP_DEFAULTRESET; |
2102 | timeout = MAP_DEFAULTRESET; |
2099 | if (timeout >= MAP_MAXRESET) |
2103 | if (timeout >= MAP_MAXRESET) |
2100 | timeout = MAP_MAXRESET; |
2104 | timeout = MAP_MAXRESET; |
2101 | MAP_WHEN_RESET (map) = seconds () + timeout; |
2105 | MAP_WHEN_RESET (map) = time (0) + timeout; |
2102 | } |
2106 | } |
2103 | |
2107 | |
2104 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2108 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2105 | * the map. It also takes care of linking back the freshly loaded |
2109 | * the map. It also takes care of linking back the freshly loaded |
2106 | * maps tile_map values if it tiles back to this one. It returns |
2110 | * maps tile_map values if it tiles back to this one. It returns |