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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.98 by root, Sun Dec 31 17:17:22 2006 UTC vs.
Revision 1.107 by pippijn, Sat Jan 6 14:42:29 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
624 return; 625 return;
625 } 626 }
626 627
627 mapspace &m = op->ms (); 628 mapspace &m = op->ms ();
628 629
629 if (m.flags_ & P_NEED_UPDATE) 630 if (!(m.flags_ & P_UPTODATE))
630 /* nop */; 631 /* nop */;
631 else if (action == UP_OBJ_INSERT) 632 else if (action == UP_OBJ_INSERT)
632 { 633 {
633 // this is likely overkill, TODO: revisit (schmorp) 634 // this is likely overkill, TODO: revisit (schmorp)
634 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) 635 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW))
643 /* This isn't perfect, but I don't expect a lot of objects to 644 /* This isn't perfect, but I don't expect a lot of objects to
644 * to have move_allow right now. 645 * to have move_allow right now.
645 */ 646 */
646 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block 647 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block
647 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) 648 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp)
648 m.flags_ = P_NEED_UPDATE; 649 m.flags_ = 0;
649 } 650 }
650 /* if the object is being removed, we can't make intelligent 651 /* if the object is being removed, we can't make intelligent
651 * decisions, because remove_ob can't really pass the object 652 * decisions, because remove_ob can't really pass the object
652 * that is being removed. 653 * that is being removed.
653 */ 654 */
654 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 655 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
655 m.flags_ = P_NEED_UPDATE; 656 m.flags_ = 0;
656 else if (action == UP_OBJ_FACE) 657 else if (action == UP_OBJ_FACE)
657 /* Nothing to do for that case */ ; 658 /* Nothing to do for that case */ ;
658 else 659 else
659 LOG (llevError, "update_object called with invalid action: %d\n", action); 660 LOG (llevError, "update_object called with invalid action: %d\n", action);
660 661
733void 734void
734object::activate_recursive () 735object::activate_recursive ()
735{ 736{
736 activate (); 737 activate ();
737 738
738 for (object *op = inv; op; op = op->above) 739 for (object *op = inv; op; op = op->below)
739 op->activate_recursive (); 740 op->activate_recursive ();
740} 741}
741 742
742/* This function removes object 'op' from the list of active 743/* This function removes object 'op' from the list of active
743 * objects. 744 * objects.
772} 773}
773 774
774void 775void
775object::deactivate_recursive () 776object::deactivate_recursive ()
776{ 777{
777 for (object *op = inv; op; op = op->above) 778 for (object *op = inv; op; op = op->below)
778 op->deactivate_recursive (); 779 op->deactivate_recursive ();
779 780
780 deactivate (); 781 deactivate ();
782}
783
784void
785object::set_flag_inv (int flag, int value)
786{
787 for (object *op = inv; op; op = op->below)
788 {
789 op->flag [flag] = value;
790 op->set_flag_inv (flag, value);
791 }
781} 792}
782 793
783/* 794/*
784 * Remove and free all objects in the inventory of the given object. 795 * Remove and free all objects in the inventory of the given object.
785 * object.c ? 796 * object.c ?
870 freed_map->name = "/internal/freed_objects_map"; 881 freed_map->name = "/internal/freed_objects_map";
871 freed_map->width = 3; 882 freed_map->width = 3;
872 freed_map->height = 3; 883 freed_map->height = 3;
873 884
874 freed_map->alloc (); 885 freed_map->alloc ();
886 freed_map->in_memory = MAP_IN_MEMORY;
875 } 887 }
876 888
877 map = freed_map; 889 map = freed_map;
878 x = 1; 890 x = 1;
879 y = 1; 891 y = 1;
986 else if (map) 998 else if (map)
987 { 999 {
988 if (type == PLAYER) 1000 if (type == PLAYER)
989 { 1001 {
990 --map->players; 1002 --map->players;
991 map->last_access = runtime; 1003 map->touch ();
992 } 1004 }
993 1005
994 map->dirty = true; 1006 map->dirty = true;
995 1007
996 /* link the object above us */ 1008 /* link the object above us */
1072 } 1084 }
1073 1085
1074 /* last == NULL if there are no objects on this space */ 1086 /* last == NULL if there are no objects on this space */
1075 //TODO: this makes little sense, why only update the topmost object? 1087 //TODO: this makes little sense, why only update the topmost object?
1076 if (!last) 1088 if (!last)
1077 map->at (x, y).flags_ = P_NEED_UPDATE; 1089 map->at (x, y).flags_ = 0;
1078 else 1090 else
1079 update_object (last, UP_OBJ_REMOVE); 1091 update_object (last, UP_OBJ_REMOVE);
1080 1092
1081 if (flag [FLAG_BLOCKSVIEW] || glow_radius) 1093 if (flag [FLAG_BLOCKSVIEW] || glow_radius)
1082 update_all_los (map, x, y); 1094 update_all_los (map, x, y);
1203 { 1215 {
1204 /* The part may be on a different map. */ 1216 /* The part may be on a different map. */
1205 1217
1206 object *more = op->more; 1218 object *more = op->more;
1207 1219
1208 /* We really need the caller to normalize coordinates - if 1220 /* We really need the caller to normalise coordinates - if
1209 * we set the map, that doesn't work if the location is within 1221 * we set the map, that doesn't work if the location is within
1210 * a map and this is straddling an edge. So only if coordinate 1222 * a map and this is straddling an edge. So only if coordinate
1211 * is clear wrong do we normalize it. 1223 * is clear wrong do we normalise it.
1212 */ 1224 */
1213 if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) 1225 if (OUT_OF_REAL_MAP (more->map, more->x, more->y))
1214 more->map = get_map_from_coord (m, &more->x, &more->y); 1226 more->map = get_map_from_coord (m, &more->x, &more->y);
1215 else if (!more->map) 1227 else if (!more->map)
1216 { 1228 {
1376 1388
1377 if (op->type == PLAYER) 1389 if (op->type == PLAYER)
1378 { 1390 {
1379 op->contr->do_los = 1; 1391 op->contr->do_los = 1;
1380 ++op->map->players; 1392 ++op->map->players;
1381 op->map->last_access = runtime; 1393 op->map->touch ();
1382 } 1394 }
1383 1395
1384 op->map->dirty = true; 1396 op->map->dirty = true;
1385 1397
1386 /* If we have a floor, we know the player, if any, will be above 1398 /* If we have a floor, we know the player, if any, will be above
1395 * visible to others on this map. But update_all_los is really 1407 * visible to others on this map. But update_all_los is really
1396 * an inefficient way to do this, as it means los for all players 1408 * an inefficient way to do this, as it means los for all players
1397 * on the map will get recalculated. The players could very well 1409 * on the map will get recalculated. The players could very well
1398 * be far away from this change and not affected in any way - 1410 * be far away from this change and not affected in any way -
1399 * this should get redone to only look for players within range, 1411 * this should get redone to only look for players within range,
1400 * or just updating the P_NEED_UPDATE for spaces within this area 1412 * or just updating the P_UPTODATE for spaces within this area
1401 * of effect may be sufficient. 1413 * of effect may be sufficient.
1402 */ 1414 */
1403 if (op->map->darkness && (op->glow_radius != 0)) 1415 if (op->map->darkness && (op->glow_radius != 0))
1404 update_all_los (op->map, op->x, op->y); 1416 update_all_los (op->map, op->x, op->y);
1405 1417
1443{ 1455{
1444 object *tmp, *tmp1; 1456 object *tmp, *tmp1;
1445 1457
1446 /* first search for itself and remove any old instances */ 1458 /* first search for itself and remove any old instances */
1447 1459
1448 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1460 for (tmp = op->ms ().bot; tmp; tmp = tmp->above)
1449 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ 1461 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */
1450 tmp->destroy (); 1462 tmp->destroy ();
1451 1463
1452 tmp1 = arch_to_object (archetype::find (arch_string)); 1464 tmp1 = arch_to_object (archetype::find (arch_string));
1453 1465
1776 1788
1777 /* The objects have to be checked from top to bottom. 1789 /* The objects have to be checked from top to bottom.
1778 * Hence, we first go to the top: 1790 * Hence, we first go to the top:
1779 */ 1791 */
1780 1792
1781 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp && tmp->above; tmp = tmp->above) 1793 for (tmp = op->ms ().bot; tmp && tmp->above; tmp = tmp->above)
1782 { 1794 {
1783 /* Trim the search when we find the first other spell effect 1795 /* Trim the search when we find the first other spell effect
1784 * this helps performance so that if a space has 50 spell objects, 1796 * this helps performance so that if a space has 50 spell objects,
1785 * we don't need to check all of them. 1797 * we don't need to check all of them.
1786 */ 1798 */
1844 * The first matching object is returned, or NULL if none. 1856 * The first matching object is returned, or NULL if none.
1845 */ 1857 */
1846object * 1858object *
1847present_arch (const archetype *at, maptile *m, int x, int y) 1859present_arch (const archetype *at, maptile *m, int x, int y)
1848{ 1860{
1849 if (m == NULL || out_of_map (m, x, y)) 1861 if (!m || out_of_map (m, x, y))
1850 { 1862 {
1851 LOG (llevError, "Present_arch called outside map.\n"); 1863 LOG (llevError, "Present_arch called outside map.\n");
1852 return NULL; 1864 return NULL;
1853 } 1865 }
1854 1866
1855 for (object *tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1867 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1856 if (tmp->arch == at) 1868 if (tmp->arch == at)
1857 return tmp; 1869 return tmp;
1858 1870
1859 return NULL; 1871 return NULL;
1860} 1872}
1871 { 1883 {
1872 LOG (llevError, "Present called outside map.\n"); 1884 LOG (llevError, "Present called outside map.\n");
1873 return NULL; 1885 return NULL;
1874 } 1886 }
1875 1887
1876 for (object *tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1888 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1877 if (tmp->type == type) 1889 if (tmp->type == type)
1878 return tmp; 1890 return tmp;
1879 1891
1880 return NULL; 1892 return NULL;
1881} 1893}
2613object::flag_desc (char *desc, int len) const 2625object::flag_desc (char *desc, int len) const
2614{ 2626{
2615 char *p = desc; 2627 char *p = desc;
2616 bool first = true; 2628 bool first = true;
2617 2629
2630 *p = 0;
2631
2618 for (int i = 0; i < NUM_FLAGS; i++) 2632 for (int i = 0; i < NUM_FLAGS; i++)
2619 { 2633 {
2620 if (len <= 10) // magic constant! 2634 if (len <= 10) // magic constant!
2621 { 2635 {
2622 snprintf (p, len, ",..."); 2636 snprintf (p, len, ",...");
2623 break; 2637 break;
2624 } 2638 }
2625 2639
2626 if (flag[i]) 2640 if (flag [i])
2627 { 2641 {
2628 int cnt = snprintf (p, len, "%s%d", first ? "" : ",", i); 2642 int cnt = snprintf (p, len, "%s%d", first ? "" : ",", i);
2629 len -= cnt; 2643 len -= cnt;
2630 p += cnt; 2644 p += cnt;
2631 first = false; 2645 first = false;
2633 } 2647 }
2634 2648
2635 return desc; 2649 return desc;
2636} 2650}
2637 2651
2638// return a suitable string describing an objetc in enough detail to find it 2652// return a suitable string describing an object in enough detail to find it
2639const char * 2653const char *
2640object::debug_desc (char *info) const 2654object::debug_desc (char *info) const
2641{ 2655{
2642 char flagdesc[512]; 2656 char flagdesc[512];
2643 char info2[256 * 4]; 2657 char info2[256 * 4];
2660} 2674}
2661 2675
2662const char * 2676const char *
2663object::debug_desc () const 2677object::debug_desc () const
2664{ 2678{
2665 static char info[256 * 3]; 2679 static char info[256 * 4];
2666 return debug_desc (info); 2680 return debug_desc (info);
2667} 2681}
2668 2682

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines