[Script] Station Manager v1.11 (March 27)

The place to discuss scripting and game modifications for X³: Reunion.

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

Post Reply
User avatar
Burianek
Posts: 2928
Joined: Mon, 29. Dec 03, 04:29
x3tc

[Script] Station Manager v1.11 (March 27)

Post by Burianek » Tue, 27. Dec 05, 07:44

Deutsch

Download links:
Note: with 2 authors and 2 different hosts, sometimes versions will be different. Please check that you are downloading the highest version number below.

Station Manager Version 1.11 - AalaarDB's Zip with .spk
Station Manager Version 1.11 - Zip without .spk
Station Manager Version 1.11 - Burianek's host (both .zip and .spk versions available)
(note that my host service is awful, you likely won't get in on the first attempt. If it says page not found, just keep hitting refresh until it works. The most number of tries it's ever taken me is around 15, so you'll get in soon. Sorry ;))


Hi guys! Aalaardb and I have worked very hard to attempt to improve BPH for X3. We're pretty proud of it and we hope you like it!

See the second post for version history.

Description:
Station manager is a fully automated software system that manages and coordinates traders assigned to a factory. It will decide which wares need to be bought and sold, and where the best locations are to buy/sell them. It's very flexible and allows you to assign as many or as few traders as you like to take care of a factory.

Traders assigned to the same factory will coordinate with eachother, and will not all try go out to buy the same ware at the same time. They will also not visit the same stations to trade the same ware. Station manager allows you to customize the traders belonging to a station and set up individual parameters by ship for which wares should be traded, and how far of a jumprange to look within. So, for example, it is very easy to set up a spp to have two customized ships supplying it: 1. a very small, fast ship that looks for crystals to buy within a large jumprange. 2. a huge energy tanker that sells energy cells to the stations immediately surrounding the spp.

Traders will only buy resources if your station is less than 90% full, and will only sell products if your station is more than 10% full.

Traders that have been damaged to have less than 80% hull value will not continue trading for your factory. Instead, they will automatically fly to the nearest safe repair dock and contact you for help. Safe means that they will not cross any sectors owned by races defined as enemies in the ship's friend/foe settings.

In order for your traders to be able to see the ware prices within a sector, you must have a satellite, ship, or station in the sector to be scanned (this is shown by a green border around the sector in the galaxy map). Your ships will not visit sectors where they cannot see the ware prices. You can use this to your advantage. If you don't want traders to visit sectors because you think they might not be safe, do not put any satellites or ships in those sectors, and your traders will not look for stations to trade at within them.

Station Manager costs 20,000 credits to download and install in your station. This is a one time fee. If you stop the station manager command on your station and restart it, you will not be recharged.

--------------------------------------------------------------------------

Instructions:
Starting Station Manager (station command, station command console):
Select the 'Station Manager: Automate' command from the station command console. The first time this is activated on a station, the station account will be debited 20,000 credits to install the software.

Assigning Ships to a Station (station command, station command console):
After Station Manager is running on a station the command to add / remove ships from the station's list of traders will appear in the station command console. To add a ship, select the 'Station Manager: Add/Remove Ship' command and then select one of your ships. Note that your ship must not currently be docked to be able to find it to select it. Once your ship has been selected, it will be added to the station's list of traders and the ship will begin to be controlled by the Station Manager software. The following ship types can be assigned to trade for a station: M3, M4, M5, M6, TS, TP.
To remove a ship, follow the same procedure of selecting the 'Station Manager: Add/Remove Ship' command from the station command console, but then select a ship that already belongs to the station. The ship will be removed from the station's list of traders and will stop trading for the station and will begin to idle in space.
To get a list of the ships belonging to a station, select the 'Station Manager: Add/Remove Ship' command and then select the station itself. A nicely formatted list will be sent to your logbook, listing all of the traders belonging to the station and their parameters.

Continuing a Manually Interrupted Trader (ship command, trade menu):
It is possible to manually interrupt one of your traders by simply issuing it a new command. This can be useful to tell a trader to dock somewhere safe if you think it is in danger, or to repair a trader if needed. Once a trader has been manually taken control of, after a short period of time (less than five minutes), the station will see that the trader is no longer trading for it and will send a signal to the ship. This signal places a new command in the trade menu of the ship's command console, 'Station Manager: Continue'. Select the 'Station Manager: Continue' command to order the ship to begin trading for the station again. If your trader has been automatically sent to a repair dock to get fixed, you can also restart the trader after you fix it by issuing the continue command.

Defining Wares to be Traded (ship command, ship additional commands):
Go to the command console of one of your traders. In the additional ship commands section of the command console you will have the 'Station Manager: Prohibit Ware' command. Select the command and then select one of the wares to prevent your trader from trading it. To reallow your trader to trade a prohibited ware, simply select the command again and choose a prohibited ware. Your trader will now be allowed to trade it again. To see which traders can trade which wares, use the 'Station Manager: Add/Remove Ship' command from the station command console to get the station's list of traders as described above. Traders are set up to trade all of the wares of a station by default.

Setting a Jumprange (ship command, ship additional commands):
Go to the command console of one of your traders. In the additional ship commands section of the command console you will have the 'Station Manager: Set Jumprange' command. Select the command and then enter a jumprange. To cause your ship to use the standard station jumprange parameter, select the command and enter a negative number for the jumprange. Your ship will then use the standard jumprange defined at the station. To see the jumpranges defined for each trader, use the 'Station Manager: Add/Remove Ship' command from the station command console to get the station's list of traders as described above. Traders are set up to use the standard station jumprange by default.

Stopping Station Manager (station command, station command console):
Go to the station command console and select the command slot Station Manager is running on. Select none to stop the station from running Station Manager.

--------------------------------------------------------------------------

How It Works (Detailed Trader Logic Description):
- Your ships will look at their homebase and make a decision as to what the most critical ware to trade is. They will look at what other ships belonging to your homebase are attempting to do to help them make the best decision. So, if your station desperately needs energy, but you already have another freighter enroute to buy more than enough to supply the station with energy, your trader might look for a different ware to buy or sell.
- After a trader has decided which ware to trade for the station, it will look for the best station to go to. It will search the stations of all sectors within jumprange that have a player asset in them (have a green border on the galaxy map so the player can see ware prices). The trader will rank order the stations by best price, and then by shortest jumprange. It will then visit the best station that no other trader for this station is visiting. (traders can visit the same station if it is to trade different wares, i.e. two traders from an spp might visit the same crystal fab if one was going to sell energy, and the other to buy crystals)
- Once a trader has a ware and station to trade, it will start travelling towards that station. Every sector, the trader will make a limited search to see if there is a better station to trade at. A limited search means that only stations that are as close as, or closer than the current target station will be checked. This is to prevent a trader from flying one sector east and then saying, "oh wait, the best station is to the west", flying one sector west and then saying, "oh wait ..." and never landing anywhere. Traders that set out from a station will always continue to close to a target with every sector travelled unless something happens such that there are no stations within the jumprange to the current target that trade the ware for the price limits set at the homebase. When this happens, the trader will abandon the current trade run and will start completely over, looking for the best ware to trade for the station. (if it picks the same ware, it will expand its search to include all sectors within the jumprange of the homebase)
- If a trader ever picks a ware and finds that it cannot find any stations at which to trade that ware within the price limits set at the homebase, it will give up on that ware and pick the next best ware to trade for the homebase.
- If a trader finds that it cannot trade any wares for its homebase, it will return to its homebase and sit there until it is possible to trade something.

--------------------------------------------------------------------------

Explanation of Pathfinding Algorithm:
The station manager uses AStar to find paths to the destination, rather than the normal paths. These paths are, in general, safer. You can change the way AStar makes paths relatively easily, to customize it to your playing style.
AStar assigns a cost to each path it could take to get to the destination. It then chooses the path with the lowest cost as the optimum route. The easiest way to think of cost is: safety_weighting * distance, with higher safety weighting meaning more dangerous.

As an extremely simplified example, assume there are two paths to get to a destination:
Path 1: 300km travelled through enemy sectors
Path 2: 400km travelled through neutral sectors
Foe weighting: 1.55 (this is the default weight used for Foe sectors in station manager)
Path1 cost: 300km * 1.55 = 465
Path2 cost: 400km * 1 = 400
In this example, AStar would pick the safer route, even though it is a bit longer. Notice that if Path 2 were much longer (greater than 465km) AStar would actually prefer to go through the enemy sectors.

To change the saftey weightings to get AStar to prefer different routes on your computer, open up your script editor, and open the file ADB.AStar.GetPlayerCosts. You may edit the 4 numbers at the top, but it is recommended you only edit the FOE number. You may also edit the center of the script in between where it says to edit. This spot is for those who want to have different costs for different races of the same type. For example, Xenons might be more dangerous than Pirates although they are both FOE. Please do not edit any other files.
For instance, if you want the trader to stay safer by visiting enemy sectors less often, increase the FOE number. If you want your traders to prefer faster routes with increased risk, decrease the FOE number slightly. You can even make traders prefer visiting 'Allied' sectors more often by decreasing the Friend number.

If you are interested, please see here for a further explanation of AStar. Please note: the AStar here and there are different, the station manager version will not overwrite the commands - it is only for your station traders.

Feedback is very welcome!
Last edited by Burianek on Thu, 30. Mar 06, 05:13, edited 35 times in total.
"Nature's first green is gold" . . . stay golden.

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Post by AalaarDB » Tue, 27. Dec 05, 08:36

How to Run a Debug Trace

If you run into an issue with the script that can't be solved immediately, we may ask you to provide us a with a debug trace log. These logs help us determine what the traders are thinking, and may help us solve your problem.

To run a debug trace:

First, stop your freighters that are giving you problems, keep them assigned to the station, just give them a null command for a second.

If you enter the script editor in game, you'll see a script called:

stat.mgr.set.debug.verbose.xml


Run that one in the script editor by pressing 'r'.

For the first input, just hit null.

Next, it's going to ask you to pick one of your ships, you'll have a view of the galaxy map. Select the sector your freighter is in (can't be in a station or you won't see it), and then select the ship itself from the list.

That's going to toggle debug mode for that ship. From now on, everything the ship is thinking is going to be spit out to a logfile called log07650.txt in your main x3 directory.

You can turn on debug for more than one freighter if you want, or just for one. Might be easier to sort through the data if you only have logging enabled for one, but it's up to you.

Now, restart your freighters using the continue command like normal.

Once they do something weird (or don't do anything at all), we'll have a nice debug trace that will tell us why they did what they did.

Go into your X3 directory and open up that log07650.txt file. Copy / paste the contents and either:

a. post it here
b. if it's quite long (it may be) pm it to AalaarDB or burianek.
c. if it's really, really long, email it to jsburianek@yahoo.com


to turn debugging off on your frieghter, just follow the same steps you used to turn it on. That script is a toggle, so if you run it on a ship with debug off, it turns it on. If you run it on a ship with debug on, it turns it off.



Next Steps / Currently Working On:

--------------------------------------------------------------------------

Version History:
1.11-
Fixed a bug that occured only when selling basic wares (energy, food, etc) and the potential stations all had the same selling priority.

1.10-
Now supports complexes.
Small optimization that may increase future trading oppotunities.

1.09-
Traders will no longer attempt to buy wares if they have less than 20% free cargo space remaining

1.08-
Fixed issue with selling ships getting stuck at stations when they could not sell the ware

1.07-
Numerous code tweaks and fixes

1.06-
Bug fixes
Pathfinding reduced, if the ship is heading back home the path will be reversed rather than recalculated.
Changed the update method - updates now take place on loading a game.

1.05 -
MASSIVE REWRITE OF CODE
Fixed issue where traders selling to trade stations would get stuck trying to continue to sell to the same station.
AStar pathfinding integrated - Pathfinding is now better so traders are much less likely to go through enemy sectors.
Dramatically rewrote the code for efficiency.
Optimized the speed of the code.

1.04 -
fixed a very rarely occurring bug that would cause the game to freeze.
traders will now only buy resources if the station is less than 90% full, and will only sell products if the station is more than 10% full

1.03 -
fixed an issue with the script locking up the game when it couldn't find any stations to trade at
fixed a small error with local variables not being removed correctly from ships when shutdown
when a trader gets below 80% hull, it will now fly to the nearest repair dock (but will not cross enemy sectors) and contact you to make repairs
began to add the needed code to support complexes (complexes are still not supported as of this version)

1.02 -
ships now stop correctly (idle) when removed from a station using the add/remove ship command
station manager now charges one time fee of 20,000 credits
station finding algorithm and wait times dramatically optimized
you can now manaully interrupt traders without the station retaking control
new ship command: continue is used to restart a trader that you had manually interrupted

1.01 -
you can now use M6s
added checks to make sure docking is possible at stations
tightened up many decision making processes

--------------------------------------------------------------------------

Conflict section:
This script uses the following command slots:
<t id="420">COMMAND_STAT_MGR_CONTINUE</t>
<t id="1116">COMMAND_STAT_MGR_AUTOMATE</t>
<t id="1155">COMMAND_STAT_MGR_ADDREM_SHIP</t>
<t id="1255">COMMAND_STAT_MGR_PROHIBIT_WARE</t>
<t id="1256">COMMAND_STAT_MGR_SET_JUMPS</t>
Last edited by AalaarDB on Tue, 28. Mar 06, 01:55, edited 29 times in total.

XxNe0xX
Posts: 157
Joined: Sat, 9. Oct 04, 00:48
x3

Post by XxNe0xX » Tue, 27. Dec 05, 09:03

nice one :thumb_up:

could you maybe tell me which commandslots you're using?

PS:
I'm looking forward to jumpdrive using and auto repair :-)
Do you like secrets?
Try to find some.....
Goner-Secrets Mod

Naffarin
Posts: 465
Joined: Sat, 3. Dec 05, 10:49
x3

Post by Naffarin » Tue, 27. Dec 05, 11:03

Argh you've beaten me to it :)

Putting the trading logic into the station makes much more sense...wanted to do that myself
Very nice station picking logic...it returns the best solution instead of the near best that i use. Seems like i have to bother about competition a lot :)

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Post by AalaarDB » Tue, 27. Dec 05, 11:17

And here I was thinking I should make one that uses the AStar pathfinder that I wrote.

bloodystump
Posts: 23
Joined: Fri, 23. May 03, 16:58
x4

Post by bloodystump » Tue, 27. Dec 05, 17:08

Noticed a problem with ships that already have a homebase and complexes.

When trying to assign a ship to a regular factory, all is fine but if you try to assign a ship to a complex you get a message that it failed as the ship is already assigned to a station.

User avatar
Red Spot
Posts: 3224
Joined: Fri, 4. Feb 05, 14:44
x3

Post by Red Spot » Tue, 27. Dec 05, 20:38

X2 --> combat script
X3 --> trade script/economy design
X4 --> owner off egosoft ??..

I see a patern forming here ..
:lol:


G

User avatar
Burianek
Posts: 2928
Joined: Mon, 29. Dec 03, 04:29
x3tc

Post by Burianek » Wed, 28. Dec 05, 00:08

XxNe0xX wrote:nice one :thumb_up:

could you maybe tell me which commandslots you're using?

PS:
I'm looking forward to jumpdrive using and auto repair :-)
I'm using station 16 & 55, and ship additional 55 & 56
tried to use the fewest possible, but that was as few as I could go.
I suppose I could merge the two ship commands into one, but then that would make the interface clunky.

As far as the jumpdrive, I may not put that in. I'm still debating. I'm somewhat of a purist, so I think that since your competition (NPCs) doesn't use jumpdrives, you shouldn't be able to either. Allowing freighters to use jumpdrives takes the agony (and fun) out of positioning your factories imho.

The auto repair stuff will definitely go in though. I just haven't had time yet. I want to nail the core really well before I start adding frills and fluff. :)

Naffarin wrote:Argh you've beaten me to it :)

Putting the trading logic into the station makes much more sense...wanted to do that myself
Very nice station picking logic...it returns the best solution instead of the near best that i use. Seems like i have to bother about competition a lot :)
Yeah, I didn't like any of the stock trade solutions that return stations, so I wrote my own. It's kind of a brute force approach though, as it rank orders every potential station. My only worry is if someone decides they want to set a jumprange to 42 and it has to crunch through all those stations. I haven't tested silly extremes.

