feat(game): littleroot town intro with the truck and mom cutscene

This commit is contained in:
Fiereu committed 2026-07-26 14:36:07 +02:00
1 parent 41ff99ae4f
commit 9cda538a68
23 files changed
+389 -92

No files matched your search

@@ -16,6 +16,7 @@ import de.fiereu.openmmo.common.enums.MovementType
import de.fiereu.openmmo.common.enums.Weather
import de.fiereu.openmmo.maps.BgEventDef
import de.fiereu.openmmo.maps.MapDef
import de.fiereu.openmmo.maps.MapFrameScript
import de.fiereu.openmmo.maps.NpcDef
import de.fiereu.openmmo.maps.WarpTile
import de.fiereu.openmmo.maps.WildEncounterSlot
@@ -46,4 +47,5 @@ internal val ${objectName}: MapDef =
npcs = ${RenderUtil.INSTANCE.npcs(map.getVisibleNpcs())},
bgEvents = ${RenderUtil.INSTANCE.bgEvents(map.getBgEvents())},
onTransitionScript = "${map.getOnTransitionScript()}",
onFrameScripts = ${RenderUtil.INSTANCE.frameScripts(map.getOnFrameScripts())},
)
@@ -28,6 +28,14 @@ data class ParsedMap(
val bgEvents: List<ParsedBgEvent>,
// Decomp label of the map's ON_TRANSITION script, or "" when the map has none.
val onTransitionScript: String,
// The map's ON_FRAME table: run the script once its var equals the value, on map entry.
val onFrameScripts: List<ParsedFrameScript>,
)
data class ParsedFrameScript(
val varKey: String,
val value: Int,
val script: String,
)
data class ParsedConnection(
@@ -47,6 +55,7 @@ data class ParsedWarp(
val targetX: Int,
val targetY: Int,
val targetElevation: Int,
val dynamic: Boolean = false,
)
data class ParsedNpc(
@@ -61,6 +70,8 @@ data class ParsedNpc(
val trainerType: Int,
val facing: String,
val script: String,
// Namespaced story flag that hides this npc by default, or "" when it is always shown.
val hideFlag: String,
)
data class ParsedBgEvent(
@@ -193,6 +193,7 @@ class PretGbaParser(
visibleNpcs = parseNpcs(mapJson, mapDirName, ctx),
bgEvents = parseBgEvents(mapJson),
onTransitionScript = parseOnTransitionScript(mapDirName),
onFrameScripts = parseOnFrameScripts(mapDirName),
)
}
@@ -225,9 +226,25 @@ class PretGbaParser(
mapJson["warp_events"]?.jsonArrayOrNull()?.mapNotNull { warp ->
val obj = warp.jsonObject
val destName = obj["dest_map"]?.jsonPrimitive?.contentOrNull ?: return@mapNotNull null
val destAddr = ctx.addresses[destName] ?: return@mapNotNull null
val x = obj["x"]?.jsonPrimitive?.intOrNull ?: 0
val y = obj["y"]?.jsonPrimitive?.intOrNull ?: 0
// A MAP_DYNAMIC warp has no static destination, the runtime resolves it from the player's
// dynamic warp (setdynamicwarp). Emit the tile so it still triggers, with dynamic = true.
if (destName == "MAP_DYNAMIC") {
return@mapNotNull ParsedWarp(
x = x,
y = y,
elevation = ((obj["elevation"]?.jsonPrimitive?.intOrNull ?: 0) - 1).coerceAtLeast(0),
targetRegion = 0,
targetBank = 0,
targetMap = 0,
targetX = 0,
targetY = 0,
targetElevation = 0,
dynamic = true,
)
}
val destAddr = ctx.addresses[destName] ?: return@mapNotNull null
val srcElevation = (obj["elevation"]?.jsonPrimitive?.intOrNull ?: 0)
val destWarpId =
obj["dest_warp_id"]?.jsonPrimitive?.let { it.intOrNull ?: it.content.toIntOrNull() }
@@ -249,15 +266,14 @@ class PretGbaParser(
)
} ?: emptyList()
// Every object event is emitted. A npc hidden by a story flag keeps the flag in hideFlag so the
// server can skip it at spawn and a script can show it later, the always-visible ones get "".
private fun parseNpcs(mapJson: JsonObject, mapDirName: String, ctx: Context): List<ParsedNpc> {
val visibleOverride = region.defaultVisibleNpcs[mapDirName]
return mapJson["object_events"]?.jsonArrayOrNull().orEmpty().mapIndexedNotNull { idx, npcElement
->
return mapJson["object_events"]?.jsonArrayOrNull().orEmpty().mapIndexed { idx, npcElement ->
val npc = npcElement.jsonObject
val isVisible =
if (visibleOverride != null) idx in visibleOverride
else npc["flag"]?.jsonPrimitive?.contentOrNull == "0"
if (!isVisible) return@mapIndexedNotNull null
val flag = npc["flag"]?.jsonPrimitive?.contentOrNull ?: "0"
val shownByDefault = if (visibleOverride != null) idx in visibleOverride else flag == "0"
val gfxName = npc["graphics_id"]?.jsonPrimitive?.contentOrNull ?: "OBJ_EVENT_GFX_BOY_1"
val movementName = npc["movement_type"]?.jsonPrimitive?.contentOrNull ?: "MOVEMENT_TYPE_NONE"
ParsedNpc(
@@ -274,10 +290,41 @@ class PretGbaParser(
else 1,
facing = movementTypes.facingRef(movementName),
script = npc["script"]?.jsonPrimitive?.contentOrNull ?: "0x0",
hideFlag = if (shownByDefault) "" else "${region.name}/$flag",
)
}
}
// Parses the map's ON_FRAME table: each map_script_2 runs its script once the var equals the
// value
// when the player enters the map. Values that are not plain integers (rare) are skipped.
private fun parseOnFrameScripts(mapDirName: String): List<ParsedFrameScript> {
val file = File(rootDir, "data/maps/$mapDirName/scripts.inc")
if (!file.exists()) return emptyList()
val text = file.readText()
val tableLabel =
Regex("""map_script\s+MAP_SCRIPT_ON_FRAME_TABLE\s*,\s*(\w+)""")
.find(text)
?.groupValues
?.get(1) ?: return emptyList()
val block =
Regex("""(?m)^$tableLabel:\s*\n(.*?)(?=\n\s*\.2byte)""", RegexOption.DOT_MATCHES_ALL)
.find(text)
?.groupValues
?.get(1) ?: return emptyList()
val entry = Regex("""map_script_2\s+(\w+)\s*,\s*(\d+)\s*,\s*(\w+)""")
return entry
.findAll(block)
.map {
ParsedFrameScript(
varKey = "${region.name}/${it.groupValues[1]}",
value = it.groupValues[2].toInt(),
script = it.groupValues[3],
)
}
.toList()
}
private fun parseBgEvents(mapJson: JsonObject): List<ParsedBgEvent> =
mapJson["bg_events"]?.jsonArrayOrNull()?.map { be ->
val obj = be.jsonObject
@@ -31,7 +31,8 @@ object RenderUtil {
"WarpTile(x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," +
" targetRegionId = ${it.targetRegion}, targetBankId = ${it.targetBank}," +
" targetMapId = ${it.targetMap}," +
" targetX = ${it.targetX}, targetY = ${it.targetY}, targetElevation = ${it.targetElevation})"
" targetX = ${it.targetX}, targetY = ${it.targetY}, targetElevation = ${it.targetElevation}," +
" dynamic = ${it.dynamic})"
}
}
@@ -42,7 +43,16 @@ object RenderUtil {
" x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," +
" movementType = ${it.movementType}, movementRangeX = ${it.movementRangeX}," +
" movementRangeY = ${it.movementRangeY}, trainerType = ${it.trainerType}," +
" facing = ${it.facing}, script = ${escapeString(it.script)})"
" facing = ${it.facing}, script = ${escapeString(it.script)}," +
" hideFlag = ${escapeString(it.hideFlag)})"
}
}
fun frameScripts(scripts: List<ParsedFrameScript>): String {
if (scripts.isEmpty()) return EMPTY_LIST
return scripts.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
"MapFrameScript(varKey = ${escapeString(it.varKey)}, value = ${it.value}," +
" script = ${escapeString(it.script)})"
}
}
@@ -34,6 +34,8 @@ class MapDef(
val bgEvents: List<BgEventDef> = emptyList(),
/** Decomp label of the script that runs when a player enters this map, or "" if none. */
val onTransitionScript: String = "",
/** Conditional entry scripts: run [MapFrameScript.script] when its var equals its value. */
val onFrameScripts: List<MapFrameScript> = emptyList(),
private val blockData: String = "",
private val behaviorData: String = "",
) {
@@ -48,6 +50,13 @@ class MapDef(
wildEncounters.firstOrNull { it.method == method }
}
/** One ON_FRAME entry: run [script] when the story var [varKey] currently equals [value]. */
data class MapFrameScript(
val varKey: String,
val value: Int,
val script: String,
)
private fun decodeBlockData(blockData: String, behaviorData: String): List<Tile2D> {
if (blockData.isEmpty()) return emptyList()
val bytes = Base64.getDecoder().decode(blockData)
@@ -15,4 +15,6 @@ data class NpcDef(
val trainerType: Int,
val facing: Direction,
val script: String = "0x0",
/** Story flag that hides this npc by default, or "" when it is always shown. */
val hideFlag: String = "",
)
@@ -13,4 +13,12 @@ data class WarpTile(
val targetY: Int,
val targetElevation: Int = 0,
val facingDirection: Direction? = null,
/** Direction the player faces after this warp, or null to infer it. */
val exitFacing: Direction? = null,
/**
* A MAP_DYNAMIC warp whose destination is not baked in but set at runtime (the decomp
* setdynamicwarp). The target fields are placeholders, the real destination comes from the
* player's stored dynamic warp when they step on it.
*/
val dynamic: Boolean = false,
)