Skip to content

Commit

Permalink
v0.2.0 (#48)
Browse files Browse the repository at this point in the history
* Add name/loadout overrides

Fix `PsyonixLoadouts.GetFromName`

* Experimental multi-RL mode for epic

* Update `rl_ball_sym`

* Fix Linux launch

* Update Bridge.dll

* Implement group ids spec

* Add `has_jumped`, `has_double_jumped` & `has_flipped`

* Fix team parsing for loadouts

* Update to new future spec

* Update to new spec

* Rename `loadout_config` -> `loadout_file`

* Remove `num_cars` and `num_scripts` from toml config parser

* Rename group id to agent id

* Update RLBotCS/Server/BridgeMessage.cs

Co-authored-by: Nicolaj 'Eastvillage' Ø Jensen <[email protected]>

* Don't send `PlayerInfoRequest` if agent id is empty

* Rename `SetMatchSettings` -> `ClearProcessPlayerReservation`

* `PlayerIdMap` -> `PlayerIdPair`

* Update `Bridge.dll`

* group id -> agent id

---------

Co-authored-by: Nicolaj 'Eastvillage' Ø Jensen <[email protected]>
  • Loading branch information
VirxEC and NicEastvillage authored Oct 13, 2024
1 parent 500a43a commit b20bbe9
Show file tree
Hide file tree
Showing 28 changed files with 571 additions and 201 deletions.
36 changes: 22 additions & 14 deletions RLBotCS/Conversion/GameStateToFlat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using Bridge.State;
using rlbot.flat;
using CollisionShapeUnion = rlbot.flat.CollisionShapeUnion;
using GameStateType = Bridge.Models.Message.GameStateType;
using GameStatus = Bridge.Models.Message.GameStatus;

namespace RLBotCS.Conversion;

internal static class GameStateToFlat
{
private static Vector2T ToVector2T(this Bridge.Models.Phys.Vector2 vec) =>
new() { X = vec.X, Y = vec.Y };

private static Vector3T ToVector3T(this Bridge.Models.Phys.Vector3 vec) =>
new()
{
Expand Down Expand Up @@ -37,7 +40,7 @@ private static RotatorT ToRotatorT(this Bridge.Models.Phys.Rotator vec) =>
}
}

public static GameTickPacketT ToFlatBuffers(this GameState gameState)
public static GamePacketT ToFlatBuffers(this GameState gameState)
{
List<BallInfoT> balls = new(gameState.Balls.Count);
foreach (var ball in gameState.Balls.Values)
Expand Down Expand Up @@ -84,17 +87,17 @@ ICollisionShape.Cylinder cylinderShape
balls.Add(new() { Physics = ballPhysics, Shape = collisionShape });
}

rlbot.flat.GameStateType gameStateType = gameState.GameStateType switch
rlbot.flat.GameStatus gameStatus = gameState.GameStatus switch
{
GameStateType.Inactive => rlbot.flat.GameStateType.Inactive,
GameStateType.Countdown => rlbot.flat.GameStateType.Countdown,
GameStateType.Kickoff => rlbot.flat.GameStateType.Kickoff,
GameStateType.Active => rlbot.flat.GameStateType.Active,
GameStateType.GoalScored => rlbot.flat.GameStateType.GoalScored,
GameStateType.Replay => rlbot.flat.GameStateType.Replay,
GameStateType.Paused => rlbot.flat.GameStateType.Paused,
GameStateType.Ended => rlbot.flat.GameStateType.Ended,
_ => rlbot.flat.GameStateType.Inactive
GameStatus.Inactive => rlbot.flat.GameStatus.Inactive,
GameStatus.Countdown => rlbot.flat.GameStatus.Countdown,
GameStatus.Kickoff => rlbot.flat.GameStatus.Kickoff,
GameStatus.Active => rlbot.flat.GameStatus.Active,
GameStatus.GoalScored => rlbot.flat.GameStatus.GoalScored,
GameStatus.Replay => rlbot.flat.GameStatus.Replay,
GameStatus.Paused => rlbot.flat.GameStatus.Paused,
GameStatus.Ended => rlbot.flat.GameStatus.Ended,
_ => rlbot.flat.GameStatus.Inactive
};

GameInfoT gameInfo =
Expand All @@ -104,7 +107,7 @@ ICollisionShape.Cylinder cylinderShape
GameTimeRemaining = gameState.GameTimeRemaining,
IsOvertime = gameState.IsOvertime,
IsUnlimitedTime = gameState.MatchLength == Bridge.Packet.MatchLength.Unlimited,
GameStateType = gameStateType,
GameStatus = gameStatus,
WorldGravityZ = gameState.WorldGravityZ,
GameSpeed = gameState.GameSpeed,
FrameNum = gameState.FrameNum
Expand Down Expand Up @@ -197,11 +200,16 @@ ICollisionShape.Cylinder cylinderShape
Handbrake = car.LastInput.Handbrake
},
LastSpectated = car.LastSpectated,
HasJumped = car.HasJumped,
HasDoubleJumped = car.HasDoubleJumped,
HasDodged = car.HasDodged,
DodgeElapsed = car.DodgeElapsed,
DodgeDir = car.DodgeDir.ToVector2T(),
}
);
}

