Skip to content

Commit

Permalink
Fixed PlayerSqrDistanceFrom*() calculation
Browse files Browse the repository at this point in the history
Calcs now use player WorldPosition instead of RawPosition. This is inline with the game's internal calcs and gives the correct result.
  • Loading branch information
AMacro committed May 18, 2024
1 parent 220a04a commit 440b917
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Multiplayer/Multiplayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@

<!-- Copy to game install folder -->
<Exec Condition="Exists('$(DvInstallDir)') And '$(OS)' == 'Windows_NT'" Command="powershell -executionpolicy bypass -Command &quot;(../package.ps1 -NoArchive -OutputDirectory '$(DvInstallDir)\Mods')&quot;" />
<Exec Condition="Exists('$(DvInstallDir)') And '$(OS)' == 'Windows_NT'" Command="powershell -executionpolicy bypass -Command &quot;(../package.ps1 -NoArchive -OutputDirectory 'D:\SteamLibrary\steamapps\common\Derail Valley 2\Mods')&quot;" />
<Exec Condition="Exists('$(DvInstallDir)') And '$(OS)' == 'Windows_NT'" Command="powershell -executionpolicy bypass -Command &quot;(../openScript.ps1)&quot;" />
<Exec Condition="Exists('$(DvInstallDir)') And '$(OS)' != 'Windows_NT'" Command="pwsh -Command &quot;(../package.ps1 -NoArchive -OutputDirectory '$(DvInstallDir)/Mods')&quot;" />
</Target>
</Project>
5 changes: 3 additions & 2 deletions Multiplayer/Patches/Jobs/StationJobGenerationRangePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ private static bool Prefix(StationJobGenerationRange __instance, ref float __res
Vector3 anchor = __instance.stationCenterAnchor.position;

__result = float.MaxValue;

//Loop through all of the players and return the one thats closest to the anchor
foreach (ServerPlayer serverPlayer in NetworkLifecycle.Instance.Server.ServerPlayers)
{
float sqDist = (serverPlayer.RawPosition - anchor).sqrMagnitude;
float sqDist = (serverPlayer.WorldPosition - anchor).sqrMagnitude;
if (sqDist < __result)
__result = sqDist;
}
Expand All @@ -42,7 +43,7 @@ private static bool Prefix(StationJobGenerationRange __instance, ref float __res
//Loop through all of the players and return the one thats closest to the anchor
foreach (ServerPlayer serverPlayer in NetworkLifecycle.Instance.Server.ServerPlayers)
{
float sqDist = (serverPlayer.RawPosition - anchor).sqrMagnitude;
float sqDist = (serverPlayer.WorldPosition - anchor).sqrMagnitude;
if (sqDist < __result)
__result = sqDist;
}
Expand Down

0 comments on commit 440b917

Please sign in to comment.