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.44 by root, Mon Dec 18 04:07:30 2006 UTC vs.
Revision 1.45 by root, Wed Dec 20 09:14:21 2006 UTC

323 /* We basically go through the stack of objects, and if there is 323 /* We basically go through the stack of objects, and if there is
324 * some other object that has NO_PASS or FLAG_ALIVE set, return 324 * some other object that has NO_PASS or FLAG_ALIVE set, return
325 * true. If we get through the entire stack, that must mean 325 * true. If we get through the entire stack, that must mean
326 * ob is blocking it, so return 0. 326 * ob is blocking it, so return 0.
327 */ 327 */
328 for (tmp = GET_MAP_OB (m, sx, sy); tmp != NULL; tmp = tmp->above) 328 for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above)
329 { 329 {
330 330
331 /* This must be before the checks below. Code for inventory checkers. */ 331 /* This must be before the checks below. Code for inventory checkers. */
332 if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) 332 if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp))
333 { 333 {
397 * 397 *
398 * Note this used to be arch_blocked, but with new movement 398 * Note this used to be arch_blocked, but with new movement
399 * code, we need to have actual object to check its move_type 399 * code, we need to have actual object to check its move_type
400 * against the move_block values. 400 * against the move_block values.
401 */ 401 */
402
403int 402int
404ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) 403ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y)
405{ 404{
406 archetype *tmp; 405 archetype *tmp;
407 int flag; 406 int flag;
437 436
438 /* Note it is intentional that we check ob - the movement type of the 437 /* Note it is intentional that we check ob - the movement type of the
439 * head of the object should correspond for the entire object. 438 * head of the object should correspond for the entire object.
440 */ 439 */
441 if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) 440 if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy)))
442 return AB_NO_PASS; 441 return P_NO_PASS;
443
444 } 442 }
443
445 return 0; 444 return 0;
446} 445}
447 446
448/* When the map is loaded, load_object does not actually insert objects 447/* When the map is loaded, load_object does not actually insert objects
449 * into inventory, but just links them. What this does is go through 448 * into inventory, but just links them. What this does is go through
486 object *tmp, *op, *last, *above; 485 object *tmp, *op, *last, *above;
487 archetype *at; 486 archetype *at;
488 487
489 for (x = 0; x < MAP_WIDTH (m); x++) 488 for (x = 0; x < MAP_WIDTH (m); x++)
490 for (y = 0; y < MAP_HEIGHT (m); y++) 489 for (y = 0; y < MAP_HEIGHT (m); y++)
491 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) 490 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above)
492 { 491 {
493 above = tmp->above; 492 above = tmp->above;
494 493
495 /* already multipart - don't do anything more */ 494 /* already multipart - don't do anything more */
496 if (tmp->head || tmp->more) 495 if (tmp->head || tmp->more)
581 { 580 {
582 for (j = 0; j < m->height; j++) 581 for (j = 0; j < m->height; j++)
583 { 582 {
584 unique = 0; 583 unique = 0;
585 /* check for unique items, or unique squares */ 584 /* check for unique items, or unique squares */
586 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) 585 for (otmp = GET_MAP_OB (m, i, j); otmp; otmp = otmp->above)
587 { 586 {
588 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) 587 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
589 unique = 1; 588 unique = 1;
590 589
591 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) 590 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
612 /* first pass - save one-part objects */ 611 /* first pass - save one-part objects */
613 for (i = 0; i < MAP_WIDTH (m); i++) 612 for (i = 0; i < MAP_WIDTH (m); i++)
614 for (j = 0; j < MAP_HEIGHT (m); j++) 613 for (j = 0; j < MAP_HEIGHT (m); j++)
615 { 614 {
616 unique = 0; 615 unique = 0;
617 for (op = get_map_ob (m, i, j); op; op = op->above) 616 for (op = GET_MAP_OB (m, i, j); op; op = op->above)
618 { 617 {
619 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 618 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
620 unique = 1; 619 unique = 1;
621 620
622 if (op->type == PLAYER) 621 if (op->type == PLAYER)
623 {
624 LOG (llevDebug, "Player on map that is being saved\n");
625 continue; 622 continue;
626 }
627 623
628 if (op->head || op->owner) 624 if (op->head || op->owner)
629 continue; 625 continue;
630 626
631 if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) 627 if (unique || QUERY_FLAG (op, FLAG_UNIQUE))
632 save_object (fp2, op, 3); 628 save_object (fp2, op, 3);
633 else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) 629 else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID))))
634 save_object (fp, op, 3); 630 save_object (fp, op, 3);
635 631 }
636 } /* for this space */ 632 }
637 } /* for this j */
638} 633}
639 634
640maptile::maptile () 635maptile::maptile ()
641{ 636{
642 in_memory = MAP_SWAPPED; 637 in_memory = MAP_SWAPPED;
692 { 687 {
693 LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); 688 LOG (llevError, "allocate_map called with already allocated map (%s)\n", path);
694 free (spaces); 689 free (spaces);
695 } 690 }
696 691
697 spaces = (MapSpace *) 692 spaces = (mapspace *)
698 calloc (1, width * height * sizeof (MapSpace)); 693 calloc (1, width * height * sizeof (mapspace));
699 694
700 if (!spaces) 695 if (!spaces)
701 fatal (OUT_OF_MEMORY); 696 fatal (OUT_OF_MEMORY);
702} 697}
703 698
1249 for (i = 0; i < MAP_WIDTH (m); i++) 1244 for (i = 0; i < MAP_WIDTH (m); i++)
1250 for (j = 0; j < MAP_HEIGHT (m); j++) 1245 for (j = 0; j < MAP_HEIGHT (m); j++)
1251 { 1246 {
1252 unique = 0; 1247 unique = 0;
1253 1248
1254 for (op = get_map_ob (m, i, j); op; op = next) 1249 for (op = GET_MAP_OB (m, i, j); op; op = next)
1255 { 1250 {
1256 next = op->above; 1251 next = op->above;
1257 1252
1258 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 1253 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
1259 unique = 1; 1254 unique = 1;
1781 return MAP_DIFFICULTY (m); 1776 return MAP_DIFFICULTY (m);
1782 } 1777 }
1783 1778
1784 for (x = 0; x < MAP_WIDTH (m); x++) 1779 for (x = 0; x < MAP_WIDTH (m); x++)
1785 for (y = 0; y < MAP_HEIGHT (m); y++) 1780 for (y = 0; y < MAP_HEIGHT (m); y++)
1786 for (op = get_map_ob (m, x, y); op != NULL; op = op->above) 1781 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above)
1787 { 1782 {
1788 if (QUERY_FLAG (op, FLAG_MONSTER)) 1783 if (QUERY_FLAG (op, FLAG_MONSTER))
1789 { 1784 {
1790 total_exp += op->stats.exp; 1785 total_exp += op->stats.exp;
1791 monster_cnt++; 1786 monster_cnt++;
1884 /* All clients need to get re-updated for the change */ 1879 /* All clients need to get re-updated for the change */
1885 update_all_map_los (m); 1880 update_all_map_los (m);
1886 return 1; 1881 return 1;
1887} 1882}
1888 1883
1889
1890/* 1884/*
1891 * This function updates various attributes about a specific space 1885 * This function updates various attributes about a specific space
1892 * on the map (what it looks like, whether it blocks magic, 1886 * on the map (what it looks like, whether it blocks magic,
1893 * has a living creatures, prevents people from passing 1887 * has a living creatures, prevents people from passing
1894 * through, etc) 1888 * through, etc)
1895 */ 1889 */
1896void 1890void
1897update_position (maptile *m, int x, int y) 1891update_position (maptile *m, int x, int y)
1898{ 1892{
1899 object *tmp, *last = NULL; 1893 object *tmp, *last = 0;
1900 uint8 flags = 0, oldflags, light = 0, anywhere = 0; 1894 uint8 flags = 0, oldflags, light = 0, anywhere = 0;
1901 New_Face *top, *floor, *middle; 1895 New_Face *top, *floor, *middle;
1902 object *top_obj, *floor_obj, *middle_obj; 1896 object *top_obj, *floor_obj, *middle_obj;
1903 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; 1897 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1904 1898
1908 LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); 1902 LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y);
1909 return; 1903 return;
1910 } 1904 }
1911 1905
1912 middle = blank_face; 1906 middle = blank_face;
1913 top = blank_face; 1907 top = blank_face;
1914 floor = blank_face; 1908 floor = blank_face;
1915 1909
1916 middle_obj = NULL; 1910 middle_obj = 0;
1917 top_obj = NULL; 1911 top_obj = 0;
1918 floor_obj = NULL; 1912 floor_obj = 0;
1919 1913
1920 for (tmp = get_map_ob (m, x, y); tmp; last = tmp, tmp = tmp->above) 1914 for (tmp = GET_MAP_OB (m, x, y); tmp; last = tmp, tmp = tmp->above)
1921 { 1915 {
1922
1923 /* This could be made additive I guess (two lights better than 1916 /* This could be made additive I guess (two lights better than
1924 * one). But if so, it shouldn't be a simple additive - 2 1917 * one). But if so, it shouldn't be a simple additive - 2
1925 * light bulbs do not illuminate twice as far as once since 1918 * light bulbs do not illuminate twice as far as once since
1926 * it is a disapation factor that is squared (or is it cubed?) 1919 * it is a dissapation factor that is cubed.
1927 */ 1920 */
1928 if (tmp->glow_radius > light) 1921 if (tmp->glow_radius > light)
1929 light = tmp->glow_radius; 1922 light = tmp->glow_radius;
1930 1923
1931 /* This call is needed in order to update objects the player 1924 /* This call is needed in order to update objects the player
1969 { 1962 {
1970 middle = tmp->face; 1963 middle = tmp->face;
1971 middle_obj = tmp; 1964 middle_obj = tmp;
1972 } 1965 }
1973 } 1966 }
1967
1974 if (tmp == tmp->above) 1968 if (tmp == tmp->above)
1975 { 1969 {
1976 LOG (llevError, "Error in structure of map\n"); 1970 LOG (llevError, "Error in structure of map\n");
1977 exit (-1); 1971 exit (-1);
1978 } 1972 }
1979 1973
1980 move_slow |= tmp->move_slow; 1974 move_slow |= tmp->move_slow;
1981 move_block |= tmp->move_block; 1975 move_block |= tmp->move_block;
1982 move_on |= tmp->move_on; 1976 move_on |= tmp->move_on;
1983 move_off |= tmp->move_off; 1977 move_off |= tmp->move_off;
1984 move_allow |= tmp->move_allow; 1978 move_allow |= tmp->move_allow;
1985 1979
1986 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1987 flags |= P_IS_ALIVE;
1988 if (QUERY_FLAG (tmp, FLAG_NO_MAGIC))
1989 flags |= P_NO_MAGIC;
1990 if (QUERY_FLAG (tmp, FLAG_DAMNED))
1991 flags |= P_NO_CLERIC;
1992 if (tmp->type == SAFE_GROUND)
1993 flags |= P_SAFE;
1994
1995 if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) 1980 if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW;
1996 flags |= P_BLOCKSVIEW; 1981 if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC;
1997 } /* for stack of objects */ 1982 if (tmp->type == PLAYER) flags |= P_PLAYER;
1983 if (tmp->type == SAFE_GROUND) flags |= P_SAFE;
1984 if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE;
1985 if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC;
1986 }
1998 1987
1999 /* we don't want to rely on this function to have accurate flags, but 1988 /* we don't want to rely on this function to have accurate flags, but
2000 * since we're already doing the work, we calculate them here. 1989 * since we're already doing the work, we calculate them here.
2001 * if they don't match, logic is broken someplace. 1990 * if they don't match, logic is broken someplace.
2002 */ 1991 */
2003 if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) 1992 if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR)))
2004 {
2005 LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", 1993 LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n",
2006 m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); 1994 m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags);
2007 } 1995
2008 SET_MAP_FLAGS (m, x, y, flags); 1996 mapspace &s = m->at (x, y);
2009 SET_MAP_MOVE_BLOCK (m, x, y, move_block & ~move_allow); 1997
2010 SET_MAP_MOVE_ON (m, x, y, move_on); 1998 s.flags = flags;
2011 SET_MAP_MOVE_OFF (m, x, y, move_off); 1999 s.move_block = move_block & ~move_allow;
2012 SET_MAP_MOVE_SLOW (m, x, y, move_slow); 2000 s.move_on = move_on;
2001 s.move_off = move_off;
2002 s.move_slow = move_slow;
2013 2003
2014 /* At this point, we have a floor face (if there is a floor), 2004 /* At this point, we have a floor face (if there is a floor),
2015 * and the floor is set - we are not going to touch it at 2005 * and the floor is set - we are not going to touch it at
2016 * this point. 2006 * this point.
2017 * middle contains the highest visibility face. 2007 * middle contains the highest visibility face.
2071 break; 2061 break;
2072 } 2062 }
2073 } 2063 }
2074 } 2064 }
2075 } 2065 }
2066
2076 if (middle == floor) 2067 if (middle == floor)
2077 middle = blank_face; 2068 middle = blank_face;
2069
2078 if (top == middle) 2070 if (top == middle)
2079 middle = blank_face; 2071 middle = blank_face;
2072
2080 SET_MAP_FACE (m, x, y, top, 0); 2073 SET_MAP_FACE (m, x, y, top, 0);
2081 if (top != blank_face) 2074 if (top != blank_face)
2082 SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); 2075 SET_MAP_FACE_OBJ (m, x, y, top_obj, 0);
2083 else 2076 else
2084 SET_MAP_FACE_OBJ (m, x, y, NULL, 0); 2077 SET_MAP_FACE_OBJ (m, x, y, NULL, 0);
2078
2085 SET_MAP_FACE (m, x, y, middle, 1); 2079 SET_MAP_FACE (m, x, y, middle, 1);
2086 if (middle != blank_face) 2080 if (middle != blank_face)
2087 SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); 2081 SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1);
2088 else 2082 else
2089 SET_MAP_FACE_OBJ (m, x, y, NULL, 1); 2083 SET_MAP_FACE_OBJ (m, x, y, NULL, 1);
2084
2090 SET_MAP_FACE (m, x, y, floor, 2); 2085 SET_MAP_FACE (m, x, y, floor, 2);
2091 if (floor != blank_face) 2086 if (floor != blank_face)
2092 SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); 2087 SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2);
2093 else 2088 else
2094 SET_MAP_FACE_OBJ (m, x, y, NULL, 2); 2089 SET_MAP_FACE_OBJ (m, x, y, NULL, 2);
2090
2095 SET_MAP_LIGHT (m, x, y, light); 2091 SET_MAP_LIGHT (m, x, y, light);
2096} 2092}
2097 2093
2098 2094
2099void 2095void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines