… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <unistd.h> |
25 | #include <unistd.h> |
25 | |
26 | |
26 | #include "global.h" |
27 | #include "global.h" |
27 | #include "loader.h" |
28 | #include "loader.h" |
28 | #include "path.h" |
29 | #include "path.h" |
|
|
30 | |
|
|
31 | sint8 maptile::outdoor_darkness; |
29 | |
32 | |
30 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
33 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
31 | * one function that just returns a P_.. value (see map.h) |
34 | * one function that just returns a P_.. value (see map.h) |
32 | * it will also do map translation for tiled maps, returning |
35 | * it will also do map translation for tiled maps, returning |
33 | * new values into newmap, nx, and ny. Any and all of those |
36 | * new values into newmap, nx, and ny. Any and all of those |
… | |
… | |
332 | if (IN_RANGE_EXC (op->x, 0, width) && IN_RANGE_EXC (op->y, 0, height)) |
335 | if (IN_RANGE_EXC (op->x, 0, width) && IN_RANGE_EXC (op->y, 0, height)) |
333 | { |
336 | { |
334 | // we insert manually because |
337 | // we insert manually because |
335 | // a) its way faster |
338 | // a) its way faster |
336 | // b) we remove manually, too, and there are good reasons for that |
339 | // b) we remove manually, too, and there are good reasons for that |
337 | // c) its correct |
340 | // c) it's correct |
338 | mapspace &ms = at (op->x, op->y); |
341 | mapspace &ms = at (op->x, op->y); |
339 | |
342 | |
340 | op->flag [FLAG_REMOVED] = false; |
343 | op->flag [FLAG_REMOVED] = false; |
341 | |
344 | |
342 | op->above = 0; |
345 | op->above = 0; |
343 | op->below = ms.top; |
346 | op->below = ms.top; |
344 | |
347 | |
345 | if (ms.top) |
|
|
346 | ms.top->above = op; |
348 | *(ms.top ? &ms.top->above : &ms.bot) = op; |
347 | else |
|
|
348 | ms.bot = op; |
|
|
349 | |
349 | |
350 | ms.top = op; |
350 | ms.top = op; |
351 | ms.flags_ = 0; |
351 | ms.flags_ = 0; |
352 | } |
352 | } |
353 | else |
353 | else |
… | |
… | |
935 | op->destroy (); |
935 | op->destroy (); |
936 | } |
936 | } |
937 | } |
937 | } |
938 | |
938 | |
939 | /* |
939 | /* |
940 | * Updates every button on the map (by calling update_button() for them). |
|
|
941 | */ |
|
|
942 | void |
|
|
943 | maptile::update_buttons () |
|
|
944 | { |
|
|
945 | for (oblinkpt *obp = buttons; obp; obp = obp->next) |
|
|
946 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
|
|
947 | { |
|
|
948 | if (!ol->ob) |
|
|
949 | { |
|
|
950 | LOG (llevError, "Internal error in update_button (%s (%dx%d), connected %ld).\n", |
|
|
951 | ol->ob ? (const char *) ol->ob->name : "null", ol->ob ? ol->ob->x : -1, ol->ob ? ol->ob->y : -1, obp->value); |
|
|
952 | continue; |
|
|
953 | } |
|
|
954 | |
|
|
955 | if (ol->ob->type == BUTTON || ol->ob->type == PEDESTAL) |
|
|
956 | { |
|
|
957 | update_button (ol->ob); |
|
|
958 | break; |
|
|
959 | } |
|
|
960 | } |
|
|
961 | } |
|
|
962 | |
|
|
963 | /* |
|
|
964 | * This routine is supposed to find out the difficulty of the map. |
940 | * This routine is supposed to find out the difficulty of the map. |
965 | * difficulty does not have a lot to do with character level, |
941 | * difficulty does not have a lot to do with character level, |
966 | * but does have a lot to do with treasure on the map. |
942 | * but does have a lot to do with treasure on the map. |
967 | * |
943 | * |
968 | * Difficulty can now be set by the map creature. If the value stored |
944 | * Difficulty can now be set by the map creator. If the value stored |
969 | * in the map is zero, then use this routine. Maps should really |
945 | * in the map is zero, then use this routine. Maps should really |
970 | * have a difficulty set than using this function - human calculation |
946 | * have a difficulty set rather than using this function - human calculation |
971 | * is much better than this functions guesswork. |
947 | * is much better than this function's guesswork. |
972 | */ |
948 | */ |
973 | int |
949 | int |
974 | maptile::estimate_difficulty () const |
950 | maptile::estimate_difficulty () const |
975 | { |
951 | { |
976 | long monster_cnt = 0; |
952 | long monster_cnt = 0; |
… | |
… | |
1021 | * postive values make it darker, negative make it brighter |
997 | * postive values make it darker, negative make it brighter |
1022 | */ |
998 | */ |
1023 | int |
999 | int |
1024 | maptile::change_map_light (int change) |
1000 | maptile::change_map_light (int change) |
1025 | { |
1001 | { |
1026 | int new_level = darkness + change; |
|
|
1027 | |
|
|
1028 | /* Nothing to do */ |
1002 | /* Nothing to do */ |
1029 | if (!change || (new_level <= 0 && darkness == 0) || (new_level >= MAX_DARKNESS && darkness >= MAX_DARKNESS)) |
1003 | if (!change) |
1030 | return 0; |
1004 | return 0; |
1031 | |
1005 | |
1032 | /* inform all players on the map */ |
1006 | /* inform all players on the map */ |
1033 | if (change > 0) |
1007 | if (change > 0) |
1034 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes darker."); |
1008 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes darker."); |
1035 | else |
1009 | else |
1036 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes brighter."); |
1010 | new_info_map (NDI_BLACK | NDI_UNIQUE, this, "It becomes brighter."); |
1037 | |
1011 | |
1038 | /* Do extra checking. since darkness is a unsigned value, |
1012 | darkness = clamp (darkness + change, -MAX_DARKNESS, MAX_DARKNESS); |
1039 | * we need to be extra careful about negative values. |
|
|
1040 | * In general, the checks below are only needed if change |
|
|
1041 | * is not +/-1 |
|
|
1042 | */ |
|
|
1043 | if (new_level < 0) |
|
|
1044 | darkness = 0; |
|
|
1045 | else if (new_level >= MAX_DARKNESS) |
|
|
1046 | darkness = MAX_DARKNESS; |
|
|
1047 | else |
|
|
1048 | darkness = new_level; |
|
|
1049 | |
1013 | |
1050 | /* All clients need to get re-updated for the change */ |
1014 | /* All clients need to get re-updated for the change */ |
1051 | update_all_map_los (this); |
1015 | update_all_map_los (this); |
1052 | |
1016 | |
1053 | return 1; |
1017 | return 1; |
… | |
… | |
1061 | */ |
1025 | */ |
1062 | void |
1026 | void |
1063 | mapspace::update_ () |
1027 | mapspace::update_ () |
1064 | { |
1028 | { |
1065 | object *last = 0; |
1029 | object *last = 0; |
1066 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1030 | uint8 flags = P_UPTODATE, anywhere = 0; |
|
|
1031 | sint8 light = 0; |
1067 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1032 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1068 | |
1033 | |
1069 | //object *middle = 0; |
1034 | //object *middle = 0; |
1070 | //object *top = 0; |
1035 | //object *top = 0; |
1071 | //object *floor = 0; |
1036 | //object *floor = 0; |
… | |
… | |
1074 | object *&middle = faces_obj[1] = 0; |
1039 | object *&middle = faces_obj[1] = 0; |
1075 | object *&floor = faces_obj[2] = 0; |
1040 | object *&floor = faces_obj[2] = 0; |
1076 | |
1041 | |
1077 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1042 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1078 | { |
1043 | { |
1079 | /* This could be made additive I guess (two lights better than |
1044 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1080 | * one). But if so, it shouldn't be a simple additive - 2 |
|
|
1081 | * light bulbs do not illuminate twice as far as once since |
|
|
1082 | * it is a dissapation factor that is cubed. |
|
|
1083 | */ |
|
|
1084 | light = max (light, tmp->glow_radius); |
1045 | light += tmp->glow_radius; |
1085 | |
1046 | |
1086 | /* This call is needed in order to update objects the player |
1047 | /* This call is needed in order to update objects the player |
1087 | * is standing in that have animations (ie, grass, fire, etc). |
1048 | * is standing in that have animations (ie, grass, fire, etc). |
1088 | * However, it also causes the look window to be re-drawn |
1049 | * However, it also causes the look window to be re-drawn |
1089 | * 3 times each time the player moves, because many of the |
1050 | * 3 times each time the player moves, because many of the |
… | |
… | |
1137 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1098 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1138 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
1099 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
1139 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
1100 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
1140 | } |
1101 | } |
1141 | |
1102 | |
1142 | this->light = light; |
1103 | this->light = min (light, MAX_LIGHT_RADIUS); |
1143 | this->flags_ = flags; |
1104 | this->flags_ = flags; |
1144 | this->move_block = move_block & ~move_allow; |
1105 | this->move_block = move_block & ~move_allow; |
1145 | this->move_on = move_on; |
1106 | this->move_on = move_on; |
1146 | this->move_off = move_off; |
1107 | this->move_off = move_off; |
1147 | this->move_slow = move_slow; |
1108 | this->move_slow = move_slow; |
… | |
… | |
1229 | vol += op->volume (); |
1190 | vol += op->volume (); |
1230 | |
1191 | |
1231 | return vol; |
1192 | return vol; |
1232 | } |
1193 | } |
1233 | |
1194 | |
1234 | bool |
1195 | maptile * |
1235 | maptile::tile_available (int dir, bool load) |
1196 | maptile::tile_available (int dir, bool load) |
1236 | { |
1197 | { |
1237 | if (!tile_path[dir]) |
1198 | if (tile_path[dir]) |
1238 | return 0; |
1199 | { |
1239 | |
|
|
1240 | if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE)) |
1200 | if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE)) |
1241 | return 1; |
1201 | return tile_map[dir]; |
1242 | |
1202 | |
1243 | if ((tile_map[dir] = find_async (tile_path[dir], this, load))) |
1203 | if ((tile_map[dir] = find_async (tile_path[dir], this, load))) |
1244 | return 1; |
1204 | return tile_map[dir]; |
|
|
1205 | } |
1245 | |
1206 | |
1246 | return 0; |
1207 | return 0; |
1247 | } |
1208 | } |
1248 | |
1209 | |
1249 | /* this returns TRUE if the coordinates (x,y) are out of |
1210 | /* this returns TRUE if the coordinates (x,y) are out of |
… | |
… | |
1555 | else |
1516 | else |
1556 | { |
1517 | { |
1557 | retval->distance_x += op2->x - x; |
1518 | retval->distance_x += op2->x - x; |
1558 | retval->distance_y += op2->y - y; |
1519 | retval->distance_y += op2->y - y; |
1559 | |
1520 | |
1560 | retval->part = NULL; |
1521 | retval->part = 0; |
1561 | retval->distance = idistance (retval->distance_x, retval->distance_y); |
1522 | retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y)); |
1562 | retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); |
1523 | retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); |
1563 | } |
1524 | } |
1564 | } |
1525 | } |
1565 | |
1526 | |
1566 | /* Returns true of op1 and op2 are effectively on the same map |
1527 | /* Returns true of op1 and op2 are effectively on the same map |
… | |
… | |
1628 | maptile::play_sound (faceidx sound, int x, int y) const |
1589 | maptile::play_sound (faceidx sound, int x, int y) const |
1629 | { |
1590 | { |
1630 | if (!sound) |
1591 | if (!sound) |
1631 | return; |
1592 | return; |
1632 | |
1593 | |
|
|
1594 | for_all_players_on_map (pl, this) |
|
|
1595 | if (client *ns = pl->ns) |
|
|
1596 | { |
|
|
1597 | int dx = x - pl->ob->x; |
|
|
1598 | int dy = y - pl->ob->y; |
|
|
1599 | |
|
|
1600 | int distance = idistance (dx, dy); |
|
|
1601 | |
|
|
1602 | if (distance <= MAX_SOUND_DISTANCE) |
|
|
1603 | ns->play_sound (sound, dx, dy); |
|
|
1604 | } |
|
|
1605 | } |
|
|
1606 | |
|
|
1607 | void |
|
|
1608 | maptile::say_msg (const char *msg, int x, int y) const |
|
|
1609 | { |
1633 | for_all_players (pl) |
1610 | for_all_players (pl) |
1634 | if (pl->ob->map == this) |
|
|
1635 | if (client *ns = pl->ns) |
1611 | if (client *ns = pl->ns) |
1636 | { |
1612 | { |
1637 | int dx = x - pl->ob->x; |
1613 | int dx = x - pl->ob->x; |
1638 | int dy = y - pl->ob->y; |
1614 | int dy = y - pl->ob->y; |
1639 | |
1615 | |
1640 | int distance = idistance (dx, dy); |
1616 | int distance = idistance (dx, dy); |
1641 | |
1617 | |
1642 | if (distance <= MAX_SOUND_DISTANCE) |
1618 | if (distance <= MAX_SOUND_DISTANCE) |
1643 | ns->play_sound (sound, dx, dy); |
1619 | ns->send_msg (NDI_GREY | NDI_DEF, SAY_CHANNEL, msg); |
1644 | } |
1620 | } |
1645 | } |
1621 | } |
1646 | |
1622 | |
|
|
1623 | static void |
|
|
1624 | split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy) |
|
|
1625 | { |
|
|
1626 | // clip to map to the left |
|
|
1627 | if (x0 < 0) |
|
|
1628 | { |
|
|
1629 | if (maptile *tile = m->tile_available (TILE_LEFT, 1)) |
|
|
1630 | split_to_tiles (buf, tile, x0 + tile->width, y0, min (x1 + tile->width, tile->width), y1, dx - tile->width, dy); |
|
|
1631 | |
|
|
1632 | if (x1 < 0) // entirely to the left |
|
|
1633 | return; |
|
|
1634 | |
|
|
1635 | x0 = 0; |
|
|
1636 | } |
|
|
1637 | |
|
|
1638 | // clip to map to the right |
|
|
1639 | if (x1 > m->width) |
|
|
1640 | { |
|
|
1641 | if (maptile *tile = m->tile_available (TILE_RIGHT, 1)) |
|
|
1642 | split_to_tiles (buf, tile, max (x0 - m->width, 0), y0, x1 - m->width, y1, dx + m->width, dy); |
|
|
1643 | |
|
|
1644 | if (x0 > m->width) // entirely to the right |
|
|
1645 | return; |
|
|
1646 | |
|
|
1647 | x1 = m->width; |
|
|
1648 | } |
|
|
1649 | |
|
|
1650 | // clip to map above |
|
|
1651 | if (y0 < 0) |
|
|
1652 | { |
|
|
1653 | if (maptile *tile = m->tile_available (TILE_UP, 1)) |
|
|
1654 | split_to_tiles (buf, tile, x0, y0 + tile->height, x1, min (y1 + tile->height, tile->height), dx, dy - tile->height); |
|
|
1655 | |
|
|
1656 | if (y1 < 0) // entirely above |
|
|
1657 | return; |
|
|
1658 | |
|
|
1659 | y0 = 0; |
|
|
1660 | } |
|
|
1661 | |
|
|
1662 | // clip to map below |
|
|
1663 | if (y1 > m->height) |
|
|
1664 | { |
|
|
1665 | if (maptile *tile = m->tile_available (TILE_DOWN, 1)) |
|
|
1666 | split_to_tiles (buf, tile, x0, max (y0 - m->height, 0), x1, y1 - m->height, dx, dy + m->height); |
|
|
1667 | |
|
|
1668 | if (y0 > m->height) // entirely below |
|
|
1669 | return; |
|
|
1670 | |
|
|
1671 | y1 = m->height; |
|
|
1672 | } |
|
|
1673 | |
|
|
1674 | // if we get here, the rect is within the current map |
|
|
1675 | maprect *r = (maprect *)buf.alloc (sizeof (maprect)); |
|
|
1676 | |
|
|
1677 | r->m = m; |
|
|
1678 | r->x0 = x0; |
|
|
1679 | r->y0 = y0; |
|
|
1680 | r->x1 = x1; |
|
|
1681 | r->y1 = y1; |
|
|
1682 | r->dx = dx; |
|
|
1683 | r->dy = dy; |
|
|
1684 | } |
|
|
1685 | |
|
|
1686 | maprect * |
|
|
1687 | maptile::split_to_tiles (int x0, int y0, int x1, int y1) |
|
|
1688 | { |
|
|
1689 | static dynbuf buf (sizeof (maprect) * 8, sizeof (maprect) * 8); |
|
|
1690 | buf.clear (); |
|
|
1691 | |
|
|
1692 | ::split_to_tiles (buf, this, x0, y0, x1, y1, 0, 0); |
|
|
1693 | |
|
|
1694 | // add end marker |
|
|
1695 | maprect *r = (maprect *)buf.alloc (sizeof (maprect)); |
|
|
1696 | r->m = 0; |
|
|
1697 | |
|
|
1698 | return (maprect *)buf.linearise (); |
|
|
1699 | } |
|
|
1700 | |