XRWS           &¸   ï  %Éext_01.cat ext_01.dat aiscripts/interrupt.disengage.xml 287 1615917843 d94322638718f63dc0c44de6ce311702
aiscripts/lib.target.selection.xml 431 1714166704 772f4c512ee0dfda8a7378b6c9a81272
md/escape_teleporter.xml 8955 1620755150 397f6f5f3c77c26b12e1a1830919360a
<?xml version="1.0" encoding="utf-8"?>
<diff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <replace sel="//handler/conditions/check_any/check_all/check_value[@value='$target.isindestructible']/@value">$target.isindestructible and not $target.isplayerowned</replace>
</diff><?xml version="1.0" encoding="utf-8"?>
<diff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <replace sel="//do_for_each[@name='$target']/do_elseif[@value='$target.isindestructible and (not this.isplayerowned or @this.assignedcontrolled.order.$internalorder)']/@value">$target.isindestructible and not $target.isplayerowned and (not this.isplayerowned or @this.assignedcontrolled.order.$internalorder)</replace>
</diff><?xml version="1.0" encoding="utf-8"?>
<mdscript name="EscapeTeleporter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../extracted/md/md.xsd">
  <cues>
    <cue name="TeleportInit">
      <actions>
        <!-- the group only has one element (the ship the player is in) but by using a group we don't have to restart the event tracker when it changes -->
        <create_group groupname="$PlayerShip"/>
        <do_if value="player.ship.exists">
          <add_to_group groupname="$PlayerShip" object="player.ship"/>
          <set_object_min_hull object="player.ship" exact="1"/>
        </do_if>
      </actions>
      <cues>
        <!-- it seems set_object_min_hull is not saved, so we need to reapply it on load -->
        <cue name="GameLoaded" instantiate="true">
          <conditions>
            <event_game_loaded/>
          </conditions>
          <actions>
            <do_if value="$PlayerShip.count gt 0 and $PlayerShip.{1} == player.ship">
              <set_object_min_hull object="$PlayerShip.{1}" exact="1"/>
            </do_if>
          </actions>
        </cue>
        <cue name="PlayerMoved" instantiate="true">
          <conditions>
            <check_any>
              <event_object_changed_object object="player.entity"/>
              <event_object_changed_room object="player.entity"/>
              <event_object_changed_zone object="player.entity"/>
            </check_any>
            <check_value value="$PlayerShip.count == 0 or $PlayerShip.{1} != player.ship"/>
          </conditions>
          <actions>
            <do_if value="$PlayerShip.count gt 0">
              <set_object_min_hull object="$PlayerShip.{1}" exact="0"/>
            </do_if>
            <clear_group group="$PlayerShip"/>
            <do_if value="player.ship.exists">
              <add_to_group groupname="$PlayerShip" object="player.ship"/>
              <set_object_min_hull object="$PlayerShip.{1}" exact="1"/>
            </do_if>
          </actions>
        </cue>
        <!-- must set $Attacked and $Instigator before including-->
        <library name="HandleTeleport">
          <actions>
            <!-- this is first because I'm concerned teleport_player may trigger an event immediately and potentially remove the indestructible setting early -->
            <remove_from_group group="$PlayerShip" object="$Attacked"/>
            <!-- extra failsafe just to be sure -->
            <do_if value="$Attacked == player.ship">
              <!-- teleport! -->
              <find_ship_by_true_owner name="$OtherShips" multiple="true" space="player.galaxy" faction="faction.player" unit="false">
                <match shiptype="shiptype.lasertower" negate="true"/>
                <match class="class.ship_xs" negate="true"/>
                <match_gate_distance object="player.ship" min="0" max="100" comment="fail if the ship is unreachable"/>
              </find_ship_by_true_owner>
              <remove_from_list name="$OtherShips" exact="$Attacked"/>
              <do_if value="$OtherShips.count == 0">
                <debug_text text="'Escape teleport failed - no targets'"/>
              </do_if>
              <do_else>
                <set_value name="$CandidateScores" exact="table[]"/>
                <do_all exact="$OtherShips.count" counter="$i">
                  <!-- lower values are better, this is basically a prioritized list of negatives -->
                  <set_value name="$CandidateScores.{$OtherShips.{$i}}" exact="16 * $OtherShips.{$i}.gatedistance.{$Attacked} + (if ($OtherShips.{$i}.sector != $Attacked.sector) then 8 else 0) + (if ($OtherShips.{$i}.class != $Attacked.class) then 4 else 0) + (if ($OtherShips.{$i}.primarypurpose != $Attacked.primarypurpose) then 2 else 0)"/>
                </do_all>
                <!-- if there is a tie for best and they're in the same sector, sort by raw distance (otherwise, pick random) -->
                <set_value name="$SortedShips" exact="$CandidateScores.keys.sorted"/>
                <set_value name="$BestScore" exact="$CandidateScores.{$SortedShips.{1}}"/>
                <do_all exact="$SortedShips.count - 1" counter="$i">
                  <do_if value="$CandidateScores.{$SortedShips.{$i + 1}} gt $BestScore">
                    <resize_list list="$SortedShips" count="$i"/>
                    <break/>
                  </do_if>
                </do_all>
                <set_value name="$NewShip" exact="$SortedShips.random"/>
                <do_if value="$NewShip.sector == $Attacked.sector">
                  <do_for_each name="$TestShip" in="$SortedShips">
                    <do_if value="$TestShip.distanceto.{$Attacked} lt $NewShip.distanceto.{$Attacked}">
                      <set_value name="$NewShip" exact="$TestShip"/>
                    </do_if>
                  </do_for_each>
                </do_if>
                <debug_text text="'Escape teleport player to ' + @$NewShip.name + ' in ' + @$NewShip.sector.name"/>
                <do_if value="$NewShip.exists">
                  <do_if value="@$NewShip.dock.isstorage">
                    <create_order id="'Undock'" object="$NewShip" immediate="true">
                      <param name="skipwait" value="true"/>
                    </create_order>
                  </do_if>
                  <teleport_player object="$NewShip" instant="true"/>
                  <!-- TODO: should play some postmortem effect at least, but couldn't get <add_effect> to do anything -->
                </do_if>
              </do_else>
            </do_if>
            <debug_text text="'FinishOffShip: ' + $Attacked.name + ' - ' + @$Instigator.name"/>
            <signal_cue_instantly cue="FinishOffShip" param="[$Attacked, $Instigator]"/>
          </actions>
        </library>
        <cue name="DamageCheck" instantiate="true">
          <conditions>
            <event_object_attacked group="$PlayerShip"/>
            <set_value name="$Attacked" exact="event.object"/>
            <set_value name="$Instigator" exact="event.param"/>
            <check_value value="$Attacked.hullpercentage lt 2"/>
          </conditions>
          <actions>
            <include_actions ref="HandleTeleport"/>
          </actions>
        </cue>
        <!-- event_object_hull_damaged comes in before event_object_attacked so we need to give that a chance to go first because it has attacker information
             we really only want to use this cue for hazard damage
          -->
        <cue name="HazardCheck" instantiate="true">
          <conditions>
            <event_object_hull_damaged group="$PlayerShip"/>
            <check_value value="event.object == event.param"/>
            <check_value value="event.object.hullpercentage lt 2"/>
            <!-- warning: static namespace! -->
            <check_value value="event.object != @$CheckHazardVictim"/>
          </conditions>
          <actions>
            <set_value name="$CheckHazardVictim" exact="event.object"/>
            <set_value name="this.$HazardVictim" exact="event.object"/>
          </actions>
          <cues>
            <cue name="HazardCheckInternal">
              <delay exact="1s"/>
              <actions>
                <do_if value="$PlayerShip.indexof.{parent.$HazardVictim} gt 0">
                  <set_value name="$Attacked" exact="parent.$HazardVictim"/>
                  <set_value name="$Instigator" exact="null"/>
                  <include_actions ref="HandleTeleport"/>
                </do_if>
              </actions>
            </cue>
          </cues>
        </cue>
        <!-- processes the destruction of the ship we initially protected from it after a delay to make sure the player teleport went off -->
        <cue name="FinishOffShip" instantiate="true" namespace="this">
          <conditions>
            <event_cue_signalled/>
          </conditions>
          <actions>
            <set_value name="$Attacked" exact="event.param.{1}"/>
            <set_value name="$Instigator" exact="event.param.{2}"/>
          </actions>
          <cues>
            <cue name="FinishOffShipInternal">
              <delay exact="1ms"/>
              <actions>
                <set_object_min_hull object="$Attacked" exact="0"/>
                <do_if value="$Instigator.exists and $Instigator.isclass.defensible">
                  <apply_attackstrength object="$Attacked" attacker="$Instigator" strength="$Attacked.hull"/>
                </do_if>
                <do_elseif value="$Attacked.exists and $Attacked.isoperational">
                  <destroy_object object="$Attacked" explosion="true"/>
                </do_elseif>
              </actions>
            </cue>
          </cues>
        </cue>
      </cues>
    </cue>
  </cues>
</mdscript><?xml version="1.0" encoding="utf-8"?>
<content id="" author="Mysterial (mysterial@mysterial.net)" name="" description="" version="131" date="2024-06-13" save="false" lastupdate="">
</content>
