Page 1 of 1

CheckReach bug

Posted: Mon Jan 23, 2012 11:06 pm
by loafingcoyote
CheckReach, in hugolib.h, has difficulty dealing with components. If the player's reach is limited, they'll be told that they can't reach the component even if they are holding the item which the component is part_of. This is also true if the item is in an accessible object. The changes to CheckReach below, authored by Roody, appear to fix the problem.

Code: Select all

replace CheckReach(obj)
{
   local i
   
   if not obj or obj = parent(player)
      return true
   
#ifclear NO_VERBS
   if (verbroutine ~= &DoLook, &DoLookIn) and parent(object) and
      parent(object) ~= player and
      parent(object) is transparent and parent(object) is not open and
      parent(object) is not living
   {
      VMessage(&DoGet, 5)     ! "X is closed."
      return false
   }
#endif

   if not parent(player).reach or
      Contains(parent(player), obj) or   ! is the object in the same object as the player
      Contains(parent(player), obj.part_of)  ! is the object part of something in the same place
      return true

#ifclear NO_VERBS
   if parent(obj) is living
   {
      if verbroutine ~= &DoGet, &DoLook

         ! "Except that X has it..."
         Message(&CheckReach, 1, obj)

      elseif verbroutine = &DoGet and parent(obj) is unfriendly

         ! "Except that X doesn't want to give it to you..."
         Message(&CheckReach, 2, obj)
   }
#endif

   for &#40;i=1; i<=parent&#40;player&#41;.#reach; i++&#41;
   &#123;
     if Contains&#40;parent&#40;player&#41;.reach #i, obj&#41; or   ! is the object inside a reach object
          Contains&#40;parent&#40;player&#41;.reach #i, obj.part_of&#41; or ! is the object part of an object inside the reach object
          obj = parent&#40;player&#41;.reach #i  or  ! is the object a reach object
          obj.part_of = parent&#40;player&#41;.reach #i ! is the object part of a reach object
      &#123;
         return true
      &#125;
   &#125;
   
#ifset USE_ATTACHABLES
   if parent&#40;player&#41;.type = attachable
   &#123;
      if InList&#40;parent&#40;player&#41;, attached_to, obj&#41;
         return true
   &#125;
   if obj.type = attachable
   &#123;
      if InList&#40;obj, attached_to, parent&#40;player&#41;&#41;
         return true
   &#125;
#endif

   ! "You can't reach it..."
   Message&#40;&CheckReach, 3, obj&#41;
&#125;