… | |
… | |
24 | #include <unistd.h> |
24 | #include <unistd.h> |
25 | |
25 | |
26 | #include "global.h" |
26 | #include "global.h" |
27 | #include "loader.h" |
27 | #include "loader.h" |
28 | #include "path.h" |
28 | #include "path.h" |
|
|
29 | |
|
|
30 | sint8 maptile::outdoor_darkness; |
29 | |
31 | |
30 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
32 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
31 | * one function that just returns a P_.. value (see map.h) |
33 | * one function that just returns a P_.. value (see map.h) |
32 | * it will also do map translation for tiled maps, returning |
34 | * it will also do map translation for tiled maps, returning |
33 | * new values into newmap, nx, and ny. Any and all of those |
35 | * new values into newmap, nx, and ny. Any and all of those |
… | |
… | |
351 | ms.flags_ = 0; |
353 | ms.flags_ = 0; |
352 | } |
354 | } |
353 | else |
355 | else |
354 | { |
356 | { |
355 | f.parse_warn (format ("object %s out of range", op->debug_desc ())); |
357 | f.parse_warn (format ("object %s out of range", op->debug_desc ())); |
356 | op->destroy_inv (false); // be explicit about dropping |
|
|
357 | op->destroy (true); |
358 | op->destroy (); |
358 | } |
359 | } |
359 | } |
360 | } |
360 | |
361 | |
361 | continue; |
362 | continue; |
362 | |
363 | |
… | |
… | |
713 | |
714 | |
714 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
715 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
715 | unique = 1; |
716 | unique = 1; |
716 | |
717 | |
717 | if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
718 | if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
718 | { |
|
|
719 | op->destroy_inv (false); |
|
|
720 | op->destroy (true); |
719 | op->destroy (); |
721 | } |
|
|
722 | |
720 | |
723 | op = above; |
721 | op = above; |
724 | } |
722 | } |
725 | } |
723 | } |
726 | } |
724 | } |
… | |
… | |
814 | |
812 | |
815 | op->flag [FLAG_REMOVED] = true; |
813 | op->flag [FLAG_REMOVED] = true; |
816 | |
814 | |
817 | object *head = op->head_ (); |
815 | object *head = op->head_ (); |
818 | if (op == head) |
816 | if (op == head) |
819 | { |
|
|
820 | op->destroy_inv (false); |
|
|
821 | op->destroy (true); |
817 | op->destroy (); |
822 | } |
|
|
823 | else if (head->map != op->map) |
818 | else if (head->map != op->map) |
824 | { |
819 | { |
825 | LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ()); |
820 | LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ()); |
826 | head->destroy (true); |
821 | head->destroy (); |
827 | } |
822 | } |
828 | } |
823 | } |
829 | |
824 | |
830 | sfree0 (spaces, size ()); |
825 | sfree0 (spaces, size ()); |
831 | } |
826 | } |
… | |
… | |
937 | destroy = 1; |
932 | destroy = 1; |
938 | } |
933 | } |
939 | |
934 | |
940 | /* adjust overall chance below */ |
935 | /* adjust overall chance below */ |
941 | if (destroy && rndm (0, 1)) |
936 | if (destroy && rndm (0, 1)) |
942 | op->destroy (true); |
937 | op->destroy (); |
943 | } |
938 | } |
944 | } |
939 | } |
945 | |
940 | |
946 | /* |
941 | /* |
947 | * Updates every button on the map (by calling update_button() for them). |
942 | * Updates every button on the map (by calling update_button() for them). |
… | |
… | |
970 | /* |
965 | /* |
971 | * This routine is supposed to find out the difficulty of the map. |
966 | * This routine is supposed to find out the difficulty of the map. |
972 | * difficulty does not have a lot to do with character level, |
967 | * difficulty does not have a lot to do with character level, |
973 | * but does have a lot to do with treasure on the map. |
968 | * but does have a lot to do with treasure on the map. |
974 | * |
969 | * |
975 | * Difficulty can now be set by the map creature. If the value stored |
970 | * Difficulty can now be set by the map creator. If the value stored |
976 | * in the map is zero, then use this routine. Maps should really |
971 | * in the map is zero, then use this routine. Maps should really |
977 | * have a difficulty set than using this function - human calculation |
972 | * have a difficulty set rather than using this function - human calculation |
978 | * is much better than this functions guesswork. |
973 | * is much better than this function's guesswork. |
979 | */ |
974 | */ |
980 | int |
975 | int |
981 | maptile::estimate_difficulty () const |
976 | maptile::estimate_difficulty () const |
982 | { |
977 | { |
983 | long monster_cnt = 0; |
978 | long monster_cnt = 0; |
… | |
… | |
1028 | * postive values make it darker, negative make it brighter |
1023 | * postive values make it darker, negative make it brighter |
1029 | */ |
1024 | */ |
1030 | int |
1025 | int |
1031 | maptile::change_map_light (int change) |
1026 | maptile::change_map_light (int change) |
1032 | { |
1027 | { |
1033 | int new_level = darkness + change; |
|
|
1034 | |
|
|
1035 | /* Nothing to do */ |
1028 | /* Nothing to do */ |
1036 | if (!change || (new_level <= 0 && darkness == 0) || (new_level >= MAX_DARKNESS && darkness >= MAX_DARKNESS)) |
1029 | if (!change) |
1037 | return 0; |
1030 | return 0; |
1038 | |
1031 | |
1039 | /* inform all players on the map */ |
1032 | /* inform all players on the map */ |
1040 | if (change > 0) |
1033 | if (change > 0) |
1041 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes darker."); |
1034 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes darker."); |
1042 | else |
1035 | else |
1043 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes brighter."); |
1036 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes brighter."); |
1044 | |
1037 | |
1045 | /* Do extra checking. since darkness is a unsigned value, |
1038 | darkness = clamp (darkness + change, -MAX_DARKNESS, MAX_DARKNESS); |
1046 | * we need to be extra careful about negative values. |
|
|
1047 | * In general, the checks below are only needed if change |
|
|
1048 | * is not +/-1 |
|
|
1049 | */ |
|
|
1050 | if (new_level < 0) |
|
|
1051 | darkness = 0; |
|
|
1052 | else if (new_level >= MAX_DARKNESS) |
|
|
1053 | darkness = MAX_DARKNESS; |
|
|
1054 | else |
|
|
1055 | darkness = new_level; |
|
|
1056 | |
1039 | |
1057 | /* All clients need to get re-updated for the change */ |
1040 | /* All clients need to get re-updated for the change */ |
1058 | update_all_map_los (this); |
1041 | update_all_map_los (this); |
1059 | |
1042 | |
1060 | return 1; |
1043 | return 1; |
… | |
… | |
1068 | */ |
1051 | */ |
1069 | void |
1052 | void |
1070 | mapspace::update_ () |
1053 | mapspace::update_ () |
1071 | { |
1054 | { |
1072 | object *last = 0; |
1055 | object *last = 0; |
1073 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1056 | uint8 flags = P_UPTODATE, anywhere = 0; |
|
|
1057 | sint8 light = 0; |
1074 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1058 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1075 | |
1059 | |
1076 | //object *middle = 0; |
1060 | //object *middle = 0; |
1077 | //object *top = 0; |
1061 | //object *top = 0; |
1078 | //object *floor = 0; |
1062 | //object *floor = 0; |
… | |
… | |
1081 | object *&middle = faces_obj[1] = 0; |
1065 | object *&middle = faces_obj[1] = 0; |
1082 | object *&floor = faces_obj[2] = 0; |
1066 | object *&floor = faces_obj[2] = 0; |
1083 | |
1067 | |
1084 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1068 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1085 | { |
1069 | { |
1086 | /* This could be made additive I guess (two lights better than |
1070 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1087 | * one). But if so, it shouldn't be a simple additive - 2 |
|
|
1088 | * light bulbs do not illuminate twice as far as once since |
|
|
1089 | * it is a dissapation factor that is cubed. |
|
|
1090 | */ |
|
|
1091 | light = max (light, tmp->glow_radius); |
1071 | light += tmp->glow_radius; |
1092 | |
1072 | |
1093 | /* This call is needed in order to update objects the player |
1073 | /* This call is needed in order to update objects the player |
1094 | * is standing in that have animations (ie, grass, fire, etc). |
1074 | * is standing in that have animations (ie, grass, fire, etc). |
1095 | * However, it also causes the look window to be re-drawn |
1075 | * However, it also causes the look window to be re-drawn |
1096 | * 3 times each time the player moves, because many of the |
1076 | * 3 times each time the player moves, because many of the |
… | |
… | |
1144 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1124 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1145 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
1125 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
1146 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
1126 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
1147 | } |
1127 | } |
1148 | |
1128 | |
1149 | this->light = light; |
1129 | this->light = min (light, MAX_LIGHT_RADIUS); |
1150 | this->flags_ = flags; |
1130 | this->flags_ = flags; |
1151 | this->move_block = move_block & ~move_allow; |
1131 | this->move_block = move_block & ~move_allow; |
1152 | this->move_on = move_on; |
1132 | this->move_on = move_on; |
1153 | this->move_off = move_off; |
1133 | this->move_off = move_off; |
1154 | this->move_slow = move_slow; |
1134 | this->move_slow = move_slow; |
… | |
… | |
1635 | maptile::play_sound (faceidx sound, int x, int y) const |
1615 | maptile::play_sound (faceidx sound, int x, int y) const |
1636 | { |
1616 | { |
1637 | if (!sound) |
1617 | if (!sound) |
1638 | return; |
1618 | return; |
1639 | |
1619 | |
1640 | for_all_players (pl) |
1620 | for_all_players_on_map (pl, this) |
1641 | if (pl->ob->map == this) |
|
|
1642 | if (client *ns = pl->ns) |
1621 | if (client *ns = pl->ns) |
1643 | { |
1622 | { |
1644 | int dx = x - pl->ob->x; |
1623 | int dx = x - pl->ob->x; |
1645 | int dy = y - pl->ob->y; |
1624 | int dy = y - pl->ob->y; |
1646 | |
1625 | |
1647 | int distance = idistance (dx, dy); |
1626 | int distance = idistance (dx, dy); |
1648 | |
1627 | |
1649 | if (distance <= MAX_SOUND_DISTANCE) |
1628 | if (distance <= MAX_SOUND_DISTANCE) |
1650 | ns->play_sound (sound, dx, dy); |
1629 | ns->play_sound (sound, dx, dy); |
1651 | } |
1630 | } |
1652 | } |
1631 | } |
1653 | |
1632 | |