b-casey / OpenSMACX

A project to decompile SMAC/X to C++ with the long term goal of creating a full open source clone.
GNU General Public License v3.0
52 stars 4 forks source link

AI base function incorrectly using negative queue id in logic #28

Open b-casey opened 3 years ago

b-casey commented 3 years ago

As part of the code restyle, I've been setting stricter parameter variable types. An example of this would be setting a parameter to unsigned if it's directly accessing various structs without any checks or handling for a negative value.

When running some regression tests, I noticed has_abil() was crashing when the 1st prototype parameter is unsigned. Since it's directly accessing VehPrototype right off the bat, it shouldn't be signed/negative. I traced the issue to the large base_build() function used by the AI to make decisions on what to build. The issue is how it's pulling a value from the base queue where it's stored as a negative value then interacting with VehPrototype to get triad information as well as passing the same negative value to has_abil().

For now, I've added a temporary work around that will return false if a negative parameter is passed to has_abil(). Eventually, once the code in base_build is fixed, there won't be a need. There will likely be other bugs uncovered from stricter type enforcement that were silently failing or causing problems.

base_build()