[MOD] Mining/Trading Fleet ver0.03

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

TENGILL
Posts: 17
Joined: Thu, 22. Apr 04, 16:44
x4

Re: [MOD] Mining/Trading Fleet

Post by TENGILL » Sun, 23. Dec 18, 01:28

This mod looks great, +1 on adding it to NEXUS.
Please and thank you. :)

kspn
Posts: 75
Joined: Mon, 9. Jan 06, 10:59
x4

Re: [MOD] Mining/Trading Fleet

Post by kspn » Sun, 23. Dec 18, 05:32

I have the start of Wing Rename code.

Currently there is no check for the tag already existing in the Wings Name and my code assumes that you want to keep the existing wing name. An example output is Wing 1 Mining

Code: Select all

  <add sel="/aiscript/attention[1]/actions[1]/do_else[1]/do_else[1]" pos="after">
    <do_if value="($commander.subordinates.count == 1) and ($commander.defaultorder.id == 'TradeRoutine')">
      <debug_text text="'Set Wing name to %1 AutoTrade Count=%2'.[$commander.wing.name,$commander.subordinates.count]" />
      <set_object_wing_name object="$commander" name="'%1 AutoTrade'.[$commander.wing.name]" />
    </do_if>
    <do_elseif value="($commander.subordinates.count == 1) and ($commander.defaultorder.id == 'TaterTrade')">
      <debug_text text="'Set Wing name to %1 TaterTrade Count=%2'.[$commander.wing.name,$commander.subordinates.count]" />
      <set_object_wing_name object="$commander" name="'%1 TaterTrade'.[$commander.wing.name]" />
    </do_elseif>
    <do_elseif value="($commander.subordinates.count == 1) and ($commander.defaultorder.id == 'MiningRoutine')">
      <debug_text text="'Set Wing name to %1 Mining Count=%2'.[$commander.wing.name,$commander.subordinates.count]" />
      <set_object_wing_name object="$commander" name="'%1 Mining'.[$commander.wing.name]" />
    </do_elseif>
  </add>

pesoda
Posts: 16
Joined: Thu, 13. Dec 18, 19:45
x4

Re: [MOD] Mining/Trading Fleet

Post by pesoda » Sun, 23. Dec 18, 09:19

Here, substitute_text function (see libraries/common.xsd) was added to your code for removing an overlapped tag.
"Rename Wings" seems to have worked. Thanks.
Original Post
Show

Code: Select all

  <add sel="/aiscript/attention[1]/actions[1]/do_else[1]/do_else[1]" pos="after">
    <!-- Add. Rename Wings.  Thanks to kspn at Mod Forum: https://forum.egosoft.com/viewtopic.php?f=181&t=410087&start=15#p4810686 -->
    <do_if value="($commander.subordinates.count gt 0)">
      <!-- Create tag -->
      <set_value name="$wing_tag" exact="''" />
      <do_if value="($commander.defaultorder.id == 'TradeRoutine')">
        <set_value name="$wing_tag" exact="'AutoTrade'" />
      </do_if>
      <do_elseif value="($commander.defaultorder.id == 'TaterTrade')">
        <set_value name="$wing_tag" exact="'TaterTrade'" />
      </do_elseif>
      <do_elseif value="($commander.defaultorder.id == 'MiningRoutine')">
        <set_value name="$wing_tag" exact="'Mining'" />
      </do_elseif>
      <debug_text text="'Set Wing name to %1 %2 Count=%3'.[$commander.wing.name,$wing_tag,$commander.subordinates.count]" />

      <!-- Rename wing-->
      <do_if value="$wing_tag != ''">
        <substitute_text source="$commander.wing.name" text="$org_name">
          <replace string="' %1'.[$wing_tag]" with="''" />
        </substitute_text>
        <set_object_wing_name object="$commander" name="'%1 %2'.[$org_name, $wing_tag]" />
        <debug_text text="'Wing name: %1'.[$commander.wing.name]" />
      </do_if>

    </do_if>
    <!--end-->
  </add>
Save this xml-file to "extensions/mining_trading_fleet/aiscripts/".
]https://www.mediafire.com/file/mdlbsk3q ... orders.xml

Edit:
Fixed: Tag remains when the default order changed.
Image: https://i.imgur.com/o1nqeRN.png

