Let mining drones collect the right things

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

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

Post Reply
oxylos
Posts: 32
Joined: Sat, 2. Aug 08, 19:45

Let mining drones collect the right things

Post by oxylos » Fri, 17. Sep 21, 19:01

Hi,
got another interesting (maybe) bug. If you activate drones they are collecting every minerals, although in the UI only one is selected. (on player ships)

After debugging the script "mining.collect.drone" it seems, that it becomes as parameter always a target, but never a ware. Ware is null.

I couldn't find any references, who is executing it except fe "mining.collect.ship.capital", but this script seems to never be called.

How to find who is starting the mining.collect.drone script to see how the parameter are set?

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Let mining drones collect the right things

Post by j.harshaw » Fri, 17. Sep 21, 21:16

fight.attack.object.capital which is the general turret/drone control script for capital ships. what exactly is the problem?

oxylos
Posts: 32
Joined: Sat, 2. Aug 08, 19:45

Re: Let mining drones collect the right things

Post by oxylos » Sat, 18. Sep 21, 21:05

Thank you for the hint! I think i know now what is the problem :)

The "LaunchDrone_OreCollector" action (line 136) needs filled variable called "$pickuptargets_solid". This variable is filled just before drone launch at line 893 with this:

Code: Select all

<find_object name="$pickuptargets_solid" space="this.zone" class="class.asteroid" multiple="true">
  <match_distance object="this.assignedcontrolled" max="this.assignedcontrolled.maxradarrange"/>
</find_object>
"$locfindsolid" is not used in any matter when "LaunchDrone_OreCollector" is called.

So there is no handling which mineral is selected in the UI. All mining drones collect everything when activated on a ship.

There is some handling about different minerals to collect at line 682 but this seems not to be executed on player ships.

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Let mining drones collect the right things

Post by j.harshaw » Sat, 18. Sep 21, 21:25

yeah. ware detection is done when $pickuptargets_solid is populated in the event handler with comment "dronemode collectable found" and that with comment "miningdronemode changed ... ". you could add another check right before each drone is launched, but would be redundant since LaunchDrone_OreCollector is called right after each check in the two handlers.

oxylos
Posts: 32
Joined: Sat, 2. Aug 08, 19:45

Re: Let mining drones collect the right things

Post by oxylos » Sat, 18. Sep 21, 21:34

If it is redundant than i have nothing to do, do i? Because drones collect everything instead of selected mineral. Or maybe i just missunderstand you, sorry for my english.

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Let mining drones collect the right things

Post by j.harshaw » Sat, 18. Sep 21, 21:36

that's why i was asking what exactly the problem is. have you found steps to reproduce the issue? i just tested with an L ship with mining drones set to collect ore, and it did.

oxylos
Posts: 32
Joined: Sat, 2. Aug 08, 19:45

Re: Let mining drones collect the right things

Post by oxylos » Sun, 19. Sep 21, 21:25

hi,
yea its easy to reproduce it:
https://www.reddit.com/r/X4Foundations/ ... nstead_of/

No mods, fresh creative start. Disarm drones, select different mineral, mine something, arm drones with different mineral and they bring every mineral.

But about the code :)

The handler "dronemode collectable found" is not called in that case, because i disarmed drones and armed again.
I've used debug_to_file command to prove it.

When the player arms drones the another handler "miningdronemode changed" is called. I'm not sure, but could be because of this check:

Code: Select all

<event_object_miningdrones_armed object="this.assignedcontrolled"/>
In this handler there is no check for $dronemode to populate $pickuptargets_solid. Only wares.
The find_object command gives not filtered asteroids back into variable $pickuptargets_solid and after this LaunchDrone_OreCollector is called. Each mineral is collected.

In handler "dronemode collectable found" all collectables are stored first in $collectables and then filtered to variable $pickuptargets_solid.
Maybe this could be the fix for the other handler?

Edit: The drones also bring empty chunks, for that they should not launch in the first place. For this, the quantity would have to be taken into account beforehand. What is the command to do it?

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Let mining drones collect the right things

Post by j.harshaw » Mon, 20. Sep 21, 09:39

you may be on to something.

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Let mining drones collect the right things

Post by j.harshaw » Mon, 20. Sep 21, 09:43

yup, fixed. thanks!

Code: Select all

<find_object name="$pickuptargets_solid" space="this.zone" class="class.asteroid" multiple="true">
  <match_distance object="this.assignedcontrolled" max="this.assignedcontrolled.maxradarrange"/>
  <match_wares>
    <ware ware="$locwares"/>
  </match_wares>
</find_object>
in the "miningdronemode changed ... " handler

oxylos
Posts: 32
Joined: Sat, 2. Aug 08, 19:45

Re: Let mining drones collect the right things

Post by oxylos » Mon, 20. Sep 21, 10:53

Nice small fix! it works, I just tested it :)

I already wanted to filter the variable $pickuptargets_solid using $newminingdronemode or fill a new list. (After the find_object command, like in the other handler)

However, if the drones should not bring chunks with 0 minerals then I have to do it and iterate the list and check for the amount right?

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Let mining drones collect the right things

Post by j.harshaw » Mon, 20. Sep 21, 11:43

you could just check $asteroid.wares.{$ware}.count. asteroids without the ware you're interested in or that are empty should both return 0.

EDIT: sorry, time's more limited since at work today and misread your post. did you mean with the fix i posted? should implicitly also fix drones picking up empty asteroids. only asteroids with any $locwares in them would get into $pickuptargets_solid.

oxylos
Posts: 32
Joined: Sat, 2. Aug 08, 19:45

Re: Let mining drones collect the right things

Post by oxylos » Mon, 20. Sep 21, 13:03

Yea, sorry, my fault. I realized that "empty" asteroid is not in $locwares and won't be collected.

But, your hint helps me still to filter out asteroids with small amount like <50. There often asteroids with 1 or 10 minerals. The interesting one is above 500, so this saves the drone the time.

oxylos
Posts: 32
Joined: Sat, 2. Aug 08, 19:45

Re: Let mining drones collect the right things

Post by oxylos » Mon, 20. Sep 21, 15:43

Another thing: At line 695:

Code: Select all

<do_elseif value="($miningdronemode == dronemode.collectore) and $collectables.{$interruptcounter}.wares.{ware.silicon}.count">
Shouldn't it be $miningdronemode == dronemode.collectsilicon?

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1847
Joined: Mon, 23. Nov 15, 18:02

Re: Let mining drones collect the right things

Post by j.harshaw » Mon, 20. Sep 21, 16:22

right, forgot to mention. already fixed here. fix is as you said.

Post Reply

Return to “X4: Foundations - Scripts and Modding”