Many vectors, including almost all velocity vectors, have magnitude less than 1, so truncating them to an int is very unhelpful. Currently, this has to be worked around by using (sysVectorMultiply) with a large constant, then dividing the magnitude of the result.

0xabcdef 23 Jul 2017:

Essentially any function that could be more useful if it returned a double value should return one.

Here is a suggested edit to the engine code. If all functions are able to accept numbers as double values (truncating to integer if necessary), then this should not break almost any of the existing code.

https://github.com/INeedAUniqueUsername/Mammoth/commit/a2b956433ae45da3db6636e4f3a4cd33ca88fed8

nms 23 Jul 2017:

Thanks for finding that, but I realized there actually are some issues. Particularly, what if the result is being inserted into a string? "We've located the target approximately 346.09327894562890478927 light seconds away."

I see a few options:

  • Change the (sysVectorDistance) to return a double, as you did. Also remove the + 0.5, which is for making it round to nearest, rather than truncate. Go through the places it's used in core and apply (mathRound) to the result where needed. Mention it in the API, but leave it to mod creators to do the same fix if needed.
  • Same as above, but maintain the old behavior for older API versions. I'm not quite sure how this works though. Does the game look at the API version of the file where the code is located?
  • Add another optional argument (of a different type, like string) to make it return a double. This maintains compatibility of all existing code, but leaves us with a function that works a bit oddly.
  • Leave (sysVectorDistance) as-is, and add a new function that returns a double, say (sysVectorMagnitude). This could be confusing, but not too bad if the difference is documented.

George should probably weigh in on this.

george moromisato 15 Sep 2017:

In other places I've used the suffix "exact" to deal with this issue. So we would create sysVectorDistanceExact to return a float.

george moromisato 5 Oct 2017:

Merged in @NMS's pull request: https://github.com/kronosaur/Mammoth/pull/25