Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,18 @@ from the tick it became owed (or from the storage hint's last offer); a caption
without being shown frees that cooldown, so a trigger that still holds owes it again on
the next tick (the dwell clock runs on; only a tick that breaks the trigger restarts
it).
Two rules keep it from nagging (#435). It stays quiet during an attack: from the moment
the army warning fires for a wave until that invasion ends and the warning re-arms (the
army warning's own disarmed state) it is never owed, and one owed but not yet shown is
dropped like a stale one; the dwell clock runs on, so a trigger that still holds
afterwards owes it again. And it backs off when ignored: each time it is shown again
with no new Food Storage designated since the last show, the next cooldown doubles (the
waits after successive ignored shows are 60 s, 120 s, 240 s, then 480 s, the cap); a new Food Storage designation
(designated plus completed count goes up since the show) resets it to 60 s, and a
caption dropped unshown does not advance it. Both are judged on every sim tick, but the
army warning's armed state is advanced once per frame, so a wave's start or end can
shift the owe tick by up to one frame (the frame step drops anything owed on a stale
read, so it never shows during a wave). The back-off state resets with the session.
_Avoid_: "storage hint" (the #395/#413 caption about a queen held back by storage).

**Difficulty**:
Expand Down
8 changes: 8 additions & 0 deletions src/render/army-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ export function createArmyWarningState(): ArmyWarningState {
};
}

/** #435 — a wave is under way: the warning has fired for it (march, gathering or
* invasion) and has not re-armed, which it does once the army has dispersed and any
* invasion has ended, after ARMY_REARM_QUIET_TICKS of quiet. The stores-filling caption
* stays quiet meanwhile. Advanced per frame (nextArmyWarning), not per tick. */
export function armyWaveUnderWay(state: ArmyWarningState): boolean {
return !state.armed;
}

/** New round or loaded save: armed, nothing owed. */
export function resetArmyWarningState(state: ArmyWarningState): void {
state.armed = true;
Expand Down
2 changes: 2 additions & 0 deletions src/render/counter-attack-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { createQueenDangerState } from './queen-danger.js';
import { createEnemyQueenWoundState } from './enemy-queen-wound.js';
import { beforeSimTick } from './sim-tick-hook.js';
import { createStoresFillingCaptionState } from './stores-filling-caption.js';
import { createArmyWarningState } from './army-warning.js';
import { createStorageHintState } from './storage-hint.js';
import { createGameLoop, MS_PER_TICK } from '../platform/game-loop.js';
import { GameOutcome } from '../sim/game-over.js';
Expand Down Expand Up @@ -302,6 +303,7 @@ describe('the follow-up is decided per sim tick, however the ticks are batched',
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: s,
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
});
if (s.owedFollowUp && owedSeen === null) owedSeen = s.owedRoutTick;
Expand Down
3 changes: 3 additions & 0 deletions src/render/enemy-queen-wound.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from './enemy-queen-wound.js';
import { beforeSimTick } from './sim-tick-hook.js';
import { createStoresFillingCaptionState } from './stores-filling-caption.js';
import { createArmyWarningState } from './army-warning.js';
import { createStorageHintState } from './storage-hint.js';
import { createQueenDangerState } from './queen-danger.js';
import { createCounterAttackCaptionState } from './counter-attack-caption.js';
Expand Down Expand Up @@ -348,6 +349,7 @@ describe('GameScene’s wiring on the real sim: the game loop, beforeSimTick, a
enemyQueenWound: s,
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
}),
onTickOutcome: (o) => {
Expand Down Expand Up @@ -634,6 +636,7 @@ describe('batching invariance: every frame presents what the per-tick model deci
enemyQueenWound: s,
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
})
: (w) => noteEnemyQueenWoundTick(s, w, PLAYER_COLONY_ID),
Expand Down
5 changes: 4 additions & 1 deletion src/render/game-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2295,13 +2295,15 @@ export class GameScene extends Phaser.Scene {
// world, so a Food Storage the player has ordered, still queued, drops it. It is not
// owed within its cooldown of the storage hint's last offer (the same advice); the
// hint, which says why when storage then holds the queen back, is not held back by
// it.
// it. #435: quiet while an army warning's wave is under way, and its cooldown doubles
// each time it is shown again with no Food Storage built since the last show.
if (uiScene) {
noteStoresFillingTick(
this.storesFilling,
this.world,
PLAYER_COLONY_ID,
this.storageHint.lastOfferedTick,
this.armyWarning,
);
offerStoresFillingCaption(
this.storesFilling,
Expand Down Expand Up @@ -2594,6 +2596,7 @@ export class GameScene extends Phaser.Scene {
enemyQueenWound: this.enemyQueenWound,
counterAttack: this.counterAttackCaption,
storesFilling: this.storesFilling,
armyWarning: this.armyWarning,
storageHint: this.storageHint,
}),
onAfterDrain: (cmds) => {
Expand Down
3 changes: 3 additions & 0 deletions src/render/queen-danger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from './queen-danger.js';
import { beforeSimTick } from './sim-tick-hook.js';
import { createStoresFillingCaptionState } from './stores-filling-caption.js';
import { createArmyWarningState } from './army-warning.js';
import { createStorageHintState } from './storage-hint.js';
import { createCounterAttackCaptionState } from './counter-attack-caption.js';
import { createEnemyQueenWoundState } from './enemy-queen-wound.js';
Expand Down Expand Up @@ -568,6 +569,7 @@ describe('#416 review: harm inside a frame or a tick (seen before every sim tick
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
}),
},
Expand Down Expand Up @@ -988,6 +990,7 @@ describe('#416 review: the outcome of every tick is the same however the ticks a
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
})
: (w) => noteQueenDangerTick(s, w, PLAYER_COLONY_ID),
Expand Down
10 changes: 8 additions & 2 deletions src/render/sim-tick-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../sim/constants.js';
import { beforeSimTick } from './sim-tick-hook.js';
import { createStoresFillingCaptionState } from './stores-filling-caption.js';
import { createArmyWarningState } from './army-warning.js';
import { createStorageHintState } from './storage-hint.js';
import { createQueenDangerState } from './queen-danger.js';
import { createCounterAttackCaptionState } from './counter-attack-caption.js';
Expand Down Expand Up @@ -153,6 +154,7 @@ describe('beforeSimTick — the rampage threat is checked every tick (#397)', ()
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
}),
});
Expand All @@ -179,6 +181,7 @@ describe('beforeSimTick — the rampage threat is checked every tick (#397)', ()
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
}),
});
Expand Down Expand Up @@ -210,6 +213,7 @@ describe('beforeSimTick — the rampage threat is checked every tick (#397)', ()
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
}),
});
Expand All @@ -228,6 +232,7 @@ describe('beforeSimTick — the rampage threat is checked every tick (#397)', ()
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
});
// The enemy AI's opening commands are queued for this tick's drain...
Expand Down Expand Up @@ -257,6 +262,7 @@ describe('beforeSimTick — the rampage threat is checked every tick (#397)', ()
enemyQueenWound: createEnemyQueenWoundState(),
counterAttack: createCounterAttackCaptionState(),
storesFilling: createStoresFillingCaptionState(),
armyWarning: createArmyWarningState(),
storageHint: createStorageHintState(),
}),
});
Expand Down Expand Up @@ -309,7 +315,7 @@ describe('beforeSimTick — the rampage threat is checked every tick (#397)', ()
const here = dirname(fileURLToPath(import.meta.url));
const src = readFileSync(join(here, 'game-scene.ts'), 'utf8');
expect(src).toMatch(
/onBeforeTick:\s*\(w\)\s*=>\s*beforeSimTick\(\s*w,\s*this\.aiColonyIds,\s*PLAYER_COLONY_ID,\s*this\.prevState,\s*\{\s*rampage:\s*this\.rampageCaption,\s*queenDanger:\s*this\.queenDanger,\s*enemyQueenWound:\s*this\.enemyQueenWound,\s*counterAttack:\s*this\.counterAttackCaption,\s*storesFilling:\s*this\.storesFilling,\s*storageHint:\s*this\.storageHint,?\s*\},?\s*\)/,
/onBeforeTick:\s*\(w\)\s*=>\s*beforeSimTick\(\s*w,\s*this\.aiColonyIds,\s*PLAYER_COLONY_ID,\s*this\.prevState,\s*\{\s*rampage:\s*this\.rampageCaption,\s*queenDanger:\s*this\.queenDanger,\s*enemyQueenWound:\s*this\.enemyQueenWound,\s*counterAttack:\s*this\.counterAttackCaption,\s*storesFilling:\s*this\.storesFilling,\s*armyWarning:\s*this\.armyWarning,\s*storageHint:\s*this\.storageHint,?\s*\},?\s*\)/,
);
// ...and the per-frame check passes the same snapshot, for the frame's last tick.
expect(src).toMatch(
Expand All @@ -321,7 +327,7 @@ describe('beforeSimTick — the rampage threat is checked every tick (#397)', ()
);
// ...and at the stores for the stores-filling caption, with the storage hint's clock.
expect(src).toMatch(
/noteStoresFillingTick\(\s*this\.storesFilling,\s*this\.world,\s*PLAYER_COLONY_ID,\s*this\.storageHint\.lastOfferedTick,?\s*\)/,
/noteStoresFillingTick\(\s*this\.storesFilling,\s*this\.world,\s*PLAYER_COLONY_ID,\s*this\.storageHint\.lastOfferedTick,\s*this\.armyWarning,?\s*\)/,
);
});
});
8 changes: 7 additions & 1 deletion src/render/sim-tick-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { noteRampageThreat, type RampageCaptionState } from './recurring-caption
import { noteQueenDangerTick, type QueenDangerState } from './queen-danger.js';
import { noteEnemyQueenWoundTick, type EnemyQueenWoundState } from './enemy-queen-wound.js';
import { noteCounterAttackTick, type CounterAttackCaptionState } from './counter-attack-caption.js';
import type { ArmyWarningState } from './army-warning.js';
import { noteStoresFillingTick, type StoresFillingCaptionState } from './stores-filling-caption.js';
import type { StorageHintState } from './storage-hint.js';

