in0finite / SanAndreasUnity

Open source reimplementation of GTA San Andreas game engine in Unity
https://discord.gg/p6jjud5
MIT License
2.1k stars 348 forks source link

Implemented extra components selection for vehicles #135

Closed GoverLabs closed 2 years ago

GoverLabs commented 2 years ago

As was noted at #86 , some vehicles have extra componets, which are being selected by a few different rules. Since the original impementations of those tricky rules used some bit operations, I used this a reversed implementation as a cheat-sheet (see ::ChooseComponent method at gta_reversed

Now it works fine, and selects extra compontents according to rules explained in the topic: https://gtaforums.com/topic/530575-tutcomponent-rules/ The only exception is that rules should also consider current weather, which is not currenty implemented in the project.

As a possible improvement int can be replaced by bytes in my union-like struct, to save some memory. Unfortunately, I found no obvious way to work with separate 4 bits in C#, only with bytes, which are not really useful to parse values like 2ff0

GoverLabs commented 2 years ago

Fixed issues, specified at review

in0finite commented 2 years ago

I just tested it and I think it still doesn't work correctly. For some vehicles (MULE, BENSON, MESAA, SUPERGT), extras are always disabled.

However, I will merge this PR now, and we can work on this later ...

GoverLabs commented 2 years ago

I found one more copy-paste mistake, firstExtraIdx is being assigned twice in SelectExtras(). Sorry for that. And yes, some vehicles really have disabled extras, and their CompRules are 0 in vehicles.ide. I will try to find out more, but until your comment I expected there should be a non-zero value for extra selection.

in0finite commented 2 years ago

Alright, if you fix the issue, feel free to open another PR :)