XRWS           ú   S  §ext_01.cat ext_01.dat aiscripts/order.trade.perform.xml 4519 1782865230 d995d66225d54780afd0059efe656b95
<?xml version="1.0" encoding="utf-8"?> 

<diff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <add sel="//execute_trade[@tradeoffer='$tradedeal']" pos="after">
        <do_if value="$traderesult">
            <set_command_action commandaction="commandaction.executingtrade" />

            <!-- 
                Trading time calculation is 'quite' simple:
                    - each 'service crew' on board will collaborate in the following manner:
                        - 1 crew member can carry up to 14 mÂ³ (carry_volume)
                        - 1 crew member takes 2 seconds to load/unload the amount above (time_to_transfer)
                    - the amount each crew member will load/unload is defined as follows:
                        - calculate crew efficiency:
                            - get the average service crew skill level
                            - remap it to a range of 1 to 1.75
                        - service_crew_boost = service_crew.count * efficiency
                        - service_crew_helping = service_crew_boost + dock_crew.count
                        - amount_by_crew_member = amount * ware.volume / (service_crew_helping)
                    - the time it will take for the trade to complete is defined as follows:
                        - time_load_unload = amount_by_crew_member * time_to_transfer (2 seconds) / carry_volume (14 mÂ³) -->

            <!-- ====== MAIN PARAMETERS ====== -->
            <!-- volume that one employee can carry by an amount of time -->
            <set_value name="$lttcrewcarryvolume" exact="14" /> 
            <!-- time that one employee takes to carry an amount of volume -->
            <set_value name="$lttcrewcarrytime" exact="2" /> 
            <!-- the amount of dock crew available to help -->
            <set_value name="$lttservicecrewondock" min="2" max="15" />
            <!-- ====== MAIN PARAMETERS ====== -->

            <!-- the amount of 'service crew' available on the ship -->
            <set_value name="$lttservicecrewonboard" exact="this.ship.people.{entityrole.service}.list.count" />

            <!-- find out the average skill on the ship (for 'service crew' only) -->
            <set_value name="$lttservicecrewcombinedskill" exact="this.ship.people.{entityrole.service}.combinedskill" />
            <set_value name="$lttservicecrewavgskill" exact="0" />
            <do_if value="$lttservicecrewcombinedskill != 0">
                <set_value name="$lttservicecrewavgskill" exact="$lttservicecrewcombinedskill / $lttservicecrewonboard" />
            </do_if>

            <!-- 
                map average skill from the range [0, 100] to the range [1, 1.75] 
                meaning the maximum possible efficiency would be up to 75% on top of the service crew on board
            -->
            <set_value name="$lttefficiency" exact="1f + ((1.75f - 1f) / (100f - 0f)) * ($lttservicecrewavgskill - 0f)" />

            <!-- apply efficiency calculation -->
            <set_value name="$lttcargoservicecalculated" exact="($lttservicecrewonboard * $lttefficiency)i" />

            <!-- sum the amount of 'service crew' onboard (calculated) with the service crew at the docking area -->
            <set_value name="$lttcargoservicecalculated" operation="add" exact="$lttservicecrewondock" />

            <!-- sum the amount of 'service crew' onboard (not calculated) with the service crew at the docking area
                 this is for debugging purposes -->
            <set_value name="$lttcargoservice" exact="$lttservicecrewonboard + $lttservicecrewondock" />

            <!-- for the on going trade, how many volumes each employee will colaborate -->
            <set_value name="$lttcrewtradecarry" exact="$tradedeal.transferredamount * $tradedeal.ware.volume / $lttcargoservicecalculated" />

            <!-- the actual time it will take for the trade to complete -->
            <set_value name="$ltttradetime" exact="($lttcrewtradecarry * $lttcrewcarrytime / $lttcrewcarryvolume)s" />

            <debug_text chance="100" text="'%1 (%2) Trading %3x %4. %5 employees working on it (%6 provided by dock crew). (%7 sec required - crew efficiency of %8).'.[this.ship.knownname, this.ship.idcode, $tradedeal.transferredamount, $tradedeal.ware.name, $lttcargoservice, $lttservicecrewondock, $ltttradetime, $lttefficiency]" />

            <wait exact="$ltttradetime" />
        </do_if>
    </add>
</diff><?xml version="1.0" encoding="utf-8"?>
<content id="" name="" description="" author="LuccasJSantos" version="200" date="2026-06-30" save="0" lastupdate="">
  <text language="44" name="Improved Trading Time" description="Make trading time more realistic. It makes trading time depend on service crew amount and level, it will now influence the crew efficiency." author="LuccasJSantos"/>
  <text language="55" name="Improved Trading Time" description="Faz com que o tempo de trade seja mais realista. O tempo de comÃ©rcio nas estaÃ§Ãµes agora depende da quantidade de tripulaÃ§Ã£o de serviÃ§o disponÃ­vel e seu nÃ­vel irÃ¡ influenciar a eficiÃªncia de carga/descarga das mercadorias." author="LuccasJSantos"/>
</content>
