Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Strange code when creating ships #479

Open
Hammie opened this issue Apr 14, 2023 · 6 comments
Open

Strange code when creating ships #479

Hammie opened this issue Apr 14, 2023 · 6 comments

Comments

@Hammie
Copy link
Member

Hammie commented Apr 14, 2023

When executing MSG_SHIP_CREATE the following bit of code is getting run:

if (pAP && pAP->GetAttributeAsDword("index", -1) >= 0)
{
auto pVDat = static_cast<VDATA *>(core.GetScriptVariable("Characters"));
if (pVDat)
pVDat->Set(GetId(), pAP->GetAttributeAsDword("index", 0));
}

Which appears to be replacing the entry for the character data with the character index?!?

Anyone has any idea why or how this is ever needed?

@espkk
Copy link
Member

espkk commented Apr 14, 2023

It looks like a hack to update "expired" Characters array, possibly to clean up old phantoms
Do you have any issues with that code? If we remove this, I'm afraid SLIB and later phantoms mechanics can be broken.

@Hammie
Copy link
Member Author

Hammie commented Apr 14, 2023

There is a bug in New Horizons that happens when ships are recreated when in a coastal locations (ships are spawned in the background), that causes the player character entry to be deleted (as the player ship is also recreated).

For now I think I'm going to disable this code in a New Horizons-specific branch and see how it goes.

@espkk
Copy link
Member

espkk commented Apr 14, 2023

Does SD2/NH use phantoms? if not, that probably should be safe. Honestly, I would move such code into the scripts even if it's needed

By the way, you can also "fix" that from NH scripts by removing index property from generated characters

@Hammie
Copy link
Member Author

Hammie commented Apr 14, 2023

If by phantoms you mean generated characters that are temporary with recycled ids, then yes.

The biggest problem is that the main character also has an index property. And changing that will probably require some wide refactoring.

@espkk
Copy link
Member

espkk commented Apr 14, 2023

If by phantoms you mean generated characters that are temporary with recycled ids, then yes.

The biggest problem is that the main character also has an index property. And changing that will probably require some wide refactoring.

Main character should always have 0 index, while some generated characters seem to also have 0 index which is not okay
But to be honest I still don't understand how this leads to erasing an entity. Does rewriting an Object automatically calls DeleteClass on it?

@espkk
Copy link
Member

espkk commented Apr 14, 2023

Also, recently I discovered an old bug that leads to similar issues e.g. when spawning sailors. Let me know if disabling that code won't help. I'll try to find it, I think I fixed it locally

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants