Because of the heavy usage of this function in objects.cpp and the mixed use of aliases and direct references to the active object in Operate*Door functions I've done some refactoring of those areas beyond what is strictly necessary. Hopefully this makes sense and is reasonable to include in this change.
* Refactor GetRotaryDistance to use Point instead of int x/y params
* Refactor HSExists to use Point instead of int x/y params
* Refactor IsPathBlocked to take typed params (Point, Direction)
The caller was already passing in a Direction value so this matches usage better. I also pulled the Direction to Point helper function up so it is available as a static class member, this allows replacing the use of the Offset array in plrctrls.cpp.
When adding a Direction to a point (and not scaling it first) I avoid explicitly creating a Point object since the operator+ overload will do that conversion implicitly.
* Replace Offsets array with Point::fromDirection
* Refactor GetDistanceRanged to use Point
I've added ExactDistance as a member function of Point to match ApproxDistance instead of only having it defined in GetDistanceRanged, it seemed more appropriate to be part of the class. Also removed temporary variables from callers of GetDistanceRanged as they were mainly used as a convenience for avoiding repetition when passing values into this function.
* Refactor GetDistance to use Point
Added overload for DrawString taking a Point to avoid creating a rect for callers which only use position. This also documents the way DrawString operates when passed a clipping rectangle with a dimension of 0.
As part of this overload removed the logic for 0 width regions from DrawString. This does change the behaviour of the Rectangle version if called with a rect with width 0, all callers using that behaviour have been updated in this commit.
Using Rectangle/Size allowed simplifying the logic for certain calls where they could use DrawText alignment flags, previously this was manually aligning by calculating dimensions and offsetting the position. This also fixes#2169
Also includes a few instances where a temporary buffer was used to set the text to be drawn with unbounded sprintf calls, replaced those with snprintf as is recommended in modern C applications. Moving to C++ strings would be good in a future refactor.
1. Rename `CelGetFrameStart` to `CelGetFrame`, in line with the other 2
functions with the same name and load the `uint32_t` safely.
2. Remove redundant `FrameHeader`, simply use `LoadLE16`.
3. Document all the functions.
Hoping to add a few tests for normal operation as a sanity check. The eventual goal is to be able to split the distribution functions from the engine so they can be tested and implemented independently.
This is recommended for GTest and is a requirement to use FRIEND_TEST (see http://google.github.io/googletest/reference/testing.html#FRIEND_TEST). If the random number generator code becomes a class with private attributes this allows us to switch to test fixtures more easily.