ISOR3X / pawn-editor

5 stars 5 forks source link

Loading a copy of a pawn results in a pawn with the same ID. #109

Closed Demid65 closed 6 months ago

Demid65 commented 6 months ago

Added a fix for the issue with duplicate ThingID on pawn loading. Additionally, clearing the relations for the loaded pawn on collision, to prevent broken relations.

ISOR3X commented 6 months ago

I appreciate you taking the time to solve this issue. However I can't necessarily recreate the bug. Loading a pawn twice doesn't result in any errors for me. Could you give some more information on what is exactly breaking and how to reproduce this?

sharkman commented 6 months ago

Well, it will help in general, but it needs to be systematically fixed for all things, not just pawns, because it does not fix #91 for me. Also save game have a huge next ids section, I suggest you to use this instead doing +1

    <uniqueIDsManager>
      <nextThingID>264429</nextThingID>
      <nextBillID>8</nextBillID>
      <nextFactionID>20</nextFactionID>
      <nextLordID>62</nextLordID>
      <nextTaleID>3440</nextTaleID>
      <nextPassingShipID>4</nextPassingShipID>
      <nextWorldObjectID>57</nextWorldObjectID>
      <nextMapID>6</nextMapID>
      <nextCaravanID>11</nextCaravanID>
      <nextAreaID>36</nextAreaID>
      <nextTransporterGroupID>11</nextTransporterGroupID>
      <nextAncientCryptosleepCasketGroupID>1</nextAncientCryptosleepCasketGroupID>
      <nextJobID>941329</nextJobID>
      <nextSignalTagID>1</nextSignalTagID>
      <nextWorldFeatureID>4</nextWorldFeatureID>
      <nextHediffID>8135</nextHediffID>
      <nextBattleID>106</nextBattleID>
      <nextLogID>19830</nextLogID>
      <nextLetterID>256</nextLetterID>
      <nextArchivedDialogID>2</nextArchivedDialogID>
      <nextMessageID>1716</nextMessageID>
      <nextZoneID>4</nextZoneID>
      <nextQuestID>31</nextQuestID>
      <nextGameConditionID>10</nextGameConditionID>
      <nextIdeoID>14</nextIdeoID>
      <nextPreceptID>832</nextPreceptID>
      <nextPresenceDemandID>28</nextPresenceDemandID>
      <nextTransportShipID>18</nextTransportShipID>
      <nextShipJobID>65</nextShipJobID>
      <nextAbilityID>589</nextAbilityID>
      <nextGeneID>6488</nextGeneID>
      <nextStorageGroupID>10</nextStorageGroupID>
    </uniqueIDsManager>
sharkman commented 6 months ago

Fox example: psy abilities inside the pawn def have it's own ids. Hediffs inside the pawn def have it's own ids. Equipment inside the pawn def have it's own ids, etc... All those things are being copied and need to be renumbered recursively on load/copy.

sharkman commented 6 months ago

Specifically for psy abilities: when you have a copy of a pawn with psy abilities, only one pawn can use them. All the copies will fail to do so and/or cast the ability as if it was done by the initial pawn.

ISOR3X commented 6 months ago

Theoretically these issues sounds far, but I am just unable to reproduce it. I've tried doing the following;

  1. Creating a pawn with a psycast in a new save. Then saving this pawn.
  2. Loading up a new game and loading the saved pawn twice.
  3. Casting the psycast with both of the loaded pawns, one after another.

This results in no issues and both seem to cast their own psycast.

image

sharkman commented 6 months ago

Your order is off, you need to:

  1. Create a new pawn in your editor.
  2. Add all needed psycasts/hediffs/equipment to a pawn.
  3. Duplicate a pawn a couple of times (you can save/load it does not matter).

That is it, after that just continue playing, save/load, try to cast psycasts on different pawns, you'll see weird stuff I've described. Also red errors will begin to emerge at some point saying it can't find some objects or objects have the same ids. Broken save (rename to report_test_01.rws): report_test_01.txt

Demid65 commented 6 months ago

I appreciate you taking the time to solve this issue. However I can't necessarily recreate the bug. Loading a pawn twice doesn't result in any errors for me. Could you give some more information on what is exactly breaking and how to reproduce this?

As I stated before:

  1. Create a loadout of 2 pawns: A and B
  2. Save pawn A and load it as a new pawn, let's call this pawn A2
  3. Add any relation between pawn A2 and B, let's say it's a lover relation.
  4. Save and load the entire starting preset.
  5. You will see that this relation got corrupted:
  6. A2 loves B, just as normal, but B loves A, not A2

This happens because A and A2 have identical ThingID and relations are resolved trough ThingID. Same thing happens with sharkman, but with psycasts and abilities, which also have their IDs.

The fix I provided solves the issue with Pawn.ThingID but does not do anything for psycasts or other things.

Demid65 commented 6 months ago

Well, it will help in general, but it needs to be systematically fixed for all things, not just pawns, because it does not fix #91 for me. Also save game have a huge next ids section, I suggest you to use this instead doing +1

I will take a look at that.

ISOR3X commented 6 months ago

I think I managed to reproduce it, but seems like there's a lot more weird stuff going on. I'm going to have to take a deeper look into the whole saving/loading. Sorry for all the trouble.

sharkman commented 6 months ago

@ISOR3X I'm glad you managed to reproduce it. Just remember that all IDs in the game are supposed to be unique, must be unique even. When a game encounters an ID collision it does not know what to do, which results in weird behaviour. At first, it looks like it continues to function with ID collision, but at some point, usually at save/load, or quest/relation generation, it will fail, which will be indicated in the console.

Demid65 commented 6 months ago

Closing the pull request, since we would need a better solution that the one I provided.