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.175 by root, Tue Nov 10 05:06:02 2009 UTC vs.
Revision 1.188 by root, Fri Apr 16 02:32:25 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
23 */ 23 */
24 24
25#include <unistd.h> 25#include <unistd.h>
26 26
27#include "global.h" 27#include "global.h"
28#include "loader.h"
29#include "path.h" 28#include "path.h"
30 29
31//+GPL 30//+GPL
32 31
33sint8 maptile::outdoor_darkness; 32sint8 maptile::outdoor_darkness;
150 // blocks anything but wizards. 149 // blocks anything but wizards.
151 150
152 if (tmp->flag [FLAG_ALIVE] 151 if (tmp->flag [FLAG_ALIVE]
153 && tmp->head_ () != ob 152 && tmp->head_ () != ob
154 && tmp != ob 153 && tmp != ob
155 && tmp->type != DOOR 154 && tmp->type != DOOR)
156 && !tmp->flag [FLAG_WIZPASS])
157 return 1; 155 return 1;
158 } 156 }
159 } 157 }
160 158
161 return 0; 159 return 0;
243 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 241 for (mapspace *ms = spaces + size (); ms-- > spaces; )
244 for (object *tmp = ms->bot; tmp; tmp = tmp->above) 242 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
245 INVOKE_OBJECT (RESET, tmp); 243 INVOKE_OBJECT (RESET, tmp);
246} 244}
247 245
246void
247maptile::post_load ()
248{
249#if 0
250 if (!spaces)
251 return;
252
253 for (mapspace *ms = spaces + size (); ms-- > spaces; )
254 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
255 ; // nop
256#endif
257}
258
248//+GPL 259//+GPL
249 260
250/* link_multipart_objects go through all the objects on the map looking 261/* link_multipart_objects go through all the objects on the map looking
251 * for objects whose arch says they are multipart yet according to the 262 * for objects whose arch says they are multipart yet according to the
252 * info we have, they only have the head (as would be expected when 263 * info we have, they only have the head (as would be expected when
411 return false; 422 return false;
412 423
413 return freezer.save (path); 424 return freezer.save (path);
414} 425}
415 426
416maptile::maptile () 427void
428maptile::init ()
417{ 429{
418 in_memory = MAP_SWAPPED; 430 in_memory = MAP_SWAPPED;
419 431
420 /* The maps used to pick up default x and y values from the 432 /* The maps used to pick up default x and y values from the
421 * map archetype. Mimic that behaviour. 433 * map archetype. Mimic that behaviour.
422 */ 434 */
423 width = 16; 435 width = 16;
424 height = 16; 436 height = 16;
425 timeout = 300; 437 timeout = 300;
426 max_items = MAX_ITEM_PER_ACTION; 438 max_items = MAX_ITEM_PER_ACTION;
427 max_volume = 2000000; // 2m³ 439 max_volume = 2000000; // 2m³
428}
429
430maptile::maptile (int w, int h)
431{
432 in_memory = MAP_SWAPPED;
433
434 width = w;
435 height = h;
436 reset_timeout = 0; 440 reset_timeout = 0;
437 timeout = 300;
438 enter_x = 0; 441 enter_x = 0;
439 enter_y = 0; 442 enter_y = 0;
443}
444
445maptile::maptile ()
446{
447 init ();
448}
449
450maptile::maptile (int w, int h)
451{
452 init ();
453
454 width = w;
455 height = h;
440 456
441 alloc (); 457 alloc ();
442} 458}
443 459
444/* 460/*
617 case KW_shopgreed: thawer.get (shopgreed); break; 633 case KW_shopgreed: thawer.get (shopgreed); break;
618 case KW_shopmin: thawer.get (shopmin); break; 634 case KW_shopmin: thawer.get (shopmin); break;
619 case KW_shopmax: thawer.get (shopmax); break; 635 case KW_shopmax: thawer.get (shopmax); break;
620 case KW_shoprace: thawer.get (shoprace); break; 636 case KW_shoprace: thawer.get (shoprace); break;
621 case KW_outdoor: thawer.get (outdoor); break; 637 case KW_outdoor: thawer.get (outdoor); break;
622 case KW_temp: thawer.get (temp); break;
623 case KW_pressure: thawer.get (pressure); break;
624 case KW_humid: thawer.get (humid); break;
625 case KW_windspeed: thawer.get (windspeed); break;
626 case KW_winddir: thawer.get (winddir); break;
627 case KW_sky: thawer.get (sky); break;
628 638
629 case KW_per_player: thawer.get (per_player); break; 639 case KW_per_player: thawer.get (per_player); break;
630 case KW_per_party: thawer.get (per_party); break; 640 case KW_per_party: thawer.get (per_party); break;
631 case KW_no_reset: thawer.get (no_reset); break; 641 case KW_no_reset: thawer.get (no_reset); break;
632 case KW_no_drop: thawer.get (no_drop); break; 642 case KW_no_drop: thawer.get (no_drop); break;
657 case KW_end: 667 case KW_end:
658 thawer.next (); 668 thawer.next ();
659 return true; 669 return true;
660 670
661 default: 671 default:
662 if (!thawer.parse_error ("map", 0)) 672 if (!thawer.parse_error ("map"))
663 return false; 673 return false;
664 break; 674 break;
665 } 675 }
666 676
667 thawer.next (); 677 thawer.next ();
685 int unique = 0; 695 int unique = 0;
686 for (object *op = spaces [i].bot; op; ) 696 for (object *op = spaces [i].bot; op; )
687 { 697 {
688 object *above = op->above; 698 object *above = op->above;
689 699
690 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 700 if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE])
691 unique = 1; 701 unique = 1;
692 702
693 if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 703 if (op->head_ () == op && (op->flag [FLAG_UNIQUE] || unique))
694 op->destroy (); 704 op->destroy ();
695 705
696 op = above; 706 op = above;
697 } 707 }
698 } 708 }
701//-GPL 711//-GPL
702 712
703bool 713bool
704maptile::_save_header (object_freezer &freezer) 714maptile::_save_header (object_freezer &freezer)
705{ 715{
706#define MAP_OUT(k) freezer.put (KW_ ## k, k) 716#define MAP_OUT(k) freezer.put (KW(k), k)
707#define MAP_OUT2(k,v) freezer.put (KW_ ## k, v) 717#define MAP_OUT2(k,v) freezer.put (KW(k), v)
708 718
709 MAP_OUT2 (arch, "map"); 719 MAP_OUT2 (arch, CS(map));
710 720
711 if (name) MAP_OUT (name); 721 if (name) MAP_OUT (name);
712 MAP_OUT (swap_time); 722 MAP_OUT (swap_time);
713 MAP_OUT (reset_time); 723 MAP_OUT (reset_time);
714 MAP_OUT (reset_timeout); 724 MAP_OUT (reset_timeout);
722 MAP_OUT (shopgreed); 732 MAP_OUT (shopgreed);
723 MAP_OUT (shopmin); 733 MAP_OUT (shopmin);
724 MAP_OUT (shopmax); 734 MAP_OUT (shopmax);
725 if (shoprace) MAP_OUT (shoprace); 735 if (shoprace) MAP_OUT (shoprace);
726 736
727 MAP_OUT (darkness);
728 MAP_OUT (width); 737 MAP_OUT (width);
729 MAP_OUT (height); 738 MAP_OUT (height);
730 MAP_OUT (enter_x); 739 MAP_OUT (enter_x);
731 MAP_OUT (enter_y); 740 MAP_OUT (enter_y);
732 741 MAP_OUT (darkness);
733 if (msg) freezer.put (KW_msg , KW_endmsg , msg);
734 if (maplore) freezer.put (KW_maplore, KW_endmaplore, maplore);
735
736 MAP_OUT (outdoor); 742 MAP_OUT (outdoor);
737 MAP_OUT (temp); 743
738 MAP_OUT (pressure); 744 if (msg) freezer.put (KW(msg) , KW(endmsg) , msg);
739 MAP_OUT (humid); 745 if (maplore) freezer.put (KW(maplore), KW(endmaplore), maplore);
740 MAP_OUT (windspeed);
741 MAP_OUT (winddir);
742 MAP_OUT (sky);
743 746
744 MAP_OUT (per_player); 747 MAP_OUT (per_player);
745 MAP_OUT (per_party); 748 MAP_OUT (per_party);
746 749
747 if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); 750 if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]);
748 if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); 751 if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]);
749 if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); 752 if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]);
750 if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); 753 if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]);
751 754
752 freezer.put (this); 755 freezer.put (this);
753 freezer.put (KW_end); 756 freezer.put (KW(end));
754 757
755 return true; 758 return true;
756} 759}
757 760
758bool 761bool
843 846
844 clear (); 847 clear ();
845} 848}
846 849
847/* decay and destroy perishable items in a map */ 850/* decay and destroy perishable items in a map */
851// TODO: should be done regularly, not on map load?
848void 852void
849maptile::do_decay_objects () 853maptile::do_decay_objects ()
850{ 854{
851 if (!spaces) 855 if (!spaces)
852 return; 856 return;
854 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 858 for (mapspace *ms = spaces + size (); ms-- > spaces; )
855 for (object *above, *op = ms->bot; op; op = above) 859 for (object *above, *op = ms->bot; op; op = above)
856 { 860 {
857 above = op->above; 861 above = op->above;
858 862
863 // do not decay anything above unique floor tiles (yet :)
864 if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE])
865 break;
866
859 bool destroy = 0; 867 bool destroy = 0;
860 868
861 // do not decay anything above unique floor tiles (yet :) 869 if (op->flag [FLAG_IS_FLOOR]
862 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 870 || op->flag [FLAG_OBJ_ORIGINAL]
863 break; 871 || op->flag [FLAG_UNIQUE]
864 872 || op->flag [FLAG_OVERLAY_FLOOR]
865 if (QUERY_FLAG (op, FLAG_IS_FLOOR) 873 || op->flag [FLAG_UNPAID]
866 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL)
867 || QUERY_FLAG (op, FLAG_UNIQUE)
868 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)
869 || QUERY_FLAG (op, FLAG_UNPAID)
870 || op->is_alive ()) 874 || op->is_alive ())
871 ; // do not decay 875 ; // do not decay
872 else if (op->is_weapon ()) 876 else if (op->is_weapon ())
873 { 877 {
874 op->stats.dam--; 878 op->stats.dam--;
899 || mat & M_LIQUID 903 || mat & M_LIQUID
900 || (mat & M_IRON && rndm (1, 5) == 1) 904 || (mat & M_IRON && rndm (1, 5) == 1)
901 || (mat & M_GLASS && rndm (1, 2) == 1) 905 || (mat & M_GLASS && rndm (1, 2) == 1)
902 || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1) 906 || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1)
903 || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1) 907 || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1)
904 || (mat & M_ICE && temp > 32)) 908 //|| (mat & M_ICE && temp > 32)
909 )
905 destroy = 1; 910 destroy = 1;
906 } 911 }
907 912
908 /* adjust overall chance below */ 913 /* adjust overall chance below */
909 if (destroy && rndm (0, 1)) 914 if (destroy && rndm (0, 1))
929 sint64 total_exp = 0; 934 sint64 total_exp = 0;
930 935
931 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 936 for (mapspace *ms = spaces + size (); ms-- > spaces; )
932 for (object *op = ms->bot; op; op = op->above) 937 for (object *op = ms->bot; op; op = op->above)
933 { 938 {
934 if (QUERY_FLAG (op, FLAG_MONSTER)) 939 if (op->flag [FLAG_MONSTER])
935 { 940 {
936 total_exp += op->stats.exp; 941 total_exp += op->stats.exp;
937 monster_cnt++; 942 monster_cnt++;
938 } 943 }
939 944
940 if (QUERY_FLAG (op, FLAG_GENERATOR)) 945 if (op->flag [FLAG_GENERATOR])
941 { 946 {
942 total_exp += op->stats.exp; 947 total_exp += op->stats.exp;
943 948
944 if (archetype *at = op->other_arch) 949 if (archetype *at = op->other_arch)
945 { 950 {
1127 */ 1132 */
1128 1133
1129 for (object *tmp = last; tmp; tmp = tmp->below) 1134 for (object *tmp = last; tmp; tmp = tmp->below)
1130 { 1135 {
1131 /* Once we get to a floor, stop, since we already have a floor object */ 1136 /* Once we get to a floor, stop, since we already have a floor object */
1132 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1137 if (tmp->flag [FLAG_IS_FLOOR])
1133 break; 1138 break;
1134 1139
1135 /* If two top faces are already set, quit processing */ 1140 /* If two top faces are already set, quit processing */
1136 if (top && middle) 1141 if (top && middle)
1137 break; 1142 break;
1420 * 1425 *
1421 * currently, the only flag supported (0x1) is don't translate for 1426 * currently, the only flag supported (0x1) is don't translate for
1422 * closest body part of 'op1' 1427 * closest body part of 'op1'
1423 */ 1428 */
1424void 1429void
1425get_rangevector (object *op1, object *op2, rv_vector * retval, int flags) 1430get_rangevector (object *op1, object *op2, rv_vector *retval, int flags)
1426{ 1431{
1427 if (!adjacent_map (op1->map, op2->map, &retval->distance_x, &retval->distance_y)) 1432 if (!adjacent_map (op1->map, op2->map, &retval->distance_x, &retval->distance_y))
1428 { 1433 {
1429 /* be conservative and fill in _some_ data */ 1434 /* be conservative and fill in _some_ data */
1430 retval->distance = 10000; 1435 retval->distance = 10000;
1433 retval->direction = 0; 1438 retval->direction = 0;
1434 retval->part = 0; 1439 retval->part = 0;
1435 } 1440 }
1436 else 1441 else
1437 { 1442 {
1438 object *best;
1439
1440 retval->distance_x += op2->x - op1->x; 1443 retval->distance_x += op2->x - op1->x;
1441 retval->distance_y += op2->y - op1->y; 1444 retval->distance_y += op2->y - op1->y;
1442 1445
1443 best = op1; 1446 object *best = op1;
1447
1444 /* If this is multipart, find the closest part now */ 1448 /* If this is multipart, find the closest part now */
1445 if (!(flags & 0x1) && op1->more) 1449 if (!(flags & 1) && op1->more)
1446 { 1450 {
1447 int best_distance = retval->distance_x * retval->distance_x + retval->distance_y * retval->distance_y, tmpi; 1451 int best_distance = retval->distance_x * retval->distance_x + retval->distance_y * retval->distance_y, tmpi;
1448 1452
1449 /* we just take the offset of the piece to head to figure 1453 /* we just take the offset of the piece to head to figure
1450 * distance instead of doing all that work above again 1454 * distance instead of doing all that work above again
1563 */ 1567 */
1564 for (int i = 1000; --i;) 1568 for (int i = 1000; --i;)
1565 { 1569 {
1566 object *pick = at (gen (width), gen (height)).bot; 1570 object *pick = at (gen (width), gen (height)).bot;
1567 1571
1568 // do not prefer big monsters just because they are big. 1572 // must be head: do not prefer big monsters just because they are big.
1569 if (pick && pick->is_head ()) 1573 if (pick && pick->is_head ())
1570 return pick->head_ (); 1574 return pick;
1571 } 1575 }
1572 1576
1573 // instead of crashing in the unlikely(?) case, try to return *something* 1577 // instead of crashing in the unlikely(?) case, try to return *something*
1574 return archetype::find (shstr_bug); 1578 return archetype::find (shstr_bug);
1575} 1579}
1608 1612
1609 if (distance <= MAX_SOUND_DISTANCE) 1613 if (distance <= MAX_SOUND_DISTANCE)
1610 ns->send_msg (NDI_GREY | NDI_DEF, SAY_CHANNEL, msg); 1614 ns->send_msg (NDI_GREY | NDI_DEF, SAY_CHANNEL, msg);
1611 } 1615 }
1612} 1616}
1617
1618dynbuf mapwalk_buf (sizeof (maprect) * 25, sizeof (maprect) * 25);
1613 1619
1614static void 1620static void
1615split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy) 1621split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy)
1616{ 1622{
1617 // clip to map to the left 1623 // clip to map to the left
1673 r->dx = dx; 1679 r->dx = dx;
1674 r->dy = dy; 1680 r->dy = dy;
1675} 1681}
1676 1682
1677maprect * 1683maprect *
1678maptile::split_to_tiles (int x0, int y0, int x1, int y1) 1684maptile::split_to_tiles (dynbuf &buf, int x0, int y0, int x1, int y1)
1679{ 1685{
1680 static dynbuf buf (sizeof (maprect) * 8, sizeof (maprect) * 8);
1681 buf.clear (); 1686 buf.clear ();
1682 1687
1683 ::split_to_tiles (buf, this, x0, y0, x1, y1, 0, 0); 1688 ::split_to_tiles (buf, this, x0, y0, x1, y1, 0, 0);
1684 1689
1685 // add end marker 1690 // add end marker

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines