augment trees, pitch-limit fallback, and cached definitions

This commit is contained in:
tresabhi committed 2026-11-15 17:28:43 -06:00
1 parent da9c5272bc
commit 79129ff3c0
57 files changed
+2196 -717

No files matched your search

@@ -0,0 +1,239 @@
import type {
AugmentGroup,
AugmentNode,
AugmentProgression,
AugmentRequirement,
} from "@blitzkit/protos";
import type { Vector2Tuple } from "three";
import { CellGrid } from "./cellGrid";
/**
* Follows how the game routes the connectors of its augment tree.
*
* Every node is placed by hand on a shared grid and the connectors are
* per-cell flags, same as the modules screen. Each requirement becomes an
* edge that is routed along one row and one column, never diagonally. The
* game's arrowheads are left out, the same as on the modules screen.
*/
export interface AugmentTreeCell {
// 1-based grid column (depth) and row
position: Vector2Tuple;
// Missing for empty cells that only carry a connector line
node?: AugmentNode;
// The final choice every branch ends in. Takes the cell its edges point at
group?: AugmentGroup;
// Line from the cell center to the left
left: boolean;
// Line from the cell center to the right
right: boolean;
// Line from the cell center up to the previous row
top: boolean;
// Line from the cell center down to the next row
bottom: boolean;
}
// A cell as the website shows it. The game lays the tree out left to right
// and the website top to bottom, so the game's depth becomes the row
export interface AugmentTreeDisplayCell {
// 1-based grid row (depth) and column
row: number;
column: number;
node?: AugmentNode;
group?: AugmentGroup;
north: boolean;
south: boolean;
west: boolean;
east: boolean;
}
// Source row and column, then target row and column
type Edge = readonly [
fromRow: number,
fromColumn: number,
toRow: number,
toColumn: number,
verticalFirst: boolean,
];
function emptyCell(column: number, row: number) {
return {
position: [column, row],
left: false,
right: false,
top: false,
bottom: false,
} satisfies AugmentTreeCell;
}
export function layoutAugmentTree({ nodes, group }: AugmentProgression) {
// Only placed nodes can have a line drawn from them
const byTechName = new Map(
nodes
.filter((node) => node.position !== undefined)
.map((node) => [node.tech_name, node]),
);
const edges: Edge[] = [];
const connect = (
requires: AugmentRequirement[],
toRow: number,
toColumn: number,
) => {
for (const { tech_name, vertical_first } of requires) {
// Nothing to draw from a node the tank doesn't have
if (!byTechName.has(tech_name)) continue;
const from = byTechName.get(tech_name)!.position!;
edges.push([from.y, from.x, toRow, toColumn, vertical_first]);
}
};
for (const node of nodes) {
if (node.position === undefined) continue;
connect(node.requires, node.position.y, node.position.x);
}
if (group !== undefined) {
connect(group.requires, group.position!.y, group.position!.x);
}
const grid = new CellGrid<AugmentTreeCell>(emptyCell);
const { cellAt } = grid;
for (const node of nodes) {
if (node.position !== undefined) {
cellAt(node.position.x, node.position.y).node = node;
}
}
if (group !== undefined) {
cellAt(group.position!.x, group.position!.y).group = group;
}
// Cells strictly between two ends, which stay untouched here
const runHorizontally = (row: number, from: number, to: number) => {
const step = from < to ? 1 : -1;
for (let column = from + step; column !== to; column += step) {
const cell = cellAt(column, row);
cell.left = true;
cell.right = true;
}
};
const runVertically = (column: number, from: number, to: number) => {
const step = from < to ? 1 : -1;
for (let row = from + step; row !== to; row += step) {
const cell = cellAt(column, row);
cell.top = true;
cell.bottom = true;
}
};
// Where a run turns, joining the vertical and horizontal pieces
const corner = (
row: number,
column: number,
otherRow: number,
otherColumn: number,
) => {
const cell = cellAt(column, row);
if (row <= otherRow) cell.bottom = true;
else cell.top = true;
if (column <= otherColumn) cell.right = true;
else cell.left = true;
};
// Attaches the line to both nodes
const attach = (
fromRow: number,
fromColumn: number,
toRow: number,
toColumn: number,
verticalFirst: boolean,
) => {
const from = cellAt(fromColumn, fromRow);
const to = cellAt(toColumn, toRow);
if (fromColumn === toColumn) {
if (fromRow < toRow) {
from.bottom = true;
to.top = true;
} else {
from.top = true;
to.bottom = true;
}
} else if (fromRow === toRow) {
if (toColumn <= fromColumn) {
from.left = true;
to.right = true;
} else {
from.right = true;
to.left = true;
}
} else if (verticalFirst) {
if (fromRow < toRow) from.bottom = true;
else from.top = true;
if (toColumn <= fromColumn) to.right = true;
else to.left = true;
} else {
if (fromColumn < toColumn) from.right = true;
else from.left = true;
if (fromRow < toRow) to.top = true;
else to.bottom = true;
}
};
for (const [fromRow, fromColumn, toRow, toColumn, verticalFirst] of edges) {
// The client draws nothing for an edge that starts where it ends
if (fromRow === toRow && fromColumn === toColumn) continue;
// Touching ends are left to `attach`
if (fromRow === toRow) {
if (fromColumn !== toColumn)
runHorizontally(fromRow, fromColumn, toColumn);
} else if (fromColumn === toColumn) {
runVertically(fromColumn, fromRow, toRow);
} else if (verticalFirst) {
// Down the source column, then along the target row
runVertically(fromColumn, fromRow, toRow);
corner(toRow, fromColumn, fromRow, toColumn);
runHorizontally(toRow, fromColumn, toColumn);
} else {
// Along the source row, then down the target column
runHorizontally(fromRow, fromColumn, toColumn);
corner(fromRow, toColumn, toRow, fromColumn);
runVertically(toColumn, fromRow, toRow);
}
attach(fromRow, fromColumn, toRow, toColumn, verticalFirst);
}
return {
cells: grid.cells().map(
({ position: [column, row], node, group, left, right, top, bottom }) =>
({
row: column,
column: row,
node,
group,
north: left,
south: right,
west: top,
east: bottom,
} satisfies AugmentTreeDisplayCell),
),
rows: grid.columns,
columns: grid.rows,
};
}
+177
View File
@@ -0,0 +1,177 @@
import {
AugmentNodeType,
type AugmentNode,
type AugmentProgression,
type TankDefinition,
} from "@blitzkit/protos";
import type { TankState } from "./tankState";
function isAlternative(node: AugmentNode) {
return node.type === AugmentNodeType.AUGMENT_NODE_TYPE_ALTERNATIVE;
}
// Alternatives live in the final group, outside the grid
export function listAugmentNodes({ nodes, group }: AugmentProgression) {
return [...nodes, ...(group?.alternatives ?? [])];
}
// Standing in for the final group, which has no id of its own
export const AUGMENT_GROUP_ID = -1;
function directPrerequisites(
progression: AugmentProgression,
node: AugmentNode,
) {
const byTechName = new Map(
progression.nodes.map((other) => [other.tech_name, other.id]),
);
const requires = isAlternative(node)
? progression.group?.requires ?? []
: node.requires;
return requires.flatMap(({ tech_name }) => byTechName.get(tech_name) ?? []);
}
// Everything the given nodes stand on, the nodes themselves included
function foundations(progression: AugmentProgression, ids: number[]) {
const byId = new Map(
listAugmentNodes(progression).map((node) => [node.id, node]),
);
const found = new Set<number>();
const pending = [...ids];
while (pending.length > 0) {
const id = pending.pop()!;
const node = byId.get(id);
if (found.has(id) || node === undefined) continue;
found.add(id);
pending.push(...directPrerequisites(progression, node));
}
return found;
}
/**
* Like picking a module: choosing an augment installs everything on the way to
* it. Choosing one that is already installed steps back to it by removing
* what was built on top, and removes it too once nothing is left on top. The
* final group is a choice, so installing one alternative replaces the other.
*/
export function toggleAugment(
draft: Pick<TankState, "augments">,
progression: AugmentProgression,
id: number,
) {
const nodes = listAugmentNodes(progression);
const installed = new Set(draft.augments);
const alternatives = new Set(
progression.group?.alternatives.map((alternative) => alternative.id),
);
if (id === AUGMENT_GROUP_ID) {
const { group } = progression;
if (group === undefined) return;
const needed = directPrerequisites(progression, group.alternatives[0]);
if (needed.every((other) => installed.has(other))) {
// Already there, so back out of the choice
draft.augments = draft.augments.filter(
(other) => !alternatives.has(other),
);
} else {
for (const other of foundations(progression, needed))
installed.add(other);
draft.augments = [...installed];
}
return;
}
const node = nodes.find((candidate) => candidate.id === id);
if (node === undefined) return;
if (!installed.has(id)) {
for (const other of foundations(progression, [id])) installed.add(other);
if (alternatives.has(id)) {
for (const other of alternatives)
if (other !== id) installed.delete(other);
}
draft.augments = [...installed];
return;
}
// Everything installed that stands on this one, however far up
const above = new Set<number>();
let grew = true;
while (grew) {
grew = false;
for (const other of nodes) {
if (!installed.has(other.id) || above.has(other.id)) continue;
const stands = directPrerequisites(progression, other).some(
(prerequisite) => prerequisite === id || above.has(prerequisite),
);
if (!stands) continue;
above.add(other.id);
grew = true;
}
}
const removed = above.size > 0 ? above : new Set([id]);
draft.augments = draft.augments.filter((other) => !removed.has(other));
}
// Everything in the grid. The final group still needs a choice
export function createAugments(progression?: AugmentProgression) {
if (!progression) return [];
return progression.nodes.map((node) => node.id);
}
// Every value the installed augments give each attribute, keyed by the
// attribute's name without the `ATTRIBUTE_NAME_` prefix
export function augmentAttributes(
{ augment_progression }: TankDefinition,
state: TankState,
) {
const attributes = new Map<string, number[]>();
if (augment_progression === undefined) return attributes;
const installed = new Set(state.augments);
for (const node of listAugmentNodes(augment_progression)) {
if (!installed.has(node.id)) continue;
for (const { name, value } of node.attributes) {
const key = name.replace(/^ATTRIBUTE_NAME_/, "");
if (!attributes.has(key)) attributes.set(key, []);
attributes.get(key)!.push(value);
}
}
return attributes;
}
// Slots are the position of the shell in the gun's list, counted from 1
export function shellSlot(
gun: { shells: { id: number }[] },
shell: { id: number },
) {
return gun.shells.findIndex(({ id }) => id === shell.id) + 1;
}
@@ -0,0 +1,41 @@
import type { Vector2Tuple } from "three";
// A sparse grid that grows to fit whatever is placed on it, shared by the
// module and augment trees. Cells are indexed column first, then row
export class CellGrid<Cell extends { position: Vector2Tuple }> {
private readonly columnCells = new Map<number, Map<number, Cell>>();
// Highest 1-based column and row anything has been placed at
columns = 0;
rows = 0;
constructor(
private readonly createCell: (column: number, row: number) => Cell,
) {}
// An arrow, so it can be pulled off the grid and called on its own
cellAt = (column: number, row: number) => {
let cells = this.columnCells.get(column);
if (cells === undefined) {
cells = new Map();
this.columnCells.set(column, cells);
}
let cell = cells.get(row);
if (cell === undefined) {
cell = this.createCell(column, row);
cells.set(row, cell);
this.columns = Math.max(this.columns, column);
this.rows = Math.max(this.rows, row);
}
return cell;
};
cells() {
return [...this.columnCells.values()].flatMap((cells) => [
...cells.values(),
]);
}
}
@@ -1,6 +1,7 @@
import { createDefaultProvisions } from "@blitzkit/core";
import type { TankDefinition } from "@blitzkit/protos";
import { api } from "../api/dynamic";
import { createAugments } from "./augments";
import { createTankEquipment } from "./createTankEquipment";
import { createTankStatus } from "./createTankStatus";
import type { TankState } from "./tankState";
@@ -36,6 +37,7 @@ export function createTankState(tank: TankDefinition) {
model: models.models[tank.id],
consumables: [],
augments: createAugments(tank.augment_progression),
provisions: createDefaultProvisions(tank, gun, provisions, scripts),
camouflage: true,
cooldown_booster: 0,
@@ -1,30 +1,4 @@
import type {
CharacteristicContext,
CharacteristicScript,
} from "../types/characteristics";
function hullTraverseRotationCoefficient(
driverCoefficient: number,
virtuosoSkill: number,
script: CharacteristicScript,
) {
let coefficient = 1 + virtuosoSkill / 100;
let rotationSpeedFactor = 1;
script("protagonist", "StaticPhysicsAttrsModifier", (effect) => {
coefficient += (effect.bonusPercentage?.rotationSpeedFactor ?? 0) / 100;
});
script("protagonist", "ImprovedAfterburning", (effect) => {
rotationSpeedFactor *= effect.rotationSpeedFactor ?? 1;
});
script("protagonist", "AfterburnerAbility", (effect) => {
rotationSpeedFactor *= effect.bonusValues?.rotationSpeedFactor ?? 1;
});
return driverCoefficient * coefficient * rotationSpeedFactor;
}
import type { CharacteristicContext } from "../types/characteristics";
export function hullTraverseSpeed(
rawTerrainResistance: number,
@@ -38,6 +12,7 @@ export function hullTraverseSpeed(
gun,
progressive,
script,
augment,
environment,
characteristic,
} = context;
@@ -54,14 +29,32 @@ export function hullTraverseSpeed(
stockGun.weight;
const weight =
tank.weight + engine.weight + track.weight + turret.weight + gun.weight;
// Engine augments are flat, so this goes through the finished stat
const enginePower =
(engine.power * (characteristic("_engine_power_coefficient") as number)) /
stockEngine.power;
const rotationSpeed = hullTraverseRotationCoefficient(
progressive("driver"),
environment.skills.virtuoso ?? 0,
script,
);
(characteristic("engine_power") as number) / stockEngine.power;
const virtuosoSkill = environment.skills.virtuoso ?? 0;
let rotationCoefficient = 1 + virtuosoSkill / 100;
let rotationSpeedFactor = 1;
augment("HULL_ROTATION_SPEED_FACTOR_BONUS", (value) => {
rotationCoefficient += value;
});
script("protagonist", "StaticPhysicsAttrsModifier", (effect) => {
rotationCoefficient +=
(effect.bonusPercentage?.rotationSpeedFactor ?? 0) / 100;
});
script("protagonist", "ImprovedAfterburning", (effect) => {
rotationSpeedFactor *= effect.rotationSpeedFactor ?? 1;
});
script("protagonist", "AfterburnerAbility", (effect) => {
rotationSpeedFactor *= effect.bonusValues?.rotationSpeedFactor ?? 1;
});
const rotationSpeed =
progressive("driver") * rotationCoefficient * rotationSpeedFactor;
return (
enginePower *
@@ -1,9 +1,10 @@
import { ModuleType, type ModulePosition, type Unlock } from "@blitzkit/protos";
import type { Vector2Tuple } from "three";
import { CellGrid } from "./cellGrid";
/**
* Port of the game client's modules screen layout (wotblitz.exe 11.21,
* `ModulesTreeInfoCache` auto-layout + `TankModulesTreeController` arrows).
* Follows how the game lays out its modules screen: automatic placement and
* the arrows.
*
* Every node lives on one shared grid: depth is the column, and leaves take
* consecutive rows with each parent centered over its children. Connectors are
@@ -58,13 +59,6 @@ function key(unlock: Unlock) {
return `${unlock.type}:${unlock.id}`;
}
// Cells are indexed column first, then row
type CellGrid = Map<number, Map<number, ModuleTreeCell>>;
function flattenGrid(grid: CellGrid) {
return [...grid.values()].flatMap((column) => [...column.values()]);
}
function emptyCell(x: number, y: number) {
return {
position: [x, y],
@@ -93,7 +87,7 @@ function layoutSnake(placements: Placement[]) {
// The client takes this from whichever deep module sorts last
const lastOnFirstRow = deep.length > 0 && deep.at(-1)!.position[1] === 1;
const grid: CellGrid = new Map();
const grid = new CellGrid<ModuleTreeCell>(emptyCell);
for (const {
unlock,
@@ -113,17 +107,10 @@ function layoutSnake(placements: Placement[]) {
: offset + 1;
}
let columnCells = grid.get(column);
if (columnCells === undefined) {
columnCells = new Map();
grid.set(column, columnCells);
}
columnCells.set(row, { ...emptyCell(column, row), unlock });
grid.cellAt(column, row).unlock = unlock;
}
const cells = flattenGrid(grid);
const cells = grid.cells();
const width = Math.ceil(ordered.length / height);
for (const cell of cells) {
@@ -149,15 +136,11 @@ function layoutSnake(placements: Placement[]) {
}
}
let columns = width;
let rows = height;
for (const cell of cells) {
columns = Math.max(columns, cell.position[0]);
rows = Math.max(rows, cell.position[1]);
}
return { cells, columns, rows };
return {
cells,
columns: Math.max(width, grid.columns),
rows: Math.max(height, grid.rows),
};
}
function sortSiblings(unlocks: Unlock[]) {
@@ -259,29 +242,8 @@ export function layoutModuleTree(
if (isSnake) return layoutSnake([...placements.values()]);
const grid: CellGrid = new Map();
let columns = 0;
let rows = 0;
const cellAt = (x: number, y: number) => {
let columnCells = grid.get(x);
if (columnCells === undefined) {
columnCells = new Map();
grid.set(x, columnCells);
}
let cell = columnCells.get(y);
if (cell === undefined) {
cell = emptyCell(x, y);
columnCells.set(y, cell);
columns = Math.max(columns, x);
rows = Math.max(rows, y);
}
return cell;
};
const grid = new CellGrid<ModuleTreeCell>(emptyCell);
const { cellAt } = grid;
for (const {
unlock,
@@ -316,5 +278,5 @@ export function layoutModuleTree(
}
}
return { cells: flattenGrid(grid), columns, rows };
return { cells: grid.cells(), columns: grid.columns, rows: grid.rows };
}
@@ -2,7 +2,7 @@ import { characteristics } from "../config/characteristics";
import { characteristicsGroups } from "../config/characteristicsGroups";
import {
CharacteristicType,
type CharacteristicName,
type RenderedCharacteristicName,
} from "../types/characteristics";
const sortableCharacteristicTypes = new Set<CharacteristicType>([
@@ -11,9 +11,11 @@ const sortableCharacteristicTypes = new Set<CharacteristicType>([
CharacteristicType.Interval,
]);
export const sortableCharacteristics = new Set<CharacteristicName>();
export const sortableCharacteristics = new Set<RenderedCharacteristicName>();
for (const group of characteristicsGroups) {
if (!group.sortable) continue;
for (const config of group.order) {
if (!("name" in config)) continue;
@@ -18,6 +18,7 @@ export interface TankState {
consumables: number[];
provisions: number[];
augments: number[];
camouflage: boolean;
cooldown_booster: number;
}