There is not much code, you can describe it as your own function (translate pseudocode in C/C++)
You can analyze the function in which this section is located, it is possible to call the upper function with certain parameters, which guarantees that this piece of code is called and only it is called
Here is a translation example, simple and straightforward:
https://github.com/damage99/libcod/b...layer.cpp#L830
If you need to replace only a piece of code, but leave the main function unchanged, then the simplest options are to analyze the conditions and, if they match (this subroutine is called in the original) - replace it with a function call that you translated from pseudocode; if the conditions are different, just call the original function
*like this:
https://github.com/damage99/libcod/b...ibcod.cpp#L139
: only you need to analyze the input arguments of this function, when you understand that the required subroutine should be called, then call reworked_func(), if not, then call original_func()