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.180 by root, Thu Jan 14 23:46:14 2010 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;
423 return false; 422 return false;
424 423
425 return freezer.save (path); 424 return freezer.save (path);
426} 425}
427 426
428maptile::maptile () 427void
428maptile::init ()
429{ 429{
430 in_memory = MAP_SWAPPED; 430 in_memory = MAP_SWAPPED;
431 431
432 /* 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
433 * map archetype. Mimic that behaviour. 433 * map archetype. Mimic that behaviour.
434 */ 434 */
435 width = 16; 435 width = 16;
436 height = 16; 436 height = 16;
437 timeout = 300; 437 timeout = 300;
438 max_items = MAX_ITEM_PER_ACTION; 438 max_items = MAX_ITEM_PER_ACTION;
439 max_volume = 2000000; // 2m³ 439 max_volume = 2000000; // 2m³
440}
441
442maptile::maptile (int w, int h)
443{
444 in_memory = MAP_SWAPPED;
445
446 width = w;
447 height = h;
448 reset_timeout = 0; 440 reset_timeout = 0;
449 timeout = 300;
450 enter_x = 0; 441 enter_x = 0;
451 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;
452 456
453 alloc (); 457 alloc ();
454} 458}
455 459
456/* 460/*
663 case KW_end: 667 case KW_end:
664 thawer.next (); 668 thawer.next ();
665 return true; 669 return true;
666 670
667 default: 671 default:
668 if (!thawer.parse_error ("map", 0)) 672 if (!thawer.parse_error ("map"))
669 return false; 673 return false;
670 break; 674 break;
671 } 675 }
672 676
673 thawer.next (); 677 thawer.next ();
691 int unique = 0; 695 int unique = 0;
692 for (object *op = spaces [i].bot; op; ) 696 for (object *op = spaces [i].bot; op; )
693 { 697 {
694 object *above = op->above; 698 object *above = op->above;
695 699
696 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 700 if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE])
697 unique = 1; 701 unique = 1;
698 702
699 if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 703 if (op->head_ () == op && (op->flag [FLAG_UNIQUE] || unique))
700 op->destroy (); 704 op->destroy ();
701 705
702 op = above; 706 op = above;
703 } 707 }
704 } 708 }
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
859 // do not decay anything above unique floor tiles (yet :) 863 // do not decay anything above unique floor tiles (yet :)
860 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 864 if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE])
861 break; 865 break;
862 866
863 bool destroy = 0; 867 bool destroy = 0;
864 868
865 if (QUERY_FLAG (op, FLAG_IS_FLOOR) 869 if (op->flag [FLAG_IS_FLOOR]
866 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) 870 || op->flag [FLAG_OBJ_ORIGINAL]
867 || QUERY_FLAG (op, FLAG_UNIQUE) 871 || op->flag [FLAG_UNIQUE]
868 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) 872 || op->flag [FLAG_OVERLAY_FLOOR]
869 || QUERY_FLAG (op, FLAG_UNPAID) 873 || op->flag [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--;
930 sint64 total_exp = 0; 934 sint64 total_exp = 0;
931 935
932 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 936 for (mapspace *ms = spaces + size (); ms-- > spaces; )
933 for (object *op = ms->bot; op; op = op->above) 937 for (object *op = ms->bot; op; op = op->above)
934 { 938 {
935 if (QUERY_FLAG (op, FLAG_MONSTER)) 939 if (op->flag [FLAG_MONSTER])
936 { 940 {
937 total_exp += op->stats.exp; 941 total_exp += op->stats.exp;
938 monster_cnt++; 942 monster_cnt++;
939 } 943 }
940 944
941 if (QUERY_FLAG (op, FLAG_GENERATOR)) 945 if (op->flag [FLAG_GENERATOR])
942 { 946 {
943 total_exp += op->stats.exp; 947 total_exp += op->stats.exp;
944 948
945 if (archetype *at = op->other_arch) 949 if (archetype *at = op->other_arch)
946 { 950 {
1128 */ 1132 */
1129 1133
1130 for (object *tmp = last; tmp; tmp = tmp->below) 1134 for (object *tmp = last; tmp; tmp = tmp->below)
1131 { 1135 {
1132 /* 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 */
1133 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1137 if (tmp->flag [FLAG_IS_FLOOR])
1134 break; 1138 break;
1135 1139
1136 /* If two top faces are already set, quit processing */ 1140 /* If two top faces are already set, quit processing */
1137 if (top && middle) 1141 if (top && middle)
1138 break; 1142 break;
1421 * 1425 *
1422 * currently, the only flag supported (0x1) is don't translate for 1426 * currently, the only flag supported (0x1) is don't translate for
1423 * closest body part of 'op1' 1427 * closest body part of 'op1'
1424 */ 1428 */
1425void 1429void
1426get_rangevector (object *op1, object *op2, rv_vector * retval, int flags) 1430get_rangevector (object *op1, object *op2, rv_vector *retval, int flags)
1427{ 1431{
1428 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))
1429 { 1433 {
1430 /* be conservative and fill in _some_ data */ 1434 /* be conservative and fill in _some_ data */
1431 retval->distance = 10000; 1435 retval->distance = 10000;
1434 retval->direction = 0; 1438 retval->direction = 0;
1435 retval->part = 0; 1439 retval->part = 0;
1436 } 1440 }
1437 else 1441 else
1438 { 1442 {
1439 object *best;
1440
1441 retval->distance_x += op2->x - op1->x; 1443 retval->distance_x += op2->x - op1->x;
1442 retval->distance_y += op2->y - op1->y; 1444 retval->distance_y += op2->y - op1->y;
1443 1445
1444 best = op1; 1446 object *best = op1;
1447
1445 /* If this is multipart, find the closest part now */ 1448 /* If this is multipart, find the closest part now */
1446 if (!(flags & 0x1) && op1->more) 1449 if (!(flags & 1) && op1->more)
1447 { 1450 {
1448 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;
1449 1452
1450 /* 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
1451 * distance instead of doing all that work above again 1454 * distance instead of doing all that work above again
1564 */ 1567 */
1565 for (int i = 1000; --i;) 1568 for (int i = 1000; --i;)
1566 { 1569 {
1567 object *pick = at (gen (width), gen (height)).bot; 1570 object *pick = at (gen (width), gen (height)).bot;
1568 1571
1569 // do not prefer big monsters just because they are big. 1572 // must be head: do not prefer big monsters just because they are big.
1570 if (pick && pick->is_head ()) 1573 if (pick && pick->is_head ())
1571 return pick->head_ (); 1574 return pick;
1572 } 1575 }
1573 1576
1574 // instead of crashing in the unlikely(?) case, try to return *something* 1577 // instead of crashing in the unlikely(?) case, try to return *something*
1575 return archetype::find (shstr_bug); 1578 return archetype::find (shstr_bug);
1576} 1579}
1609 1612
1610 if (distance <= MAX_SOUND_DISTANCE) 1613 if (distance <= MAX_SOUND_DISTANCE)
1611 ns->send_msg (NDI_GREY | NDI_DEF, SAY_CHANNEL, msg); 1614 ns->send_msg (NDI_GREY | NDI_DEF, SAY_CHANNEL, msg);
1612 } 1615 }
1613} 1616}
1617
1618dynbuf mapwalk_buf (sizeof (maprect) * 25, sizeof (maprect) * 25);
1614 1619
1615static void 1620static void
1616split_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)
1617{ 1622{
1618 // clip to map to the left 1623 // clip to map to the left
1674 r->dx = dx; 1679 r->dx = dx;
1675 r->dy = dy; 1680 r->dy = dy;
1676} 1681}
1677 1682
1678maprect * 1683maprect *
1679maptile::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)
1680{ 1685{
1681 static dynbuf buf (sizeof (maprect) * 8, sizeof (maprect) * 8);
1682 buf.clear (); 1686 buf.clear ();
1683 1687
1684 ::split_to_tiles (buf, this, x0, y0, x1, y1, 0, 0); 1688 ::split_to_tiles (buf, this, x0, y0, x1, y1, 0, 0);
1685 1689
1686 // add end marker 1690 // add end marker

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines