Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
sysVectorDistance no longer truncates to integer
Browse files Browse the repository at this point in the history
  • Loading branch information
INeedAUniqueUsername committed Jul 23, 2017
1 parent d8c5ded commit a2b9564
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion TSE/CCExtensions.cpp
Expand Up @@ -12814,7 +12814,7 @@ ICCItem *fnSystemVectorMath (CEvalContext *pEvalCtx, ICCItem *pArgs, DWORD dwDat
}

CVector vDist = vPos1 - vPos2;
return pCC->CreateInteger((int)((vDist.Length() / LIGHT_SECOND) + 0.5));
return pCC->CreateDouble(((vDist.Length() / LIGHT_SECOND) + 0.5));
}

case FN_VECTOR_POLAR_VELOCITY:
Expand Down

1 comment on commit a2b9564

@NMS127
Copy link

@NMS127 NMS127 commented on a2b9564 Jul 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying my comment from https://ministry.kronosaur.com/record.hexm?id=73030 :

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.

Please sign in to comment.