Skip to content

Commit

Permalink
0.10.6 - Script tweaks (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
charredUtensil authored Oct 7, 2024
1 parent 1fa4d32 commit 2b2fd95
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 167 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "groundhog",
"version": "0.10.5",
"version": "0.10.6",
"homepage": "https://charredutensil.github.io/groundhog",
"private": true,
"dependencies": {
Expand Down
45 changes: 25 additions & 20 deletions src/core/architects/build_and_power.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { Plan } from "../models/plan";
import { OrderedOrEstablishedPlan } from "../transformers/01_planning/05_establish";
import { DefaultCaveArchitect, PartialArchitect } from "./default";
import { intersectsOnly } from "./utils/intersects";
import { gObjectives } from "./utils/objectives";
import { Rough, mkRough } from "./utils/rough";
import {
declareStringFromLore,
eventChain,
eventChainSynchronized,
EventChainLine,
mkVars,
scriptFragment,
transformPoint,
Expand All @@ -39,22 +40,19 @@ function buildAndPower(
"prime" | "objectives" | "script" | "scriptGlobals"
> {
const g = mkVars(`gBp${template.inspectAbbrev}`, [
"onBuild",
"built",
"onPower",
"checkPower",
"doneCount",
"done",
"msgA",
"msgB",
"msgC",
"onComplete",
]);
const metadata: BuildAndPowerMetadata = { tag: TAG, template };
const mv = (plan: Plan<any>) =>
mkVars(`p${plan.id}Bp${template.inspectAbbrev}`, [
"arrow",
"building",
"onInit",
"onBuild",
]);
return {
Expand All @@ -81,7 +79,7 @@ function buildAndPower(
sufficient: true,
};
},
scriptGlobals({ cavern }) {
scriptGlobals({ cavern, sh }) {
const pvs = cavern.plans
.filter(
(plan) =>
Expand All @@ -96,30 +94,31 @@ function buildAndPower(
// have collisions. In theory, it shouldn't be possible to level up
// multiple buildings at the same time.
`building ${g.built}`,
`when(${template.id}.${minLevel > 1 ? "levelup" : "new"})[${g.onBuild}]`,
eventChain(
g.onBuild,
sh.trigger(
`when(${template.id}.${minLevel > 1 ? "levelup" : "new"})`,
`savebuilding:${g.built};`,
minLevel > 1 && `((${g.built}.level<${minLevel}))return;`,
...pvs.map((v) => `${v.onBuild};` satisfies `${string};`),
...pvs.map((v) => `${v.onBuild};` satisfies EventChainLine),
),

// Second trigger: power state changes.
`int ${g.checkPower}=0`,
`int ${g.doneCount}=0`,
...pvs.map((v) => `arrow ${v.arrow}`),
...pvs.map((v) => `building ${v.building}`),
`when(${template.id}.poweron)[${g.onPower}]`,
`when(${template.id}.poweroff)[${g.onPower}]`,
eventChainSynchronized(
g.onPower,
`when(${template.id}.poweron)[${g.checkPower}+=1]`,
`when(${template.id}.poweroff)[${g.checkPower}+=1]`,
sh.trigger(
`when(${g.checkPower}==1)`,
`${g.doneCount}=0;`,
...pvs.flatMap(
(v) =>
[
`((${v.building}.powered>0))[hidearrow:${v.arrow}][showarrow:${v.building}.row,${v.building}.column,${v.arrow}];`,
`((${v.building}.powered>0))${g.doneCount}+=1;`,
] satisfies `${string};`[],
] satisfies EventChainLine[],
),
`((${g.checkPower}>1))[${g.checkPower}=1][${g.checkPower}=0];`,
),

// Messages & done trigger
Expand Down Expand Up @@ -163,8 +162,13 @@ function buildAndPower(
buildingName: template.name,
},
),
`if(${g.doneCount}>=${pvs.length})[${g.onComplete}]`,
eventChain(g.onComplete, `msg:${g.msgC};`, "wait:2;", `${g.done}=1;`),
sh.trigger(
`if(${g.doneCount}>=${pvs.length})`,
`${gObjectives.met}+=1;`,
`msg:${g.msgC};`,
"wait:2;",
`${g.done}=1;`,
),
);
},
script({ cavern, plan }) {
Expand All @@ -184,17 +188,18 @@ function buildAndPower(

return scriptFragment(
`# P${plan.id}: Build and Power ${template.name}`,
`if(${openOnSpawn ? `time:0` : `change:${atp}`})[${v.onInit}]`,
eventChain(v.onInit, `showarrow:${atp},${v.arrow};`),
`if(${openOnSpawn ? `time:0` : `change:${atp}`})[showarrow:${atp},${v.arrow}]`,
eventChain(
v.onBuild,
// Filter out buildings outside the baseplate rectangle
`((${g.built}.column<${bp.left - cavern.left}))return;`,
`((${g.built}.column>=${bp.right - cavern.left}))return;`,
`((${g.built}.row<${bp.top - cavern.top}))return;`,
`((${g.built}.row>=${bp.bottom - cavern.top}))return;`,
// Setting a building variable to the value of another building
// variable doesn't work in MMScript for some reason
`savebuilding:${v.building};`,
`${g.onPower};`,
`${g.checkPower}+=1;`,
),
);
},
Expand Down
38 changes: 17 additions & 21 deletions src/core/architects/established_hq/fixed_complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
GEOLOGICAL_CENTER,
ALL_BUILDINGS,
} from "../../models/building";
import { gObjectives } from "../utils/objectives";
import {
declareStringFromLore,
eventChain,
EventChainLine,
mkVars,
scriptFragment,
} from "../utils/script";
Expand All @@ -36,12 +37,7 @@ const T0_BUILDINGS = [

const T0_CRYSTALS = T0_BUILDINGS.reduce((r, bt) => r + bt.crystals, 0);

const gFCHQ = mkVars("gFCHQ", [
"onInit",
"onBaseDestroyed",
"msgBaseDestroyed",
"wasBaseDestroyed",
]);
const gFCHQ = mkVars("gFCHQ", ["msgLose", "wasBaseDestroyed"]);

export const FC_BASE: Pick<
Architect<HqMetadata>,
Expand All @@ -64,33 +60,33 @@ export const FC_BASE: Pick<
discovered: true,
templates: () => T0_BUILDINGS,
}),
scriptGlobals: ({ cavern }) => {
scriptGlobals: ({ cavern, sh }) => {
return scriptFragment(
`# Globals: Fixed Complete HQ`,
`if(time:0)[${gFCHQ.onInit}]`,
eventChain(
gFCHQ.onInit,
sh.trigger(
"if(time:0)",
// Can't just disable buildings because that disables fences - and
// nobody wants that.
...ALL_BUILDINGS.map((bt) => `disable:${bt.id};` as `${string};`),
...ALL_BUILDINGS.map(
(bt) => `disable:${bt.id};` satisfies EventChainLine,
),
),
declareStringFromLore(
cavern,
LoreDie.failureBaseDestroyed,
gFCHQ.msgBaseDestroyed,
gFCHQ.msgLose,
FAILURE_BASE_DESTROYED,
{},
{},
),
`int ${gFCHQ.wasBaseDestroyed}=0`,
`if(${TOOL_STORE.id}<=0)[${gFCHQ.onBaseDestroyed}]`,
`if(${POWER_STATION.id}<=0)[${gFCHQ.onBaseDestroyed}]`,
`if(${SUPPORT_STATION.id}<=0)[${gFCHQ.onBaseDestroyed}]`,
eventChain(
gFCHQ.onBaseDestroyed,
`((${gFCHQ.wasBaseDestroyed}>0))return;`,
`${gFCHQ.wasBaseDestroyed}=1;`,
`msg:${gFCHQ.msgBaseDestroyed};`,
`if(${TOOL_STORE.id}<=0)[${gFCHQ.wasBaseDestroyed}=1]`,
`if(${POWER_STATION.id}<=0)[${gFCHQ.wasBaseDestroyed}=1]`,
`if(${SUPPORT_STATION.id}<=0)[${gFCHQ.wasBaseDestroyed}=1]`,
sh.trigger(
`if(${gFCHQ.wasBaseDestroyed}>=1)`,
`((${gObjectives.won}>0))return;`,
`msg:${gFCHQ.msgLose};`,
`wait:5;`,
`lose;`,
),
Expand Down
10 changes: 4 additions & 6 deletions src/core/architects/established_hq/lost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
scriptFragment,
mkVars,
transformPoint,
eventChain,
declareStringFromLore,
} from "../utils/script";
import { BASE, HqMetadata, getPlaceBuildings, getPrime } from "./base";
Expand Down Expand Up @@ -39,7 +38,7 @@ const LOST_BASE: Pick<
},
scriptGlobals: () =>
scriptFragment("# Globals: Lost HQ", `int ${gLostHq.foundHq}=0`),
script({ cavern, plan }) {
script({ cavern, plan, sh }) {
const discoPoint = getDiscoveryPoint(cavern, plan)!;
const shouldPanMessage =
cavern.ownsScriptOnDiscover[
Expand All @@ -50,7 +49,7 @@ const LOST_BASE: Pick<
return r.pearlRadius > p.pearlRadius ? r : p;
}).center;

const v = mkVars(`p${plan.id}LostHq`, ["messageDiscover", "onDiscover"]);
const v = mkVars(`p${plan.id}LostHq`, ["messageDiscover"]);

return scriptFragment(
`# P${plan.id}: Lost HQ`,
Expand All @@ -63,9 +62,8 @@ const LOST_BASE: Pick<
{},
{},
),
`if(change:${transformPoint(cavern, discoPoint)})[${v.onDiscover}]`,
eventChain(
v.onDiscover,
sh.trigger(
`if(change:${transformPoint(cavern, discoPoint)})`,
shouldPanMessage && `msg:${v.messageDiscover};`,
shouldPanMessage && `pan:${transformPoint(cavern, camPoint)};`,
`wait:1;`,
Expand Down
19 changes: 7 additions & 12 deletions src/core/architects/fissure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DefaultHallArchitect, PartialArchitect } from "./default";
import { mkRough, Rough } from "./utils/rough";
import {
declareStringFromLore,
eventChain,
EventChainLine,
mkVars,
scriptFragment,
transformPoint,
Expand Down Expand Up @@ -35,7 +35,6 @@ const sVars = (plan: Plan<any>) =>
mkVars(`p${plan.id}Fissure`, [
"onDiscover",
`onTrip`,
`onFissure`,
`msgForeshadow`,
`spawn`,
"tripCount",
Expand All @@ -44,7 +43,7 @@ const sVars = (plan: Plan<any>) =>
const BASE: PartialArchitect<typeof METADATA> = {
...DefaultHallArchitect,
prime: () => METADATA,
script: ({ cavern, plan }) => {
script: ({ cavern, plan, sh }) => {
const v = sVars(plan);
const discoveryPoints = getDiscoveryPoints(cavern, plan);
const panTo = plan.innerPearl[0][Math.floor(plan.innerPearl[0].length / 2)];
Expand All @@ -68,17 +67,13 @@ const BASE: PartialArchitect<typeof METADATA> = {
{},
),
...discoveryPoints.map(
(pos) => `if(change:${transformPoint(cavern, pos)})[${v.onTrip}]`,
(pos) => `if(change:${transformPoint(cavern, pos)})[${v.tripCount}+=1]`,
),
...drillPoints.map(
(pos) => `if(drill:${transformPoint(cavern, pos)})[${v.onTrip}]`,
(pos) => `if(drill:${transformPoint(cavern, pos)})[${v.tripCount}+=1]`,
),
eventChain(
v.onTrip,
`((${v.tripCount}==${trips}))[${v.onFissure}][${v.tripCount}+=1];`,
),
eventChain(
v.onFissure,
sh.trigger(
`if(${v.tripCount}>=${trips})`,
`wait:random(5)(30);`,
`shake:1;`,
`msg:${v.msgForeshadow};`,
Expand All @@ -91,7 +86,7 @@ const BASE: PartialArchitect<typeof METADATA> = {
.filter((pos) => cavern.tiles.get(...pos)?.isWall)
.map(
(pos) =>
`drill:${transformPoint(cavern, pos)};` satisfies `${string};`,
`drill:${transformPoint(cavern, pos)};` satisfies EventChainLine,
),
cavern.context.hasMonsters && `${v.spawn};`,
),
Expand Down
16 changes: 7 additions & 9 deletions src/core/architects/lost_miners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
FOUND_LM_BREADCRUMB,
FOUND_LOST_MINERS,
} from "../lore/graphs/events";
import { gObjectives } from "./utils/objectives";

export type LostMinersMetadata = {
readonly tag: "lostMiners";
Expand Down Expand Up @@ -260,20 +261,19 @@ const BASE: PartialArchitect<LostMinersMetadata> = {
),
eventChain(
gLostMiners.onFoundAll,
`${gObjectives.met}+=1;`,
`msg:${gLostMiners.messageFoundAll};`,
`wait:3;`,
`${gLostMiners.done}=1;`,
),
);
},
script({ cavern, plan }) {
script({ cavern, plan, sh }) {
const rng = cavern.dice.script(plan.id);
const { lostMinerCaves } = countLostMiners(cavern);
const v = mkVars(`p${plan.id}LostMiners`, [
"msgFoundBreadcrumb",
"msgFoundMiners",
"onFoundBreadcrumb",
"onFoundMiners",
"onIncomplete",
"wasFound",
]);
Expand Down Expand Up @@ -310,9 +310,8 @@ const BASE: PartialArchitect<LostMinersMetadata> = {
},
),
`int ${v.wasFound}=0`,
`if(change:${transformPoint(cavern, minersPoint)})[${v.onFoundMiners}]`,
eventChain(
v.onFoundMiners,
sh.trigger(
`if(change:${transformPoint(cavern, minersPoint)})`,
shouldPanOnMiners && `pan:${transformPoint(cavern, minersPoint)};`,
`${v.wasFound}=1;`,
`${gLostMiners.remainingCaves}-=1;`,
Expand All @@ -334,9 +333,8 @@ const BASE: PartialArchitect<LostMinersMetadata> = {
vehicleName: breadcrumb!.template.name,
},
),
`if(change:${transformPoint(cavern, breadcrumbPoint)})[${v.onFoundBreadcrumb}]`,
eventChain(
v.onFoundBreadcrumb,
sh.trigger(
`if(change:${transformPoint(cavern, breadcrumbPoint)})`,
`((${v.wasFound}>0))return;`,
`pan:${transformPoint(cavern, breadcrumbPoint)};`,
`msg:${v.msgFoundBreadcrumb};`,
Expand Down
Loading

0 comments on commit 2b2fd95

Please sign in to comment.