return new GameTickPacketT
return new GamePacketT
{
Balls = balls,
GameInfo = gameInfo,
Expand Down
11 changes: 7 additions & 4 deletions RLBotCS/Conversion/PsyonixLoadouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ public static void Reset()

public static PlayerLoadoutT? GetFromName(string name, int team)
{
int index = Unused.FindIndex(n => n.Contains(name));
if (index == -1)
var loadoutKey = DefaultLoadouts.Keys.FirstOrDefault(k => k.Contains(name));
if (loadoutKey == null)
return null;

var loadout = DefaultLoadouts[Unused[index]][team];
Unused.RemoveAt(index);
int index = Unused.FindIndex(n => n == loadoutKey);
if (index != -1)
Unused.RemoveAt(index);

var loadout = DefaultLoadouts[loadoutKey][team];
return loadout;
}

Expand Down
110 changes: 110 additions & 0 deletions RLBotCS/ManagerTools/AgentReservation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using rlbot.flat;

namespace RLBotCS.ManagerTools;

public struct PlayerIdPair
{
public uint Index;
public int SpawnId;
}

public class AgentReservation
{
private class PlayerMetadata
{
public uint Index;
public int SpawnId;
public uint Team;
public string AgentId = "";
public bool IsReserved;
}

private readonly List<PlayerMetadata> _knownPlayers = new();

public void SetPlayers(MatchSettingsT matchSettings)
{
_knownPlayers.Clear();

uint indexOffset = 0;
for (int i = 0; i < matchSettings.PlayerConfigurations.Count; i++)
{
var playerConfig = matchSettings.PlayerConfigurations[i];

if (playerConfig.Variety.Type != PlayerClass.RLBot)
{
if (playerConfig.Variety.Type == PlayerClass.Human)
indexOffset++;

continue;
}

uint index = (uint)i - indexOffset;
_knownPlayers.Add(
(
new PlayerMetadata
{
Index = index,
SpawnId = playerConfig.SpawnId,
Team = playerConfig.Team,
AgentId = playerConfig.AgentId,
}
)
);
}
}

public (PlayerIdPair, uint)? ReservePlayer(string agentId)
{
PlayerMetadata? player = _knownPlayers.FirstOrDefault(
playerMetadata => !playerMetadata.IsReserved && playerMetadata.AgentId == agentId
);
if (player != null)
{
player.IsReserved = true;

return (
new PlayerIdPair { Index = player.Index, SpawnId = player.SpawnId },
player.Team
);
}

return null;
}

public (List<PlayerIdPair>, uint)? ReservePlayers(string agentId)
{
// find the first player in the group
if (ReservePlayer(agentId) is (PlayerIdPair, uint) initalPlayer)
{
var playerIdPair = initalPlayer.Item1;
var team = initalPlayer.Item2;

List<PlayerIdPair> players = new() { playerIdPair };

// find other players in the same group & team

var otherPlayers = _knownPlayers.Where(
playerMetadata =>
!playerMetadata.IsReserved
&& playerMetadata.AgentId == agentId
&& playerMetadata.Team == team
);

foreach (var playerMetadata in otherPlayers)
{
playerMetadata.IsReserved = true;
players.Add(
new PlayerIdPair
{
Index = playerMetadata.Index,
SpawnId = playerMetadata.SpawnId
}
);
}

return (players, team);
}

return null;
}
}
Loading

0 comments on commit b20bbe9

Please sign in to comment.