XRWS           GÁ   ¶  Gext_01.cat ext_01.dat aiscripts/engineer.player.xml 18059 1457019593 877b01bfd45c8b276872ca69fd7d732c
assets/units/player/macros/unit_player_ship_macro.xml 128 1457015341 8d1cad0ec604c2683d2556a4d7ede1cd
<?xml version="1.0" encoding="utf-8" ?>
<diff>
  <replace sel="/aiscript[@name='engineer.player']">
<aiscript name="engineer.player" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="aiscripts.xsd" version="9">
  <params>
    <param name="debugoutputchance" default="0"/>
    <param name="debugoutputchance2" default="0"/>
  </params>
  <interrupts>
    <handler comment="Engineer hacked">
      <conditions>
        <event_object_signalled object="this.object" param="'engineer_hacked'" />
      </conditions>
      <actions>
        <debug_text text="'engineer_hacked'" chance="$debugoutputchance" />
        <set_value name="this.$hacked" exact="player.age + event.param2" />
      </actions>
    </handler>
  </interrupts>
  <init>
    <set_command command="command.repair" />
    <set_command_action commandaction="commandaction.repairchecking" />
  </init>
  <patch sinceversion="3">
    <set_value name="$baserepairrate" exact="50" />
  </patch>
  <patch sinceversion="8">
    <do_if value="this.defensible.exists">
      <find_active_repair_mass_traffic object="this.defensible" result="$networkid" />
    </do_if>
    <remove_value name="$networkcreated" />
  </patch>
  <patch sinceversion="9">
    <do_if value="this.defensible.isclass.station">
      <set_value name="$hulldamagelimit" exact="100" comment="below what percentage hull is a component considered damaged"/>
    </do_if>
    <do_else>
      <set_value name="$hulldamagelimit" exact="30 + (70 * this.combinedskill / 100)" comment="below what percentage hull is a component considered damaged (ship engineer repairs up to a value between 44% and 100%, dependent on skill)"/>
    </do_else>
  </patch>
  <attention min="unknown">
    <actions>
      <!--###REMOVED######
      Script rewrite in 1.19. Previous blocking actions set to chance="0"
      #######REMOVED######-->
      <wait exact="0s" chance="0"/>
      <wait exact="0s" chance="0"/>
      <wait exact="0s" chance="0"/>
      <wait exact="0s" sinceversion="2" chance="0" />
      <do_if value="$operationalelements?">
        <remove_value name="$operationalelements"/>
      </do_if>

      <!--Patch in value-->
      <do_if value="not $debugoutputchance2?">
        <set_value name="$debugoutputchance2" exact="0"/>
      </do_if>

      <!-- init -->
      <set_value name="$repairfrequency" exact="10s" />
      <set_value name="$nextelementcheck" exact="0" />
      <set_value name="$baserepairrate" exact="50" />
      <set_value name="$CurrentElement" exact="null"/>

      <label name="checkforrepair" />

      <do_if value="this.defensible.isclass.station">
        <set_value name="$hulldamagelimit" exact="100" comment="below what percentage hull is a component considered damaged"/>
      </do_if>
      <do_else>
        <set_value name="$hulldamagelimit" exact="30 + (70 * this.combinedskill / 100)" comment="below what percentage hull is a component considered damaged (ship engineer repairs up to a value between 44% and 100%, dependent on skill)"/>
      </do_else>

      <do_if value="player.age le @this.$hacked">
        <wait exact="@this.$hacked - player.age" sinceversion="4" />
      </do_if>

      <!-- If no elements or main hull to repair -->
      <do_if value="not $CurrentElement.exists and this.defensible.hullpercentage ge $hulldamagelimit">
        <wait min="1min" max="5min" sinceversion="3" />
      </do_if>

      <debug_text text="'Begin wait'" chance="$debugoutputchance2"/>
      <wait min="$repairfrequency" max="$repairfrequency + 1s" sinceversion="2"/>

      <set_value name="$Defensible" exact="this.defensible"/>

      <do_if value="$CurrentElement.exists">
        <do_if value="$CurrentElement.iswreck">
          <!--Do not fix wrecked components where the parent is also a wreck-->
          <do_if value="not $CurrentElement.parent.iswreck">
            <resume label="startrepair"/>
          </do_if>
        </do_if>

        <do_if value="$CurrentElement.hullpercentage lt $hulldamagelimit">
          <!--Have a chance to break out if the component is already functional again-->
          <do_if value="$CurrentElement.isfunctional">
            <resume label="startrepair" chance="70"/>
          </do_if>
          <do_else>
            <resume label="startrepair"/>
          </do_else>
        </do_if>
      </do_if>
      <set_value name="$CurrentElement" exact="null"/>

      <!--Find surface elements and put them in the correct lists/groups-->
      <!--This can be quite expensive so only do it once finished with the $CurrentElement-->
      <do_if value="player.age" min="$nextelementcheck">
        <set_value name="$nextelementcheck" min="player.age + 1min" max="player.age + 2min"/>
        <create_group groupname="$PossibleElements"/>
        <set_value name="$FindChance" exact="100"/>

        <!--If ship, find engines and jumpdrives - High priority-->
        <do_if value="$Defensible.isclass.ship">
          <find_object_component chance="$FindChance" groupname="$PossibleElements" object="$Defensible" class="[class.jumpdrive, class.engine]" checkoperational="false" multiple="true">
            <match_any>
              <match restorable="true" comment="wrecked"/>
              <match repairable="true" invulnerable="false">
                <match_hull min="$hulldamagelimit" negate="true" />
              </match>
            </match_any>
          </find_object_component>
        </do_if>
        <!--find large, non surface element destructibles-->
        <find_object_component chance="$FindChance" groupname="$PossibleElements" object="$Defensible" class="class.destructible" surfaceelement="false" checkoperational="false" multiple="true">
          <match class="[class.adsign, class.ship]" checkoperational="false" negate="true"/>
          <match_macro_children min="1" comment="Does this component have children, use macro so collapsed surface elements also count"/>
          <match_any>
            <match restorable="true" comment="wrecked"/>
            <match repairable="true" invulnerable="false">
              <match_hull min="$hulldamagelimit" negate="true" />
            </match>
          </match_any>
        </find_object_component>
        <debug_text text="$PossibleElements.count + ' priority things to repair found'" chance="$debugoutputchance2"/>
        <do_all exact="$PossibleElements.count" counter="$Counter" chance="$debugoutputchance2">
          <debug_text text="'Priority Destructible: ' + $PossibleElements.{$Counter} + ' ' + $PossibleElements.{$Counter}.macro.id"/>
        </do_all>
        <do_if value="$PossibleElements.count" min="1">
          <!--If something important was found there is only a small chance of finding something small to fix instead-->
          <!--TODO: Could be based on Engineer skill-->
          <set_value name="$FindChance" exact="5"/>
        </do_if>
        <!--A chance to find something small to fix. (100% if nothing important was found)-->
        <find_object_component chance="$FindChance" groupname="$PossibleElements" object="$Defensible" class="class.destructible" checkoperational="false" multiple="true">
          <match class="class.ship" checkoperational="false" negate="true"/>
          <match_any>
            <match restorable="true" comment="wrecked"/>
            <match repairable="true" invulnerable="false">
              <match_hull min="$hulldamagelimit" negate="true" />
            </match>
          </match_any>
        </find_object_component>
        <debug_text text="$PossibleElements.count + ' potential things to repair found'" chance="$debugoutputchance2"/>

        <do_if value="$PossibleElements.count" min="1">
          <set_value name="$MassTrafficTargets" exact="$PossibleElements.list"/>
          <set_value name="$CurrentElement" exact="$PossibleElements.random"/>
          <set_value name="$nextelementcheck" exact="0"/>
          <do_if value="$CurrentElement.iswreck">
            <debug_text text="'CurrentElement is now the wreck of ' + $CurrentElement + ' ' + $CurrentElement.knownname" chance="$debugoutputchance"/>
            <set_value name="$BaseRestoreTime" exact="($CurrentElement.size)s"/>
            <do_if value="$BaseRestoreTime" min="10min">
              <set_value name="$BaseRestoreTime" exact="10min" comment="cap time for large components"/>
            </do_if>
            <do_elseif value="$BaseRestoreTime" max="1min">
              <set_value name="$BaseRestoreTime" exact="1min" comment="cap time for small components"/>
            </do_elseif>
            <debug_text text="'BaseRestoreTime is ' + $BaseRestoreTime" chance="$debugoutputchance"/>
            <set_value name="$RestoreTime" min="player.age + $BaseRestoreTime" max="player.age + $BaseRestoreTime + 1s"/>
          </do_if>
          <do_else>
            <debug_text text="'CurrentElement is now the damaged ' + $CurrentElement + ' ' + $CurrentElement.knownname" chance="$debugoutputchance"/>
          </do_else>
        </do_if>
        <clear_group group="$PossibleElements"/>
      </do_if>

      <!--Check if there is nothing to fix-->
      <do_if value="not $CurrentElement.exists">
        <do_if value="$Defensible.hullpercentage ge $hulldamagelimit">
          <!--Remove mass traffic. Don't care about damaged summaries-->
          <debug_text text="$Defensible.knownname + ' is ending mass traffic (nothing left to repair)'" chance="$debugoutputchance" />
          <end_repair_mass_traffic object="$Defensible" />
          <remove_value name="$networkid" />

          <do_if value="$Defensible.summary.numadsigns.wreck
          + $Defensible.summary.numefficiencyupgrades.wreck
          + $Defensible.summary.numshields.wreck
          + $Defensible.summary.numsurfacedestructible.wreck
          + $Defensible.summary.numturrets.wreck" exact="0">

            <!-- set command action to repair checking -->
            <set_command_action commandaction="commandaction.repairchecking" />

            <resume label="checkforrepair"/>
          </do_if>
        </do_if>
      </do_if>

      <label name="startrepair" />
      <!-- send out the repair drones -->
      <do_if value="not @$networkid">
        <do_if value="not $MassTrafficTargets?">
          <set_value name="$MassTrafficTargets" exact="[$Defensible]" />
        </do_if>
        <launch_repair_drones object="$Defensible" target="$Defensible" components="$MassTrafficTargets" result="$networkid" />
        <debug_text text="$Defensible.knownname + ' launched mass traffic - network id: ' + $networkid" chance="$debugoutputchance" />
        <set_value name="$MassTrafficTargets" exact="[]"/>
      </do_if>

      <!-- calculate repair speed -->
      <set_value name="$repairratefactor" exact="0" />
      <do_if value="@$networkid">
        <find_active_repair_mass_traffic object="$Defensible" result="$networkid" />
        <get_units_in_mass_traffic masstraffic="$networkid" category="unitcategory.welder" amounts="$unitamounts" />

        <do_if value="$unitamounts">
          <do_all exact="unitcategory.welder.maxmk" counter="$i">
            <debug_text text="$unitamounts.{$i} + ' welders mk ' + $i" chance="$debugoutputchance" />
            <set_value name="$repairratefactor" operation="add" exact="$unitamounts.{$i} * $i" />
          </do_all>
          <remove_value name="$unitamounts" />
        </do_if>
      </do_if>
      <do_if value="$repairratefactor == 0">
        <do_if value="@$networkid">
          <debug_text text="$Defensible.knownname + ' is ending mass traffic (no more units are flying)'" chance="$debugoutputchance" />
          <end_repair_mass_traffic object="$Defensible" />
          <remove_value name="$networkid" />
        </do_if>
        <!-- if no welders are underway, repair 10 times more slowly than with just one mk1 drone -->
        <set_value name="$repairratefactor" exact="0.1" />
      </do_if>
      <set_value name="$repairratefactor" operation="add" exact="$repairratefactor * this.combinedskill / 25" comment="engineer speeds up repair by up to 400% (meaning a fifth of the normal repair time)" />

      <set_value name="$repairrate" exact="$baserepairrate * $repairratefactor" />
      <debug_text text="'Repairrate: ' + $repairrate" chance="$debugoutputchance" />

      <!--Fix summary components first-->
      <!--Currently only attempt to fix one. Only fix those which have an operational parent-->
      <!--TODO: Balance-->
      <do_if value="$Defensible.attention lt attention.visible">
        <do_if value="$Defensible.summary.numadsigns.wreck" min="1">
          <set_summarised_adsign_state object="$Defensible" state="operational" parentstate="operational" previous="wreck" exact="1"/>
        </do_if>
        <do_if value="$Defensible.summary.numefficiencyupgrades.wreck" min="1">
          <set_summarised_efficiencyupgrade_state object="$Defensible" state="operational" parentstate="operational" previous="wreck" exact="1"/>
        </do_if>
        <do_if value="$Defensible.summary.numshields.wreck" min="1">
          <set_summarised_shield_state object="$Defensible" state="operational" parentstate="operational" previous="wreck" exact="1"/>
        </do_if>
        <do_if value="$Defensible.summary.numsurfacedestructible.wreck" min="1">
          <set_summarised_surfacedestructible_state object="$Defensible" state="operational" parentstate="operational" previous="wreck" exact="1"/>
        </do_if>
        <do_if value="$Defensible.summary.numturrets.wreck" min="1">
          <set_summarised_turret_state object="$Defensible" state="operational" parentstate="operational" previous="wreck" exact="1"/>
        </do_if>
      </do_if>

      <!--Repair Defensible Hull-->
      <do_if value="not $Defensible.isclass.station and $Defensible.maxhull ge 1">
        <do_if value="$Defensible.hullpercentage lt $hulldamagelimit">
          <set_value name="$addedhullpercentage" exact="100f * $repairrate / $Defensible.maxhull" />
          <!-- handle the case of the percentage being < 0 -->
          <do_if value="$addedhullpercentage lt 1">
            <set_value name="$addedhullpercentage" exact="1"/>
          </do_if>
          <do_if value="$addedhullpercentage" min="1">
            <!-- set the repair command action -->
            <set_command_action commandaction="commandaction.repairingto" param="$Defensible" />
            <!-- repair the hull -->
            <set_object_hull object="$Defensible" exact="$Defensible.hullpercentage + $addedhullpercentage" />
            <debug_text text="'repaired main object ' + $Defensible + ' ' + $Defensible.knownname + ' to hull value ' + $Defensible.hull + ' (' + $Defensible.hullpercentage + '%)'" chance="$debugoutputchance" />
            <do_if value="$Defensible.hullpercentage ge $hulldamagelimit">
              <debug_text text="$Defensible + ' ' + $Defensible.knownname + ' was repaired as much as possible.'" chance="$debugoutputchance"/>
            </do_if>
          </do_if>
        </do_if>
      </do_if>

      <do_if value="$CurrentElement">
        <do_if value="$CurrentElement.iswreck">
          <do_if value="@$RestoreTime" min="1">
            <do_if value="player.age" min="$RestoreTime">
              <!--Restore the $CurrentElement and all of its contained components to 1% hull-->
              <restore_object object="$CurrentElement" hull="1" recursive="true" />
              <set_value name="$RestoreTime" exact="0"/>
              <debug_text text="'Restoring ' + $CurrentElement + ' ' + $CurrentElement.knownname" chance="$debugoutputchance"/>
            </do_if>
          </do_if>
          <do_else>
            <!--Component is wrecked but no restore time is defined. It may have been recently wrecked.-->
            <set_value name="$CurrentElement" exact="null"/>
          </do_else>
        </do_if>
        <do_else>
          <do_if value="$CurrentElement.maxhull" min="1">
            <do_if value="$CurrentElement.hullpercentage ge $hulldamagelimit">
              <!--Component is as repaired as possible-->
              <debug_text text="$CurrentElement + ' ' + $CurrentElement.knownname + ' was repaired as much as possible.'" chance="$debugoutputchance"/>
            </do_if>
            <do_else>
              <!--Repair Damaged Component-->
              <set_value name="$addedhullpercentage" exact="100f * $repairrate / $CurrentElement.maxhull" />
              <!-- handle the case of the percentage being < 0 -->
              <do_if value="$addedhullpercentage lt 1">
                <set_value name="$addedhullpercentage" exact="1"/>
              </do_if>
              <do_if value="$addedhullpercentage" min="1">
                <!-- set the repair command action -->
                <set_command_action commandaction="commandaction.repairingto" param="$CurrentElement" />
                <!-- repair the hull -->
                <set_object_hull object="$CurrentElement" exact="$CurrentElement.hullpercentage + $addedhullpercentage" />
                <debug_text text="player.age + ' repaired ' + $CurrentElement + ' ' + $CurrentElement.knownname + ' to hull value ' + $CurrentElement.hull + ' (' + $CurrentElement.hullpercentage + '%)'" chance="$debugoutputchance" />
                <do_if value="$CurrentElement.hullpercentage ge $hulldamagelimit">
                  <debug_text text="$CurrentElement + ' ' + $CurrentElement.knownname + ' was repaired as much as possible.'" chance="$debugoutputchance"/>
                </do_if>
              </do_if>
            </do_else>
          </do_if>
        </do_else>
      </do_if>

      <resume label="checkforrepair" />
    </actions>
  </attention>
</aiscript>
</replace>
</diff><?xml version="1.0" encoding="utf-8"?>
<diff>
<replace sel="//hull">
<hull max="300000" threshold="0" />
</replace>
</diff><?xml version="1.0" encoding="iso-8859-1"?>
<content id="" name="" description="" author="angel618" version="100" date="2016-03-03" save="false" lastupdate="">
</content>
