storm-engine icon indicating copy to clipboard operation
storm-engine copied to clipboard

Strange code when creating ships

Open Hammie opened this issue 2 years ago • 6 comments

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

https://github.com/storm-devs/storm-engine/blob/ee274cc0789fac2d7a2766cab378ec3c8316d075/src/libs/ship/src/ship.cpp#L1937-L1942

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?

Hammie avatar Apr 14 '23 17:04 Hammie

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.

espkk avatar Apr 14 '23 17:04 espkk

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.

Hammie avatar Apr 14 '23 17:04 Hammie

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

espkk avatar Apr 14 '23 17:04 espkk

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.

Hammie avatar Apr 14 '23 17:04 Hammie

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 avatar Apr 14 '23 18:04 espkk

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

espkk avatar Apr 14 '23 18:04 espkk