Code: Select all

  <add sel="/aiscript/attention[1]/actions[1]/do_else[1]/do_else[1]" pos="after">
    <!-- Add. Rename Wings.  Thanks to kspn at Mod Forum: https://forum.egosoft.com/viewtopic.php?f=181&t=410087&start=15#p4810686 -->
    <do_if value="($commander.subordinates.count gt 0)">
      <!-- Prepare tags. ** Should be used dictionary **  -->
      <set_value name="$mtf_orders" exact="['TradeRoutine', 'TaterTrade', 'MiningRoutine']" />
      <set_value name="$mtf_tags" exact="[  'AutoTrade',    'TaterTrade', 'Mining']" />

      <!-- Create tag -->
      <set_value name="$wing_tag" exact="''" />
      <substitute_text source="$commander.wing.name" text="$org_name">
        <replace string="' %1'.[$mtf_tags.{1}]" with="''" />
      </substitute_text>
      <debug_text text="'mtf_orders.count=%1'.[$mtf_orders.count]" />
      <do_all exact="$mtf_orders.count" counter="$i">
        <!-- Remove existing tag -->
        <substitute_text text="$org_name">
          <replace string="' %1'.[$mtf_tags.{$i}]" with="''" />
        </substitute_text>

        <!-- Rename Wing -->
        <do_if value="($commander.defaultorder.id == $mtf_orders.{$i})">
          <set_value name="$wing_tag" exact="' %1'.[$mtf_tags.{$i}]" />
        </do_if>
      </do_all>
      <set_object_wing_name object="$commander" name="'%1%2'.[$org_name, $wing_tag]" />
      <debug_text text="'Set Wing name to %1 Count=%2'.[$commander.wing.name,$commander.subordinates.count]" />
    </do_if>
    <!--end-->
  </add>
Save this xml-file to "extensions/mining_trading_fleet/aiscripts/".
http://www.mediafire.com/file/w6lzeydpb ... orders.xml
Last edited by pesoda on Sun, 23. Dec 18, 12:35, edited 1 time in total.

kspn
Posts: 75
Joined: Mon, 9. Jan 06, 10:59
x4

Re: [MOD] Mining/Trading Fleet

Post by kspn » Sun, 23. Dec 18, 09:46

Awesome :)

I have added the update to my game.

pesoda
Posts: 16
Joined: Thu, 13. Dec 18, 19:45
x4

Re: [MOD] Mining/Trading Fleet

Post by pesoda » Tue, 25. Dec 18, 01:21

MTF ver0.03 is in progress.
If you want to test an experimental version, see bottom.

Attempt to realize real-time updating of wares/distances.

1) Introduction: Passing by reference of $warebasket. Passing by value of $maxbuy/$maxsell.
Firstly, author isn’t a programmer, but as a basic knowledge of programming, a list structure will basically be passed by reference of list[0] and the program uses not a real value (e.g. “name=spaceweed, price=500”) but a reference (e.g. 0x12345) for accessing to the list. Therefore, when the commander’s “warebasket” is passed to subordinates, their references are shared and wares-lists will synchronize. That’s the reason why updating wares-lists is easier.
However, “maxbuy” is an integer and is passed its copy. It means that the program must execute to copy of “maxbuy” every time when commander’s “maxbuy” is changed. Because the only function to set param one-by-one was prepared, I couldn't implement shallow-copy of whole order-params even though create params-list. An alternative way was necessary.

2) Method A: Using EventHandler.
I tried to hook the moment which the commander’s default-order-param is changed. (About hooking. For example, imagine Paint Tools, your click event is hooked and detected as “pos.x=250 [px], pos.y=600 [px], mouse_button=Left” by OS and that info is processed by Paint Tool to display your drawing activity.) However, no valid functions (prefix: event_) exist for that purpose and event_object_order_param_edited was inappropriate, too. Maybe the valid function will be found in the menu-UI, inside of lua codes.
In conclusion, the perfect real-time updating of wares/distances should be realized as the one of the Lua-UI mod.
Sample code is available. Put it to the aiscripts directory and add <handler ref=“FleetDefaultOrderChangedHandler” /> within <interrupts> block of an order script.
https://www.mediafire.com/file/e081aw5i ... detail.xml

3) Method B: Inject copy-params code into docking script.
Copy-params code was injected to order.dock that frequently be executed. It seems to work fine.

I would like to share it, but I have no time to check the scripts completely work. So, this is an unstable version. And feel free to modify/fix and reupload.

ver0.03 experimental
https://www.mediafire.com/file/y9dms5eu ... 3_exp3.zip