Expand All @@ -30,6 +31,9 @@ export interface BeforeTickCaptions {
readonly enemyQueenWound: EnemyQueenWoundState;
readonly counterAttack: CounterAttackCaptionState;
readonly storesFilling: StoresFillingCaptionState;
/** Read for whether an army warning's wave is under way (#435), when the
* stores-filling caption stays quiet. */
readonly armyWarning: ArmyWarningState;
/** Read for the storage hint's last offer, which the stores-filling caption follows. */
readonly storageHint: StorageHintState;
}
Expand Down Expand Up @@ -57,7 +61,8 @@ export interface BeforeTickCaptions {
* 6. (economy captions) the stores-filling caption's look at the viewer's colony
* (noteStoresFillingTick), so its dwell and cooldown run on world ticks; with the
* storage hint's last offer (`captions.storageHint`), which it does not follow
* within its cooldown;
* within its cooldown, and the army warning (`captions.armyWarning`), during whose
* wave it stays quiet (#435);
* 7. the prevState snapshot for render interpolation.
*/
export function beforeSimTick(
Expand All @@ -77,6 +82,7 @@ export function beforeSimTick(
world,
viewerColonyId,
captions.storageHint.lastOfferedTick,
captions.armyWarning,
);
copyWorldState(world, prevState);
}
Loading
Loading