AalaarDB wrote:And here I was thinking I should make one that uses the AStar pathfinder that I wrote.
I'd be very welcome to trying to incorporate pathfinding into this one if you want to try to make the effort. I don't feel very territorial about my work, you can take it apart and rerelease it, or I'm happy to work together to try to improve it. Whatever turns out the best product for the community. I'm already a mod, I don't need the glory, I just kick/ban people that don't worship me enough :D heh
Arrested Development is the most underrated show on television by the way, I literally almost pissed myself when he stood up from behind the couch and said that. :D I'm astonished they didn't decide to renew the show, but I think HBO or Showtime is talking about picking it up. That might make it even better with no censorship :)
bloodystump wrote:Noticed a problem with ships that already have a homebase and complexes.

When trying to assign a ship to a regular factory, all is fine but if you try to assign a ship to a complex you get a message that it failed as the ship is already assigned to a station.
Hmmmmm.... complexes create all sorts of problems don't they?
I don't want to remove that check since I don't want people accidentally assigning a trader to two different stations (all sorts of bad things would happen). I'll test that more eventually, but to be honest, at this point, I have no complexes in my current game :D (I don't get a whole ton of time to play to be perfectly honest)
"Nature's first green is gold" . . . stay golden.

meadmb
Posts: 4
Joined: Tue, 27. Dec 05, 22:03
x3

