Private
Public Access
1
0

feat(gameplay): Adding a military power section to exploit population numbers and steal ennemy tiles

This commit is contained in:
gauvainboiche
2026-03-31 18:27:08 +02:00
parent e04560c7f9
commit 570d83c3c0
10 changed files with 587 additions and 9 deletions

View File

@@ -54,6 +54,26 @@ export async function initGameSchema() {
PRIMARY KEY (world_seed, team)
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS team_military_deductions (
world_seed TEXT NOT NULL,
team TEXT NOT NULL CHECK (team IN ('blue', 'red')),
deducted DOUBLE PRECISION NOT NULL DEFAULT 0,
PRIMARY KEY (world_seed, team)
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS cell_attack_log (
id SERIAL PRIMARY KEY,
world_seed TEXT NOT NULL,
x SMALLINT NOT NULL,
y SMALLINT NOT NULL,
attacking_team TEXT NOT NULL CHECK (attacking_team IN ('blue', 'red')),
attacked_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_cell_attack_log_seed_xy
ON cell_attack_log (world_seed, x, y);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS db_metadata (
id SERIAL PRIMARY KEY,
@@ -124,6 +144,8 @@ export async function ensureSeedEpoch() {
await pool.query("DELETE FROM user_cooldowns WHERE world_seed != $1", [worldSeed]);
await pool.query("DELETE FROM team_econ_scores WHERE world_seed != $1", [worldSeed]);
await pool.query("DELETE FROM team_element_bonus WHERE world_seed != $1", [worldSeed]);
await pool.query("DELETE FROM team_military_deductions WHERE world_seed != $1", [worldSeed]);
await pool.query("DELETE FROM cell_attack_log WHERE world_seed != $1", [worldSeed]);
console.log(`[world] Slot ${lastSeedSlot}${seedSlot}; grid wiped, old cooldowns cleared.`);
lastSeedSlot = seedSlot;
}
@@ -287,3 +309,49 @@ export async function getActivePlayerCounts(worldSeed) {
for (const row of rows) result[row.team] = row.count;
return result;
}
// ── Military deductions ───────────────────────────────────────────────────────
export async function getMilitaryDeductions(worldSeed) {
const { rows } = await pool.query(
`SELECT team, deducted FROM team_military_deductions WHERE world_seed = $1`,
[worldSeed]
);
const result = { blue: 0, red: 0 };
for (const row of rows) result[row.team] = Number(row.deducted);
return result;
}
export async function addMilitaryDeduction(worldSeed, team, amount) {
await pool.query(
`INSERT INTO team_military_deductions (world_seed, team, deducted)
VALUES ($1, $2, $3)
ON CONFLICT (world_seed, team) DO UPDATE
SET deducted = team_military_deductions.deducted + EXCLUDED.deducted`,
[worldSeed, team, amount]
);
}
// ── Cell attack log ───────────────────────────────────────────────────────────
export async function recordCellAttack(worldSeed, x, y, attackingTeam) {
await pool.query(
`INSERT INTO cell_attack_log (world_seed, x, y, attacking_team) VALUES ($1, $2, $3, $4)`,
[worldSeed, x, y, attackingTeam]
);
}
export async function getCellAttackCount(worldSeed, x, y) {
const { rows } = await pool.query(
`SELECT COUNT(*)::int AS cnt FROM cell_attack_log WHERE world_seed = $1 AND x = $2 AND y = $3`,
[worldSeed, x, y]
);
return rows[0]?.cnt ?? 0;
}
export async function setTileOwner(worldSeed, x, y, team) {
await pool.query(
`UPDATE grid_cells SET discovered_by = $1 WHERE world_seed = $2 AND x = $3 AND y = $4`,
[team, worldSeed, x, y]
);
}