Jump to content

[MOD] Goods Hauler (Automatically buy/sell/move goods!)


Splutty

Recommended Posts

  • Replies 116
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

I've been thinking about further improvements of Goods Hauler. What would you think about some kind of priority queue instead of the current list of traderoutes?

Well, since that requires some kind of sorting, it would need a little more CPU-time, compared to the current system.

 

Have you got other ideas for the Mod?

Link to comment
Share on other sites

Hi,

 

spoiler-alert :)

 

 

2019-02-12 22-15-20| Goodshauler v0.10.0-alpha1 12.02.2019 22:15:20 (Frachter 2) : haulGoodsGetRoute (Stage 1) finished. Starting to transport 420 Platinum from Goldgrube 1 to Prozessorfabrik
2019-02-12 22-17-58| Goodshauler v0.10.0-alpha1 12.02.2019 22:17:58 (Frachter 2) : BuyGoods Data: 420 Platinum size 0.5 requested, 97 in the cargobay, room for 2939 more. Decided to buy 323 more.
2019-02-12 22-21-06| Goodshauler v0.10.0-alpha1 12.02.2019 22:21:06 (Frachter 2) : Finished trade from Goldgrube 1 to Prozessorfabrik

Well, that's all the default-level logging of the current development-version (of a successful trade-run)... Server-Admins will love it :)

 

If anybody is interested, I could share the latest dev-version.

Disclaimer: This is experimental software, you can expect some unintended behavior.

 

Link to comment
Share on other sites

Hi,

 

Shrooblord had to wait more then a year for a reply now...

Sometimes Goods Haulers try to do one or both of the following problematic things:

  • Buy more goods than the Cargo Hauler has stock for, usually as simple as 1 over the total amount they could carry.
  • Push more goods to the receiving Station than that Station has space for.

 

Whenever they decide they want to do either, they don't let up and continue to try and perform this behaviour somewhere between 5 and 10 times in a row, which spams both the Console and the main game screen itself full of error messages (Console says something along the lines of "Expected to buy 5 goods but bought only 4", while the game screen shows an error in the typical red "You can't do that" message with a red cross, on the right) every second or so. With multiple Goods Haulers at work in one Sector, this gets very spammy very quickly, but more importantly, your Goods Haulers aren't doing anything, because they load up their Cargo Bays with goods they can now no longer push, because the receiving Station doesn't accept more goods of that type anymore.

 

Is there anything you can do to include some sort of check that wouldn't trigger this behaviour anymore? It's made me steer clear of giving my craft the Goods Hauler orders inside my own Sector, because they keep trying to push Aluminium from my Alu Mine to my Shipyard, which doesn't want it anymore, instead of acting as my handy cargo shuttle between production chains as I intended for them to do.

 

Furthermore, Goods Haulers with cargo already with them will never try and push these items for profit, which I think isn't in the spirit of how this mod operates.

 

"Buys more then fits into the cargobay"

The dispatcher decided in 0.9.x versions of Goods Hauler how much to buy. That data is simply old at some point.

 

"Push more goods to the receiving Station than that Station has space for."

Goods Hauler always tries to sell as much as possible. That's not a bug, it was the only way for the 0.9.x versions to try to keep the cargobay free. Well, I'm not going to change that.

 

"Whenever they decide they want to do either, they don't let up and continue to try and perform this behaviour somewhere between 5 and 10 times in a row, ..."

That's actually a bug, the 0.9.x versions were missing 2 "undocking" stages - one after buying and one after selling stuff - , so the updateServer-function ran the same code again and again.

 

"...your Goods Haulers aren't doing anything, because they load up their Cargo Bays with goods they can now no longer push, because the receiving Station doesn't accept more goods of that type anymore."

Well, 0.10.0-alpha1 took a look at the cargobay before buying anything, so it should maximize free cargospace over time. Problem is: It still relied on old (inaccurate) data.

0.10.0-alpha2 now updates the amount of goods in the cargobays of your ship, selling station and buying station and decides then how much to transport.

 

So, now I'm talking about 0.10.0 again... alpha2 is still missing features I'd like in the final 0.10.0, but in hours of testing I didn't come across a single bug, it works much better then the old 0.9.x versions. What has changed? - Spoiler :)

 

 

These changes should slowly free your cargospace - or at least keep the cargobay free as good as possible:

Ships don't buy stuff that's already in the cargobay

Amount of goods to transport is determined just before buying - previous versions used the dispatcher-information (old data - very likely wrong)

 

Added limitation to transporterrange (35km range should be enough - or do people equip ships with 10 legendary Transporter-Software now?)

Changed docking distance calculation for ships with transporters

 

Introduced Log-Levels, haulGoodsLogThreshold (default 2):

5 and higher values should suppress all messages,

choose 4 for Errors,

choose 3 for Errors and Warnings,

choose 2 for Errors, Warnings and Notifications,

choose 1 for all the beauty of console- and log-spamming that you know from previous versions: Errors, Warnings, Notifications and the rest of the Spam.

Also changed Log-Entry format.

 

Ships without transporters: Properly resetting DockAI.dockStage and .undockStage, and waiting until ships are fully undocked

Fixes: Ships without transporters are sometimes going mad and fly thousands of kilometers away

 

Added additional stages for undocking - this reduces spamming of buy- and sell-stages

 

 

 

EDIT: Removed old 0.10.0-alpha2 version of the Mod.

Link to comment
Share on other sites

Thanks for the mod.

I tested 0.10.0-alpha2. And in the case without Transporters it did a nice operation.

Improved dispatchers are great.

However, it seems that the ship with Transporters is stuck when leaving the station.

 

The part considered to be the log at that time is below.

Execution Context (inner to outer):
#0: updateServer data/scripts/entity/ai/haulgoods.lua

could not execute function 'updateServer' in '"data/scripts/entity/ai/haulgoods.lua"':

data/scripts/entity/ai/haulgoods.lua:425: attempt to concatenate local 'station' (a userdata value)
stack traceback:
     data/scripts/entity/ai/haulgoods.lua:425: in function 'haulGoodsMoveToStation'
     data/scripts/entity/ai/haulgoods.lua:576: in function <data/scripts/entity/ai/haulgoods.lua:548>

 

Link to comment
Share on other sites

Hi,

 

Thanks for the mod.

I tested 0.10.0-alpha2. And in the case without Transporters it did a nice operation.

Improved dispatchers are great.

However, it seems that the ship with Transporters is stuck when leaving the station.

 

The part considered to be the log at that time is below.

Execution Context (inner to outer):
#0: updateServer data/scripts/entity/ai/haulgoods.lua

could not execute function 'updateServer' in '"data/scripts/entity/ai/haulgoods.lua"':

data/scripts/entity/ai/haulgoods.lua:425: attempt to concatenate local 'station' (a userdata value)
stack traceback:
     data/scripts/entity/ai/haulgoods.lua:425: in function 'haulGoodsMoveToStation'
     data/scripts/entity/ai/haulgoods.lua:576: in function <data/scripts/entity/ai/haulgoods.lua:548>

 

I didn't touch the dispatcher so far, I just updated the data (amount) before buying anything.

 

Well, the Error you found is a bug in one of the only Error-Messages at the moment. In line 425 the variable station needs to be replaced with station.name. If you changed that, you would get the following output:

ERROR: Can't dock to <Enter station-name here> using Transporters. Calculated Distance is <some negative value here> meters.

The Transporter-Software is limiting the range, in your case the Freighter would need to park somewhere inside the station - and I dislike crashing your ships into stations.

 

During my tests with transporters, I saw that 500m range are not sufficient, even on smaller stations.  However, the transporter-code in 0.9.3 is even worse, it needs about twice the range to work (compared to 0.10.0alpha2).

 

I'm currently working on 0.10.0alpha4, so I can't release a fixed alpha2 version at the moment.

Link to comment
Share on other sites

I fixed station.name and tested it with a 2.5 km transporter.

The ship was ported to Uenhzauz and stacked after selling the goods.