Post by meadmb » Wed, 28. Dec 05, 01:18

Sounds great :thumb_up:

Just the dl link doesn't work for me :(

User avatar
Burianek
Posts: 2928
Joined: Mon, 29. Dec 03, 04:29
x3tc

Post by Burianek » Wed, 28. Dec 05, 04:26

Try it at least 5-10 times before giving up (wait a few seconds in between tries)
SBC Yahoo (my host space) is absolutely awful. Unfortunately, it's what I've got.
It should work eventually, sorry about that.
If it still doesn't work for you, try again later. I promise the link is ok.
"Nature's first green is gold" . . . stay golden.

Sgt. Steiner
Posts: 32
Joined: Mon, 28. Nov 05, 07:29

Post by Sgt. Steiner » Wed, 28. Dec 05, 06:04

I wouldn't put in jumpdrive personally. I had problems with Naffarin's script, when I had transports over near OL. They wanted to go get a jumpdrive, or drones etc., but couldn't find any so they just sat their and did nothing. It's just tricky since the only place to buy JP's is at HofL or CBSW. Well that I knew of anyway. Personally I don't think it's really necessary. They don't seem to use them for trade and most of the time they're only going 3 sectors away at best.

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 6053
Joined: Mon, 15. Dec 03, 19:53
x4

