1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_object_c = |
|
|
4 | * "$Id: object.C,v 1.24 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
1 | |
7 | /* |
2 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
9 | |
4 | |
10 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
… | |
… | |
29 | |
24 | |
30 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
25 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
31 | sub/add_weight will transcend the environment updating the carrying |
26 | sub/add_weight will transcend the environment updating the carrying |
32 | variable. */ |
27 | variable. */ |
33 | #include <global.h> |
28 | #include <global.h> |
34 | #ifndef WIN32 /* ---win32 exclude headers */ |
|
|
35 | # include <stdio.h> |
29 | #include <stdio.h> |
36 | # include <sys/types.h> |
30 | #include <sys/types.h> |
37 | # include <sys/uio.h> |
31 | #include <sys/uio.h> |
38 | #endif /* win32 */ |
|
|
39 | #include <object.h> |
32 | #include <object.h> |
40 | #include <funcpoint.h> |
33 | #include <funcpoint.h> |
41 | #include <skills.h> |
34 | #include <skills.h> |
42 | #include <loader.h> |
35 | #include <loader.h> |
|
|
36 | |
43 | int nrofallocobjects = 0; |
37 | int nrofallocobjects = 0; |
44 | |
38 | |
45 | object *objects; /* Pointer to the list of used objects */ |
39 | object *objects; /* Pointer to the list of used objects */ |
46 | object *active_objects; /* List of active objects that need to be processed */ |
40 | object *active_objects; /* List of active objects that need to be processed */ |
47 | |
41 | |
… | |
… | |
214 | if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) |
208 | if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) |
215 | return 0; |
209 | return 0; |
216 | |
210 | |
217 | switch (ob1->type) |
211 | switch (ob1->type) |
218 | { |
212 | { |
219 | case SCROLL: |
213 | case SCROLL: |
220 | if (ob1->level != ob2->level) |
214 | if (ob1->level != ob2->level) |
221 | return 0; |
215 | return 0; |
222 | break; |
216 | break; |
223 | } |
217 | } |
224 | |
218 | |
225 | if (ob1->key_values != NULL || ob2->key_values != NULL) |
219 | if (ob1->key_values != NULL || ob2->key_values != NULL) |
226 | { |
220 | { |
227 | /* At least one of these has key_values. */ |
221 | /* At least one of these has key_values. */ |
… | |
… | |
249 | /* |
243 | /* |
250 | * sum_weight() is a recursive function which calculates the weight |
244 | * sum_weight() is a recursive function which calculates the weight |
251 | * an object is carrying. It goes through in figures out how much |
245 | * an object is carrying. It goes through in figures out how much |
252 | * containers are carrying, and sums it up. |
246 | * containers are carrying, and sums it up. |
253 | */ |
247 | */ |
254 | signed long |
248 | long |
255 | sum_weight (object *op) |
249 | sum_weight (object *op) |
256 | { |
250 | { |
257 | signed long sum; |
251 | long sum; |
258 | object *inv; |
252 | object *inv; |
259 | |
253 | |
260 | for (sum = 0, inv = op->inv; inv != NULL; inv = inv->below) |
254 | for (sum = 0, inv = op->inv; inv != NULL; inv = inv->below) |
261 | { |
255 | { |
262 | if (inv->inv) |
256 | if (inv->inv) |
… | |
… | |
449 | * Changed 2004-02-12 - if the player is setting at the play again |
443 | * Changed 2004-02-12 - if the player is setting at the play again |
450 | * prompt, he is removed, and we don't want to treat him as an owner of |
444 | * prompt, he is removed, and we don't want to treat him as an owner of |
451 | * anything, so check removed flag. I don't expect that this should break |
445 | * anything, so check removed flag. I don't expect that this should break |
452 | * anything - once an object is removed, it is basically dead anyways. |
446 | * anything - once an object is removed, it is basically dead anyways. |
453 | */ |
447 | */ |
454 | |
|
|
455 | object * |
448 | object * |
456 | get_owner (object *op) |
449 | object::get_owner () |
457 | { |
450 | { |
458 | if (op->owner == NULL) |
451 | if (!owner |
459 | return NULL; |
452 | || QUERY_FLAG (owner, FLAG_FREED) |
|
|
453 | || QUERY_FLAG (owner, FLAG_REMOVED)) |
|
|
454 | owner = 0; |
460 | |
455 | |
461 | if (!QUERY_FLAG (op->owner, FLAG_FREED) && !QUERY_FLAG (op->owner, FLAG_REMOVED) && op->owner->count == op->ownercount) |
|
|
462 | return op->owner; |
456 | return owner; |
463 | |
|
|
464 | op->owner = NULL; |
|
|
465 | op->ownercount = 0; |
|
|
466 | return NULL; |
|
|
467 | } |
|
|
468 | |
|
|
469 | void |
|
|
470 | clear_owner (object *op) |
|
|
471 | { |
|
|
472 | if (!op) |
|
|
473 | return; |
|
|
474 | |
|
|
475 | if (op->owner && op->ownercount == op->owner->count) |
|
|
476 | op->owner->refcount--; |
|
|
477 | |
|
|
478 | op->owner = NULL; |
|
|
479 | op->ownercount = 0; |
|
|
480 | } |
457 | } |
481 | |
458 | |
482 | /* |
459 | /* |
483 | * Sets the owner and sets the skill and exp pointers to owner's current |
460 | * Sets the owner and sets the skill and exp pointers to owner's current |
484 | * skill and experience objects. |
461 | * skill and experience objects. |
485 | */ |
462 | */ |
486 | void |
463 | void |
487 | set_owner (object *op, object *owner) |
464 | object::set_owner (object *owner) |
488 | { |
465 | { |
489 | if (owner == NULL || op == NULL) |
466 | if (!owner) |
490 | return; |
467 | return; |
491 | |
468 | |
492 | /* next line added to allow objects which own objects */ |
469 | /* next line added to allow objects which own objects */ |
493 | /* Add a check for ownercounts in here, as I got into an endless loop |
470 | /* Add a check for ownercounts in here, as I got into an endless loop |
494 | * with the fireball owning a poison cloud which then owned the |
471 | * with the fireball owning a poison cloud which then owned the |
495 | * fireball. I believe that was caused by one of the objects getting |
472 | * fireball. I believe that was caused by one of the objects getting |
496 | * freed and then another object replacing it. Since the ownercounts |
473 | * freed and then another object replacing it. Since the ownercounts |
497 | * didn't match, this check is valid and I believe that cause is valid. |
474 | * didn't match, this check is valid and I believe that cause is valid. |
498 | */ |
475 | */ |
499 | while (owner->owner && owner != owner->owner && owner->ownercount == owner->owner->count) |
476 | while (owner->owner) |
500 | owner = owner->owner; |
477 | owner = owner->owner; |
501 | |
478 | |
502 | /* IF the owner still has an owner, we did not resolve to a final owner. |
|
|
503 | * so lets not add to that. |
|
|
504 | */ |
|
|
505 | if (owner->owner) |
|
|
506 | return; |
|
|
507 | |
|
|
508 | op->owner = owner; |
479 | this->owner = owner; |
509 | |
|
|
510 | op->ownercount = owner->count; |
|
|
511 | owner->refcount++; |
|
|
512 | |
|
|
513 | } |
|
|
514 | |
|
|
515 | /* Set the owner to clone's current owner and set the skill and experience |
|
|
516 | * objects to clone's objects (typically those objects that where the owner's |
|
|
517 | * current skill and experience objects at the time when clone's owner was |
|
|
518 | * set - not the owner's current skill and experience objects). |
|
|
519 | * |
|
|
520 | * Use this function if player created an object (e.g. fire bullet, swarm |
|
|
521 | * spell), and this object creates further objects whose kills should be |
|
|
522 | * accounted for the player's original skill, even if player has changed |
|
|
523 | * skills meanwhile. |
|
|
524 | */ |
|
|
525 | void |
|
|
526 | copy_owner (object *op, object *clone) |
|
|
527 | { |
|
|
528 | object *owner = get_owner (clone); |
|
|
529 | |
|
|
530 | if (owner == NULL) |
|
|
531 | { |
|
|
532 | /* players don't have owners - they own themselves. Update |
|
|
533 | * as appropriate. |
|
|
534 | */ |
|
|
535 | if (clone->type == PLAYER) |
|
|
536 | owner = clone; |
|
|
537 | else |
|
|
538 | return; |
|
|
539 | } |
|
|
540 | set_owner (op, owner); |
|
|
541 | |
|
|
542 | } |
480 | } |
543 | |
481 | |
544 | /* Zero the key_values on op, decrementing the shared-string |
482 | /* Zero the key_values on op, decrementing the shared-string |
545 | * refcounts and freeing the links. |
483 | * refcounts and freeing the links. |
546 | */ |
484 | */ |
… | |
… | |
562 | { |
500 | { |
563 | attachable_base::clear (); |
501 | attachable_base::clear (); |
564 | |
502 | |
565 | free_key_values (this); |
503 | free_key_values (this); |
566 | |
504 | |
|
|
505 | owner = 0; |
567 | name = 0; |
506 | name = 0; |
568 | name_pl = 0; |
507 | name_pl = 0; |
569 | title = 0; |
508 | title = 0; |
570 | race = 0; |
509 | race = 0; |
571 | slaying = 0; |
510 | slaying = 0; |
572 | skill = 0; |
511 | skill = 0; |
573 | msg = 0; |
512 | msg = 0; |
574 | lore = 0; |
513 | lore = 0; |
575 | custom_name = 0; |
514 | custom_name = 0; |
576 | materialname = 0; |
515 | materialname = 0; |
|
|
516 | contr = 0; |
|
|
517 | below = 0; |
|
|
518 | above = 0; |
|
|
519 | inv = 0; |
|
|
520 | container = 0; |
|
|
521 | env = 0; |
|
|
522 | more = 0; |
|
|
523 | head = 0; |
|
|
524 | map = 0; |
|
|
525 | active_next = 0; |
|
|
526 | active_prev = 0; |
577 | |
527 | |
578 | memset (static_cast < object_pod * >(this), 0, sizeof (object_pod)); |
528 | memset (static_cast<object_pod *>(this), 0, sizeof (object_pod)); |
579 | |
529 | |
580 | SET_FLAG (this, FLAG_REMOVED); |
530 | SET_FLAG (this, FLAG_REMOVED); |
|
|
531 | |
|
|
532 | /* What is not cleared is next, prev, and count */ |
|
|
533 | |
|
|
534 | expmul = 1.0; |
|
|
535 | face = blank_face; |
|
|
536 | attacked_by_count = -1; |
|
|
537 | |
|
|
538 | if (settings.casting_time) |
|
|
539 | casting_time = -1; |
581 | } |
540 | } |
582 | |
541 | |
583 | void object::clone (object *destination) |
542 | void object::clone (object *destination) |
584 | { |
543 | { |
585 | *(object_copy *) destination = *this; |
544 | *(object_copy *)destination = *this; |
586 | *(object_pod *) destination = *this; |
545 | *(object_pod *)destination = *this; |
587 | |
546 | |
588 | if (self || cb) |
547 | if (self || cb) |
589 | INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); |
548 | INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); |
590 | } |
|
|
591 | |
|
|
592 | /* |
|
|
593 | * clear_object() frees everything allocated by an object, and also |
|
|
594 | * clears all variables and flags to default settings. |
|
|
595 | */ |
|
|
596 | |
|
|
597 | void |
|
|
598 | clear_object (object *op) |
|
|
599 | { |
|
|
600 | op->clear (); |
|
|
601 | |
|
|
602 | op->contr = NULL; |
|
|
603 | op->below = NULL; |
|
|
604 | op->above = NULL; |
|
|
605 | op->inv = NULL; |
|
|
606 | op->container = NULL; |
|
|
607 | op->env = NULL; |
|
|
608 | op->more = NULL; |
|
|
609 | op->head = NULL; |
|
|
610 | op->map = NULL; |
|
|
611 | op->refcount = 0; |
|
|
612 | op->active_next = NULL; |
|
|
613 | op->active_prev = NULL; |
|
|
614 | /* What is not cleared is next, prev, and count */ |
|
|
615 | |
|
|
616 | op->expmul = 1.0; |
|
|
617 | op->face = blank_face; |
|
|
618 | op->attacked_by_count = -1; |
|
|
619 | |
|
|
620 | if (settings.casting_time) |
|
|
621 | op->casting_time = -1; |
|
|
622 | } |
549 | } |
623 | |
550 | |
624 | /* |
551 | /* |
625 | * copy object first frees everything allocated by the second object, |
552 | * copy object first frees everything allocated by the second object, |
626 | * and then copies the contends of the first object into the second |
553 | * and then copies the contends of the first object into the second |
627 | * object, allocating what needs to be allocated. Basically, any |
554 | * object, allocating what needs to be allocated. Basically, any |
628 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
555 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
629 | * if the first object is freed, the pointers in the new object |
556 | * if the first object is freed, the pointers in the new object |
630 | * will point at garbage. |
557 | * will point at garbage. |
631 | */ |
558 | */ |
632 | |
|
|
633 | void |
559 | void |
634 | copy_object (object *op2, object *op) |
560 | copy_object (object *op2, object *op) |
635 | { |
561 | { |
636 | bool is_freed = QUERY_FLAG (op, FLAG_FREED); |
562 | bool is_freed = QUERY_FLAG (op, FLAG_FREED); |
637 | bool is_removed = QUERY_FLAG (op, FLAG_REMOVED); |
563 | bool is_removed = QUERY_FLAG (op, FLAG_REMOVED); |
… | |
… | |
890 | /* if the object is being removed, we can't make intelligent |
816 | /* if the object is being removed, we can't make intelligent |
891 | * decisions, because remove_ob can't really pass the object |
817 | * decisions, because remove_ob can't really pass the object |
892 | * that is being removed. |
818 | * that is being removed. |
893 | */ |
819 | */ |
894 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
820 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
895 | { |
|
|
896 | update_now = 1; |
821 | update_now = 1; |
897 | } |
|
|
898 | else if (action == UP_OBJ_FACE) |
822 | else if (action == UP_OBJ_FACE) |
899 | { |
|
|
900 | /* Nothing to do for that case */ |
823 | /* Nothing to do for that case */ ; |
901 | } |
|
|
902 | else |
824 | else |
903 | { |
|
|
904 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
825 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
905 | } |
|
|
906 | |
826 | |
907 | if (update_now) |
827 | if (update_now) |
908 | { |
828 | { |
909 | SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE); |
829 | SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE); |
910 | update_position (op->map, op->x, op->y); |
830 | update_position (op->map, op->x, op->y); |
… | |
… | |
912 | |
832 | |
913 | if (op->more != NULL) |
833 | if (op->more != NULL) |
914 | update_object (op->more, action); |
834 | update_object (op->more, action); |
915 | } |
835 | } |
916 | |
836 | |
917 | static |
837 | static unordered_vector<object *> mortals; |
918 | std::vector < object *> |
838 | static std::vector<object *> freed; |
919 | mortals; |
|
|
920 | |
839 | |
921 | void object::free_mortals () |
840 | void object::free_mortals () |
922 | { |
841 | { |
923 | for (std::vector < object *>::iterator i = mortals.begin (); i != mortals.end (); ++i) |
842 | for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) |
924 | delete * |
843 | if ((*i)->refcnt) |
|
|
844 | ++i; // further delay freeing |
|
|
845 | else |
925 | i; |
846 | { |
|
|
847 | freed.push_back (*i);//D |
|
|
848 | //delete *i; |
|
|
849 | mortals.erase (i); |
|
|
850 | } |
926 | |
851 | |
927 | mortals.clear (); |
852 | if (mortals.size())//D |
|
|
853 | LOG (llevDebug, "%d objects in mortal queue\n", mortals.size());//D |
928 | } |
854 | } |
929 | |
855 | |
930 | object::object () |
856 | object::object () |
931 | { |
857 | { |
932 | SET_FLAG (this, FLAG_REMOVED); |
858 | SET_FLAG (this, FLAG_REMOVED); |
… | |
… | |
958 | { |
884 | { |
959 | count = 0; |
885 | count = 0; |
960 | |
886 | |
961 | /* Remove this object from the list of used objects */ |
887 | /* Remove this object from the list of used objects */ |
962 | if (prev) |
888 | if (prev) |
|
|
889 | { |
963 | prev->next = next; |
890 | prev->next = next; |
|
|
891 | prev = 0; |
|
|
892 | } |
|
|
893 | |
964 | if (next) |
894 | if (next) |
|
|
895 | { |
965 | next->prev = prev; |
896 | next->prev = prev; |
|
|
897 | next = 0; |
|
|
898 | } |
|
|
899 | |
966 | if (this == objects) |
900 | if (this == objects) |
967 | objects = next; |
901 | objects = next; |
968 | } |
902 | } |
969 | |
903 | |
970 | object *object::create () |
904 | object *object::create () |
971 | { |
905 | { |
972 | object * |
906 | object * |
|
|
907 | op; |
|
|
908 | |
|
|
909 | if (freed.empty ()) |
973 | op = new object; |
910 | op = new object; |
|
|
911 | else |
|
|
912 | { |
|
|
913 | // highly annoying, but the only way to get it stable right now |
|
|
914 | op = freed.back (); |
|
|
915 | freed.pop_back (); |
|
|
916 | op->~object (); |
|
|
917 | new ((void *) op) object; |
|
|
918 | } |
974 | |
919 | |
975 | op->link (); |
920 | op->link (); |
976 | return op; |
921 | return op; |
977 | } |
922 | } |
978 | |
923 | |
… | |
… | |
986 | * If free_inventory is set, free inventory as well. Else drop items in |
931 | * If free_inventory is set, free inventory as well. Else drop items in |
987 | * inventory to the ground. |
932 | * inventory to the ground. |
988 | */ |
933 | */ |
989 | void object::free (bool free_inventory) |
934 | void object::free (bool free_inventory) |
990 | { |
935 | { |
|
|
936 | if (QUERY_FLAG (this, FLAG_FREED)) |
|
|
937 | return; |
|
|
938 | |
991 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
939 | if (!QUERY_FLAG (this, FLAG_REMOVED)) |
992 | { |
940 | remove_ob (this); |
993 | LOG (llevDebug, "Free object called with non removed object\n"); |
|
|
994 | dump_object (this); |
|
|
995 | #ifdef MANY_CORES |
|
|
996 | abort (); |
|
|
997 | #endif |
|
|
998 | } |
|
|
999 | |
941 | |
1000 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
942 | if (QUERY_FLAG (this, FLAG_FRIENDLY)) |
1001 | { |
|
|
1002 | LOG (llevMonster, "Warning: tried to free friendly object.\n"); |
|
|
1003 | remove_friendly_object (this); |
943 | remove_friendly_object (this); |
1004 | } |
|
|
1005 | |
944 | |
1006 | if (QUERY_FLAG (this, FLAG_FREED)) |
945 | SET_FLAG (this, FLAG_FREED); |
1007 | { |
|
|
1008 | dump_object (this); |
|
|
1009 | LOG (llevError, "Trying to free freed object.\n%s\n", errmsg); |
|
|
1010 | return; |
|
|
1011 | } |
|
|
1012 | |
946 | |
1013 | if (more) |
947 | if (more) |
1014 | { |
948 | { |
1015 | more->free (free_inventory); |
949 | more->free (free_inventory); |
1016 | more = 0; |
950 | more = 0; |
… | |
… | |
1022 | * if some form of movement is allowed, let objects |
956 | * if some form of movement is allowed, let objects |
1023 | * drop on that space. |
957 | * drop on that space. |
1024 | */ |
958 | */ |
1025 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || (GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)) |
959 | if (free_inventory || !map || map->in_memory != MAP_IN_MEMORY || (GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)) |
1026 | { |
960 | { |
1027 | object * |
961 | object *op = inv; |
1028 | op = inv; |
|
|
1029 | |
962 | |
1030 | while (op) |
963 | while (op) |
1031 | { |
964 | { |
1032 | object * |
|
|
1033 | tmp = op->below; |
965 | object *tmp = op->below; |
1034 | |
|
|
1035 | remove_ob (op); |
|
|
1036 | op->free (free_inventory); |
966 | op->free (free_inventory); |
1037 | op = tmp; |
967 | op = tmp; |
1038 | } |
968 | } |
1039 | } |
969 | } |
1040 | else |
970 | else |
1041 | { /* Put objects in inventory onto this space */ |
971 | { /* Put objects in inventory onto this space */ |
1042 | object * |
972 | object *op = inv; |
1043 | op = inv; |
|
|
1044 | |
973 | |
1045 | while (op) |
974 | while (op) |
1046 | { |
975 | { |
1047 | object * |
|
|
1048 | tmp = op->below; |
976 | object *tmp = op->below; |
1049 | |
977 | |
1050 | remove_ob (op); |
978 | remove_ob (op); |
1051 | |
979 | |
1052 | if (QUERY_FLAG (op, FLAG_STARTEQUIP) |
980 | if (QUERY_FLAG (op, FLAG_STARTEQUIP) |
1053 | || QUERY_FLAG (op, FLAG_NO_DROP) || op->type == RUNE || op->type == TRAP || QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
981 | || QUERY_FLAG (op, FLAG_NO_DROP) || op->type == RUNE || op->type == TRAP || QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) |
… | |
… | |
1062 | op = tmp; |
990 | op = tmp; |
1063 | } |
991 | } |
1064 | } |
992 | } |
1065 | } |
993 | } |
1066 | |
994 | |
|
|
995 | owner = 0; |
|
|
996 | |
1067 | /* Remove object from the active list */ |
997 | /* Remove object from the active list */ |
1068 | speed = 0; |
998 | speed = 0; |
1069 | update_ob_speed (this); |
999 | update_ob_speed (this); |
1070 | |
1000 | |
1071 | unlink (); |
1001 | unlink (); |
1072 | |
|
|
1073 | SET_FLAG (this, FLAG_FREED); |
|
|
1074 | |
1002 | |
1075 | mortals.push_back (this); |
1003 | mortals.push_back (this); |
1076 | } |
1004 | } |
1077 | |
1005 | |
1078 | /* |
1006 | /* |
… | |
… | |
1109 | object * |
1037 | object * |
1110 | tmp, * |
1038 | tmp, * |
1111 | last = NULL; |
1039 | last = NULL; |
1112 | object * |
1040 | object * |
1113 | otmp; |
1041 | otmp; |
|
|
1042 | |
1114 | tag_t |
1043 | tag_t |
1115 | tag; |
1044 | tag; |
1116 | int |
1045 | int |
1117 | check_walk_off; |
1046 | check_walk_off; |
1118 | mapstruct * |
1047 | mapstruct * |
1119 | m; |
1048 | m; |
|
|
1049 | |
1120 | sint16 |
1050 | sint16 |
1121 | x, |
1051 | x, |
1122 | y; |
1052 | y; |
1123 | |
1053 | |
1124 | |
|
|
1125 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1054 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1126 | { |
1055 | return; |
1127 | dump_object (op); |
|
|
1128 | LOG (llevError, "Trying to remove removed object.\n%s\n", errmsg); |
|
|
1129 | |
1056 | |
1130 | /* Changed it to always dump core in this case. As has been learned |
1057 | SET_FLAG (op, FLAG_REMOVED); |
1131 | * in the past, trying to recover from errors almost always |
1058 | |
1132 | * make things worse, and this is a real error here - something |
|
|
1133 | * that should not happen. |
|
|
1134 | * Yes, if this was a mission critical app, trying to do something |
|
|
1135 | * to recover may make sense, but that is because failure of the app |
|
|
1136 | * may have other disastrous problems. Cf runs out of a script |
|
|
1137 | * so is easily enough restarted without any real problems. |
|
|
1138 | * MSW 2001-07-01 |
|
|
1139 | */ |
|
|
1140 | abort (); |
|
|
1141 | } |
|
|
1142 | if (op->more != NULL) |
1059 | if (op->more != NULL) |
1143 | remove_ob (op->more); |
1060 | remove_ob (op->more); |
1144 | |
|
|
1145 | SET_FLAG (op, FLAG_REMOVED); |
|
|
1146 | |
1061 | |
1147 | /* |
1062 | /* |
1148 | * In this case, the object to be removed is in someones |
1063 | * In this case, the object to be removed is in someones |
1149 | * inventory. |
1064 | * inventory. |
1150 | */ |
1065 | */ |
… | |
… | |
1176 | */ |
1091 | */ |
1177 | op->x = op->env->x, op->y = op->env->y; |
1092 | op->x = op->env->x, op->y = op->env->y; |
1178 | op->map = op->env->map; |
1093 | op->map = op->env->map; |
1179 | op->above = NULL, op->below = NULL; |
1094 | op->above = NULL, op->below = NULL; |
1180 | op->env = NULL; |
1095 | op->env = NULL; |
1181 | return; |
1096 | } |
|
|
1097 | else if (op->map) |
1182 | } |
1098 | { |
1183 | |
|
|
1184 | /* If we get here, we are removing it from a map */ |
|
|
1185 | if (op->map == NULL) |
|
|
1186 | return; |
|
|
1187 | |
|
|
1188 | x = op->x; |
1099 | x = op->x; |
1189 | y = op->y; |
1100 | y = op->y; |
1190 | m = get_map_from_coord (op->map, &x, &y); |
1101 | m = get_map_from_coord (op->map, &x, &y); |
1191 | |
1102 | |
1192 | if (!m) |
1103 | if (!m) |
1193 | { |
1104 | { |
1194 | LOG (llevError, "remove_ob called when object was on map but appears to not be within valid coordinates? %s (%d,%d)\n", |
1105 | LOG (llevError, "remove_ob called when object was on map but appears to not be within valid coordinates? %s (%d,%d)\n", |
1195 | op->map->path, op->x, op->y); |
1106 | op->map->path, op->x, op->y); |
1196 | /* in old days, we used to set x and y to 0 and continue. |
1107 | /* in old days, we used to set x and y to 0 and continue. |
1197 | * it seems if we get into this case, something is probablye |
1108 | * it seems if we get into this case, something is probablye |
1198 | * screwed up and should be fixed. |
1109 | * screwed up and should be fixed. |
|
|
1110 | */ |
|
|
1111 | abort (); |
|
|
1112 | } |
|
|
1113 | |
|
|
1114 | if (op->map != m) |
|
|
1115 | LOG (llevDebug, "remove_ob: Object not really on map it claimed to be on? %s != %s, %d,%d != %d,%d\n", |
|
|
1116 | op->map->path, m->path, op->x, op->y, x, y); |
|
|
1117 | |
|
|
1118 | /* Re did the following section of code - it looks like it had |
|
|
1119 | * lots of logic for things we no longer care about |
1199 | */ |
1120 | */ |
1200 | abort (); |
|
|
1201 | } |
|
|
1202 | if (op->map != m) |
|
|
1203 | { |
|
|
1204 | LOG (llevDebug, "remove_ob: Object not really on map it claimed to be on? %s != %s, %d,%d != %d,%d\n", |
|
|
1205 | op->map->path, m->path, op->x, op->y, x, y); |
|
|
1206 | } |
|
|
1207 | |
1121 | |
1208 | /* Re did the following section of code - it looks like it had |
|
|
1209 | * lots of logic for things we no longer care about |
|
|
1210 | */ |
|
|
1211 | |
|
|
1212 | /* link the object above us */ |
1122 | /* link the object above us */ |
1213 | if (op->above) |
1123 | if (op->above) |
1214 | op->above->below = op->below; |
1124 | op->above->below = op->below; |
1215 | else |
1125 | else |
1216 | SET_MAP_TOP (m, x, y, op->below); /* we were top, set new top */ |
1126 | SET_MAP_TOP (m, x, y, op->below); /* we were top, set new top */ |
1217 | |
1127 | |
1218 | /* Relink the object below us, if there is one */ |
1128 | /* Relink the object below us, if there is one */ |
1219 | if (op->below) |
1129 | if (op->below) |
1220 | { |
|
|
1221 | op->below->above = op->above; |
1130 | op->below->above = op->above; |
1222 | } |
|
|
1223 | else |
1131 | else |
1224 | { |
1132 | { |
1225 | /* Nothing below, which means we need to relink map object for this space |
1133 | /* Nothing below, which means we need to relink map object for this space |
1226 | * use translated coordinates in case some oddness with map tiling is |
1134 | * use translated coordinates in case some oddness with map tiling is |
1227 | * evident |
1135 | * evident |
1228 | */ |
|
|
1229 | if (GET_MAP_OB (m, x, y) != op) |
|
|
1230 | { |
|
|
1231 | dump_object (op); |
|
|
1232 | LOG (llevError, "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", |
|
|
1233 | errmsg); |
|
|
1234 | dump_object (GET_MAP_OB (m, x, y)); |
|
|
1235 | LOG (llevError, "%s\n", errmsg); |
|
|
1236 | } |
|
|
1237 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
|
|
1238 | } |
|
|
1239 | op->above = NULL; |
|
|
1240 | op->below = NULL; |
|
|
1241 | |
|
|
1242 | if (op->map->in_memory == MAP_SAVING) |
|
|
1243 | return; |
|
|
1244 | |
|
|
1245 | tag = op->count; |
|
|
1246 | check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY); |
|
|
1247 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1248 | { |
|
|
1249 | /* No point updating the players look faces if he is the object |
|
|
1250 | * being removed. |
|
|
1251 | */ |
|
|
1252 | |
|
|
1253 | if (tmp->type == PLAYER && tmp != op) |
|
|
1254 | { |
|
|
1255 | /* If a container that the player is currently using somehow gets |
|
|
1256 | * removed (most likely destroyed), update the player view |
|
|
1257 | * appropriately. |
|
|
1258 | */ |
1136 | */ |
1259 | if (tmp->container == op) |
1137 | if (GET_MAP_OB (m, x, y) != op) |
1260 | { |
1138 | { |
1261 | CLEAR_FLAG (op, FLAG_APPLIED); |
1139 | dump_object (op); |
1262 | tmp->container = NULL; |
1140 | LOG (llevError, |
|
|
1141 | "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", errmsg); |
|
|
1142 | dump_object (GET_MAP_OB (m, x, y)); |
|
|
1143 | LOG (llevError, "%s\n", errmsg); |
1263 | } |
1144 | } |
1264 | tmp->contr->socket.update_look = 1; |
1145 | |
1265 | } |
1146 | SET_MAP_OB (m, x, y, op->above); /* goes on above it. */ |
1266 | /* See if player moving off should effect something */ |
|
|
1267 | if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
|
|
1268 | { |
1147 | } |
1269 | |
1148 | |
1270 | move_apply (tmp, op, NULL); |
1149 | op->above = 0; |
1271 | if (was_destroyed (op, tag)) |
1150 | op->below = 0; |
|
|
1151 | |
|
|
1152 | if (op->map->in_memory == MAP_SAVING) |
|
|
1153 | return; |
|
|
1154 | |
|
|
1155 | tag = op->count; |
|
|
1156 | check_walk_off = !QUERY_FLAG (op, FLAG_NO_APPLY); |
|
|
1157 | |
|
|
1158 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
|
|
1159 | { |
|
|
1160 | /* No point updating the players look faces if he is the object |
|
|
1161 | * being removed. |
|
|
1162 | */ |
|
|
1163 | |
|
|
1164 | if (tmp->type == PLAYER && tmp != op) |
1272 | { |
1165 | { |
1273 | LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); |
1166 | /* If a container that the player is currently using somehow gets |
|
|
1167 | * removed (most likely destroyed), update the player view |
|
|
1168 | * appropriately. |
|
|
1169 | */ |
|
|
1170 | if (tmp->container == op) |
|
|
1171 | { |
|
|
1172 | CLEAR_FLAG (op, FLAG_APPLIED); |
|
|
1173 | tmp->container = NULL; |
|
|
1174 | } |
|
|
1175 | |
|
|
1176 | tmp->contr->socket.update_look = 1; |
1274 | } |
1177 | } |
|
|
1178 | |
|
|
1179 | /* See if player moving off should effect something */ |
|
|
1180 | if (check_walk_off && ((op->move_type & tmp->move_off) && (op->move_type & ~tmp->move_off & ~tmp->move_block) == 0)) |
|
|
1181 | { |
|
|
1182 | move_apply (tmp, op, NULL); |
|
|
1183 | |
|
|
1184 | if (was_destroyed (op, tag)) |
|
|
1185 | { |
|
|
1186 | LOG (llevError, "BUG: remove_ob(): name %s, archname %s destroyed " "leaving object\n", &tmp->name, &tmp->arch->name); |
|
|
1187 | } |
1275 | } |
1188 | } |
1276 | |
1189 | |
1277 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1190 | /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ |
1278 | |
1191 | |
1279 | if (tmp->above == tmp) |
1192 | if (tmp->above == tmp) |
1280 | tmp->above = NULL; |
1193 | tmp->above = NULL; |
|
|
1194 | |
1281 | last = tmp; |
1195 | last = tmp; |
1282 | } |
1196 | } |
|
|
1197 | |
1283 | /* last == NULL of there are no objects on this space */ |
1198 | /* last == NULL of there are no objects on this space */ |
1284 | if (last == NULL) |
1199 | if (last == NULL) |
1285 | { |
1200 | { |
1286 | /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, |
1201 | /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, |
1287 | * we could preserve the flags (GET_MAP_FLAGS), but update_position figures |
1202 | * we could preserve the flags (GET_MAP_FLAGS), but update_position figures |
1288 | * those out anyways, and if there are any flags set right now, they won't |
1203 | * those out anyways, and if there are any flags set right now, they won't |
1289 | * be correct anyways. |
1204 | * be correct anyways. |
1290 | */ |
1205 | */ |
1291 | SET_MAP_FLAGS (op->map, op->x, op->y, P_NEED_UPDATE); |
1206 | SET_MAP_FLAGS (op->map, op->x, op->y, P_NEED_UPDATE); |
1292 | update_position (op->map, op->x, op->y); |
1207 | update_position (op->map, op->x, op->y); |
1293 | } |
1208 | } |
1294 | else |
1209 | else |
1295 | update_object (last, UP_OBJ_REMOVE); |
1210 | update_object (last, UP_OBJ_REMOVE); |
1296 | |
1211 | |
1297 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0)) |
1212 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0)) |
1298 | update_all_los (op->map, op->x, op->y); |
1213 | update_all_los (op->map, op->x, op->y); |
1299 | |
1214 | } |
1300 | } |
1215 | } |
1301 | |
1216 | |
1302 | /* |
1217 | /* |
1303 | * merge_ob(op,top): |
1218 | * merge_ob(op,top): |
1304 | * |
1219 | * |
… | |
… | |
1311 | object * |
1226 | object * |
1312 | merge_ob (object *op, object *top) |
1227 | merge_ob (object *op, object *top) |
1313 | { |
1228 | { |
1314 | if (!op->nrof) |
1229 | if (!op->nrof) |
1315 | return 0; |
1230 | return 0; |
|
|
1231 | |
1316 | if (top == NULL) |
1232 | if (top == NULL) |
1317 | for (top = op; top != NULL && top->above != NULL; top = top->above); |
1233 | for (top = op; top != NULL && top->above != NULL; top = top->above); |
|
|
1234 | |
1318 | for (; top != NULL; top = top->below) |
1235 | for (; top != NULL; top = top->below) |
1319 | { |
1236 | { |
1320 | if (top == op) |
1237 | if (top == op) |
1321 | continue; |
1238 | continue; |
1322 | if (CAN_MERGE (op, top)) |
1239 | if (CAN_MERGE (op, top)) |
… | |
… | |
1328 | remove_ob (op); |
1245 | remove_ob (op); |
1329 | free_object (op); |
1246 | free_object (op); |
1330 | return top; |
1247 | return top; |
1331 | } |
1248 | } |
1332 | } |
1249 | } |
|
|
1250 | |
1333 | return NULL; |
1251 | return NULL; |
1334 | } |
1252 | } |
1335 | |
1253 | |
1336 | /* |
1254 | /* |
1337 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1255 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1338 | * job preparing multi-part monsters |
1256 | * job preparing multi-part monsters |
1339 | */ |
1257 | */ |
1340 | object * |
1258 | object * |
1341 | insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) |
1259 | insert_ob_in_map_at (object *op, mapstruct *m, object *originator, int flag, int x, int y) |
1342 | { |
1260 | { |
1343 | object * |
1261 | object *tmp; |
1344 | tmp; |
|
|
1345 | |
1262 | |
1346 | if (op->head) |
1263 | if (op->head) |
1347 | op = op->head; |
1264 | op = op->head; |
|
|
1265 | |
1348 | for (tmp = op; tmp; tmp = tmp->more) |
1266 | for (tmp = op; tmp; tmp = tmp->more) |
1349 | { |
1267 | { |
1350 | tmp->x = x + tmp->arch->clone.x; |
1268 | tmp->x = x + tmp->arch->clone.x; |
1351 | tmp->y = y + tmp->arch->clone.y; |
1269 | tmp->y = y + tmp->arch->clone.y; |
1352 | } |
1270 | } |
|
|
1271 | |
1353 | return insert_ob_in_map (op, m, originator, flag); |
1272 | return insert_ob_in_map (op, m, originator, flag); |
1354 | } |
1273 | } |
1355 | |
1274 | |
1356 | /* |
1275 | /* |
1357 | * insert_ob_in_map (op, map, originator, flag): |
1276 | * insert_ob_in_map (op, map, originator, flag): |
… | |
… | |
1375 | */ |
1294 | */ |
1376 | |
1295 | |
1377 | object * |
1296 | object * |
1378 | insert_ob_in_map (object *op, mapstruct *m, object *originator, int flag) |
1297 | insert_ob_in_map (object *op, mapstruct *m, object *originator, int flag) |
1379 | { |
1298 | { |
1380 | object * |
1299 | object *tmp, *top, *floor = NULL; |
1381 | tmp, * |
1300 | sint16 x, y; |
1382 | top, * |
|
|
1383 | floor = NULL; |
|
|
1384 | sint16 |
|
|
1385 | x, |
|
|
1386 | y; |
|
|
1387 | |
1301 | |
1388 | if (QUERY_FLAG (op, FLAG_FREED)) |
1302 | if (QUERY_FLAG (op, FLAG_FREED)) |
1389 | { |
1303 | { |
1390 | LOG (llevError, "Trying to insert freed object!\n"); |
1304 | LOG (llevError, "Trying to insert freed object!\n"); |
1391 | return NULL; |
1305 | return NULL; |
1392 | } |
1306 | } |
|
|
1307 | |
1393 | if (m == NULL) |
1308 | if (m == NULL) |
1394 | { |
1309 | { |
1395 | dump_object (op); |
1310 | dump_object (op); |
1396 | LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); |
1311 | LOG (llevError, "Trying to insert in null-map!\n%s\n", errmsg); |
1397 | return op; |
1312 | return op; |
1398 | } |
1313 | } |
|
|
1314 | |
1399 | if (out_of_map (m, op->x, op->y)) |
1315 | if (out_of_map (m, op->x, op->y)) |
1400 | { |
1316 | { |
1401 | dump_object (op); |
1317 | dump_object (op); |
1402 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); |
1318 | LOG (llevError, "Trying to insert object outside the map.\n%s\n", errmsg); |
1403 | #ifdef MANY_CORES |
1319 | #ifdef MANY_CORES |
… | |
… | |
1407 | */ |
1323 | */ |
1408 | abort (); |
1324 | abort (); |
1409 | #endif |
1325 | #endif |
1410 | return op; |
1326 | return op; |
1411 | } |
1327 | } |
|
|
1328 | |
1412 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1329 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
1413 | { |
1330 | { |
1414 | dump_object (op); |
1331 | dump_object (op); |
1415 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); |
1332 | LOG (llevError, "Trying to insert (map) inserted object.\n%s\n", errmsg); |
1416 | return op; |
1333 | return op; |
1417 | } |
1334 | } |
|
|
1335 | |
1418 | if (op->more != NULL) |
1336 | if (op->more != NULL) |
1419 | { |
1337 | { |
1420 | /* The part may be on a different map. */ |
1338 | /* The part may be on a different map. */ |
1421 | |
1339 | |
1422 | object * |
|
|
1423 | more = op->more; |
1340 | object *more = op->more; |
1424 | |
1341 | |
1425 | /* We really need the caller to normalize coordinates - if |
1342 | /* We really need the caller to normalize coordinates - if |
1426 | * we set the map, that doesn't work if the location is within |
1343 | * we set the map, that doesn't work if the location is within |
1427 | * a map and this is straddling an edge. So only if coordinate |
1344 | * a map and this is straddling an edge. So only if coordinate |
1428 | * is clear wrong do we normalize it. |
1345 | * is clear wrong do we normalize it. |
1429 | */ |
1346 | */ |
1430 | if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) |
1347 | if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) |
1431 | { |
|
|
1432 | more->map = get_map_from_coord (m, &more->x, &more->y); |
1348 | more->map = get_map_from_coord (m, &more->x, &more->y); |
1433 | } |
|
|
1434 | else if (!more->map) |
1349 | else if (!more->map) |
1435 | { |
1350 | { |
1436 | /* For backwards compatibility - when not dealing with tiled maps, |
1351 | /* For backwards compatibility - when not dealing with tiled maps, |
1437 | * more->map should always point to the parent. |
1352 | * more->map should always point to the parent. |
1438 | */ |
1353 | */ |
… | |
… | |
1441 | |
1356 | |
1442 | if (insert_ob_in_map (more, more->map, originator, flag) == NULL) |
1357 | if (insert_ob_in_map (more, more->map, originator, flag) == NULL) |
1443 | { |
1358 | { |
1444 | if (!op->head) |
1359 | if (!op->head) |
1445 | LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n"); |
1360 | LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n"); |
|
|
1361 | |
1446 | return NULL; |
1362 | return NULL; |
1447 | } |
1363 | } |
1448 | } |
1364 | } |
|
|
1365 | |
1449 | CLEAR_FLAG (op, FLAG_REMOVED); |
1366 | CLEAR_FLAG (op, FLAG_REMOVED); |
1450 | |
1367 | |
1451 | /* Ideally, the caller figures this out. However, it complicates a lot |
1368 | /* Ideally, the caller figures this out. However, it complicates a lot |
1452 | * of areas of callers (eg, anything that uses find_free_spot would now |
1369 | * of areas of callers (eg, anything that uses find_free_spot would now |
1453 | * need extra work |
1370 | * need extra work |
… | |
… | |
1457 | y = op->y; |
1374 | y = op->y; |
1458 | |
1375 | |
1459 | /* this has to be done after we translate the coordinates. |
1376 | /* this has to be done after we translate the coordinates. |
1460 | */ |
1377 | */ |
1461 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1378 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1462 | { |
|
|
1463 | for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) |
1379 | for (tmp = GET_MAP_OB (op->map, x, y); tmp != NULL; tmp = tmp->above) |
1464 | if (CAN_MERGE (op, tmp)) |
1380 | if (CAN_MERGE (op, tmp)) |
1465 | { |
1381 | { |
1466 | op->nrof += tmp->nrof; |
1382 | op->nrof += tmp->nrof; |
1467 | remove_ob (tmp); |
1383 | remove_ob (tmp); |
1468 | free_object (tmp); |
1384 | free_object (tmp); |
1469 | } |
1385 | } |
1470 | } |
|
|
1471 | |
1386 | |
1472 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1387 | CLEAR_FLAG (op, FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ |
1473 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
1388 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
|
|
1389 | |
1474 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1390 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1475 | CLEAR_FLAG (op, FLAG_NO_STEAL); |
1391 | CLEAR_FLAG (op, FLAG_NO_STEAL); |
1476 | |
1392 | |
1477 | if (flag & INS_BELOW_ORIGINATOR) |
1393 | if (flag & INS_BELOW_ORIGINATOR) |
1478 | { |
1394 | { |
1479 | if (originator->map != op->map || originator->x != op->x || originator->y != op->y) |
1395 | if (originator->map != op->map || originator->x != op->x || originator->y != op->y) |
1480 | { |
1396 | { |
1481 | LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); |
1397 | LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); |
1482 | abort (); |
1398 | abort (); |
1483 | } |
1399 | } |
|
|
1400 | |
1484 | op->above = originator; |
1401 | op->above = originator; |
1485 | op->below = originator->below; |
1402 | op->below = originator->below; |
|
|
1403 | |
1486 | if (op->below) |
1404 | if (op->below) |
1487 | op->below->above = op; |
1405 | op->below->above = op; |
1488 | else |
1406 | else |
1489 | SET_MAP_OB (op->map, op->x, op->y, op); |
1407 | SET_MAP_OB (op->map, op->x, op->y, op); |
|
|
1408 | |
1490 | /* since *below* originator, no need to update top */ |
1409 | /* since *below* originator, no need to update top */ |
1491 | originator->below = op; |
1410 | originator->below = op; |
1492 | } |
1411 | } |
1493 | else |
1412 | else |
1494 | { |
1413 | { |
1495 | /* If there are other objects, then */ |
1414 | /* If there are other objects, then */ |
1496 | if ((!(flag & INS_MAP_LOAD)) && ((top = GET_MAP_OB (op->map, op->x, op->y)) != NULL)) |
1415 | if ((!(flag & INS_MAP_LOAD)) && ((top = GET_MAP_OB (op->map, op->x, op->y)) != NULL)) |
1497 | { |
1416 | { |
1498 | object * |
|
|
1499 | last = NULL; |
1417 | object *last = NULL; |
1500 | |
1418 | |
1501 | /* |
1419 | /* |
1502 | * If there are multiple objects on this space, we do some trickier handling. |
1420 | * If there are multiple objects on this space, we do some trickier handling. |
1503 | * We've already dealt with merging if appropriate. |
1421 | * We've already dealt with merging if appropriate. |
1504 | * Generally, we want to put the new object on top. But if |
1422 | * Generally, we want to put the new object on top. But if |
… | |
… | |
1513 | |
1431 | |
1514 | while (top != NULL) |
1432 | while (top != NULL) |
1515 | { |
1433 | { |
1516 | if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) |
1434 | if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) |
1517 | floor = top; |
1435 | floor = top; |
|
|
1436 | |
1518 | if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) |
1437 | if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) |
1519 | { |
1438 | { |
1520 | /* We insert above top, so we want this object below this */ |
1439 | /* We insert above top, so we want this object below this */ |
1521 | top = top->below; |
1440 | top = top->below; |
1522 | break; |
1441 | break; |
1523 | } |
1442 | } |
|
|
1443 | |
1524 | last = top; |
1444 | last = top; |
1525 | top = top->above; |
1445 | top = top->above; |
1526 | } |
1446 | } |
|
|
1447 | |
1527 | /* Don't want top to be NULL, so set it to the last valid object */ |
1448 | /* Don't want top to be NULL, so set it to the last valid object */ |
1528 | top = last; |
1449 | top = last; |
1529 | |
1450 | |
1530 | /* We let update_position deal with figuring out what the space |
1451 | /* We let update_position deal with figuring out what the space |
1531 | * looks like instead of lots of conditions here. |
1452 | * looks like instead of lots of conditions here. |
… | |
… | |
1551 | */ |
1472 | */ |
1552 | if (last && last->below && last != floor) |
1473 | if (last && last->below && last != floor) |
1553 | top = last->below; |
1474 | top = last->below; |
1554 | } |
1475 | } |
1555 | } /* If objects on this space */ |
1476 | } /* If objects on this space */ |
|
|
1477 | |
1556 | if (flag & INS_MAP_LOAD) |
1478 | if (flag & INS_MAP_LOAD) |
1557 | top = GET_MAP_TOP (op->map, op->x, op->y); |
1479 | top = GET_MAP_TOP (op->map, op->x, op->y); |
|
|
1480 | |
1558 | if (flag & INS_ABOVE_FLOOR_ONLY) |
1481 | if (flag & INS_ABOVE_FLOOR_ONLY) |
1559 | top = floor; |
1482 | top = floor; |
1560 | |
1483 | |
1561 | /* Top is the object that our object (op) is going to get inserted above. |
1484 | /* Top is the object that our object (op) is going to get inserted above. |
1562 | */ |
1485 | */ |
1563 | |
1486 | |
1564 | /* First object on this space */ |
1487 | /* First object on this space */ |
1565 | if (!top) |
1488 | if (!top) |
1566 | { |
1489 | { |
1567 | op->above = GET_MAP_OB (op->map, op->x, op->y); |
1490 | op->above = GET_MAP_OB (op->map, op->x, op->y); |
|
|
1491 | |
1568 | if (op->above) |
1492 | if (op->above) |
1569 | op->above->below = op; |
1493 | op->above->below = op; |
|
|
1494 | |
1570 | op->below = NULL; |
1495 | op->below = NULL; |
1571 | SET_MAP_OB (op->map, op->x, op->y, op); |
1496 | SET_MAP_OB (op->map, op->x, op->y, op); |
1572 | } |
1497 | } |
1573 | else |
1498 | else |
1574 | { /* get inserted into the stack above top */ |
1499 | { /* get inserted into the stack above top */ |
1575 | op->above = top->above; |
1500 | op->above = top->above; |
|
|
1501 | |
1576 | if (op->above) |
1502 | if (op->above) |
1577 | op->above->below = op; |
1503 | op->above->below = op; |
|
|
1504 | |
1578 | op->below = top; |
1505 | op->below = top; |
1579 | top->above = op; |
1506 | top->above = op; |
1580 | } |
1507 | } |
|
|
1508 | |
1581 | if (op->above == NULL) |
1509 | if (op->above == NULL) |
1582 | SET_MAP_TOP (op->map, op->x, op->y, op); |
1510 | SET_MAP_TOP (op->map, op->x, op->y, op); |
1583 | } /* else not INS_BELOW_ORIGINATOR */ |
1511 | } /* else not INS_BELOW_ORIGINATOR */ |
1584 | |
1512 | |
1585 | if (op->type == PLAYER) |
1513 | if (op->type == PLAYER) |
… | |
… | |
1588 | /* If we have a floor, we know the player, if any, will be above |
1516 | /* If we have a floor, we know the player, if any, will be above |
1589 | * it, so save a few ticks and start from there. |
1517 | * it, so save a few ticks and start from there. |
1590 | */ |
1518 | */ |
1591 | if (!(flag & INS_MAP_LOAD)) |
1519 | if (!(flag & INS_MAP_LOAD)) |
1592 | for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1520 | for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1593 | { |
|
|
1594 | if (tmp->type == PLAYER) |
1521 | if (tmp->type == PLAYER) |
1595 | tmp->contr->socket.update_look = 1; |
1522 | tmp->contr->socket.update_look = 1; |
1596 | } |
|
|
1597 | |
1523 | |
1598 | /* If this object glows, it may affect lighting conditions that are |
1524 | /* If this object glows, it may affect lighting conditions that are |
1599 | * visible to others on this map. But update_all_los is really |
1525 | * visible to others on this map. But update_all_los is really |
1600 | * an inefficient way to do this, as it means los for all players |
1526 | * an inefficient way to do this, as it means los for all players |
1601 | * on the map will get recalculated. The players could very well |
1527 | * on the map will get recalculated. The players could very well |
… | |
… | |
1605 | * of effect may be sufficient. |
1531 | * of effect may be sufficient. |
1606 | */ |
1532 | */ |
1607 | if (MAP_DARKNESS (op->map) && (op->glow_radius != 0)) |
1533 | if (MAP_DARKNESS (op->map) && (op->glow_radius != 0)) |
1608 | update_all_los (op->map, op->x, op->y); |
1534 | update_all_los (op->map, op->x, op->y); |
1609 | |
1535 | |
1610 | |
|
|
1611 | /* updates flags (blocked, alive, no magic, etc) for this map space */ |
1536 | /* updates flags (blocked, alive, no magic, etc) for this map space */ |
1612 | update_object (op, UP_OBJ_INSERT); |
1537 | update_object (op, UP_OBJ_INSERT); |
1613 | |
|
|
1614 | |
1538 | |
1615 | /* Don't know if moving this to the end will break anything. However, |
1539 | /* Don't know if moving this to the end will break anything. However, |
1616 | * we want to have update_look set above before calling this. |
1540 | * we want to have update_look set above before calling this. |
1617 | * |
1541 | * |
1618 | * check_move_on() must be after this because code called from |
1542 | * check_move_on() must be after this because code called from |
… | |
… | |
1620 | * blocked() and wall() work properly), and these flags are updated by |
1544 | * blocked() and wall() work properly), and these flags are updated by |
1621 | * update_object(). |
1545 | * update_object(). |
1622 | */ |
1546 | */ |
1623 | |
1547 | |
1624 | /* if this is not the head or flag has been passed, don't check walk on status */ |
1548 | /* if this is not the head or flag has been passed, don't check walk on status */ |
1625 | |
|
|
1626 | if (!(flag & INS_NO_WALK_ON) && !op->head) |
1549 | if (!(flag & INS_NO_WALK_ON) && !op->head) |
1627 | { |
1550 | { |
1628 | if (check_move_on (op, originator)) |
1551 | if (check_move_on (op, originator)) |
1629 | return NULL; |
1552 | return NULL; |
1630 | |
1553 | |
… | |
… | |
1633 | */ |
1556 | */ |
1634 | for (tmp = op->more; tmp != NULL; tmp = tmp->more) |
1557 | for (tmp = op->more; tmp != NULL; tmp = tmp->more) |
1635 | if (check_move_on (tmp, originator)) |
1558 | if (check_move_on (tmp, originator)) |
1636 | return NULL; |
1559 | return NULL; |
1637 | } |
1560 | } |
|
|
1561 | |
1638 | return op; |
1562 | return op; |
1639 | } |
1563 | } |
1640 | |
1564 | |
1641 | /* this function inserts an object in the map, but if it |
1565 | /* this function inserts an object in the map, but if it |
1642 | * finds an object of its own type, it'll remove that one first. |
1566 | * finds an object of its own type, it'll remove that one first. |
… | |
… | |
1660 | free_object (tmp); |
1584 | free_object (tmp); |
1661 | } |
1585 | } |
1662 | } |
1586 | } |
1663 | |
1587 | |
1664 | tmp1 = arch_to_object (find_archetype (arch_string)); |
1588 | tmp1 = arch_to_object (find_archetype (arch_string)); |
1665 | |
|
|
1666 | |
1589 | |
1667 | tmp1->x = op->x; |
1590 | tmp1->x = op->x; |
1668 | tmp1->y = op->y; |
1591 | tmp1->y = op->y; |
1669 | insert_ob_in_map (tmp1, op->map, op, 0); |
1592 | insert_ob_in_map (tmp1, op->map, op, 0); |
1670 | } |
1593 | } |
… | |
… | |
1688 | if (orig_ob->nrof < nr) |
1611 | if (orig_ob->nrof < nr) |
1689 | { |
1612 | { |
1690 | sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name); |
1613 | sprintf (errmsg, "There are only %d %ss.", orig_ob->nrof ? orig_ob->nrof : 1, &orig_ob->name); |
1691 | return NULL; |
1614 | return NULL; |
1692 | } |
1615 | } |
|
|
1616 | |
1693 | newob = object_create_clone (orig_ob); |
1617 | newob = object_create_clone (orig_ob); |
|
|
1618 | |
1694 | if ((orig_ob->nrof -= nr) < 1) |
1619 | if ((orig_ob->nrof -= nr) < 1) |
1695 | { |
1620 | { |
1696 | if (!is_removed) |
1621 | if (!is_removed) |
1697 | remove_ob (orig_ob); |
1622 | remove_ob (orig_ob); |
1698 | free_object2 (orig_ob, 1); |
1623 | free_object2 (orig_ob, 1); |
… | |
… | |
1706 | strcpy (errmsg, "Tried to split object whose map is not in memory."); |
1631 | strcpy (errmsg, "Tried to split object whose map is not in memory."); |
1707 | LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); |
1632 | LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); |
1708 | return NULL; |
1633 | return NULL; |
1709 | } |
1634 | } |
1710 | } |
1635 | } |
|
|
1636 | |
1711 | newob->nrof = nr; |
1637 | newob->nrof = nr; |
1712 | |
1638 | |
1713 | return newob; |
1639 | return newob; |
1714 | } |
1640 | } |
1715 | |
1641 | |
… | |
… | |
1722 | */ |
1648 | */ |
1723 | |
1649 | |
1724 | object * |
1650 | object * |
1725 | decrease_ob_nr (object *op, uint32 i) |
1651 | decrease_ob_nr (object *op, uint32 i) |
1726 | { |
1652 | { |
1727 | object * |
1653 | object *tmp; |
1728 | tmp; |
|
|
1729 | player * |
1654 | player *pl; |
1730 | pl; |
|
|
1731 | |
1655 | |
1732 | if (i == 0) /* objects with op->nrof require this check */ |
1656 | if (i == 0) /* objects with op->nrof require this check */ |
1733 | return op; |
1657 | return op; |
1734 | |
1658 | |
1735 | if (i > op->nrof) |
1659 | if (i > op->nrof) |
1736 | i = op->nrof; |
1660 | i = op->nrof; |
1737 | |
1661 | |
1738 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1662 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1739 | { |
|
|
1740 | op->nrof -= i; |
1663 | op->nrof -= i; |
1741 | } |
|
|
1742 | else if (op->env != NULL) |
1664 | else if (op->env != NULL) |
1743 | { |
1665 | { |
1744 | /* is this object in the players inventory, or sub container |
1666 | /* is this object in the players inventory, or sub container |
1745 | * therein? |
1667 | * therein? |
1746 | */ |
1668 | */ |
… | |
… | |
1781 | } |
1703 | } |
1782 | } |
1704 | } |
1783 | } |
1705 | } |
1784 | else |
1706 | else |
1785 | { |
1707 | { |
1786 | object * |
|
|
1787 | above = op->above; |
1708 | object *above = op->above; |
1788 | |
1709 | |
1789 | if (i < op->nrof) |
1710 | if (i < op->nrof) |
1790 | { |
|
|
1791 | op->nrof -= i; |
1711 | op->nrof -= i; |
1792 | } |
|
|
1793 | else |
1712 | else |
1794 | { |
1713 | { |
1795 | remove_ob (op); |
1714 | remove_ob (op); |
1796 | op->nrof = 0; |
1715 | op->nrof = 0; |
1797 | } |
1716 | } |
|
|
1717 | |
1798 | /* Since we just removed op, op->above is null */ |
1718 | /* Since we just removed op, op->above is null */ |
1799 | for (tmp = above; tmp != NULL; tmp = tmp->above) |
1719 | for (tmp = above; tmp != NULL; tmp = tmp->above) |
1800 | if (tmp->type == PLAYER) |
1720 | if (tmp->type == PLAYER) |
1801 | { |
1721 | { |
1802 | if (op->nrof) |
1722 | if (op->nrof) |
… | |
… | |
1805 | esrv_del_item (tmp->contr, op->count); |
1725 | esrv_del_item (tmp->contr, op->count); |
1806 | } |
1726 | } |
1807 | } |
1727 | } |
1808 | |
1728 | |
1809 | if (op->nrof) |
1729 | if (op->nrof) |
1810 | { |
|
|
1811 | return op; |
1730 | return op; |
1812 | } |
|
|
1813 | else |
1731 | else |
1814 | { |
1732 | { |
1815 | free_object (op); |
1733 | free_object (op); |
1816 | return NULL; |
1734 | return NULL; |
1817 | } |
1735 | } |
… | |
… | |
1826 | add_weight (object *op, signed long weight) |
1744 | add_weight (object *op, signed long weight) |
1827 | { |
1745 | { |
1828 | while (op != NULL) |
1746 | while (op != NULL) |
1829 | { |
1747 | { |
1830 | if (op->type == CONTAINER) |
1748 | if (op->type == CONTAINER) |
1831 | { |
|
|
1832 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1749 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1833 | } |
1750 | |
1834 | op->carrying += weight; |
1751 | op->carrying += weight; |
1835 | op = op->env; |
1752 | op = op->env; |
1836 | } |
1753 | } |
1837 | } |
1754 | } |
1838 | |
1755 | |
… | |
… | |
1861 | { |
1778 | { |
1862 | dump_object (op); |
1779 | dump_object (op); |
1863 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); |
1780 | LOG (llevError, "Trying to insert (ob) inserted object.\n%s\n", errmsg); |
1864 | return op; |
1781 | return op; |
1865 | } |
1782 | } |
|
|
1783 | |
1866 | if (where == NULL) |
1784 | if (where == NULL) |
1867 | { |
1785 | { |
1868 | dump_object (op); |
1786 | dump_object (op); |
1869 | LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); |
1787 | LOG (llevError, "Trying to put object in NULL.\n%s\n", errmsg); |
1870 | return op; |
1788 | return op; |
1871 | } |
1789 | } |
|
|
1790 | |
1872 | if (where->head) |
1791 | if (where->head) |
1873 | { |
1792 | { |
1874 | LOG (llevDebug, "Warning: Tried to insert object wrong part of multipart object.\n"); |
1793 | LOG (llevDebug, "Warning: Tried to insert object wrong part of multipart object.\n"); |
1875 | where = where->head; |
1794 | where = where->head; |
1876 | } |
1795 | } |
|
|
1796 | |
1877 | if (op->more) |
1797 | if (op->more) |
1878 | { |
1798 | { |
1879 | LOG (llevError, "Tried to insert multipart object %s (%d)\n", &op->name, op->count); |
1799 | LOG (llevError, "Tried to insert multipart object %s (%d)\n", &op->name, op->count); |
1880 | return op; |
1800 | return op; |
1881 | } |
1801 | } |
|
|
1802 | |
1882 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1803 | CLEAR_FLAG (op, FLAG_OBJ_ORIGINAL); |
1883 | CLEAR_FLAG (op, FLAG_REMOVED); |
1804 | CLEAR_FLAG (op, FLAG_REMOVED); |
1884 | if (op->nrof) |
1805 | if (op->nrof) |
1885 | { |
1806 | { |
1886 | for (tmp = where->inv; tmp != NULL; tmp = tmp->below) |
1807 | for (tmp = where->inv; tmp != NULL; tmp = tmp->below) |
… | |
… | |
1979 | tag; |
1900 | tag; |
1980 | mapstruct * |
1901 | mapstruct * |
1981 | m = op->map; |
1902 | m = op->map; |
1982 | int |
1903 | int |
1983 | x = op->x, y = op->y; |
1904 | x = op->x, y = op->y; |
|
|
1905 | |
1984 | MoveType |
1906 | MoveType |
1985 | move_on, |
1907 | move_on, |
1986 | move_slow, |
1908 | move_slow, |
1987 | move_block; |
1909 | move_block; |
1988 | |
1910 | |
… | |
… | |
2022 | * we don't need to check all of them. |
1944 | * we don't need to check all of them. |
2023 | */ |
1945 | */ |
2024 | if ((tmp->move_type & MOVE_FLY_LOW) && QUERY_FLAG (tmp, FLAG_NO_PICK)) |
1946 | if ((tmp->move_type & MOVE_FLY_LOW) && QUERY_FLAG (tmp, FLAG_NO_PICK)) |
2025 | break; |
1947 | break; |
2026 | } |
1948 | } |
|
|
1949 | |
2027 | for (; tmp != NULL; tmp = tmp->below) |
1950 | for (; tmp; tmp = tmp->below) |
2028 | { |
1951 | { |
2029 | if (tmp == op) |
1952 | if (tmp == op) |
2030 | continue; /* Can't apply yourself */ |
1953 | continue; /* Can't apply yourself */ |
2031 | |
1954 | |
2032 | /* Check to see if one of the movement types should be slowed down. |
1955 | /* Check to see if one of the movement types should be slowed down. |
… | |
… | |
2040 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
1963 | if ((!op->move_type && tmp->move_slow & MOVE_WALK) || |
2041 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
1964 | ((op->move_type & tmp->move_slow) && (op->move_type & ~tmp->move_slow & ~tmp->move_block) == 0)) |
2042 | { |
1965 | { |
2043 | |
1966 | |
2044 | float |
1967 | float |
2045 | diff; |
|
|
2046 | |
|
|
2047 | diff = tmp->move_slow_penalty * FABS (op->speed); |
1968 | diff = tmp->move_slow_penalty * FABS (op->speed); |
|
|
1969 | |
2048 | if (op->type == PLAYER) |
1970 | if (op->type == PLAYER) |
2049 | { |
|
|
2050 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
1971 | if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || |
2051 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
1972 | (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) |
2052 | { |
|
|
2053 | diff /= 4.0; |
1973 | diff /= 4.0; |
2054 | } |
1974 | |
2055 | } |
|
|
2056 | op->speed_left -= diff; |
1975 | op->speed_left -= diff; |
2057 | } |
1976 | } |
2058 | } |
1977 | } |
2059 | |
1978 | |
2060 | /* Basically same logic as above, except now for actual apply. */ |
1979 | /* Basically same logic as above, except now for actual apply. */ |
2061 | if ((!op->move_type && tmp->move_on & MOVE_WALK) || |
1980 | if ((!op->move_type && tmp->move_on & MOVE_WALK) || |
2062 | ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) |
1981 | ((op->move_type & tmp->move_on) && (op->move_type & ~tmp->move_on & ~tmp->move_block) == 0)) |
2063 | { |
1982 | { |
2064 | |
|
|
2065 | move_apply (tmp, op, originator); |
1983 | move_apply (tmp, op, originator); |
|
|
1984 | |
2066 | if (was_destroyed (op, tag)) |
1985 | if (was_destroyed (op, tag)) |
2067 | return 1; |
1986 | return 1; |
2068 | |
1987 | |
2069 | /* what the person/creature stepped onto has moved the object |
1988 | /* what the person/creature stepped onto has moved the object |
2070 | * someplace new. Don't process any further - if we did, |
1989 | * someplace new. Don't process any further - if we did, |
… | |
… | |
2072 | */ |
1991 | */ |
2073 | if (op->map != m || op->x != x || op->y != y) |
1992 | if (op->map != m || op->x != x || op->y != y) |
2074 | return 0; |
1993 | return 0; |
2075 | } |
1994 | } |
2076 | } |
1995 | } |
|
|
1996 | |
2077 | return 0; |
1997 | return 0; |
2078 | } |
1998 | } |
2079 | |
1999 | |
2080 | /* |
2000 | /* |
2081 | * present_arch(arch, map, x, y) searches for any objects with |
2001 | * present_arch(arch, map, x, y) searches for any objects with |
… | |
… | |
2372 | find_dir (mapstruct *m, int x, int y, object *exclude) |
2292 | find_dir (mapstruct *m, int x, int y, object *exclude) |
2373 | { |
2293 | { |
2374 | int |
2294 | int |
2375 | i, |
2295 | i, |
2376 | max = SIZEOFFREE, mflags; |
2296 | max = SIZEOFFREE, mflags; |
2377 | sint16 |
2297 | |
2378 | nx, |
2298 | sint16 nx, ny; |
2379 | ny; |
|
|
2380 | object * |
2299 | object * |
2381 | tmp; |
2300 | tmp; |
2382 | mapstruct * |
2301 | mapstruct * |
2383 | mp; |
2302 | mp; |
2384 | MoveType |
2303 | |
2385 | blocked, |
2304 | MoveType blocked, move_type; |
2386 | move_type; |
|
|
2387 | |
2305 | |
2388 | if (exclude && exclude->head) |
2306 | if (exclude && exclude->head) |
2389 | { |
2307 | { |
2390 | exclude = exclude->head; |
2308 | exclude = exclude->head; |
2391 | move_type = exclude->move_type; |
2309 | move_type = exclude->move_type; |
… | |
… | |
2598 | |
2516 | |
2599 | |
2517 | |
2600 | int |
2518 | int |
2601 | can_see_monsterP (mapstruct *m, int x, int y, int dir) |
2519 | can_see_monsterP (mapstruct *m, int x, int y, int dir) |
2602 | { |
2520 | { |
2603 | sint16 |
2521 | sint16 dx, dy; |
2604 | dx, |
|
|
2605 | dy; |
|
|
2606 | int |
2522 | int |
2607 | mflags; |
2523 | mflags; |
2608 | |
2524 | |
2609 | if (dir < 0) |
2525 | if (dir < 0) |
2610 | return 0; /* exit condition: invalid direction */ |
2526 | return 0; /* exit condition: invalid direction */ |
… | |
… | |
2741 | fprintf (tempfile, obstr); |
2657 | fprintf (tempfile, obstr); |
2742 | fclose (tempfile); |
2658 | fclose (tempfile); |
2743 | |
2659 | |
2744 | op = get_object (); |
2660 | op = get_object (); |
2745 | |
2661 | |
2746 | object_thawer |
2662 | object_thawer thawer (filename); |
2747 | thawer (filename); |
|
|
2748 | |
2663 | |
2749 | if (thawer) |
2664 | if (thawer) |
2750 | load_object (thawer, op, 0); |
2665 | load_object (thawer, op, 0); |
2751 | |
2666 | |
2752 | LOG (llevDebug, " load str completed, object=%s\n", &op->name); |
2667 | LOG (llevDebug, " load str completed, object=%s\n", &op->name); |
… | |
… | |
2876 | if (last) |
2791 | if (last) |
2877 | last->next = field->next; |
2792 | last->next = field->next; |
2878 | else |
2793 | else |
2879 | op->key_values = field->next; |
2794 | op->key_values = field->next; |
2880 | |
2795 | |
2881 | delete |
|
|
2882 | field; |
2796 | delete field; |
2883 | } |
2797 | } |
2884 | } |
2798 | } |
2885 | return TRUE; |
2799 | return TRUE; |
2886 | } |
2800 | } |
2887 | /* IF we get here, key doesn't exist */ |
2801 | /* IF we get here, key doesn't exist */ |
… | |
… | |
2922 | * Returns TRUE on success. |
2836 | * Returns TRUE on success. |
2923 | */ |
2837 | */ |
2924 | int |
2838 | int |
2925 | set_ob_key_value (object *op, const char *key, const char *value, int add_key) |
2839 | set_ob_key_value (object *op, const char *key, const char *value, int add_key) |
2926 | { |
2840 | { |
2927 | shstr |
|
|
2928 | key_ (key); |
2841 | shstr key_ (key); |
2929 | |
2842 | |
2930 | return set_ob_key_value_s (op, key_, value, add_key); |
2843 | return set_ob_key_value_s (op, key_, value, add_key); |
2931 | } |
2844 | } |