The ship has not moved from Uenhzauz.

 

It is the error code at that time.

: BuyGoods Data: 214 Steel size 1 requested. Updated to 214 and 0 in the cargobay, room for 526 more. Decided to buy 214 more.
: Sold 214 Steel
: Finished trade from Yi'now to Uenhzauz
: haulGoodsGetRoute (Stage 1) finished. Starting to transport 11900 Oxygen from Moyouwua to Nouwrie
: ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.
: ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.
: ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.

 

I am looking forward to 0.10.0alpha4.

Link to comment
Share on other sites

Hi,

 

: ERROR: Can't dock to Moyouwua using Transporters. Calculated Distance is -2257.4322414398 meters.

hmm, how big are the ships and stations? Since the ship was able to "dock" at the other stations, I'd guess Moyouwua is big (compared to the other stations).

 

In alpha2 I calculated the possible distance in line 416:

local Distance = (range - ((ship.radius + station.radius)/2))

I don't see how to further reduce that... (And if it's radius even that formula is wrong, the radius-values shouldn't be divided by 2)

 

If you could find the sector-file, compress it to a zip and upload it here, so I could take a look myself, it would be a great help.

I am looking forward to 0.10.0alpha4.

Well, first I need to finish it, then I'll need to run tests for hours... And after that I'll think about releasing it.

 

I didn't release alpha3, the reason is: It didn't change a lot for the players. I introduced shortcuts - if a ship receives a route and has got the needed goods in the cargobay, it can skip flying to the selling station. The result was:

torsten@debian:~/.avorion/galaxies/avorion_galaxy$ cat serverlog\ 2019-02-14\ 17-00-59.txt | grep directly
2019-02-14 17-21-37| Goods Hauler v0.10.0-alpha3 17:21:37 (Frachter 1) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 18-05-37| Goods Hauler v0.10.0-alpha3 18:05:37 (Frachter 3) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 18-57-37| Goods Hauler v0.10.0-alpha3 18:57:37 (Allianz-Frachter 1) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 20-26-45| Goods Hauler v0.10.0-alpha3 20:26:45 (Frachter 3) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 20-51-20| Goods Hauler v0.10.0-alpha3 20:51:20 (Allianz-Frachter 2) : Amount is in the cargobay, directly moving to buyer.
2019-02-14 21-10-09| Goods Hauler v0.10.0-alpha3 21:10:09 (Frachter 1) : Amount is in the cargobay, directly moving to buyer.
torsten@debian:~/.avorion/galaxies/avorion_galaxy$

The shortcut was used 6 times during 4 hours of testing in a sector with 20 stations and 5 Goods Hauler controlled freighters - as I said before, it didn't change a lot for the players.

 

There was also another shortcut: If a route is received and the updated amount of goods is 0, then the route is reset. That didn't happen at all during the test.

Link to comment
Share on other sites

The ship is small with 6 slots.

 

Upload the sector I tested.

Thanks for the effort.

 

Since the file was large, I could not upload it here, so I will put a link destination uploaded to a different location.

Please tell me when downloading because I will erase the link.

 

 

Link to comment
Share on other sites

Hi,

 

The ship is small with 6 slots.

 

Upload the sector I tested.

thank you. Well, I was unable to run tests in that sector (becoming a friend of that pirate-faction would have taken some time), but I think I've got a working formula now...

local Distance = range + station.radius - ship.radius

If you put that formula into line 416 of your haulgoods.lua, your ship shouldn't try to crash into the stations, but it should be able to dock and do business then.

BTW: That's the formula I'm using in 0.10.0alpha4 now...

 

My tests with the formula above were successful:

2019-02-15 17-07-52| Goods Hauler v0.10.0-alpha4 17:07:52 (Longrange) : Trying to dock with Transporters to Chemiefabrik. Calculated Distance is 4513.9723396301 meters.
2019-02-15 17-08-32| Goods Hauler v0.10.0-alpha4 17:08:32 (Longrange) : Trying to dock with Transporters to Siliziummine. Calculated Distance is 4439.3046760559 meters.

That ship has got a legendary Transporter-Software (3.5 km range).

Link to comment
Share on other sites

 

local Distance = range + station.radius - ship.radius

If you put that formula into line 416 of your haulgoods.lua, your ship shouldn't try to crash into the stations, but it should be able to dock and do business then.

BTW: That's the formula I'm using in 0.10.0alpha4 now...

 

 

Although it worked better than before, if the station is very long, it stopped short of approaching the station.

 

So I tested the formula as follows.

local Distance = range - ship.radius

 

In this case, as far as I tested a little, the problems such as stopping and colliding on the way did not occur.

Link to comment
Share on other sites

Hi,

 

So I tested the formula as follows.

local Distance = range - ship.radius

 

In this case, as far as I tested a little, the problems such as stopping and colliding on the way did not occur.

in my tests, the distance exceeded the 3.5km range of the Transporter Software, so you won't need to reduce it further.

 

I've got a stupid idea:  Line 422 looks like this:

ShipAI(ship):setFly(target, 0)

The 0 in the end is the distance from the target-coordinates, so we could try to change it to:

ShipAI(ship):setFly(target, range)

but the target would need to be changed, line 417 could be changed to:

local target = station.translationf

the ship-AI should avoid collisions.

Link to comment
Share on other sites

OK. I tested it as unbekannt1984 said.

 

Line416:  local Distance = range + station.radius - ship.radius
Line417:  local target = station.translationf

Line422:  ShipAI(ship):setFly(target, range)

 

It worked fine. Even at the station where the problem occurred because it was too long.

Link to comment
Share on other sites

Hi,

 

I know you like my Patchnotes (collected since 0.9.3):

 

 

These changes should slowly free your cargospace - or at least keep the cargobay free as good as possible:

    Ships don't buy stuff that's already in the cargobay

    Amount of goods to transport is determined just before buying - previous versions used the dispatcher-information (old data - very likely wrong)

    alpha3: Introduced shortcuts:

          If a route with amount 0 is received, it won't be excuted

          If a route is received and the required amount of goods are in the cargobay "Buy"-Stages are skipped

          alpha4: If a route updates to the amount 0 during the buy-stage, we ask for a new route.

 

Added limitation to transporterrange (35km range should be enough - or do people equip ships with 10 legendary Transporter-Software now?)

Changed docking distance calculation for ships with transporters (alpha4: twice now)

 

Introduced Log-Levels, haulGoodsLogThreshold (default 2):

      5 and higher values should suppress all messages,

      choose 4 for Errors,

      choose 3 for Errors and Warnings,

      choose 2 for Errors, Warnings and Notifications,

      choose 1 for all the beauty of console- and log-spamming that you know from previous versions: Errors, Warnings, Notifications and the rest of the Spam.

  Also changed Log-Entry format.

  alpha3: Dropped date from messages - it will be added in the logs and shouldn't matter that much while playing

 

Ships without transporters: Properly resetting DockAI.dockStage and .undockStage, and waiting until ships are fully undocked

    Fixes: Ships without transporters are sometimes going mad and fly thousands of kilometers away

 

Added additional stages for undocking - this reduces spamming of buy- and sell-stages

      alpha3: Added additional stages to haulGoodsStatus (/goodshauler status)- Oops

          fixes: Wrong status-messages in alpha2

 

alpha5: Added a shitload of patches from Hammelpilaw (33 lines of code imported from his version)

      Changed filestructure - most files are in the mods-directory now

      Made Mod compatible with Custom Craft Orders (by Hammelpilaw), includes config-files and a Readme.txt.

 

 

When upgrading to this version, active Goodshaulers won't find their scripts - don't worry about a few weird errors.

 

Custom Craft Orders (by Hammelpilaw) can be found here.

haulgoods_0100_a5.zip

Link to comment
Share on other sites

Hi,

 

I assume this mod only works if you're physically in the sector with the ship you've designated as a hauler?

the script keeps running, when you leave the sector.

 

The problem is: Ship movement and docking/undocking aren't simulated in weak-loaded sectors - and that causes the script to be stuck.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...