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.136 by root, Mon Apr 21 23:35:24 2008 UTC vs.
Revision 1.146 by root, Sun Aug 17 22:46:26 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
724 MAP_OUT (swap_time); 736 MAP_OUT (swap_time);
725 MAP_OUT (reset_time); 737 MAP_OUT (reset_time);
726 MAP_OUT (reset_timeout); 738 MAP_OUT (reset_timeout);
727 MAP_OUT (fixed_resettime); 739 MAP_OUT (fixed_resettime);
728 MAP_OUT (no_reset); 740 MAP_OUT (no_reset);
741 MAP_OUT (no_drop);
729 MAP_OUT (difficulty); 742 MAP_OUT (difficulty);
730 743
731 if (default_region) MAP_OUT2 (region, default_region->name); 744 if (default_region) MAP_OUT2 (region, default_region->name);
732 745
733 if (shopitems) 746 if (shopitems)
811 LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ()); 824 LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ());
812 head->destroy (); 825 head->destroy ();
813 } 826 }
814 } 827 }
815 828
816 sfree (spaces, size ()), spaces = 0; 829 sfree0 (spaces, size ());
817 } 830 }
818 831
819 if (buttons) 832 if (buttons)
820 free_objectlinkpt (buttons), buttons = 0; 833 free_objectlinkpt (buttons), buttons = 0;
821 834
822 sfree (regions, size ()); regions = 0; 835 sfree0 (regions, size ());
823 delete [] regionmap; regionmap = 0; 836 delete [] regionmap; regionmap = 0;
824} 837}
825 838
826void 839void
827maptile::clear_header () 840maptile::clear_header ()
981 994
982 if (QUERY_FLAG (op, FLAG_GENERATOR)) 995 if (QUERY_FLAG (op, FLAG_GENERATOR))
983 { 996 {
984 total_exp += op->stats.exp; 997 total_exp += op->stats.exp;
985 998
986 if (archetype *at = type_to_archetype (GENERATE_TYPE (op))) 999 if (archetype *at = op->other_arch)
1000 {
987 total_exp += at->stats.exp * 8; 1001 total_exp += at->stats.exp * 8;
988
989 monster_cnt++; 1002 monster_cnt++;
1003 }
1004
1005 for (object *inv = op->inv; inv; inv = inv->below)
1006 {
1007 total_exp += op->stats.exp * 8;
1008 monster_cnt++;
1009 }
990 } 1010 }
991 } 1011 }
992 1012
993 avgexp = (double) total_exp / monster_cnt; 1013 avgexp = (double) total_exp / monster_cnt;
994 1014
1033 else 1053 else
1034 darkness = new_level; 1054 darkness = new_level;
1035 1055
1036 /* All clients need to get re-updated for the change */ 1056 /* All clients need to get re-updated for the change */
1037 update_all_map_los (this); 1057 update_all_map_los (this);
1058
1038 return 1; 1059 return 1;
1039} 1060}
1040 1061
1041/* 1062/*
1042 * This function updates various attributes about a specific space 1063 * This function updates various attributes about a specific space
1045 * through, etc) 1066 * through, etc)
1046 */ 1067 */
1047void 1068void
1048mapspace::update_ () 1069mapspace::update_ ()
1049{ 1070{
1050 object *tmp, *last = 0; 1071 object *last = 0;
1051 uint8 flags = P_UPTODATE, light = 0, anywhere = 0; 1072 uint8 flags = P_UPTODATE, light = 0, anywhere = 0;
1052 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; 1073 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1053 1074
1054 //object *middle = 0; 1075 //object *middle = 0;
1055 //object *top = 0; 1076 //object *top = 0;
1057 // this seems to generate better code than using locals, above 1078 // this seems to generate better code than using locals, above
1058 object *&top = faces_obj[0] = 0; 1079 object *&top = faces_obj[0] = 0;
1059 object *&middle = faces_obj[1] = 0; 1080 object *&middle = faces_obj[1] = 0;
1060 object *&floor = faces_obj[2] = 0; 1081 object *&floor = faces_obj[2] = 0;
1061 1082
1062 for (tmp = bot; tmp; last = tmp, tmp = tmp->above) 1083 for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above)
1063 { 1084 {
1064 /* This could be made additive I guess (two lights better than 1085 /* This could be made additive I guess (two lights better than
1065 * one). But if so, it shouldn't be a simple additive - 2 1086 * one). But if so, it shouldn't be a simple additive - 2
1066 * light bulbs do not illuminate twice as far as once since 1087 * light bulbs do not illuminate twice as far as once since
1067 * it is a dissapation factor that is cubed. 1088 * it is a dissapation factor that is cubed.
1068 */ 1089 */
1069 if (tmp->glow_radius > light)
1070 light = tmp->glow_radius; 1090 light = max (light, tmp->glow_radius);
1071 1091
1072 /* This call is needed in order to update objects the player 1092 /* This call is needed in order to update objects the player
1073 * is standing in that have animations (ie, grass, fire, etc). 1093 * is standing in that have animations (ie, grass, fire, etc).
1074 * However, it also causes the look window to be re-drawn 1094 * However, it also causes the look window to be re-drawn
1075 * 3 times each time the player moves, because many of the 1095 * 3 times each time the player moves, because many of the
1094 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) 1114 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE))
1095 { 1115 {
1096 middle = tmp; 1116 middle = tmp;
1097 anywhere = 1; 1117 anywhere = 1;
1098 } 1118 }
1119
1099 /* Find the highest visible face around. If equal 1120 /* Find the highest visible face around. If equal
1100 * visibilities, we still want the one nearer to the 1121 * visibilities, we still want the one nearer to the
1101 * top 1122 * top
1102 */ 1123 */
1103 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) 1124 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere))
1152 * 1) top face is set, need middle to be set. 1173 * 1) top face is set, need middle to be set.
1153 * 2) middle is set, need to set top. 1174 * 2) middle is set, need to set top.
1154 * 3) neither middle or top is set - need to set both. 1175 * 3) neither middle or top is set - need to set both.
1155 */ 1176 */
1156 1177
1157 for (tmp = last; tmp; tmp = tmp->below) 1178 for (object *tmp = last; tmp; tmp = tmp->below)
1158 { 1179 {
1159 /* Once we get to a floor, stop, since we already have a floor object */ 1180 /* Once we get to a floor, stop, since we already have a floor object */
1160 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1181 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1161 break; 1182 break;
1162 1183
1565} 1586}
1566 1587
1567object * 1588object *
1568maptile::insert (object *op, int x, int y, object *originator, int flags) 1589maptile::insert (object *op, int x, int y, object *originator, int flags)
1569{ 1590{
1570 if (!op->flag [FLAG_REMOVED])
1571 op->remove ();
1572
1573 return insert_ob_in_map_at (op, this, originator, flags, x, y); 1591 return insert_ob_in_map_at (op, this, originator, flags, x, y);
1574} 1592}
1575 1593
1576region * 1594region *
1577maptile::region (int x, int y) const 1595maptile::region (int x, int y) const
1587 1605
1588 return ::region::default_region (); 1606 return ::region::default_region ();
1589} 1607}
1590 1608
1591/* picks a random object from a style map. 1609/* picks a random object from a style map.
1592 * Redone by MSW so it should be faster and not use static
1593 * variables to generate tables.
1594 */ 1610 */
1595object * 1611object *
1596maptile::pick_random_object () const 1612maptile::pick_random_object (rand_gen &gen) const
1597{ 1613{
1598 /* while returning a null object will result in a crash, that 1614 /* while returning a null object will result in a crash, that
1599 * is actually preferable to an infinite loop. That is because 1615 * is actually preferable to an infinite loop. That is because
1600 * most servers will automatically restart in case of crash. 1616 * most servers will automatically restart in case of crash.
1601 * Change the logic on getting the random space - shouldn't make 1617 * Change the logic on getting the random space - shouldn't make
1602 * any difference, but this seems clearer to me. 1618 * any difference, but this seems clearer to me.
1603 */ 1619 */
1604 for (int i = 1000; --i;) 1620 for (int i = 1000; --i;)
1605 { 1621 {
1606 object *pick = at (rndm (width), rndm (height)).bot; 1622 object *pick = at (gen (width), gen (height)).bot;
1607 1623
1608 // do not prefer big monsters just because they are big. 1624 // do not prefer big monsters just because they are big.
1609 if (pick && pick->head_ () == pick) 1625 if (pick && pick->is_head ())
1610 return pick->head_ (); 1626 return pick->head_ ();
1611 } 1627 }
1612 1628
1613 // instead of crashing in the unlikely(?) case, try to return *something* 1629 // instead of crashing in the unlikely(?) case, try to return *something*
1614 return get_archetype ("blocked"); 1630 return archetype::find ("bug");
1615} 1631}
1616 1632
1617void 1633void
1618maptile::play_sound (faceidx sound, int x, int y) const 1634maptile::play_sound (faceidx sound, int x, int y) const
1619{ 1635{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines