# R3 Base building research (walls, floors, doors on wilderness world-map tiles) Board item R3 (owner, 2026-10-06). Research only: nothing in the mod was changed. Options are PROPOSED, one recommendation each; the owner settles them before design. Path short forms: `F/` = `LonaRPG/Data/Scripts/Frames/`, `E/` = `LonaRPG/Data/Scripts/Editables/`, `HCG/` = `LonaRPG/Data/HCGframes/`, `LC/` = `ModScripts/_Mods/LonaCraft/Scripts/`, `CS/` = `ModScripts/_Mods/Campsites/Scripts/`. Map facts were read from the `.rvdata2` files with the scratchpad tools (`r3/regmaps.py`, `r3/tilesets.py`, `tools/home_evdump.py`). ## 0. Summary | Question | Finding | PROPOSED | |---|---|---| | Where is "a base on a wilderness tile"? | Entering a tile loads a random map of that region each time (`E/34_Functions_ChangeMap.rb:263`); field maps are small (522-992 passable tiles, plains are a 25 x 25 square; forests are corridors) | Base = the mod's own base map per biome family, entered from the overmap tile and keyed by that tile (option B) | | Walls with autotiling | Map tiles can be rewritten at runtime (Homes already does it, `LC/100_Homes.rb:1187-1204`); every wilderness tileset has 32 A3 and 24 A4 wall kinds | Walls are TILES: A4 top + face (building look), A3 kind as the cheap "palisade" | | Floors | Layer-0 swap to an A5 tile, no autotile needed | Tiles | | Doors | Game doors are 2-page events toggled by `doorEV_setup` (`E/29_Functions_417_Interpreter.rb:943-961`) | Placed door = the same 2-page event, built like a furniture piece | | Persistence | Furniture records are per map number (`LC/90_Furniture.rb:745-768`) | One record per base in `$game_system.lonacraft_data["bases"]`, tiles as a grid string (596 B for 20 x 20 against 33,403 B as furniture-style records) | | Build size | | 8 build items in 4 phases, about 1,000-1,200 Ruby lines + 11 generated maps | ## 1. World map model ### 1.1 How a wilderness tile becomes a field map | Step | Evidence | |---|---| | OvermapMain is Map002, note `isOverMap=true`, 170 x 150 tiles, 168 events | Map002 note; `F/31_Game_Map.rb:285-303` reads `isOverMap` from the note, makes the player transparent and the map turn-based | | Each overmap tile has a region id (layer 3 >> 8); 4,709 of 25,500 tiles have one (ids 1-32), 20,791 are region 0 | `F/31_Game_Map.rb:880-882`; Map002 count | | The action key on an overmap tile reserves the region event | `F/35_Game_Player.rb:604-620` (`check_region_event`, only when `isOverMap`) -> `F/10_Game_Temp.rb:107-109` -> `E/22_GMI_CommonEvents.rb:41-48` | | Region menu: Cancel / Relax / Observe / Remove tracks / Enter / Kyaaah | `E/33_Functions_OverMapEvents.rb:27-132` | | "Enter" calls `change_map_enter_region` | `E/33_Functions_OverMapEvents.rb:106`, `:132` | | The map is picked AT RANDOM from all maps whose note has `region=`, on every entry | `E/34_Functions_ChangeMap.rb:257-269` (`$data_region_maps[$game_player.region_id].sample`), list built at boot in `F/5_DataManager.rb:351-388` | | Way back: overmap id and LastOverMapX/Y | `E/34_Functions_ChangeMap.rb:259-260`, `:271-289` | | The field map is reloaded from disk at every setup, so nothing on it persists | `F/31_Game_Map.rb:172` | | Its events are rolled again on every entry: BIOS spawns resources and wildlife on in-map region ids while `ReRollHalfEvents` = 1 | Map028 event 1 (BIOS); `E/34_Functions_ChangeMap.rb:138` sets it, `:114` clears it | | 30 callers of `change_map_enter_region` (region menu, encounters, out-of-stamina nap on the overmap) | grep; Map002 event 9 (NapEvent: `sta <= -100` -> `change_map_enter_region`) | So the same overmap tile does NOT give the same map: PlainField (region 1) picks one of Map016, 026, 028. ### 1.2 Field map families (wilderness and towns) | Region (overmap name) | Field maps | Tileset | Passable tiles (measured) | |---|---|---|---| | 1 Plainfield | 16, 26, 28 | 14 RMDLC OUTA | 625 each (25 x 25 open square, x 36-60, y 31-55 on Map028) | | 11 Road | 32, 33, 34 | 14 | 612 (34) | | 23 Highway | 51, 54, 55 | 14 | 625 (51) | | 12 Rudesind Slope | 83 | 14 | - | | 2 / 27 Shore | 27, 147, 149 | 4 RMDLC ACJbeach | 764 (27) | | 5 Pine Forest | 13, 30, 124 | 10 Exterior417a1 | 587 (30) | | 7 Mountain | 37 / 184 | 28 / 45 Mountain,Poor | 1,063 (37) | | 8/25 Swamp, 13/24 Swamp Trail, 15/26 Marsh | 19, 163 / 101, 102 / 108, 125 | 32 Exterior417 swAMP | 522 (19) | | 4 Rain Forest | 29, 80, 93 | 18 Mack-badlandOUTA | 525 (29, all in narrow paths) | | 3 Infested Mountain | 39 | 29 AbomMountain | 879 | | 6 Dead Forest | 21, 127 | 39 badlandTerrian | 522 (21) | | 14 Wasteland, 16 Infested Creep, 28 Infected Terrain | 107, 112 / 131, 134 / 160, 161 | 17 Mack-badlandINSA | 3,431 (107) | | 19 Polluted Land | 111, 159 | 40 badlandTown | 992 (111) | | 9 Abandoned House | 45 / 47 | 23 / 13 | - | | 20 Refugee Camp | 35 | 13 Interior-poora | - | | Towns and ruins: 10 Slums, 17 Blighted Road, 18 Infected City Ruins, 21 Town of Noer, 22 Streets of Noer, 29/30 Fortress Ruins, 31/32 Sybaris | 17, 170 / 145, 146 / 150 / 4, 5, 7 / 48, 56, 57 / 191, 192 / 200, 201 | 42, 40, 23, 34, 15 | - | Region names: `LonaRPG/Text/ENG/OvermapEvents.txt:160-256`. Every playable tile of Map028 has a spawn region (3, 4, 7, 9-12) and the ring around it is region 1 (exit trigger, Map028 event 4 `set_region_trigger(1)` -> `change_map_region_map_exit`, `E/34_Functions_ChangeMap.rb:377-401`). Renders: `scratchpad/r3/plainfield1_play.png`, `scratchpad/r3/rainforest1_small.png`. ### 1.3 Sleeping and camping today | Where | What runs | Evidence | |---|---|---| | Overmap, "Relax" | heal from satiety only, no map change | `E/33_Functions_OverMapEvents.rb` Relax branch; `E/100_Game_Player_handle_on_move.rb:135-142` | | Overmap, nap | Map002 event 9 NapEvent: `handleNap` on the overmap, or forced into a random field map when stamina <= -100 | Map002 event 9 | | Field map, nap | Map's NapEvent (Map028 event 32) -> `region_map_wildness_nap` -> maybe a raid (`region_map_wildness_nap_stats`, loads `HCG/encounter/`) -> `handleNap` | `HCG/Command_Nap.rb:10`, `F/31_Game_Map.rb:1299-1308`, `E/34_Functions_RegionMap.rb:237-246`, `:1645-1840` | | Any nap | `$game_map.setup(map_id)` again (tile data reloaded), live events kept only if `nappable`, spriteset re-created | `F/Game_InterpreterModifies/Game_Interpreter_Modifies_OM.rb:12-47`, `F/31_Game_Map.rb:359-372` | ### 1.4 What Campsites does (closest prior art) | Point | Campsites | Evidence | |---|---|---| | Loaded? | No: `Banned = 1` | `UserData/GameMods.ini` | | Record per camp | `{id, map_id, x, y, region_id, biome, camp_tag, icon_event, raid_event, expire_segment}` in `$game_system.campsites_list` (the OVERMAP tile) | `CS/10_Campsites.rb:203-225`, `:291-303` | | Biome | overmap region id -> name table, towns included (21, 22, 31, 32) | `CS/10_Campsites.rb:25-58`, `:129-131` | | City vs wilderness | not checked. `can_setup_here?` needs `isOverMap` and a random tag map; OvermapMain's note has no `event=` tag, so the option never shows on Map002 | `CS/10_Campsites.rb:149-175`, Map002 note `isOverMap=true` | | Inside of a camp | one fixed tag map per biome via `change_map_enter_tag`; the 21 `Camp_*.rvdata2` maps and `CampEvents.rvdata2` named in `mod.cfg` are not in the mod folder | `CS/10_Campsites.rb:240-244`, `:263-288`; `Campsites/mod.cfg` | | Overmap marker | an EventLib event re-summoned at every overmap setup | `CS/10_Campsites.rb:184-193`, `:305-317` | | Expiry / raids | expires after PERSIST_DAYS x 2 nap segments; raid roll in an alias of `process_nap_change` | `CS/10_Campsites.rb:69-71`, `:235-255`, `:319-346` | | Menu | replaces the whole `overmap_event_EnterMap` | `CS/10_Campsites.rb:348-482` | Nothing built inside a camp persists; only the overmap record does. The useful parts are the overmap key (map id + x + y) and the icon re-summon. ### 1.5 What "base on a wilderness tile" can mean (PROPOSED) | Option | How | For | Against | |---|---|---|---| | A. Pin the game's field map | Base record keeps the field map number picked on the first visit; a per-base runtime map number points at that game file, so entering that tile always loads it | no map authoring; real biome, BIOS weather, gathering | space: 25 x 25 on plains, corridors in forests (1.2); BIOS spawns land inside the base unless region filtering (6); StartPoint and the exit ring must stay free; a game update that edits the map moves terrain under the base | | B. The mod's own base map per biome family | A generated template map per tileset family (about 11), e.g. 40 x 40 open ground of that biome with the exit ring, a BIOS (biome weather) and a NapEvent; one runtime map number per base slot, all pointing at the template file | room to build; no clash with game events; own NapEvent = clean raid hook; immune to game map edits | 11 maps to generate (one script, as `home_build_stonehouse.py`); less "the field Lona saw" | | C. On the overmap tile itself | Write tiles into Map002 | none | 1 overmap tile = a whole region; overmap is turn-based with the player hidden (`F/31_Game_Map.rb:292-296`) | Recommendation: **B**. Key the base by the overmap tile like Campsites (Map002 id, x, y), allow it only on a wilderness region whitelist (PROPOSED: 1-8, 13-16, 19, 24-28; owner to decide roads 11, 23 and Abandoned House 9 / Refugee Camp 20), and enter it with an "Enter base" line in the region menu plus an alias of `change_map_enter_region` (`E/34_Functions_ChangeMap.rb:257-269`) that sends Lona to the base when she enters that tile any other way (encounters, out-of-stamina nap). A is the fallback for plains/roads only. Per-base runtime map number: `$data_mapinfos[]` with its own `.id` and `.filename` = the template (or, for A, `Data/MapNNN.rvdata2`), exactly as Homes registers its houses (`LC/100_Homes.rb:546-576`, setup key fix `:580-590`); `Game_Map#setup` only reads `$data_mapinfos[map_id].filename` (`F/31_Game_Map.rb:170-172`). Distinct map numbers per base keep the furniture code working unchanged (its records are per map number, `LC/90_Furniture.rb:745-751`). ## 2. Walls with autotiling ### 2.1 Can a mod change tiles at runtime? | Point | Evidence | |---|---| | Tile data is `@map.data` (a Table, 4 layers: 0-2 tiles, 3 = shadow + region) and is freshly loaded at each setup | `F/31_Game_Map.rb:172`, `:524-526`, `:880-882` | | Writes before the events are built: `setup_event_hack` runs after load, before `setup_region_map` and `setup_events` | `F/31_Game_Map.rb:193`, `:199`, `:205`, `:223-225` | | LonaCraft already writes tiles there: `lonacraft_apply_tile_overrides` and the floor fill of owned rooms | `LC/100_Homes.rb:1187-1204`, `:1252-1259`, hook `:1285-1304` | | Passability reads the live tiles: `check_passage` over `layered_tiles` with the tileset flags | `F/31_Game_Map.rb:734-756`, `:773-776` | | Pathfinding reads the same `check_passage` | `F/202_pathfinding.rb:399-410`, `:465-475` | | Drawing: `update_tilemap` assigns `$game_map.data` to the tilemap every frame | `F/49_Spriteset_Map.rb:322-328` | | Engine is stock RGSS3 (`System\RGSS301.dll`) | `LonaRPG/Game.ini` | | A nap re-runs setup and re-creates the spriteset | `F/Game_InterpreterModifies/Game_Interpreter_Modifies_OM.rb:24`, `:37-38` | | The live map (with written tiles) is saved inside `$game_map` and not reloaded on load unless the game version changed | `F/5_DataManager.rb:939`, `:964`, `:994-1000` | UNVERIFIED (no agent runs the game): that an in-place write shows on the next frame. VX Ace's Tilemap is known to redraw from the Table it holds, but the first build item must prove it; the fallback is the nap's own `SceneManager.scene.dispose_spriteset; create_spriteset` (`Game_Interpreter_Modifies_OM.rb:37-38`), a short hitch per placed piece. Tiles written in `setup_event_hack` need no redraw at all. ### 2.2 Wall and floor sheets in the wilderness tilesets | Tileset | Maps (region) | A3 sheet | A4 sheet | A5 sheet | A4 used by the maps | |---|---|---|---|---|---| | 14 | 1, 11, 23, 12 | TileA3 | TileA4 (stone, wood, timber, plaster, brick, log walls) | TileA5_exterior1 | none (Map083: 9 kinds) | | 4 | 2/27 | TileA3 | Village&town A4 Cliffs_And_Mines (cliffs and mine walls only) | TileA5_exterior1 | 113-116, 122 | | 10, 28, 45, 32 | 5, 7, 8/25, 13/24, 15/26 | Outside_POOR_A3 | Outside_POOR_A4 (stone, brick, wood walls; cliffs 112-127) | Outside_POOR_A5 | 112, 113, 117, 120-125 (cliffs) | | 18 | 4 | macks_A3 | macks_A4 (brick, plank, timber, plaster walls 96-111) | macks_A5 | none | | 17, 29, 39 | 14, 16, 28 / 3 / 6 | macks_A3 / TileA3 (39) | macks417_badland_A4 (same wall rows as macks_A4) | macks_A5 / TileA5_exterior3 (39) | 113, 114, 120 (29), 82 (39) | | 40 | 19 | TileA3Abom | macks417_AbomTown_A4 (stone, wood walls 96-111) | TileA5_exterior1 | none (Map111) | | 13 | 20, 9 (Map047) | Outside_POOR_A3 | Inside_POOR_A4 (indoor walls) | Inside_POOR_A5 | 83, 84, 92 | Labelled sheets: `scratchpad/r3/a4_field_1.png`, `a4_field_2.png`, `a3_field.png`, `a5_field.png`. Flags (checked on tilesets 4, 10, 14, 17, 18, 28, 29, 32, 39, 40): | Tile group | Passable | Terrain tag | Meaning | |---|---|---|---| | A3, all 32 kinds (48-79) | X in all 10 | 4 in all 10 | wall pieces block movement, sight (`F/Modules/Sensors.rb:161-171`) and projectiles (`F/33_Game_CharacterBase.rb:225-234`) for free | | A4 tops, even rows (80-87, 96-103, 112-119) | O (walkable) in all 10 | 4 in most; 0 on a few kinds (e.g. tileset 29 kinds 96-103) | tops must be made impassable by the mod (2.4) | | A4 faces, odd rows (88-95, 104-111, 120-127) | X in all 10 | 4 in most | face blocks for free | | A5 | O in 14, 4, 17, 18, 29, 39, 40; mixed O / X / directional in 10, 28, 32 | | floor ids must come from the O cells | No tileset swap and no new sheet is needed: every family has building-wall kinds. Only Shore (4) lacks A4 building walls (its A4 is cliffs), so Shore uses A3 walls. Adding a custom sheet would mean a cloned `RPG::Tileset` with one `tileset_names` slot replaced (`Cache.tileset` prepends `Graphics/Tilesets/`, `F/4_Cache.rb:71-73`; the "../../" mod-path trick of `LC/90_Furniture.rb:15-23` works the same) and a runtime tileset id that exists before a save loads; not needed for phase 1-3. ### 2.3 Autotile shape formulas (PROPOSED code, checked against `tools/home_render.py:28-42`) Tile id = `2048 + kind * 48 + shape`. `same[d]` = the neighbour in direction d is the same kind (PROPOSED: off-map counts as same, as the editor does). Wall type, 16 shapes (all A3 kinds, A4 odd rows): ```ruby def wall_shape(same) # bit set = edge drawn on that side (same[:w] ? 0 : 1) | (same[:n] ? 0 : 2) | (same[:e] ? 0 : 4) | (same[:s] ? 0 : 8) end ``` Ground / ceiling type, 47 shapes (A2, A4 even rows): ```ruby def ground_shape(same) n, s, w, e = same[:n], same[:s], same[:w], same[:e] c = lambda{|a, b, d| a && b && !same[d] } # inner corner: both sides same, diagonal not case [!w, !n, !e, !s] # edges drawn: west, north, east, south when [false, false, false, false] (c[n, w, :nw] ? 1 : 0) | (c[n, e, :ne] ? 2 : 0) | (c[s, e, :se] ? 4 : 0) | (c[s, w, :sw] ? 8 : 0) when [true, false, false, false] then 16 + (c[n, e, :ne] ? 1 : 0) + (c[s, e, :se] ? 2 : 0) when [false, true, false, false] then 20 + (c[s, e, :se] ? 1 : 0) + (c[s, w, :sw] ? 2 : 0) when [false, false, true, false] then 24 + (c[s, w, :sw] ? 1 : 0) + (c[n, w, :nw] ? 2 : 0) when [false, false, false, true ] then 28 + (c[n, w, :nw] ? 1 : 0) + (c[n, e, :ne] ? 2 : 0) when [true, false, true, false] then 32 when [false, true, false, true ] then 33 when [true, true, false, false] then 34 + (c[s, e, :se] ? 1 : 0) when [false, true, true, false] then 36 + (c[s, w, :sw] ? 1 : 0) when [false, false, true, true ] then 38 + (c[n, w, :nw] ? 1 : 0) when [true, false, false, true ] then 40 + (c[n, e, :ne] ? 1 : 0) when [true, true, true, false] then 42 when [true, true, false, true ] then 43 when [true, false, true, true ] then 44 when [false, true, true, true ] then 45 else 46 end end ``` Placing or removing one wall tile changes at most its 8 neighbours' shapes (9 tiles for the 47-shape top, 5 for the 16-shape face); recompute those only. Building look with A4 (as the game's own buildings and the Stone House builder `scratchpad/tools/home_build_stonehouse.py`): wall tiles W get the TOP kind with `ground_shape` over W; every tile directly south of a W tile that is not itself W (and not a door) gets the FACE kind with `wall_shape` over that face set. Mock-up written with exactly these formulas (`scratchpad/r3/mockup.py`), TileA4 top 97 / face 105 on the left, TileA3 log kind 76 on the right, A5 1609 floor, game door sprite: `scratchpad/r3/base_mockup_plainfield.png`. ### 2.4 Walls as tiles vs walls as events | | Tiles (PROPOSED) | Events with a wall sprite sheet | |---|---|---| | Look | the game's own wall art, same as its buildings; A4 gives top + face, A3 a one-tile strip | needs a 16-piece (or 47-piece) sheet drawn per wall style; events draw above tiles, can look pasted on | | Autotile correctness | the engine draws the shape from the tile id; the mod computes the id (2.3) | the mod picks the piece the same way; mistakes are visible the same way | | Passability | A3 and A4 faces: from the flags. A4 tops: walkable, so an alias of `Game_Map#check_passage` (`F/31_Game_Map.rb:734`) returns false for the base's wall tiles from a per-map Hash; that one alias covers walking (`:773-776`) and pathfinding (`F/202_pathfinding.rb:406-409`, `:465-468`). `@forced_block_dir` (`F/31_Game_Map.rb:56`, `:134`, `:777-779`) is NOT enough: pathfinding skips it and it is a linear Array | one non-through event per tile, as furniture blockers (`LC/90_Furniture.rb:608-632`); pathfinding sees them (`F/202_pathfinding.rb:399-404`) | | Sight / projectiles | terrain tag 4 from the flags (2.2) | needs `ev_terrain_tag` 4 per event (`F/31_Game_Map.rb:858-877`) | | Save size, 20 x 20 base (76 walls) | in the base record (5) | 76 furniture-style records + 76 live events in the saved map | | Events on the map | 0 | 76 walls, 400 with floors; the busiest game map has 207 (Map121), PlainField has 6 | | NPC pathing, fog, lighting | as any game wall; KHAS shadows are off (`E/50_System_Settings.rb:132`) and editor shadows are cleared at setup (`E/50_System_Settings.rb:131`, `F/RVscript/460_KHAS_LightLib.rb:1866-1880`) | events are characters: NPCs collide, sprites sort by y | | Nap / reload | rewritten in `setup_event_hack` at every setup and nap | events must stay `nappable` (`F/31_Game_Map.rb:359-366`) | Recommendation: **tiles**. A3 (one kind, no passability work) for the first build; A4 top + face with the `check_passage` alias as the "building wall". ## 3. Floors | | Layer-0 tile swap (PROPOSED) | Event | |---|---|---| | How | layer 0 = an A5 floor id; layers 1-2 cleared on that tile | walkable event (`LC/90_Furniture.rb:571-573` style, priority below characters) | | Autotile | A5 has none; grass/dirt A2 neighbours keep their shapes (small seam) unless recomputed with `ground_shape` | none | | Passability | must pick an O-flag A5 id (2.2) | through | | Cost | 0 events, 1 char per cell in the record | 324 events for an 18 x 18 floor | | Limit | building only where layer 2 is empty (Map028's playable area has 0 layer-2 tiles; forests have trees) | same | Recommendation: **tile swap**. Candidates per family to be picked by the owner from `scratchpad/r3/a5_field.png` (1609 = wood planks on TileA5_exterior1, used in the mock-up). ## 4. Doors ### 4.1 The game's doors (NoerTavern, Map059) | Point | Evidence | |---|---| | 6 doors named `WoodenDoorSide4`, sprite `!Door4` (cells 32 x 96: 384 x 768 sheet) | Map059 events 49, 54, 55, 60, 61, 62 | | Page 1 = OPEN: through ON, priority "same as characters", action button | Map059 event 49 page 1 | | Page 2 = CLOSED: through OFF, same priority, action button | Map059 event 49 page 2 | | Starts closed: init block `init_jump_page(2, tag)` (tag 1 side door, 4 front door) | `F/39_Game_Event.rb:1997-2002` | | Action key: `doorEV_setup(id, page, tag, sound)` plays openDoor / closeDoor and forces the other page + terrain tag; refuses to close while a living NPC stands in the doorway | `E/29_Functions_417_Interpreter.rb:943-961`, `:1082-1086` | | Animation: none, a page swap (sprite pattern changes) | Map059 pages | | Closed tag 4 blocks sight and projectiles | `F/31_Game_Map.rb:858-877`, `F/Modules/Sensors.rb:161-171` | Render: `scratchpad/r3/tavern_doors.png`, sheet `scratchpad/r3/door4_sheet.png`. ### 4.2 A placed door (PROPOSED) | Point | How | |---|---| | Event | built at runtime like `LC/90_Furniture.rb:542-606`, with the two pages above and `doorEV_setup(get_character(0).id, ...)` in each page (works on summoned events: it only uses `$game_map.events[id]`) | | Tile under it | a floor tile; the door tile is not in the wall set, so no face is drawn under it (mock-up) | | Lona | opens with the action key, walks through (page 1 through ON), closes it from either side | | NPCs and companions | no NPC ever opens a door (only the player's action key starts it, `F/35_Game_Player.rb:604-614`); a closed door blocks them (`collide_with_characters`, and pathfinding `F/202_pathfinding.rb:399-404`). Companions wait outside a closed door, as in towns | | State | closed at every setup (init block); PROPOSED keep it that way (an open door after a nap is the raid follow-up's question) | | Injection | added to `@map.events` in `setup_event_hack`, as the home doors (`LC/100_Homes.rb:1262-1283`), so a nap rebuilds it the same way | ## 5. Persistence (PROPOSED) Where: `$game_system.lonacraft_data["bases"]` (plain types, no save hook, as furniture `LC/90_Furniture.rb:475-509` and homes `LC/100_Homes.rb:71-73`). ```ruby lonacraft_data["bases"] = { "next" => 2, "list" => [{ "id" => 1, "om" => [2, 88, 61], # overmap map id, x, y (the owner's "the tile") "region" => 1, # overmap region at creation "family" => "plain", # template / tile table row "slot" => 1, # runtime map number = BASE_MAP_ID + slot "ox" => 5, "oy" => 5, "w" => 40, "h" => 40, "rows" => ["....WWWWWW....", ...], # one char per cell: "." untouched, "W"/"w" wall kinds, "F"/"f" floor kinds "doors" => [[12, 9, "Door_Wood"]] }] } ``` | Format, 20 x 20 base (76 walls, 323 floor, 1 door), Ruby Marshal | Bytes | |---|---| | furniture-style record per piece (`{"uid","map_id","x","y","item_name"}`) | 33,403 | | per-base `[x, y, kind]` list | 3,262 | | per-base grid string (PROPOSED) | 596 | | a current save, for scale (`UserData/SavAuto*.rvdata2`) | 1,132,145-1,284,524 | Rebuild: alias `setup_event_hack` (`F/31_Game_Map.rb:193`): when the map number is a base slot, write walls (top + face), floors and their shapes into `@map.data`, fill the wall Hash for `check_passage`, inject door events; furniture inside the base keeps working through `LC/90_Furniture.rb:899-911` because each base has its own map number. Overmap marker: an event re-added at every Map002 setup, as `CS/10_Campsites.rb:184-193` / `:305-317`. This is Campsites' model (overmap tile record + re-summon) with the inside kept as well. ## 6. Engine limits for this | Limit | Fact | PROPOSED handling | |---|---|---| | Random field map per entry | `E/34_Functions_ChangeMap.rb:263` | base map number per slot; alias `change_map_enter_region` for the base tile | | Field maps reloaded each setup | `F/31_Game_Map.rb:172` | rebuild from the record in `setup_event_hack` | | Small field maps | 522-992 passable tiles; plains 25 x 25 (1.2) | option B (40 x 40 template) | | Spawns inside the base | BIOS / encounters place events at `region_map[id].sample` (Map028 event 1; `E/34_Functions_RegionMap.rb:361-1100`); `region_map` is built from layer 3 after `setup_event_hack` (`F/31_Game_Map.rb:199`, `:270-281`) | B: template paints spawn regions only outside the build area. A: drop base cells from `@region_map` after `setup_region_map`, never emptying a region (BIOS does `region_map[11].sample[0]` and would crash on nil) | | NPC pathing | tiles: through `check_passage` (2.4); doors: event collision | as 2.4 / 4.2 | | Enemies through walls | no destructible tiles or door-breaking in the game | raid follow-up R4 (new AI) | | Map events | no hard cap (new id = max + 1, `LC/90_Furniture.rb:787-799`); every event costs update + sprite each frame | tiles: only doors and furniture are events | | Fog / lighting | KHAS fog is a screen overlay (`F/RVscript/480_KHAS_Fog.rb:398-420`); shadows off (`E/50_System_Settings.rb:132`) | nothing to do | | Live redraw | UNVERIFIED (2.1) | proven in build item B2; fallback spriteset re-create | | Nap on the base | field NapEvent -> `region_map_wildness_nap` (1.3) | B: template's own NapEvent (raid hook for R4) | | Saved live map | `$game_map` incl. written tiles is in the save (`F/5_DataManager.rb:939`) | consistent; nothing extra | ## 7. Build plan (PROPOSED) | Phase | Item | What | Files | Lines (rough) | |---|---|---|---|---| | 1 minimum | B1 Base record and entry | wilderness whitelist, "Build a base here" / "Enter base" in the region menu (append, not replace, unlike Campsites), `change_map_enter_region` alias, slot map numbers, setup key, PlainField template map (generated) | new `LC/110_Bases.rb`, `loader.rb`, `Maps/LonaCraftBase_Plain.rvdata2`, `Text/*/Bases.txt` (6 languages) | 220 + map | | | B2 Wall + floor tiles | one A3 wall kind and one A5 floor as items + recipes; placement cursor reusing the furniture ghost loop; tile write + neighbour shapes; live-redraw proof with fallback; rebuild in `setup_event_hack` | `110_Bases.rb`, `90_Furniture.rb` (route tile kinds, ~30), `Item/`, `Recipes/` (2 + 2 JSON), texts | 280 | | | B3 Door | 2-page door event with `doorEV_setup`, record, injection, item + recipe | `110_Bases.rb`, `Item/`, `Recipes/`, texts | 110 | | 2 building | B4 A4 building walls | top + face kinds, `check_passage` alias, per-family kind table | `110_Bases.rb` | 150 | | | B5 Remove and furniture | pick up a wall / floor / door (refund, shapes recomputed), furniture allowed inside a base (`Furniture.map_allowed?`) | `110_Bases.rb`, `90_Furniture.rb` (~15) | 90 | | 3 all biomes | B6 Templates for the other 10 families | generator script + 10 maps, tile table (A3 / A4 / A5 ids per family) | `Maps/LonaCraftBase_*.rvdata2`, `110_Bases.rb` | 60 + maps | | | B7 Overmap marker and limits | marker event on Map002, max bases, base list | `110_Bases.rb`, texts | 70 | | 4 follow-up | B8 Raids (board R4) | base NapEvent rolls a raid, enemies spawn on the exit ring, doors / walls as obstacles; new AI to break doors | `110_Bases.rb`, template NapEvent | owner research first | Raid hooks for R4: the field map NapEvent (Map028 event 32) -> `HCG/Command_Nap.rb:10` -> `F/31_Game_Map.rb:1305-1308` -> `region_map_wildness_nap` (`E/34_Functions_RegionMap.rb:1645`) -> `region_map_wildness_nap_stats` (`:237-246`) -> encounter script (`:232`); Campsites' place for its raid roll: `process_nap_change` alias (`CS/10_Campsites.rb:319-346`). With option B the base template carries its own NapEvent, so the raid code is the mod's, not a patch of the game's. ## 8. Choices for the owner (design phase) | # | Choice | PROPOSED | |---|---|---| | 1 | Base location: A pinned field map / B own template / C overmap | B | | 2 | Which overmap regions count as wilderness | 1-8, 13-16, 19, 24-28; roads 11 / 23, Abandoned House 9, Refugee Camp 20 open | | 3 | Wall look: A3 palisade, A4 building wall, both | both (A3 in phase 1, A4 in phase 2) | | 4 | Template size and buildable area | 40 x 40 map, 30 x 30 buildable | | 5 | Max bases | 3 (Campsites' default, `Campsites/mod.cfg`) | | 6 | Costs (materials per wall / floor / door) | from existing LonaCraft materials, set in the recipe JSONs | | 7 | Doors after a nap | closed | ## 9. Design for the owner's decisions (2026-10-06) Binding owner decisions: option A, pinned only while buildings stand; a marker on Map002 in phase 1; the game's own resource respawn kept; allowed tiles by rule; A3 palisade first, A4 later; "Destroy all bases" on the System page; raids stay research. B1 is built (9.8); this section is its spec. ### 9.1 Record schema (`$game_system.lonacraft_data["bases"]`, plain types) ```ruby lonacraft_data["bases"] = { "next_id" => 3, "list" => [{ "id" => 2, "om" => [2, 47, 92], # overmap map number, tile x, y (the owner's "the tile") "region" => 1, # overmap region id of that tile "field" => 28, # the $data_region_maps entry picked on that visit: a game map # number, or a mod map key (RolePlayS adds file-path keys, # RolePlayS/Scripts/0_CORE.rb:147-156) "key" => "LonaCraftBase_2", # $data_mapinfos key of the pinned map "map_no" => 9202, # its runtime map number ($game_map.map_id there; furniture keys by it) "pieces" => {"40,38" => "debug"}, # "x,y" => kind; B2/B3 put walls, floors, doors here "made" => 1234 # $game_date.dateAmt }], "maps" => {"LonaCraftBase_2" => [9202, 28]}, # runtime map registry (kept while a save can stand on it) "entry" => {"om" => [2, 47, 92], "region" => 1, "event" => 0, "to" => 28, "base" => nil} } ``` `entry` = the last region entry (written on the overmap, cleared at the next overmap setup). A base can only be created on the map named in `entry["to"]`, so the record knows its tile without reading the overmap again. ### 9.2 Pin and revert | Rule | How | Evidence | |---|---|---| | Every way into a field map goes through one function | `change_map_enter_region` is the only reader of `$data_region_maps`. Callers: region menu Enter, 27 encounter scripts, the pregnancy-pain overmap event, Map002 NapEvent (out of stamina), Map211 | `E/34_Functions_ChangeMap.rb:257-269`; `E/33_Functions_OverMapEvents.rb:132`; `E/40_OverEvent_Check.rb:351`; grep of `Data/HCGframes/encounter/` and `Data/Map*.rvdata2` | | Pin | alias in `GIM_ADDON` (included in Game_Interpreter, `F/40_Game_Interpreter.rb:19`). On the overmap, `$data_region_maps[region]` is set to `[pick]` for the call and restored after: `pick` = the base's key when a record holds Lona's tile, else one `sample` of the list (so the entry knows `to`) | the original's own `.sample` then returns `pick` (`:263`) | | Pinned map | `$data_mapinfos[key]` = new MapInfo: `.filename` = the field map's file, `.name` = the field map's name, `.id` = `map_no`. `Game_Map#setup` only reads those | `F/31_Game_Map.rb:169-172`; Homes does the same (`LC/100_Homes.rb:546-576`) | | Numbers back to keys | `Game_Map#setup` alias turns a base `map_no` into its key (a load after a game update calls setup with the number) and registers a missing key from `maps` | `F/5_DataManager.rb:994-1000`; `LC/100_Homes.rb:580-590` | | After a load | `DataManager.extract_save_contents` alias registers every key in `maps` (a nap on a pinned map calls `setup(map_id_rec)` with the key) | `F/5_DataManager.rb:954-964`; `F/Game_InterpreterModifies/Game_Interpreter_Modifies_OM.rb:12`, `:24` | | Created by | the first piece: `Bases.on_piece_placed(map, x, y, kind)` on the map named in `entry["to"]`, tile and entry passing 9.4 | | | Reverted by | `Bases.on_piece_removed(map, x, y)` taking the last piece, or `Bases.destroy_all!`: the record goes, the next entry picks a random map again, the marker goes | | | Map numbers | `9200 + id`; moved to a free number if another mod took it (furniture records follow) | `F/5_DataManager.rb:390-405` (`extra_map_register` takes max + 1) | Resources (decision 3): field maps have no regrow timer. Every entry reloads the map file (`F/31_Game_Map.rb:172`) and its BIOS rolls resources and wildlife again because `change_map_story_stats_fix` sets `ReRollHalfEvents` = 1 (`E/34_Functions_ChangeMap.rb:138`, called at `:264`; Map028 event 1 rolls `RandomRootVegetables` and `StaticRockInsect0` on in-map regions 9 and 11, then `region_map_wildness_*`). Trees and nodes are plain map events without self-switch conditions (Map030). The pin runs the same function on the same file, so this is unchanged. The only difference is the map number (9200 + id), which only separates self switches (`[map_id, event_id, key]`, `F/39_Game_Event.rb:1992-1995`); field maps use none. ### 9.3 Marker on Map002 | Point | How | |---|---| | Where | injected into `@map.events` in `setup_event_hack` when the map note has `isOverMap=true`, one per record of that overmap, like the home doors (`LC/100_Homes.rb:1262-1283`, `:1285-1304`), so a nap rebuilds it | | Sprite | `!World Map 02` index 4, direction 4, pattern 0, a small fenced camp (`scratchpad/r3/worldmap02_sheet.png`) | | Page | below characters, through, action button, command `lonacraft_base_marker` = `$game_temp.reserve_region_event(region)`. Any event under Lona takes the action key first, so without this the region menu would not open on a base tile (`F/35_Game_Player.rb:604-620`, `:331-345`) | | Removed | not injected once the record is gone; `destroy_all!` on the overmap also deletes the live events | ### 9.4 Allowed tile rule (`Bases.allowed_tile?`) | # | Rule | Evidence | |---|---|---| | 1 | the map is a world map (note `isOverMap=true`) | `F/31_Game_Map.rb:285-287` | | 2 | the tile has a region id > 0 with field maps in `$data_region_maps` (an enterable tile) | `F/5_DataManager.rb:381-388`, `E/34_Functions_ChangeMap.rb:263` | | 3 | no map event stands on the tile: every town, cave and quest place is a Map002 event (`-point-*`, `AbanHouse1`, `DfRefugeeCamp`, ...) and takes the action key before the region does | Map002 events; `F/35_Game_Player.rb:604-614` | | 4 | not inside the walls of Noer: three boxes on OvermapMain, x 22-28 y 94-103, x 28-40 y 95-103, x 33-37 y 92-96, read off the wall art (`scratchpad/r3/om_noer.png`; gates `-point-NoerGate` (40,99), `-point-NoerGate2` (31,95)) | Map002 render | | 5 | not a settlement region (deny list): 10 Slums, 12 Rudesind Slope, 18 Infected City Ruins, 20 Refugee Camp, 21 Town of Noer, 22 Streets of Noer, 29/30 Fortress Ruins, 31/32 Sybaris | `Text/ENG/OvermapEvents.txt:160-256` | | 6 | creation only: a plain visit, `OverMapEvent_name` was 0 when Lona entered. Every world-map event sets it before entering (`HCG/encounter/RefugeeCamp.rb:1`, `E/33_Functions_OverMapEvents.rb:128`, `:178-201`); the game clears it after the BIOS (`E/34_Functions_ChangeMap.rb:111`), so it is kept in `entry["event"]` | | Dry run over Map002 (`scratchpad/r3/allowed_tiles.py`, same constants): | Result | Tiles | |---|---| | allowed | 4,246 | | refused, settlement region | 345 | | refused, event on the tile | 104 | | refused, inside Noer's walls (regions 23, 7, 11 inside the boxes) | 14 | | region 0, not enterable | 20,791 | | allowed tiles inside the Noer boxes / static events on allowed tiles | 0 / 0 | Abandoned House (region 9): 83 tiles allowed; the `AbanHouse1` / `AbanHouse2` points (41,90), (108,90) are event maps and stay refused by rule 3. Renders: `scratchpad/r3/om_allowed.png`, `scratchpad/r3/om_allowed_noer.png` (green allowed, red refused by rules 3-5, yellow Noer boxes). ### 9.5 Destroy all bases (System page) | Point | How | |---|---| | Line | appended last in `Menu_System#create_sprites` (`F/194_menu_08_0_System.rb:67-90`; RolePlayS replaces that method, `RolePlayS/Scripts/Frames/194_menu_08_0_System.rb:22-39`, and loads first, so the alias sits on top of either), row 9 under Keybinding (`BASE_LINE + UNIT_HEIGHT * 9`), text "Destroy all bases (N)" | | Prompt | an overlay like the hardcore prompt (`:408-440`): title, two lines, Confirm / Cancel keys. `update_input` and `mouse_update_input` answer it first (`:487-500`, `:502-506`); `mouse_force_main_menu_pause` is true while it shows (`:909-912`) | | Yes | `Bases.destroy_all!`: every record; the map registry except the map Lona stands on; furniture records on base map numbers (no refund); live markers when on the overmap | | No bases | the line buzzes | ### 9.6 Option A space and spawn mitigations (B2) | Problem | Measure | |---|---| | Small or corridor maps (1.2: 522 passable tiles on Map019 swamp and Map021 dead forest, 525 on Map029 rain forest, all in paths, 587 on Map030) | allowed (the rule is about the tile); the map limits what fits | | BIOS spawns inside a built area | after `setup_region_map` (`F/31_Game_Map.rb:199`, `:270-281`) drop built cells from `@region_map[id]` unless the list would become empty (Map028's BIOS does `region_map[11].sample[0]`) | | StartPoint, exits | no piece on the region-1 exit ring (Map028 event 4, `set_region_trigger(1)`), on `-point-StartPoint` or its 4 neighbours | ### 9.7 Raids (R4, research only) On a pinned GAME map the nap event is the game's: Map028 event 32 `region_map_wildness_nap` (`E/34_Functions_RegionMap.rb:1645`), reached through `HCG/Command_Nap.rb:10` and `F/31_Game_Map.rb:1305-1308`. Two hooks: (1) alias `region_map_wildness_nap` / `region_map_wildness_nap_stats` (`:237-246`) when `Bases.base_at_map?` is true; (2) alias `Game_Actor#process_nap_change`, as Campsites does (`CS/10_Campsites.rb:319-346`). Different scenarios per tile type (Abandoned House vs field) are wanted later; the record's `region` and `field` give the type. ### 9.8 Phase 1, updated | Item | Scope | Files | State | |---|---|---|---| | B1 | record, pin / revert, entry note, marker, allowed rule, Destroy-all line + prompt, debug key Numpad / (adds or removes a debug piece), public API | `Scripts/110_Bases.rb` (new), `loader.rb`, `Text//Bases.txt` (5 language folders), README, BOARD | built, owner's run pending | | B2 | A3 palisade wall + A5 floor tiles; placement through the furniture cursor, calling `Bases.on_piece_placed` / `on_piece_removed`; tile rebuild and region-map filter (9.6) | `110_Bases.rb`, `90_Furniture.rb`, items, recipes | after the 90_Furniture.rb work | | B3 | door event (4.2) | `110_Bases.rb`, items, recipes | after B2 | API for B2: `Bases.record_for_tile(om_map, x, y)`, `Bases.record_for_map(map)`, `Bases.base_at_map?(map)`, `Bases.can_build_here?(map)`, `Bases.on_piece_placed(map, x, y, kind)`, `Bases.on_piece_removed(map, x, y)`, `Bases.allowed_tile?(x, y, om_map = nil)`, `Bases.destroy_all!`. ### 9.9 B2 / B3 as built (2026-10-06) | Point | Built | |---|---| | Items | Palisade Wall (2 Plank + 1 Rope), Plank Floor (2 Plank), Wooden Door (3 Plank + 1 Rope); hand and Carpentry Bench, Common, new recipe category / craft group "building"; `0_Core.rb` ITEMS rows, icons in cells 13-15 of `Iconset_LonaCraft.png` | | Tile table (by sheet name, all 13 tilesets of allowed regions) | wall A3 kind: TileA3 68, TileA3Abom 68, Outside_POOR_A3 66, macks_A3 70 (vertical logs); floor A5: TileA5_exterior1 1600, TileA5_exterior3 1600, Outside_POOR_A5 1552, macks_A5 1570, Inside_POOR_A5 1552 (picked to stand apart from the logs). Flags checked: wall impassable in all 13 (terrain tag 4, tag 0 on tileset 13), floor passable in all 13 | | Wall shape | 16-shape from the 4 neighbours (2.3), neighbours repainted; dry run 3x3 ring = 3 10 6 / 5 . 5 / 9 10 12, L = 7 / 5 / 9 10 14 | | Storage | the base record's `pieces` ("W", "F", "D", "FD", "S" = sideways door); no furniture records | | Rebuild | `setup_event_hack` writes the tiles, `setup_region_map` alias drops built cells from the spawn lists, doors spawned after setup and closed after every nap | | Live repaint | `REDRAW = :table` (a fresh Table copy, so the tilemap's next `map_data =` sees a new object, `F/49_Spriteset_Map.rb:322-328`); fallback `:spriteset`. Unverified until the owner's run | | Doors | the game's two-page door (open through, closed solid, `doorEV_setup`); the side-door sprite (`!Door4` [4]) is a small hatch, so both orientations use the front door [0] (one-line switch `DOOR_SIDE`) | | Taking down | action key facing a wall / floor: Take down / Cancel; open door: Close / Take down / Cancel; full refund; the last piece reverts the tile (B1) | | Render | `scratchpad/r3/b2_base_plainfield.png` (`scratchpad/r3/b2_render.py` reads the table from the Ruby file) |