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.96 by root, Sat Dec 30 10:16:10 2006 UTC vs.
Revision 1.106 by root, Wed Jan 3 20:08:04 2007 UTC

276 276
277 /* Note sure why the following is the case - either the object has to 277 /* Note sure why the following is the case - either the object has to
278 * be animated or have a very low speed. Is this an attempted monster 278 * be animated or have a very low speed. Is this an attempted monster
279 * check? 279 * check?
280 */ 280 */
281 if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) 281 if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && ob1->has_active_speed ())
282 return 0; 282 return 0;
283 283
284 switch (ob1->type) 284 switch (ob1->type)
285 { 285 {
286 case SCROLL: 286 case SCROLL:
563 speed = 0; 563 speed = 0;
564 } 564 }
565 565
566 this->speed = speed; 566 this->speed = speed;
567 567
568 if (FABS (speed) > MIN_ACTIVE_SPEED) 568 if (has_active_speed ())
569 { 569 activate ();
570 /* If already on active list, don't do anything */
571 if (active_next || active_prev || this == active_objects)
572 return;
573
574 /* process_events() expects us to insert the object at the beginning
575 * of the list. */
576 active_next = active_objects;
577
578 if (active_next)
579 active_next->active_prev = this;
580
581 active_objects = this;
582 }
583 else 570 else
584 { 571 deactivate ();
585 /* If not on the active list, nothing needs to be done */
586 if (!active_next && !active_prev && this != active_objects)
587 return;
588
589 if (!active_prev)
590 {
591 active_objects = active_next;
592
593 if (active_next)
594 active_next->active_prev = 0;
595 }
596 else
597 {
598 active_prev->active_next = active_next;
599
600 if (active_next)
601 active_next->active_prev = active_prev;
602 }
603
604 active_next = 0;
605 active_prev = 0;
606 }
607} 572}
608 573
609/* 574/*
610 * update_object() updates the the map. 575 * update_object() updates the the map.
611 * It takes into account invisible objects (and represent squares covered 576 * It takes into account invisible objects (and represent squares covered
659 return; 624 return;
660 } 625 }
661 626
662 mapspace &m = op->ms (); 627 mapspace &m = op->ms ();
663 628
664 if (m.flags_ & P_NEED_UPDATE) 629 if (!(m.flags_ & P_UPTODATE))
665 /* nop */; 630 /* nop */;
666 else if (action == UP_OBJ_INSERT) 631 else if (action == UP_OBJ_INSERT)
667 { 632 {
668 // this is likely overkill, TODO: revisit (schmorp) 633 // this is likely overkill, TODO: revisit (schmorp)
669 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) 634 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW))
678 /* This isn't perfect, but I don't expect a lot of objects to 643 /* This isn't perfect, but I don't expect a lot of objects to
679 * to have move_allow right now. 644 * to have move_allow right now.
680 */ 645 */
681 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block 646 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block
682 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) 647 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp)
683 m.flags_ = P_NEED_UPDATE; 648 m.flags_ = 0;
684 } 649 }
685 /* if the object is being removed, we can't make intelligent 650 /* if the object is being removed, we can't make intelligent
686 * decisions, because remove_ob can't really pass the object 651 * decisions, because remove_ob can't really pass the object
687 * that is being removed. 652 * that is being removed.
688 */ 653 */
689 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 654 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
690 m.flags_ = P_NEED_UPDATE; 655 m.flags_ = 0;
691 else if (action == UP_OBJ_FACE) 656 else if (action == UP_OBJ_FACE)
692 /* Nothing to do for that case */ ; 657 /* Nothing to do for that case */ ;
693 else 658 else
694 LOG (llevError, "update_object called with invalid action: %d\n", action); 659 LOG (llevError, "update_object called with invalid action: %d\n", action);
695 660
696 if (op->more) 661 if (op->more)
697 update_object (op->more, action); 662 update_object (op->more, action);
698} 663}
699 664
700object::vector object::objects; // not yet used
701object *object::first; 665object *object::first;
702 666
703object::object () 667object::object ()
704{ 668{
705 SET_FLAG (this, FLAG_REMOVED); 669 SET_FLAG (this, FLAG_REMOVED);
738 702
739 prev = 0; 703 prev = 0;
740 next = 0; 704 next = 0;
741} 705}
742 706
707bool
708object::active () const
709{
710 return active_next || active_prev || this == active_objects;
711}
712
743void 713void
714object::activate ()
715{
716 /* If already on active list, don't do anything */
717 if (active ())
718 return;
719
720 if (has_active_speed ())
721 {
722 /* process_events() expects us to insert the object at the beginning
723 * of the list. */
724 active_next = active_objects;
725
726 if (active_next)
727 active_next->active_prev = this;
728
729 active_objects = this;
730 }
731}
732
733void
744object::activate (bool recursive) 734object::activate_recursive ()
745{ 735{
746 // uh, hack 736 activate ();
747 set_speed (speed);
748 737
749 if (recursive)
750 for (object *op = inv; op; op = op->above) 738 for (object *op = inv; op; op = op->below)
751 op->activate (1); 739 op->activate_recursive ();
752} 740}
753 741
754/* This function removes object 'op' from the list of active 742/* This function removes object 'op' from the list of active
755 * objects. 743 * objects.
756 * This should only be used for style maps or other such 744 * This should only be used for style maps or other such
758 * in play chewing up cpu time getting processed. 746 * in play chewing up cpu time getting processed.
759 * The reverse of this is to call update_ob_speed, which 747 * The reverse of this is to call update_ob_speed, which
760 * will do the right thing based on the speed of the object. 748 * will do the right thing based on the speed of the object.
761 */ 749 */
762void 750void
763object::deactivate (bool recursive) 751object::deactivate ()
764{ 752{
765 /* If not on the active list, nothing needs to be done */ 753 /* If not on the active list, nothing needs to be done */
766 if (!active_next && !active_prev && this != active_objects) 754 if (!active ())
767 return; 755 return;
768 756
769 if (active_prev == 0) 757 if (active_prev == 0)
770 { 758 {
771 active_objects = active_next; 759 active_objects = active_next;
779 active_next->active_prev = active_prev; 767 active_next->active_prev = active_prev;
780 } 768 }
781 769
782 active_next = 0; 770 active_next = 0;
783 active_prev = 0; 771 active_prev = 0;
772}
784 773
785 if (recursive) 774void
775object::deactivate_recursive ()
776{
786 for (object *op = inv; op; op = op->above) 777 for (object *op = inv; op; op = op->below)
778 op->deactivate_recursive ();
779
787 op->deactivate (1); 780 deactivate ();
781}
782
783void
784object::set_flag_inv (int flag, int value)
785{
786 for (object *op = inv; op; op = op->below)
787 {
788 op->flag [flag] = value;
789 op->set_flag_inv (flag, value);
790 }
788} 791}
789 792
790/* 793/*
791 * Remove and free all objects in the inventory of the given object. 794 * Remove and free all objects in the inventory of the given object.
792 * object.c ? 795 * object.c ?
877 freed_map->name = "/internal/freed_objects_map"; 880 freed_map->name = "/internal/freed_objects_map";
878 freed_map->width = 3; 881 freed_map->width = 3;
879 freed_map->height = 3; 882 freed_map->height = 3;
880 883
881 freed_map->alloc (); 884 freed_map->alloc ();
885 freed_map->in_memory = MAP_IN_MEMORY;
882 } 886 }
883 887
884 map = freed_map; 888 map = freed_map;
885 x = 1; 889 x = 1;
886 y = 1; 890 y = 1;
993 else if (map) 997 else if (map)
994 { 998 {
995 if (type == PLAYER) 999 if (type == PLAYER)
996 { 1000 {
997 --map->players; 1001 --map->players;
998 map->last_access = runtime; 1002 map->touch ();
999 } 1003 }
1000 1004
1005 map->dirty = true;
1001 1006
1002 /* link the object above us */ 1007 /* link the object above us */
1003 if (above) 1008 if (above)
1004 above->below = below; 1009 above->below = below;
1005 else 1010 else
1078 } 1083 }
1079 1084
1080 /* last == NULL if there are no objects on this space */ 1085 /* last == NULL if there are no objects on this space */
1081 //TODO: this makes little sense, why only update the topmost object? 1086 //TODO: this makes little sense, why only update the topmost object?
1082 if (!last) 1087 if (!last)
1083 map->at (x, y).flags_ = P_NEED_UPDATE; 1088 map->at (x, y).flags_ = 0;
1084 else 1089 else
1085 update_object (last, UP_OBJ_REMOVE); 1090 update_object (last, UP_OBJ_REMOVE);
1086 1091
1087 if (flag [FLAG_BLOCKSVIEW] || glow_radius) 1092 if (flag [FLAG_BLOCKSVIEW] || glow_radius)
1088 update_all_los (map, x, y); 1093 update_all_los (map, x, y);
1209 { 1214 {
1210 /* The part may be on a different map. */ 1215 /* The part may be on a different map. */
1211 1216
1212 object *more = op->more; 1217 object *more = op->more;
1213 1218
1214 /* We really need the caller to normalize coordinates - if 1219 /* We really need the caller to normalise coordinates - if
1215 * we set the map, that doesn't work if the location is within 1220 * we set the map, that doesn't work if the location is within
1216 * a map and this is straddling an edge. So only if coordinate 1221 * a map and this is straddling an edge. So only if coordinate
1217 * is clear wrong do we normalize it. 1222 * is clear wrong do we normalise it.
1218 */ 1223 */
1219 if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) 1224 if (OUT_OF_REAL_MAP (more->map, more->x, more->y))
1220 more->map = get_map_from_coord (m, &more->x, &more->y); 1225 more->map = get_map_from_coord (m, &more->x, &more->y);
1221 else if (!more->map) 1226 else if (!more->map)
1222 { 1227 {
1382 1387
1383 if (op->type == PLAYER) 1388 if (op->type == PLAYER)
1384 { 1389 {
1385 op->contr->do_los = 1; 1390 op->contr->do_los = 1;
1386 ++op->map->players; 1391 ++op->map->players;
1387 op->map->last_access = runtime; 1392 op->map->touch ();
1388 } 1393 }
1394
1395 op->map->dirty = true;
1389 1396
1390 /* If we have a floor, we know the player, if any, will be above 1397 /* If we have a floor, we know the player, if any, will be above
1391 * it, so save a few ticks and start from there. 1398 * it, so save a few ticks and start from there.
1392 */ 1399 */
1393 if (!(flag & INS_MAP_LOAD)) 1400 if (!(flag & INS_MAP_LOAD))
1399 * visible to others on this map. But update_all_los is really 1406 * visible to others on this map. But update_all_los is really
1400 * an inefficient way to do this, as it means los for all players 1407 * an inefficient way to do this, as it means los for all players
1401 * on the map will get recalculated. The players could very well 1408 * on the map will get recalculated. The players could very well
1402 * be far away from this change and not affected in any way - 1409 * be far away from this change and not affected in any way -
1403 * this should get redone to only look for players within range, 1410 * this should get redone to only look for players within range,
1404 * or just updating the P_NEED_UPDATE for spaces within this area 1411 * or just updating the P_UPTODATE for spaces within this area
1405 * of effect may be sufficient. 1412 * of effect may be sufficient.
1406 */ 1413 */
1407 if (op->map->darkness && (op->glow_radius != 0)) 1414 if (op->map->darkness && (op->glow_radius != 0))
1408 update_all_los (op->map, op->x, op->y); 1415 update_all_los (op->map, op->x, op->y);
1409 1416
1447{ 1454{
1448 object *tmp, *tmp1; 1455 object *tmp, *tmp1;
1449 1456
1450 /* first search for itself and remove any old instances */ 1457 /* first search for itself and remove any old instances */
1451 1458
1452 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1459 for (tmp = op->ms ().bot; tmp; tmp = tmp->above)
1453 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ 1460 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */
1454 tmp->destroy (); 1461 tmp->destroy ();
1455 1462
1456 tmp1 = arch_to_object (archetype::find (arch_string)); 1463 tmp1 = arch_to_object (archetype::find (arch_string));
1457 1464
1780 1787
1781 /* The objects have to be checked from top to bottom. 1788 /* The objects have to be checked from top to bottom.
1782 * Hence, we first go to the top: 1789 * Hence, we first go to the top:
1783 */ 1790 */
1784 1791
1785 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp && tmp->above; tmp = tmp->above) 1792 for (tmp = op->ms ().bot; tmp && tmp->above; tmp = tmp->above)
1786 { 1793 {
1787 /* Trim the search when we find the first other spell effect 1794 /* Trim the search when we find the first other spell effect
1788 * this helps performance so that if a space has 50 spell objects, 1795 * this helps performance so that if a space has 50 spell objects,
1789 * we don't need to check all of them. 1796 * we don't need to check all of them.
1790 */ 1797 */
1848 * The first matching object is returned, or NULL if none. 1855 * The first matching object is returned, or NULL if none.
1849 */ 1856 */
1850object * 1857object *
1851present_arch (const archetype *at, maptile *m, int x, int y) 1858present_arch (const archetype *at, maptile *m, int x, int y)
1852{ 1859{
1853 if (m == NULL || out_of_map (m, x, y)) 1860 if (!m || out_of_map (m, x, y))
1854 { 1861 {
1855 LOG (llevError, "Present_arch called outside map.\n"); 1862 LOG (llevError, "Present_arch called outside map.\n");
1856 return NULL; 1863 return NULL;
1857 } 1864 }
1858 1865
1859 for (object *tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1866 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1860 if (tmp->arch == at) 1867 if (tmp->arch == at)
1861 return tmp; 1868 return tmp;
1862 1869
1863 return NULL; 1870 return NULL;
1864} 1871}
1875 { 1882 {
1876 LOG (llevError, "Present called outside map.\n"); 1883 LOG (llevError, "Present called outside map.\n");
1877 return NULL; 1884 return NULL;
1878 } 1885 }
1879 1886
1880 for (object *tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1887 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1881 if (tmp->type == type) 1888 if (tmp->type == type)
1882 return tmp; 1889 return tmp;
1883 1890
1884 return NULL; 1891 return NULL;
1885} 1892}
2610 } 2617 }
2611 else 2618 else
2612 item = item->env; 2619 item = item->env;
2613} 2620}
2614 2621
2622
2623const char *
2624object::flag_desc (char *desc, int len) const
2625{
2626 char *p = desc;
2627 bool first = true;
2628
2629 *p = 0;
2630
2631 for (int i = 0; i < NUM_FLAGS; i++)
2632 {
2633 if (len <= 10) // magic constant!
2634 {
2635 snprintf (p, len, ",...");
2636 break;
2637 }
2638
2639 if (flag [i])
2640 {
2641 int cnt = snprintf (p, len, "%s%d", first ? "" : ",", i);
2642 len -= cnt;
2643 p += cnt;
2644 first = false;
2645 }
2646 }
2647
2648 return desc;
2649}
2650
2615// return a suitable string describing an objetc in enough detail to find it 2651// return a suitable string describing an object in enough detail to find it
2616const char * 2652const char *
2617object::debug_desc (char *info) const 2653object::debug_desc (char *info) const
2618{ 2654{
2655 char flagdesc[512];
2619 char info2[256 * 3]; 2656 char info2[256 * 4];
2620 char *p = info; 2657 char *p = info;
2621 2658
2622 p += snprintf (p, 256, "%d=\"%s%s%s\"", 2659 p += snprintf (p, 512, "{cnt:%d,uuid:<1,%" PRIx64 ">,name:\"%s%s%s\",flags:[%s],type:%d}",
2623 count, 2660 count, uuid.seq,
2624 &name, 2661 &name,
2625 title ? " " : "", 2662 title ? "\",title:" : "",
2626 title ? (const char *)title : ""); 2663 title ? (const char *)title : "",
2664 flag_desc (flagdesc, 512), type);
2627 2665
2628 if (env) 2666 if (env)
2629 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2667 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2630 2668
2631 if (map) 2669 if (map)
2635} 2673}
2636 2674
2637const char * 2675const char *
2638object::debug_desc () const 2676object::debug_desc () const
2639{ 2677{
2640 static char info[256 * 3]; 2678 static char info[256 * 4];
2641 return debug_desc (info); 2679 return debug_desc (info);
2642} 2680}
2643 2681

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines