fertig-classic-games/src/games/forbiddenisland/IslandChat.js

166 lines
7.8 KiB
JavaScript

// The Drowning Isle — expedition chat. 100% offline string templates.
//
// The planner (IslandAI.describeIntent) produces a rationale object; this turns
// it into a line of table talk in the speaking crew member's voice. Each role
// has a personality (ROLES[role].voice): the Bush Pilot is breezy, the Field
// Engineer gruff, the Wireless Operator crisp radio-speak, the Cartographer
// professorial, the Hard-Hat Diver laconic, the Mountaineer eager. Game events
// (a tile sinking, a Waters Rise, a capture) get their own lines so the journal
// reads like an expedition log.
import { TREASURES, ROLES } from './IslandData.js';
const EMOJI = {
pilot: '✈️', engineer: '🔧', messenger: '📻', navigator: '🧭', diver: '🤿', explorer: '🧗',
};
export function roleEmoji(role) { return EMOJI[role] ?? '🧩'; }
export function roleName(role) { return ROLES[role]?.name ?? role; }
export function roleColorHex(role) { return ROLES[role]?.colorHex ?? '#f2ead8'; }
const pick = (arr) => arr[Math.floor(Math.random() * arr.length)];
const tName = (key) => TREASURES[key]?.name ?? 'the relic';
const tShort = (key) => TREASURES[key]?.short ?? 'relic';
// Sign-offs and asides in each crew member's voice.
const FLAVOR = {
pilot: ['Wheels up whenever you are.', 'Lovely weather for it. Not.', 'I can be anywhere in a heartbeat.', 'Keep the dock dry, chums. That is our ride home.'],
engineer: ['Mind the timbers.', 'Right. Get on with it.', 'I have seen worse. Not much worse.', 'Everything floods. Question is when.'],
messenger: ['Over.', 'Signal is clear, over.', 'Standing by on all frequencies.', 'Copy all, over.'],
navigator: ['Fascinating, truly fascinating.', 'I have marked it in the survey.', 'Note the bearing, everyone.', 'The old maps did warn of this.'],
diver: ['Water is fine.', 'Seen deeper.', 'Mm.', 'I will go under if I have to.'],
explorer: ['There is always another way across!', 'Diagonal is my favourite direction.', 'What a place!', 'Onward!'],
};
// Openers by voice for the same plan, so six crew don't all sound alike.
const VOICE = {
breezy: { go: 'Hopping over to', hold: 'I will keep the kite in the air and', yes: 'Easy as you like:' },
gruff: { go: 'Heading for', hold: 'Not much for me. I will', yes: 'Right:' },
crisp: { go: 'Moving to', hold: 'No traffic for me, will', yes: 'Confirmed:' },
professorial: { go: 'By my reckoning I should make for', hold: 'Nothing pressing in my survey, so I shall', yes: 'Splendid:' },
laconic: { go: 'Going to', hold: 'Nothing for me. I will', yes: 'Done:' },
eager: { go: 'Off to', hold: 'Nothing for me yet, so I will', yes: 'Here we go:' },
};
const voiceOf = (role) => VOICE[ROLES[role]?.voice] ?? VOICE.crisp;
const radio = (role, text) => (ROLES[role]?.voice === 'crisp' && !/over\.$/i.test(text) ? `${text} Over.` : text);
const INTENT = {
CAPTURE: (r) => {
const v = voiceOf(r.role);
return pick([
`${v.yes} I am standing on the shrine with four cards. Claiming ${tName(r.treasure)} now!`,
`Four cards and my boots on the tile. ${tName(r.treasure)} comes with us this turn.`,
`Securing ${tName(r.treasure)}. One less thing for the sea to take.`,
]);
},
SEEK: (r) => {
const v = voiceOf(r.role);
const base = pick([
`I hold ${r.cards} of the 4 cards for the ${tShort(r.treasure)}. ${v.go} its shrine.`,
`The ${tShort(r.treasure)} is my job: ${r.cards}/4 so far. ${v.go} the shrine.`,
`${v.go} the ${tShort(r.treasure)} shrine, ${r.cards} cards in hand.`,
]);
if (r.request) return `${base} ${roleName(r.request.fromRole)}, if you have a matching card, send it my way?`;
return base;
},
GIVE: (r) => pick([
`Pooling the ${tShort(r.treasure)} cards. Mine goes to whoever is carrying the set.`,
`Card hand-off this turn: ${tShort(r.treasure)} goes to our collector.`,
`One of us should hold every ${tShort(r.treasure)} card. Passing mine along.`,
]),
SHORE: (r) => {
const v = voiceOf(r.role);
return pick([
`${v.yes} shoring up. We cannot lose ground here.`,
`Bracing the flooded tiles near me before the next swell.`,
`Holding the line on the wet ground around me.`,
]);
},
ESCAPE: () => pick([
`All four relics are in! Everyone to the Expedition Dock. We need a Helicopter Lift.`,
`That is the lot! Converge on the dock, and whoever holds the Helicopter Lift, keep it safe.`,
`Home stretch, everyone. Make for the Expedition Dock.`,
]),
SUPPORT: (r) => {
const v = voiceOf(r.role);
return pick([
`${v.hold} move to where I will be useful.`,
`${v.hold} keep my options open.`,
`${v.hold} back up whoever needs it.`,
]);
},
};
// A line announcing the AI partner's plan for the turn.
export function lineForIntent(rationale) {
const make = INTENT[rationale.intent] ?? INTENT.SUPPORT;
let text = make(rationale);
const t = rationale.threats?.[0];
if (t && Math.random() < 0.5) {
text += ` ${pick([
`Heads up: ${t.name} could flood next. Someone watch it.`,
`Also, ${t.name} is in danger. Do not let it sink.`,
`Keep an eye on ${t.name}. It is one flood from trouble.`,
])}`;
} else if (Math.random() < 0.3) {
text += ` ${pick(FLAVOR[rationale.role] ?? [''])}`;
}
return { role: rationale.role, text: radio(rationale.role, text) };
}
// Lines for notable game events. `ctx` carries the names already resolved.
export function lineForEvent(kind, ctx = {}) {
const say = (arr) => radio(ctx.role, pick(arr));
switch (kind) {
case 'sink': return { role: ctx.role ?? null, text: pick([
`${ctx.tileName} slid beneath the waves.`,
`${ctx.tileName} is gone. The sea has it now.`,
`We have lost ${ctx.tileName}.`,
]) };
case 'watersRise': return { role: ctx.role ?? null, text: pick([
`The Waters Rise! The gauge reads ${ctx.waterLevel}, and every flooded tile goes back on top of the flood deck.`,
`Waters Rise. The tide climbs to ${ctx.waterLevel}, and the tiles we saw flood are coming round again.`,
]) };
case 'capture': return { role: ctx.role, text: say([
`Got it! ${tName(ctx.treasure)} is ours. ${4 - (ctx.remaining ?? 0)} of 4 relics recovered.`,
`${tName(ctx.treasure)} is in the crate. Lovely work, everyone.`,
]) };
case 'sandbags': return { role: ctx.role, text: say([
`Sandbags down on ${ctx.tileName}. That holds it, and it costs no action.`,
`Sandbagging ${ctx.tileName}. We cannot lose that one.`,
]) };
case 'heliMove': return { role: ctx.role, text: say([
`Helicopter Lift: flying ${ctx.who} straight to ${ctx.tileName}.`,
`Calling in a Helicopter Lift to get ${ctx.who} onto ${ctx.tileName}.`,
]) };
case 'give': return { role: ctx.role, text: say([
`Passing a ${tShort(ctx.card?.slice(9))} card to ${ctx.to}.`,
`${ctx.to}, here: one more for the ${tShort(ctx.card?.slice(9))}.`,
]) };
case 'swim': return { role: ctx.role, text: say([
`The ground went out from under me. Swimming to ${ctx.tileName}.`,
`Had to swim for ${ctx.tileName} as the tile sank.`,
]) };
case 'won': return { role: null, text: pick([
`The helicopter lifts off the Expedition Dock with all four relics aboard. The expedition is saved!`,
`Rotors turning, crates lashed down. We made it off the island, together.`,
]) };
case 'lost': return { role: null, text: ctx.reason ?? 'The island is lost.' };
default: return null;
}
}
// Acknowledgement when the human sets a strategy priority.
export function lineForAck(role, label) {
return { role, text: radio(role, pick([
`Understood: ${label}.`,
`Re-planning around: ${label}.`,
`Right. Prioritising ${label}.`,
])) };
}
// Journal heading for each new round, e.g. "Day 3 · Gauge 4".
export function journalStamp(round, level) {
return `Day ${round} · Gauge ${level}`;
}