fix(engine): use BGS-compatible achievement IDs

This commit is contained in:
coyotte508 2026-11-13 17:12:25 +00:00 • committed by Eliott C.
commit a5dc982cd3
3 changed files with 98 additions and 91 deletions

View file

@ -40,6 +40,11 @@ return `{ seat, earned: [] }`, with no outcome, rather than shifting later seats
## Revision 1 catalog (36 IDs)
IDs follow BGS's `^[a-z0-9][a-z0-9-]{0,63}$` validator: lowercase letters,
ASCII digits, and hyphens, at most 64 characters. All 36 IDs are unique. The
pre-publication dotted spellings were replaced with hyphens; they are not aliases
and were never published. The initial manifest therefore remains revision 1.
### Faction victories (18)
Each requires a win as the named faction; either ruleset qualifies where that
@ -47,35 +52,35 @@ faction is available.
| ID | Faction |
| --------------------------- | ------------- |
| `win.faction.terrans` | Terrans |
| `win.faction.lantids` | Lantids |
| `win.faction.hadsch-hallas` | Hadsch Hallas |
| `win.faction.ivits` | Ivits |
| `win.faction.geodens` | Geodens |
| `win.faction.baltaks` | Bal T'aks |
| `win.faction.xenos` | Xenos |
| `win.faction.gleens` | Gleens |
| `win.faction.taklons` | Taklons |
| `win.faction.ambas` | Ambas |
| `win.faction.firaks` | Firaks |
| `win.faction.bescods` | Bescods |
| `win.faction.nevlas` | Nevlas |
| `win.faction.itars` | Itars |
| `win.faction.tinkeroids` | Tinkeroids |
| `win.faction.darkanians` | Darkanians |
| `win.faction.moweyds` | Moweyds |
| `win.faction.space-giants` | Space Giants |
| `win-faction-terrans` | Terrans |
| `win-faction-lantids` | Lantids |
| `win-faction-hadsch-hallas` | Hadsch Hallas |
| `win-faction-ivits` | Ivits |
| `win-faction-geodens` | Geodens |
| `win-faction-baltaks` | Bal T'aks |
| `win-faction-xenos` | Xenos |
| `win-faction-gleens` | Gleens |
| `win-faction-taklons` | Taklons |
| `win-faction-ambas` | Ambas |
| `win-faction-firaks` | Firaks |
| `win-faction-bescods` | Bescods |
| `win-faction-nevlas` | Nevlas |
| `win-faction-itars` | Itars |
| `win-faction-tinkeroids` | Tinkeroids |
| `win-faction-darkanians` | Darkanians |
| `win-faction-moweyds` | Moweyds |
| `win-faction-space-giants` | Space Giants |
### Ruleset victories and scores (6)
| ID | Requirement |
| ---------------------- | --------------------------------------------------- |
| `win.mode.base` | Win a base game |
| `win.mode.lost-fleet` | Win a Lost Fleet game |
| `score.base.150` | Finish a base game with at least 150 final VP |
| `score.base.200` | Finish a base game with at least 200 final VP |
| `score.lost-fleet.150` | Finish a Lost Fleet game with at least 150 final VP |
| `score.lost-fleet.200` | Finish a Lost Fleet game with at least 200 final VP |
| `win-mode-base` | Win a base game |
| `win-mode-lost-fleet` | Win a Lost Fleet game |
| `score-base-150` | Finish a base game with at least 150 final VP |
| `score-base-200` | Finish a base game with at least 200 final VP |
| `score-lost-fleet-150` | Finish a Lost Fleet game with at least 150 final VP |
| `score-lost-fleet-200` | Finish a Lost Fleet game with at least 200 final VP |
`options.lostFleet` selects the ruleset; a Lost Fleet game does not also award base
mode IDs. Score achievements require **no win**, and 200 VP earns both thresholds
@ -85,11 +90,11 @@ for the selected mode.
| ID | Exact difficulty |
| ------------------------- | ---------------- |
| `win.automa.automalein` | `automalein` |
| `win.automa.automa` | `automa` |
| `win.automa.automaechtig` | `automaechtig` |
| `win.automa.ultoma` | `ultoma` |
| `win.automa.alptrauma` | `alptrauma` |
| `win-automa-automalein` | `automalein` |
| `win-automa-automa` | `automa` |
| `win-automa-automaechtig` | `automaechtig` |
| `win-automa-ultoma` | `ultoma` |
| `win-automa-alptrauma` | `alptrauma` |
Only the configured difficulty's ID is earned, not all lower difficulties.
In both multiplayer and solo Automa games, a human at the highest final score
@ -104,13 +109,13 @@ human in an authoritatively completed game.
| ID | Requirement |
| ------------------------------------- | ---------------------------------------------------------------------------- |
| `build.all-standard` | All 18 standard building pieces simultaneously deployed at game end |
| `federation.form.3` | At least three federation formations in one game |
| `explore.all-types.base` | Main-owned colonies on all 9 required physical types in a base game |
| `explore.all-types.lost-fleet` | Main-owned colonies on all 11 required physical types in a Lost Fleet game |
| `faction.ivits.growing-federation` | As Ivits, at least three federation formation milestones |
| `faction.lantids.shared-civilization` | As Lantids, at least six additional mines on opponents' colonies at game end |
| `faction.bescods.balanced-research` | As Bescods, finish at level 3 or higher on all six research tracks |
| `build-all-standard` | All 18 standard building pieces simultaneously deployed at game end |
| `federation-form-3` | At least three federation formations in one game |
| `explore-all-types-base` | Main-owned colonies on all 9 required physical types in a base game |
| `explore-all-types-lost-fleet` | Main-owned colonies on all 11 required physical types in a Lost Fleet game |
| `faction-ivits-growing-federation` | As Ivits, at least three federation formation milestones |
| `faction-lantids-shared-civilization` | As Lantids, at least six additional mines on opponents' colonies at game end |
| `faction-bescods-balanced-research` | As Bescods, finish at level 3 or higher on all six research tracks |
**Full deployment:** the standard supply is 8 mines, 4 trading stations, 3 research
labs, 1 planetary institute, and both academies (18 pieces). The predicate checks

View file

@ -60,8 +60,10 @@ describe("BGS achievement hooks", () => {
expect(manifest.revision).to.equal(1);
expect(ids).to.have.length(36);
expect(new Set(ids).size).to.equal(ids.length);
for (const faction of Faction.values(Expansion.All)) expect(ids).to.include(`win.faction.${faction}`);
for (const difficulty of automaDifficulties) expect(ids).to.include(`win.automa.${difficulty}`);
// BGS packages/protocol/achievements.ts: achievementIdSchema.
for (const id of ids) expect(id).to.match(/^[a-z0-9][a-z0-9-]{0,63}$/);
for (const faction of Faction.values(Expansion.All)) expect(ids).to.include(`win-faction-${faction}`);
for (const difficulty of automaDifficulties) expect(ids).to.include(`win-automa-${difficulty}`);
expect(manifest.achievements.every((definition) => definition.name && definition.description)).to.equal(true);
manifest.achievements[0].name = "mutated";
expect(achievementDefinitions().achievements[0].name).not.to.equal("mutated");
@ -76,14 +78,14 @@ describe("BGS achievement hooks", () => {
expect(factions(engine)[2]).to.equal(Faction.HadschHallas);
expect(result[2].outcome).to.equal("win");
expect(result[2].earned).to.include.members([
"win.faction.hadsch-hallas",
"win.mode.base",
"score.base.150",
"score.base.200",
"win-faction-hadsch-hallas",
"win-mode-base",
"score-base-150",
"score-base-200",
]);
expect(result[0].outcome).to.equal("loss");
expect(result[0].earned).to.include("score.base.150");
expect(result[0].earned.some((id) => id.startsWith("win."))).to.equal(false);
expect(result[0].earned).to.include("score-base-150");
expect(result[0].earned.some((id) => id.startsWith("win-"))).to.equal(false);
expect(achievements(engine)).to.deep.equal(result);
expect(achievements(data)).to.deep.equal(result);
const ids = new Set(achievementDefinitions().achievements.map((definition) => definition.id));
@ -123,7 +125,7 @@ describe("BGS achievement hooks", () => {
const result = achievements(data);
expect(result[0]).to.deep.equal({ seat: 0, earned: [] });
expect(result[2].seat).to.equal(2);
expect(result[2].earned).to.include("win.faction.hadsch-hallas");
expect(result[2].earned).to.include("win-faction-hadsch-hallas");
});
it("treats multiplayer tied first place as wins, not draws", () => {
@ -143,10 +145,10 @@ describe("BGS achievement hooks", () => {
expect(result[0].seat).to.equal(0);
const won = rankings(Engine.fromData(data))[0] === 1;
expect(result[0].outcome).to.equal(won ? "win" : "loss");
expect(result[0].earned.filter((id) => id.startsWith("win.automa."))).to.deep.equal(
won ? [`win.automa.${difficulty}`] : []
expect(result[0].earned.filter((id) => id.startsWith("win-automa-"))).to.deep.equal(
won ? [`win-automa-${difficulty}`] : []
);
expect(result[0].earned).to.include("score.base.200");
expect(result[0].earned).to.include("score-base-200");
}
}
});
@ -159,11 +161,11 @@ describe("BGS achievement hooks", () => {
for (const score of [149, 150, 199, 200]) {
data.players[0].data.victoryPoints = score;
const ids = earned(data);
expect(ids.includes(`score.${mode}.150`)).to.equal(score >= 150);
expect(ids.includes(`score.${mode}.200`)).to.equal(score >= 200);
expect(ids.some((id) => id.startsWith(`score.${lostFleet ? "base" : "lost-fleet"}.`))).to.equal(false);
expect(ids.includes(`score-${mode}-150`)).to.equal(score >= 150);
expect(ids.includes(`score-${mode}-200`)).to.equal(score >= 200);
expect(ids.some((id) => id.startsWith(`score-${lostFleet ? "base" : "lost-fleet"}-`))).to.equal(false);
}
expect(earned(data, 2)).to.include(`win.mode.${mode}`);
expect(earned(data, 2)).to.include(`win-mode-${mode}`);
}
});
@ -173,7 +175,7 @@ describe("BGS achievement hooks", () => {
data.options.lostFleet = true;
data.players[2].faction = faction;
delete data.players[2].variant;
expect(earned(data, 2)).to.include(`win.faction.${faction}`);
expect(earned(data, 2)).to.include(`win-faction-${faction}`);
}
});
@ -188,12 +190,12 @@ describe("BGS achievement hooks", () => {
[Building.Academy2]: 1,
};
Object.assign(data.players[0].data.buildings, buildings);
expect(earned(data)).to.include("build.all-standard");
expect(earned(data)).to.include("build-all-standard");
for (const building of Object.keys(buildings)) {
data.players[0].data.buildings[building]--;
data.players[0].data.lostPlanet = 1;
data.players[0].data.artifactPlanetTypes = [Planet.Asteroid, Planet.Protoplanet];
expect(earned(data)).not.to.include("build.all-standard");
expect(earned(data)).not.to.include("build-all-standard");
data.players[0].data.buildings[building]++;
}
});
@ -203,29 +205,29 @@ describe("BGS achievement hooks", () => {
data.players[0].data.federationCount = 2;
data.players[0].data.tiles.federations = Array(5).fill({ tile: "fed1", green: true });
data.players[0].data.spaceshipFederations = [{ tile: "unused", green: true }];
expect(earned(data)).not.to.include("federation.form.3");
expect(earned(data)).not.to.include("federation-form-3");
data.players[0].data.federationCount = 3;
data.players[0].data.tiles.federations = [];
data.players[0].data.spaceshipFederations = [];
expect(earned(data)).to.include("federation.form.3");
expect(earned(data)).not.to.include("faction.ivits.growing-federation");
expect(earned(data)).to.include("federation-form-3");
expect(earned(data)).not.to.include("faction-ivits-growing-federation");
data.players[0].faction = Faction.Ivits;
delete data.players[0].variant;
expect(earned(data)).to.include("faction.ivits.growing-federation");
expect(earned(data)).to.include("faction-ivits-growing-federation");
});
it("requires all nine physical base types including Lost, but never Transdim", () => {
const data = state();
colonies(data, baseTypes);
expect(earned(data)).to.include("explore.all-types.base");
expect(earned(data)).to.include("explore-all-types-base");
for (let index = 0; index < baseTypes.length; index++) {
const hex = data.map[index];
hex.data.planet = Planet.Transdim;
expect(earned(data)).not.to.include("explore.all-types.base");
expect(earned(data)).not.to.include("explore-all-types-base");
hex.data.planet = baseTypes[index];
}
data.map[7].data.building = Building.GaiaFormer;
expect(earned(data)).not.to.include("explore.all-types.base");
expect(earned(data)).not.to.include("explore-all-types-base");
});
it("requires physical asteroid and protoplanet colonies in Lost Fleet, not artifact types", () => {
@ -233,10 +235,10 @@ describe("BGS achievement hooks", () => {
data.options.lostFleet = true;
colonies(data, baseTypes);
data.players[0].data.artifactPlanetTypes = [Planet.Asteroid, Planet.Protoplanet];
expect(earned(data)).not.to.include("explore.all-types.lost-fleet");
expect(earned(data)).not.to.include("explore-all-types-lost-fleet");
colonies(data, [...baseTypes, Planet.Asteroid, Planet.Protoplanet]);
expect(earned(data)).to.include("explore.all-types.lost-fleet");
expect(earned(data)).not.to.include("explore.all-types.base");
expect(earned(data)).to.include("explore-all-types-lost-fleet");
expect(earned(data)).not.to.include("explore-all-types-base");
});
it("counts Lantids shared mines separately from main-owned planet types", () => {
@ -247,22 +249,22 @@ describe("BGS achievement hooks", () => {
for (let index = 0; index < 6; index++) {
Object.assign(data.map[index].data, { player: 1, additionalMine: 0 });
}
expect(earned(data)).to.include("faction.lantids.shared-civilization");
expect(earned(data)).not.to.include("explore.all-types.base");
expect(earned(data)).to.include("faction-lantids-shared-civilization");
expect(earned(data)).not.to.include("explore-all-types-base");
delete data.map[5].data.additionalMine;
expect(earned(data)).not.to.include("faction.lantids.shared-civilization");
expect(earned(data)).not.to.include("faction-lantids-shared-civilization");
});
it("requires Bescods and all six research tracks at level three or above", () => {
const data = state();
for (const field of ResearchField.values(Expansion.All)) data.players[0].data.research[field] = 3;
expect(earned(data)).not.to.include("faction.bescods.balanced-research");
expect(earned(data)).not.to.include("faction-bescods-balanced-research");
data.players[0].faction = Faction.Bescods;
delete data.players[0].variant;
expect(earned(data)).to.include("faction.bescods.balanced-research");
expect(earned(data)).to.include("faction-bescods-balanced-research");
for (const field of ResearchField.values(Expansion.All)) {
data.players[0].data.research[field] = 2;
expect(earned(data)).not.to.include("faction.bescods.balanced-research");
expect(earned(data)).not.to.include("faction-bescods-balanced-research");
data.players[0].data.research[field] = 4;
}
});

View file

@ -51,20 +51,20 @@ function displayName(id: string): string {
/** The complete catalog, independent of the current game's mode or faction selection. */
export function achievementDefinitions(): AchievementManifest {
const definitions: AchievementDefinition[] = Faction.values(Expansion.All).map((faction) => ({
id: `win.faction.${faction}`,
id: `win-faction-${faction}`,
name: `${displayName(faction)} Victory`,
description: `Win as ${displayName(faction)}. Shared first place counts; either ruleset qualifies.`,
}));
for (const mode of ["base", "lost-fleet"]) {
const name = mode === "base" ? "Base Game" : "Lost Fleet";
definitions.push({
id: `win.mode.${mode}`,
id: `win-mode-${mode}`,
name: `${name} Victory`,
description: `Win a ${name} game, including shared first place.`,
});
for (const threshold of [150, 200]) {
definitions.push({
id: `score.${mode}.${threshold}`,
id: `score-${mode}-${threshold}`,
name: `${name}: ${threshold} Points`,
description: `Finish a ${name} game with at least ${threshold} final victory points, after auction deductions. No win required.`,
});
@ -72,48 +72,48 @@ export function achievementDefinitions(): AchievementManifest {
}
for (const difficulty of automaDifficulties) {
definitions.push({
id: `win.automa.${difficulty}`,
id: `win-automa-${difficulty}`,
name: `Defeat ${displayName(difficulty)}`,
description: `Win against Automa at exactly ${difficulty} difficulty. A tied score counts as a human win.`,
});
}
definitions.push(
{
id: "build.all-standard",
id: "build-all-standard",
name: "Full Deployment",
description:
"Finish with all 18 standard building pieces simultaneously deployed: 8 mines, 4 trading stations, 3 research labs, the institute and both academies. Excludes Lost Planet, artifacts, Gaiaformers and space stations. No win required.",
},
{
id: "federation.form.3",
id: "federation-form-3",
name: "Federation Builder",
description:
"Complete at least three federation formations in one game (extensions of the growing federation for Ivits). Token rewards and rescores do not count. No win required.",
},
{
id: "explore.all-types.base",
id: "explore-all-types-base",
name: "Every World: Base Game",
description:
"Finish a base game with main-owned colonies on all seven ordinary planet types, Gaia and the Lost Planet. Gaiaformers and Lantids shared mines do not count. No win required.",
},
{
id: "explore.all-types.lost-fleet",
id: "explore-all-types-lost-fleet",
name: "Every World: Lost Fleet",
description:
"Finish a Lost Fleet game with main-owned colonies on all seven ordinary types, Gaia, Lost Planet, Asteroid and Protoplanet. Artifacts, Gaiaformers and Lantids shared mines do not count. No win required.",
},
{
id: "faction.ivits.growing-federation",
id: "faction-ivits-growing-federation",
name: "Growing Federation",
description: "As Ivits, complete three federation formation milestones in one game. No win required.",
},
{
id: "faction.lantids.shared-civilization",
id: "faction-lantids-shared-civilization",
name: "Shared Civilization",
description: "As Lantids, finish with at least six additional mines on opponents' colonies. No win required.",
},
{
id: "faction.bescods.balanced-research",
id: "faction-bescods-balanced-research",
name: "Balanced Research",
description: "As Bescods, finish at level 3 or higher on all six research tracks. No win required.",
}
@ -147,33 +147,33 @@ export function achievements(data: Engine | Record<string, any>): SeatAchievemen
const earned: string[] = [];
const won = player.data.victoryPoints >= bestScore;
if (won) {
earned.push(`win.faction.${player.faction}`, `win.mode.${mode}`);
if (engine.automa) earned.push(`win.automa.${engine.automa.difficulty}`);
earned.push(`win-faction-${player.faction}`, `win-mode-${mode}`);
if (engine.automa) earned.push(`win-automa-${engine.automa.difficulty}`);
}
for (const threshold of [150, 200]) {
if (player.data.victoryPoints >= threshold) earned.push(`score.${mode}.${threshold}`);
if (player.data.victoryPoints >= threshold) earned.push(`score-${mode}-${threshold}`);
}
if (standardBuildings.every((building) => player.data.buildings[building] === player.maxBuildings(building))) {
earned.push("build.all-standard");
earned.push("build-all-standard");
}
if (player.data.federationCount >= 3) {
earned.push("federation.form.3");
if (player.faction === Faction.Ivits) earned.push("faction.ivits.growing-federation");
earned.push("federation-form-3");
if (player.faction === Faction.Ivits) earned.push("faction-ivits-growing-federation");
}
// Unlike Condition.PlanetType, ownedPlanets excludes virtual artifact types and shared mines.
const physicalTypes = new Set(player.ownedPlanets.map((hex) => hex.data.planet));
if (requiredTypes.every((type) => physicalTypes.has(type))) earned.push(`explore.all-types.${mode}`);
if (requiredTypes.every((type) => physicalTypes.has(type))) earned.push(`explore-all-types-${mode}`);
if (
player.faction === Faction.Lantids &&
[...engine.map.grid.values()].filter((hex) => hex.data.additionalMine === player.player).length >= 6
) {
earned.push("faction.lantids.shared-civilization");
earned.push("faction-lantids-shared-civilization");
}
if (
player.faction === Faction.Bescods &&
ResearchField.values(engine.expansions).every((field) => player.data.research[field] >= 3)
) {
earned.push("faction.bescods.balanced-research");
earned.push("faction-bescods-balanced-research");
}
return { seat, earned, outcome: won ? "win" : "loss" };
});