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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import kotlin.reflect.typeOf

private const val EXTERNAL_BUNDLE_FORMAT = "rylween.compiled.bundle"
private const val EXTERNAL_BUNDLE_VERSION = 3
private const val EXTERNAL_RUNTIME_SYSTEMS_VERSION = 14
private const val EXTERNAL_RUNTIME_SYSTEMS_VERSION = 15
private const val GRID_CASTLE_KIND = "gridCastle"

/** Serializes this game into the canonical strict JSON J1 artifact bytes. */
Expand Down Expand Up @@ -585,6 +585,8 @@ data class ExternalRuntimeRealm(
val timeOfDay: List<ExternalTimeOfDayBand>,
/** Slug of the formula that prices a spell for its caster, or null when a spell costs its base cost. */
val spellCost: String?,
/** Slug of the formula for how many squares a party sees other parties, or null when parties never see each other. */
val partySight: String?,
)

/** One status-line time label exported for direct runtimes. */
Expand Down Expand Up @@ -1710,6 +1712,7 @@ private class ExternalBundleArtifactWriter {
"camp" to campJson(realm.camp),
"hunt" to realm.hunt?.let(::huntJson).orJsonNull(),
"spellCost" to realm.spellCost?.let { formula -> JsonString(formula.slug) }.orJsonNull(),
"partySight" to realm.partySight?.let { formula -> JsonString(formula.slug) }.orJsonNull(),
"timeOfDay" to
JsonArray(
realm.timeOfDay.map { band ->
Expand Down Expand Up @@ -3815,6 +3818,7 @@ private class ExternalRuntimeSystemsReader(
camp = requiredObject("camp").readCamp(),
hunt = optional("hunt")?.takeUnless { it is JsonNull }?.asObject("hunt")?.readHunt(),
spellCost = optional("spellCost")?.takeUnless { it is JsonNull }?.asString("spellCost"),
partySight = optional("partySight")?.takeUnless { it is JsonNull }?.asString("partySight"),
timeOfDay =
requiredArray("timeOfDay")
.values
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/kotlin/rylween/dsl/Dsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,9 @@ class FormulaBuilder(
// The spell being cast, for the spell cost formula; the caster's stats are bound above.
val spellBaseCost: IntExpr = v("spell_base_cost")

// The hour of the party's day, 0-23, for party sight.
val hour: IntExpr = v("hour")

// Upkeep and town entry: the party's living members and the gold it
// carries, and the tax rate of the town it enters.
val livingMembers: IntExpr = v("living_members")
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/kotlin/rylween/dsl/DslValidation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fun validateFormulas(formulas: List<FormulaModel>) {
check(formulas.map { it.id }.toSet().size == formulas.size) { "duplicate formula" }
}

/** Validates that the hunt and castle trap chances, the spell cost and the battle arithmetic name authored formulas. */
/** Validates that the hunt and castle trap chances, the spell cost, party sight and the battle arithmetic name authored formulas. */
private fun validateSystemFormulaReferences(content: GameModel) {
val formulaIds = content.formulas.map { it.id }.toSet()
content.realm.hunt?.let { hunt ->
Expand All @@ -336,6 +336,9 @@ private fun validateSystemFormulaReferences(content: GameModel) {
content.realm.spellCost?.let { spellCost ->
check(spellCost in formulaIds) { "realm spell cost references missing formula ${spellCost.slug}" }
}
content.realm.partySight?.let { partySight ->
check(partySight in formulaIds) { "realm party sight references missing formula ${partySight.slug}" }
}
content.realm.upkeep.foodCost?.let { foodCost ->
check(foodCost in formulaIds) { "realm upkeep food cost references missing formula ${foodCost.slug}" }
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/kotlin/rylween/dsl/ItemRealmDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class RealmContentBuilder {
/** What a spell costs its caster, mage spells in battle and priest spells alike; without it a spell costs its base cost. */
var spellCost: FormulaId? = null

/**
* How many squares away a party in the wilderness sees other players' parties on the same map; without it
* parties never see each other.
*/
var partySight: FormulaId? = null

fun baseResourceCapacity(
resource: Resource,
amount: Int,
Expand Down Expand Up @@ -169,6 +175,7 @@ class RealmContentBuilder {
hunt = hunt,
timeOfDay = timeOfDayBands,
spellCost = spellCost,
partySight = partySight,
)
}

Expand Down
1 change: 1 addition & 0 deletions core/src/main/kotlin/rylween/dsl/impl/ContentModelsDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ data class RealmContentModel(
val hunt: HuntRulesModel? = null,
val timeOfDay: List<TimeOfDayBandModel> = defaultTimeOfDayBands(),
val spellCost: FormulaId? = null,
val partySight: FormulaId? = null,
)

/** Authored label for an inclusive hour span in the status line. */
Expand Down
15 changes: 9 additions & 6 deletions docs/dsl-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,11 @@ The system that uses a formula binds its variables: the member it is about
(`weaponSkill`, `weaponDamage`, `hitPoints`, `armorClass`, `level`, `charisma`,
`dexterity`), the monster (`monsterWeaponSkill`, `monsterHitPoints`,
`monsterSpellPower`), the encounter, the party (`firstLevel`, `livingMembers`,
`gold`), a town's `taxPercent`, a shop item's `itemCost`, or a spell's
`spellBaseCost`. `atLeast` and `atMost` clamp a value, `whenValue(condition, a, b)`
picks one, and `random(lo..hi)` draws from the game's own random numbers. A
chance is a percentage the runtime rolls 0-99 against.
`gold`, and the `hour` of its day), a town's `taxPercent`, a shop item's
`itemCost`, or a spell's `spellBaseCost`. `atLeast` and `atMost` clamp a value,
`whenValue(condition, a, b)` picks one, and `random(lo..hi)` draws from the
game's own random numbers. A chance is a percentage the runtime rolls 0-99
against.

This game's rules that are formulas: what a spell costs (`realm { spellCost }`),
a party member's and a monster's chance to hit and damage, a monster's chance to
Expand All @@ -554,7 +555,9 @@ and the hit point range), battle experience and gold, level-up hit points, the
food the party eats (`upkeep { foodCost }`), the town entry tax
(`entryTax { amount }`; a party with less gold than the tax is shown the
`entryTaxShortfall` prompt, with `TownText.taxShortfall`, and stays outside),
shop prices, the hunting and trap-disarm chances, and the haggle bonus. Inside a
shop prices, the hunting and trap-disarm chances, the haggle bonus, and how many
squares away players' parties see each other in the wilderness
(`realm { partySight }`; without it they never do). Inside a
priest spell, `withCurrentCasterCost { caster, cost -> }`
hands over the cost the formula works out; the spell's `baseCost` is declared
once, in its `spell(...)` header.
Expand Down Expand Up @@ -790,7 +793,7 @@ Use this placement rule during design review:

A change to the shape of the `runtimeSystems` rows also bumps
`EXTERNAL_RUNTIME_SYSTEMS_VERSION` in
`core/src/main/kotlin/rylween/compiled/ExternalBundleArtifact.kt` (14 today), so
`core/src/main/kotlin/rylween/compiled/ExternalBundleArtifact.kt` (15 today), so
a runtime refuses a bundle written for another shape.

If a rule mentions Rylween story content, item names, NPCs, mission prose,
Expand Down
18 changes: 12 additions & 6 deletions game/src/main/kotlin/rylween/game/RylweenGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ val authoredRylween: RylweenModel =
realm {
baseResourceCapacity(Resource.Food, 150)
spellCost = Formulas.spellCost
partySight = Formulas.partySight
// Upkeep runs during wilderness turns. These fields control food
// ticking, fatigue labels/drain, mana recovery, and starvation.
upkeep {
Expand All @@ -411,9 +412,9 @@ val authoredRylween: RylweenModel =
line(UpkeepText.memberName, " starved to death!!!")
}
fatigueAt(0, literalText("You begin to feel tired"), statusLabel = "TIRED")
fatigueAt(-4, literalText("You are exhausted!!!"), drain = true, statusLabel = "EXHAUSTED")
fatigueAt(-8, flowText("You begin to feel weak from lack of sleep."), drain = true, statusLabel = "WEAK")
fatigueBelow(-8, flowText("You faint from lack of much-needed sleep."), drain = true, statusLabel = "FAINT")
fatigueAt(-6, literalText("You are exhausted!!!"), drain = true, statusLabel = "EXHAUSTED")
fatigueAt(-12, flowText("You begin to feel weak from lack of sleep."), drain = true, statusLabel = "WEAK")
fatigueBelow(-12, flowText("You faint from lack of much-needed sleep."), drain = true, statusLabel = "FAINT")
}
// Hunt is a reusable ranger action. The fields define chance,
// move cost, food range, target prompts, and result text.
Expand Down Expand Up @@ -450,7 +451,7 @@ val authoredRylween: RylweenModel =
healthGain = 15
foodCostPerMember = 4
hoursAdvanced = 8
hoursRestedReset = 14
hoursRestedReset = 21
temperatureMax = 15
ambushChancePercent = 19
ambushTier = EncounterTiers.weak
Expand Down Expand Up @@ -1217,7 +1218,7 @@ val authoredRylween: RylweenModel =
torches = 5
food = 100
timeLeft = 200
restedHours = 14
restedHours = 21
}
}

Expand Down Expand Up @@ -1365,6 +1366,11 @@ val authoredRylween: RylweenModel =
formula(Formulas.spellCost) {
value = spellBaseCost + level
}
// Players' parties see each other three squares away, and one
// square at night.
formula(Formulas.partySight) {
value = whenValue(hour lt 6, 1, 3)
}
// Battle arithmetic. A chance is a percentage, rolled against
// 0-99. A confused party fights at a third of its weapon skill,
// and a member's own hit points add to the damage they deal.
Expand Down Expand Up @@ -4317,7 +4323,7 @@ val authoredRylween: RylweenModel =
ok = {
writeText("You go to bed... {pause 1s}")
playSound(Sounds.Explore.rest)
party.restedHours set 14
party.restedHours set 21
writeText("Zzzz... {pause}")
writeText(
flowText(
Expand Down
9 changes: 5 additions & 4 deletions game/src/test/kotlin/rylween/RylweenCompiledGameLedgerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ class RylweenCompiledGameLedgerTest {
val externalBundleText = externalBundle.decodeToString()
val runtimeSystems = externalBundle.readExternalRuntimeSystems()

check(runtimeSystems.schemaVersion == 14)
check(runtimeSystems.schemaVersion == 15)
check(runtimeSystems.realm.spellCost == Formulas.spellCost.slug)
check(runtimeSystems.realm.partySight == Formulas.partySight.slug)
check("\"dexterity\"" in externalBundleText)
check(nextDsl.flags.size == 14)
check(nextDsl.authoredFlags.size == 14)
Expand Down Expand Up @@ -158,7 +159,7 @@ class RylweenCompiledGameLedgerTest {
torches = 5,
food = 100,
timeLeft = 200,
restedHours = 14,
restedHours = 21,
),
)
check(characterCreation.races.map { it.race } == listOf(Race.Human, Race.Dwarf, Race.Elf, Race.Halfling))
Expand Down Expand Up @@ -199,7 +200,7 @@ class RylweenCompiledGameLedgerTest {
it.requiredStat == CharacterCreationStat.Dexterity && it.minimum == 50
},
)
check(nextDsl.formulas.size == 22)
check(nextDsl.formulas.size == 23)
check(nextDsl.rewards.size == 1)
check(
nextDsl.rewards
Expand Down Expand Up @@ -1145,7 +1146,7 @@ class RylweenCompiledGameLedgerTest {
check(nextDsl.realm.camp.healthGain == 15)
check(nextDsl.realm.camp.foodCostPerMember == 4)
check(nextDsl.realm.camp.hoursAdvanced == 8)
check(nextDsl.realm.camp.hoursRestedReset == 14)
check(nextDsl.realm.camp.hoursRestedReset == 21)
check(
nextDsl.realm.camp.temperatureBands ==
listOf(
Expand Down
8 changes: 8 additions & 0 deletions runtimes/runtime-bitmap-web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ val installRuntimeBitmapWeb: TaskProvider<Sync> =
}
}

// The name Gradle's application plugin gives this task, for the project's default distribution.
tasks.register("installDist") {
group = "application"
description = "Installs the bitmap web runtime, the project's default distribution. Same as installRuntimeBitmapWeb."

dependsOn(installRuntimeBitmapWeb)
}

val installBitmapSmokeBrowser: TaskProvider<JavaExec> =
tasks.register<JavaExec>("installBitmapSmokeBrowser") {
group = "verification"
Expand Down
Loading
Loading