Author Topic: Bug in DELETE_WORLDMAP_LINKS  (Read 1423 times)

Offline DavidW

  • Planewalker
  • *****
  • Posts: 316
Bug in DELETE_WORLDMAP_LINKS
« on: July 20, 2019, 04:05:28 AM »
There is a subtle bug in DELETE_WORLDMAP_LINKS which means it doesn't work correctly if there are multiple links between the same areas at the same direction node.

(Which, yes, should never happen, but it does, even in the vanilla game: look at the North set of links from AR6400.)

The offending bit of code is (worldmap_links.tpa line 71 et seq.):

Code: [Select]
    PATCH_FOR_EACH node IN 0 3 2 1 BEGIN
      io = lao + 0x50 + 0x8 * node
      no = lao + 0x54 + 0x8 * node
      WRITE_LONG io links
      READ_LONG no number
      PATCH_IF "%source_name%" STRING_EQUAL_CASE "%from_area%" AND
               (source_node = node OR source_node = fl#SOURCE_NODE_DEFAULT)
      BEGIN
        FOR (j = 0; j < number; ++j) BEGIN
          llo = lo + 0xd8 * (links + j)
          READ_ASCII ao + 0xf0 * (LONG_AT llo) target_name
          PATCH_IF "%target_name%" STRING_EQUAL_CASE "%to_area%" BEGIN
            DELETE_BYTES llo 0xd8
            --number
          END
        END
      END
      WRITE_LONG no number
      links += number
    END

This fixes it:

Code: [Select]
    PATCH_FOR_EACH node IN 0 3 2 1 BEGIN
      io = lao + 0x50 + 0x8 * node
      no = lao + 0x54 + 0x8 * node
      ndel=0
      WRITE_LONG io links
      READ_LONG no number
      PATCH_IF "%source_name%" STRING_EQUAL_CASE "%from_area%" AND
               (source_node = node OR source_node = fl#SOURCE_NODE_DEFAULT)
      BEGIN
        FOR (j = 0; j < number; ++j) BEGIN
          ncurrent = j - ndel
          llo = lo + 0xd8 * (links + ncurrent)
          READ_ASCII ao + 0xf0 * (LONG_AT llo) target_name
          PATCH_IF "%target_name%" STRING_EQUAL_CASE "%to_area%" BEGIN
            DELETE_BYTES llo 0xd8
            ndel +=1
          END
        END
      END
      WRITE_LONG no ( number - ndel)
      links += (number - ndel)
    END

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1176
Re: Bug in DELETE_WORLDMAP_LINKS
« Reply #1 on: July 21, 2019, 03:05:51 PM »
Oh, that old chestnut. My bad; will fix.

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: