XRWS           1Ü   ê  0òext_01.cat ext_01.dat md/drjele_khaak_pressure.xml 7054 1790265324 1f6e7f96030be9d7de8de37f4c500256
md/drjele_khaak_pressure_options.xml 4909 1790265324 023ac8d5c831432322ade213c647aab8
md/khaak_activity.xml 567 1790265324 96e9cfab8c1e04d8eb09efcc1a595081
<?xml version="1.0" encoding="utf-8"?>
<mdscript name="DrJele_KhaakPressure" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
    <cues>

        <cue name="Configuration" instantiate="true" namespace="static" version="1">
            <conditions>
                <event_cue_signalled cue="md.Setup.Start"/>
            </conditions>
            <actions>
                <set_value name="$HiveGateRange" exact="3" comment="gate jumps within which a hive may place an outpost, and the radius of the sectors it watches; 3 is vanilla"/>
                <set_value name="$OutpostThreshold" exact="50000" comment="mining activity a sector must reach before the Kha'ak look for somewhere to place an outpost; 50000 is vanilla"/>
                <set_value name="$SpawnChanceFactor" exact="1" comment="multiplies the chance that mining next to an outpost spawns a Kha'ak group; 1 is vanilla"/>
                <set_value name="$DebugChance" exact="0" comment="100 writes every applied change to the debug log"/>

                <set_value name="global.$DrJeleKhaakPressureConfig" exact="table[$HiveGateRange     = $HiveGateRange,
                                                                          $OutpostThreshold  = $OutpostThreshold,
                                                                          $SpawnChanceFactor = $SpawnChanceFactor,
                                                                          $DebugChance       = $DebugChance]"/>
            </actions>
        </cue>

        <cue name="Apply" instantiate="true" version="1">
            <conditions>
                <event_cue_signalled cue="md.Setup.Start"/>
                <check_value value="macro.xu_ep2_universe_macro == player.galaxy.macro" comment="the same guard the vanilla manager uses; without it the child below would poll forever in a Timelines scenario, a tutorial or the workshop map, where the Kha'ak manager never initialises"/>
            </conditions>
            <cues>
                <cue name="ApplyWhenManagerReady" checkinterval="5s">
                    <conditions>
                        <check_value value="md.Khaak_Activity.Manager.$HiveStationGateRange?"/>
                    </conditions>
                    <actions>
                        <include_actions ref="ApplySettings"/>
                    </actions>
                </cue>
            </cues>
        </cue>

        <!-- Signalled by the options menu when a slider moves. -->
        <cue name="Reapply" instantiate="true">
            <conditions>
                <event_cue_signalled/>
                <check_value value="md.Khaak_Activity.Manager.$HiveStationGateRange?"/>
            </conditions>
            <actions>
                <include_actions ref="ApplySettings"/>
            </actions>
        </cue>

        <library name="ApplySettings">
            <actions>
                <set_value name="$Config" exact="if global.$DrJeleKhaakPressureConfig? then global.$DrJeleKhaakPressureConfig else table[]"/>
                <set_value name="$DebugChance" exact="if global.$DrJeleKhaakDebugChance? then global.$DrJeleKhaakDebugChance else (if $Config.$DebugChance? then $Config.$DebugChance else 0)"/>

                <set_value name="$GateRange" exact="if global.$DrJeleKhaakHiveGateRange? then global.$DrJeleKhaakHiveGateRange else (if $Config.$HiveGateRange? then $Config.$HiveGateRange else 3)"/>
                <set_value name="$Threshold" exact="if global.$DrJeleKhaakOutpostThreshold? then global.$DrJeleKhaakOutpostThreshold else (if $Config.$OutpostThreshold? then $Config.$OutpostThreshold else 50000)"/>

                <set_value name="$MinThreshold" exact="$Threshold / 2"/>

                <set_value name="md.Khaak_Activity.Manager.$SpawnOutpostThreshold" exact="$Threshold"/>
                <set_value name="md.Khaak_Activity.Manager.$MinSpawnOutpostThreshold" exact="$MinThreshold"/>
                <debug_text text="'DrJele Khaak Pressure: applied gate range %s, outpost threshold %s (min %s), watching %s sectors'.[$GateRange, $Threshold, $MinThreshold, md.Khaak_Activity.Manager.$WatchedSectors.count]" chance="$DebugChance"/>

                <do_if value="md.Khaak_Activity.Manager.$HiveStationGateRange != $GateRange">
                    <debug_text text="'DrJele Khaak Pressure: gate range %s -> %s, outpost threshold %s (min %s)'.[md.Khaak_Activity.Manager.$HiveStationGateRange, $GateRange, $Threshold, $MinThreshold]" chance="$DebugChance"/>
                    <set_value name="md.Khaak_Activity.Manager.$HiveStationGateRange" exact="$GateRange"/>
                    <include_actions ref="RebuildWatchedSectors"/>
                </do_if>
            </actions>
        </library>

        <library name="RebuildWatchedSectors">
            <actions>
                <set_value name="$DebugChance" exact="if global.$DrJeleKhaakDebugChance? then global.$DrJeleKhaakDebugChance else (if global.$DrJeleKhaakPressureConfig? then global.$DrJeleKhaakPressureConfig.$DebugChance else 0)"/>
                <set_value name="$ValidSectors" exact="[]"/>
                <do_for_each name="$Hive" in="md.Khaak_Activity.Manager.$HiveStations">
                    <find_sector_in_range name="$ValidSectors" object="$Hive"
                                          excluded="md.Khaak_Activity.Manager.$IgnoredSectors"
                                          maxdistance="md.Khaak_Activity.Manager.$HiveStationGateRange"
                                          multiple="true" append="true"/>
                </do_for_each>
                <do_for_each name="$Outpost" in="md.Khaak_Activity.Manager.$Outposts">
                    <append_to_list name="$ValidSectors" exact="$Outpost.sector"/>
                </do_for_each>

                <!-- Groups are sets, so adding one that is already in is free. -->
                <do_for_each name="$Sector" in="$ValidSectors">
                    <add_to_group groupname="md.Khaak_Activity.Manager.$WatchedSectors" object="$Sector"/>
                </do_for_each>

                <set_value name="$OldSectors" exact="md.Khaak_Activity.Manager.$WatchedSectors.list"/>
                <do_for_each name="$Sector" in="$OldSectors">
                    <do_if value="0 == $ValidSectors.indexof.{$Sector}">
                        <remove_value name="md.Khaak_Activity.Manager.$SectorMiningActivityTable.{$Sector}"/>
                        <remove_value name="md.Khaak_Activity.Manager.$SectorKhaakActivityTable.{$Sector}"/>
                        <remove_from_group group="md.Khaak_Activity.Manager.$WatchedSectors" object="$Sector"/>
                    </do_if>
                </do_for_each>

                <debug_text text="'DrJele Khaak Pressure: watching %s sectors after rebuild'.[md.Khaak_Activity.Manager.$WatchedSectors.count]" chance="$DebugChance"/>

                <remove_value name="$ValidSectors"/>
                <remove_value name="$OldSectors"/>
            </actions>
        </library>

    </cues>
