Cataclysm-DDA icon indicating copy to clipboard operation
Cataclysm-DDA copied to clipboard

tidy up fault code a bit

Open GuardianDll opened this issue 1 year ago • 2 comments

Summary

None

Purpose of change

Code i made in #74696 is... not good

Describe the solution

This tries to clean it up a bit, and also resolves the problem of function applying the first fault it finds instead of random one

Testing

I shoot a gun and was able to apply more than 1 type of fault image image image

GuardianDll avatar Sep 09 '24 17:09 GuardianDll

🤔 IDK the old code seemed pretty fine to me? The new code is almost strictly less efficient (although in practice it doesn't matter) and not really cleaner.

You could maybe make the random_fault_of_type a static helper in item.cpp

Does faults_potential_of_type have to return a set (can there be duplicate entries in type->faults), or can it be a vector which is generally cheaper?

akrieger avatar Sep 09 '24 21:09 akrieger

it is cleaner in a sense that instead of calling faults:: and shoving both item and fault type, you instead call item and shove only fault type

I could, if i knew what static helper is and how to make it :)

No, it can return a vector, array of faults in item should not repeat

GuardianDll avatar Sep 10 '24 06:09 GuardianDll