Repository navigation
Author game rules as formulas, with pause and color markers in text - #53
Merged
Merged
Conversation
A {pause} at the very end of a text now holds the page that long
instead of showing it a second time, and appendText takes one there.
About a hundred writeText calls followed by a pause became one call,
such as writeText("No money - No drink! {pause 1s}"), and the
pause600ms() to pause4s() aliases are gone. pause(ms) stays for the
one beat between a sound and the line after it.
writeText always starts a fresh page, so the clearText() calls just
before one did nothing and are removed, and writeText, waitInput and
clearText in a row are showTextAndWait. The battle runner's clearText
now also forgets the page, so an appendText after it no longer brings
the cleared text back.
Two monster spells colored "X DIES!" with raw ANSI escapes, which the
browser drew as "[31m...". A line or paragraph that starts with {red},
or green, yellow, blue, magenta or cyan, is now shown in that color:
- Compiled text starts the line with the color's escape, and the line
wrapper keeps it on every row the line wraps to.
- The terminal resets the color after each colored row.
- The bitmap frame sends the line as plain text and names its color in
textLineColors, which the browser draws.
The content check rejects raw escape codes, and a color marker anywhere
but the start of a line.
The runtime counts the living members again after every member write, but the church raise, Rebirth and the poison potion also changed party.memberCount by hand: the church left it one too high and the potion one too low. memberCount is read-only now. Members and monsters get wound(amount), which kills at zero hit points, kill() and revive(), in place of the hit point and death bookkeeping each spell and item repeated.
Battle charged a mage spell its base cost plus the caster's level in
code, and each priest spell repeated its cost as
withCurrentCasterCost(8) next to the baseCost in its header, which was
the number actually charged.
The game now declares formula(Formulas.spellCost) with
value = spellBaseCost + level and points realm { spellCost } at it.
Battle and the priest spell runner evaluate it for the caster, and
withCurrentCasterCost { caster, cost -> } hands the result to the
script. The runtime systems schema is 14.
Function-local lists, sets, maps and strings that were filled and then only read are buildList, buildSet, buildMap, buildString or a plain functional expression, var accumulators are folds, and the public MutableList on SwitchBuilder and the flag registry are read-only views. DSL builders, runtime state machines, RNG threading and test fakes that record calls keep their mutable state.
The runtime worked out hit chance, damage, a monster's chance to cast,
the healing a defending member gets, how encounters grow with the
leader's level, the food the party eats and the town entry tax in
code, with only some constants authored. They are formulas now:
- playerRound and monsterRound name playerHitChance, playerDamage,
defendHealing, monsterSpellChance, monsterHitChance and
monsterDamage.
- standardBattle names encounterFoeCountMax and encounterWeaponSkill.
- upkeep { foodCost } and entryTax { amount } name foodUpkeep and
townEntryTax.
The runtime binds the same values and draws the same random numbers in
the same order, so replays play out exactly as before. Formulas gain
atLeast and atMost, a plain number can stand on the left of an
expression, and the hunt, disarm and haggle formulas no longer need
lit(). The test autopilot evaluates the combat formulas at their
average instead of copying the rules, and the town street view is
authored as townSystem { image } instead of named in the runtime.
Shops chose prices from schemes coded in the runtime: the leader's level plus a number, an item's cost plus the level times a number, and half the cost when the shop buys. A price is now the item's cost, a fixed amount or ShopPrices.formula(...), and the game declares rationPrice, healingPotionPrice and sellPrice. A sell section names its price instead of falling back to half the cost.
The runtime assembled battle pages from fragments, wrote "Round N" itself, and joined the castle thief's name to a trapTriesDisarmSuffix. Each message is one authored template now: - encounter and nextRound replace encounterBanner, youFace, foeDisplayName and stillFace; nextRound shows BattleText.roundNumber. - victoryReward and victoryLoot absorb victoryEachSurvivor and victoryFoundObject. - trapTriesDisarm names the thief with CastleText.thiefName. The drop message names the item with InventoryText.itemName instead of a raw TextPart.
The castle's script roots were raw sceneId("castle.ydarg...") strings;
they are Scenes.Castle handles now. The guardian's give menu repeated
the stairs items' names and ended in a "5. Nothing" row that the
runtime knew by its digit. The runtime now lists the stairs items under
the authored givePrompt and leaves on RETURN, as other menus do.
All nine dungeon scenarios repeated the same eight weighted events.
dungeons { randomEvents(...) } now sets the mix of every scenario that
names none of its own, and level(13..19, ...) and
level(3, 6, 9, event = ...) put one event on several levels.
Scripts borrowed HuntText.partyMemberCount and partyMemberMax to write "Who? (1-4)" in the church, spells and potions, and the equipment prompt printed "Who? (1-N)" as written. PartyText.memberCount and memberMax serve every prompt that lists the members. A reward's messages can name the item with itemName, so Ron's drop prompt says "You can't carry the Admt. Mail." instead of the cut-off "You can't carry all the".
Tybalt and Ron gave 6x20 and 42x23 in their speech and in the journal, copied from their missions' at(xy(...)). mission(Missions.x).coordinates shows the mission's square, or its location's placement, and the runtime and the compiler share the coordinate format.
The inn and tavern repeated the same pay-and-heal block for every drink, each price typed twice. orderDrink takes a table of drinks and builds the menu rows and their options from it. The tavern's drinks now heal only living members, as the inn's do. pay takes a plain number, so the game has no lit() left, and the clearText() calls before menus that start a fresh page are removed.
The authoring guide gains a Formulas section, listing the rules that are formulas and the variables each system binds, and covers PartyText, CastleText, BattleText.roundNumber, mission coordinates, reward item names, shop prices, the shared dungeon event mix and the menus the runtime builds.
The runtime never checked that a party could pay the town entry tax. A
tax larger than the party's gold would have been paid down to 0 gold
and let the party in. The game's tax is a share of the gold carried, so
this never happened, but the tax is an authored formula now.
A party that can't pay is shown the new town { entryTaxShortfall }
prompt instead of the pay-or-leave choice, and stays outside.
TownText.taxShortfall names the gold it lacks:
There is a tax of 7% to enter Thord. You need 500 additional au
to be able to pay.
flowText had three forms: a single string, whose blank lines started
paragraphs; strings and values, which made one paragraph; and a
flowText { paragraph(...) } builder for several paragraphs with values.
It has one now. flowText(...) takes strings and values, and in every
string a newline is a space and a blank line, or \n\n, starts a new
paragraph:
flowText(
townNpcName(NpcJobs.innkeeper),
", the Innkeeper welcomes you.",
"\n\nDo you want supper, travelers?",
)
The seven builder uses in the game are written this way, and the
compiled bundle is byte for byte the same. The lines { } overload, which
only ran its block, is gone too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #52, one commit per step. Game rules the runtime computed in code are formulas in the game DSL now, and more text is written with inline markers and placeholders instead of helper calls and copied values.
Rules are formulas
The runtime only binds variables and evaluates what the game declares under
formulas { }:value = spellBaseCost + level, referenced asrealm { spellCost }. The priest spells'withCurrentCasterCost(8)repeated a number that thebaseCostin the spell header already set; it iswithCurrentCasterCost { caster, cost -> }now.playerHitChance,playerDamage,defendHealing,monsterHitChance,monsterDamage,monsterSpellChance,encounterWeaponSkillandencounterFoeCountMax.foodUpkeepandtownEntryTax. The runtime never checked that a party could pay the tax, so a tax above the party's gold would have been paid down to 0 and let it in. A party that can't pay now sees the newtown { entryTaxShortfall }prompt and stays outside: "There is a tax of 7% to enter Thord. You need 500 additional au to be able to pay." The game's tax is a share of the gold carried, so today it is always payable.rationPrice,healingPotionPriceandsellPrice, throughShopPrices.formula(...). A sell section must name its price.Formulas gain
atLeastandatMost, and a plain number can stand on the left of an expression, so the game has nolit()left. The runtime draws the same random numbers in the same order as before, so replays play out unchanged. The test autopilot evaluates the combat formulas at their average instead of copying the rules. The runtime systems schema is 14, so the server needs a redeploy.Markers and placeholders in text
flowText: it takes strings and values. In every string a newline is a space, and a blank line or\n\nstarts a new paragraph. The single-string form and theflowText { paragraph(...) }builder are gone, along with an unusedlines { }overload. The compiled bundle is byte-identical after the change.{pause}: a marker at the end of a text holds the page instead of showing it again. About a hundredwriteText+pause…()pairs are single calls now, andpause600ms()…pause4s()are gone;pause(ms)stays.{red}(or green, yellow, blue, magenta, cyan) is shown in that color. Two monster spells used raw ANSI escapes, which the browser drew as[31m…. The content check rejects raw escapes and markers that don't start a line.BattleText.roundNumber,CastleText.thiefName) instead of fragments the runtime joined.PartyText.memberCount/memberMaxserve every "Who? (1-N)" prompt, a reward's messages can name the item, andmission(Missions.x).coordinatesreplaces the 6x20 and 42x23 copied into Tybalt's and Ron's speech.Smaller DSL pieces
wound(),kill()andrevive()on members and monsters.party.memberCountis read-only.dungeons { randomEvents(...) }sets one event mix for all nine scenarios;level(13..19, …)andlevel(3, 6, 9, event = …)place an event on several levels.orderDrinkbuilds the inn and tavern menus from a table of drinks.Scenes.Castlehandles;townSystem { image }names the street view.buildList/buildMap/buildStringor folds instead of filled mutable locals.docs/dsl-authoring.mddocuments the formulas, the variables each system binds, and the new placeholders.What players will notice
Tests
./gradlew check --rerun-tasks --no-build-cachepasses at the head: 243 tests, 0 failures, 0 skipped. The dungeon event commit was also built and tested on its own.Not checked by hand: the colored lines were not looked at in a browser, and the build has not been deployed.