</mdscript>
<?xml version="1.0" encoding="utf-8"?>
<mdscript name="DrJele_KhaakPressureOptions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
    <cues>

        <cue name="RegisterOptions" instantiate="true" version="1">
            <conditions>
                <event_cue_signalled cue="md.Simple_Menu_Options.Reloaded"/>
            </conditions>
            <actions>
                <signal_cue_instantly
                        cue="md.Simple_Menu_Options.Register_Option"
                        param="table[
            $id        = 'drjele_khaak_hive_gate_range_jumps',
            $category  = 'Khaak Pressure',
            $name      = 'Hive reach',
            $mouseover = 'How many gate jumps from one of their hives the Kha\'ak will watch a sector and place an outpost in it. Vanilla is 3. Raising it lets them follow your mining much further out; at 10 they watch most of the galaxy, which costs some CPU on the once-a-minute evaluation.',
            $type      = 'slidercell',
            $default   = 3,
            $args      = table[$min = 3, $max = 10, $step = 1, $suffix = ' jumps'],
            $callback  = OnHiveGateRangeChanged,
            ]"/>
                <signal_cue_instantly
                        cue="md.Simple_Menu_Options.Register_Option"
                        param="table[
            $id        = 'drjele_khaak_outpost_threshold_points',
            $category  = 'Khaak Pressure',
            $name      = 'Outpost cost',
            $mouseover = 'Mining activity a sector has to build up before the Kha\'ak look for somewhere to plant an outpost. Vanilla is 50000, which is roughly 20000 units of silicon mined by you in one sector. Lower means they come sooner. The floor a sector needs to be considered at all is always half this number.',
            $type      = 'slidercell',
            $default   = 50000,
            $args      = table[$min = 10000, $max = 50000, $step = 5000],
            $callback  = OnOutpostThresholdChanged,
            ]"/>
                <signal_cue_instantly
                        cue="md.Simple_Menu_Options.Register_Option"
                        param="table[
            $id        = 'drjele_khaak_spawn_chance_factor_x',
            $category  = 'Khaak Pressure',
            $name      = 'Ambush chance multiplier',
            $mouseover = 'Multiplies the chance that mining an asteroid drops a Kha\'ak group on top of you. Vanilla is 1x, which is 0.03 percent per mined unit at full sector activity. Only applies in sectors that already hold a Kha\'ak outpost - elsewhere the chance is zero whatever this says.',
            $type      = 'slidercell',
            $default   = 1,
            $args      = table[$min = 1, $max = 100, $step = 1, $suffix = 'x'],
            $callback  = OnSpawnChanceFactorChanged,
            ]"/>
                <signal_cue_instantly
                        cue="md.Simple_Menu_Options.Register_Option"
                        param="table[
            $id        = 'drjele_khaak_pressure_debug',
            $category  = 'Khaak Pressure',
            $name      = 'Debug logging',
            $mouseover = 'Writes every applied setting and every rebuild of the watched sectors to the debug log. Needs the game started with -debug scripts.',
            $type      = 'button',
            $default   = 0,
            $callback  = OnDebugChanged,
            ]"/>
            </actions>
        </cue>

        <cue name="OnHiveGateRangeChanged" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            <actions>
                <set_value name="global.$DrJeleKhaakHiveGateRange" exact="event.param.$value"/>
                <signal_cue_instantly cue="md.DrJele_KhaakPressure.Reapply"/>
            </actions>
        </cue>

        <cue name="OnOutpostThresholdChanged" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            <actions>
                <set_value name="global.$DrJeleKhaakOutpostThreshold" exact="event.param.$value"/>
                <signal_cue_instantly cue="md.DrJele_KhaakPressure.Reapply"/>
            </actions>
        </cue>

        <cue name="OnSpawnChanceFactorChanged" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            <actions>
                <set_value name="global.$DrJeleKhaakSpawnChanceFactor" exact="event.param.$value"/>
            </actions>
        </cue>

        <cue name="OnDebugChanged" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            <actions>
                <set_value name="global.$DrJeleKhaakDebugChance" exact="if event.param.$value then 100 else 0"/>
            </actions>
        </cue>

    </cues>
</mdscript>
<?xml version="1.0" encoding="utf-8"?>
<diff>

    <add sel="//library[@name='GetSuitableBaseStationForShipSpawn']/actions/do_if[@value='$CheckSectorChance']/set_value[@name='$BaseSpawnChance']" pos="after">
        <set_value name="$DrJeleSpawnFactor" exact="if global.$DrJeleKhaakSpawnChanceFactor? then global.$DrJeleKhaakSpawnChanceFactor else (if global.$DrJeleKhaakPressureConfig? then global.$DrJeleKhaakPressureConfig.$SpawnChanceFactor else 1)"/>
        <set_value name="$BaseSpawnChance" exact="$BaseSpawnChance * $DrJeleSpawnFactor"/>
    </add>

</diff>
<?xml version="1.0" encoding="utf-8"?>
<content id="" name="" description="" author="drjele" version="110" date="2026-09-24" save="0" lastupdate="">
  <text language="44" name="Khaak Pressure" description="Sliders for how far the Kha'ak reach and how hard they push: the gate range a hive can place outposts within, the mining activity an outpost costs, and a multiplier on the chance mining spawns a Kha'ak group. Works on an existing savegame."/>
  <dependency version="900"/>
  <dependency id="ws_2042901274" optional="true" name="SirNukes Mod Support APIs" comment="only for the in-game options menu; the mod works without it"/>
</content>
