X4: Foundations

X4: Foundations

Mules, Supply and Warehouses Extended
Mig1985 13 Jul, 2024 @ 2:30pm
Rewriting distrimule
I tried to rewrite the distrimule.

I want to feed wares into a storage station (Trading station with only self trade) and then move all wares above a set percentage limit to another Trading Station.

cant make it work with the mules I have and the rewriting seems to overwhelm me and gpt4 and gemini advanced....

Someone willing to talk to me about this?

I´m willing to learn or i would you a code snippet....
I think only this part must be rewritten:

<!-- Distribution Mule Routine -->
<do_all exact="2">
<do_if value="$needs.count gt 0 and $supplies.count gt 0">
<sort_trades name="$innerList" tradelist="$needs" sorter="totalvolume" />
<sort_trades name="$outerList" tradelist="$supplies" sorter="volume" />

<debug_to_file chance="$debugchance" name="$debugFileName" directory="$debugDirName" text="'static storage setting value. If no source ratios are above this, no trades will happen'" output="false" append="true" />
<debug_to_file chance="$debugchance" name="$debugFileName" directory="$debugDirName" text="' ' +$staticStorage" output="false" append="true" />

<do_all exact="$outerList.count" counter="$idx">
<set_value name="$sourceCargoRatio" exact="($outerList.{$idx}.owner.cargo.{$outerList.{$idx}.ware}.count * 100.0 / [$outerList.{$idx}.owner.cargo.{$outerList.{$idx}.ware}.target, 1].max)" />
<debug_to_file chance="$debugchance" name="$debugFileName" directory="$debugDirName" text="' source cargo ratio for ' +$outerList.{$idx}.ware + ': ' +$sourceCargoRatio" output="false" append="true" />

<do_if value="(not $needFound) and ($sourceCargoRatio gt $staticStorage)">
<set_value name="$someOuter" exact="$outerList.{$idx}" />

<do_all exact="$innerList.count" counter="$ctr">
<set_value name="$targetCargoRatio" exact="($innerList.{$ctr}.owner.cargo.{$innerList.{$ctr}.ware}.count * 100.0 / [$innerList.{$ctr}.owner.cargo.{$innerList.{$ctr}.ware}.target, 1].max)" />
<debug_to_file chance="$debugchance" name="$debugFileName" directory="$debugDirName" text="' target cargo ratio for ' +$innerList.{$ctr}.ware + ': ' +$targetCargoRatio" output="false" append="true" />
<do_if value="(not $needFound) and ($targetCargoRatio lt $minStorage or ($sourceCargoRatio gt $maxStorage and $sourceCargoRatio gt ($targetCargoRatio + 10)))">
<set_value name="$someInner" exact="$innerList.{$ctr}" />

<do_if value="$someOuter.ware.id" exact="$someInner.ware.id">
<do_if value="$someInner.owner.owner == this.ship.owner">
<set_value name="$targetAmount" exact="$someInner.desiredamount" />
</do_if>

<do_else>
<set_value name="$targetAmount" exact="$someInner.amount" />
</do_else>

<set_value name="$cargoHauled" exact="[this.ship.cargo.{$someInner.ware}.free,$targetAmount,$someOuter.amount].min" />
<do_if value="($cargoHauled gt (this.ship.cargo.{$someInner.ware}.max / 1.25)) or ($needFound2 and ($cargoHauled gt (this.ship.cargo.{$someInner.ware}.max / 2.0))) ">
<set_value name="$supplyTarget" exact="$someInner" />
<set_value name="$supplySource" exact="$someOuter" />
<set_value name="$needFound" exact="true" />
<debug_to_file chance="$debugchance" name="$debugFileName" directory="$debugDirName" text="'found a trade: ' +$someInner.ware + ' ' +$cargoHauled" output="false" append="true" />
</do_if>
</do_if>
</do_if>
</do_all>
< >
Showing 1-1 of 1 comments
Mo¡stDreams  [developer] 23 Apr @ 8:05pm 
Distro mule is a legacy mule unlike the other mules which got re-written from scratch.
if you ever found the time to do so you can make a PR into the github and it can be tested.
< >
Showing 1-1 of 1 comments
Per page: 1530 50