Skip to content

Commit

Permalink
Added HandicapHelper class.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmcbride committed Sep 27, 2014
1 parent 03ec4dc commit 9abc0cd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
47 changes: 47 additions & 0 deletions InSimDotNet/Helpers/HandicapHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using InSimDotNet.Packets;
using System.Collections.Generic;

namespace InSimDotNet.Helpers {
/// <summary>
/// Helper class for setting car handicaps.
/// </summary>
public static class HandicapHelper {
private static Dictionary<CarFlags, byte> CarMap = new Dictionary<CarFlags, byte>() {
{ CarFlags.XFG, 0 },
{ CarFlags.XRG, 1 },
{ CarFlags.XRT, 2 },
{ CarFlags.RB4, 3 },
{ CarFlags.FXO, 4 },
{ CarFlags.LX4, 5 },
{ CarFlags.LX6, 6 },
{ CarFlags.MRT, 7 },
{ CarFlags.UF1, 8 },
{ CarFlags.RAC, 9 },
{ CarFlags.FZ5, 10 },
{ CarFlags.FOX, 11 },
{ CarFlags.XFR, 12 },
{ CarFlags.UFR, 13 },
{ CarFlags.FO8, 14 },
{ CarFlags.FXR, 15 },
{ CarFlags.XRR, 16 },
{ CarFlags.FZR, 17 },
{ CarFlags.BF1, 18 },
{ CarFlags.FBM, 19 },
};

/// <summary>
/// Sets the handicap for the specified cars.
/// </summary>
/// <param name="packet">The <see cref="IS_HCP"/> packet containing the handicaps.
/// <param name="T_Mass">The added mass to set in kilograms (0 - 200).</param>
/// <param name="H_TRes">The intake restriction to set (0 - 50).</param>
public static void SetHandicap(IS_HCP packet, CarFlags cars, byte H_Mass = 0, byte H_TRes = 0) {
foreach (var car in CarMap) {
if (cars.HasFlag(car.Key) || cars.HasFlag(CarFlags.All)) {
packet.Info[car.Value].H_Mass = H_Mass;
packet.Info[car.Value].H_TRes = H_TRes;
}
}
}
}
}
1 change: 1 addition & 0 deletions InSimDotNet/InSimDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="DisconnectedEventArgs.cs" />
<Compile Include="DisconnectReason.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Helpers\HandicapHelper.cs" />
<Compile Include="LfsEncoding.cs" />
<Compile Include="Helpers\CarHelper.cs" />
<Compile Include="InitializeEventArgs.cs" />
Expand Down
4 changes: 2 additions & 2 deletions version.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- 2.1.1 (26th September 2014)

* Added new IS_HCP packet and HandicapHelper class.
* Added ContinueOnCapturedContext property to InSim, TcpSocket and UdpSocket. Setting this to false prevents InSim.NET from marshalling packet callbacks back onto the calling thread e.g. in UI programs.
* Fixed exploit that allowed players to crash InSim.NET by typing characters in LFS that were not translatable into unicode.
* Fixed bug where sending certain multibyte characters could cause a crash.
* Fixed bug that allowed players to crash InSim.NET by typing characters in LFS that were not translatable into unicode.
* TcpSocket and UdpSocket now expose their underlying .NET Socket objects for convienence.

- 2.1.0 (19th August 2014)
Expand Down

0 comments on commit 9abc0cd

Please sign in to comment.