wip(0.S3): packages and examples migrated in one run - ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:02:45 +03:00
parent d490d4f9f1
commit 3eda72e8c2
172 changed files with 3094 additions and 2966 deletions

View file

@ -23,13 +23,16 @@ event Died { e: int = 0, src: int = 0 }
event Healed { e: int = 0, amount: int = 0 }
event Crit { target: int = 0, src: int = 0 } # the attacker's crit_pct fired
var combat_reflecting: bool = false # thorns never reflect thorns
state GameplayState {
combat_reflecting: bool = false # thorns never reflect thorns
combat_pending: int = 0
fac_tbl: words = null
}
# the mutable channel for lever 6: listeners rewrite the pending damage here.
var combat_pending: int = 0
@Namespace(Combat) function combat_amount() -> int { return combat_pending }
@Namespace(Combat) function combat_set_amount(n: int) -> void { combat_pending = n }
@Namespace(Combat) function combat_amount(gameplay_st: GameplayState) -> int { return gameplay_st.combat_pending }
@Namespace(Combat) function combat_set_amount(gameplay_st: mut GameplayState, n: int) -> void { gameplay_st.combat_pending = n }
# Combat.mitigate(target, raw) — raw minus effective defence, floored at 1 so any
# landed hit chips at least a point (a common, tunable default). A game that wants
@ -43,7 +46,7 @@ var combat_pending: int = 0
# Combat.damage(target, src, amount) — the full pipeline. Returns the damage
# actually applied (0 when vetoed or the target has no Stats/hp).
@Namespace(Combat) function combat_damage(target: int, src: int, amount: int) -> int {
@Namespace(Combat) function combat_damage(gameplay_st: mut GameplayState, target: int, src: int, amount: int) -> int {
let P = World.prop_id("Stats")
if P < 0 { return 0 }
if World.has(target, P) == 0 { return 0 }
@ -54,9 +57,9 @@ var combat_pending: int = 0
var raw = amount * stats_field(src, "damage_pct", 100) / 100
let crit = stats_field(src, "crit_pct", 0)
if (crit > 0) and Random.chance(percent: crit) { raw *= 2; emit Crit(target: target, src: src) }
combat_pending = combat_mitigate(target, raw)
if emit DamageAboutToApply(target: target, src: src, amount: combat_pending) != 0 { return 0 }
var dmg = combat_pending
gameplay_st.combat_pending = combat_mitigate(target, raw)
if emit DamageAboutToApply(target: target, src: src, amount: gameplay_st.combat_pending) != 0 { return 0 }
var dmg = gameplay_st.combat_pending
if dmg < 0 { dmg = 0 }
var hp = World.get(target, P, fhp) - dmg
@ -69,10 +72,10 @@ var combat_pending: int = 0
let leech = stats_field(src, "leech_pct", 0)
if (leech > 0) and Random.chance(percent: leech) { combat_heal(src, stats_field(src, "leech_hp", 1)) }
let thorns = stats_field(target, "thorns", 0)
if (thorns > 0) and (src != target) and (not combat_reflecting) and (World.has(src, P) != 0) {
combat_reflecting = true
combat_damage(src, target, thorns)
combat_reflecting = false
if (thorns > 0) and (src != target) and (not gameplay_st.combat_reflecting) and (World.has(src, P) != 0) {
gameplay_st.combat_reflecting = true
combat_damage(gameplay_st, src, target, thorns)
gameplay_st.combat_reflecting = false
}
}
return dmg

View file

@ -16,26 +16,25 @@ const REL_HOSTILE: int = 2
# relationships stored as (rel + 1); a zero slot means "unset -> use the default".
# A global var initialiser must be a literal, so it is allocated lazily.
var fac_tbl: words = null
function fac_ensure() -> void {
if fac_tbl == null { fac_tbl = words(FAC_MAX * FAC_MAX) }
function fac_ensure(gameplay_st: mut GameplayState) -> void {
if gameplay_st.fac_tbl == null { gameplay_st.fac_tbl = words(FAC_MAX * FAC_MAX) }
}
# Faction.set(a, b, rel) — record a symmetric relationship between two factions.
@Namespace(Faction) function faction_set(a: int, b: int, rel: int) -> void {
fac_ensure()
@Namespace(Faction) function faction_set(gameplay_st: mut GameplayState, a: int, b: int, rel: int) -> void {
fac_ensure(gameplay_st)
if (a < 0) or (a >= FAC_MAX) { return }
if (b < 0) or (b >= FAC_MAX) { return }
fac_tbl[a * FAC_MAX + b] = rel + 1
fac_tbl[b * FAC_MAX + a] = rel + 1
gameplay_st.fac_tbl[a * FAC_MAX + b] = rel + 1
gameplay_st.fac_tbl[b * FAC_MAX + a] = rel + 1
}
# Faction.rel(a, b) — the relationship code (0 friend, 1 neutral, 2 hostile).
@Namespace(Faction) function faction_rel(a: int, b: int) -> int {
fac_ensure()
@Namespace(Faction) function faction_rel(gameplay_st: mut GameplayState, a: int, b: int) -> int {
fac_ensure(gameplay_st)
if (a >= 0) and (a < FAC_MAX) and (b >= 0) and (b < FAC_MAX) {
let v = fac_tbl[a * FAC_MAX + b]
let v = gameplay_st.fac_tbl[a * FAC_MAX + b]
if v != 0 { return v - 1 }
}
if a == b { return REL_FRIEND }
@ -43,12 +42,12 @@ function fac_ensure() -> void {
}
# Faction.hostile(a, b) / Faction.friendly(a, b) — the common yes/no queries.
@Namespace(Faction) function faction_hostile(a: int, b: int) -> int {
if faction_rel(a, b) == REL_HOSTILE { return 1 }
@Namespace(Faction) function faction_hostile(gameplay_st: mut GameplayState, a: int, b: int) -> int {
if faction_rel(gameplay_st, a, b) == REL_HOSTILE { return 1 }
return 0
}
@Namespace(Faction) function faction_friendly(a: int, b: int) -> int {
if faction_rel(a, b) == REL_FRIEND { return 1 }
@Namespace(Faction) function faction_friendly(gameplay_st: mut GameplayState, a: int, b: int) -> int {
if faction_rel(gameplay_st, a, b) == REL_FRIEND { return 1 }
return 0
}
@ -65,6 +64,6 @@ function fac_ensure() -> void {
# Faction.enemies(a, b) — true when the two entities' factions are hostile; the
# one-call test the shooter and AI reach for. Missing factions read as hostile
# (an unaligned hazard hits anyone) unless the ids happen to match.
@Namespace(Faction) function faction_enemies(ea: int, eb: int) -> int {
return faction_hostile(faction_id_of(ea), faction_id_of(eb))
@Namespace(Faction) function faction_enemies(gameplay_st: mut GameplayState, ea: int, eb: int) -> int {
return faction_hostile(gameplay_st, faction_id_of(ea), faction_id_of(eb))
}