Skip to content

Commit

Permalink
Update to new flatbuffers spec
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jul 2, 2024
1 parent c3f20cc commit 0a21786
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
44 changes: 18 additions & 26 deletions RLBotCS/Conversion/FlatToCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ private static string MapMatchLength(MatchLength matchLength) =>
private static string MapMaxScore(MaxScore maxScore) =>
maxScore switch
{
MaxScore.Unlimited => "",
MaxScore.Default => "",
MaxScore.One_Goal => "Max1",
MaxScore.Three_Goals => "Max3",
MaxScore.Five_Goals => "Max5",
MaxScore.Seven_Goals => "Max7",
MaxScore.Unlimited => "UnlimitedScore",
_ => throw new ArgumentOutOfRangeException(nameof(maxScore), maxScore, null)
};

Expand Down Expand Up @@ -82,6 +84,9 @@ private static string MapBallType(BallTypeOption option) =>
BallTypeOption.Cube => "Ball_CubeBall",
BallTypeOption.Puck => "Ball_Puck",
BallTypeOption.Basketball => "Ball_BasketBall",
BallTypeOption.Beachball => "Ball_BeachBall",
BallTypeOption.Anniversary => "Ball_Anniversary",
BallTypeOption.Haunted => "Ball_Haunted",
_ => throw new ArgumentOutOfRangeException(nameof(option), option, null)
};

Expand All @@ -92,6 +97,8 @@ private static string MapBallWeight(BallWeightOption option) =>
BallWeightOption.Light => "LightBall",
BallWeightOption.Heavy => "HeavyBall",
BallWeightOption.Super_Light => "SuperLightBall",
BallWeightOption.Curve_Ball => "MagnusBall",
BallWeightOption.Beach_Ball_Curve => "MagnusBeachBall",
_ => throw new ArgumentOutOfRangeException(nameof(option), option, null)
};

Expand Down Expand Up @@ -137,6 +144,8 @@ private static string MapRumble(RumbleOption option) =>
RumbleOption.Spring_Loaded => "ItemsModeSprings",
RumbleOption.Spikes_Only => "ItemsModeSpikes",
RumbleOption.Spike_Rush => "ItemsModeRugby",
RumbleOption.Haunted_Ball_Beam => "ItemsModeHauntedBallBeam",
RumbleOption.Tactical => "ItemsModeSelection",
_ => throw new ArgumentOutOfRangeException(nameof(option), option, null)
};

Expand All @@ -157,6 +166,7 @@ private static string MapGravity(GravityOption option) =>
GravityOption.Low => "LowGravity",
GravityOption.High => "HighGravity",
GravityOption.Super_High => "SuperGravity",
GravityOption.Reverse => "ReverseGravity",
_ => throw new ArgumentOutOfRangeException(nameof(option), option, null)
};

Expand Down Expand Up @@ -212,12 +222,15 @@ public static string MakeOpenCommand(MatchSettingsT matchSettings)
if (!matchSettings.InstantStart)
command += "?Playtest";

// Parse mutator settings
command += "?GameTags=PlayerCount8";

if (matchSettings.Freeplay)
command += ",Freeplay";

if (matchSettings.MutatorSettings is not { } mutatorSettings)
return command;

// Parse mutator settings
command += GetOption(MapMatchLength(mutatorSettings.MatchLength));
command += GetOption(MapMaxScore(mutatorSettings.MaxScore));
command += GetOption(MapOvertime(mutatorSettings.OvertimeOption));
Expand All @@ -229,7 +242,7 @@ public static string MakeOpenCommand(MatchSettingsT matchSettings)
command += GetOption(MapBallSize(mutatorSettings.BallSizeOption));
command += GetOption(MapBallBounciness(mutatorSettings.BallBouncinessOption));
command += GetOption(MapBoost(mutatorSettings.BoostOption));
command += GetOption(MapRumble(mutatorSettings.RumbleOption)); //TODO - probably doesn't work
command += GetOption(MapRumble(mutatorSettings.RumbleOption));
command += GetOption(MapBoostStrength(mutatorSettings.BoostStrengthOption));
command += GetOption(MapGravity(mutatorSettings.GravityOption));
command += GetOption(MapDemolish(mutatorSettings.DemolishOption));
Expand All @@ -238,30 +251,9 @@ public static string MakeOpenCommand(MatchSettingsT matchSettings)
return command;
}

private static string MakeGameSpeedCommand(float gameSpeed) => "Set WorldInfo TimeDilation " + gameSpeed;

public static string MakeGameSpeedCommandFromOption(GameSpeedOption gameSpeed) =>
MakeGameSpeedCommand(
gameSpeed switch
{
GameSpeedOption.Slo_Mo => 0.5f,
GameSpeedOption.Time_Warp => 1.5f,
_ => 1.0f,
}
);

private static string MakeGravityCommand(float gravity) => "Set WorldInfo WorldGravityZ " + gravity;
public static string MakeGameSpeedCommand(float gameSpeed) => "Set WorldInfo TimeDilation " + gameSpeed;

public static string MakeGravityCommandFromOption(GravityOption gravityOption) =>
MakeGravityCommand(
gravityOption switch
{
GravityOption.Low => -325,
GravityOption.High => -1137.5f,
GravityOption.Super_High => -3250,
_ => -650,
}
);
public static string MakeGravityCommand(float gravity) => "Set WorldInfo WorldGravityZ " + gravity;

public static string MakeAutoSaveReplayCommand() => "QueSaveReplay";
}
3 changes: 2 additions & 1 deletion RLBotCS/ManagerTools/Parsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,11 @@ public static MatchSettingsT GetMatchSettings(string path)
ExistingMatchBehavior.Restart_If_Different
),
AutoSaveReplay = ParseBool(matchTable, "auto_save_replay", false),
Freeplay = ParseBool(matchTable, "freeplay", false),
MutatorSettings = new MutatorSettingsT()
{
MatchLength = ParseEnum(mutatorTable, "match_length", MatchLength.Five_Minutes),
MaxScore = ParseEnum(mutatorTable, "max_score", MaxScore.Unlimited),
MaxScore = ParseEnum(mutatorTable, "max_score", MaxScore.Default),
OvertimeOption = ParseEnum(mutatorTable, "overtime", OvertimeOption.Unlimited),
GameSpeedOption = ParseEnum(mutatorTable, "game_speed", GameSpeedOption.Default),
BallMaxSpeedOption = ParseEnum(mutatorTable, "ball_max_speed", BallMaxSpeedOption.Default),
Expand Down
2 changes: 1 addition & 1 deletion RLBotCSTests/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class TestGameState
public void Test()
{
var packet = new GameState();

FlatBufferBuilder build = new(1024);
packet.ToFlatBuffers(build);
}
Expand Down
2 changes: 1 addition & 1 deletion flatbuffers-schema

0 comments on commit 0a21786

Please sign in to comment.