ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.138 by root, Sun May 4 14:12:37 2008 UTC vs.
Revision 1.151 by root, Tue Dec 23 00:39:48 2008 UTC

22 */ 22 */
23 23
24#include <unistd.h> 24#include <unistd.h>
25 25
26#include "global.h" 26#include "global.h"
27
28#include "loader.h" 27#include "loader.h"
29
30#include "path.h" 28#include "path.h"
31 29
32/* This rolls up wall, blocks_magic, blocks_view, etc, all into 30/* This rolls up wall, blocks_magic, blocks_view, etc, all into
33 * one function that just returns a P_.. value (see map.h) 31 * one function that just returns a P_.. value (see map.h)
34 * it will also do map translation for tiled maps, returning 32 * it will also do map translation for tiled maps, returning
260 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 258 for (mapspace *ms = spaces + size (); ms-- > spaces; )
261 for (object *tmp = ms->bot; tmp; tmp = tmp->above) 259 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
262 tmp->flag [flag] = value; 260 tmp->flag [flag] = value;
263} 261}
264 262
263void
264maptile::post_load_original ()
265{
266 if (!spaces)
267 return;
268
269 set_object_flag (FLAG_OBJ_ORIGINAL);
270
271 for (mapspace *ms = spaces + size (); ms-- > spaces; )
272 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
273 INVOKE_OBJECT (RESET, tmp);
274}
275
265/* link_multipart_objects go through all the objects on the map looking 276/* link_multipart_objects go through all the objects on the map looking
266 * for objects whose arch says they are multipart yet according to the 277 * for objects whose arch says they are multipart yet according to the
267 * info we have, they only have the head (as would be expected when 278 * info we have, they only have the head (as would be expected when
268 * they are saved). 279 * they are saved).
269 */ 280 */
641 case KW_sky: thawer.get (sky); break; 652 case KW_sky: thawer.get (sky); break;
642 653
643 case KW_per_player: thawer.get (per_player); break; 654 case KW_per_player: thawer.get (per_player); break;
644 case KW_per_party: thawer.get (per_party); break; 655 case KW_per_party: thawer.get (per_party); break;
645 case KW_no_reset: thawer.get (no_reset); break; 656 case KW_no_reset: thawer.get (no_reset); break;
657 case KW_no_drop: thawer.get (no_drop); break;
646 658
647 case KW_region: default_region = region::find (thawer.get_str ()); break; 659 case KW_region: default_region = region::find (thawer.get_str ()); break;
648 case KW_shopitems: shopitems = parse_shop_string (thawer.get_str ()); break; 660 case KW_shopitems: shopitems = parse_shop_string (thawer.get_str ()); break;
649 661
650 // old names new names 662 // old names new names
700 712
701 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 713 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
702 unique = 1; 714 unique = 1;
703 715
704 if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 716 if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
705 {
706 op->destroy_inv (false);
707 op->destroy (); 717 op->destroy ();
708 }
709 718
710 op = above; 719 op = above;
711 } 720 }
712 } 721 }
713} 722}
724 MAP_OUT (swap_time); 733 MAP_OUT (swap_time);
725 MAP_OUT (reset_time); 734 MAP_OUT (reset_time);
726 MAP_OUT (reset_timeout); 735 MAP_OUT (reset_timeout);
727 MAP_OUT (fixed_resettime); 736 MAP_OUT (fixed_resettime);
728 MAP_OUT (no_reset); 737 MAP_OUT (no_reset);
738 MAP_OUT (no_drop);
729 MAP_OUT (difficulty); 739 MAP_OUT (difficulty);
730 740
731 if (default_region) MAP_OUT2 (region, default_region->name); 741 if (default_region) MAP_OUT2 (region, default_region->name);
732 742
733 if (shopitems) 743 if (shopitems)
800 810
801 op->flag [FLAG_REMOVED] = true; 811 op->flag [FLAG_REMOVED] = true;
802 812
803 object *head = op->head_ (); 813 object *head = op->head_ ();
804 if (op == head) 814 if (op == head)
805 {
806 op->destroy_inv (false);
807 op->destroy (); 815 op->destroy ();
808 }
809 else if (head->map != op->map) 816 else if (head->map != op->map)
810 { 817 {
811 LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ()); 818 LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ());
812 head->destroy (); 819 head->destroy ();
813 } 820 }
981 988
982 if (QUERY_FLAG (op, FLAG_GENERATOR)) 989 if (QUERY_FLAG (op, FLAG_GENERATOR))
983 { 990 {
984 total_exp += op->stats.exp; 991 total_exp += op->stats.exp;
985 992
986 if (archetype *at = type_to_archetype (GENERATE_TYPE (op))) 993 if (archetype *at = op->other_arch)
994 {
987 total_exp += at->stats.exp * 8; 995 total_exp += at->stats.exp * 8;
988
989 monster_cnt++; 996 monster_cnt++;
997 }
998
999 for (object *inv = op->inv; inv; inv = inv->below)
1000 {
1001 total_exp += op->stats.exp * 8;
1002 monster_cnt++;
1003 }
990 } 1004 }
991 } 1005 }
992 1006
993 avgexp = (double) total_exp / monster_cnt; 1007 avgexp = (double) total_exp / monster_cnt;
994 1008
1033 else 1047 else
1034 darkness = new_level; 1048 darkness = new_level;
1035 1049
1036 /* All clients need to get re-updated for the change */ 1050 /* All clients need to get re-updated for the change */
1037 update_all_map_los (this); 1051 update_all_map_los (this);
1052
1038 return 1; 1053 return 1;
1039} 1054}
1040 1055
1041/* 1056/*
1042 * This function updates various attributes about a specific space 1057 * This function updates various attributes about a specific space
1045 * through, etc) 1060 * through, etc)
1046 */ 1061 */
1047void 1062void
1048mapspace::update_ () 1063mapspace::update_ ()
1049{ 1064{
1050 object *tmp, *last = 0; 1065 object *last = 0;
1051 uint8 flags = P_UPTODATE, light = 0, anywhere = 0; 1066 uint8 flags = P_UPTODATE, anywhere = 0;
1067 sint8 light = 0;
1052 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; 1068 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1053 1069
1054 //object *middle = 0; 1070 //object *middle = 0;
1055 //object *top = 0; 1071 //object *top = 0;
1056 //object *floor = 0; 1072 //object *floor = 0;
1057 // this seems to generate better code than using locals, above 1073 // this seems to generate better code than using locals, above
1058 object *&top = faces_obj[0] = 0; 1074 object *&top = faces_obj[0] = 0;
1059 object *&middle = faces_obj[1] = 0; 1075 object *&middle = faces_obj[1] = 0;
1060 object *&floor = faces_obj[2] = 0; 1076 object *&floor = faces_obj[2] = 0;
1061 1077
1062 for (tmp = bot; tmp; last = tmp, tmp = tmp->above) 1078 for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above)
1063 { 1079 {
1064 /* This could be made additive I guess (two lights better than 1080 // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C)
1065 * one). But if so, it shouldn't be a simple additive - 2
1066 * light bulbs do not illuminate twice as far as once since
1067 * it is a dissapation factor that is cubed.
1068 */
1069 if (tmp->glow_radius > light)
1070 light = tmp->glow_radius; 1081 light += tmp->glow_radius;
1071 1082
1072 /* This call is needed in order to update objects the player 1083 /* This call is needed in order to update objects the player
1073 * is standing in that have animations (ie, grass, fire, etc). 1084 * is standing in that have animations (ie, grass, fire, etc).
1074 * However, it also causes the look window to be re-drawn 1085 * However, it also causes the look window to be re-drawn
1075 * 3 times each time the player moves, because many of the 1086 * 3 times each time the player moves, because many of the
1094 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) 1105 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE))
1095 { 1106 {
1096 middle = tmp; 1107 middle = tmp;
1097 anywhere = 1; 1108 anywhere = 1;
1098 } 1109 }
1110
1099 /* Find the highest visible face around. If equal 1111 /* Find the highest visible face around. If equal
1100 * visibilities, we still want the one nearer to the 1112 * visibilities, we still want the one nearer to the
1101 * top 1113 * top
1102 */ 1114 */
1103 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) 1115 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere))
1122 if (tmp->type == SAFE_GROUND) flags |= P_SAFE; 1134 if (tmp->type == SAFE_GROUND) flags |= P_SAFE;
1123 if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; 1135 if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE;
1124 if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; 1136 if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC;
1125 } 1137 }
1126 1138
1127 this->light = light; 1139 this->light = min (light, MAX_LIGHT_RADIUS);
1128 this->flags_ = flags; 1140 this->flags_ = flags;
1129 this->move_block = move_block & ~move_allow; 1141 this->move_block = move_block & ~move_allow;
1130 this->move_on = move_on; 1142 this->move_on = move_on;
1131 this->move_off = move_off; 1143 this->move_off = move_off;
1132 this->move_slow = move_slow; 1144 this->move_slow = move_slow;
1152 * 1) top face is set, need middle to be set. 1164 * 1) top face is set, need middle to be set.
1153 * 2) middle is set, need to set top. 1165 * 2) middle is set, need to set top.
1154 * 3) neither middle or top is set - need to set both. 1166 * 3) neither middle or top is set - need to set both.
1155 */ 1167 */
1156 1168
1157 for (tmp = last; tmp; tmp = tmp->below) 1169 for (object *tmp = last; tmp; tmp = tmp->below)
1158 { 1170 {
1159 /* Once we get to a floor, stop, since we already have a floor object */ 1171 /* Once we get to a floor, stop, since we already have a floor object */
1160 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1172 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1161 break; 1173 break;
1162 1174
1565} 1577}
1566 1578
1567object * 1579object *
1568maptile::insert (object *op, int x, int y, object *originator, int flags) 1580maptile::insert (object *op, int x, int y, object *originator, int flags)
1569{ 1581{
1570 if (!op->flag [FLAG_REMOVED])
1571 op->remove ();
1572
1573 return insert_ob_in_map_at (op, this, originator, flags, x, y); 1582 return insert_ob_in_map_at (op, this, originator, flags, x, y);
1574} 1583}
1575 1584
1576region * 1585region *
1577maptile::region (int x, int y) const 1586maptile::region (int x, int y) const
1616maptile::play_sound (faceidx sound, int x, int y) const 1625maptile::play_sound (faceidx sound, int x, int y) const
1617{ 1626{
1618 if (!sound) 1627 if (!sound)
1619 return; 1628 return;
1620 1629
1621 for_all_players (pl) 1630 for_all_players_on_map (pl, this)
1622 if (pl->ob->map == this)
1623 if (client *ns = pl->ns) 1631 if (client *ns = pl->ns)
1624 { 1632 {
1625 int dx = x - pl->ob->x; 1633 int dx = x - pl->ob->x;
1626 int dy = y - pl->ob->y; 1634 int dy = y - pl->ob->y;
1627 1635
1628 int distance = idistance (dx, dy); 1636 int distance = idistance (dx, dy);
1629 1637
1630 if (distance <= MAX_SOUND_DISTANCE) 1638 if (distance <= MAX_SOUND_DISTANCE)
1631 ns->play_sound (sound, dx, dy); 1639 ns->play_sound (sound, dx, dy);
1632 } 1640 }
1633} 1641}
1634 1642

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines