Compare commits
3 Commits
1261f7149b
...
4d864503f2
| Author | SHA1 | Date |
|---|---|---|
|
|
4d864503f2 | |
|
|
325692fa35 | |
|
|
e4ad09de67 |
Binary file not shown.
|
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 171 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 150 KiB |
Binary file not shown.
|
|
@ -11,7 +11,7 @@
|
|||
"terrainSheet": { "key": "civilization-terrain", "path": "assets/images/civilization/civilization-terrain.png", "frameWidth": 128, "frameHeight": 96 },
|
||||
"resourceSheet": { "key": "civilization-resources", "path": null, "frameWidth": 64, "frameHeight": 64 },
|
||||
"improvementSheet": { "key": "civilization-improvements", "path": null, "frameWidth": 64, "frameHeight": 64 },
|
||||
"unitSheet": { "key": "civilization-units", "path": null, "frameWidth": 64, "frameHeight": 64 },
|
||||
"unitSheet": { "key": "civilization-units", "path": "assets/images/civilization/civilization-units.png", "frameWidth": 64, "frameHeight": 96 },
|
||||
"iconSheet": { "key": "civilization-icons", "path": null, "frameWidth": 48, "frameHeight": 48 },
|
||||
"citySheets": {
|
||||
"classic": { "key": "civilization-cities-classic", "path": null, "frameWidth": 128, "frameHeight": 96 }
|
||||
|
|
|
|||
|
|
@ -114,9 +114,10 @@ export function openCityScreen(scene, rules, state, city, onClose) {
|
|||
const rx = px + 60;
|
||||
const cost = Logic.buildCost(rules, city);
|
||||
const cur = city.build.type === 'unit' ? rules.units[city.build.id] : rules.buildings[city.build.id];
|
||||
const turns = y.shield > 0 ? Math.ceil((cost - city.shieldBox) / y.shield) : '∞';
|
||||
const shownShields = Math.min(city.shieldBox, cost);
|
||||
const turns = y.shield > 0 ? Math.max(0, Math.ceil((cost - shownShields) / y.shield)) : '∞';
|
||||
dynamic.add(scene.add.text(rx, top + 64,
|
||||
`Building: ${cur.name} ${city.shieldBox}/${cost} shields (${turns} turns)`, {
|
||||
`Building: ${cur.name} ${shownShields}/${cost} shields (${turns} turns)`, {
|
||||
fontFamily: FONT, fontSize: '22px', color: COLORS.textHex,
|
||||
}));
|
||||
const buyPrice = Logic.buyCost(rules, city);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
import * as Phaser from 'phaser';
|
||||
import { GAME_WIDTH, GAME_HEIGHT, COLORS } from '../../config.js';
|
||||
import { Button } from '../../ui/Button.js';
|
||||
import { TextInput } from '../../ui/TextInput.js';
|
||||
import { MusicPlayer } from '../../ui/MusicPlayer.js';
|
||||
import { compileRules, turnToYear, formatYear } from './CivilizationRules.js';
|
||||
import * as Logic from './CivilizationLogic.js';
|
||||
|
|
@ -32,6 +33,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
this.phase = 'setup';
|
||||
this.modalOpen = false;
|
||||
this.busy = false;
|
||||
this.endTurnFlashTween = null;
|
||||
}
|
||||
|
||||
create() {
|
||||
|
|
@ -382,7 +384,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
});
|
||||
this.input.on('wheel', (pointer, objs, dx, dy) => {
|
||||
if (this.modalOpen || this.phase !== 'playing') return;
|
||||
this.view.zoomBy(dy > 0 ? -1 : 1);
|
||||
this.view.zoomBy(dy > 0 ? -1 : 1, pointer.x, pointer.y);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -425,7 +427,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
moveTo(unit, c, r) {
|
||||
if (this.state.current !== this.state.humanIndex) return;
|
||||
if (Logic.cheb(unit.x, unit.y, c, r) === 1) {
|
||||
this.tryStep(unit, c - unit.x, r - unit.y);
|
||||
this.tryStep(unit, c - unit.x, r - unit.y, true);
|
||||
return;
|
||||
}
|
||||
const path = Logic.findPath(this.rules, this.state, unit, c, r);
|
||||
|
|
@ -508,6 +510,28 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
if (unit) this.view.centerOnIfOffscreen?.(unit.x, unit.y);
|
||||
this.view.refresh();
|
||||
this.refreshUnitPanel();
|
||||
// Nothing left to move this turn — nudge the player toward End Turn.
|
||||
const noneLeft = !unit && this.phase === 'playing' && !this.busy
|
||||
&& this.state?.current === this.state?.humanIndex;
|
||||
this.setEndTurnFlash(noneLeft);
|
||||
}
|
||||
|
||||
setEndTurnFlash(on) {
|
||||
if (on === !!this.endTurnFlashTween) return;
|
||||
if (!on) {
|
||||
this.endTurnFlashTween?.stop();
|
||||
this.endTurnFlashTween = null;
|
||||
this.endTurnBtn?.setAlpha(1);
|
||||
return;
|
||||
}
|
||||
this.endTurnFlashTween = this.tweens.add({
|
||||
targets: this.endTurnBtn,
|
||||
alpha: 0.55,
|
||||
duration: 550,
|
||||
yoyo: true,
|
||||
repeat: -1,
|
||||
ease: 'Sine.easeInOut',
|
||||
});
|
||||
}
|
||||
|
||||
selectNextUnit() {
|
||||
|
|
@ -521,49 +545,95 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
this.view.centerOn(next.x, next.y);
|
||||
}
|
||||
|
||||
tryStep(unit, dx, dy) {
|
||||
tryStep(unit, dx, dy, animate = false) {
|
||||
if (this.state.current !== this.state.humanIndex) return;
|
||||
const from = [unit.x, unit.y];
|
||||
const out = unit.carriedBy
|
||||
? Logic.disembark(this.rules, this.state, unit, dx, dy)
|
||||
: Logic.tryMove(this.rules, this.state, unit, dx, dy);
|
||||
if (out.result === 'blocked' && out.needsWar !== undefined) {
|
||||
this.confirmWar(out.needsWar, () => {
|
||||
Logic.declareWar(this.rules, this.state, this.state.humanIndex, out.needsWar);
|
||||
this.tryStep(unit, dx, dy);
|
||||
this.tryStep(unit, dx, dy, animate);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (out.result === 'invalid') return;
|
||||
if (out.hut) this.toastHut(out.hut);
|
||||
this.afterAction();
|
||||
if (unit.mp <= 0 && this.state.units.includes(unit)) this.selectNextUnit();
|
||||
if (!this.state.units.includes(unit)) this.selectNextUnit();
|
||||
const finish = () => {
|
||||
this.afterAction();
|
||||
if (unit.mp <= 0 && this.state.units.includes(unit)) this.selectNextUnit();
|
||||
if (!this.state.units.includes(unit)) this.selectNextUnit();
|
||||
};
|
||||
const combatEvents = this.collectNewCombatEvents();
|
||||
if (combatEvents.length) {
|
||||
this.busy = true;
|
||||
this.view.animateCombat(combatEvents, () => { this.busy = false; finish(); });
|
||||
return;
|
||||
}
|
||||
const moved = unit.x !== from[0] || unit.y !== from[1];
|
||||
if (!animate || !moved) { finish(); return; }
|
||||
this.animateMoveThen([from, [unit.x, unit.y]], finish);
|
||||
}
|
||||
|
||||
walkPath(unit, path) {
|
||||
// Step along the found path until movement runs out or something happens.
|
||||
// Resolve the whole turn's worth of movement instantly (combat, huts,
|
||||
// etc. all need the real logic), then replay the tiles actually crossed
|
||||
// as a smooth glide so the player sees continuous motion, not a snap.
|
||||
// A combat step always ends the walk — the rest of the original path
|
||||
// no longer applies once a fight breaks out.
|
||||
const visited = [[unit.x, unit.y]];
|
||||
let i = 0;
|
||||
const step = () => {
|
||||
if (i >= path.length || unit.mp <= 0 || !this.state.units.includes(unit) || this.state.over) {
|
||||
this.view.showPath(null);
|
||||
this.afterAction();
|
||||
if (!this.state.units.includes(unit) || unit.mp <= 0) this.selectNextUnit();
|
||||
return;
|
||||
}
|
||||
let hutEvent = null;
|
||||
while (i < path.length && unit.mp > 0 && this.state.units.includes(unit) && !this.state.over) {
|
||||
const [nx, ny] = path[i];
|
||||
i += 1;
|
||||
const out = Logic.tryMove(this.rules, this.state, unit,
|
||||
Math.sign(nx - unit.x), Math.sign(ny - unit.y));
|
||||
if (out.result === 'invalid' || out.result === 'blocked') {
|
||||
this.view.showPath(null);
|
||||
this.afterAction();
|
||||
return;
|
||||
}
|
||||
if (out.hut) this.toastHut(out.hut);
|
||||
this.view.refresh();
|
||||
this.time.delayedCall(60, step);
|
||||
if (out.result === 'invalid' || out.result === 'blocked' || out.result === 'combat') break;
|
||||
if (out.hut) hutEvent = out.hut;
|
||||
visited.push([unit.x, unit.y]);
|
||||
}
|
||||
if (hutEvent) this.toastHut(hutEvent);
|
||||
const finish = () => {
|
||||
this.view.showPath(null);
|
||||
this.afterAction();
|
||||
if (!this.state.units.includes(unit) || unit.mp <= 0) this.selectNextUnit();
|
||||
};
|
||||
step();
|
||||
const combatEvents = this.collectNewCombatEvents();
|
||||
if (combatEvents.length) {
|
||||
// Walk the peaceful leg of the path first, then play the clash.
|
||||
this.animateMoveThen(visited, () => {
|
||||
this.busy = true;
|
||||
this.view.animateCombat(combatEvents, () => { this.busy = false; finish(); });
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.animateMoveThen(visited, finish);
|
||||
}
|
||||
|
||||
// Picks up any 'combat' events pushed since the last time this ran
|
||||
// (marking them consumed so they never replay), for the caller to animate.
|
||||
collectNewCombatEvents() {
|
||||
const found = [];
|
||||
for (const e of this.state.events) {
|
||||
if (e.type === 'combat' && !e.animated) { e.animated = true; found.push(e); }
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// Glides the selected unit's marker smoothly across `tiles`
|
||||
// ([[c,r], ...], already-resolved positions) over 1s, pauses 250ms at the
|
||||
// destination, then invokes `finish`. Falls straight through to `finish`
|
||||
// when there's nothing to animate (unit didn't actually move).
|
||||
animateMoveThen(tiles, finish) {
|
||||
if (tiles.length < 2) { finish(); return; }
|
||||
this.view.refresh();
|
||||
this.busy = true;
|
||||
this.view.animateUnitAlong(tiles, 1000, 250, () => {
|
||||
this.busy = false;
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
tryFound(unit) {
|
||||
|
|
@ -573,13 +643,55 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
this.toast('Cannot found a city here');
|
||||
return;
|
||||
}
|
||||
const city = Logic.foundCity(this.rules, this.state, unit);
|
||||
if (city) {
|
||||
this.toast(`${city.name} founded!`);
|
||||
this.view.repaintTileAndNeighbors(city.x, city.y);
|
||||
this.afterAction();
|
||||
this.selectNextUnit();
|
||||
}
|
||||
if (this.modalOpen) return;
|
||||
const defaultName = Logic.peekCityName(this.rules, this.state, unit.civ);
|
||||
this.promptCityName(defaultName, (name) => {
|
||||
const city = Logic.foundCity(this.rules, this.state, unit, name);
|
||||
if (city) {
|
||||
this.toast(`${city.name} founded!`);
|
||||
this.view.repaintTileAndNeighbors(city.x, city.y);
|
||||
this.afterAction();
|
||||
this.selectNextUnit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
promptCityName(defaultName, onConfirm) {
|
||||
this.modalOpen = true;
|
||||
const cx = GAME_WIDTH / 2;
|
||||
const cy = GAME_HEIGHT / 2;
|
||||
const root = this.add.container(0, 0).setDepth(D.modal);
|
||||
const dim = this.add.rectangle(cx, cy, GAME_WIDTH, GAME_HEIGHT, 0x000000, 0.55).setInteractive();
|
||||
const panel = this.add.rectangle(cx, cy, 560, 240, COLORS.panel).setStrokeStyle(2, COLORS.accent);
|
||||
const title = this.add.text(cx, cy - 84, 'Found City', {
|
||||
fontFamily: 'Righteous', fontSize: '26px', color: COLORS.accentHex,
|
||||
}).setOrigin(0.5);
|
||||
const label = this.add.text(cx, cy - 40, 'Name this city:', {
|
||||
fontFamily: FONT, fontSize: '18px', color: COLORS.textHex,
|
||||
}).setOrigin(0.5);
|
||||
root.add([dim, panel, title, label]);
|
||||
|
||||
const input = new TextInput(this, cx, cy + 4, {
|
||||
width: 380, height: 48, value: defaultName, maxLength: 24, autocomplete: 'off',
|
||||
});
|
||||
input.focus();
|
||||
input.el.select();
|
||||
|
||||
const close = () => { input.destroy(); root.destroy(true); this.modalOpen = false; };
|
||||
const confirm = () => {
|
||||
const name = input.value.trim() || defaultName;
|
||||
close();
|
||||
onConfirm(name);
|
||||
};
|
||||
input.on('keydown', (e) => {
|
||||
if (e.key === 'Enter') confirm();
|
||||
else if (e.key === 'Escape') close();
|
||||
});
|
||||
|
||||
const found = new Button(this, cx - 110, cy + 68, 'FOUND', confirm, { width: 180, height: 52 });
|
||||
const cancel = new Button(this, cx + 110, cy + 68, 'CANCEL', close,
|
||||
{ width: 180, height: 52, variant: 'ghost' });
|
||||
root.add([found, cancel]);
|
||||
}
|
||||
|
||||
tryWork(unit, impId) {
|
||||
|
|
@ -645,6 +757,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
}
|
||||
|
||||
runToHumanTurn() {
|
||||
this.setEndTurnFlash(false);
|
||||
this.busy = true;
|
||||
this.endTurnBtn?.setAlpha(0.4);
|
||||
this.refreshUnitPanel();
|
||||
|
|
@ -658,11 +771,36 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
return;
|
||||
}
|
||||
Logic.beginCivTurn(this.rules, this.state, cur);
|
||||
const before = new Map(Logic.civUnits(this.state, cur).map((u) => [u.id, [u.x, u.y]]));
|
||||
runAITurn(this.rules, this.state, cur);
|
||||
Logic.endCivTurn(this.rules, this.state, cur);
|
||||
this.view.refresh();
|
||||
this.refreshHud();
|
||||
this.time.delayedCall(90, stepCiv);
|
||||
// Resolve the whole civ's turn instantly (as ever). Combats play first,
|
||||
// from whatever's still on screen from before this civ acted (no
|
||||
// refresh yet, so a ghost can stand in for a unit that's already dead
|
||||
// or already moved); then one refresh syncs everyone else, and the
|
||||
// remaining units' start/end tiles are diffed and glided — same
|
||||
// "resolve now, animate after" trick as the player's own moves, just
|
||||
// via a before/after snapshot instead of a waypoint path.
|
||||
const combatEvents = this.collectNewCombatEvents();
|
||||
const visibleCombat = combatEvents.filter((e) => this.view.isTileVisible(e.ax, e.ay)
|
||||
|| this.view.isTileVisible(e.x, e.y));
|
||||
const combatUnitIds = new Set(combatEvents.flatMap((e) => [e.attackerId, e.defenderId]));
|
||||
const moves = [];
|
||||
for (const [id, from] of before) {
|
||||
if (combatUnitIds.has(id)) continue;
|
||||
const u = Logic.unitById(this.state, id);
|
||||
if (!u || u.carriedBy) continue;
|
||||
if (u.x !== from[0] || u.y !== from[1]) moves.push({ unitId: id, from, to: [u.x, u.y] });
|
||||
}
|
||||
const afterCombat = () => {
|
||||
this.view.refresh();
|
||||
this.refreshHud();
|
||||
this.view.animateUnitsAlong(moves, 1000, 250, () => {
|
||||
this.time.delayedCall(90, stepCiv);
|
||||
});
|
||||
};
|
||||
if (visibleCombat.length) this.view.animateCombat(visibleCombat, afterCombat);
|
||||
else afterCombat();
|
||||
};
|
||||
stepCiv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -378,16 +378,28 @@ export function cityYields(rules, state, city) {
|
|||
// ---------------------------------------------------------------------------
|
||||
// Cities
|
||||
|
||||
export function nextCityName(rules, state, civ) {
|
||||
// Read-only preview of the name a new city would get, without consuming it
|
||||
// from the pool — lets UI show a default before the player confirms.
|
||||
export function peekCityName(rules, state, civ) {
|
||||
const c = state.civs[civ];
|
||||
if (civCities(state, civ).length === 0) return `${c.name} City`;
|
||||
const pool = rules.cityNames;
|
||||
const idx = c.nameOrder[c.nameCursor % pool.length];
|
||||
const round = Math.floor(c.nameCursor / pool.length);
|
||||
c.nameCursor += state.civs.length;
|
||||
return round > 0 ? `${pool[idx]} ${'I'.repeat(round + 1)}` : pool[idx];
|
||||
}
|
||||
|
||||
function advanceCityNameCursor(state, civ) {
|
||||
if (civCities(state, civ).length === 0) return; // first city never draws from the pool
|
||||
state.civs[civ].nameCursor += state.civs.length;
|
||||
}
|
||||
|
||||
export function nextCityName(rules, state, civ) {
|
||||
const name = peekCityName(rules, state, civ);
|
||||
advanceCityNameCursor(state, civ);
|
||||
return name;
|
||||
}
|
||||
|
||||
export function canFoundCity(rules, state, x, y) {
|
||||
const terr = terrainAt(rules, state.world, x, y);
|
||||
if (terr.water || terr.id === 'glacier') return false;
|
||||
|
|
@ -397,15 +409,17 @@ export function canFoundCity(rules, state, x, y) {
|
|||
return true;
|
||||
}
|
||||
|
||||
export function foundCity(rules, state, unit) {
|
||||
export function foundCity(rules, state, unit, name) {
|
||||
if (!canFoundCity(rules, state, unit.x, unit.y)) return null;
|
||||
const civ = state.civs[unit.civ];
|
||||
const cityName = name && name.trim() ? name.trim() : peekCityName(rules, state, unit.civ);
|
||||
advanceCityNameCursor(state, unit.civ);
|
||||
const city = {
|
||||
id: state.nextCityId,
|
||||
civ: unit.civ,
|
||||
x: unit.x,
|
||||
y: unit.y,
|
||||
name: nextCityName(rules, state, unit.civ),
|
||||
name: cityName,
|
||||
size: 1,
|
||||
foodBox: 0,
|
||||
shieldBox: 0,
|
||||
|
|
@ -534,8 +548,11 @@ function processCity(rules, state, city) {
|
|||
if (city.size <= 0) { destroyCity(rules, state, city); return; }
|
||||
}
|
||||
|
||||
// Shields.
|
||||
city.shieldBox += y.shield;
|
||||
// Shields. Capped at cost — a settler build stalled on city.size < 2
|
||||
// (see completeBuild) would otherwise keep banking shields turn after
|
||||
// turn with nowhere to go, showing e.g. "60/40 shields" and a negative
|
||||
// turn count once shields overshot the cost.
|
||||
city.shieldBox = Math.min(city.shieldBox + y.shield, buildCost(rules, city));
|
||||
if (city.shieldBox >= buildCost(rules, city)) completeBuild(rules, state, city);
|
||||
city.boughtThisTurn = false;
|
||||
|
||||
|
|
@ -919,6 +936,15 @@ export function resolveAttack(rules, state, attacker, tx, ty) {
|
|||
return { result: 'nuked' };
|
||||
}
|
||||
|
||||
const ax = attacker.x;
|
||||
const ay = attacker.y;
|
||||
const attackerId = attacker.id;
|
||||
const attackerCiv = attacker.civ;
|
||||
const attackerType = attacker.type;
|
||||
const defenderId = defender.id;
|
||||
const defenderCiv = defender.civ;
|
||||
const defenderType = defender.type;
|
||||
|
||||
const A = attackerStrength(rules, state, attacker);
|
||||
const D = defenderStrength(rules, state, defender, attacker);
|
||||
const duel = simulateDuel(state, A, attDef.hp, attDef.fp, D, defDef.hp, defDef.fp, attacker.hp);
|
||||
|
|
@ -927,6 +953,10 @@ export function resolveAttack(rules, state, attacker, tx, ty) {
|
|||
const idx = tileIndex(state.world, tx, ty);
|
||||
const protectedStack = !!city || !!(state.world.improvements[idx] & IMP.FORTRESS);
|
||||
|
||||
// Advance-after-kill: an unopposed winner (not a self-destructing missile)
|
||||
// steps onto the tile it just cleared, matching the victory-glide the UI
|
||||
// plays for it.
|
||||
let advanced = false;
|
||||
if (duel.attackerWon) {
|
||||
removeUnit(state, defender);
|
||||
if (!protectedStack) {
|
||||
|
|
@ -934,6 +964,14 @@ export function resolveAttack(rules, state, attacker, tx, ty) {
|
|||
}
|
||||
attacker.hp = Math.max(1, duel.attackerHp);
|
||||
if (!attacker.vet && rand(state) < 0.5) attacker.vet = true;
|
||||
if (!attDef.flags.includes('missile') && unitsAt(state, tx, ty).length === 0) {
|
||||
attacker.x = tx;
|
||||
attacker.y = ty;
|
||||
dropCarried(rules, state, attacker, tx, ty);
|
||||
exploreAround(state, attacker.civ, tx, ty, 2);
|
||||
makeContacts(rules, state, attacker.civ, tx, ty);
|
||||
advanced = true;
|
||||
}
|
||||
} else {
|
||||
defender.hp = Math.max(1, duel.defenderHp);
|
||||
if (!defender.vet && rand(state) < 0.5) defender.vet = true;
|
||||
|
|
@ -943,10 +981,11 @@ export function resolveAttack(rules, state, attacker, tx, ty) {
|
|||
if (attDef.flags.includes('missile') && duel.attackerWon) removeUnit(state, attacker);
|
||||
|
||||
state.events.push({
|
||||
type: 'combat', x: tx, y: ty,
|
||||
attacker: { civ: attacker.civ, type: attacker.type },
|
||||
defender: { civ: defender.civ, type: defender.type },
|
||||
type: 'combat', x: tx, y: ty, ax, ay,
|
||||
attackerId, attackerCiv, attackerType,
|
||||
defenderId, defenderCiv, defenderType,
|
||||
attackerWon: duel.attackerWon,
|
||||
advanced,
|
||||
});
|
||||
checkVictory(rules, state);
|
||||
return { result: 'combat', won: duel.attackerWon };
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ import {
|
|||
export const TILE_W = 128;
|
||||
export const TILE_H = 64;
|
||||
export const FRAME_H = 96; // sprite frames carry 32px of headroom above the diamond
|
||||
export const UNIT_FRAME_H = 96; // unit frames get the same 32px headroom as terrain
|
||||
|
||||
const ZOOMS = [0.5, 0.75, 1.0];
|
||||
const ZOOMS = [0.5, 0.75, 1.0, 1.5, 2.0];
|
||||
|
||||
export class CivilizationMapView {
|
||||
constructor(scene, rules, state, callbacks = {}) {
|
||||
|
|
@ -33,6 +34,7 @@ export class CivilizationMapView {
|
|||
this.zoomIdx = 1;
|
||||
this.selectedUnitId = null;
|
||||
this.exploredDrawn = null;
|
||||
this.unitContainers = new Map();
|
||||
|
||||
const { world } = state;
|
||||
this.originX = world.rows * (TILE_W / 2); // keeps iso x positive
|
||||
|
|
@ -140,12 +142,25 @@ export class CivilizationMapView {
|
|||
return best;
|
||||
}
|
||||
|
||||
setZoom(idx) {
|
||||
setZoom(idx, mouseX, mouseY) {
|
||||
const oldScale = this.root.scaleX;
|
||||
this.zoomIdx = Phaser.Math.Clamp(idx, 0, ZOOMS.length - 1);
|
||||
this.root.setScale(ZOOMS[this.zoomIdx]);
|
||||
const newScale = this.root.scaleX;
|
||||
|
||||
// Zoom toward mouse position if provided.
|
||||
if (mouseX != null && mouseY != null) {
|
||||
// Convert screen mouse position to world space using old scale.
|
||||
const worldX = (mouseX - this.root.x) / oldScale;
|
||||
const worldY = (mouseY - this.root.y) / oldScale;
|
||||
// Adjust root position so that world point stays under the mouse.
|
||||
this.root.x += worldX * (oldScale - newScale);
|
||||
this.root.y += worldY * (oldScale - newScale);
|
||||
}
|
||||
|
||||
this.clampPan();
|
||||
}
|
||||
zoomBy(delta) { this.setZoom(this.zoomIdx + delta); }
|
||||
zoomBy(delta, mouseX, mouseY) { this.setZoom(this.zoomIdx + delta, mouseX, mouseY); }
|
||||
|
||||
panBy(dx, dy) {
|
||||
this.root.x += dx;
|
||||
|
|
@ -439,6 +454,7 @@ export class CivilizationMapView {
|
|||
refresh() {
|
||||
this.updateFog();
|
||||
this.dynamic.removeAll(true);
|
||||
this.unitContainers.clear();
|
||||
const { state, rules } = this;
|
||||
const povIdx = this.humanIdx >= 0 ? this.humanIdx : state.current;
|
||||
const visible = computeVisible(state, povIdx);
|
||||
|
|
@ -517,7 +533,10 @@ export class CivilizationMapView {
|
|||
const label = scene.add.text(0, TILE_H + 10, `${city.size} ${city.name}`, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '15px', color: civ.color,
|
||||
}).setOrigin(0.5);
|
||||
banner.width = label.width + 16;
|
||||
// Direct `.width =` leaves the cached display origin stale (it's only
|
||||
// recomputed by setSize/setOrigin), so the box renders left-anchored
|
||||
// instead of staying centered under the label — use setSize instead.
|
||||
banner.setSize(label.width + 16, 22);
|
||||
container.add([banner, label]);
|
||||
container.setDepth(y + 1);
|
||||
banner.setInteractive({ useHandCursor: true });
|
||||
|
|
@ -537,9 +556,13 @@ export class CivilizationMapView {
|
|||
const y = this.isoY(c, r) + TILE_H / 2;
|
||||
const container = scene.add.container(x, y);
|
||||
|
||||
if (scene.textures.exists('civilization-units')) {
|
||||
// Sprite mode: the 64x96 unit frame carries the same 32px headroom as
|
||||
// terrain, so its bottom 64px (the diamond zone) sits over the tile and
|
||||
// the top 32px rises into the tile behind it, like a tree or peak does.
|
||||
const spriteMode = scene.textures.exists('civilization-units');
|
||||
if (spriteMode) {
|
||||
const ring = scene.add.circle(0, 0, 22, color, 0.5).setStrokeStyle(2, color, 1);
|
||||
const img = scene.add.image(0, -6, 'civilization-units', def.frame);
|
||||
const img = scene.add.image(0, TILE_H / 2 - UNIT_FRAME_H / 2, 'civilization-units', def.frame);
|
||||
container.add([ring, img]);
|
||||
} else {
|
||||
const g = scene.add.graphics();
|
||||
|
|
@ -555,22 +578,27 @@ export class CivilizationMapView {
|
|||
}).setOrigin(0.5);
|
||||
container.add(label);
|
||||
}
|
||||
// Badges ride at shoulder height: low against the flat procedural
|
||||
// roundel, higher up against the taller sprite frame.
|
||||
const badgeY = spriteMode ? -28 : -14;
|
||||
if (unit.vet) {
|
||||
container.add(scene.add.circle(12, -14, 4, 0xd4a017).setStrokeStyle(1, 0x000000, 0.6));
|
||||
container.add(scene.add.circle(12, badgeY, 4, 0xd4a017).setStrokeStyle(1, 0x000000, 0.6));
|
||||
}
|
||||
if (stackCount > 1) {
|
||||
const badge = scene.add.circle(-16, -14, 8, 0x000000, 0.8);
|
||||
const num = scene.add.text(-16, -14, `${stackCount}`, {
|
||||
const badge = scene.add.circle(-16, badgeY, 8, 0x000000, 0.8);
|
||||
const num = scene.add.text(-16, badgeY, `${stackCount}`, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '11px', color: '#ffffff',
|
||||
}).setOrigin(0.5);
|
||||
container.add([badge, num]);
|
||||
}
|
||||
container.setDepth(y + 2);
|
||||
this.dynamic.add(container);
|
||||
this.unitContainers.set(unit.id, container);
|
||||
if (unit.id === this.selectedUnitId) this.selectedContainer = container;
|
||||
}
|
||||
|
||||
drawSelection() {
|
||||
this.selectionRing = null;
|
||||
if (!this.selectedUnitId) return;
|
||||
const unit = this.state.units.find((u) => u.id === this.selectedUnitId);
|
||||
if (!unit) { this.selectedUnitId = null; return; }
|
||||
|
|
@ -579,11 +607,241 @@ export class CivilizationMapView {
|
|||
const ring = this.scene.add.circle(x, y - 2, 24).setStrokeStyle(3, 0xffffff, 1);
|
||||
ring.setDepth(y + 3);
|
||||
this.dynamic.add(ring);
|
||||
this.selectionRing = ring;
|
||||
this.scene.tweens.add({
|
||||
targets: ring, alpha: 0.25, duration: 420, yoyo: true, repeat: -1,
|
||||
});
|
||||
}
|
||||
|
||||
// Glides the currently-selected unit's marker (and its selection ring)
|
||||
// through `tiles` ([[c,r], ...]) — state is already at the final tile by
|
||||
// the time this runs, so we snap the marker back to the first point and
|
||||
// tween forward, splitting `duration` evenly across the hops. Pauses
|
||||
// `pauseMs` on arrival before calling `onComplete`.
|
||||
animateUnitAlong(tiles, duration, pauseMs, onComplete) {
|
||||
const container = this.selectedContainer;
|
||||
const points = tiles.map(([c, r]) => ({
|
||||
x: this.isoX(c, r), y: this.isoY(c, r) + TILE_H / 2,
|
||||
}));
|
||||
if (!container || points.length < 2) { onComplete?.(); return; }
|
||||
const ring = this.selectionRing;
|
||||
const place = (p) => {
|
||||
container.setPosition(p.x, p.y);
|
||||
container.setDepth(p.y + 2);
|
||||
if (ring) { ring.setPosition(p.x, p.y - 2); ring.setDepth(p.y + 3); }
|
||||
};
|
||||
place(points[0]);
|
||||
const segDuration = duration / (points.length - 1);
|
||||
let idx = 0;
|
||||
const nextSeg = () => {
|
||||
idx += 1;
|
||||
const target = points[idx];
|
||||
this.scene.tweens.add({
|
||||
targets: container,
|
||||
x: target.x,
|
||||
y: target.y,
|
||||
duration: segDuration,
|
||||
ease: 'Sine.easeInOut',
|
||||
onUpdate: () => place({ x: container.x, y: container.y }),
|
||||
onComplete: () => {
|
||||
if (idx < points.length - 1) nextSeg();
|
||||
else this.scene.time.delayedCall(pauseMs, () => onComplete?.());
|
||||
},
|
||||
});
|
||||
};
|
||||
nextSeg();
|
||||
}
|
||||
|
||||
// Glides any number of already-drawn units' markers from their turn-start
|
||||
// tile to their turn-end tile simultaneously — used for AI civs, whose
|
||||
// moves are only known as a before/after snapshot (no waypoint list like
|
||||
// the human's click-to-move path), so each glide is a straight line.
|
||||
// `moves` is [{ unitId, from: [c,r], to: [c,r] }, ...]. Units with no
|
||||
// on-screen marker (not currently visible, stacked under another unit,
|
||||
// etc.) are silently skipped. Fires `onComplete` once, after `pauseMs`.
|
||||
animateUnitsAlong(moves, duration, pauseMs, onComplete) {
|
||||
const live = moves.filter((m) => this.unitContainers.has(m.unitId));
|
||||
if (!live.length) { onComplete?.(); return; }
|
||||
for (const { unitId, from, to } of live) {
|
||||
const container = this.unitContainers.get(unitId);
|
||||
const start = { x: this.isoX(from[0], from[1]), y: this.isoY(from[0], from[1]) + TILE_H / 2 };
|
||||
const end = { x: this.isoX(to[0], to[1]), y: this.isoY(to[0], to[1]) + TILE_H / 2 };
|
||||
container.setPosition(start.x, start.y);
|
||||
container.setDepth(start.y + 2);
|
||||
this.scene.tweens.add({
|
||||
targets: container,
|
||||
x: end.x,
|
||||
y: end.y,
|
||||
duration,
|
||||
ease: 'Sine.easeInOut',
|
||||
onUpdate: () => container.setDepth(container.y + 2),
|
||||
});
|
||||
}
|
||||
this.scene.time.delayedCall(duration + pauseMs, () => onComplete?.());
|
||||
}
|
||||
|
||||
isTileVisible(c, r) {
|
||||
const povIdx = this.humanIdx >= 0 ? this.humanIdx : this.state.current;
|
||||
return computeVisible(this.state, povIdx).has(tileIndex(this.state.world, c, r));
|
||||
}
|
||||
|
||||
// Standalone unit visual for combat animation. Not tracked in
|
||||
// unitContainers and not tied to live state — combat has already resolved
|
||||
// by the time this plays (the loser may already be gone, the winner may
|
||||
// already have moved), so ghosts are built fresh from the event's
|
||||
// civ/type/tile snapshot and discarded when the sequence finishes.
|
||||
buildCombatGhost(civIdx, unitType, c, r) {
|
||||
const { scene, rules } = this;
|
||||
const def = rules.units[unitType];
|
||||
const civ = this.state.civs[civIdx];
|
||||
const color = Phaser.Display.Color.HexStringToColor(civ.color).color;
|
||||
const x = this.isoX(c, r);
|
||||
const y = this.isoY(c, r) + TILE_H / 2;
|
||||
const container = scene.add.container(x, y);
|
||||
const spriteMode = scene.textures.exists('civilization-units');
|
||||
let img = null;
|
||||
let roundel = null;
|
||||
if (spriteMode) {
|
||||
const ring = scene.add.circle(0, 0, 22, color, 0.5).setStrokeStyle(2, color, 1);
|
||||
img = scene.add.image(0, TILE_H / 2 - UNIT_FRAME_H / 2, 'civilization-units', def.frame);
|
||||
container.add([ring, img]);
|
||||
} else {
|
||||
roundel = scene.add.graphics();
|
||||
roundel.fillStyle(0x000000, 0.35);
|
||||
roundel.fillEllipse(0, 12, 40, 14);
|
||||
roundel.fillStyle(color, 1);
|
||||
roundel.fillCircle(0, -2, 17);
|
||||
roundel.lineStyle(2, 0xffffff, 0.5);
|
||||
roundel.strokeCircle(0, -2, 17);
|
||||
container.add(roundel);
|
||||
const label = scene.add.text(0, -2, def.abbr, {
|
||||
fontFamily: '"Julius Sans One"', fontSize: '14px', color: '#ffffff', fontStyle: 'bold',
|
||||
}).setOrigin(0.5);
|
||||
container.add(label);
|
||||
}
|
||||
container.setDepth(y + 2);
|
||||
this.dynamic.add(container);
|
||||
return { container, img, roundel, color };
|
||||
}
|
||||
|
||||
// Tints the loser bright red (setTint on sprite art; a manual red redraw
|
||||
// for the procedural-roundel fallback, which has no Tint component),
|
||||
// flashes it a few times, then shrinks it away and destroys it.
|
||||
playDeathFlash(ghost, onDone) {
|
||||
const { container, img, roundel, color } = ghost;
|
||||
const setRed = (on) => {
|
||||
if (img) { if (on) img.setTint(0xff0000); else img.clearTint(); return; }
|
||||
if (!roundel) return;
|
||||
roundel.clear();
|
||||
roundel.fillStyle(0x000000, 0.35);
|
||||
roundel.fillEllipse(0, 12, 40, 14);
|
||||
roundel.fillStyle(on ? 0xff0000 : color, 1);
|
||||
roundel.fillCircle(0, -2, 17);
|
||||
roundel.lineStyle(2, 0xffffff, 0.5);
|
||||
roundel.strokeCircle(0, -2, 17);
|
||||
};
|
||||
const FLASH_MS = 110;
|
||||
const FLASHES = 3;
|
||||
let n = 0;
|
||||
const flash = () => {
|
||||
setRed(true);
|
||||
this.scene.time.delayedCall(FLASH_MS, () => {
|
||||
setRed(false);
|
||||
n += 1;
|
||||
if (n < FLASHES) { this.scene.time.delayedCall(FLASH_MS, flash); return; }
|
||||
this.scene.tweens.add({
|
||||
targets: container, scale: 0, alpha: 0, duration: 300, ease: 'Cubic.easeIn',
|
||||
onComplete: () => { container.destroy(); onDone?.(); },
|
||||
});
|
||||
});
|
||||
};
|
||||
flash();
|
||||
}
|
||||
|
||||
// Plays a queue of combat events sequentially: attacker lunges onto the
|
||||
// defender's tile and back, the loser tints/flashes/shrinks away, then —
|
||||
// only if the attacker won and the tile ended up empty — the attacker
|
||||
// glides into it, followed by a short pause. `events` come from the
|
||||
// engine's `combat`-type entries in state.events (already fully resolved;
|
||||
// this just replays what happened for the player to see).
|
||||
animateCombat(events, onComplete) {
|
||||
const queue = events.slice();
|
||||
const playNext = () => {
|
||||
const e = queue.shift();
|
||||
if (!e) { onComplete?.(); return; }
|
||||
this.playCombatEvent(e, playNext);
|
||||
};
|
||||
playNext();
|
||||
}
|
||||
|
||||
playCombatEvent(e, onDone) {
|
||||
// Defends against stale-shape combat events — e.g. a save (or a live
|
||||
// session carrying pre-existing state.events) written before this
|
||||
// snapshot shape existed — rather than throwing and wedging the turn.
|
||||
const civOk = (idx) => Number.isInteger(idx) && !!this.state.civs[idx];
|
||||
const typeOk = (t) => !!this.rules.units[t];
|
||||
if (!civOk(e.attackerCiv) || !civOk(e.defenderCiv) || !typeOk(e.attackerType) || !typeOk(e.defenderType)
|
||||
|| !Number.isInteger(e.ax) || !Number.isInteger(e.ay) || !Number.isInteger(e.x) || !Number.isInteger(e.y)) {
|
||||
onDone?.();
|
||||
return;
|
||||
}
|
||||
this.unitContainers.get(e.attackerId)?.setVisible(false);
|
||||
this.unitContainers.get(e.defenderId)?.setVisible(false);
|
||||
|
||||
const attackerGhost = this.buildCombatGhost(e.attackerCiv, e.attackerType, e.ax, e.ay);
|
||||
const defenderGhost = this.buildCombatGhost(e.defenderCiv, e.defenderType, e.x, e.y);
|
||||
|
||||
const home = { x: this.isoX(e.ax, e.ay), y: this.isoY(e.ax, e.ay) + TILE_H / 2 };
|
||||
const target = { x: this.isoX(e.x, e.y), y: this.isoY(e.x, e.y) + TILE_H / 2 };
|
||||
const LUNGE_MS = 250;
|
||||
|
||||
// Lunge onto the defender's tile...
|
||||
this.scene.tweens.add({
|
||||
targets: attackerGhost.container,
|
||||
x: target.x,
|
||||
y: target.y,
|
||||
duration: LUNGE_MS,
|
||||
ease: 'Sine.easeIn',
|
||||
onUpdate: () => attackerGhost.container.setDepth(attackerGhost.container.y + 3),
|
||||
onComplete: () => {
|
||||
// ...then retreat back to where the attack came from.
|
||||
this.scene.tweens.add({
|
||||
targets: attackerGhost.container,
|
||||
x: home.x,
|
||||
y: home.y,
|
||||
duration: LUNGE_MS,
|
||||
ease: 'Sine.easeOut',
|
||||
onUpdate: () => attackerGhost.container.setDepth(attackerGhost.container.y + 2),
|
||||
onComplete: () => this.finishCombatEvent(e, attackerGhost, defenderGhost, home, target, onDone),
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
finishCombatEvent(e, attackerGhost, defenderGhost, home, target, onDone) {
|
||||
const loser = e.attackerWon ? defenderGhost : attackerGhost;
|
||||
const winner = e.attackerWon ? attackerGhost : defenderGhost;
|
||||
this.playDeathFlash(loser, () => {
|
||||
if (e.attackerWon && e.advanced) {
|
||||
this.scene.tweens.add({
|
||||
targets: winner.container,
|
||||
x: target.x,
|
||||
y: target.y,
|
||||
duration: 1000,
|
||||
ease: 'Sine.easeInOut',
|
||||
onUpdate: () => winner.container.setDepth(winner.container.y + 2),
|
||||
onComplete: () => {
|
||||
winner.container.destroy();
|
||||
this.scene.time.delayedCall(250, onDone);
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
winner.container.destroy();
|
||||
this.scene.time.delayedCall(250, onDone);
|
||||
});
|
||||
}
|
||||
|
||||
showPath(path) {
|
||||
this.pathGfx.clear();
|
||||
if (!path || !path.length) return;
|
||||
|
|
|
|||
|
|
@ -136,14 +136,24 @@ vector-drawn (they connect dynamically between tiles), so they are NOT here.
|
|||
## 4. Units sheet — `civilization-units.png`
|
||||
|
||||
Unit art is **neutral** (no civ color baked in): the game draws a player-color
|
||||
ring/roundel underneath your frame. Center the unit in the frame with its feet
|
||||
around y = 52 so it sits on the tile.
|
||||
ring/roundel underneath your frame. Frames use the classic pronounced look —
|
||||
taller than the tile, so the figure stands up off the diamond instead of
|
||||
being squashed flat into it.
|
||||
|
||||
The frame carries the same **32px headroom** convention as the terrain sheet:
|
||||
the bottom 64px is the diamond zone (matches the 128×64 tile footprint,
|
||||
just narrower), the top 32px is headroom the figure's head/torso rises into,
|
||||
overlapping the tile behind it exactly the way a tree or mountain peak does
|
||||
on the terrain sheet. Plant the feet around **y = 84** (within the diamond
|
||||
zone, forward of center toward the tile's front tip) and let the body extend
|
||||
upward from there — most of a standing unit's height should land in the
|
||||
headroom band (y = 0–32), not the diamond zone.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Path** | `public/assets/images/civilization/civilization-units.png` |
|
||||
| **Sheet size** | **512 × 448 px** |
|
||||
| **Frame size** | **64 × 64 px** |
|
||||
| **Sheet size** | **512 × 672 px** |
|
||||
| **Frame size** | **64 × 96 px** |
|
||||
| **Layout** | 8 columns × 7 rows = 56 frames (51 used, 52–55 reserved) |
|
||||
| **Status** | ❌ not created — roundel + 2-letter label renders meanwhile |
|
||||
| **JSON** | `unitSheet` |
|
||||
|
|
@ -269,7 +279,7 @@ city. The menu shows a generic fallback until painted.
|
|||
|---|---|---|---|
|
||||
| 1 | `civilization-terrain.png` | 768×192 | **High** — biggest visual upgrade |
|
||||
| 2 | `civilization-cities-classic.png` | 512×192 | **High** |
|
||||
| 3 | `civilization-units.png` | 512×448 | **High** (51 frames — biggest lift) |
|
||||
| 3 | `civilization-units.png` | 512×672 | **High** (51 frames — biggest lift) |
|
||||
| 4 | `civilization-resources.png` | 320×256 | Medium |
|
||||
| 5 | `civilization-improvements.png` | 384×64 | Medium |
|
||||
| 6 | `civilization-icons.png` | 480×96 | Low |
|
||||
|
|
|
|||
|
|
@ -336,6 +336,33 @@ if (RULES) {
|
|||
check('granary keeps half box', city.foodBox >= Math.floor(((sizeBefore + 1) * Logic.FOODBOX_PER_SIZE) / 2));
|
||||
}
|
||||
|
||||
// Settler-hold: a size-1 city building a settler must not bank shields
|
||||
// past cost turn after turn while it waits for the city to spare a
|
||||
// citizen (used to show e.g. "60/40 shields (-5 turns)").
|
||||
{
|
||||
const st = makeFlatState({ terrain: 'plains' });
|
||||
const city = Logic.foundCity(RULES, st, Logic.spawnUnit(RULES, st, 0, 'settlers', 5, 5, null));
|
||||
city.build = { type: 'unit', id: 'settlers' };
|
||||
const cost = Logic.buildCost(RULES, city);
|
||||
city.size = 1;
|
||||
city.shieldBox = cost + 20; // as if it had banked well past cost over many stalled turns
|
||||
city.foodBox = 0;
|
||||
Logic.beginCivTurn(RULES, st, 0);
|
||||
check('shieldBox re-capped at cost on a stalled turn', city.shieldBox <= cost,
|
||||
`${city.shieldBox}/${cost}`);
|
||||
|
||||
// Once the city can spare a citizen, the stalled build completes
|
||||
// immediately. foodBox=2 keeps this turn's -1 deficit (size-2 plains
|
||||
// under despotism) from also triggering a famine shrink, which would
|
||||
// confound the size assertion below.
|
||||
const unitsBefore = st.units.length;
|
||||
city.size = 2;
|
||||
city.foodBox = 2;
|
||||
Logic.beginCivTurn(RULES, st, 0);
|
||||
check('stalled settler completes once city can spare population',
|
||||
st.units.length === unitsBefore + 1 && city.size === 1 && city.shieldBox === 0);
|
||||
}
|
||||
|
||||
// Despotism penalty & government trade bonus on tile yields.
|
||||
{
|
||||
const st = makeFlatState({ terrain: 'plains' });
|
||||
|
|
@ -601,6 +628,12 @@ if (RULES) {
|
|||
{
|
||||
const st = makeFlatState();
|
||||
setWar(st, 0, 1);
|
||||
// Cityless civs with no settler are auto-eliminated by checkVictory (run
|
||||
// at the end of resolveAttack) — give each side a settler elsewhere so
|
||||
// wiping out the other's stack doesn't also eliminate the attacker's own
|
||||
// civ (and remove the tank) as a side effect of this fixture.
|
||||
Logic.spawnUnit(RULES, st, 0, 'settlers', 0, 0, null);
|
||||
Logic.spawnUnit(RULES, st, 1, 'settlers', 15, 15, null);
|
||||
Logic.spawnUnit(RULES, st, 1, 'warriors', 5, 5, null);
|
||||
Logic.spawnUnit(RULES, st, 1, 'warriors', 5, 5, null);
|
||||
Logic.spawnUnit(RULES, st, 1, 'warriors', 5, 5, null);
|
||||
|
|
@ -612,7 +645,19 @@ if (RULES) {
|
|||
out = Logic.resolveAttack(RULES, st, tank, 5, 5);
|
||||
if (out.won) break;
|
||||
}
|
||||
check('stack dies on open ground', out.won === true && Logic.unitsAt(st, 5, 5).length === 0);
|
||||
// Winner advances onto an open-ground tile it just cleared entirely
|
||||
// (matches the victory-glide the UI plays for an unopposed win).
|
||||
check('stack dies on open ground', out.won === true);
|
||||
check('attacker advances onto the now-empty tile',
|
||||
tank.x === 5 && tank.y === 5 && Logic.unitsAt(st, 5, 5).length === 1
|
||||
&& Logic.unitsAt(st, 5, 5)[0].id === tank.id);
|
||||
|
||||
const combatEvt = st.events.filter((e) => e.type === 'combat').pop();
|
||||
check('combat event carries attacker/defender snapshot for the UI',
|
||||
!!combatEvt && combatEvt.ax === 4 && combatEvt.ay === 5 && combatEvt.x === 5 && combatEvt.y === 5
|
||||
&& combatEvt.attackerId === tank.id && combatEvt.attackerCiv === 0 && combatEvt.attackerType === 'armor'
|
||||
&& combatEvt.defenderCiv === 1 && combatEvt.defenderType === 'warriors'
|
||||
&& combatEvt.attackerWon === true && combatEvt.advanced === true);
|
||||
|
||||
const st2 = makeFlatState();
|
||||
setWar(st2, 0, 1);
|
||||
|
|
@ -629,6 +674,12 @@ if (RULES) {
|
|||
}
|
||||
check('city stack loses only defender', won2 && Logic.unitsAt(st2, 5, 5).length === 1,
|
||||
`${Logic.unitsAt(st2, 5, 5).length} left, city ${!!city}`);
|
||||
// A win against a protected (city) stack that still has defenders left
|
||||
// does NOT advance the attacker onto the tile.
|
||||
check('attacker does not advance into a still-defended city',
|
||||
!(tank2.x === 5 && tank2.y === 5));
|
||||
const combatEvt2 = st2.events.filter((e) => e.type === 'combat').pop();
|
||||
check('non-advancing combat event says so', !!combatEvt2 && combatEvt2.advanced === false);
|
||||
}
|
||||
|
||||
// City capture: pop loss, loot, palace relocation, elimination.
|
||||
|
|
|
|||
Loading…
Reference in New Issue