New feature: deltaone’s compatibility patch for TaterTrade (v3.1).
New feature: kspn’s-based Rename Wings.
New feature: Dynamic updating of subordinates’ order-properties (wares, distances, etc) when the commander docked at a station.

Edit:
Fixed: Only AutoTrade ships were updated their distance.
File was reuploaded.
Captions were added to this text.
Last edited by pesoda on Wed, 26. Dec 18, 15:24, edited 2 times in total.

kspn
Posts: 75
Joined: Mon, 9. Jan 06, 10:59
x4

Re: [MOD] Mining/Trading Fleet

Post by kspn » Tue, 25. Dec 18, 07:26

Awesome update.

Just a quick question, will you be putting this onto Nexus soon? :) :P

I have installed the Experimental version, lets see how it goes :D

Spacecop42
Posts: 26
Joined: Fri, 14. Dec 18, 18:45
x4

Re: [MOD] Mining/Trading Fleet

Post by Spacecop42 » Tue, 25. Dec 18, 08:27

I suggest you use X-Perimental instead of Experimental :D

pesoda
Posts: 16
Joined: Thu, 13. Dec 18, 19:45
x4

Re: [MOD] Mining/Trading Fleet

Post by pesoda » Tue, 25. Dec 18, 12:55

OK. Initial and X-perimental versions were uploaded to Nexus and added contributors' names. Enjoy to watch it.
https://www.nexusmods.com/x4foundations/mods/191

Buzz2005
Posts: 2184
Joined: Sat, 26. Feb 05, 01:47
x4

Re: [MOD] Mining/Trading Fleet

Post by Buzz2005 » Tue, 25. Dec 18, 15:05

my wing leader doesn't do anything, I set him up with tatertrade and then assign 4 other traders to him

all 4 traders are working perfectly, but wing leader does nothing, all have the same settings enabled
Fixed ships getting spawned away from ship configuration menu at resupply ships from automatically getting deployables.

Buzz2005
Posts: 2184
Joined: Sat, 26. Feb 05, 01:47
x4

Re: [MOD] Mining/Trading Fleet

Post by Buzz2005 » Tue, 25. Dec 18, 16:57

just a update

it does not copy restrictions to sectors from tatertrade
Fixed ships getting spawned away from ship configuration menu at resupply ships from automatically getting deployables.

Elephant42
Posts: 23
Joined: Tue, 11. Dec 18, 06:39

Re: [MOD] Mining/Trading Fleet

Post by Elephant42 » Tue, 25. Dec 18, 23:29

This is awesome, been waiting for something like it to appear.

Any chance you could add a purely cosmetic wing option? - what I mean by that is forming a wing just for keeping the ship list organised. Each member of the wing still has completely independant orders. Not sure if this is possible but it would be great if it was...

pesoda
Posts: 16
Joined: Thu, 13. Dec 18, 19:45
x4

Re: [MOD] Mining/Trading Fleet

Post by pesoda » Wed, 26. Dec 18, 01:14

Buzz2005 wrote:
Tue, 25. Dec 18, 15:05
my wing leader doesn't do anything, I set him up with tatertrade and then assign 4 other traders to him

all 4 traders are working perfectly, but wing leader does nothing, all have the same settings enabled
Buzz2005 wrote:
Tue, 25. Dec 18, 16:57
just a update

it does not copy restrictions to sectors from tatertrade
Thanks for reporting. First one was not replayed on my environment today, so it seems to need some time. Second one was fixed by inserting a missing line.

ver0.03 X-perimental 3
https://www.mediafire.com/file/y9dms5eu ... 3_exp3.zip

Fixed: Did not copy restrictions to sectors from tatertrade.

Elephant42 wrote:
Tue, 25. Dec 18, 23:29
Any chance you could add a purely cosmetic wing option? - what I mean by that is forming a wing just for keeping the ship list organised. Each member of the wing still has completely independant orders. Not sure if this is possible but it would be great if it was...
It's nice idea. Keeping independent orders in the wing is capable, not difficult. However, some additional idea is necessary to switch order mode (Keep independent, Same as commander, Vanilla, etc). For instance, if the new assignment commands are added to the menu of right click on ship, we can select order mode precisely and your idea will be realized.

Buzz2005
Posts: 2184
Joined: Sat, 26. Feb 05, 01:47
x4

Re: [MOD] Mining/Trading Fleet

Post by Buzz2005 » Wed, 26. Dec 18, 01:27

yes did not report back that I was stupid and the trader was full of left over wares

but when I have them in a wing with tatertrade every so often they put a fly and wait command to a place where the leader is
Fixed ships getting spawned away from ship configuration menu at resupply ships from automatically getting deployables.

Elephant42
Posts: 23
Joined: Tue, 11. Dec 18, 06:39

Re: [MOD] Mining/Trading Fleet

Post by Elephant42 » Wed, 26. Dec 18, 02:39

pesoda wrote:
Wed, 26. Dec 18, 01:14
Elephant42 wrote:
Tue, 25. Dec 18, 23:29
Any chance you could add a purely cosmetic wing option? - what I mean by that is forming a wing just for keeping the ship list organised. Each member of the wing still has completely independant orders. Not sure if this is possible but it would be great if it was...
It's nice idea. Keeping independent orders in the wing is capable, not difficult. However, some additional idea is necessary to switch order mode (Keep independent, Same as commander, Vanilla, etc). For instance, if the new assignment commands are added to the menu of right click on ship, we can select order mode precisely and your idea will be realized.
Many thanks, good luck and happy coding :)

pesoda
Posts: 16
Joined: Thu, 13. Dec 18, 19:45
x4

Re: [MOD] Mining/Trading Fleet ver0.03

Post by pesoda » Sat, 29. Dec 18, 06:09

MTF ver0.03 was uploaded. This is almost same as latest X-perimental version.

Buzz2005 wrote:
Wed, 26. Dec 18, 01:27
yes did not report back that I was stupid and the trader was full of left over wares

but when I have them in a wing with tatertrade every so often they put a fly and wait command to a place where the leader is
Full cargo ships often stop their work and should be fixed. And maybe it was serious than I think because it will also happen when many subordinates' trade-wares are changed at same time. Possibly, an efficiency of their trading is degraded by existing wrong cargo (but I unchecked).
Easy way to avoid it is just dropping wrong cargo when their order is changed. But it's not cool. So, I'm going to let subordinates try to sell them at nearest station and start new task quickly.

Edit:
Above expectation is incorrect. Both wrong and right cargoes seem to be processed similarly.

The problem was investigated using a stuck AutoTrade ship (commander) and AutoMining ships. The stuck point was identified by following code and AutoTrade ship dropped cargo which made ship stuck. However, miners were not detected and their cargo is still full.

trade.find.free.xml

Code: Select all

<diff>
  <add sel="/aiscript/attention[1]/actions[1]/do_elseif[1]">
    <debug_text text="'Stuck pos 2: %1 (%2)'.[this.ship.knownname, this.ship.idcode]" />
    <do_if value="this.ship.isplayerowned">
      <debug_text text="'Cargo count=%1'.[this.ship.cargo.list.count]" />
      <do_all exact="this.ship.cargo.list.count" counter="$i">
        <set_value name="$ware" exact="this.ship.cargo.list.{$i}"/>
        <debug_text text="'stuck. cargo %1 (%2) was dropped. %3 (%4)'.[$ware.name, this.ship.cargo.{$ware}.count, this.ship.knownname, this.ship.idcode]" />
        <drop_cargo object="this.ship" ware="$ware" exact="this.ship.cargo.{$ware}.count"/>
        <!-- ** if list size is changed by dropping cargo, use do_all reverse **-->
      </do_all>
    </do_if>
  </add>
  </add>
</diff>
Last edited by pesoda on Sun, 6. Jan 19, 14:33, edited 1 time in total.

pesoda
Posts: 16
Joined: Thu, 13. Dec 18, 19:45
x4

Re: [MOD] Mining/Trading Fleet ver0.03

Post by pesoda » Sun, 6. Jan 19, 14:28

"Fly and Wait" issue, subordinates frequently do that, was probably solved (thanks to Jebinator in Nexus). Now you can watch your fleets calmly.
The cause was MoveWait order which is called in lib.recall.subordinates.xml. Thus MoveWait order will be skipped if the commander and subordinates have a same default order.

Here, a test version was uploaded.
https://www.mediafire.com/file/lvjubflx ... 04_exp.rar

Behaviour of not MTF wings can also be affected from this change. Maybe some adjustment or restriction are necessary.

* * *

Procedure
  1. The language file (t/0001-L044.xml) was searched by using a keyword, "Fly and Wait". The text-id was identified.
  2. Full-text search was executed by using the text-id in aiscripts. MoveWait order was identified (order.move.wait.xml).
  3. Anyway, all MoveWait orders in aiscripts that related to subordinates were removed.
  4. It was confirmed that the problem doesn't occur.
  5. Candidates were narrowed down. Consequently, above code was obtained.
Edit:
Added procedure.

g_BonE
Posts: 153
Joined: Thu, 28. Aug 03, 11:37
x4

Re: [MOD] Mining/Trading Fleet ver0.03

Post by g_BonE » Fri, 18. Jan 19, 17:54

Testing this currently with the latest TaterTrader release and found that some settings of the "lead ship" are not copied over to the subordinates. "check distance" flag and "scan speed" are reset to default values immediately and do not reflect what has been set in the leader. Also most of the ships seem to be sitting around idle and not do anything while they are subordinates.
(x|x) .oO[ Fenster fährt mich Nüsse !!! ]

taintedxodus
Posts: 28
Joined: Fri, 2. Mar 07, 00:58
x4

Re: [MOD] Mining/Trading Fleet ver0.03

Post by taintedxodus » Fri, 29. Mar 19, 15:37

Its in need of updating for game version 2.20, orders to mine no longer get set on subordinates.

Misunderstood Wookie
Posts: 377
Joined: Mon, 15. Mar 04, 08:07
x4

Re: [MOD] Mining/Trading Fleet ver0.03

Post by Misunderstood Wookie » Tue, 9. Apr 19, 13:55

Bugger I was about to install.
I am seriously starting to get frustrated with doing it the way base game tells me and only solution to see what is going on is to shove all traders in a wing manually and configure the behaviours ship by ship.
*modified*
*X3 LiteCube User*
MOD GemFX Real Space Shaders
MOD Variety and Rebalance Overhaul Icon Pack
I lost my Hans and should not be flying Solo.
Image

Vectorial1024
Posts: 222
Joined: Mon, 30. Jul 18, 04:16
x4

Re: [MOD] Mining/Trading Fleet ver0.03

Post by Vectorial1024 » Wed, 7. Aug 19, 17:17

Seeing that this mod has gone inactive, as a somewhat experienced programmer and modder myself, I have updated this mod to be compatible with vanilla game v2.50. It is available here: viewtopic.php?f=181&t=418144

The <run_script/> XML tag has been heavily [s]abused[/s] utilized to simulate function calls inside aiscripts. This allows the internal code to be more modular and tidied.

The update also responded to the original mod's problems:
pesoda wrote:
Sat, 22. Dec 18, 01:19
  • Partially solved. Real-time updating of wares and distances. detail
Still adopts the dock-sync approach, but also allowed subordinates to sync with their commanders when they subordinates dock.
pesoda wrote:
Sat, 22. Dec 18, 01:19
  • In progress. Subordinates frequently take a coffee break (“Fly and Wait”) between tasks (eventually they return to work, so may not a problem). detail
    - According to the report, “Fly and Wait” may directs the commander’s position.
Subordinates are excluded from the commander's Recall Subordinates if they are part of the "civilian fleet".
pesoda wrote:
Sat, 22. Dec 18, 01:19
  • Subordinates can only have same default order as the commander. E.g. They cannot protect ships in the same wing.
    - For now, you can request unassigned ships or different wings to escort them.
    - I think one of the solutions is that adding assignment commands to the right click menu of ships. (Alternative idea is also welcome.)
The updated version utilizes the Right Click API. Subordinates intended to perform trading or mining activities should be assigned to their commanders using the new "form/join [...] fleet" buttons. UI scripts are used to force normally impossible "trade" and "mining" assignments onto such ships. This allows the game to signal fighters to protect the commander as usual, while allowing civilian ships to work in the same fleet doing something else.
pesoda wrote:
Sat, 22. Dec 18, 01:19
  • Compatibility with many order mods.
    - In order to solve it fundamentally, the basal framework of this mod should be changed over from aiscripts to UI because the function for enumerating order-params is only provided to UI.
Partially responded; used Right Click API and UI scripts to handle assignments, but still used aiscripts to actually give assignments. I think it is impossible to avoid using aiscripts, as they are the only way for us to intercept certain events without needing to know the event target before hand, compared to MD scripts (and aiscripts work).
The future awaits.

X4 Foundations mods:
Civilian Fleets: Managing your civilian ships has never been easier.
Station Logistics: Managing your station networks has never been easier.
Scrap Delivery Coordination: No more starving scrap processors.

Post Reply

Return to “X4: Foundations - Scripts and Modding”