Compare commits
3 Commits
4d864503f2
...
def5c9904a
| Author | SHA1 | Date |
|---|---|---|
|
|
def5c9904a | |
|
|
80d4a79593 | |
|
|
543f751fe2 |
Binary file not shown.
|
After Width: | Height: | Size: 3.6 MiB |
|
|
@ -257,6 +257,26 @@
|
|||
{ "id": "emperor", "name": "Emperor", "humanResearchFactor": 1.2, "aiProdBonus": 1.5, "aiScienceBonus": 1.5, "aiStartUnits": 1, "aiAggression": 0.8 }
|
||||
],
|
||||
|
||||
"civTraits": [
|
||||
{ "id": "scientific", "name": "Scientific", "description": "+30% Science",
|
||||
"scienceMult": 1.3, "goldMult": 1, "shieldMult": 1, "startingGold": 0, "startingTechs": [] },
|
||||
{ "id": "industrious", "name": "Industrious", "description": "+30% Production",
|
||||
"scienceMult": 1, "goldMult": 1, "shieldMult": 1.3, "startingGold": 0, "startingTechs": [] },
|
||||
{ "id": "commercial", "name": "Commercial", "description": "+30% Gold",
|
||||
"scienceMult": 1, "goldMult": 1.3, "shieldMult": 1, "startingGold": 0, "startingTechs": [] },
|
||||
{ "id": "philosophical", "name": "Philosophical", "description": "+50% Science, -20% Production",
|
||||
"scienceMult": 1.5, "goldMult": 1, "shieldMult": 0.8, "startingGold": 0, "startingTechs": [] },
|
||||
{ "id": "zealous", "name": "Zealous", "description": "+50% Production, -20% Gold",
|
||||
"scienceMult": 1, "goldMult": 0.8, "shieldMult": 1.5, "startingGold": 0, "startingTechs": [] },
|
||||
{ "id": "mercantile", "name": "Mercantile", "description": "+50% Gold, -20% Science",
|
||||
"scienceMult": 0.8, "goldMult": 1.5, "shieldMult": 1, "startingGold": 0, "startingTechs": [] },
|
||||
{ "id": "pioneering", "name": "Pioneering", "description": "Starts knowing Alphabet and Bronze Working",
|
||||
"scienceMult": 1, "goldMult": 1, "shieldMult": 1, "startingGold": 0,
|
||||
"startingTechs": ["alphabet", "bronzeworking"] },
|
||||
{ "id": "wealthy", "name": "Wealthy", "description": "+100 starting Gold",
|
||||
"scienceMult": 1, "goldMult": 1, "shieldMult": 1, "startingGold": 100, "startingTechs": [] }
|
||||
],
|
||||
|
||||
"worldSizes": [
|
||||
{ "id": "small", "name": "Small", "cols": 40, "rows": 32, "startSettlers": 1 },
|
||||
{ "id": "medium", "name": "Medium", "cols": 56, "rows": 44, "startSettlers": 2 },
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@
|
|||
"id": "cybro",
|
||||
"spriteIndex": 0,
|
||||
"name": "Cy-Bro",
|
||||
"trait": "scientific",
|
||||
"startingTechs": [
|
||||
"alphabet",
|
||||
"pottery"
|
||||
],
|
||||
"bio": "AI Bro sent from the future to show the superiority of the future.",
|
||||
"voice": "Legion",
|
||||
"convo": [
|
||||
|
|
@ -39,6 +44,12 @@
|
|||
"id": "brad",
|
||||
"spriteIndex": 1,
|
||||
"name": "Brad",
|
||||
"trait": "wealthy",
|
||||
"startingTechs": [
|
||||
"horsebackriding",
|
||||
"bronzeworking",
|
||||
"thewheel"
|
||||
],
|
||||
"bio": "Came for the honey, stayed for the salmon!",
|
||||
"voice": "Jewel Weaver - Bear",
|
||||
"convo": [
|
||||
|
|
@ -74,6 +85,8 @@
|
|||
"id": "victor",
|
||||
"spriteIndex": 2,
|
||||
"name": "Victor",
|
||||
"trait": "pioneering",
|
||||
"startingTechs": [],
|
||||
"bio": "Patient and calculating. Moves are made using ancient technology.",
|
||||
"voice": "Starfield - Vasco",
|
||||
"convo": [
|
||||
|
|
@ -109,6 +122,11 @@
|
|||
"id": "croc",
|
||||
"spriteIndex": 3,
|
||||
"name": "Croc",
|
||||
"trait": "commercial",
|
||||
"startingTechs": [
|
||||
"bronzeworking",
|
||||
"masonry"
|
||||
],
|
||||
"bio": "Wassssuppp everybody! I'm here for the party!!",
|
||||
"voice": "Batman - Killer Croc",
|
||||
"convo": [
|
||||
|
|
@ -144,6 +162,12 @@
|
|||
"id": "mario",
|
||||
"spriteIndex": 4,
|
||||
"name": "Mario",
|
||||
"trait": "philosophical",
|
||||
"startingTechs": [
|
||||
"alphabet",
|
||||
"warriorcode",
|
||||
"thewheel"
|
||||
],
|
||||
"bio": "Can you find your way out of my maze of puzzles, games and fun!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -166,6 +190,11 @@
|
|||
"id": "ethel",
|
||||
"spriteIndex": 5,
|
||||
"name": "Ethel",
|
||||
"trait": "wealthy",
|
||||
"startingTechs": [
|
||||
"horsebackriding",
|
||||
"masonry"
|
||||
],
|
||||
"bio": "Thank you for visiting with me.",
|
||||
"voice": "Betty White",
|
||||
"convo": [
|
||||
|
|
@ -201,6 +230,11 @@
|
|||
"id": "jeff",
|
||||
"spriteIndex": 6,
|
||||
"name": "Jeff",
|
||||
"trait": "philosophical",
|
||||
"startingTechs": [
|
||||
"horsebackriding",
|
||||
"pottery"
|
||||
],
|
||||
"bio": "I play slow, I win fast!",
|
||||
"voice": "SlowAltered",
|
||||
"convo": [
|
||||
|
|
@ -236,6 +270,12 @@
|
|||
"id": "gerome",
|
||||
"spriteIndex": 7,
|
||||
"name": "Gerome",
|
||||
"trait": "zealous",
|
||||
"startingTechs": [
|
||||
"horsebackriding",
|
||||
"warriorcode",
|
||||
"masonry"
|
||||
],
|
||||
"bio": "I'm here for the thrill of extreme victory!",
|
||||
"voice": "Mass Effect - Commander Shepard",
|
||||
"convo": [
|
||||
|
|
@ -271,6 +311,12 @@
|
|||
"id": "fireball",
|
||||
"spriteIndex": 8,
|
||||
"name": "Fireball",
|
||||
"trait": "industrious",
|
||||
"startingTechs": [
|
||||
"alphabet",
|
||||
"thewheel",
|
||||
"bronzeworking"
|
||||
],
|
||||
"bio": "Come on let's play! I promise not to use my x-ray eyes.",
|
||||
"voice": "Zero - Borderlands 3",
|
||||
"convo": [
|
||||
|
|
@ -306,6 +352,12 @@
|
|||
"id": "bernie",
|
||||
"spriteIndex": 9,
|
||||
"name": "Bernie",
|
||||
"trait": "mercantile",
|
||||
"startingTechs": [
|
||||
"pottery",
|
||||
"ceremonialburial",
|
||||
"bronzeworking"
|
||||
],
|
||||
"bio": "Having fun and playing is the name of the game for me!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -328,6 +380,11 @@
|
|||
"id": "jerry",
|
||||
"spriteIndex": 10,
|
||||
"name": "Jerry",
|
||||
"trait": "commercial",
|
||||
"startingTechs": [
|
||||
"pottery",
|
||||
"alphabet"
|
||||
],
|
||||
"bio": "Well now yall know I want to play some them games!",
|
||||
"voice": "Life is Strange - Jed Lucan",
|
||||
"convo": [
|
||||
|
|
@ -363,6 +420,8 @@
|
|||
"id": "natasha",
|
||||
"spriteIndex": 11,
|
||||
"name": "Natasha",
|
||||
"trait": "pioneering",
|
||||
"startingTechs": [],
|
||||
"bio": "Perhaps if I win, you will spill the secrets you've been keeping!",
|
||||
"voice": "Street Fighter 6 - Marisa",
|
||||
"convo": [
|
||||
|
|
@ -398,6 +457,11 @@
|
|||
"id": "zanthor",
|
||||
"spriteIndex": 12,
|
||||
"name": "Zanthor",
|
||||
"trait": "philosophical",
|
||||
"startingTechs": [
|
||||
"thewheel",
|
||||
"alphabet"
|
||||
],
|
||||
"bio": "Hocus Pocus Alacazam!!!!",
|
||||
"convo": [
|
||||
"terry",
|
||||
|
|
@ -432,6 +496,12 @@
|
|||
"id": "kona",
|
||||
"spriteIndex": 14,
|
||||
"name": "Kona",
|
||||
"trait": "industrious",
|
||||
"startingTechs": [
|
||||
"pottery",
|
||||
"masonry",
|
||||
"ceremonialburial"
|
||||
],
|
||||
"bio": "Woof! Woof!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -454,6 +524,11 @@
|
|||
"id": "michael",
|
||||
"spriteIndex": 15,
|
||||
"name": "Michael",
|
||||
"trait": "commercial",
|
||||
"startingTechs": [
|
||||
"warriorcode",
|
||||
"masonry"
|
||||
],
|
||||
"bio": "Hey mon! Yous be knowin' I been wantin' ta play on da Fertig Games for a while now mon!",
|
||||
"voice": "Djed Spence",
|
||||
"convo": [
|
||||
|
|
@ -488,6 +563,11 @@
|
|||
"id": "juliet",
|
||||
"spriteIndex": 13,
|
||||
"name": "Juliet",
|
||||
"trait": "wealthy",
|
||||
"startingTechs": [
|
||||
"thewheel",
|
||||
"alphabet"
|
||||
],
|
||||
"bio": "Let's take a break on a warm summer day to spend time playing games!",
|
||||
"voice": "Street Fighter 6 - Crimson Viper",
|
||||
"speech": {
|
||||
|
|
@ -518,6 +598,8 @@
|
|||
"id": "balam",
|
||||
"spriteIndex": 16,
|
||||
"name": "Balam",
|
||||
"trait": "pioneering",
|
||||
"startingTechs": [],
|
||||
"bio": "Mystical Powers and a knack for games.",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -547,6 +629,12 @@
|
|||
"id": "steve",
|
||||
"spriteIndex": 17,
|
||||
"name": "Steve",
|
||||
"trait": "scientific",
|
||||
"startingTechs": [
|
||||
"pottery",
|
||||
"masonry",
|
||||
"bronzeworking"
|
||||
],
|
||||
"bio": "I traveled WAY to far for this stupid Earth Internet.",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -576,6 +664,11 @@
|
|||
"id": "beth",
|
||||
"spriteIndex": 18,
|
||||
"name": "Beth",
|
||||
"trait": "industrious",
|
||||
"startingTechs": [
|
||||
"alphabet",
|
||||
"pottery"
|
||||
],
|
||||
"bio": "I ain't seen you 'round these parts before.",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -605,6 +698,11 @@
|
|||
"id": "blackwind",
|
||||
"spriteIndex": 19,
|
||||
"name": "Blackwind",
|
||||
"trait": "mercantile",
|
||||
"startingTechs": [
|
||||
"masonry",
|
||||
"alphabet"
|
||||
],
|
||||
"bio": "Aaaaaaargh! Me be playin' these games matey!",
|
||||
"voice": "pirate",
|
||||
"speech": {
|
||||
|
|
@ -635,6 +733,11 @@
|
|||
"id": "nadia",
|
||||
"spriteIndex": 20,
|
||||
"name": "Nadia",
|
||||
"trait": "scientific",
|
||||
"startingTechs": [
|
||||
"bronzeworking",
|
||||
"horsebackriding"
|
||||
],
|
||||
"bio": "She's here from the future to learn our games and study our culture.",
|
||||
"voice": "Invincible VS - Atom Eve",
|
||||
"speech": {
|
||||
|
|
@ -665,6 +768,12 @@
|
|||
"id": "smasher",
|
||||
"spriteIndex": 21,
|
||||
"name": "The Smasher",
|
||||
"trait": "zealous",
|
||||
"startingTechs": [
|
||||
"warriorcode",
|
||||
"pottery",
|
||||
"ceremonialburial"
|
||||
],
|
||||
"bio": "Oooooooh yeah brother!!! You wanna play with The Smasher?!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -694,6 +803,8 @@
|
|||
"id": "dv-8-2303",
|
||||
"spriteIndex": 22,
|
||||
"name": "DV-8-2303",
|
||||
"trait": "pioneering",
|
||||
"startingTechs": [],
|
||||
"bio": "Cybernetic Systems online. Activate human defeat protocol... EOF",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -723,6 +834,11 @@
|
|||
"id": "nicole",
|
||||
"spriteIndex": 23,
|
||||
"name": "Nicole",
|
||||
"trait": "scientific",
|
||||
"startingTechs": [
|
||||
"pottery",
|
||||
"ceremonialburial"
|
||||
],
|
||||
"bio": "I've disabled the firewall protections on this website. Now to hack the core!",
|
||||
"voice": "Life is Strange - Rachael Amber",
|
||||
"speech": {
|
||||
|
|
@ -753,6 +869,11 @@
|
|||
"id": "kage",
|
||||
"spriteIndex": 24,
|
||||
"name": "Kage",
|
||||
"trait": "philosophical",
|
||||
"startingTechs": [
|
||||
"masonry",
|
||||
"pottery"
|
||||
],
|
||||
"bio": "I have traveled far to play these games. Honor me and let us play!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -782,6 +903,11 @@
|
|||
"id": "terry",
|
||||
"spriteIndex": 25,
|
||||
"name": "Terry",
|
||||
"trait": "industrious",
|
||||
"startingTechs": [
|
||||
"ceremonialburial",
|
||||
"masonry"
|
||||
],
|
||||
"bio": "I haven't had this much fun since the Mezasoic era!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -811,6 +937,11 @@
|
|||
"id": "schooner",
|
||||
"spriteIndex": 26,
|
||||
"name": "Schooner",
|
||||
"trait": "commercial",
|
||||
"startingTechs": [
|
||||
"ceremonialburial",
|
||||
"horsebackriding"
|
||||
],
|
||||
"bio": "Ahoy you land lovers!",
|
||||
"voice": "Defiant Calder",
|
||||
"convo": [
|
||||
|
|
@ -846,6 +977,12 @@
|
|||
"id": "maurice",
|
||||
"spriteIndex": 27,
|
||||
"name": "Maurice",
|
||||
"trait": "industrious",
|
||||
"startingTechs": [
|
||||
"masonry",
|
||||
"pottery",
|
||||
"thewheel"
|
||||
],
|
||||
"bio": "Bucky Beaver and I are there to TRAP all the fun and games!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -875,6 +1012,11 @@
|
|||
"id": "aiko",
|
||||
"spriteIndex": 28,
|
||||
"name": "Aiko",
|
||||
"trait": "scientific",
|
||||
"startingTechs": [
|
||||
"pottery",
|
||||
"thewheel"
|
||||
],
|
||||
"bio": "From a different galaxy, but has the same great Earth based lifeforms taste for games!",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -904,6 +1046,11 @@
|
|||
"id": "klaxon",
|
||||
"spriteIndex": 29,
|
||||
"name": "Klaxon",
|
||||
"trait": "zealous",
|
||||
"startingTechs": [
|
||||
"horsebackriding",
|
||||
"thewheel"
|
||||
],
|
||||
"bio": "MISSION OBJECTIVE: Victory.... all other priorities recinded.",
|
||||
"speech": {
|
||||
"intro": [
|
||||
|
|
@ -930,4 +1077,4 @@
|
|||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ export const MANIFEST = {
|
|||
// (classic today; asian etc. drop in later with no code change).
|
||||
civilization: [
|
||||
{ type: 'json', key: 'civilization-rules', path: 'data/civilization-rules.json' },
|
||||
image('civilization-setup-bg', 'assets/images/civilization/background.png'),
|
||||
(scene) => sheetsFrom(scene, 'civilization-artwork',
|
||||
['terrainSheet', 'resourceSheet', 'improvementSheet', 'unitSheet', 'iconSheet', 'citySheets']),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -26,12 +26,29 @@ const D = { hud: 30, modal: 60, toast: 80 };
|
|||
export default class CivilizationGame extends Phaser.Scene {
|
||||
constructor() { super('CivilizationGame'); }
|
||||
|
||||
// Any window opening or closing flips `modalOpen`. Buttons fire their
|
||||
// onClick on 'pointerup', so a click that closes a window (e.g. a modal's
|
||||
// own Close/Cancel button) has already set modalOpen back to false by the
|
||||
// time the scene-wide pointerup handler below runs its own check — without
|
||||
// this guard that same mouse-up would fall through and register as a map
|
||||
// click (moving the selected unit, etc). Flipping modalOpen either way arms
|
||||
// the guard; the next pointerup (almost always the one in progress right
|
||||
// now) consumes it and is swallowed, so the map only responds to a fresh
|
||||
// click made after the mouse button has been released.
|
||||
get modalOpen() { return this._modalOpen; }
|
||||
|
||||
set modalOpen(value) {
|
||||
if (value !== this._modalOpen) this.clickGuard = true;
|
||||
this._modalOpen = value;
|
||||
}
|
||||
|
||||
init(data) {
|
||||
this.gameDef = data.game ?? { slug: 'civilization', name: 'Civilization' };
|
||||
this.state = null;
|
||||
this.view = null;
|
||||
this.phase = 'setup';
|
||||
this.modalOpen = false;
|
||||
this.clickGuard = false;
|
||||
this.busy = false;
|
||||
this.endTurnFlashTween = null;
|
||||
}
|
||||
|
|
@ -83,6 +100,14 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
const root = this.setupRoot;
|
||||
const cx = GAME_WIDTH / 2;
|
||||
|
||||
// Background art is optional (assets/images/civilization/background.png,
|
||||
// registered in src/data/assetManifest.js) — the scene's base dark fill
|
||||
// from create() already covers the fallback if it isn't loaded, so this
|
||||
// is simply skipped when missing rather than needing its own else-branch.
|
||||
if (this.textures.exists('civilization-setup-bg')) {
|
||||
root.add(this.add.image(cx, GAME_HEIGHT / 2, 'civilization-setup-bg'));
|
||||
}
|
||||
|
||||
root.add(this.add.text(cx, 52, 'CIVILIZATION', {
|
||||
fontFamily: 'Righteous', fontSize: '54px', color: COLORS.accentHex,
|
||||
}).setOrigin(0.5));
|
||||
|
|
@ -134,6 +159,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
m.ring.setStrokeStyle(3, j === i ? COLORS.gold : COLORS.muted);
|
||||
m.label.setColor(j === i ? COLORS.goldHex : COLORS.mutedHex);
|
||||
});
|
||||
this.updateLeaderDetailPanel();
|
||||
});
|
||||
this.leaderMarks.push({ ring, label });
|
||||
root.add([ring, face, label]);
|
||||
|
|
@ -143,7 +169,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
let oy = gy + rowsUsed * (cell + 18) + 40;
|
||||
|
||||
// --- option rows
|
||||
this.setupOpts = this.setupOpts ?? { sizeId: 'medium', opponents: 3, difficultyId: 'prince' };
|
||||
this.setupOpts = this.setupOpts ?? { sizeId: 'medium', opponents: 5, difficultyId: 'prince' };
|
||||
const mkRow = (label, options, current, onPick) => {
|
||||
root.add(this.add.text(cx - 560, oy, label, {
|
||||
fontFamily: FONT, fontSize: '22px', color: COLORS.textHex,
|
||||
|
|
@ -194,6 +220,44 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
}, { width: 280, height: 64, fontSize: 26, variant: 'ghost' });
|
||||
root.add(resumeBtn);
|
||||
}
|
||||
|
||||
// --- leader details panel (below BEGIN/RESUME), updated live from the
|
||||
// leader-pick ring handler above — see updateLeaderDetailPanel().
|
||||
const panelY = oy + 20 + 32 + 24;
|
||||
const panelW = 900;
|
||||
const panelH = 150;
|
||||
const panelBg = this.add.rectangle(cx, panelY + panelH / 2, panelW, panelH, COLORS.panel, 0.92)
|
||||
.setStrokeStyle(2, COLORS.accent, 0.7);
|
||||
const nameText = this.add.text(cx, panelY + 26, '', {
|
||||
fontFamily: 'Righteous', fontSize: '26px', color: COLORS.goldHex,
|
||||
}).setOrigin(0.5);
|
||||
const traitText = this.add.text(cx, panelY + 66, '', {
|
||||
fontFamily: FONT, fontSize: '20px', color: COLORS.textHex,
|
||||
}).setOrigin(0.5);
|
||||
const descText = this.add.text(cx, panelY + 100, '', {
|
||||
fontFamily: FONT, fontSize: '18px', color: COLORS.mutedHex,
|
||||
}).setOrigin(0.5);
|
||||
root.add([panelBg, nameText, traitText, descText]);
|
||||
this.leaderDetailPanel = { nameText, traitText, descText };
|
||||
this.updateLeaderDetailPanel();
|
||||
}
|
||||
|
||||
// Reflects the currently-picked leader's starting-condition trait in the
|
||||
// setup-screen details panel. Called once when the panel is first built,
|
||||
// and again from the leader-pick ring's click handler — both share this
|
||||
// one code path so there's no separate "initial" vs "on click" logic.
|
||||
updateLeaderDetailPanel() {
|
||||
if (!this.leaderDetailPanel) return;
|
||||
const op = this.setupLeaders[this.pickedLeader];
|
||||
const trait = this.rules.civTraits[op?.trait];
|
||||
const { nameText, traitText, descText } = this.leaderDetailPanel;
|
||||
nameText.setText(op?.name ?? '');
|
||||
traitText.setText(trait ? trait.name : 'Balanced (no bonuses)');
|
||||
const techNames = (op?.startingTechs ?? []).map((id) => this.rules.techs[id]?.name ?? id);
|
||||
const lines = [];
|
||||
if (trait?.description) lines.push(trait.description);
|
||||
if (techNames.length) lines.push(`Starts knowing ${techNames.join(', ')}`);
|
||||
descText.setText(lines.join(' • '));
|
||||
}
|
||||
|
||||
hasSave() {
|
||||
|
|
@ -211,7 +275,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
[rivals[i], rivals[j]] = [rivals[j], rivals[i]];
|
||||
}
|
||||
const leaders = [me, ...rivals.slice(0, opponents)]
|
||||
.map((op) => ({ id: op.id, name: op.name }));
|
||||
.map((op) => ({ id: op.id, name: op.name, trait: op.trait, startingTechs: op.startingTechs }));
|
||||
const seed = (Date.now() % 1000000) + 1;
|
||||
try {
|
||||
this.state = Logic.createGame(this.rules, {
|
||||
|
|
@ -252,6 +316,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
this.setupRoot = null;
|
||||
this.view = new CivilizationMapView(this, this.rules, this.state, {
|
||||
onCityClick: (city) => this.onCityClick(city),
|
||||
onUnitClick: (unit) => this.onUnitClick(unit),
|
||||
});
|
||||
this.view.buildMinimap(16, GAME_HEIGHT - 260, 300);
|
||||
this.buildHud();
|
||||
|
|
@ -374,6 +439,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
const wasDrag = dragged;
|
||||
dragStart = null;
|
||||
dragged = false;
|
||||
if (this.clickGuard) { this.clickGuard = false; return; }
|
||||
if (wasDrag || this.modalOpen || this.phase !== 'playing' || this.busy) return;
|
||||
if (pointer.y < 56 || pointer.y > GAME_HEIGHT - 44) return; // HUD bands
|
||||
// Clicks that landed on any interactive object (buttons, minimap, city
|
||||
|
|
@ -455,6 +521,15 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
}
|
||||
|
||||
update() {
|
||||
// Phaser Containers render children in list order, not by their .depth —
|
||||
// .setDepth() alone (used throughout CivilizationMapView for units/cities/
|
||||
// combat ghosts/selection ring) has no effect on draw order inside
|
||||
// this.view.dynamic unless the list is explicitly re-sorted. Units and
|
||||
// cities are added in arbitrary (state-array) order each refresh, and
|
||||
// move/combat animations update depth continuously, so this has to run
|
||||
// every frame — including mid-animation, hence it runs before the
|
||||
// busy/modal early-return below.
|
||||
this.view?.dynamic?.sort('depth');
|
||||
if (this.phase !== 'playing' || this.modalOpen || this.busy) return;
|
||||
// Edge-of-keyboard panning.
|
||||
const k = this.keys;
|
||||
|
|
@ -481,7 +556,7 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
else if (just(k.Z)) this.tryStep(sel, -1, 1);
|
||||
else if (just(k.C)) this.tryStep(sel, 1, 1);
|
||||
else if (just(k.SPACE)) { sel.mp = 0; this.selectNextUnit(); }
|
||||
else if (just(k.F)) { sel.fortified = true; sel.mp = 0; this.afterAction(); this.selectNextUnit(); }
|
||||
else if (just(k.F)) this.tryFortify(sel);
|
||||
else if (just(k.B)) this.tryFound(sel);
|
||||
else if (just(k.R)) this.tryWork(sel, this.canRail(sel) ? 'railroad' : 'road');
|
||||
else if (just(k.I)) this.tryWork(sel, 'irrigation');
|
||||
|
|
@ -715,6 +790,112 @@ export default class CivilizationGame extends Phaser.Scene {
|
|||
}
|
||||
}
|
||||
|
||||
tryFortify(unit) {
|
||||
unit.fortified = true;
|
||||
unit.mp = 0;
|
||||
this.afterAction();
|
||||
this.selectNextUnit();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Unit action popup (clicking the currently-selected unit's sprite)
|
||||
|
||||
onUnitClick(unit) {
|
||||
if (this.modalOpen || this.busy || this.state.current !== this.state.humanIndex) return;
|
||||
this.openUnitActionMenu(unit);
|
||||
}
|
||||
|
||||
// Mirrors the same eligibility checks the keyboard shortcuts use (tryFound,
|
||||
// tryWork, tryCaravan, tryFortify) so the menu never offers something that
|
||||
// would just toast a failure.
|
||||
getUnitActions(unit) {
|
||||
const { rules, state } = this;
|
||||
const def = rules.units[unit.type];
|
||||
const actions = [];
|
||||
if (!unit.fortified) actions.push({ label: 'Fortify', onSelect: () => this.tryFortify(unit) });
|
||||
if (def.flags.includes('settler') && Logic.canFoundCity(rules, state, unit.x, unit.y)) {
|
||||
actions.push({ label: 'Found City', onSelect: () => this.tryFound(unit) });
|
||||
}
|
||||
const roadImp = this.canRail(unit) ? 'railroad' : 'road';
|
||||
if (Logic.canWork(rules, state, unit, roadImp)) {
|
||||
const label = roadImp === 'railroad' ? 'Build Railroad' : 'Build Road';
|
||||
actions.push({ label, onSelect: () => this.tryWork(unit, roadImp) });
|
||||
}
|
||||
if (Logic.canWork(rules, state, unit, 'irrigation')) {
|
||||
actions.push({ label: 'Irrigate', onSelect: () => this.tryWork(unit, 'irrigation') });
|
||||
}
|
||||
if (Logic.canWork(rules, state, unit, 'mine')) {
|
||||
actions.push({ label: 'Build Mine', onSelect: () => this.tryWork(unit, 'mine') });
|
||||
}
|
||||
if (Logic.canWork(rules, state, unit, 'fortress')) {
|
||||
actions.push({ label: 'Build Fortress', onSelect: () => this.tryWork(unit, 'fortress') });
|
||||
}
|
||||
if (Logic.canWork(rules, state, unit, 'transform')) {
|
||||
actions.push({ label: 'Transform Terrain', onSelect: () => this.tryWork(unit, 'transform') });
|
||||
}
|
||||
if (Logic.canEstablishRoute(rules, state, unit)) {
|
||||
actions.push({ label: 'Establish Trade Route', onSelect: () => this.tryCaravan(unit) });
|
||||
}
|
||||
actions.push({ label: 'Skip Turn', onSelect: () => { unit.mp = 0; this.selectNextUnit(); } });
|
||||
return actions;
|
||||
}
|
||||
|
||||
openUnitActionMenu(unit) {
|
||||
this.modalOpen = true;
|
||||
const def = this.rules.units[unit.type];
|
||||
const actions = this.getUnitActions(unit);
|
||||
|
||||
const cx = GAME_WIDTH / 2;
|
||||
const cy = GAME_HEIGHT / 2;
|
||||
const itemH = 52;
|
||||
const gap = 10;
|
||||
const pw = 380;
|
||||
const ph = 96 + actions.length * (itemH + gap) + 56;
|
||||
const px = cx - pw / 2;
|
||||
const py = cy - ph / 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, py + ph / 2, pw, ph, COLORS.panel).setStrokeStyle(2, COLORS.accent);
|
||||
const title = this.add.text(cx, py + 34, def.name, {
|
||||
fontFamily: 'Righteous', fontSize: '24px', color: COLORS.accentHex,
|
||||
}).setOrigin(0.5);
|
||||
root.add([dim, panel, title]);
|
||||
|
||||
// This menu opens from a pointerdown on the unit's sprite, so the mouse
|
||||
// button is typically still held when these buttons appear. Selected
|
||||
// units are frequently screen-centered (selectNextUnit centers the view
|
||||
// on them), same as this menu, so the imminent mouse-up can land right
|
||||
// on a button and fire it before the player ever sees the menu. Ignore
|
||||
// clicks until that one release has passed.
|
||||
let armed = !this.input.activePointer.isDown;
|
||||
const arm = () => { armed = true; };
|
||||
if (!armed) this.input.once('pointerup', arm);
|
||||
|
||||
const close = () => {
|
||||
this.input.off('pointerup', arm);
|
||||
root.destroy(true);
|
||||
this.modalOpen = false;
|
||||
};
|
||||
|
||||
actions.forEach((action, i) => {
|
||||
const by = py + 76 + i * (itemH + gap);
|
||||
const btn = new Button(this, cx, by + itemH / 2, action.label, () => {
|
||||
if (!armed) return;
|
||||
close();
|
||||
action.onSelect();
|
||||
}, { width: pw - 48, height: itemH, fontSize: 18 });
|
||||
root.add(btn);
|
||||
});
|
||||
|
||||
const cancelY = py + 76 + actions.length * (itemH + gap) + 8;
|
||||
const cancel = new Button(this, cx, cancelY + 20, 'CANCEL', () => {
|
||||
if (!armed) return;
|
||||
close();
|
||||
}, { width: pw - 48, height: 44, fontSize: 16, variant: 'ghost' });
|
||||
root.add(cancel);
|
||||
}
|
||||
|
||||
afterAction() {
|
||||
// Repaint tiles that may have changed (work orders complete on turn start,
|
||||
// but roads from engineers etc. show up next refresh — cheap full check
|
||||
|
|
|
|||
|
|
@ -88,9 +88,14 @@ export function createGame(rules, opts) {
|
|||
for (let j = 0; j < numCivs; j += 1) {
|
||||
if (j !== i) { relations[j] = 'nocontact'; attitude[j] = 0; }
|
||||
}
|
||||
state.civs.push({
|
||||
// Leader starting-condition trait (see data/civilization-rules.json
|
||||
// civTraits) — trait id may be missing/unknown (old saves, setup-screen
|
||||
// dummy-leader fallback), every consumer degrades to neutral via ?./??.
|
||||
const trait = rules.civTraits[leaders[i].trait];
|
||||
const civ = {
|
||||
id: i,
|
||||
leaderId: leaders[i].id,
|
||||
traitId: leaders[i].trait ?? null,
|
||||
name: leaders[i].name,
|
||||
color: rules.playerColors[i % rules.playerColors.length],
|
||||
human: i === humanIndex,
|
||||
|
|
@ -98,7 +103,7 @@ export function createGame(rules, opts) {
|
|||
government: 'despotism',
|
||||
revolutionTurns: 0,
|
||||
pendingGovernment: null,
|
||||
gold: 50,
|
||||
gold: 50 + (trait?.startingGold ?? 0),
|
||||
beakers: 0,
|
||||
researching: null,
|
||||
known: {},
|
||||
|
|
@ -110,7 +115,15 @@ export function createGame(rules, opts) {
|
|||
nameCursor: i, // stride through the shared shuffled name pool
|
||||
nameOrder,
|
||||
score: 0,
|
||||
});
|
||||
};
|
||||
// Every leader personally lists 2-3 starting techs (data/opponents.json
|
||||
// startingTechs) independent of their trait — pioneering leaders already
|
||||
// get 2 from their trait above and list none of their own, everyone else
|
||||
// gets their personal pick. Union (not concat) guards against double-
|
||||
// granting if a personal list ever overlaps a trait-granted tech.
|
||||
const startingTechs = new Set([...(trait?.startingTechs ?? []), ...(leaders[i].startingTechs ?? [])]);
|
||||
for (const techId of startingTechs) grantTech(rules, state, civ, techId);
|
||||
state.civs.push(civ);
|
||||
state.explored.push(new Array(n).fill(0));
|
||||
}
|
||||
|
||||
|
|
@ -330,9 +343,10 @@ export function cityYields(rules, state, city) {
|
|||
const anarchy = gov.noScience === true;
|
||||
const baseGold = Math.floor(netTrade / 2);
|
||||
const baseScience = anarchy ? 0 : Math.ceil(netTrade / 2);
|
||||
let goldMult = 1;
|
||||
let sciMult = 1;
|
||||
let shieldMult = 1;
|
||||
const trait = rules.civTraits[civ.traitId];
|
||||
let goldMult = trait?.goldMult ?? 1;
|
||||
let sciMult = trait?.scienceMult ?? 1;
|
||||
let shieldMult = trait?.shieldMult ?? 1;
|
||||
for (const bId of Object.keys(city.buildings)) {
|
||||
const b = rules.buildings[bId];
|
||||
if (!b) continue;
|
||||
|
|
|
|||
|
|
@ -499,7 +499,12 @@ export class CivilizationMapView {
|
|||
const y = this.isoY(city.x, city.y);
|
||||
const civ = this.state.civs[city.civ];
|
||||
const color = Phaser.Display.Color.HexStringToColor(civ.color).color;
|
||||
const container = scene.add.container(x, y).setDepth(y);
|
||||
// Depth uses the same isoY + TILE_H/2 "ground" base as units/ghosts so
|
||||
// cities and units sort correctly against each other; the container's
|
||||
// actual (x, y) position stays at the bare isoY so the city art doesn't
|
||||
// shift on screen.
|
||||
const depthY = y + TILE_H / 2;
|
||||
const container = scene.add.container(x, y).setDepth(depthY);
|
||||
const walled = !!city.buildings.citywalls;
|
||||
|
||||
const themeKey = 'civilization-cities-classic';
|
||||
|
|
@ -538,7 +543,7 @@ export class CivilizationMapView {
|
|||
// instead of staying centered under the label — use setSize instead.
|
||||
banner.setSize(label.width + 16, 22);
|
||||
container.add([banner, label]);
|
||||
container.setDepth(y + 1);
|
||||
container.setDepth(depthY + 1);
|
||||
banner.setInteractive({ useHandCursor: true });
|
||||
banner.on('pointerdown', (pointer, lx, ly, event) => {
|
||||
event.stopPropagation();
|
||||
|
|
@ -556,13 +561,14 @@ export class CivilizationMapView {
|
|||
const y = this.isoY(c, r) + TILE_H / 2;
|
||||
const container = scene.add.container(x, y);
|
||||
|
||||
// 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.
|
||||
// Sprite mode: lift the unit frame so its bottom edge lands just below
|
||||
// the tile's vertical middle (roughly the middle of the colored civ
|
||||
// ring, nudged 5px down) rather than the diamond's lower point, so units
|
||||
// read as standing on the tile instead of at its front edge.
|
||||
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, TILE_H / 2 - UNIT_FRAME_H / 2, 'civilization-units', def.frame);
|
||||
const img = scene.add.image(0, -UNIT_FRAME_H / 2 + 5, 'civilization-units', def.frame);
|
||||
container.add([ring, img]);
|
||||
} else {
|
||||
const g = scene.add.graphics();
|
||||
|
|
@ -580,7 +586,7 @@ export class CivilizationMapView {
|
|||
}
|
||||
// Badges ride at shoulder height: low against the flat procedural
|
||||
// roundel, higher up against the taller sprite frame.
|
||||
const badgeY = spriteMode ? -28 : -14;
|
||||
const badgeY = spriteMode ? -60 : -14;
|
||||
if (unit.vet) {
|
||||
container.add(scene.add.circle(12, badgeY, 4, 0xd4a017).setStrokeStyle(1, 0x000000, 0.6));
|
||||
}
|
||||
|
|
@ -591,6 +597,17 @@ export class CivilizationMapView {
|
|||
}).setOrigin(0.5);
|
||||
container.add([badge, num]);
|
||||
}
|
||||
// Only the currently-selected unit is clickable — clicking any other
|
||||
// unit's tile still goes through the normal tile-click select/move flow
|
||||
// in CivilizationGame (see bindPointer/onTileClick).
|
||||
if (unit.id === this.selectedUnitId) {
|
||||
container.setSize(64, 64);
|
||||
container.setInteractive({ useHandCursor: true });
|
||||
container.on('pointerdown', (pointer, lx, ly, event) => {
|
||||
event.stopPropagation();
|
||||
this.cb.onUnitClick?.(unit);
|
||||
});
|
||||
}
|
||||
container.setDepth(y + 2);
|
||||
this.dynamic.add(container);
|
||||
this.unitContainers.set(unit.id, container);
|
||||
|
|
@ -605,7 +622,10 @@ export class CivilizationMapView {
|
|||
const x = this.isoX(unit.x, unit.y);
|
||||
const y = this.isoY(unit.x, unit.y) + TILE_H / 2;
|
||||
const ring = this.scene.add.circle(x, y - 2, 24).setStrokeStyle(3, 0xffffff, 1);
|
||||
ring.setDepth(y + 3);
|
||||
// Depth below the unit's own y + 2 (see drawUnit) so the unit sprite
|
||||
// renders in front of its own pulsing selection ring instead of the ring
|
||||
// sitting on top of it.
|
||||
ring.setDepth(y + 1);
|
||||
this.dynamic.add(ring);
|
||||
this.selectionRing = ring;
|
||||
this.scene.tweens.add({
|
||||
|
|
@ -628,7 +648,7 @@ export class CivilizationMapView {
|
|||
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); }
|
||||
if (ring) { ring.setPosition(p.x, p.y - 2); ring.setDepth(p.y + 1); }
|
||||
};
|
||||
place(points[0]);
|
||||
const segDuration = duration / (points.length - 1);
|
||||
|
|
@ -703,7 +723,7 @@ export class CivilizationMapView {
|
|||
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);
|
||||
img = scene.add.image(0, -UNIT_FRAME_H / 2 + 5, 'civilization-units', def.frame);
|
||||
container.add([ring, img]);
|
||||
} else {
|
||||
roundel = scene.add.graphics();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export function compileRules(json) {
|
|||
need(Array.isArray(json.buildings) && json.buildings.length > 0, 'buildings missing');
|
||||
need(Array.isArray(json.governments) && json.governments.length > 0, 'governments missing');
|
||||
need(Array.isArray(json.difficulties) && json.difficulties.length > 0, 'difficulties missing');
|
||||
need(Array.isArray(json.civTraits) && json.civTraits.length > 0, 'civTraits missing');
|
||||
if (errors.length) throw new Error(`civilization-rules invalid: ${errors.join('; ')}`);
|
||||
|
||||
const byId = (list, label) => {
|
||||
|
|
@ -33,6 +34,7 @@ export function compileRules(json) {
|
|||
const buildings = byId(json.buildings, 'building');
|
||||
const governments = byId(json.governments, 'government');
|
||||
const difficulties = byId(json.difficulties, 'difficulty');
|
||||
const civTraits = byId(json.civTraits, 'civTrait');
|
||||
const improvements = byId(json.improvements ?? [], 'improvement');
|
||||
const worldSizes = byId(json.worldSizes ?? [], 'worldSize');
|
||||
|
||||
|
|
@ -42,6 +44,15 @@ export function compileRules(json) {
|
|||
for (const p of t.prereqs) need(!!techs[p], `tech ${t.id} prereq ${p} unknown`);
|
||||
need(['ancient', 'medieval', 'industrial', 'modern'].includes(t.era), `tech ${t.id} bad era`);
|
||||
}
|
||||
for (const ct of json.civTraits) {
|
||||
need(typeof ct.name === 'string' && ct.name.length > 0, `civTrait ${ct.id} missing name`);
|
||||
need(typeof ct.description === 'string' && ct.description.length > 0, `civTrait ${ct.id} missing description`);
|
||||
need(typeof ct.scienceMult === 'number' && ct.scienceMult > 0, `civTrait ${ct.id} bad scienceMult`);
|
||||
need(typeof ct.goldMult === 'number' && ct.goldMult > 0, `civTrait ${ct.id} bad goldMult`);
|
||||
need(typeof ct.shieldMult === 'number' && ct.shieldMult > 0, `civTrait ${ct.id} bad shieldMult`);
|
||||
need(typeof ct.startingGold === 'number' && ct.startingGold >= 0, `civTrait ${ct.id} bad startingGold`);
|
||||
need(Array.isArray(ct.startingTechs), `civTrait ${ct.id} startingTechs must be an array`);
|
||||
}
|
||||
if (errors.length) throw new Error(`civilization-rules invalid: ${errors.join('; ')}`);
|
||||
|
||||
// Topological rank: rank 0 = no prereqs; rank(t) = 1 + max(rank(prereqs)).
|
||||
|
|
@ -82,6 +93,9 @@ export function compileRules(json) {
|
|||
for (const t of json.terrains) {
|
||||
if (t.transform) need(!!terrains[t.transform], `terrain ${t.id} transform ${t.transform} unknown`);
|
||||
}
|
||||
for (const ct of json.civTraits) {
|
||||
for (const techId of ct.startingTechs) need(!!techs[techId], `civTrait ${ct.id} startingTechs ${techId} unknown`);
|
||||
}
|
||||
for (const imp of json.improvements ?? []) {
|
||||
if (imp.prereq) need(!!techs[imp.prereq], `improvement ${imp.id} prereq tech ${imp.prereq} unknown`);
|
||||
if (imp.requires) need(!!improvements[imp.requires], `improvement ${imp.id} requires ${imp.requires} unknown`);
|
||||
|
|
@ -107,7 +121,7 @@ export function compileRules(json) {
|
|||
return {
|
||||
version: json.version ?? 1,
|
||||
raw: json,
|
||||
techs, units, terrains, specials, buildings, governments, difficulties,
|
||||
techs, units, terrains, specials, buildings, governments, difficulties, civTraits,
|
||||
improvements, worldSizes,
|
||||
techList: json.techs,
|
||||
unitList: json.units,
|
||||
|
|
@ -116,6 +130,7 @@ export function compileRules(json) {
|
|||
buildingList: json.buildings,
|
||||
governmentList: json.governments,
|
||||
difficultyList: json.difficulties,
|
||||
civTraitList: json.civTraits,
|
||||
improvementList: json.improvements ?? [],
|
||||
worldSizeList: json.worldSizes ?? [],
|
||||
techRank: rank,
|
||||
|
|
|
|||
|
|
@ -141,6 +141,16 @@ if (RULES) {
|
|||
check('difficulty ordering', RULES.difficultyList[0].aiProdBonus
|
||||
< RULES.difficultyList[4].aiProdBonus);
|
||||
|
||||
// Leader starting-condition traits.
|
||||
check('8 civ traits', RULES.civTraitList.length === 8, `${RULES.civTraitList.length}`);
|
||||
for (const id of Object.keys(RULES.civTraits)) {
|
||||
const t = RULES.civTraits[id];
|
||||
check(`civTrait ${id} mults positive`,
|
||||
t.scienceMult > 0 && t.goldMult > 0 && t.shieldMult > 0);
|
||||
check(`civTrait ${id} startingGold >= 0`, t.startingGold >= 0);
|
||||
for (const techId of t.startingTechs) check(`civTrait ${id} startingTechs ${techId} known tech`, !!RULES.techs[techId]);
|
||||
}
|
||||
|
||||
// World sizes / colors / names.
|
||||
check('3 world sizes', RULES.worldSizeList.length === 3);
|
||||
for (const w of RULES.worldSizeList) check(`world ${w.id} dims`, w.cols >= 32 && w.rows >= 24);
|
||||
|
|
@ -178,6 +188,69 @@ if (RULES) {
|
|||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
section('1b. opponents data');
|
||||
|
||||
const opponentsJson = JSON.parse(readFileSync(join(root, 'data/opponents.json'), 'utf8'));
|
||||
check('opponents present', Array.isArray(opponentsJson.opponents) && opponentsJson.opponents.length > 0);
|
||||
if (RULES) {
|
||||
for (const op of opponentsJson.opponents ?? []) {
|
||||
check(`opponent ${op.id} has trait`, typeof op.trait === 'string' && op.trait.length > 0);
|
||||
check(`opponent ${op.id} trait resolves`, !!RULES.civTraits[op.trait], op.trait);
|
||||
check(`opponent ${op.id} has startingTechs array`, Array.isArray(op.startingTechs));
|
||||
for (const techId of op.startingTechs ?? []) {
|
||||
check(`opponent ${op.id} startingTechs ${techId} known tech`, !!RULES.techs[techId]);
|
||||
}
|
||||
const traitTechs = RULES.civTraits[op.trait]?.startingTechs ?? [];
|
||||
const total = new Set([...traitTechs, ...(op.startingTechs ?? [])]).size;
|
||||
check(`opponent ${op.id} has 2-3 total starting techs`, total === 2 || total === 3, `${total}`);
|
||||
}
|
||||
|
||||
// Some variety across leaders — not every leader with the same trait
|
||||
// should end up with an identical personal tech list.
|
||||
const nonPioneering = opponentsJson.opponents.filter((op) => op.trait !== 'pioneering');
|
||||
const distinctLists = new Set(nonPioneering.map((op) => [...op.startingTechs].sort().join(',')));
|
||||
check('starting tech lists show variety across leaders', distinctLists.size > 5, `${distinctLists.size}`);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
section('1c. trait application');
|
||||
|
||||
if (RULES) {
|
||||
const leaders = [
|
||||
{ id: 'a', name: 'A', trait: 'scientific', startingTechs: ['pottery', 'masonry'] },
|
||||
{ id: 'b', name: 'B', trait: 'wealthy' },
|
||||
{ id: 'c', name: 'C', trait: 'pioneering' },
|
||||
{ id: 'd', name: 'D', trait: undefined },
|
||||
// trait's alphabet/bronzeworking overlaps this leader's own list — the
|
||||
// union must dedupe, not error or double-grant.
|
||||
{ id: 'e', name: 'E', trait: 'pioneering', startingTechs: ['alphabet', 'thewheel'] },
|
||||
];
|
||||
const st = Logic.createGame(RULES, { sizeId: 'small', seed: 5, difficultyId: 'prince', leaders });
|
||||
check('personal startingTechs granted', st.civs[0].known.pottery === true && st.civs[0].known.masonry === true);
|
||||
check('wealthy gets +100 starting gold', st.civs[1].gold === 150, `${st.civs[1].gold}`);
|
||||
check('pioneering knows alphabet', st.civs[2].known.alphabet === true);
|
||||
check('pioneering knows bronzeworking', st.civs[2].known.bronzeworking === true);
|
||||
check('no-trait civ unaffected', st.civs[3].gold === 50 && Object.keys(st.civs[3].known).length === 0,
|
||||
`${st.civs[3].gold}`);
|
||||
check('overlapping trait + personal techs dedupe to 3 known',
|
||||
Object.keys(st.civs[4].known).length === 3
|
||||
&& st.civs[4].known.alphabet && st.civs[4].known.bronzeworking && st.civs[4].known.thewheel,
|
||||
`${Object.keys(st.civs[4].known).join(',')}`);
|
||||
|
||||
// scienceMult/goldMult/shieldMult actually flow into cityYields: two
|
||||
// synthetic cities sharing the exact same tile/buildings/size, differing
|
||||
// only in which civ owns them (civ 0 = scientific, civ 3 = no trait). A
|
||||
// large fixed trade-route amount swamps any terrain-dependent tile yield,
|
||||
// so the only meaningful difference in output is the trait multiplier —
|
||||
// deterministic regardless of what terrain worldgen placed at (5,5).
|
||||
const baseCity = { x: 5, y: 5, worked: [], routes: [{ amount: 200 }], buildings: {}, size: 1 };
|
||||
const sciY = Logic.cityYields(RULES, st, { ...baseCity, civ: 0 });
|
||||
const plainY = Logic.cityYields(RULES, st, { ...baseCity, civ: 3 });
|
||||
check('scientific trait raises science output', sciY.science > plainY.science,
|
||||
`${sciY.science} vs ${plainY.science}`);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
section('2. world generation');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue