XRWS           G‡   „  Gext_01.cat ext_01.dat md/fleet_apologize.xml 17768 1785279787 406c79a61ee9561f95677902d39c504b
t/0001.xml 411 1783823808 2732f7a2059a604ca763ec9537fda4c3
<?xml version="1.0" encoding="utf-8"?>
<mdscript name="FleetApologize" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
  <cues>
    <cue name="FleetApologizeRoot">
      <cues>
        <cue name="InteractMenu_AddAction" instantiate="true">
          <conditions>
            <event_cue_signalled cue="md.Interact_Menu_API.Get_Actions"/>
          </conditions>
          <actions>
            <set_value name="$target" exact="@event.param.$object"/>
            <do_if value="$target.exists and $target.isclass.ship and not $target.isplayerowned and not $target.isunit">
              <run_actions ref="FleetApologize_SectorHasTempHostile" result="$show">
                <param name="Ship" value="$target"/>
              </run_actions>
              <do_if value="$show">
                <set_value name="$section" exact="if @event.param.$showPlayerInteractions then 'player_interaction' else 'interaction'"/>
                <signal_cue_instantly cue="md.Interact_Menu_API.Add_Action" param="table[
                  $id = 'fleet_apologize',
                  $section = $section,
                  $text = {802901,1},
                  $mouseover = {802901,2},
                  $callback = InteractMenu_OnApologize,
                ]"/>
              </do_if>
            </do_if>
          </actions>
        </cue>

        <cue name="InteractMenu_OnApologize" instantiate="true">
          <conditions>
            <event_cue_signalled/>
          </conditions>
          <actions>
            <set_value name="$target" exact="@event.param.$object"/>
            <do_if value="$target.exists and $target.isclass.ship">
              <run_actions ref="FleetApologize_Apply">
                <param name="Ship" value="$target"/>
                <param name="MenuShips" value="@event.param.$selectedplayerships"/>
              </run_actions>
              <show_notification text="{802901,3}" sound="notification_success"/>
            </do_if>
          </actions>
        </cue>

        <!-- Recover ships left idle by older apologize versions that forced a permanent Wait default. -->
        <cue name="RecoverStuckWaits_OnLoad" instantiate="true">
          <conditions>
            <event_game_loaded/>
          </conditions>
          <delay exact="15s"/>
          <actions>
            <do_if value="player.sector">
              <run_actions ref="FleetApologize_RecoverSectorWaits">
                <param name="Sector" value="player.sector"/>
              </run_actions>
            </do_if>
          </actions>
        </cue>

        <cue name="RecoverStuckWaits_SectorChange" instantiate="true">
          <conditions>
            <event_object_changed_sector object="player.entity"/>
          </conditions>
          <delay exact="5s"/>
          <actions>
            <do_if value="player.sector">
              <run_actions ref="FleetApologize_RecoverSectorWaits">
                <param name="Sector" value="player.sector"/>
              </run_actions>
            </do_if>
          </actions>
        </cue>
      </cues>
    </cue>

    <library name="FleetApologize_FactionStillFriendly" purpose="run_actions">
      <params>
        <param name="Faction"/>
      </params>
      <actions>
        <return value="$Faction and $Faction != faction.ownerless and ($Faction.hasrelation.friend.{faction.player} or $Faction.hasrelation.neutral.{faction.player})"/>
      </actions>
    </library>

    <library name="FleetApologize_GetSectorFactionShips" purpose="run_actions">
      <params>
        <param name="ReferenceShip"/>
      </params>
      <actions>
        <set_value name="$sector" exact="@$ReferenceShip.sector"/>
        <set_value name="$faction" exact="$ReferenceShip.owner"/>
        <create_list name="$ships"/>
        <run_actions ref="FleetApologize_FactionStillFriendly" result="$friendlyFaction">
          <param name="Faction" value="$faction"/>
        </run_actions>
        <do_if value="$sector and $friendlyFaction">
          <!-- Include defence drones (isunit) so they receive the same reset as their parent ships. -->
          <find_ship name="$found" space="$sector" owner="$faction" class="class.ship" multiple="true"/>
          <do_for_each name="$ship" in="$found">
            <do_if value="$ship.isoperational and not $ship.isplayerowned">
              <do_if value="not $ships.indexof.{$ship}">
                <append_to_list name="$ships" exact="$ship"/>
              </do_if>
            </do_if>
          </do_for_each>
          <!-- Catch deployed units still listed as subordinates if find_ship missed them. -->
          <create_list name="$extraUnits"/>
          <do_for_each name="$ship" in="$ships">
            <do_if value="not $ship.isunit and @$ship.allsubordinates.count">
              <do_for_each name="$sub" in="$ship.allsubordinates">
                <do_if value="$sub.isoperational and $sub.isunit and not $sub.isplayerowned and not $ships.indexof.{$sub} and not $extraUnits.indexof.{$sub}">
                  <append_to_list name="$extraUnits" exact="$sub"/>
                </do_if>
              </do_for_each>
            </do_if>
          </do_for_each>
          <do_for_each name="$unit" in="$extraUnits">
            <append_to_list name="$ships" exact="$unit"/>
          </do_for_each>
        </do_if>
        <return value="$ships"/>
      </actions>
    </library>

    <library name="FleetApologize_CollectPlayerShips" purpose="run_actions">
      <params>
        <param name="MenuShips"/>
        <param name="Sector"/>
      </params>
      <actions>
        <create_list name="$ships"/>
        <do_if value="@$MenuShips.count">
          <do_for_each name="$ship" in="$MenuShips">
            <do_if value="$ship.exists and $ship.isoperational and $ship.isclass.ship and not $ship.isunit">
              <do_if value="not $ships.indexof.{$ship}">
                <append_to_list name="$ships" exact="$ship"/>
              </do_if>
            </do_if>
          </do_for_each>
        </do_if>
        <do_if value="player.ship.exists and player.ship.isoperational and player.ship.isclass.ship">
          <do_if value="not $ships.indexof.{player.ship}">
            <append_to_list name="$ships" exact="player.ship"/>
          </do_if>
        </do_if>
        <do_if value="player.occupiedship.exists and player.occupiedship.isoperational and player.occupiedship.isclass.ship">
          <do_if value="not $ships.indexof.{player.occupiedship}">
            <append_to_list name="$ships" exact="player.occupiedship"/>
          </do_if>
        </do_if>
        <do_if value="$Sector">
          <!-- Include player defence drones so cease-fire / boost clears apply to them too. -->
          <find_ship name="$sectorShips" space="$Sector" owner="faction.player" class="class.ship" multiple="true"/>
          <do_for_each name="$ship" in="$sectorShips">
            <do_if value="$ship.isoperational">
              <do_if value="not $ships.indexof.{$ship}">
                <append_to_list name="$ships" exact="$ship"/>
              </do_if>
              <do_if value="not $ship.isunit and @$ship.allsubordinates.count">
                <do_for_each name="$sub" in="$ship.allsubordinates">
                  <do_if value="$sub.isoperational and $sub.isclass.ship and not $ships.indexof.{$sub}">
                    <append_to_list name="$ships" exact="$sub"/>
                  </do_if>
                </do_for_each>
              </do_if>
            </do_if>
          </do_for_each>
        </do_if>
        <return value="$ships"/>
      </actions>
    </library>

    <library name="FleetApologize_IsTempHostile" purpose="run_actions">
      <params>
        <param name="Ship"/>
      </params>
      <actions>
        <set_value name="$owner" exact="$Ship.owner"/>
        <set_value name="$result" exact="false"/>
        <!-- Units (defence drones) count as temp-hostile so sector checks notice angry drones. -->
        <do_if value="$Ship.isoperational and $Ship.isclass.ship and not $Ship.isplayerowned and $owner and $owner != faction.ownerless and $Ship.ishostileto.{faction.player}">
          <do_if value="$owner.hasrelation.friend.{faction.player} or $owner.hasrelation.neutral.{faction.player}">
            <set_value name="$result" exact="true"/>
          </do_if>
        </do_if>
        <return value="$result"/>
      </actions>
    </library>

    <library name="FleetApologize_SectorHasTempHostile" purpose="run_actions">
      <params>
        <param name="Ship"/>
      </params>
      <actions>
        <run_actions ref="FleetApologize_GetSectorFactionShips" result="$ships">
          <param name="ReferenceShip" value="$Ship"/>
        </run_actions>
        <set_value name="$found" exact="false"/>
        <do_for_each name="$candidate" in="$ships">
          <run_actions ref="FleetApologize_IsTempHostile" result="$isHostile">
            <param name="Ship" value="$candidate"/>
          </run_actions>
          <do_if value="$isHostile">
            <set_value name="$found" exact="true"/>
            <break/>
          </do_if>
        </do_for_each>
        <return value="$found"/>
      </actions>
    </library>

    <library name="FleetApologize_ClearObjectBoosts" purpose="run_actions">
      <params>
        <param name="Object"/>
        <param name="OtherShips"/>
      </params>
      <actions>
        <reset_relation_boost object="$Object" faction="faction.player"/>
        <reset_tolerance_boost object="$Object" faction="faction.player"/>
        <do_if value="player.entity.exists">
          <reset_relation_boost object="$Object" otherobject="player.entity"/>
          <reset_tolerance_boost object="$Object" otherobject="player.entity"/>
        </do_if>
        <do_for_each name="$other" in="$OtherShips">
          <do_if value="$other.exists and $other.isoperational">
            <reset_relation_boost object="$Object" otherobject="$other"/>
            <reset_relation_boost object="$other" otherobject="$Object"/>
            <reset_tolerance_boost object="$Object" otherobject="$other"/>
            <reset_tolerance_boost object="$other" otherobject="$Object"/>
          </do_if>
        </do_for_each>
      </actions>
    </library>

    <library name="FleetApologize_ResetSurfaceElements" purpose="run_actions">
      <params>
        <param name="Ship"/>
        <param name="OtherShips"/>
      </params>
      <actions>
        <find_object_component name="$components" object="$Ship" class="[class.turret, class.weapon]" multiple="true"/>
        <do_for_each name="$component" in="$components">
          <run_actions ref="FleetApologize_ClearObjectBoosts">
            <param name="Object" value="$component"/>
            <param name="OtherShips" value="$OtherShips"/>
          </run_actions>
        </do_for_each>
      </actions>
    </library>

    <library name="FleetApologize_RestoreIdleShip" purpose="run_actions">
      <params>
        <param name="Ship"/>
      </params>
      <actions>
        <!-- Older apologize versions forced a permanent Wait default. Cancel it and restore normal work. -->
        <do_if value="$Ship.isoperational and $Ship.isclass.ship and not $Ship.isplayerowned and not $Ship.isunit and @$Ship.defaultorder.id == 'Wait'">
          <cancel_order order="$Ship.defaultorder"/>
          <do_if value="$Ship.islasertower">
            <create_order id="'Lasertower'" object="$Ship" default="true"/>
          </do_if>
          <do_elseif value="$Ship.commander.isoperational">
            <!-- Re-assert commander so lib.request.orders recreates Escort/Trade/Protect for their assignment. -->
            <create_order id="'AssignCommander'" object="$Ship" immediate="true">
              <param name="commander" value="$Ship.commander"/>
              <param name="cancelorders" value="false"/>
            </create_order>
          </do_elseif>
          <do_elseif value="$Ship.primarypurpose == purpose.mine">
            <create_order id="'MiningRoutine'" object="$Ship" default="true">
              <param name="warebasket" value="if @$Ship.warebasket.count then $Ship.warebasket.list else []"/>
            </create_order>
          </do_elseif>
          <do_elseif value="$Ship.primarypurpose == purpose.trade">
            <create_order id="'TradeRoutine'" object="$Ship" default="true">
              <param name="warebasket" value="if @$Ship.warebasket.count then $Ship.warebasket.list else []"/>
              <param name="maxbuy" value="3"/>
              <param name="maxsell" value="3"/>
            </create_order>
          </do_elseif>
          <do_elseif value="$Ship.primarypurpose == purpose.build">
            <create_order id="'FindBuildTasks'" object="$Ship" default="true">
              <param name="maxjumps" value="5"/>
            </create_order>
          </do_elseif>
          <do_else>
            <create_order id="'Patrol'" object="$Ship" default="true">
              <param name="range" value="class.sector"/>
            </create_order>
          </do_else>
        </do_if>
      </actions>
    </library>

    <library name="FleetApologize_RecoverSectorWaits" purpose="run_actions">
      <params>
        <param name="Sector"/>
      </params>
      <actions>
        <do_if value="$Sector">
          <find_ship name="$found" space="$Sector" class="class.ship" multiple="true"/>
          <do_for_each name="$ship" in="$found">
            <do_if value="$ship.isoperational and not $ship.isplayerowned and not $ship.isunit">
              <run_actions ref="FleetApologize_RestoreIdleShip">
                <param name="Ship" value="$ship"/>
              </run_actions>
            </do_if>
          </do_for_each>
        </do_if>
      </actions>
    </library>

    <library name="FleetApologize_ResetNpcShip" purpose="run_actions">
      <params>
        <param name="Ship"/>
        <param name="PlayerShips"/>
        <param name="NpcShips"/>
      </params>
      <actions>
        <do_if value="$Ship.isoperational and $Ship.isclass.ship and not $Ship.isplayerowned">
          <cease_fire object="$Ship"/>
          <!-- Cancel only combat interrupt orders. Do not wipe the default job/patrol/trade order or force Wait. -->
          <do_if value="@$Ship.orders.count">
            <do_for_each name="$order" in="$Ship.orders" reverse="true">
              <do_if value="$order.exists and ($order.id == 'Attack' or $order.id == 'Attack_Player' or $order.id == 'AttackInRange')">
                <cancel_order order="$order"/>
              </do_if>
            </do_for_each>
          </do_if>
          <!-- Wait recovery is for real ships only; drones keep their unit AI. -->
          <do_if value="not $Ship.isunit">
            <run_actions ref="FleetApologize_RestoreIdleShip">
              <param name="Ship" value="$Ship"/>
            </run_actions>
          </do_if>
          <run_actions ref="FleetApologize_ClearObjectBoosts">
            <param name="Object" value="$Ship"/>
            <param name="OtherShips" value="$PlayerShips"/>
          </run_actions>
          <run_actions ref="FleetApologize_ClearObjectBoosts">
            <param name="Object" value="$Ship"/>
            <param name="OtherShips" value="$NpcShips"/>
          </run_actions>
          <do_if value="not $Ship.isunit">
            <run_actions ref="FleetApologize_ResetSurfaceElements">
              <param name="Ship" value="$Ship"/>
              <param name="OtherShips" value="$PlayerShips"/>
            </run_actions>
          </do_if>
          <set_relation_boost object="$Ship" faction="faction.player" value="1.0" decay="0.02" delay="60s" silent="true"/>
        </do_if>
      </actions>
    </library>

    <library name="FleetApologize_ResetPlayerShip" purpose="run_actions">
      <params>
        <param name="Ship"/>
        <param name="NpcShips"/>
      </params>
      <actions>
        <do_if value="$Ship.isoperational and $Ship.isclass.ship and $Ship.isplayerowned">
          <cease_fire object="$Ship"/>
          <run_actions ref="FleetApologize_ClearObjectBoosts">
            <param name="Object" value="$Ship"/>
            <param name="OtherShips" value="$NpcShips"/>
          </run_actions>
          <run_actions ref="FleetApologize_ResetSurfaceElements">
            <param name="Ship" value="$Ship"/>
            <param name="OtherShips" value="$NpcShips"/>
          </run_actions>
        </do_if>
      </actions>
    </library>

    <library name="FleetApologize_Apply" purpose="run_actions">
      <params>
        <param name="Ship"/>
        <param name="MenuShips"/>
      </params>
      <actions>
        <set_value name="$sector" exact="@$Ship.sector"/>
        <run_actions ref="FleetApologize_GetSectorFactionShips" result="$npcShips">
          <param name="ReferenceShip" value="$Ship"/>
        </run_actions>
        <run_actions ref="FleetApologize_CollectPlayerShips" result="$playerShips">
          <param name="MenuShips" value="$MenuShips"/>
          <param name="Sector" value="$sector"/>
        </run_actions>
        <do_for_each name="$npc" in="$npcShips">
          <run_actions ref="FleetApologize_ResetNpcShip">
            <param name="Ship" value="$npc"/>
            <param name="PlayerShips" value="$playerShips"/>
            <param name="NpcShips" value="$npcShips"/>
          </run_actions>
        </do_for_each>
        <do_for_each name="$playerShip" in="$playerShips">
          <run_actions ref="FleetApologize_ResetPlayerShip">
            <param name="Ship" value="$playerShip"/>
            <param name="NpcShips" value="$npcShips"/>
          </run_actions>
        </do_for_each>
      </actions>
    </library>
  </cues>
</mdscript>
<?xml version="1.0" encoding="UTF-8"?>
<language xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="44" xsi:noNamespaceSchemaLocation="aiscripts.xsd">
<page id="802901" voice="no">
<t id="1">Apologize</t>
<t id="2">Calm all ships of this faction in the sector. Only works while your faction standing with them is still neutral or friendly.</t>
<t id="3">Fleet relations restored.</t>
</page>
</language>
<?xml version="1.0" encoding="utf-8"?>
<content id="" name="" description="" author="SOS-Games" version="104" date="2026-07-28" save="0" lastupdate="">
  <text language="44" name="Fleet Apologize" description="Apologize to temporarily hostile NPC fleets and their defence drones via the right-click menu." author="SOS-Games"/>
  <dependency id="ws_2042901274" version="100" optional="false" name="SirNukes Mod Support APIs"/>
  <dependency id="ego_dlc_terran" version="100" optional="true" name="Cradle of Humanity"/>
  <dependency id="ego_dlc_split" version="100" optional="true" name="Split Vendetta"/>
  <dependency id="ego_dlc_boron" version="100" optional="true" name="Kingdom End"/>
  <dependency id="ego_dlc_pirate" version="100" optional="true" name="Tides of Avarice"/>
  <dependency id="ego_dlc_timelines" version="100" optional="true" name="Timelines"/>
</content>