Post by BlackRain » Wed, 28. Dec 05, 06:53

What are you talking about Sgt. Steiner? The jumpdrives are what makes Naffarin's script so good. I have my merchants jumping all over, I usually set my jump range to 10, so they will jump up to 10 sectors away to trade. I have no issues with supplying them with jumpdrives or drones and I am making much more money now then I was. I don't think I could go back to manual flight.

User avatar
Burianek
Posts: 2928
Joined: Mon, 29. Dec 03, 04:29
x3tc

Post by Burianek » Wed, 28. Dec 05, 07:44

That's exactly the problem, you make too much money, it takes all the think aspect out of the game.

You can literally plop your factory anywhere, set your jumprange to 50 and rape the universe. The poor NPCs have no hope of competing.

To be fair, I don't like / use the MK3 universe trader either because I consider it unbalanced. The sector trader is fine imho (and appropriately priced) but the universe traders are ridiculous. They make more money than high end factories.

The more I think about it, I really doubt if I'll ever put jumpdrive support into this script.

I don't mind if someone else that can't live without jumpdrives wants to take this script and add in support for them and re-release it, but I don't think I'm going to do it.

I'm kind of making this script for the other purists out there that want the game to be more challenging, and want factory positioning to have a dramatic effect on factory performance. Not saying anyone is right or wrong, just my personal opinion on the matter.
"Nature's first green is gold" . . . stay golden.

AalaarDB
Posts: 2279
Joined: Thu, 29. Jan 04, 09:19
x3tc

Post by AalaarDB » Wed, 28. Dec 05, 07:45

Burianek wrote:
AalaarDB wrote:And here I was thinking I should make one that uses the AStar pathfinder that I wrote.
I'd be very welcome to trying to incorporate pathfinding into this one if you want to try to make the effort. I don't feel very territorial about my work, you can take it apart and rerelease it, or I'm happy to work together to try to improve it. Whatever turns out the best product for the community. I'm already a mod, I don't need the glory, I just kick/ban people that don't worship me enough :D heh
That sounds like LV. I think I'll get some ideas from your code but that's about it. I'm a programming student and classes don't start until January 23rd. So, I'd like to write it myself so it's a fun thing and a learning experience at the same time.
Burianek wrote:Arrested Development is the most underrated show on television by the way, I literally almost pissed myself when he stood up from behind the couch and said that. :D I'm astonished they didn't decide to renew the show, but I think HBO or Showtime is talking about picking it up. That might make it even better with no censorship :)
Gob: Well check it, the illusion is called 'Freebird'. A magical bird, me in a beak, stands on a platform. There's a puff of smoke; and I'm gone. Then, seconds later, high above in a once empty cage, who should appear...
Lucille: A guy that kind of looks like you?
Gob: No. Not how I do the trick. Even if it was... how'd the lookalike get up there?
Michael: He was hiding behind this mirror?
Gob: NO!!!

You may or may not be aware but I've compiled a bunch of Arrested Development jokes into the Comm Chatter Missions. OK, you probably already knew about that, I just wanted to put in a plug for it.

Tobias: Oop, correction, make that 4,000 plugs.
Lupe: Mr. Gay, he's bleeding! Mr Gay.

User avatar
Burianek
Posts: 2928
Joined: Mon, 29. Dec 03, 04:29
x3tc

Post by Burianek » Wed, 28. Dec 05, 07:47

Oh, version 1.01 released by the way.
I'll keep a version history and planned next steps in the second post.
Biggest thing about this new version is that I'm pretty sure the decision making logic (which ware to trade, which station to fly to, etc.) is near final in this version. I've tweaked a lot and I'm pretty happy with it.
"Nature's first green is gold" . . . stay golden.

Post Reply

Return to “X³: Reunion - Scripts and Modding”