Author Topic: [MOD] Goods Hauler (Automatically buy/sell/move goods!)  (Read 42155 times)

Uchiki

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    5
    • View Profile
on: February 15, 2019, 06:50:01 AM
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.
Code: [Select]
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>
« Last Edit: February 15, 2019, 06:51:51 AM by Uchiki »



unbekannt1984

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    164
    • View Profile
on: February 15, 2019, 10:17:23 AM
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.
Code: [Select]
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:
Quote
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.



Uchiki

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    5
    • View Profile
on: February 15, 2019, 12:41:29 PM
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.
Code: [Select]
: 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.



unbekannt1984

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    164
    • View Profile
on: February 15, 2019, 01:17:57 PM
Hi,

Code: [Select]
: 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:
Code: [Select]
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.
Quote
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:
Code: [Select]
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.



Uchiki

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    5
    • View Profile
on: February 15, 2019, 01:59:21 PM
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.

« Last Edit: February 15, 2019, 05:46:02 PM by Uchiki »



unbekannt1984

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    164
    • View Profile
on: February 15, 2019, 05:23:34 PM
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...
Code: [Select]
local Distance = range + station.radius - ship.radiusIf 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:
Code: [Select]
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).



Uchiki

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    5
    • View Profile
on: February 15, 2019, 06:22:23 PM

Code: [Select]
local Distance = range + station.radius - ship.radiusIf 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.
Code: [Select]
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.



unbekannt1984

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    164
    • View Profile
on: February 15, 2019, 07:41:44 PM
Hi,

So I tested the formula as follows.
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
ShipAI(ship):setFly(target, range)but the target would need to be changed, line 417 could be changed to:
Code: [Select]
local target = station.translationfthe ship-AI should avoid collisions.



Uchiki

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    5
    • View Profile
on: February 15, 2019, 10:05:10 PM
OK. I tested it as unbekannt1984 said.

Code: [Select]
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.



unbekannt1984

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    164
    • View Profile
on: February 17, 2019, 07:39:16 PM
Hi,

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

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.



Bocephus666

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    4
    • View Profile
on: February 20, 2019, 03:52:58 AM
I assume this mod only works if you're physically in the sector with the ship you've designated as a hauler?



unbekannt1984

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    164
    • View Profile
on: February 20, 2019, 09:33:16 AM
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.