695 lines
28 KiB
Ruby
695 lines
28 KiB
Ruby
#==============================================================================
|
|
# LonaCraft - 130_Sewer.rb (board R9, research docs/RESEARCH_SEWER.md, owner
|
|
# decisions 2026-10-06). The Deep Sewer: one big sewer map of the mod's own
|
|
# under Noer, with four ways in, its own vermin, hobos and goblins, night
|
|
# raids from the tunnels, and the only map where Lona may build while NPCs
|
|
# are around (the build rule itself is in 110_Bases.rb).
|
|
# What it does:
|
|
# * The map: Maps/LonaCraftDeepSewer.rvdata2 (100 x 70, tileset 19 Mack-Sewer
|
|
# like the game's NoerSewer Map053; made by the generator in the
|
|
# scratchpad, r3/build_deep_sewer_v2.py, seed 70). Narrow walkways along
|
|
# sewage channels, bridges (the E tiles 885 / 886 Map053 uses) and
|
|
# stairs (E 870), nine sunken pockets 3x3 to 5x4 for Lona. Regions: 1 the
|
|
# tunnel mouths (spawns of the raids, the edge rule of 110_Bases.rb),
|
|
# 2 the walkways, bridges and the flooded basin (vermin), 3 the homeless
|
|
# camp, 4 the goblin den, 5 quest spawns (reserved), 0 the pockets.
|
|
# Note "isOverMap=false isUnderGround=true event=LonaCraftDeepSewer".
|
|
# * Registered at DataManager.load_mod_database like the homes
|
|
# (100_Homes.rb:546-576): $data_mapinfos["LonaCraftDeepSewer"] with the
|
|
# map file and the fixed number MAP_NO (or the next free one), and the tag
|
|
# $data_tag_maps["LonaCraftDeepSewer"]. 110_Bases.rb NAMED_MAPS keys the
|
|
# one base record of the whole map by that name.
|
|
# * Entrances (ENTRANCES): a grate event "LonaCraftSewerGrate_<id>" (the
|
|
# game's !Trapdoor sheet, the open hatch) and a point
|
|
# "-point-LonaCraftSewerOut_<id>" next to it, added to the town map's
|
|
# events in setup_event_hack (as the home doors, 100_Homes.rb:1262-1304)
|
|
# on the map whose note tag is ENTRANCES[:tag]. A tile with a map event,
|
|
# or one that is not open floor, skips the grate with a console line.
|
|
# Standing on the grate, OK asks "Climb down"; Lona lands on
|
|
# -point-StartPoint_<id> of the Deep Sewer (TagSubTrans, honoured by
|
|
# enter_static_tag_map, 34_Functions_ChangeMap.rb:58-61). Each Deep
|
|
# Sewer ladder ("LonaCraftSewerLadder_<id>", in the map file) carries its
|
|
# entrance id and goes back up to that grate's point; LastOverMapX/Y
|
|
# become that town's world-map point, so leaving the town later puts
|
|
# Lona at the right place on the world map. No purchase, no owner.
|
|
# * BIOS (event 1 of the map, autorun): the game's sewer light and sound
|
|
# (HCGframes/event/NoerSewer_begin.rb:2-8), the entry move, then the
|
|
# population on every setup (entry and nap, as Map053's BIOS does):
|
|
# 4-6 AnimalRattus, 4-6 AnimalRoach, 3-5 WildGiantMice (the game's
|
|
# abomination rat, NPCdata race "Abomination") on region 2; 2-4
|
|
# MobHumanCommoner / MobMootCommoner (the hobos of Map053's BIOS) on
|
|
# region 3; 2-4 GoblinCommoner on region 4; at least POP_MIN_DIST steps
|
|
# from Lona, never on the edge zone or a StartPoint, never inside walls
|
|
# (the region lists are already pruned by 110_Bases.rb). They carry
|
|
# :LonaCraftSewerPop and no raid tag.
|
|
# * Nap (event 2, NapEvent): the game's danger roll needs OnRegionMap >= 1
|
|
# (34_Functions_RegionMap.rb:1832) and a tag map has 0, so the sewer rolls
|
|
# by itself: NAP_CHANCE_DAY / NAP_CHANCE_NIGHT percent, the group from the
|
|
# "sewer" scenario of 120_Raids.rb (CommonMobs 50, AbomBreedlingRaid 30,
|
|
# SewerRats 30, UndeadWalking 10), the raid armed when the sewer has a
|
|
# base (Raids.arm). After the nap the BIOS spawns the group on the tunnel
|
|
# mouths (RegionMap_RegionOuta / Insa = [1]) with the game's own
|
|
# region_map_wildness_spawn; "SewerRats" are WildGiantMice spawned here.
|
|
# * Water: none on the map (owner: bring it).
|
|
# * Layout v2 (owner review 2026-10-06, generator scratchpad
|
|
# r3/build_deep_sewer_v2.py, measured against Map053): a compact net of
|
|
# bending sewage corridors, sunken pockets for Lona behind a ditch and a
|
|
# stair, a flooded basin, a homeless camp (region 3) and a goblin den
|
|
# (region 4), each one distinct area, at least 6 tiles from the pockets.
|
|
# * Quests (docs/SEWER_QUESTS.md): six reserved points
|
|
# -point-LonaCraftSewerQuest_1..6 (1 goblin den, 2 homeless camp,
|
|
# 3 flooded basin, 4 dead end, 5 tunnel mouth, 6 mid-tunnel bridge),
|
|
# region 5 (QUEST_REGION) reserved for quest spawns and never used by the
|
|
# population, Sewer.quest_points, and the callbacks Sewer.on_enter /
|
|
# Sewer.on_setup / Sewer.on_nap run by the BIOS and the NapEvent. No quest
|
|
# is built here.
|
|
# * Console lines "LonaCraft Sewer: ..." for registration, grates, entry,
|
|
# exit, population and the nap roll.
|
|
# * Difficulty (board R10, 120_Raids.rb diff / step, Config/Bases.json
|
|
# "difficulty"; "hard" changes nothing): the nap chance + "sewer_day_add"
|
|
# / "sewer_night_add" of the level + the sewer base's Danger step
|
|
# ("sewer_chance_add", Lower -10, Higher +10), 0 to 100; the vermin, hobo
|
|
# and goblin counts x "sewer_pop_mult" (rounded). "Danger" next to
|
|
# "Rename base" on the ladders' menu (110_Bases.rb rename_menu,
|
|
# cycle_danger). The SewerRats raid size is not scaled.
|
|
#==============================================================================
|
|
module LonaCraft
|
|
module Sewer
|
|
ENABLED = true
|
|
TEXT = "LonaCraft:Sewer:"
|
|
KEY = "LonaCraftDeepSewer" # $data_mapinfos key, tag, 110_Bases.rb NAMED_MAPS key
|
|
FILE = "Maps/LonaCraftDeepSewer.rvdata2"
|
|
MAP_NO = 9150 # runtime map number (homes 9001+, bases 9200+)
|
|
GRATE_PREFIX = "LonaCraftSewerGrate_"
|
|
OUT_PREFIX = "LonaCraftSewerOut_" # -point- in the town map where Lona comes up
|
|
START_PREFIX = "StartPoint_" # -point- in the Deep Sewer per entrance
|
|
GRATE_SPRITE = ["!Trapdoor", 4, 8, 0] # sheet, index, direction, pattern: the open hatch
|
|
# :tag = the town map's note tag (event=...), :grate = the grate tile,
|
|
# :out = where Lona stands when she comes up, :world = the building's
|
|
# own point on OvermapMain (LastOverMapX/Y): EV38 -point-NoerMobHouse
|
|
# (39,97), EV6 -point-NoerDock (35,103), EV15 -point-NoerMarket
|
|
# (35,101), EV31 -point-NoerBackStreet (31,97). Tiles checked by
|
|
# scratchpad r9/grate_rules.py (owner rules 2026-10-06): floor on all
|
|
# three layers with open ground above, no event on it or its 4
|
|
# neighbours, not within 1 of a StartPoint / ExitPoint, removing it
|
|
# cuts nothing off the map's StartPoint, off the walking line from the
|
|
# StartPoint to the NPCs and exits. The market tile is the owner's
|
|
# accepted one (2026-10-06).
|
|
# Parked 2026-10-06 (owner, after the slum ladder crash: "remove the sewer
|
|
# entrances for now. It needs more work"): ENTRANCES_OPEN false injects no grate
|
|
# anywhere, so the Deep Sewer cannot be entered; its ladders still bring Lona
|
|
# out onto the world map (go_up_parked) for a save made inside. The slum row
|
|
# is WRONG and must not be reopened as it is: NoerMobHouse (Map058) is the
|
|
# capture loop's holding house; its BIOS (NoerMobHouse_CapturedBegin.rb:5)
|
|
# crashes outside a capture (nil switch1_id) and its MapCont sets Captured /
|
|
# RapeLoop. The plan was a world-map hatch at OvermapMain (38,97) drawn like
|
|
# the game's own sewer hatch (Map002 EV3 -point-NoerSewer, !World Map 02 0/6/0).
|
|
ENTRANCES_OPEN = false
|
|
ENTRANCES_ALL = [
|
|
{:id => "slum", :tag => "NoerMobHouse", :grate => [25, 35], :out => [26, 35], :world => [39, 97]},
|
|
{:id => "dock", :tag => "NoerDock", :grate => [51, 31], :out => [51, 32], :world => [35, 103]},
|
|
{:id => "market", :tag => "NoerMarket", :grate => [46, 40], :out => [46, 41], :world => [35, 101]},
|
|
{:id => "backstreet", :tag => "NoerBackStreet", :grate => [37, 50], :out => [37, 49], :world => [31, 97]}
|
|
]
|
|
ENTRANCES = ENTRANCES_OPEN ? ENTRANCES_ALL : []
|
|
NAP_CHANCE_DAY = 35
|
|
NAP_CHANCE_NIGHT = 60
|
|
RAT_GROUP = "SewerRats"
|
|
RAT_UNIT = "WildGiantMice"
|
|
# used when 120_Raids.rb (its "sewer" scenario) is not there
|
|
GROUPS_FALLBACK = {"CommonMobs" => 50, "AbomBreedlingRaid" => 30, "SewerRats" => 30, "UndeadWalking" => 10}
|
|
MOUTH_REGION = 1
|
|
WALK_REGION = 2
|
|
HOBO_REGION = 3
|
|
GOBLIN_REGION = 4
|
|
POP_MIN_DIST = 5
|
|
POP_TAG = :LonaCraftSewerPop
|
|
# [EventLib name, least, most] on the walkways
|
|
VERMIN = [["AnimalRattus", 4, 6], ["AnimalRoach", 4, 6], ["WildGiantMice", 3, 5]]
|
|
HOBOS = ["MobHumanCommoner", "MobMootCommoner"]
|
|
HOBO_COUNT = [2, 4]
|
|
GOBLIN = "GoblinCommoner"
|
|
GOBLIN_COUNT = [2, 4]
|
|
QUEST_REGION = 5 # reserved for quest spawns, never filled by populate
|
|
QUEST_PREFIX = "LonaCraftSewerQuest_" # -point-LonaCraftSewerQuest_<n> in the map
|
|
QUEST_POINTS = {1 => :goblin_den, 2 => :homeless_camp, 3 => :flooded_basin,
|
|
4 => :dead_end, 5 => :tunnel_mouth, 6 => :bridge}
|
|
@hooks = {:enter => [], :setup => [], :nap => []}
|
|
|
|
@registered = false
|
|
@pending = nil # the group the last nap rolled, spawned by the BIOS after it
|
|
|
|
def self.enabled?
|
|
ENABLED && @registered ? true : false
|
|
end
|
|
|
|
def self.text_key(key)
|
|
"#{TEXT}#{key}"
|
|
end
|
|
|
|
def self.entrance(id)
|
|
ENTRANCES.find{|e| e[:id] == id.to_s }
|
|
end
|
|
|
|
def self.map?(map = $game_map)
|
|
!map.nil? && map.map_id_rec == KEY
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Registration (DataManager.load_mod_database alias, end of this file)
|
|
#----------------------------------------------------------------------
|
|
def self.free_map_id(want)
|
|
used = {}
|
|
$data_mapinfos.each{|k, v|
|
|
next if v.nil? || k == KEY
|
|
used[v.id] = true if v.respond_to?(:id)
|
|
}
|
|
want += 1 while used[want]
|
|
want
|
|
end
|
|
|
|
def self.register_map
|
|
@registered = false
|
|
return unless ENABLED
|
|
return if $data_mapinfos.nil?
|
|
file = LonaCraft.resource(FILE)
|
|
unless File.exist?(file)
|
|
p "LonaCraft Sewer: missing map #{file}, the Deep Sewer is left out"
|
|
return
|
|
end
|
|
info = RPG::MapInfo.new
|
|
info.name = KEY
|
|
info.filename = file
|
|
info.id = free_map_id(MAP_NO)
|
|
$data_mapinfos[KEY] = info
|
|
$data_tag_maps[KEY] = [KEY] if $data_tag_maps
|
|
@registered = true
|
|
p "LonaCraft Sewer: the Deep Sewer is map #{info.id}#{info.id != MAP_NO ? " (#{MAP_NO} was taken)" : ""}, #{file}"
|
|
rescue => e
|
|
p "LonaCraft Sewer register error #{e.class} #{e.message}"
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Grates in the town maps (Game_Map#setup_event_hack alias below)
|
|
#----------------------------------------------------------------------
|
|
def self.blank_page
|
|
page = RPG::Event::Page.new
|
|
page.graphic.tile_id = 0
|
|
page.graphic.character_name = ""
|
|
page.move_type = 0
|
|
page.walk_anime = false
|
|
page.step_anime = false
|
|
page.direction_fix = true
|
|
page.through = true
|
|
page.priority_type = 0
|
|
page.trigger = 0
|
|
page.list = [RPG::EventCommand.new(0, 0, [])]
|
|
page
|
|
end
|
|
|
|
def self.build_grate(ent)
|
|
sheet, index, dir, pattern = GRATE_SPRITE
|
|
ev = RPG::Event.new(ent[:grate][0].to_i, ent[:grate][1].to_i)
|
|
ev.name = "#{GRATE_PREFIX}#{ent[:id]}"
|
|
page = blank_page
|
|
page.graphic.character_name = sheet.to_s
|
|
page.graphic.character_index = index.to_i
|
|
page.graphic.direction = dir.to_i
|
|
page.graphic.pattern = pattern.to_i
|
|
# below Lona: she stands on it and presses OK
|
|
page.list = [
|
|
EvLib.NewEventCMD("lonacraft_sewer_enter(#{ent[:id].inspect}) if respond_to?(:lonacraft_sewer_enter)"),
|
|
RPG::EventCommand.new(0, 0, [])
|
|
]
|
|
ev.pages = [page]
|
|
ev
|
|
end
|
|
|
|
def self.build_out_point(ent, x, y)
|
|
ev = RPG::Event.new(x.to_i, y.to_i)
|
|
ev.name = "-point-#{OUT_PREFIX}#{ent[:id]}"
|
|
ev.pages = [blank_page]
|
|
ev
|
|
end
|
|
|
|
# +gm+ the Game_Map being set up, +data+ its RPG::Map, +preload+ its
|
|
# @preload_EventHash. The point is always added (TagSubTrans needs it:
|
|
# get_storypoint raises on a missing point, 31_Game_Map.rb:1330-1333);
|
|
# it falls back to the map's StartPoint when its own tile is not open.
|
|
def self.inject(gm, data, ent, preload)
|
|
grate_name = "#{GRATE_PREFIX}#{ent[:id]}"
|
|
point_name = "-point-#{OUT_PREFIX}#{ent[:id]}"
|
|
evs = data.events
|
|
return if evs.values.any?{|e| e && (e.name == grate_name || e.name == point_name) }
|
|
gx, gy = ent[:grate]
|
|
ox, oy = ent[:out]
|
|
taken = lambda{|x, y| evs.values.any?{|e| e && e.x == x && e.y == y } }
|
|
open = lambda{|x, y| gm.valid?(x, y) && [1, 2, 4, 8].all?{|bit| gm.lonacraft_layer_pass?(x, y, bit) } }
|
|
made = []
|
|
if taken.call(gx, gy) || taken.call(ox, oy)
|
|
p "LonaCraft Sewer: grate #{ent[:id]} on #{gm.name} (#{gx},#{gy}) skipped, a map event stands there"
|
|
elsif !open.call(gx, gy) || !open.call(ox, oy)
|
|
p "LonaCraft Sewer: grate #{ent[:id]} on #{gm.name} (#{gx},#{gy}) skipped, not open floor"
|
|
else
|
|
made << build_grate(ent)
|
|
end
|
|
unless open.call(ox, oy)
|
|
st = evs.values.find{|e| e && e.name == "-point-StartPoint" }
|
|
ox, oy = st.x, st.y if st
|
|
end
|
|
made << build_out_point(ent, ox, oy)
|
|
made.each{|ev|
|
|
new_id = evs.keys.max
|
|
new_id = new_id.nil? ? 1 : new_id + 1
|
|
ev.id = new_id
|
|
evs[new_id] = ev
|
|
preload[ev.name] = ev if preload.is_a?(Hash)
|
|
}
|
|
p "LonaCraft Sewer: grate #{ent[:id]} at (#{gx},#{gy}) on #{gm.name}, way up at (#{ox},#{oy})" if made.size == 2
|
|
end
|
|
|
|
# The Deep Sewer itself: a -point-WakeUp on the StartPoint, which
|
|
# enter_static_tag_map uses after a capture (34_Functions_ChangeMap.rb:70-80)
|
|
def self.add_wakeup_point(data, preload)
|
|
evs = data.events
|
|
return if evs.values.any?{|e| e && e.name == "-point-WakeUp" }
|
|
st = evs.values.find{|e| e && e.name == "-point-StartPoint" }
|
|
return if st.nil?
|
|
ev = RPG::Event.new(st.x, st.y)
|
|
ev.name = "-point-WakeUp"
|
|
ev.pages = [blank_page]
|
|
new_id = evs.keys.max
|
|
ev.id = new_id.nil? ? 1 : new_id + 1
|
|
evs[ev.id] = ev
|
|
preload[ev.name] = ev if preload.is_a?(Hash)
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Down and up
|
|
#----------------------------------------------------------------------
|
|
# into the Deep Sewer, onto -point-StartPoint_<id>
|
|
def self.go_down(ent, interp)
|
|
return false unless enabled? && $data_mapinfos[KEY]
|
|
$story_stats["TagSubTrans"] = "#{START_PREFIX}#{ent[:id]}"
|
|
$story_stats["TagSubForceDir"] = 2
|
|
SndLib.me_play("SE/Move", 75, 120 + rand(31))
|
|
interp.change_map_weather_cleaner
|
|
$game_player.reserve_transfer(KEY, 1, 1, 2)
|
|
interp.change_map_story_stats_fix
|
|
p "LonaCraft Sewer: down the #{ent[:id]} grate to #{START_PREFIX}#{ent[:id]}"
|
|
true
|
|
end
|
|
|
|
# up the ladder of entrance +ent+, onto its grate's point in the town map
|
|
def self.go_up(ent, interp)
|
|
ids = $data_tag_maps.nil? ? nil : $data_tag_maps[ent[:tag]]
|
|
target = ids.is_a?(Array) ? ids.first : nil
|
|
if target.nil? || $data_mapinfos[target].nil?
|
|
p "LonaCraft Sewer: no map with the tag #{ent[:tag]}, the #{ent[:id]} ladder goes nowhere"
|
|
return false
|
|
end
|
|
$story_stats["TagSubTrans"] = "#{OUT_PREFIX}#{ent[:id]}"
|
|
$story_stats["TagSubForceDir"] = 2
|
|
$story_stats["LastOverMapX"] = ent[:world][0]
|
|
$story_stats["LastOverMapY"] = ent[:world][1]
|
|
SndLib.me_play("SE/Move", 75, 120 + rand(31))
|
|
interp.change_map_weather_cleaner
|
|
$game_player.reserve_transfer(target, 1, 1, 2)
|
|
interp.change_map_story_stats_fix
|
|
p "LonaCraft Sewer: up the #{ent[:id]} ladder to #{ent[:tag]} (map #{target}), world map point #{ent[:world].inspect}"
|
|
true
|
|
end
|
|
|
|
# ENTRANCES parked (ENTRANCES_OPEN false): a ladder leaves the tag map the
|
|
# game's way, onto the last world-map point (LastOverMapX/Y), as the game's
|
|
# change_map_tag_map_exit -> change_map_leave_tag_map
|
|
# (34_Functions_ChangeMap.rb:326-347, 179-198). The ladder ran
|
|
# lonacraft_sewer_can_move? (cannot_change_map, hardcore threat) already.
|
|
def self.go_up_parked(interp)
|
|
$story_stats["TagSubTrans"] = 0
|
|
$story_stats["TagSubForceDir"] = 0
|
|
SndLib.me_play("SE/Move", 75, 120 + rand(31))
|
|
interp.change_map_leave_tag_map
|
|
p "LonaCraft Sewer: up a ladder to the world map (entrances parked)"
|
|
true
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Population (the BIOS, every setup)
|
|
#----------------------------------------------------------------------
|
|
def self.populate(map)
|
|
rm = map.region_map
|
|
unless rm.is_a?(Array)
|
|
p "LonaCraft Sewer: no region lists, nobody placed"
|
|
return
|
|
end
|
|
bases = defined?(LonaCraft::Bases) ? LonaCraft::Bases : nil
|
|
edge = bases ? bases.edge_zone(map) : {}
|
|
px = $game_player.x
|
|
py = $game_player.y
|
|
taken = {}
|
|
pools = {}
|
|
pool = lambda{|region|
|
|
unless pools[region]
|
|
list = rm[region].is_a?(Array) ? rm[region] : []
|
|
pools[region] = list.map{|c| [c[0], c[1]] }.select{|x, y|
|
|
(x - px).abs + (y - py).abs >= POP_MIN_DIST && !edge[[x, y]] &&
|
|
!(bases && bases.near_start?(map, x, y)) && map.events_xy(x, y).empty?
|
|
}.shuffle
|
|
end
|
|
pools[region]
|
|
}
|
|
place = lambda{|name, region|
|
|
list = pool.call(region)
|
|
c = list.shift
|
|
c = list.shift while c && taken[c]
|
|
next false if c.nil?
|
|
taken[c] = true
|
|
ev = map.summon_event(name, c[0], c[1], -1, {POP_TAG => true})
|
|
sd = ev && ev.respond_to?(:summon_data) ? ev.summon_data : nil
|
|
sd[:WildnessNapEvent] = nil if sd.is_a?(Hash) # never counted as a raid group
|
|
true
|
|
}
|
|
counts = Hash.new(0)
|
|
VERMIN.each{|name, lo, hi|
|
|
pop_count(lo + rand(hi - lo + 1)).times{ counts[name] += 1 if place.call(name, WALK_REGION) }
|
|
}
|
|
pop_count(HOBO_COUNT[0] + rand(HOBO_COUNT[1] - HOBO_COUNT[0] + 1)).times{
|
|
counts["hobos"] += 1 if place.call(HOBOS.sample, HOBO_REGION)
|
|
}
|
|
pop_count(GOBLIN_COUNT[0] + rand(GOBLIN_COUNT[1] - GOBLIN_COUNT[0] + 1)).times{
|
|
counts[GOBLIN] += 1 if place.call(GOBLIN, GOBLIN_REGION)
|
|
}
|
|
p "LonaCraft Sewer: population #{counts["AnimalRattus"]} rats, #{counts["AnimalRoach"]} roaches, " +
|
|
"#{counts["WildGiantMice"]} giant rats on the walkways, #{counts["hobos"]} hobos (region #{HOBO_REGION}), " +
|
|
"#{counts[GOBLIN]} goblins (region #{GOBLIN_REGION})"
|
|
rescue => e
|
|
p "LonaCraft Sewer population error #{e.class} #{e.message}"
|
|
end
|
|
|
|
#----------------------------------------------------------------------
|
|
# Nap roll and the group after it
|
|
#----------------------------------------------------------------------
|
|
def self.pick_group
|
|
if defined?(LonaCraft::Raids) && LonaCraft::Raids.respond_to?(:pick_group)
|
|
g = begin
|
|
LonaCraft::Raids.pick_group("sewer")
|
|
rescue
|
|
nil
|
|
end
|
|
return g if g
|
|
end
|
|
total = GROUPS_FALLBACK.values.inject(0){|t, w| t + w }
|
|
n = rand(total)
|
|
GROUPS_FALLBACK.each{|g, w|
|
|
return g if n < w
|
|
n -= w
|
|
}
|
|
GROUPS_FALLBACK.keys.last
|
|
end
|
|
|
|
# Our NapEvent, before handleNap: roll, set the race, arm the raid
|
|
# R10: the level's and the base's additions to the nap chance (0 without 120_Raids.rb)
|
|
def self.chance_add(night, rec)
|
|
return 0 unless defined?(LonaCraft::Raids) && LonaCraft::Raids.respond_to?(:diff)
|
|
r = LonaCraft::Raids
|
|
r.diff(night ? "sewer_night_add" : "sewer_day_add").to_i + (rec ? r.step(rec, "sewer_chance_add").to_i : 0)
|
|
rescue
|
|
0
|
|
end
|
|
|
|
# R10: a population count x the level's "sewer_pop_mult"
|
|
def self.pop_count(n)
|
|
return n unless defined?(LonaCraft::Raids) && LonaCraft::Raids.respond_to?(:diff)
|
|
(n * LonaCraft::Raids.diff("sewer_pop_mult").to_f).round
|
|
rescue
|
|
n
|
|
end
|
|
|
|
def self.nap_roll
|
|
@pending = nil
|
|
night = $game_date.night?
|
|
rec = defined?(LonaCraft::Bases) ? LonaCraft::Bases.record_for_map($game_map) : nil
|
|
chance = [[(night ? NAP_CHANCE_NIGHT : NAP_CHANCE_DAY) + chance_add(night, rec), 0].max, 100].min
|
|
roll = rand(100)
|
|
race = roll < chance ? pick_group : nil
|
|
$story_stats["OnRegionMapSpawnRace"] = race || 0
|
|
armed = false
|
|
if race && rec && defined?(LonaCraft::Raids) && LonaCraft::Raids.respond_to?(:arm)
|
|
armed = LonaCraft::Raids.arm(rec, race)
|
|
end
|
|
@pending = race
|
|
what = race.nil? ? "a quiet nap" : "#{race} will come out of the tunnels#{armed ? ", a raid on base #{rec["id"]}" : (rec ? "" : ", no base here")}"
|
|
p "LonaCraft Sewer: nap roll #{roll} against #{chance} % (#{night ? "night" : "day"}), #{what}"
|
|
rescue => e
|
|
p "LonaCraft Sewer nap roll error #{e.class} #{e.message}"
|
|
@pending = nil
|
|
end
|
|
|
|
# The BIOS after a nap: the rolled group on the tunnel mouths
|
|
#----------------------------------------------------------------------
|
|
# Quest API (docs/SEWER_QUESTS.md)
|
|
#----------------------------------------------------------------------
|
|
# {n => [x, y, event id]} of the reserved quest points on the live map
|
|
# (empty when Lona is not in the Deep Sewer)
|
|
def self.quest_points(map = $game_map)
|
|
out = {}
|
|
return out unless map?(map) && map.storypoint_map.is_a?(Hash)
|
|
QUEST_POINTS.each_key{|n|
|
|
pt = map.storypoint_map["#{QUEST_PREFIX}#{n}"]
|
|
out[n] = pt if pt
|
|
}
|
|
out
|
|
end
|
|
|
|
# the point of one kind (:goblin_den, :homeless_camp, :flooded_basin,
|
|
# :dead_end, :tunnel_mouth, :bridge) as [x, y], or nil
|
|
def self.quest_point(kind, map = $game_map)
|
|
n = QUEST_POINTS.key(kind)
|
|
pt = n ? quest_points(map)[n] : nil
|
|
pt ? pt[0, 2] : nil
|
|
end
|
|
|
|
# the tiles of the quest spawn region (QUEST_REGION) on the live map
|
|
def self.quest_tiles(map = $game_map)
|
|
return [] unless map?(map)
|
|
rm = map.region_map
|
|
rm.is_a?(Array) && rm[QUEST_REGION].is_a?(Array) ? rm[QUEST_REGION] : []
|
|
end
|
|
|
|
# Callbacks for quest scripts. Each block gets (interpreter, map):
|
|
# on_enter Lona came down a grate (after the population)
|
|
# on_setup every setup of the map: entry and after each nap
|
|
# on_nap before the nap's own roll; return :skip_roll to skip it
|
|
def self.on_enter(&block); @hooks[:enter] << block if block; end
|
|
def self.on_setup(&block); @hooks[:setup] << block if block; end
|
|
def self.on_nap(&block); @hooks[:nap] << block if block; end
|
|
|
|
def self.run_hooks(kind, interp)
|
|
res = []
|
|
@hooks[kind].each{|b|
|
|
begin
|
|
res << b.call(interp, $game_map)
|
|
rescue => e
|
|
p "LonaCraft Sewer #{kind} hook error #{e.class} #{e.message}"
|
|
end
|
|
}
|
|
res
|
|
end
|
|
|
|
def self.spawn_nap_group(interp)
|
|
race = @pending
|
|
@pending = nil
|
|
return if race.nil? || $story_stats["OnRegionMapSpawnRace"] != race
|
|
p "LonaCraft Sewer: #{race} spawn on the tunnel mouths"
|
|
interp.region_map_wildness_spawn(race)
|
|
raid = defined?(LonaCraft::Raids) && LonaCraft::Raids.respond_to?(:active?) && LonaCraft::Raids.active?
|
|
$game_map.popup(0, text_key("Nap/noise"), 0, 0) unless raid # a raid gives its own warning
|
|
rescue => e
|
|
p "LonaCraft Sewer nap spawn error #{e.class} #{e.message}"
|
|
end
|
|
|
|
# region_map_wildness_spawn alias: the mod's own group
|
|
def self.spawn_rats
|
|
rm = $game_map.region_map
|
|
tiles = rm.is_a?(Array) && rm[MOUTH_REGION].is_a?(Array) ? rm[MOUTH_REGION] : []
|
|
return p("LonaCraft Sewer: no tunnel mouth tiles, no rats") if tiles.empty?
|
|
n = 4 + (($story_stats["WorldDifficulty"].to_i / 30) * 2)
|
|
n = 10 if n > 10
|
|
n.times{
|
|
c = tiles.sample
|
|
EvLib.sum(RAT_UNIT, c[0], c[1], {:WildnessNapEvent => RAT_GROUP})
|
|
}
|
|
p "LonaCraft Sewer: #{n} #{RAT_UNIT} for #{RAT_GROUP}"
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# DataManager: register the map after every other map list is built.
|
|
#==============================================================================
|
|
module DataManager
|
|
unless respond_to?(:load_mod_database_lonacraft_sewer)
|
|
self.singleton_class.send(:alias_method, :load_mod_database_lonacraft_sewer, :load_mod_database)
|
|
def self.load_mod_database
|
|
load_mod_database_lonacraft_sewer
|
|
LonaCraft::Sewer.register_map
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# Game_Map: the grates in the town maps.
|
|
#==============================================================================
|
|
class Game_Map
|
|
def lonacraft_inject_sewer_grates
|
|
sewer = LonaCraft::Sewer
|
|
return unless sewer.enabled?
|
|
tags = Note.get_data(@map.note.to_s)["event"].to_s.split(",")
|
|
return if tags.empty?
|
|
sewer.add_wakeup_point(@map, @preload_EventHash) if tags.include?(sewer::KEY)
|
|
sewer::ENTRANCES.each{|ent|
|
|
next unless tags.include?(ent[:tag])
|
|
sewer.inject(self, @map, ent, @preload_EventHash)
|
|
}
|
|
end
|
|
|
|
unless method_defined?(:setup_event_hack_lonacraft_sewer)
|
|
alias_method :setup_event_hack_lonacraft_sewer, :setup_event_hack
|
|
def setup_event_hack
|
|
setup_event_hack_lonacraft_sewer
|
|
begin
|
|
lonacraft_inject_sewer_grates
|
|
rescue => e
|
|
p "LonaCraft Sewer grate error #{e.class} #{e.message}"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# The rats group (34_Functions_RegionMap.rb:361 has no case for it; the
|
|
# inner aliases, 120_Raids.rb after_spawn, then begin the raid).
|
|
#==============================================================================
|
|
module GIM_ADDON
|
|
if method_defined?(:region_map_wildness_spawn) && !method_defined?(:lonacraft_sewer_spawn)
|
|
alias_method :lonacraft_sewer_spawn, :region_map_wildness_spawn
|
|
def region_map_wildness_spawn(tmpForceSpawn = false)
|
|
race = tmpForceSpawn ? tmpForceSpawn : $story_stats["OnRegionMapSpawnRace"]
|
|
if race == LonaCraft::Sewer::RAT_GROUP
|
|
begin
|
|
LonaCraft::Sewer.spawn_rats
|
|
rescue => e
|
|
p "LonaCraft Sewer rat spawn error #{e.class} #{e.message}"
|
|
end
|
|
end
|
|
lonacraft_sewer_spawn(tmpForceSpawn)
|
|
end
|
|
end
|
|
end
|
|
|
|
#==============================================================================
|
|
# Game_Interpreter: grate, ladder, BIOS, nap.
|
|
#==============================================================================
|
|
class Game_Interpreter
|
|
# true when Lona may change maps now (the game's rule for leaving a tag
|
|
# map, 34_Functions_ChangeMap.rb:326-347: in combat only on hardcore)
|
|
def lonacraft_sewer_can_move?
|
|
if $game_player.cannot_change_map
|
|
SndLib.sys_buzzer
|
|
return false
|
|
end
|
|
if $game_map.threat && $story_stats["Setup_Hardcore"] >= 1
|
|
SndLib.sys_buzzer
|
|
$game_map.popup(0, "QuickMsg:Lona/incombat#{rand(2)}", 0, 0)
|
|
return false
|
|
end
|
|
true
|
|
end
|
|
|
|
# The grate in a town map
|
|
def lonacraft_sewer_enter(id)
|
|
sewer = LonaCraft::Sewer
|
|
ent = sewer.entrance(id)
|
|
return if ent.nil? || !sewer.enabled?
|
|
return unless lonacraft_sewer_can_move?
|
|
$game_portraits.lprt.hide
|
|
call_msg(sewer.text_key("Grate/down"))
|
|
pick = $game_temp.choice
|
|
$game_temp.choice = -1
|
|
return unless pick == 1
|
|
return unless lonacraft_sewer_can_move?
|
|
$game_player.move_normal
|
|
chcg_background_color(0, 0, 0, 0, 14)
|
|
SndLib.sys_buzzer unless sewer.go_down(ent, self)
|
|
end
|
|
|
|
# A ladder in the Deep Sewer
|
|
def lonacraft_sewer_ladder(id)
|
|
sewer = LonaCraft::Sewer
|
|
ent = sewer.entrance(id)
|
|
# entrances parked: the ladder still leads out (go_up_parked)
|
|
parked = ent.nil? && !sewer::ENTRANCES_OPEN && sewer::ENTRANCES_ALL.any?{|e| e[:id] == id.to_s }
|
|
return if ent.nil? && !parked
|
|
return unless lonacraft_sewer_can_move?
|
|
$game_portraits.lprt.hide
|
|
key = sewer.text_key("Ladder/#{id}")
|
|
# a base on the Deep Sewer: "Rename base" and "Danger" on the ladder's menu (110_Bases.rb)
|
|
base = LonaCraft::Bases.record_for_map($game_map)
|
|
menu = base ? LonaCraft::Bases.rename_menu(key, base, "rt_rename_ladder") : nil
|
|
call_msg(menu ? menu[0] : key)
|
|
pick = $game_temp.choice
|
|
$game_temp.choice = -1
|
|
if menu && pick == menu[1]
|
|
LonaCraft::Bases.open_rename(base)
|
|
return
|
|
end
|
|
if menu && menu[2] && pick == menu[2]
|
|
LonaCraft::Bases.cycle_danger(base) # R10: Lower, Normal, Higher in turn
|
|
return
|
|
end
|
|
return unless pick == 1
|
|
return unless lonacraft_sewer_can_move?
|
|
$game_player.move_normal
|
|
chcg_background_color(0, 0, 0, 0, 14)
|
|
SndLib.sys_buzzer unless (parked ? sewer.go_up_parked(self) : sewer.go_up(ent, self))
|
|
end
|
|
|
|
# Event 1 of the Deep Sewer (autorun), after every setup
|
|
def lonacraft_sewer_bios
|
|
sewer = LonaCraft::Sewer
|
|
SndLib.bgm_play("Cave/Espionage LOOP MOVING", 80)
|
|
SndLib.bgs_play("Cave/Cavern Sound effect_Short", 50)
|
|
$game_map.shadows.set_color(0, 20, 40)
|
|
$game_map.shadows.set_opacity(130)
|
|
map_background_color(80, 80, 200, 40, 0)
|
|
$story_stats["RegionMap_RegionOuta"] = [sewer::MOUTH_REGION] # raids come out of the tunnel mouths
|
|
$story_stats["RegionMap_RegionInsa"] = [sewer::MOUTH_REGION]
|
|
entering = $story_stats["ReRollHalfEvents"] == 1
|
|
if entering
|
|
enter_static_tag_map(nil, true) # TagSubTrans: the entrance's StartPoint_<id>
|
|
p "LonaCraft Sewer: Lona enters the Deep Sewer at (#{$game_player.x},#{$game_player.y})"
|
|
end
|
|
summon_companion
|
|
sewer.populate($game_map)
|
|
sewer.spawn_nap_group(self)
|
|
sewer.run_hooks(:enter, self) if entering # quest scripts (docs/SEWER_QUESTS.md)
|
|
sewer.run_hooks(:setup, self)
|
|
eventPlayEnd
|
|
end
|
|
|
|
# Event 2 of the Deep Sewer (NapEvent, set_as_nap_event)
|
|
def lonacraft_sewer_nap
|
|
$game_portraits.lprt.hide
|
|
sewer = LonaCraft::Sewer
|
|
if sewer.run_hooks(:nap, self).include?(:skip_roll)
|
|
$story_stats["OnRegionMapSpawnRace"] = 0 # a quest took this nap over
|
|
p "LonaCraft Sewer: nap roll skipped by a quest hook"
|
|
else
|
|
sewer.nap_roll
|
|
end
|
|
handleNap
|
|
$game_player.actor.set_action_state(:none)
|
|
end
|
|
end
|