Football: every player picks their own team and position
Closes the gap left by the football commit. Members publish their picks as lobby member data (tm/ps) alongside their loadout, and the owner publishes the scenario (sc) so members know when the picks matter. The lobby room turns into a team sheet: each member row shows their team and position, and MY TEAM / MY POSITION buttons cycle the local pick and republish it live, so everyone watches the sides fill out before the host launches. The egg builder honors explicit picks and only fills gaps: - pilots who chose a team get it; the rest are spread across the host team and one other so the sides stay balanced - a team with no volunteer runner promotes its first UNPICKED member, never overriding someone who chose crusher or blocker - if two pilots on a team both claim runner, the first keeps it and the second lines up - colors stay derived: runner in the team runner color, everyone else in the team color Verified: a three-pilot egg puts the host on crusher in team color with an unpicked teammate promoted to runner in runner color, the other side gets its own runner, and the teams/pilots blocks group correctly; the lobby room cycles picks and repaints the roster; both scenarios still pass their single-player regressions. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+216
-37
@@ -250,6 +250,8 @@ namespace
|
||||
char vehicle[24];
|
||||
char color[16];
|
||||
char badge[24];
|
||||
char team[32]; // football pick, "" = assign for them
|
||||
char position[16];
|
||||
};
|
||||
|
||||
// lobby-fed override (real personas + loadouts); empty = env parsing
|
||||
@@ -273,6 +275,8 @@ namespace
|
||||
gHostedPilots[i].color[0] ? gHostedPilots[i].color : "Red");
|
||||
strcpy(extras[i].badge,
|
||||
gHostedPilots[i].badge[0] ? gHostedPilots[i].badge : "None");
|
||||
strcpy(extras[i].team, gHostedPilots[i].team);
|
||||
strcpy(extras[i].position, gHostedPilots[i].position);
|
||||
}
|
||||
return gHostedPilotCount;
|
||||
}
|
||||
@@ -324,6 +328,7 @@ namespace
|
||||
}
|
||||
|
||||
ExtraPilot *pilot = &extras[extra_count];
|
||||
memset(pilot, 0, sizeof(*pilot));
|
||||
sprintf(pilot->address, "%s:%d", entry, console_port + 1);
|
||||
sprintf(pilot->name, "PILOT %d", extra_count + 2);
|
||||
strcpy(pilot->vehicle, kVehicles[
|
||||
@@ -797,6 +802,7 @@ namespace
|
||||
const char *badge;
|
||||
int team; // kTeams index, -1 outside football
|
||||
const char *position;
|
||||
Logical chosePosition; // picked it themselves
|
||||
};
|
||||
PilotEntry pilots[maxExtraPilots + 1];
|
||||
int pilot_count = 0;
|
||||
@@ -809,6 +815,7 @@ namespace
|
||||
owner->badge = kBadges[fe->selection[GroupBadge]].key;
|
||||
owner->team = -1;
|
||||
owner->position = NULL;
|
||||
owner->chosePosition = False;
|
||||
for (int p = 0; p < extra_count; ++p)
|
||||
{
|
||||
PilotEntry *pilot = &pilots[pilot_count++];
|
||||
@@ -819,47 +826,121 @@ namespace
|
||||
pilot->badge = extras[p].badge;
|
||||
pilot->team = -1;
|
||||
pilot->position = NULL;
|
||||
pilot->chosePosition = False;
|
||||
}
|
||||
|
||||
//
|
||||
// Football: assign teams and positions, derive colors
|
||||
// Football: every pilot's own team/position pick is honored;
|
||||
// unset picks get filled in, then each team is normalized to
|
||||
// exactly one runner (the console's rule).
|
||||
//
|
||||
int teams_used[2] = { 0, 1 };
|
||||
if (football)
|
||||
{
|
||||
teams_used[0] = fe->selection[GroupTeam];
|
||||
teams_used[1] = (teams_used[0] + 1) % FE_COUNT(kTeams);
|
||||
|
||||
int runner_on_team[2] = { 0, 0 };
|
||||
int line_position[2] = { 0, 0 }; // crusher/blocker rotation
|
||||
|
||||
owner->team = 0;
|
||||
owner->position = kPositions[fe->selection[GroupPosition]].key;
|
||||
if (strcmp(owner->position, "runner") == 0)
|
||||
{
|
||||
runner_on_team[0] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
// 1. Teams: the host's pick, then each member's, then
|
||||
// alternate whoever did not choose across the two
|
||||
// most-used teams so the sides stay balanced.
|
||||
//
|
||||
owner->team = fe->selection[GroupTeam];
|
||||
for (int p = 1; p < pilot_count; ++p)
|
||||
{
|
||||
int side = p % 2; // alternate: B, A, B, A...
|
||||
side = (side == 1) ? 1 : 0;
|
||||
pilots[p].team = side;
|
||||
if (!runner_on_team[side])
|
||||
for (int t = 0; t < FE_COUNT(kTeams); ++t)
|
||||
{
|
||||
pilots[p].position = "runner";
|
||||
runner_on_team[side] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pilots[p].position =
|
||||
(line_position[side]++ % 2) ? "blocker" : "crusher";
|
||||
if (strcmp(extras[p - 1].team, kTeams[t].key) == 0)
|
||||
{
|
||||
pilots[p].team = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fallback_team = (owner->team + 1) % FE_COUNT(kTeams);
|
||||
int unassigned = 0;
|
||||
for (int p = 1; p < pilot_count; ++p)
|
||||
{
|
||||
if (pilots[p].team < 0)
|
||||
{
|
||||
pilots[p].team = (unassigned++ % 2) ? owner->team : fallback_team;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 2. Positions: honor each pick, default the rest to the
|
||||
// line, then give every team exactly one runner.
|
||||
//
|
||||
for (int p = 1; p < pilot_count; ++p)
|
||||
{
|
||||
const char *pick = extras[p - 1].position;
|
||||
for (int i = 0; i < FE_COUNT(kPositions); ++i)
|
||||
{
|
||||
if (strcmp(pick, kPositions[i].key) == 0)
|
||||
{
|
||||
pilots[p].position = kPositions[i].key;
|
||||
pilots[p].chosePosition = True;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
owner->position = kPositions[fe->selection[GroupPosition]].key;
|
||||
owner->chosePosition = True;
|
||||
|
||||
for (int t = 0; t < FE_COUNT(kTeams); ++t)
|
||||
{
|
||||
int members = 0, runner = -1, spare = -1, line = 0;
|
||||
for (int p = 0; p < pilot_count; ++p)
|
||||
{
|
||||
if (pilots[p].team != t)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
++members;
|
||||
if (spare < 0 && !pilots[p].chosePosition)
|
||||
{
|
||||
spare = p; // nobody's plans to disturb
|
||||
}
|
||||
if (pilots[p].position != NULL &&
|
||||
strcmp(pilots[p].position, "runner") == 0)
|
||||
{
|
||||
if (runner < 0)
|
||||
{
|
||||
runner = p; // first runner keeps the ball
|
||||
}
|
||||
else
|
||||
{
|
||||
// two pilots claimed it - the later one lines up
|
||||
pilots[p].position = NULL;
|
||||
pilots[p].chosePosition = False;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (members == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (runner < 0 && spare >= 0)
|
||||
{
|
||||
// no volunteer: the first pilot without a pick of
|
||||
// their own runs (explicit picks are never overridden)
|
||||
pilots[spare].position = "runner";
|
||||
runner = spare;
|
||||
}
|
||||
for (int p = 0; p < pilot_count; ++p)
|
||||
{
|
||||
if (pilots[p].team == t && p != runner &&
|
||||
pilots[p].position == NULL)
|
||||
{
|
||||
pilots[p].position = (line++ % 2) ? "crusher" : "blocker";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 3. Colors follow team and position (runner wears the
|
||||
// team's runner color - that is how you spot the ball)
|
||||
//
|
||||
for (int p = 0; p < pilot_count; ++p)
|
||||
{
|
||||
const TeamEntry *team = &kTeams[teams_used[pilots[p].team]];
|
||||
const TeamEntry *team = &kTeams[pilots[p].team];
|
||||
pilots[p].color =
|
||||
(strcmp(pilots[p].position, "runner") == 0)
|
||||
? team->runnerColor : team->teamColor;
|
||||
@@ -921,7 +1002,7 @@ namespace
|
||||
egg += line;
|
||||
if (football)
|
||||
{
|
||||
sprintf(line, "team=team::%s\n", kTeams[teams_used[pilots[p].team]].key);
|
||||
sprintf(line, "team=team::%s\n", kTeams[pilots[p].team].key);
|
||||
egg += line;
|
||||
sprintf(line, "position=%s\n", pilots[p].position);
|
||||
egg += line;
|
||||
@@ -933,24 +1014,26 @@ namespace
|
||||
//
|
||||
if (football)
|
||||
{
|
||||
Logical team_present[2] = { False, False };
|
||||
for (int p = 0; p < pilot_count; ++p)
|
||||
{
|
||||
team_present[pilots[p].team] = True;
|
||||
}
|
||||
|
||||
std::string teams_list = "[teams]\n";
|
||||
std::string team_sections, pilots_sections;
|
||||
std::string teambitmap_list = "[teambitmap]\n";
|
||||
std::string teambitmap_sections;
|
||||
int bitmap_index = 1;
|
||||
for (int side = 0; side < 2; ++side)
|
||||
for (int side = 0; side < FE_COUNT(kTeams); ++side)
|
||||
{
|
||||
if (!team_present[side])
|
||||
Logical team_present = False;
|
||||
for (int p = 0; p < pilot_count; ++p)
|
||||
{
|
||||
if (pilots[p].team == side)
|
||||
{
|
||||
team_present = True;
|
||||
}
|
||||
}
|
||||
if (!team_present)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const char *team_key = kTeams[teams_used[side]].key;
|
||||
const char *team_key = kTeams[side].key;
|
||||
sprintf(line, "team=team::%s\n", team_key);
|
||||
teams_list += line;
|
||||
sprintf(line, "[team::%s]\nbitmapindex=%d\npilots=pilots::%s\n",
|
||||
@@ -1297,6 +1380,102 @@ void
|
||||
strcpy(badge, kBadges[b].key);
|
||||
}
|
||||
|
||||
//########################################################################
|
||||
// Football team / position picks (the lobby publishes and cycles these)
|
||||
//########################################################################
|
||||
|
||||
int
|
||||
RPL4FrontEnd_TeamCount()
|
||||
{
|
||||
return FE_COUNT(kTeams);
|
||||
}
|
||||
|
||||
const char *
|
||||
RPL4FrontEnd_TeamName(int index)
|
||||
{
|
||||
if (index < 0 || index >= FE_COUNT(kTeams))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return kTeams[index].name;
|
||||
}
|
||||
|
||||
const char *
|
||||
RPL4FrontEnd_TeamKey(int index)
|
||||
{
|
||||
if (index < 0 || index >= FE_COUNT(kTeams))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return kTeams[index].key;
|
||||
}
|
||||
|
||||
int
|
||||
RPL4FrontEnd_PositionCount()
|
||||
{
|
||||
return FE_COUNT(kPositions);
|
||||
}
|
||||
|
||||
const char *
|
||||
RPL4FrontEnd_PositionName(int index)
|
||||
{
|
||||
if (index < 0 || index >= FE_COUNT(kPositions))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return kPositions[index].name;
|
||||
}
|
||||
|
||||
const char *
|
||||
RPL4FrontEnd_PositionKey(int index)
|
||||
{
|
||||
if (index < 0 || index >= FE_COUNT(kPositions))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return kPositions[index].key;
|
||||
}
|
||||
|
||||
int
|
||||
RPL4FrontEnd_GetTeamIndex()
|
||||
{
|
||||
return gHavePersist ? gPersistSelection[GroupTeam] : 0;
|
||||
}
|
||||
|
||||
void
|
||||
RPL4FrontEnd_SetTeamIndex(int index)
|
||||
{
|
||||
if (index < 0 || index >= FE_COUNT(kTeams))
|
||||
{
|
||||
return;
|
||||
}
|
||||
gPersistSelection[GroupTeam] = index;
|
||||
gHavePersist = True;
|
||||
}
|
||||
|
||||
int
|
||||
RPL4FrontEnd_GetPositionIndex()
|
||||
{
|
||||
return gHavePersist ? gPersistSelection[GroupPosition] : 0;
|
||||
}
|
||||
|
||||
void
|
||||
RPL4FrontEnd_SetPositionIndex(int index)
|
||||
{
|
||||
if (index < 0 || index >= FE_COUNT(kPositions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
gPersistSelection[GroupPosition] = index;
|
||||
gHavePersist = True;
|
||||
}
|
||||
|
||||
Logical
|
||||
RPL4FrontEnd_IsFootballSelected()
|
||||
{
|
||||
return gHavePersist && IsFootball(gPersistSelection);
|
||||
}
|
||||
|
||||
void
|
||||
RPL4FrontEnd_SetHostedPilots(
|
||||
const char *owner_address,
|
||||
|
||||
Reference in New Issue
Block a user