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.65 by root, Wed Dec 13 00:42:03 2006 UTC vs.
Revision 1.106 by root, Wed Jan 3 20:08:04 2007 UTC

29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/uio.h> 30#include <sys/uio.h>
31#include <object.h> 31#include <object.h>
32#include <funcpoint.h> 32#include <funcpoint.h>
33#include <loader.h> 33#include <loader.h>
34
35#include <bitset>
34 36
35int nrofallocobjects = 0; 37int nrofallocobjects = 0;
36static UUID uuid; 38static UUID uuid;
37const uint64 UUID_SKIP = 1<<19; 39const uint64 UUID_SKIP = 1<<19;
38 40
139 * objects with lists are rare, and lists stay short. If not, use a 141 * objects with lists are rare, and lists stay short. If not, use a
140 * different structure or at least keep the lists sorted... 142 * different structure or at least keep the lists sorted...
141 */ 143 */
142 144
143 /* For each field in wants, */ 145 /* For each field in wants, */
144 for (wants_field = wants->key_values; wants_field != NULL; wants_field = wants_field->next) 146 for (wants_field = wants->key_values; wants_field; wants_field = wants_field->next)
145 { 147 {
146 key_value *has_field; 148 key_value *has_field;
147 149
148 /* Look for a field in has with the same key. */ 150 /* Look for a field in has with the same key. */
149 has_field = get_ob_key_link (has, wants_field->key); 151 has_field = get_ob_key_link (has, wants_field->key);
183 * 185 *
184 * Note that this function appears a lot longer than the macro it 186 * Note that this function appears a lot longer than the macro it
185 * replaces - this is mostly for clarity - a decent compiler should hopefully 187 * replaces - this is mostly for clarity - a decent compiler should hopefully
186 * reduce this to the same efficiency. 188 * reduce this to the same efficiency.
187 * 189 *
188 * Check nrof variable *before* calling CAN_MERGE() 190 * Check nrof variable *before* calling can_merge()
189 * 191 *
190 * Improvements made with merge: Better checking on potion, and also 192 * Improvements made with merge: Better checking on potion, and also
191 * check weight 193 * check weight
192 */ 194 */
193
194bool object::can_merge (object *ob1, object *ob2) 195bool object::can_merge_slow (object *ob1, object *ob2)
195{ 196{
196 /* A couple quicksanity checks */ 197 /* A couple quicksanity checks */
197 if ((ob1 == ob2) || (ob1->type != ob2->type)) 198 if (ob1 == ob2
199 || ob1->type != ob2->type
200 || ob1->speed != ob2->speed
201 || ob1->value != ob2->value
202 || ob1->name != ob2->name)
198 return 0; 203 return 0;
199 204
200 if (ob1->speed != ob2->speed) 205 //TODO: this ain't working well, use nicer and correct overflow check
201 return 0;
202
203 /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that 206 /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that
204 * value could not be stored in a sint32 (which unfortunately sometimes is 207 * value could not be stored in a sint32 (which unfortunately sometimes is
205 * used to store nrof). 208 * used to store nrof).
206 */ 209 */
207 if (ob1->nrof + ob2->nrof >= 1UL << 31) 210 if (ob1->nrof + ob2->nrof >= 1UL << 31)
217 SET_FLAG (ob1, FLAG_BEEN_APPLIED); 220 SET_FLAG (ob1, FLAG_BEEN_APPLIED);
218 221
219 if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) 222 if (QUERY_FLAG (ob2, FLAG_IDENTIFIED))
220 SET_FLAG (ob2, FLAG_BEEN_APPLIED); 223 SET_FLAG (ob2, FLAG_BEEN_APPLIED);
221 224
222 225 if ((ob1->flag ^ ob2->flag).reset (FLAG_INV_LOCKED).reset (FLAG_CLIENT_SENT).any ()
223 /* the 0x400000 on flags2 is FLAG_INV_LOCK. I don't think something 226 || ob1->arch != ob2->arch
224 * being locked in inventory should prevent merging.
225 * 0x4 in flags3 is CLIENT_SENT
226 */
227 if ((ob1->arch != ob2->arch) ||
228 (ob1->flags[0] != ob2->flags[0]) ||
229 (ob1->flags[1] != ob2->flags[1]) ||
230 ((ob1->flags[2] & ~0x400000) != (ob2->flags[2] & ~0x400000)) ||
231 ((ob1->flags[3] & ~0x4) != (ob2->flags[3] & ~0x4)) ||
232 (ob1->name != ob2->name) || 227 || ob1->name != ob2->name
233 (ob1->title != ob2->title) || 228 || ob1->title != ob2->title
234 (ob1->msg != ob2->msg) || 229 || ob1->msg != ob2->msg
235 (ob1->weight != ob2->weight) || 230 || ob1->weight != ob2->weight
236 (memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) != 0) || 231 || memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist))
237 (memcmp (&ob1->stats, &ob2->stats, sizeof (ob1->stats)) != 0) || 232 || memcmp (&ob1->stats , &ob2->stats , sizeof (ob1->stats) )
238 (ob1->attacktype != ob2->attacktype) || 233 || ob1->attacktype != ob2->attacktype
239 (ob1->magic != ob2->magic) || 234 || ob1->magic != ob2->magic
240 (ob1->slaying != ob2->slaying) || 235 || ob1->slaying != ob2->slaying
241 (ob1->skill != ob2->skill) || 236 || ob1->skill != ob2->skill
242 (ob1->value != ob2->value) || 237 || ob1->value != ob2->value
243 (ob1->animation_id != ob2->animation_id) || 238 || ob1->animation_id != ob2->animation_id
244 (ob1->client_type != ob2->client_type) || 239 || ob1->client_type != ob2->client_type
245 (ob1->materialname != ob2->materialname) || 240 || ob1->materialname != ob2->materialname
246 (ob1->lore != ob2->lore) || 241 || ob1->lore != ob2->lore
247 (ob1->subtype != ob2->subtype) || 242 || ob1->subtype != ob2->subtype
248 (ob1->move_type != ob2->move_type) || 243 || ob1->move_type != ob2->move_type
249 (ob1->move_block != ob2->move_block) || 244 || ob1->move_block != ob2->move_block
250 (ob1->move_allow != ob2->move_allow) || 245 || ob1->move_allow != ob2->move_allow
251 (ob1->move_on != ob2->move_on) || 246 || ob1->move_on != ob2->move_on
252 (ob1->move_off != ob2->move_off) || (ob1->move_slow != ob2->move_slow) || (ob1->move_slow_penalty != ob2->move_slow_penalty)) 247 || ob1->move_off != ob2->move_off
248 || ob1->move_slow != ob2->move_slow
249 || ob1->move_slow_penalty != ob2->move_slow_penalty)
253 return 0; 250 return 0;
254 251
255 /* This is really a spellbook check - really, we should 252 /* This is really a spellbook check - really, we should
256 * check all objects in the inventory. 253 * check all objects in the inventory.
257 */ 254 */
260 /* if one object has inventory but the other doesn't, not equiv */ 257 /* if one object has inventory but the other doesn't, not equiv */
261 if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv)) 258 if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv))
262 return 0; 259 return 0;
263 260
264 /* Now check to see if the two inventory objects could merge */ 261 /* Now check to see if the two inventory objects could merge */
265 if (!CAN_MERGE (ob1->inv, ob2->inv)) 262 if (!object::can_merge (ob1->inv, ob2->inv))
266 return 0; 263 return 0;
267 264
268 /* inventory ok - still need to check rest of this object to see 265 /* inventory ok - still need to check rest of this object to see
269 * if it is valid. 266 * if it is valid.
270 */ 267 */
279 276
280 /* 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
281 * 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
282 * check? 279 * check?
283 */ 280 */
284 if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) 281 if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && ob1->has_active_speed ())
285 return 0; 282 return 0;
286 283
287 switch (ob1->type) 284 switch (ob1->type)
288 { 285 {
289 case SCROLL: 286 case SCROLL:
354 op = op->env; 351 op = op->env;
355 return op; 352 return op;
356} 353}
357 354
358/* 355/*
359 * Eneq(@csd.uu.se): Since we can have items buried in a character we need
360 * a better check. We basically keeping traversing up until we can't
361 * or find a player.
362 */
363
364object *
365is_player_inv (object *op)
366{
367 for (; op != NULL && op->type != PLAYER; op = op->env)
368 if (op->env == op)
369 op->env = NULL;
370 return op;
371}
372
373/*
374 * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. 356 * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump.
375 * Some error messages. 357 * Some error messages.
376 * The result of the dump is stored in the static global errmsg array. 358 * The result of the dump is stored in the static global errmsg array.
377 */ 359 */
378 360
381{ 363{
382 if (!op) 364 if (!op)
383 return strdup ("[NULLOBJ]"); 365 return strdup ("[NULLOBJ]");
384 366
385 object_freezer freezer; 367 object_freezer freezer;
386 save_object (freezer, op, 3); 368 save_object (freezer, op, 1);
387 return freezer.as_string (); 369 return freezer.as_string ();
388} 370}
389 371
390/* 372/*
391 * get_nearest_part(multi-object, object 2) returns the part of the 373 * get_nearest_part(multi-object, object 2) returns the part of the
484 } 466 }
485 467
486 op->key_values = 0; 468 op->key_values = 0;
487} 469}
488 470
489void object::clear ()
490{
491 attachable_base::clear ();
492
493 free_key_values (this);
494
495 owner = 0;
496 name = 0;
497 name_pl = 0;
498 title = 0;
499 race = 0;
500 slaying = 0;
501 skill = 0;
502 msg = 0;
503 lore = 0;
504 custom_name = 0;
505 materialname = 0;
506 contr = 0;
507 below = 0;
508 above = 0;
509 inv = 0;
510 container = 0;
511 env = 0;
512 more = 0;
513 head = 0;
514 map = 0;
515 active_next = 0;
516 active_prev = 0;
517
518 memset (static_cast<object_pod *>(this), 0, sizeof (object_pod));
519
520 SET_FLAG (this, FLAG_REMOVED);
521
522 /* What is not cleared is next, prev, and count */
523
524 expmul = 1.0;
525 face = blank_face;
526
527 if (settings.casting_time)
528 casting_time = -1;
529}
530
531/* 471/*
532 * copy_to first frees everything allocated by the dst object, 472 * copy_to first frees everything allocated by the dst object,
533 * and then copies the contents of itself into the second 473 * and then copies the contents of itself into the second
534 * object, allocating what needs to be allocated. Basically, any 474 * object, allocating what needs to be allocated. Basically, any
535 * data that is malloc'd needs to be re-malloc/copied. Otherwise, 475 * data that is malloc'd needs to be re-malloc/copied. Otherwise,
541{ 481{
542 bool is_freed = QUERY_FLAG (dst, FLAG_FREED); 482 bool is_freed = QUERY_FLAG (dst, FLAG_FREED);
543 bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); 483 bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED);
544 484
545 *(object_copy *)dst = *this; 485 *(object_copy *)dst = *this;
546 *(object_pod *)dst = *this;
547
548 if (self || cb)
549 INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
550 486
551 if (is_freed) 487 if (is_freed)
552 SET_FLAG (dst, FLAG_FREED); 488 SET_FLAG (dst, FLAG_FREED);
553 489
554 if (is_removed) 490 if (is_removed)
585 tail = new_link; 521 tail = new_link;
586 } 522 }
587 } 523 }
588 } 524 }
589 525
590 update_ob_speed (dst); 526 dst->set_speed (dst->speed);
591} 527}
592 528
593object * 529object *
594object::clone () 530object::clone ()
595{ 531{
601/* 537/*
602 * If an object with the IS_TURNABLE() flag needs to be turned due 538 * If an object with the IS_TURNABLE() flag needs to be turned due
603 * to the closest player being on the other side, this function can 539 * to the closest player being on the other side, this function can
604 * be called to update the face variable, _and_ how it looks on the map. 540 * be called to update the face variable, _and_ how it looks on the map.
605 */ 541 */
606
607void 542void
608update_turn_face (object *op) 543update_turn_face (object *op)
609{ 544{
610 if (!QUERY_FLAG (op, FLAG_IS_TURNABLE) || op->arch == NULL) 545 if (!QUERY_FLAG (op, FLAG_IS_TURNABLE) || !op->arch)
611 return; 546 return;
547
612 SET_ANIMATION (op, op->direction); 548 SET_ANIMATION (op, op->direction);
613 update_object (op, UP_OBJ_FACE); 549 update_object (op, UP_OBJ_FACE);
614} 550}
615 551
616/* 552/*
617 * Updates the speed of an object. If the speed changes from 0 to another 553 * Updates the speed of an object. If the speed changes from 0 to another
618 * value, or vice versa, then add/remove the object from the active list. 554 * value, or vice versa, then add/remove the object from the active list.
619 * This function needs to be called whenever the speed of an object changes. 555 * This function needs to be called whenever the speed of an object changes.
620 */ 556 */
621void 557void
622update_ob_speed (object *op) 558object::set_speed (float speed)
623{ 559{
624 extern int arch_init; 560 if (flag [FLAG_FREED] && speed)
625
626 /* No reason putting the archetypes objects on the speed list,
627 * since they never really need to be updated.
628 */
629
630 if (QUERY_FLAG (op, FLAG_FREED) && op->speed)
631 { 561 {
632 LOG (llevError, "Object %s is freed but has speed.\n", &op->name); 562 LOG (llevError, "Object %s is freed but has speed.\n", &name);
633#ifdef MANY_CORES
634 abort ();
635#else
636 op->speed = 0; 563 speed = 0;
637#endif
638 }
639
640 if (arch_init)
641 return;
642
643 if (FABS (op->speed) > MIN_ACTIVE_SPEED)
644 { 564 }
645 /* If already on active list, don't do anything */
646 if (op->active_next || op->active_prev || op == active_objects)
647 return;
648 565
649 /* process_events() expects us to insert the object at the beginning 566 this->speed = speed;
650 * of the list. */
651 op->active_next = active_objects;
652 567
653 if (op->active_next != NULL) 568 if (has_active_speed ())
654 op->active_next->active_prev = op; 569 activate ();
655
656 active_objects = op;
657 }
658 else 570 else
659 { 571 deactivate ();
660 /* If not on the active list, nothing needs to be done */
661 if (!op->active_next && !op->active_prev && op != active_objects)
662 return;
663
664 if (op->active_prev == NULL)
665 {
666 active_objects = op->active_next;
667
668 if (op->active_next != NULL)
669 op->active_next->active_prev = NULL;
670 }
671 else
672 {
673 op->active_prev->active_next = op->active_next;
674
675 if (op->active_next)
676 op->active_next->active_prev = op->active_prev;
677 }
678
679 op->active_next = NULL;
680 op->active_prev = NULL;
681 }
682} 572}
683 573
684/* This function removes object 'op' from the list of active
685 * objects.
686 * This should only be used for style maps or other such
687 * reference maps where you don't want an object that isn't
688 * in play chewing up cpu time getting processed.
689 * The reverse of this is to call update_ob_speed, which
690 * will do the right thing based on the speed of the object.
691 */
692void
693remove_from_active_list (object *op)
694{
695 /* If not on the active list, nothing needs to be done */
696 if (!op->active_next && !op->active_prev && op != active_objects)
697 return;
698
699 if (op->active_prev == NULL)
700 {
701 active_objects = op->active_next;
702 if (op->active_next != NULL)
703 op->active_next->active_prev = NULL;
704 }
705 else
706 {
707 op->active_prev->active_next = op->active_next;
708 if (op->active_next)
709 op->active_next->active_prev = op->active_prev;
710 }
711 op->active_next = NULL;
712 op->active_prev = NULL;
713}
714
715/* 574/*
716 * update_object() updates the array which represents the map. 575 * update_object() updates the the map.
717 * It takes into account invisible objects (and represent squares covered 576 * It takes into account invisible objects (and represent squares covered
718 * by invisible objects by whatever is below them (unless it's another 577 * by invisible objects by whatever is below them (unless it's another
719 * invisible object, etc...) 578 * invisible object, etc...)
720 * If the object being updated is beneath a player, the look-window 579 * If the object being updated is beneath a player, the look-window
721 * of that player is updated (this might be a suboptimal way of 580 * of that player is updated (this might be a suboptimal way of
722 * updating that window, though, since update_object() is called _often_) 581 * updating that window, though, since update_object() is called _often_)
723 * 582 *
724 * action is a hint of what the caller believes need to be done. 583 * action is a hint of what the caller believes need to be done.
725 * For example, if the only thing that has changed is the face (due to
726 * an animation), we don't need to call update_position until that actually
727 * comes into view of a player. OTOH, many other things, like addition/removal
728 * of walls or living creatures may need us to update the flags now.
729 * current action are: 584 * current action are:
730 * UP_OBJ_INSERT: op was inserted 585 * UP_OBJ_INSERT: op was inserted
731 * UP_OBJ_REMOVE: op was removed 586 * UP_OBJ_REMOVE: op was removed
732 * UP_OBJ_CHANGE: object has somehow changed. In this case, we always update 587 * UP_OBJ_CHANGE: object has somehow changed. In this case, we always update
733 * as that is easier than trying to look at what may have changed. 588 * as that is easier than trying to look at what may have changed.
734 * UP_OBJ_FACE: only the objects face has changed. 589 * UP_OBJ_FACE: only the objects face has changed.
735 */ 590 */
736
737void 591void
738update_object (object *op, int action) 592update_object (object *op, int action)
739{ 593{
740 int update_now = 0, flags;
741 MoveType move_on, move_off, move_block, move_slow; 594 MoveType move_on, move_off, move_block, move_slow;
742 595
743 if (op == NULL) 596 if (op == NULL)
744 { 597 {
745 /* this should never happen */ 598 /* this should never happen */
746 LOG (llevDebug, "update_object() called for NULL object.\n"); 599 LOG (llevDebug, "update_object() called for NULL object.\n");
747 return; 600 return;
748 } 601 }
749 602
750 if (op->env != NULL) 603 if (op->env)
751 { 604 {
752 /* Animation is currently handled by client, so nothing 605 /* Animation is currently handled by client, so nothing
753 * to do in this case. 606 * to do in this case.
754 */ 607 */
755 return; 608 return;
760 */ 613 */
761 if (!op->map || op->map->in_memory == MAP_SAVING) 614 if (!op->map || op->map->in_memory == MAP_SAVING)
762 return; 615 return;
763 616
764 /* make sure the object is within map boundaries */ 617 /* make sure the object is within map boundaries */
765 if (op->x < 0 || op->x >= MAP_WIDTH (op->map) || op->y < 0 || op->y >= MAP_HEIGHT (op->map)) 618 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height)
766 { 619 {
767 LOG (llevError, "update_object() called for object out of map!\n"); 620 LOG (llevError, "update_object() called for object out of map!\n");
768#ifdef MANY_CORES 621#ifdef MANY_CORES
769 abort (); 622 abort ();
770#endif 623#endif
771 return; 624 return;
772 } 625 }
773 626
774 flags = GET_MAP_FLAGS (op->map, op->x, op->y); 627 mapspace &m = op->ms ();
775 SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NEED_UPDATE);
776 move_slow = GET_MAP_MOVE_SLOW (op->map, op->x, op->y);
777 move_on = GET_MAP_MOVE_ON (op->map, op->x, op->y);
778 move_block = GET_MAP_MOVE_BLOCK (op->map, op->x, op->y);
779 move_off = GET_MAP_MOVE_OFF (op->map, op->x, op->y);
780 628
629 if (!(m.flags_ & P_UPTODATE))
630 /* nop */;
781 if (action == UP_OBJ_INSERT) 631 else if (action == UP_OBJ_INSERT)
782 { 632 {
633 // this is likely overkill, TODO: revisit (schmorp)
783 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(flags & P_BLOCKSVIEW)) 634 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW))
784 update_now = 1;
785
786 if (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(flags & P_NO_MAGIC)) 635 || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC))
787 update_now = 1; 636 || (op->type == PLAYER && !(m.flags_ & P_PLAYER))
788 637 || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE))
638 || (QUERY_FLAG (op, FLAG_ALIVE) && !(m.flags_ & P_IS_ALIVE))
789 if (QUERY_FLAG (op, FLAG_DAMNED) && !(flags & P_NO_CLERIC)) 639 || (QUERY_FLAG (op, FLAG_DAMNED) && !(m.flags_ & P_NO_CLERIC))
790 update_now = 1;
791
792 if (QUERY_FLAG (op, FLAG_ALIVE) && !(flags & P_IS_ALIVE))
793 update_now = 1;
794
795 if (op->type == SAFE_GROUND && !(flags & P_SAFE))
796 update_now = 1;
797
798 if ((move_on | op->move_on) != move_on) 640 || (m.move_on | op->move_on ) != m.move_on
799 update_now = 1;
800
801 if ((move_off | op->move_off) != move_off) 641 || (m.move_off | op->move_off ) != m.move_off
802 update_now = 1; 642 || (m.move_slow | op->move_slow) != m.move_slow
803
804 /* 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
805 * to have move_allow right now. 644 * to have move_allow right now.
806 */ 645 */
807 if (((move_block | op->move_block) & ~op->move_allow) != move_block) 646 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block
808 update_now = 1; 647 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp)
809 648 m.flags_ = 0;
810 if ((move_slow | op->move_slow) != move_slow)
811 update_now = 1;
812 } 649 }
813
814 /* if the object is being removed, we can't make intelligent 650 /* if the object is being removed, we can't make intelligent
815 * decisions, because remove_ob can't really pass the object 651 * decisions, because remove_ob can't really pass the object
816 * that is being removed. 652 * that is being removed.
817 */ 653 */
818 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 654 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
819 update_now = 1; 655 m.flags_ = 0;
820 else if (action == UP_OBJ_FACE) 656 else if (action == UP_OBJ_FACE)
821 /* Nothing to do for that case */ ; 657 /* Nothing to do for that case */ ;
822 else 658 else
823 LOG (llevError, "update_object called with invalid action: %d\n", action); 659 LOG (llevError, "update_object called with invalid action: %d\n", action);
824 660
825 if (update_now)
826 {
827 SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE);
828 update_position (op->map, op->x, op->y);
829 }
830
831 if (op->more != NULL) 661 if (op->more)
832 update_object (op->more, action); 662 update_object (op->more, action);
833} 663}
834 664
835object::vector object::mortals;
836object::vector object::objects; // not yet used
837object *object::first; 665object *object::first;
838
839void object::free_mortals ()
840{
841 for (AUTODECL (i, mortals.begin ()); i != mortals.end ();)
842 if ((*i)->refcnt)
843 ++i; // further delay freeing
844 else
845 {
846 delete *i;
847 mortals.erase (i);
848 }
849}
850 666
851object::object () 667object::object ()
852{ 668{
853 SET_FLAG (this, FLAG_REMOVED); 669 SET_FLAG (this, FLAG_REMOVED);
854 670
886 702
887 prev = 0; 703 prev = 0;
888 next = 0; 704 next = 0;
889} 705}
890 706
707bool
708object::active () const
709{
710 return active_next || active_prev || this == active_objects;
711}
712
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
734object::activate_recursive ()
735{
736 activate ();
737
738 for (object *op = inv; op; op = op->below)
739 op->activate_recursive ();
740}
741
742/* This function removes object 'op' from the list of active
743 * objects.
744 * This should only be used for style maps or other such
745 * reference maps where you don't want an object that isn't
746 * in play chewing up cpu time getting processed.
747 * The reverse of this is to call update_ob_speed, which
748 * will do the right thing based on the speed of the object.
749 */
750void
751object::deactivate ()
752{
753 /* If not on the active list, nothing needs to be done */
754 if (!active ())
755 return;
756
757 if (active_prev == 0)
758 {
759 active_objects = active_next;
760 if (active_next)
761 active_next->active_prev = 0;
762 }
763 else
764 {
765 active_prev->active_next = active_next;
766 if (active_next)
767 active_next->active_prev = active_prev;
768 }
769
770 active_next = 0;
771 active_prev = 0;
772}
773
774void
775object::deactivate_recursive ()
776{
777 for (object *op = inv; op; op = op->below)
778 op->deactivate_recursive ();
779
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 }
791}
792
793/*
794 * Remove and free all objects in the inventory of the given object.
795 * object.c ?
796 */
797void
798object::destroy_inv (bool drop_to_ground)
799{
800 // need to check first, because the checks below might segfault
801 // as we might be on an invalid mapspace and crossfire code
802 // is too buggy to ensure that the inventory is empty.
803 // corollary: if you create arrows etc. with stuff in tis inventory,
804 // cf will crash below with off-map x and y
805 if (!inv)
806 return;
807
808 /* Only if the space blocks everything do we not process -
809 * if some form of movement is allowed, let objects
810 * drop on that space.
811 */
812 if (!drop_to_ground
813 || !map
814 || map->in_memory != MAP_IN_MEMORY
815 || ms ().move_block == MOVE_ALL)
816 {
817 while (inv)
818 {
819 inv->destroy_inv (drop_to_ground);
820 inv->destroy ();
821 }
822 }
823 else
824 { /* Put objects in inventory onto this space */
825 while (inv)
826 {
827 object *op = inv;
828
829 if (op->flag [FLAG_STARTEQUIP]
830 || op->flag [FLAG_NO_DROP]
831 || op->type == RUNE
832 || op->type == TRAP
833 || op->flag [FLAG_IS_A_TEMPLATE])
834 op->destroy ();
835 else
836 map->insert (op, x, y);
837 }
838 }
839}
840
891object *object::create () 841object *object::create ()
892{ 842{
893 object *op = new object; 843 object *op = new object;
894 op->link (); 844 op->link ();
895 return op; 845 return op;
896} 846}
897 847
898/* 848void
899 * free_object() frees everything allocated by an object, removes 849object::do_destroy ()
900 * it from the list of used objects, and puts it on the list of
901 * free objects. The IS_FREED() flag is set in the object.
902 * The object must have been removed by remove_ob() first for
903 * this function to succeed.
904 *
905 * If destroy_inventory is set, free inventory as well. Else drop items in
906 * inventory to the ground.
907 */
908void object::destroy (bool destroy_inventory)
909{ 850{
910 if (QUERY_FLAG (this, FLAG_FREED)) 851 if (flag [FLAG_IS_LINKED])
852 remove_button_link (this);
853
854 if (flag [FLAG_FRIENDLY])
855 remove_friendly_object (this);
856
857 if (!flag [FLAG_REMOVED])
858 remove ();
859
860 if (flag [FLAG_FREED])
911 return; 861 return;
912 862
913 if (QUERY_FLAG (this, FLAG_FRIENDLY)) 863 set_speed (0);
914 remove_friendly_object (this);
915 864
916 if (!QUERY_FLAG (this, FLAG_REMOVED)) 865 flag [FLAG_FREED] = 1;
917 remove ();
918 866
919 SET_FLAG (this, FLAG_FREED); 867 attachable::do_destroy ();
920 868
921 if (more) 869 destroy_inv (true);
922 { 870 unlink ();
923 more->destroy (destroy_inventory);
924 more = 0;
925 }
926
927 if (inv)
928 {
929 /* Only if the space blocks everything do we not process -
930 * if some form of movement is allowed, let objects
931 * drop on that space.
932 */
933 if (destroy_inventory || !map || map->in_memory != MAP_IN_MEMORY || GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)
934 {
935 object *op = inv;
936
937 while (op)
938 {
939 object *tmp = op->below;
940 op->destroy (destroy_inventory);
941 op = tmp;
942 }
943 }
944 else
945 { /* Put objects in inventory onto this space */
946 object *op = inv;
947
948 while (op)
949 {
950 object *tmp = op->below;
951
952 op->remove ();
953
954 if (QUERY_FLAG (op, FLAG_STARTEQUIP)
955 || QUERY_FLAG (op, FLAG_NO_DROP) || op->type == RUNE || op->type == TRAP || QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
956 op->destroy ();
957 else
958 {
959 op->x = x;
960 op->y = y;
961 insert_ob_in_map (op, map, 0, 0); /* Insert in same map as the envir */
962 }
963
964 op = tmp;
965 }
966 }
967 }
968 871
969 // hack to ensure that freed objects still have a valid map 872 // hack to ensure that freed objects still have a valid map
970 { 873 {
971 static maptile *freed_map; // freed objects are moved here to avoid crashes 874 static maptile *freed_map; // freed objects are moved here to avoid crashes
972 875
976 879
977 freed_map->name = "/internal/freed_objects_map"; 880 freed_map->name = "/internal/freed_objects_map";
978 freed_map->width = 3; 881 freed_map->width = 3;
979 freed_map->height = 3; 882 freed_map->height = 3;
980 883
981 freed_map->allocate (); 884 freed_map->alloc ();
885 freed_map->in_memory = MAP_IN_MEMORY;
982 } 886 }
983 887
984 map = freed_map; 888 map = freed_map;
985 x = 1; 889 x = 1;
986 y = 1; 890 y = 1;
987 } 891 }
988 892
893 head = 0;
894
895 if (more)
896 {
897 more->destroy ();
898 more = 0;
899 }
900
989 // clear those pointers that likely might have circular references to us 901 // clear those pointers that likely might have circular references to us
990 owner = 0; 902 owner = 0;
991 enemy = 0; 903 enemy = 0;
992 attacked_by = 0; 904 attacked_by = 0;
993 905
994 // only relevant for players(?), but make sure of it anyways 906 // only relevant for players(?), but make sure of it anyways
995 contr = 0; 907 contr = 0;
908}
996 909
997 /* Remove object from the active list */ 910void
998 speed = 0; 911object::destroy (bool destroy_inventory)
999 update_ob_speed (this); 912{
913 if (destroyed ())
914 return;
1000 915
1001 unlink (); 916 if (destroy_inventory)
917 destroy_inv (false);
1002 918
1003 mortals.push_back (this); 919 attachable::destroy ();
1004} 920}
1005 921
1006/* 922/*
1007 * sub_weight() recursively (outwards) subtracts a number from the 923 * sub_weight() recursively (outwards) subtracts a number from the
1008 * weight of an object (and what is carried by it's environment(s)). 924 * weight of an object (and what is carried by it's environment(s)).
1032object::remove () 948object::remove ()
1033{ 949{
1034 object *tmp, *last = 0; 950 object *tmp, *last = 0;
1035 object *otmp; 951 object *otmp;
1036 952
1037 int check_walk_off;
1038
1039 if (QUERY_FLAG (this, FLAG_REMOVED)) 953 if (QUERY_FLAG (this, FLAG_REMOVED))
1040 return; 954 return;
1041 955
1042 SET_FLAG (this, FLAG_REMOVED); 956 SET_FLAG (this, FLAG_REMOVED);
957 INVOKE_OBJECT (REMOVE, this);
1043 958
1044 if (more) 959 if (more)
1045 more->remove (); 960 more->remove ();
1046 961
1047 /* 962 /*
1057 972
1058 /* NO_FIX_PLAYER is set when a great many changes are being 973 /* NO_FIX_PLAYER is set when a great many changes are being
1059 * made to players inventory. If set, avoiding the call 974 * made to players inventory. If set, avoiding the call
1060 * to save cpu time. 975 * to save cpu time.
1061 */ 976 */
1062 if ((otmp = is_player_inv (env)) != NULL && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 977 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER))
1063 fix_player (otmp); 978 otmp->update_stats ();
1064 979
1065 if (above != NULL) 980 if (above)
1066 above->below = below; 981 above->below = below;
1067 else 982 else
1068 env->inv = below; 983 env->inv = below;
1069 984
1070 if (below != NULL) 985 if (below)
1071 below->above = above; 986 below->above = above;
1072 987
1073 /* we set up values so that it could be inserted into 988 /* we set up values so that it could be inserted into
1074 * the map, but we don't actually do that - it is up 989 * the map, but we don't actually do that - it is up
1075 * to the caller to decide what we want to do. 990 * to the caller to decide what we want to do.
1079 above = 0, below = 0; 994 above = 0, below = 0;
1080 env = 0; 995 env = 0;
1081 } 996 }
1082 else if (map) 997 else if (map)
1083 { 998 {
1084 /* Re did the following section of code - it looks like it had 999 if (type == PLAYER)
1085 * lots of logic for things we no longer care about
1086 */ 1000 {
1001 --map->players;
1002 map->touch ();
1003 }
1004
1005 map->dirty = true;
1087 1006
1088 /* link the object above us */ 1007 /* link the object above us */
1089 if (above) 1008 if (above)
1090 above->below = below; 1009 above->below = below;
1091 else 1010 else
1092 SET_MAP_TOP (map, x, y, below); /* we were top, set new top */ 1011 map->at (x, y).top = below; /* we were top, set new top */
1093 1012
1094 /* Relink the object below us, if there is one */ 1013 /* Relink the object below us, if there is one */
1095 if (below) 1014 if (below)
1096 below->above = above; 1015 below->above = above;
1097 else 1016 else
1109 dump = dump_object (GET_MAP_OB (map, x, y)); 1028 dump = dump_object (GET_MAP_OB (map, x, y));
1110 LOG (llevError, "%s\n", dump); 1029 LOG (llevError, "%s\n", dump);
1111 free (dump); 1030 free (dump);
1112 } 1031 }
1113 1032
1114 SET_MAP_OB (map, x, y, above); /* goes on above it. */ 1033 map->at (x, y).bot = above; /* goes on above it. */
1115 } 1034 }
1116 1035
1117 above = 0; 1036 above = 0;
1118 below = 0; 1037 below = 0;
1119 1038
1120 if (map->in_memory == MAP_SAVING) 1039 if (map->in_memory == MAP_SAVING)
1121 return; 1040 return;
1122 1041
1123 check_walk_off = !QUERY_FLAG (this, FLAG_NO_APPLY); 1042 int check_walk_off = !flag [FLAG_NO_APPLY];
1124 1043
1125 for (tmp = GET_MAP_OB (map, x, y); tmp; tmp = tmp->above) 1044 for (tmp = map->at (x, y).bot; tmp; tmp = tmp->above)
1126 { 1045 {
1127 /* No point updating the players look faces if he is the object 1046 /* No point updating the players look faces if he is the object
1128 * being removed. 1047 * being removed.
1129 */ 1048 */
1130 1049
1134 * removed (most likely destroyed), update the player view 1053 * removed (most likely destroyed), update the player view
1135 * appropriately. 1054 * appropriately.
1136 */ 1055 */
1137 if (tmp->container == this) 1056 if (tmp->container == this)
1138 { 1057 {
1139 CLEAR_FLAG (this, FLAG_APPLIED); 1058 flag [FLAG_APPLIED] = 0;
1140 tmp->container = 0; 1059 tmp->container = 0;
1141 } 1060 }
1142 1061
1143 tmp->contr->socket.update_look = 1; 1062 if (tmp->contr->ns)
1063 tmp->contr->ns->floorbox_update ();
1144 } 1064 }
1145 1065
1146 /* See if player moving off should effect something */ 1066 /* See if object moving off should effect something */
1147 if (check_walk_off 1067 if (check_walk_off
1148 && ((move_type & tmp->move_off) 1068 && ((move_type & tmp->move_off)
1149 && (move_type & ~tmp->move_off & ~tmp->move_block) == 0)) 1069 && (move_type & ~tmp->move_off & ~tmp->move_block) == 0))
1150 { 1070 {
1151 move_apply (tmp, this, 0); 1071 move_apply (tmp, this, 0);
1153 if (destroyed ()) 1073 if (destroyed ())
1154 LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); 1074 LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ());
1155 } 1075 }
1156 1076
1157 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ 1077 /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */
1158 1078 //TODO: why is this horrible hacka fix? get rid of this code=bug! (schmorp)
1159 if (tmp->above == tmp) 1079 if (tmp->above == tmp)
1160 tmp->above = 0; 1080 tmp->above = 0;
1161 1081
1162 last = tmp; 1082 last = tmp;
1163 } 1083 }
1164 1084
1165 /* last == NULL of there are no objects on this space */ 1085 /* last == NULL if there are no objects on this space */
1086 //TODO: this makes little sense, why only update the topmost object?
1166 if (!last) 1087 if (!last)
1167 { 1088 map->at (x, y).flags_ = 0;
1168 /* set P_NEED_UPDATE, otherwise update_position will complain. In theory,
1169 * we could preserve the flags (GET_MAP_FLAGS), but update_position figures
1170 * those out anyways, and if there are any flags set right now, they won't
1171 * be correct anyways.
1172 */
1173 SET_MAP_FLAGS (map, x, y, P_NEED_UPDATE);
1174 update_position (map, x, y);
1175 }
1176 else 1089 else
1177 update_object (last, UP_OBJ_REMOVE); 1090 update_object (last, UP_OBJ_REMOVE);
1178 1091
1179 if (QUERY_FLAG (this, FLAG_BLOCKSVIEW) || glow_radius) 1092 if (flag [FLAG_BLOCKSVIEW] || glow_radius)
1180 update_all_los (map, x, y); 1093 update_all_los (map, x, y);
1181 } 1094 }
1182} 1095}
1183 1096
1184/* 1097/*
1193merge_ob (object *op, object *top) 1106merge_ob (object *op, object *top)
1194{ 1107{
1195 if (!op->nrof) 1108 if (!op->nrof)
1196 return 0; 1109 return 0;
1197 1110
1198 if (top == NULL) 1111 if (top)
1199 for (top = op; top != NULL && top->above != NULL; top = top->above); 1112 for (top = op; top && top->above; top = top->above)
1113 ;
1200 1114
1201 for (; top != NULL; top = top->below) 1115 for (; top; top = top->below)
1202 { 1116 {
1203 if (top == op) 1117 if (top == op)
1204 continue; 1118 continue;
1205 if (CAN_MERGE (op, top)) 1119
1120 if (object::can_merge (op, top))
1206 { 1121 {
1207 top->nrof += op->nrof; 1122 top->nrof += op->nrof;
1208 1123
1209/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/ 1124/* CLEAR_FLAG(top,FLAG_STARTEQUIP);*/
1210 op->weight = 0; /* Don't want any adjustements now */ 1125 op->weight = 0; /* Don't want any adjustements now */
1221 * job preparing multi-part monsters 1136 * job preparing multi-part monsters
1222 */ 1137 */
1223object * 1138object *
1224insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y) 1139insert_ob_in_map_at (object *op, maptile *m, object *originator, int flag, int x, int y)
1225{ 1140{
1226 object *tmp;
1227
1228 if (op->head)
1229 op = op->head;
1230
1231 for (tmp = op; tmp; tmp = tmp->more) 1141 for (object *tmp = op->head_ (); tmp; tmp = tmp->more)
1232 { 1142 {
1233 tmp->x = x + tmp->arch->clone.x; 1143 tmp->x = x + tmp->arch->clone.x;
1234 tmp->y = y + tmp->arch->clone.y; 1144 tmp->y = y + tmp->arch->clone.y;
1235 } 1145 }
1236 1146
1255 * Return value: 1165 * Return value:
1256 * new object if 'op' was merged with other object 1166 * new object if 'op' was merged with other object
1257 * NULL if 'op' was destroyed 1167 * NULL if 'op' was destroyed
1258 * just 'op' otherwise 1168 * just 'op' otherwise
1259 */ 1169 */
1260
1261object * 1170object *
1262insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1171insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1263{ 1172{
1264 object *tmp, *top, *floor = NULL; 1173 object *tmp, *top, *floor = NULL;
1265 sint16 x, y; 1174 sint16 x, y;
1268 { 1177 {
1269 LOG (llevError, "Trying to insert freed object!\n"); 1178 LOG (llevError, "Trying to insert freed object!\n");
1270 return NULL; 1179 return NULL;
1271 } 1180 }
1272 1181
1273 if (m == NULL) 1182 if (!m)
1274 { 1183 {
1275 char *dump = dump_object (op); 1184 char *dump = dump_object (op);
1276 LOG (llevError, "Trying to insert in null-map!\n%s\n", dump); 1185 LOG (llevError, "Trying to insert in null-map!\n%s\n", dump);
1277 free (dump); 1186 free (dump);
1278 return op; 1187 return op;
1299 LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", dump); 1208 LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", dump);
1300 free (dump); 1209 free (dump);
1301 return op; 1210 return op;
1302 } 1211 }
1303 1212
1304 if (op->more != NULL) 1213 if (op->more)
1305 { 1214 {
1306 /* The part may be on a different map. */ 1215 /* The part may be on a different map. */
1307 1216
1308 object *more = op->more; 1217 object *more = op->more;
1309 1218
1310 /* We really need the caller to normalize coordinates - if 1219 /* We really need the caller to normalise coordinates - if
1311 * 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
1312 * 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
1313 * is clear wrong do we normalize it. 1222 * is clear wrong do we normalise it.
1314 */ 1223 */
1315 if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) 1224 if (OUT_OF_REAL_MAP (more->map, more->x, more->y))
1316 more->map = get_map_from_coord (m, &more->x, &more->y); 1225 more->map = get_map_from_coord (m, &more->x, &more->y);
1317 else if (!more->map) 1226 else if (!more->map)
1318 { 1227 {
1325 if (insert_ob_in_map (more, more->map, originator, flag) == NULL) 1234 if (insert_ob_in_map (more, more->map, originator, flag) == NULL)
1326 { 1235 {
1327 if (!op->head) 1236 if (!op->head)
1328 LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n"); 1237 LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n");
1329 1238
1330 return NULL; 1239 return 0;
1331 } 1240 }
1332 } 1241 }
1333 1242
1334 CLEAR_FLAG (op, FLAG_REMOVED); 1243 CLEAR_FLAG (op, FLAG_REMOVED);
1335 1244
1342 y = op->y; 1251 y = op->y;
1343 1252
1344 /* this has to be done after we translate the coordinates. 1253 /* this has to be done after we translate the coordinates.
1345 */ 1254 */
1346 if (op->nrof && !(flag & INS_NO_MERGE)) 1255 if (op->nrof && !(flag & INS_NO_MERGE))
1347 for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) 1256 for (tmp = GET_MAP_OB (op->map, x, y); tmp; tmp = tmp->above)
1348 if (CAN_MERGE (op, tmp)) 1257 if (object::can_merge (op, tmp))
1349 { 1258 {
1350 op->nrof += tmp->nrof; 1259 op->nrof += tmp->nrof;
1351 tmp->destroy (); 1260 tmp->destroy ();
1352 } 1261 }
1353 1262
1369 op->below = originator->below; 1278 op->below = originator->below;
1370 1279
1371 if (op->below) 1280 if (op->below)
1372 op->below->above = op; 1281 op->below->above = op;
1373 else 1282 else
1374 SET_MAP_OB (op->map, op->x, op->y, op); 1283 op->ms ().bot = op;
1375 1284
1376 /* since *below* originator, no need to update top */ 1285 /* since *below* originator, no need to update top */
1377 originator->below = op; 1286 originator->below = op;
1378 } 1287 }
1379 else 1288 else
1380 { 1289 {
1381 /* If there are other objects, then */ 1290 /* If there are other objects, then */
1382 if ((!(flag & INS_MAP_LOAD)) && ((top = GET_MAP_OB (op->map, op->x, op->y)) != NULL)) 1291 if ((!(flag & INS_MAP_LOAD)) && ((top = GET_MAP_OB (op->map, op->x, op->y)) != NULL))
1383 { 1292 {
1384 object *last = NULL; 1293 object *last = 0;
1385 1294
1386 /* 1295 /*
1387 * If there are multiple objects on this space, we do some trickier handling. 1296 * If there are multiple objects on this space, we do some trickier handling.
1388 * We've already dealt with merging if appropriate. 1297 * We've already dealt with merging if appropriate.
1389 * Generally, we want to put the new object on top. But if 1298 * Generally, we want to put the new object on top. But if
1393 * once we get to them. This reduces the need to traverse over all of 1302 * once we get to them. This reduces the need to traverse over all of
1394 * them when adding another one - this saves quite a bit of cpu time 1303 * them when adding another one - this saves quite a bit of cpu time
1395 * when lots of spells are cast in one area. Currently, it is presumed 1304 * when lots of spells are cast in one area. Currently, it is presumed
1396 * that flying non pickable objects are spell objects. 1305 * that flying non pickable objects are spell objects.
1397 */ 1306 */
1398
1399 while (top != NULL) 1307 while (top)
1400 { 1308 {
1401 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) 1309 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR))
1402 floor = top; 1310 floor = top;
1403 1311
1404 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) 1312 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR))
1425 * If INS_ON_TOP is used, don't do this processing 1333 * If INS_ON_TOP is used, don't do this processing
1426 * Need to find the object that in fact blocks view, otherwise 1334 * Need to find the object that in fact blocks view, otherwise
1427 * stacking is a bit odd. 1335 * stacking is a bit odd.
1428 */ 1336 */
1429 if (!(flag & INS_ON_TOP) && 1337 if (!(flag & INS_ON_TOP) &&
1430 (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_BLOCKSVIEW) && (op->face && !op->face->visibility)) 1338 (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_BLOCKSVIEW) && (op->face && !op->face->visibility))
1431 { 1339 {
1432 for (last = top; last != floor; last = last->below) 1340 for (last = top; last != floor; last = last->below)
1433 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) 1341 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT))
1434 break; 1342 break;
1435 /* Check to see if we found the object that blocks view, 1343 /* Check to see if we found the object that blocks view,
1457 op->above = GET_MAP_OB (op->map, op->x, op->y); 1365 op->above = GET_MAP_OB (op->map, op->x, op->y);
1458 1366
1459 if (op->above) 1367 if (op->above)
1460 op->above->below = op; 1368 op->above->below = op;
1461 1369
1462 op->below = NULL; 1370 op->below = 0;
1463 SET_MAP_OB (op->map, op->x, op->y, op); 1371 op->ms ().bot = op;
1464 } 1372 }
1465 else 1373 else
1466 { /* get inserted into the stack above top */ 1374 { /* get inserted into the stack above top */
1467 op->above = top->above; 1375 op->above = top->above;
1468 1376
1471 1379
1472 op->below = top; 1380 op->below = top;
1473 top->above = op; 1381 top->above = op;
1474 } 1382 }
1475 1383
1476 if (op->above == NULL) 1384 if (!op->above)
1477 SET_MAP_TOP (op->map, op->x, op->y, op); 1385 op->ms ().top = op;
1478 } /* else not INS_BELOW_ORIGINATOR */ 1386 } /* else not INS_BELOW_ORIGINATOR */
1479 1387
1480 if (op->type == PLAYER) 1388 if (op->type == PLAYER)
1389 {
1481 op->contr->do_los = 1; 1390 op->contr->do_los = 1;
1391 ++op->map->players;
1392 op->map->touch ();
1393 }
1394
1395 op->map->dirty = true;
1482 1396
1483 /* 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
1484 * it, so save a few ticks and start from there. 1398 * it, so save a few ticks and start from there.
1485 */ 1399 */
1486 if (!(flag & INS_MAP_LOAD)) 1400 if (!(flag & INS_MAP_LOAD))
1487 for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1401 if (object *pl = op->ms ().player ())
1488 if (tmp->type == PLAYER) 1402 if (pl->contr->ns)
1489 tmp->contr->socket.update_look = 1; 1403 pl->contr->ns->floorbox_update ();
1490 1404
1491 /* If this object glows, it may affect lighting conditions that are 1405 /* If this object glows, it may affect lighting conditions that are
1492 * 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
1493 * 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
1494 * on the map will get recalculated. The players could very well 1408 * on the map will get recalculated. The players could very well
1495 * 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 -
1496 * this should get redone to only look for players within range, 1410 * this should get redone to only look for players within range,
1497 * or just updating the P_NEED_UPDATE for spaces within this area 1411 * or just updating the P_UPTODATE for spaces within this area
1498 * of effect may be sufficient. 1412 * of effect may be sufficient.
1499 */ 1413 */
1500 if (MAP_DARKNESS (op->map) && (op->glow_radius != 0)) 1414 if (op->map->darkness && (op->glow_radius != 0))
1501 update_all_los (op->map, op->x, op->y); 1415 update_all_los (op->map, op->x, op->y);
1502 1416
1503 /* updates flags (blocked, alive, no magic, etc) for this map space */ 1417 /* updates flags (blocked, alive, no magic, etc) for this map space */
1504 update_object (op, UP_OBJ_INSERT); 1418 update_object (op, UP_OBJ_INSERT);
1505 1419
1420 INVOKE_OBJECT (INSERT, op);
1421
1506 /* Don't know if moving this to the end will break anything. However, 1422 /* Don't know if moving this to the end will break anything. However,
1507 * we want to have update_look set above before calling this. 1423 * we want to have floorbox_update called before calling this.
1508 * 1424 *
1509 * check_move_on() must be after this because code called from 1425 * check_move_on() must be after this because code called from
1510 * check_move_on() depends on correct map flags (so functions like 1426 * check_move_on() depends on correct map flags (so functions like
1511 * blocked() and wall() work properly), and these flags are updated by 1427 * blocked() and wall() work properly), and these flags are updated by
1512 * update_object(). 1428 * update_object().
1514 1430
1515 /* if this is not the head or flag has been passed, don't check walk on status */ 1431 /* if this is not the head or flag has been passed, don't check walk on status */
1516 if (!(flag & INS_NO_WALK_ON) && !op->head) 1432 if (!(flag & INS_NO_WALK_ON) && !op->head)
1517 { 1433 {
1518 if (check_move_on (op, originator)) 1434 if (check_move_on (op, originator))
1519 return NULL; 1435 return 0;
1520 1436
1521 /* If we are a multi part object, lets work our way through the check 1437 /* If we are a multi part object, lets work our way through the check
1522 * walk on's. 1438 * walk on's.
1523 */ 1439 */
1524 for (tmp = op->more; tmp != NULL; tmp = tmp->more) 1440 for (tmp = op->more; tmp != NULL; tmp = tmp->more)
1525 if (check_move_on (tmp, originator)) 1441 if (check_move_on (tmp, originator))
1526 return NULL; 1442 return 0;
1527 } 1443 }
1528 1444
1529 return op; 1445 return op;
1530} 1446}
1531 1447
1532/* this function inserts an object in the map, but if it 1448/* this function inserts an object in the map, but if it
1533 * finds an object of its own type, it'll remove that one first. 1449 * finds an object of its own type, it'll remove that one first.
1534 * op is the object to insert it under: supplies x and the map. 1450 * op is the object to insert it under: supplies x and the map.
1535 */ 1451 */
1536void 1452void
1537replace_insert_ob_in_map (const char *arch_string, object *op) 1453replace_insert_ob_in_map (const char *arch_string, object *op)
1538{ 1454{
1539 object * 1455 object *tmp, *tmp1;
1540 tmp;
1541 object *
1542 tmp1;
1543 1456
1544 /* first search for itself and remove any old instances */ 1457 /* first search for itself and remove any old instances */
1545 1458
1546 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)
1547 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ 1460 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */
1548 tmp->destroy (); 1461 tmp->destroy ();
1549 1462
1550 tmp1 = arch_to_object (archetype::find (arch_string)); 1463 tmp1 = arch_to_object (archetype::find (arch_string));
1551 1464
1552 tmp1->x = op->x; 1465 tmp1->x = op->x;
1553 tmp1->y = op->y; 1466 tmp1->y = op->y;
1554 insert_ob_in_map (tmp1, op->map, op, 0); 1467 insert_ob_in_map (tmp1, op->map, op, 0);
1468}
1469
1470object *
1471object::insert_at (object *where, object *originator, int flags)
1472{
1473 where->map->insert (this, where->x, where->y, originator, flags);
1555} 1474}
1556 1475
1557/* 1476/*
1558 * get_split_ob(ob,nr) splits up ob into two parts. The part which 1477 * get_split_ob(ob,nr) splits up ob into two parts. The part which
1559 * is returned contains nr objects, and the remaining parts contains 1478 * is returned contains nr objects, and the remaining parts contains
1560 * the rest (or is removed and freed if that number is 0). 1479 * the rest (or is removed and freed if that number is 0).
1561 * On failure, NULL is returned, and the reason put into the 1480 * On failure, NULL is returned, and the reason put into the
1562 * global static errmsg array. 1481 * global static errmsg array.
1563 */ 1482 */
1564
1565object * 1483object *
1566get_split_ob (object *orig_ob, uint32 nr) 1484get_split_ob (object *orig_ob, uint32 nr)
1567{ 1485{
1568 object *newob; 1486 object *newob;
1569 int is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0); 1487 int is_removed = (QUERY_FLAG (orig_ob, FLAG_REMOVED) != 0);
1605 1523
1606object * 1524object *
1607decrease_ob_nr (object *op, uint32 i) 1525decrease_ob_nr (object *op, uint32 i)
1608{ 1526{
1609 object *tmp; 1527 object *tmp;
1610 player *pl;
1611 1528
1612 if (i == 0) /* objects with op->nrof require this check */ 1529 if (i == 0) /* objects with op->nrof require this check */
1613 return op; 1530 return op;
1614 1531
1615 if (i > op->nrof) 1532 if (i > op->nrof)
1616 i = op->nrof; 1533 i = op->nrof;
1617 1534
1618 if (QUERY_FLAG (op, FLAG_REMOVED)) 1535 if (QUERY_FLAG (op, FLAG_REMOVED))
1619 op->nrof -= i; 1536 op->nrof -= i;
1620 else if (op->env != NULL) 1537 else if (op->env)
1621 { 1538 {
1622 /* is this object in the players inventory, or sub container 1539 /* is this object in the players inventory, or sub container
1623 * therein? 1540 * therein?
1624 */ 1541 */
1625 tmp = is_player_inv (op->env); 1542 tmp = op->in_player ();
1626 /* nope. Is this a container the player has opened? 1543 /* nope. Is this a container the player has opened?
1627 * If so, set tmp to that player. 1544 * If so, set tmp to that player.
1628 * IMO, searching through all the players will mostly 1545 * IMO, searching through all the players will mostly
1629 * likely be quicker than following op->env to the map, 1546 * likely be quicker than following op->env to the map,
1630 * and then searching the map for a player. 1547 * and then searching the map for a player.
1631 */ 1548 */
1632 if (!tmp) 1549 if (!tmp)
1633 { 1550 for_all_players (pl)
1634 for (pl = first_player; pl; pl = pl->next)
1635 if (pl->ob->container == op->env) 1551 if (pl->ob->container == op->env)
1552 {
1553 tmp = pl->ob;
1636 break; 1554 break;
1637 if (pl)
1638 tmp = pl->ob;
1639 else
1640 tmp = NULL;
1641 } 1555 }
1642 1556
1643 if (i < op->nrof) 1557 if (i < op->nrof)
1644 { 1558 {
1645 sub_weight (op->env, op->weight * i); 1559 sub_weight (op->env, op->weight * i);
1646 op->nrof -= i; 1560 op->nrof -= i;
1647 if (tmp) 1561 if (tmp)
1648 {
1649 esrv_send_item (tmp, op); 1562 esrv_send_item (tmp, op);
1650 }
1651 } 1563 }
1652 else 1564 else
1653 { 1565 {
1654 op->remove (); 1566 op->remove ();
1655 op->nrof = 0; 1567 op->nrof = 0;
1656 if (tmp) 1568 if (tmp)
1657 {
1658 esrv_del_item (tmp->contr, op->count); 1569 esrv_del_item (tmp->contr, op->count);
1659 }
1660 } 1570 }
1661 } 1571 }
1662 else 1572 else
1663 { 1573 {
1664 object *above = op->above; 1574 object *above = op->above;
1670 op->remove (); 1580 op->remove ();
1671 op->nrof = 0; 1581 op->nrof = 0;
1672 } 1582 }
1673 1583
1674 /* Since we just removed op, op->above is null */ 1584 /* Since we just removed op, op->above is null */
1675 for (tmp = above; tmp != NULL; tmp = tmp->above) 1585 for (tmp = above; tmp; tmp = tmp->above)
1676 if (tmp->type == PLAYER) 1586 if (tmp->type == PLAYER)
1677 { 1587 {
1678 if (op->nrof) 1588 if (op->nrof)
1679 esrv_send_item (tmp, op); 1589 esrv_send_item (tmp, op);
1680 else 1590 else
1685 if (op->nrof) 1595 if (op->nrof)
1686 return op; 1596 return op;
1687 else 1597 else
1688 { 1598 {
1689 op->destroy (); 1599 op->destroy ();
1690 return NULL; 1600 return 0;
1691 } 1601 }
1692} 1602}
1693 1603
1694/* 1604/*
1695 * add_weight(object, weight) adds the specified weight to an object, 1605 * add_weight(object, weight) adds the specified weight to an object,
1755 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); 1665 CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL);
1756 CLEAR_FLAG (op, FLAG_REMOVED); 1666 CLEAR_FLAG (op, FLAG_REMOVED);
1757 if (op->nrof) 1667 if (op->nrof)
1758 { 1668 {
1759 for (tmp = inv; tmp != NULL; tmp = tmp->below) 1669 for (tmp = inv; tmp != NULL; tmp = tmp->below)
1760 if (CAN_MERGE (tmp, op)) 1670 if (object::can_merge (tmp, op))
1761 { 1671 {
1762 /* return the original object and remove inserted object 1672 /* return the original object and remove inserted object
1763 (client needs the original object) */ 1673 (client needs the original object) */
1764 tmp->nrof += op->nrof; 1674 tmp->nrof += op->nrof;
1765 /* Weight handling gets pretty funky. Since we are adding to 1675 /* Weight handling gets pretty funky. Since we are adding to
1783 add_weight (this, op->weight * op->nrof); 1693 add_weight (this, op->weight * op->nrof);
1784 } 1694 }
1785 else 1695 else
1786 add_weight (this, (op->weight + op->carrying)); 1696 add_weight (this, (op->weight + op->carrying));
1787 1697
1788 otmp = is_player_inv (this); 1698 otmp = this->in_player ();
1789 if (otmp && otmp->contr) 1699 if (otmp && otmp->contr)
1790 if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1700 if (!QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER))
1791 fix_player (otmp); 1701 otmp->update_stats ();
1792 1702
1793 op->map = NULL; 1703 op->map = 0;
1794 op->env = this; 1704 op->env = this;
1795 op->above = NULL; 1705 op->above = 0;
1796 op->below = NULL; 1706 op->below = 0;
1797 op->x = 0, op->y = 0; 1707 op->x = 0, op->y = 0;
1798 1708
1799 /* reset the light list and los of the players on the map */ 1709 /* reset the light list and los of the players on the map */
1800 if ((op->glow_radius != 0) && map) 1710 if ((op->glow_radius != 0) && map)
1801 { 1711 {
1802#ifdef DEBUG_LIGHTS 1712#ifdef DEBUG_LIGHTS
1803 LOG (llevDebug, " insert_ob_in_ob(): got %s to insert in map/op\n", op->name); 1713 LOG (llevDebug, " insert_ob_in_ob(): got %s to insert in map/op\n", op->name);
1804#endif /* DEBUG_LIGHTS */ 1714#endif /* DEBUG_LIGHTS */
1805 if (MAP_DARKNESS (map)) 1715 if (map->darkness)
1806 update_all_los (map, x, y); 1716 update_all_los (map, x, y);
1807 } 1717 }
1808 1718
1809 /* Client has no idea of ordering so lets not bother ordering it here. 1719 /* Client has no idea of ordering so lets not bother ordering it here.
1810 * It sure simplifies this function... 1720 * It sure simplifies this function...
1815 { 1725 {
1816 op->below = inv; 1726 op->below = inv;
1817 op->below->above = op; 1727 op->below->above = op;
1818 inv = op; 1728 inv = op;
1819 } 1729 }
1730
1731 INVOKE_OBJECT (INSERT, this);
1820 1732
1821 return op; 1733 return op;
1822} 1734}
1823 1735
1824/* 1736/*
1839 * 1751 *
1840 * MSW 2001-07-08: Check all objects on space, not just those below 1752 * MSW 2001-07-08: Check all objects on space, not just those below
1841 * object being inserted. insert_ob_in_map may not put new objects 1753 * object being inserted. insert_ob_in_map may not put new objects
1842 * on top. 1754 * on top.
1843 */ 1755 */
1844
1845int 1756int
1846check_move_on (object *op, object *originator) 1757check_move_on (object *op, object *originator)
1847{ 1758{
1848 object *tmp; 1759 object *tmp;
1849 maptile *m = op->map; 1760 maptile *m = op->map;
1876 1787
1877 /* The objects have to be checked from top to bottom. 1788 /* The objects have to be checked from top to bottom.
1878 * Hence, we first go to the top: 1789 * Hence, we first go to the top:
1879 */ 1790 */
1880 1791
1881 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && tmp->above != NULL; tmp = tmp->above) 1792 for (tmp = op->ms ().bot; tmp && tmp->above; tmp = tmp->above)
1882 { 1793 {
1883 /* Trim the search when we find the first other spell effect 1794 /* Trim the search when we find the first other spell effect
1884 * 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,
1885 * we don't need to check all of them. 1796 * we don't need to check all of them.
1886 */ 1797 */
1941/* 1852/*
1942 * present_arch(arch, map, x, y) searches for any objects with 1853 * present_arch(arch, map, x, y) searches for any objects with
1943 * a matching archetype at the given map and coordinates. 1854 * a matching archetype at the given map and coordinates.
1944 * The first matching object is returned, or NULL if none. 1855 * The first matching object is returned, or NULL if none.
1945 */ 1856 */
1946
1947object * 1857object *
1948present_arch (const archetype *at, maptile *m, int x, int y) 1858present_arch (const archetype *at, maptile *m, int x, int y)
1949{ 1859{
1950 object *
1951 tmp;
1952
1953 if (m == NULL || out_of_map (m, x, y)) 1860 if (!m || out_of_map (m, x, y))
1954 { 1861 {
1955 LOG (llevError, "Present_arch called outside map.\n"); 1862 LOG (llevError, "Present_arch called outside map.\n");
1956 return NULL; 1863 return NULL;
1957 } 1864 }
1958 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1865
1866 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1959 if (tmp->arch == at) 1867 if (tmp->arch == at)
1960 return tmp; 1868 return tmp;
1869
1961 return NULL; 1870 return NULL;
1962} 1871}
1963 1872
1964/* 1873/*
1965 * present(type, map, x, y) searches for any objects with 1874 * present(type, map, x, y) searches for any objects with
1966 * a matching type variable at the given map and coordinates. 1875 * a matching type variable at the given map and coordinates.
1967 * The first matching object is returned, or NULL if none. 1876 * The first matching object is returned, or NULL if none.
1968 */ 1877 */
1969
1970object * 1878object *
1971present (unsigned char type, maptile *m, int x, int y) 1879present (unsigned char type, maptile *m, int x, int y)
1972{ 1880{
1973 object *
1974 tmp;
1975
1976 if (out_of_map (m, x, y)) 1881 if (out_of_map (m, x, y))
1977 { 1882 {
1978 LOG (llevError, "Present called outside map.\n"); 1883 LOG (llevError, "Present called outside map.\n");
1979 return NULL; 1884 return NULL;
1980 } 1885 }
1981 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1886
1887 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1982 if (tmp->type == type) 1888 if (tmp->type == type)
1983 return tmp; 1889 return tmp;
1890
1984 return NULL; 1891 return NULL;
1985} 1892}
1986 1893
1987/* 1894/*
1988 * present_in_ob(type, object) searches for any objects with 1895 * present_in_ob(type, object) searches for any objects with
1989 * a matching type variable in the inventory of the given object. 1896 * a matching type variable in the inventory of the given object.
1990 * The first matching object is returned, or NULL if none. 1897 * The first matching object is returned, or NULL if none.
1991 */ 1898 */
1992
1993object * 1899object *
1994present_in_ob (unsigned char type, const object *op) 1900present_in_ob (unsigned char type, const object *op)
1995{ 1901{
1996 object *
1997 tmp;
1998
1999 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1902 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below)
2000 if (tmp->type == type) 1903 if (tmp->type == type)
2001 return tmp; 1904 return tmp;
1905
2002 return NULL; 1906 return NULL;
2003} 1907}
2004 1908
2005/* 1909/*
2006 * present_in_ob (type, str, object) searches for any objects with 1910 * present_in_ob (type, str, object) searches for any objects with
2014 * str is the string to match against. Note that we match against 1918 * str is the string to match against. Note that we match against
2015 * the object name, not the archetype name. this is so that the 1919 * the object name, not the archetype name. this is so that the
2016 * spell code can use one object type (force), but change it's name 1920 * spell code can use one object type (force), but change it's name
2017 * to be unique. 1921 * to be unique.
2018 */ 1922 */
2019
2020object * 1923object *
2021present_in_ob_by_name (int type, const char *str, const object *op) 1924present_in_ob_by_name (int type, const char *str, const object *op)
2022{ 1925{
2023 object *
2024 tmp;
2025
2026 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1926 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2027 {
2028 if ((type == -1 || tmp->type == type) && (!strcmp (str, tmp->name))) 1927 if ((type == -1 || tmp->type == type) && (!strcmp (str, tmp->name)))
2029 return tmp; 1928 return tmp;
2030 } 1929
2031 return NULL; 1930 return 0;
2032} 1931}
2033 1932
2034/* 1933/*
2035 * present_arch_in_ob(archetype, object) searches for any objects with 1934 * present_arch_in_ob(archetype, object) searches for any objects with
2036 * a matching archetype in the inventory of the given object. 1935 * a matching archetype in the inventory of the given object.
2037 * The first matching object is returned, or NULL if none. 1936 * The first matching object is returned, or NULL if none.
2038 */ 1937 */
2039
2040object * 1938object *
2041present_arch_in_ob (const archetype *at, const object *op) 1939present_arch_in_ob (const archetype *at, const object *op)
2042{ 1940{
2043 object *
2044 tmp;
2045
2046 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1941 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below)
2047 if (tmp->arch == at) 1942 if (tmp->arch == at)
2048 return tmp; 1943 return tmp;
1944
2049 return NULL; 1945 return NULL;
2050} 1946}
2051 1947
2052/* 1948/*
2053 * activate recursively a flag on an object inventory 1949 * activate recursively a flag on an object inventory
2054 */ 1950 */
2055void 1951void
2056flag_inv (object *op, int flag) 1952flag_inv (object *op, int flag)
2057{ 1953{
2058 object *
2059 tmp;
2060
2061 if (op->inv) 1954 if (op->inv)
2062 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1955 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below)
2063 { 1956 {
2064 SET_FLAG (tmp, flag); 1957 SET_FLAG (tmp, flag);
2065 flag_inv (tmp, flag); 1958 flag_inv (tmp, flag);
2066 } 1959 }
2067} /* 1960}
1961
1962/*
2068 * desactivate recursively a flag on an object inventory 1963 * deactivate recursively a flag on an object inventory
2069 */ 1964 */
2070void 1965void
2071unflag_inv (object *op, int flag) 1966unflag_inv (object *op, int flag)
2072{ 1967{
2073 object *
2074 tmp;
2075
2076 if (op->inv) 1968 if (op->inv)
2077 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1969 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below)
2078 { 1970 {
2079 CLEAR_FLAG (tmp, flag); 1971 CLEAR_FLAG (tmp, flag);
2080 unflag_inv (tmp, flag); 1972 unflag_inv (tmp, flag);
2081 } 1973 }
2082} 1974}
2085 * set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in 1977 * set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in
2086 * all it's inventory (recursively). 1978 * all it's inventory (recursively).
2087 * If checksums are used, a player will get set_cheat called for 1979 * If checksums are used, a player will get set_cheat called for
2088 * him/her-self and all object carried by a call to this function. 1980 * him/her-self and all object carried by a call to this function.
2089 */ 1981 */
2090
2091void 1982void
2092set_cheat (object *op) 1983set_cheat (object *op)
2093{ 1984{
2094 SET_FLAG (op, FLAG_WAS_WIZ); 1985 SET_FLAG (op, FLAG_WAS_WIZ);
2095 flag_inv (op, FLAG_WAS_WIZ); 1986 flag_inv (op, FLAG_WAS_WIZ);
2114 * because arch_blocked (now ob_blocked) needs to know the movement type 2005 * because arch_blocked (now ob_blocked) needs to know the movement type
2115 * to know if the space in question will block the object. We can't use 2006 * to know if the space in question will block the object. We can't use
2116 * the archetype because that isn't correct if the monster has been 2007 * the archetype because that isn't correct if the monster has been
2117 * customized, changed states, etc. 2008 * customized, changed states, etc.
2118 */ 2009 */
2119
2120int 2010int
2121find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) 2011find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop)
2122{ 2012{
2123 int
2124 i,
2125 index = 0, flag; 2013 int index = 0, flag;
2126 static int
2127 altern[SIZEOFFREE]; 2014 int altern[SIZEOFFREE];
2128 2015
2129 for (i = start; i < stop; i++) 2016 for (int i = start; i < stop; i++)
2130 { 2017 {
2131 flag = ob_blocked (ob, m, x + freearr_x[i], y + freearr_y[i]); 2018 flag = ob_blocked (ob, m, x + freearr_x[i], y + freearr_y[i]);
2132 if (!flag) 2019 if (!flag)
2133 altern[index++] = i; 2020 altern [index++] = i;
2134 2021
2135 /* Basically, if we find a wall on a space, we cut down the search size. 2022 /* Basically, if we find a wall on a space, we cut down the search size.
2136 * In this way, we won't return spaces that are on another side of a wall. 2023 * In this way, we won't return spaces that are on another side of a wall.
2137 * This mostly work, but it cuts down the search size in all directions - 2024 * This mostly work, but it cuts down the search size in all directions -
2138 * if the space being examined only has a wall to the north and empty 2025 * if the space being examined only has a wall to the north and empty
2139 * spaces in all the other directions, this will reduce the search space 2026 * spaces in all the other directions, this will reduce the search space
2140 * to only the spaces immediately surrounding the target area, and 2027 * to only the spaces immediately surrounding the target area, and
2141 * won't look 2 spaces south of the target space. 2028 * won't look 2 spaces south of the target space.
2142 */ 2029 */
2143 else if ((flag & AB_NO_PASS) && maxfree[i] < stop) 2030 else if ((flag & P_NO_PASS) && maxfree[i] < stop)
2144 stop = maxfree[i]; 2031 stop = maxfree[i];
2145 } 2032 }
2033
2146 if (!index) 2034 if (!index)
2147 return -1; 2035 return -1;
2036
2148 return altern[RANDOM () % index]; 2037 return altern[RANDOM () % index];
2149} 2038}
2150 2039
2151/* 2040/*
2152 * find_first_free_spot(archetype, maptile, x, y) works like 2041 * find_first_free_spot(archetype, maptile, x, y) works like
2153 * find_free_spot(), but it will search max number of squares. 2042 * find_free_spot(), but it will search max number of squares.
2154 * But it will return the first available spot, not a random choice. 2043 * But it will return the first available spot, not a random choice.
2155 * Changed 0.93.2: Have it return -1 if there is no free spot available. 2044 * Changed 0.93.2: Have it return -1 if there is no free spot available.
2156 */ 2045 */
2157
2158int 2046int
2159find_first_free_spot (const object *ob, maptile *m, int x, int y) 2047find_first_free_spot (const object *ob, maptile *m, int x, int y)
2160{ 2048{
2161 int
2162 i;
2163
2164 for (i = 0; i < SIZEOFFREE; i++) 2049 for (int i = 0; i < SIZEOFFREE; i++)
2165 {
2166 if (!ob_blocked (ob, m, x + freearr_x[i], y + freearr_y[i])) 2050 if (!ob_blocked (ob, m, x + freearr_x[i], y + freearr_y[i]))
2167 return i; 2051 return i;
2168 } 2052
2169 return -1; 2053 return -1;
2170} 2054}
2171 2055
2172/* 2056/*
2173 * The function permute(arr, begin, end) randomly reorders the array 2057 * The function permute(arr, begin, end) randomly reorders the array
2174 * arr[begin..end-1]. 2058 * arr[begin..end-1].
2059 * now uses a fisher-yates shuffle, old permute was broken
2175 */ 2060 */
2176static void 2061static void
2177permute (int *arr, int begin, int end) 2062permute (int *arr, int begin, int end)
2178{ 2063{
2179 int 2064 arr += begin;
2180 i,
2181 j,
2182 tmp,
2183 len;
2184
2185 len = end - begin; 2065 end -= begin;
2186 for (i = begin; i < end; i++)
2187 {
2188 j = begin + RANDOM () % len;
2189 2066
2190 tmp = arr[i]; 2067 while (--end)
2191 arr[i] = arr[j]; 2068 swap (arr [end], arr [RANDOM () % (end + 1)]);
2192 arr[j] = tmp;
2193 }
2194} 2069}
2195 2070
2196/* new function to make monster searching more efficient, and effective! 2071/* new function to make monster searching more efficient, and effective!
2197 * This basically returns a randomized array (in the passed pointer) of 2072 * This basically returns a randomized array (in the passed pointer) of
2198 * the spaces to find monsters. In this way, it won't always look for 2073 * the spaces to find monsters. In this way, it won't always look for
2201 * the 3x3 area will be searched, just not in a predictable order. 2076 * the 3x3 area will be searched, just not in a predictable order.
2202 */ 2077 */
2203void 2078void
2204get_search_arr (int *search_arr) 2079get_search_arr (int *search_arr)
2205{ 2080{
2206 int 2081 int i;
2207 i;
2208 2082
2209 for (i = 0; i < SIZEOFFREE; i++) 2083 for (i = 0; i < SIZEOFFREE; i++)
2210 {
2211 search_arr[i] = i; 2084 search_arr[i] = i;
2212 }
2213 2085
2214 permute (search_arr, 1, SIZEOFFREE1 + 1); 2086 permute (search_arr, 1, SIZEOFFREE1 + 1);
2215 permute (search_arr, SIZEOFFREE1 + 1, SIZEOFFREE2 + 1); 2087 permute (search_arr, SIZEOFFREE1 + 1, SIZEOFFREE2 + 1);
2216 permute (search_arr, SIZEOFFREE2 + 1, SIZEOFFREE); 2088 permute (search_arr, SIZEOFFREE2 + 1, SIZEOFFREE);
2217} 2089}
2226 * Perhaps incorrectly, but I'm making the assumption that exclude 2098 * Perhaps incorrectly, but I'm making the assumption that exclude
2227 * is actually want is going to try and move there. We need this info 2099 * is actually want is going to try and move there. We need this info
2228 * because we have to know what movement the thing looking to move 2100 * because we have to know what movement the thing looking to move
2229 * there is capable of. 2101 * there is capable of.
2230 */ 2102 */
2231
2232int 2103int
2233find_dir (maptile *m, int x, int y, object *exclude) 2104find_dir (maptile *m, int x, int y, object *exclude)
2234{ 2105{
2235 int
2236 i,
2237 max = SIZEOFFREE, mflags; 2106 int i, max = SIZEOFFREE, mflags;
2238 2107
2239 sint16 nx, ny; 2108 sint16 nx, ny;
2240 object * 2109 object *tmp;
2241 tmp;
2242 maptile * 2110 maptile *mp;
2243 mp;
2244 2111
2245 MoveType blocked, move_type; 2112 MoveType blocked, move_type;
2246 2113
2247 if (exclude && exclude->head) 2114 if (exclude && exclude->head)
2248 { 2115 {
2260 mp = m; 2127 mp = m;
2261 nx = x + freearr_x[i]; 2128 nx = x + freearr_x[i];
2262 ny = y + freearr_y[i]; 2129 ny = y + freearr_y[i];
2263 2130
2264 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 2131 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny);
2132
2265 if (mflags & P_OUT_OF_MAP) 2133 if (mflags & P_OUT_OF_MAP)
2266 {
2267 max = maxfree[i]; 2134 max = maxfree[i];
2268 }
2269 else 2135 else
2270 { 2136 {
2271 blocked = GET_MAP_MOVE_BLOCK (mp, nx, ny); 2137 mapspace &ms = mp->at (nx, ny);
2138
2139 blocked = ms.move_block;
2272 2140
2273 if ((move_type & blocked) == move_type) 2141 if ((move_type & blocked) == move_type)
2274 {
2275 max = maxfree[i]; 2142 max = maxfree[i];
2276 }
2277 else if (mflags & P_IS_ALIVE) 2143 else if (mflags & P_IS_ALIVE)
2278 { 2144 {
2279 for (tmp = GET_MAP_OB (mp, nx, ny); tmp != NULL; tmp = tmp->above) 2145 for (tmp = ms.bot; tmp; tmp = tmp->above)
2280 { 2146 if ((tmp->flag [FLAG_MONSTER] || tmp->type == PLAYER)
2281 if ((QUERY_FLAG (tmp, FLAG_MONSTER) || tmp->type == PLAYER) && (tmp != exclude || (tmp->head && tmp->head != exclude))) 2147 && (tmp != exclude || (tmp->head && tmp->head != exclude)))
2282 {
2283 break; 2148 break;
2284 } 2149
2285 }
2286 if (tmp) 2150 if (tmp)
2287 {
2288 return freedir[i]; 2151 return freedir[i];
2289 }
2290 } 2152 }
2291 } 2153 }
2292 } 2154 }
2155
2293 return 0; 2156 return 0;
2294} 2157}
2295 2158
2296/* 2159/*
2297 * distance(object 1, object 2) will return the square of the 2160 * distance(object 1, object 2) will return the square of the
2298 * distance between the two given objects. 2161 * distance between the two given objects.
2299 */ 2162 */
2300
2301int 2163int
2302distance (const object *ob1, const object *ob2) 2164distance (const object *ob1, const object *ob2)
2303{ 2165{
2304 int
2305 i;
2306
2307 i = (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); 2166 return (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y);
2308 return i;
2309} 2167}
2310 2168
2311/* 2169/*
2312 * find_dir_2(delta-x,delta-y) will return a direction in which 2170 * find_dir_2(delta-x,delta-y) will return a direction in which
2313 * an object which has subtracted the x and y coordinates of another 2171 * an object which has subtracted the x and y coordinates of another
2314 * object, needs to travel toward it. 2172 * object, needs to travel toward it.
2315 */ 2173 */
2316
2317int 2174int
2318find_dir_2 (int x, int y) 2175find_dir_2 (int x, int y)
2319{ 2176{
2320 int 2177 int q;
2321 q;
2322 2178
2323 if (y) 2179 if (y)
2324 q = x * 100 / y; 2180 q = x * 100 / y;
2325 else if (x) 2181 else if (x)
2326 q = -300 * x; 2182 q = -300 * x;
2361int 2217int
2362absdir (int d) 2218absdir (int d)
2363{ 2219{
2364 while (d < 1) 2220 while (d < 1)
2365 d += 8; 2221 d += 8;
2222
2366 while (d > 8) 2223 while (d > 8)
2367 d -= 8; 2224 d -= 8;
2225
2368 return d; 2226 return d;
2369} 2227}
2370 2228
2371/* 2229/*
2372 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is 2230 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is
2374 */ 2232 */
2375 2233
2376int 2234int
2377dirdiff (int dir1, int dir2) 2235dirdiff (int dir1, int dir2)
2378{ 2236{
2379 int 2237 int d;
2380 d;
2381 2238
2382 d = abs (dir1 - dir2); 2239 d = abs (dir1 - dir2);
2383 if (d > 4) 2240 if (d > 4)
2384 d = 8 - d; 2241 d = 8 - d;
2242
2385 return d; 2243 return d;
2386} 2244}
2387 2245
2388/* peterm: 2246/* peterm:
2389 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster. 2247 * do LOS stuff for ball lightning. Go after the closest VISIBLE monster.
2392 * This basically means that if direction is 15, then it could either go 2250 * This basically means that if direction is 15, then it could either go
2393 * direction 4, 14, or 16 to get back to where we are. 2251 * direction 4, 14, or 16 to get back to where we are.
2394 * Moved from spell_util.c to object.c with the other related direction 2252 * Moved from spell_util.c to object.c with the other related direction
2395 * functions. 2253 * functions.
2396 */ 2254 */
2397
2398int
2399 reduction_dir[SIZEOFFREE][3] = { 2255int reduction_dir[SIZEOFFREE][3] = {
2400 {0, 0, 0}, /* 0 */ 2256 {0, 0, 0}, /* 0 */
2401 {0, 0, 0}, /* 1 */ 2257 {0, 0, 0}, /* 1 */
2402 {0, 0, 0}, /* 2 */ 2258 {0, 0, 0}, /* 2 */
2403 {0, 0, 0}, /* 3 */ 2259 {0, 0, 0}, /* 3 */
2404 {0, 0, 0}, /* 4 */ 2260 {0, 0, 0}, /* 4 */
2452 * find a path to that monster that we found. If not, 2308 * find a path to that monster that we found. If not,
2453 * we don't bother going toward it. Returns 1 if we 2309 * we don't bother going toward it. Returns 1 if we
2454 * can see a direct way to get it 2310 * can see a direct way to get it
2455 * Modified to be map tile aware -.MSW 2311 * Modified to be map tile aware -.MSW
2456 */ 2312 */
2457
2458
2459int 2313int
2460can_see_monsterP (maptile *m, int x, int y, int dir) 2314can_see_monsterP (maptile *m, int x, int y, int dir)
2461{ 2315{
2462 sint16 dx, dy; 2316 sint16 dx, dy;
2463 int
2464 mflags; 2317 int mflags;
2465 2318
2466 if (dir < 0) 2319 if (dir < 0)
2467 return 0; /* exit condition: invalid direction */ 2320 return 0; /* exit condition: invalid direction */
2468 2321
2469 dx = x + freearr_x[dir]; 2322 dx = x + freearr_x[dir];
2482 return 0; 2335 return 0;
2483 2336
2484 /* yes, can see. */ 2337 /* yes, can see. */
2485 if (dir < 9) 2338 if (dir < 9)
2486 return 1; 2339 return 1;
2340
2487 return can_see_monsterP (m, x, y, reduction_dir[dir][0]) | 2341 return can_see_monsterP (m, x, y, reduction_dir[dir][0])
2488 can_see_monsterP (m, x, y, reduction_dir[dir][1]) | can_see_monsterP (m, x, y, reduction_dir[dir][2]); 2342 | can_see_monsterP (m, x, y, reduction_dir[dir][1])
2343 | can_see_monsterP (m, x, y, reduction_dir[dir][2]);
2489} 2344}
2490
2491
2492 2345
2493/* 2346/*
2494 * can_pick(picker, item): finds out if an object is possible to be 2347 * can_pick(picker, item): finds out if an object is possible to be
2495 * picked up by the picker. Returnes 1 if it can be 2348 * picked up by the picker. Returnes 1 if it can be
2496 * picked up, otherwise 0. 2349 * picked up, otherwise 0.
2507 return /*QUERY_FLAG(who,FLAG_WIZ)|| */ 2360 return /*QUERY_FLAG(who,FLAG_WIZ)|| */
2508 (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) && 2361 (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) &&
2509 !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3)); 2362 !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3));
2510} 2363}
2511 2364
2512
2513/* 2365/*
2514 * create clone from object to another 2366 * create clone from object to another
2515 */ 2367 */
2516object * 2368object *
2517object_create_clone (object *asrc) 2369object_create_clone (object *asrc)
2536 { 2388 {
2537 dst = tmp; 2389 dst = tmp;
2538 tmp->head = 0; 2390 tmp->head = 0;
2539 } 2391 }
2540 else 2392 else
2541 {
2542 tmp->head = dst; 2393 tmp->head = dst;
2543 }
2544 2394
2545 tmp->more = 0; 2395 tmp->more = 0;
2546 2396
2547 if (prev) 2397 if (prev)
2548 prev->more = tmp; 2398 prev->more = tmp;
2560/* Basically, we save the content of the string to a temp file, then call */ 2410/* Basically, we save the content of the string to a temp file, then call */
2561/* load_object on it. I admit it is a highly inefficient way to make things, */ 2411/* load_object on it. I admit it is a highly inefficient way to make things, */
2562/* but it was simple to make and allows reusing the load_object function. */ 2412/* but it was simple to make and allows reusing the load_object function. */
2563/* Remember not to use load_object_str in a time-critical situation. */ 2413/* Remember not to use load_object_str in a time-critical situation. */
2564/* Also remember that multiparts objects are not supported for now. */ 2414/* Also remember that multiparts objects are not supported for now. */
2565
2566object * 2415object *
2567load_object_str (const char *obstr) 2416load_object_str (const char *obstr)
2568{ 2417{
2569 object *op; 2418 object *op;
2570 char filename[MAX_BUF]; 2419 char filename[MAX_BUF];
2600 * returns NULL if no match. 2449 * returns NULL if no match.
2601 */ 2450 */
2602object * 2451object *
2603find_obj_by_type_subtype (const object *who, int type, int subtype) 2452find_obj_by_type_subtype (const object *who, int type, int subtype)
2604{ 2453{
2605 object *tmp;
2606
2607 for (tmp = who->inv; tmp; tmp = tmp->below) 2454 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2608 if (tmp->type == type && tmp->subtype == subtype) 2455 if (tmp->type == type && tmp->subtype == subtype)
2609 return tmp; 2456 return tmp;
2610 2457
2611 return NULL; 2458 return 0;
2612} 2459}
2613 2460
2614/* If ob has a field named key, return the link from the list, 2461/* If ob has a field named key, return the link from the list,
2615 * otherwise return NULL. 2462 * otherwise return NULL.
2616 * 2463 *
2618 * do the desired thing. 2465 * do the desired thing.
2619 */ 2466 */
2620key_value * 2467key_value *
2621get_ob_key_link (const object *ob, const char *key) 2468get_ob_key_link (const object *ob, const char *key)
2622{ 2469{
2623 key_value *link;
2624
2625 for (link = ob->key_values; link != NULL; link = link->next) 2470 for (key_value *link = ob->key_values; link; link = link->next)
2626 if (link->key == key) 2471 if (link->key == key)
2627 return link; 2472 return link;
2628 2473
2629 return NULL; 2474 return 0;
2630} 2475}
2631 2476
2632/* 2477/*
2633 * Returns the value of op has an extra_field for key, or NULL. 2478 * Returns the value of op has an extra_field for key, or NULL.
2634 * 2479 *
2674 * Returns TRUE on success. 2519 * Returns TRUE on success.
2675 */ 2520 */
2676int 2521int
2677set_ob_key_value_s (object *op, const shstr & canonical_key, const char *value, int add_key) 2522set_ob_key_value_s (object *op, const shstr & canonical_key, const char *value, int add_key)
2678{ 2523{
2679 key_value *
2680 field = NULL, *last = NULL; 2524 key_value *field = NULL, *last = NULL;
2681 2525
2682 for (field = op->key_values; field != NULL; field = field->next) 2526 for (field = op->key_values; field != NULL; field = field->next)
2683 { 2527 {
2684 if (field->key != canonical_key) 2528 if (field->key != canonical_key)
2685 { 2529 {
2713 /* IF we get here, key doesn't exist */ 2557 /* IF we get here, key doesn't exist */
2714 2558
2715 /* No field, we'll have to add it. */ 2559 /* No field, we'll have to add it. */
2716 2560
2717 if (!add_key) 2561 if (!add_key)
2718 {
2719 return FALSE; 2562 return FALSE;
2720 } 2563
2721 /* There isn't any good reason to store a null 2564 /* There isn't any good reason to store a null
2722 * value in the key/value list. If the archetype has 2565 * value in the key/value list. If the archetype has
2723 * this key, then we should also have it, so shouldn't 2566 * this key, then we should also have it, so shouldn't
2724 * be here. If user wants to store empty strings, 2567 * be here. If user wants to store empty strings,
2725 * should pass in "" 2568 * should pass in ""
2774 } 2617 }
2775 else 2618 else
2776 item = item->env; 2619 item = item->env;
2777} 2620}
2778 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
2779// 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
2780const char * 2652const char *
2781object::debug_desc (char *info) const 2653object::debug_desc (char *info) const
2782{ 2654{
2655 char flagdesc[512];
2783 char info2[256 * 3]; 2656 char info2[256 * 4];
2784 char *p = info; 2657 char *p = info;
2785 2658
2786 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}",
2787 count, 2660 count, uuid.seq,
2788 &name, 2661 &name,
2789 title ? " " : "", 2662 title ? "\",title:" : "",
2790 title ? (const char *)title : ""); 2663 title ? (const char *)title : "",
2664 flag_desc (flagdesc, 512), type);
2791 2665
2792 if (env) 2666 if (env)
2793 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2667 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2794 2668
2795 if (map) 2669 if (map)
2796 p += snprintf (p, 256, "(on %s@%d+%d)", map->path, x, y); 2670 p += snprintf (p, 256, "(on %s@%d+%d)", &map->path, x, y);
2797 2671
2798 return info; 2672 return info;
2799} 2673}
2800 2674
2801const char * 2675const char *
2802object::debug_desc () const 2676object::debug_desc () const
2803{ 2677{
2804 static char info[256 * 3]; 2678 static char info[256 * 4];
2805 return debug_desc (info); 2679 return debug_desc (info);
2806} 2680}
2807 2681

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines