[SCR] OK Traders v1.7.1 (04-12-14)

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

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

Post Reply
reiks
Posts: 110
Joined: Mon, 11. Jan 10, 07:28
x4

Post by reiks » Wed, 5. Jun 13, 15:54

One thing I would love as a feature is that to have the ability to save a sector blacklist list. Every game start I need to re enter all the sectors i want blacklisted like for example in AP I always tend to blacklist all the terran sectors or the war sectors and sectors adjoining xenon sectors from the list.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 5. Jun 13, 16:14

I can sympathize with that but the ideal export/import approach might require manual intervention as the script can't readily interact with the filesystem:
1. Pushing Export could write a logfile into My Documents\Egosoft\X3AP with delimited blacklist items.
2. User must manually copy and paste that into a line within 9055-L044.xml
3. The setup script reads the textfile ID, parses the delimited sector names out, resolves them and builds up a default list.

Another approach might be to add buttons into the blacklist menu to ban all sectors for a race, ban AP war sectors, which I think are detectable using AP specific script commands.

I'd probably go for the latter as it's less arcane and will be more generally useful. Though it won't be an immediate priority as I'm trying to restrain feature creep right now and drive stability with patches.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 5. Jun 13, 22:14

I've uploaded 1.2.3. The key change in this mission is the middle part about revising search criteria.

Most significantly free traders weren't ever using a search mode other than 'find nearest' when looking for a place to sell a ware. This had 2 key issues:
- Reduced profit. Selling a ware was looking for the nearest place to offload rather than based on price, although it was still buying at the best price so the problem was mitigated and harder to detect. I didn't notice until the following occurred...
- When buying from a dock it would then sell the ware back to the same dock as it was also the nearest place to sell at. Repeat until some other ware makes a better trade.

I've revised this logic and set a new floor for amount of jumpdrive energy available before performing a 'best price' search for buyer/seller stations. That is 2x max jumps worth for homebased traders, and 1.5x max jumps worth for free traders. Where max jumps for free trader is approximated as universe width plus height. Note that traders will load up on 2.5x max jumps energy when refuelling, though this is capped at 40% of cargo bay size.

If they don't have that much energy, or have no jumpdrive at all, they'll fall back to a 'best chance' search. This is identical to the search type used in 'buy ware for best price', and still produces excellent results. It just appears to prefer stations within jumprange to those further away.

'Find nearest' isn't used at all except when looking for equipment (jumpdrive), as for some reason the 'best chance' method doesn't find them.

It may still be possible for a free trader to buy and sell at the same dock, though I haven't observed it. This is harder to tackle because a sale is carried out independently from a purchase. Free traders simply sell everything on board that isn't nailed down before buying something. So they don't know where they bought it or what price it was bought for. The idea is it sells what it has at the best price anywhere, as it's better to make a loss in rare cases than to clog up the cargobay and reduce efficiency.

1.2.3
- Switch display command to COMMAND_REFUEL when moving to an SPP.
- Revised criteria for searching stations by best-price vs best-chance vs nearest.
- When rerouting a buying mission check the ship can jump to the new destination, otherwise reevaluate.

User avatar
vukica
Posts: 1744
Joined: Sun, 10. Aug 08, 18:05
x4

Post by vukica » Wed, 5. Jun 13, 23:22

Shimrod wrote:It may still be possible for a free trader to buy and sell at the same dock, though I haven't observed it. This is harder to tackle because a sale is carried out independently from a purchase. Free traders simply sell everything on board that isn't nailed down before buying something. So they don't know where they bought it or what price it was bought for. The idea is it sells what it has at the best price anywhere, as it's better to make a loss in rare cases than to clog up the cargobay and reduce efficiency.
why not just have it buy at price less or equal to average, and sell for anything higher than average?

buy_price <= average
sell_price > average
Split say NEED MORE FIREPOWER!!

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 6. Jun 13, 00:25

Unless I'm mistaken docks buy an sell at fixed average price, so if traders only sell at avg+1, they'll never be able to sell lasers, missiles or shields as docks are the consumers.

If it was done the other way round, only buy if price < average, traders wouldn't then buy anything from a dock either. Typically I hope they'll find more profitable trades, but it'll at least prevent them finding a jumpdrive.

I think it might require some annoying hack like recording last purchased ware, location and price, and if [DOCKEDAT] sells that ware for that price then put it in the exclude array when searching.

However the 'find nearest' fix both reduces the likelyhood of it and the impact. At worst it might buy and sell 1 lot, if market conditions (or jumpdrive energy) changes so it's not worth selling it elsewhere. That might not actually be a bad thing.

As soon as the next mission is planned it won't generate the same mission net profit of buying and selling at the same place will be zero, and if it does pick a 2nd leg station that's not the one it's docked at, then this will also be the place it sells at since both use the same search logic.

So it's reduced to an imo harmless, rare and academically interesting condition that warrants an elegant fix, but isn't worth doing anything kludgy to try and address.

reiks
Posts: 110
Joined: Mon, 11. Jan 10, 07:28
x4

Post by reiks » Thu, 6. Jun 13, 14:44

Shimrod wrote:I can sympathize with that but the ideal export/import approach might require manual intervention as the script can't readily interact with the filesystem:
1. Pushing Export could write a logfile into My Documents\Egosoft\X3AP with delimited blacklist items.
2. User must manually copy and paste that into a line within 9055-L044.xml
3. The setup script reads the textfile ID, parses the delimited sector names out, resolves them and builds up a default list.

Another approach might be to add buttons into the blacklist menu to ban all sectors for a race, ban AP war sectors, which I think are detectable using AP specific script commands.

I'd probably go for the latter as it's less arcane and will be more generally useful. Though it won't be an immediate priority as I'm trying to restrain feature creep right now and drive stability with patches.
Thank you for the reply and yes I think what you suggested would also work!

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Fri, 7. Jun 13, 23:46

I'm going to call 1.2.3 is stable as far as free traders go. I have 30 free trader mercury haulers now at 16 game hours and the profits steadily clock up. I've only had one ding where a neutral pirate base was surrounded by red lasertowers, and even with only a 1MW shield he managed to jump with 2% hull remaining so I could send him for repair.

After finishing exploring and as rep permits I'm going to set up some factories and watch out for any homebase trader issues. If it's all pretty solid then that'd be the time to review enhancements that have been proposed (inc. repairs, blacklist enhancements add-by-race/war). Though I fancy playing through the AP missions in earnest to see what's new so maybe will back burner that.

Major avenues of future development might include trading from ship homebases (miner support, sell wares that a mothership roams around collecting, resupply), huge ships acting as traders via transporter/trade drones. At some point I want to call it done though.

Playtesting notes:
- Couple of free traders killed when en route for fuel. One was heading through Xenon Sector 472.
- Getting attacked by terrans in war sectors despite neutral relations.
- Most pirate sectors end up needing blacklisted. A few other race sectors due to wandering pirates, Grand exchange agro from Xenon. Yaki sectors no trouble at all.
- Just 1 trade mission for teladi and my rep jumped up from not able to buy m3+, to being able to buy osprey and albatross. Way higher boost than what my army of traders are bringing in on their own.
- Manually equipping jumpdrive on homebased traders was annoying, need an auto equip option for them. Consider as part of an overall equipping config model.
- Starting off with no fuel from terracorp hq, homebased traders went to buy wares rather getting energy first. Had to manually send them to SPP to fuel up. Should make them refuel first.

johntarmac
Posts: 393
Joined: Fri, 5. Mar 04, 19:47
x3tc

Post by johntarmac » Sun, 9. Jun 13, 09:50

If there is another revision the only niggle I have is the warning message when a trader is is trouble is a little short. Another 5 seconds or so on the duration of the pop-up would be great.

Cheers

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 12. Jun 13, 00:57

These are the 1.3.0 changes I'm currently testing. No ETA eta on release though.

Code: Select all

- Traders now repair hull damage at a shipyard
- Homebased traders now buy jumpdrives like free traders already do
- Ships will refuel when below 15% of reserve energy.
- Increase the attacked warning subtitle message duration from 3 to 6 seconds.
- The monitor task now rapidly restarts the cmd script on version upgrade. This resumes the ships current action where possible.
- Fix a bug where traders might think they had sufficient energy to jump when they didn't (since 1.0.0)
- Fix: prevent selling wares at player owned stations. Bringing available funds into the equation adds complexity and supporting selling to self may not always be desirable. (since 1.0.0)
- Fix attempting to top up jump energy amount exceeding available cargo space (since 1.1.0)
If any of this presents a problem for anyone's edge cases let me know (particularly JD for homebase traders, no selling to player stations).

The last part I'm looking at is the blacklist enhancements. I'm considering adding the following 3 options, as they're the only blanket bans I'd need based on my current AP game experience.

1. Add pirate sectors
2. Add non-jumpable sectors
3. Add war sectors

As traders exclude stations they have no docking rights for, there's no need to include Xenon, Khaak or whatever race is at war. There might be edge cases of hacked stations in border sectors but these could be individually blacklisted. I might add that these won't dynamically update the blacklist over time, it's just a one-off search and mass addition of sectors.


Finally an observation. I found my free trading kestrel had stopped trading. Turns out he'd been buying lasers and fighter drones in his travels, and because OK's 'get amount of ware on board for sale' calculation excludes the amount of lasers that could be equipped by the mainguns and all turrets, as well as a quantity of fighter drones, he finally filled up his cargobay when topping up on jump energy and just parked up in a station. So be wary of ships with miniature cargobays :)

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Wed, 12. Jun 13, 01:23

Some other possible refinements for your long-term list (not priority):

- Do not attempt to travel without sufficient jump fuel to reach the destination (this might be something you are already doing -- I could not tell for sure).

- Obey ATF restrictions to inner Terran sectors. In TC, never enter Earth sector.

- Be careful about jumping to outer Terran sectors in AP. AI likes to jump to the North gate in Asteroid Belt. They often survive through the gate, only to wind up having to cross Jupiter (war sector). It is a large and lonely place for a trader. (Most current blacklists do not take this issue into account; they may not choose Jupiter as a destination, but they attempt to travel through Jupiter.)

- There are situations in which a trader may find itself inside targeting range of an enemy capable of a one-shot kill (3km OOS and 7-ish IS). This may be a certain-death situation when OOS because it can take two turns to jump while only one turn to die. To make matters worse, the faster ship gets the first turn; and that is often a Xenon Q. In those cases, consider an insta-emergency jump. It is a feature that should be in the vanilla game, so this is your opportunity to "fix" that. ;)

- Speaking of blacklists, consider a ware blacklist as well. It can be annoying to try to find a rare weapon or missile when the free traders have sold them all for profitsss!

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 12. Jun 13, 02:30

Thanks, some handy ideas. I haven't done any Terran sector trading so far, have yet to encounter those problems. I've only ever used tethered sector traders with a jumprange in terran sectors before, and only with a purpose of boosting reputation rather than seeking profits. Never seemed like a worthwhile excercise for profit, given size of sectors, lack of jump access, and trade scripts tripping over special access conditions for the inner planets.

I've significantly revised jump energy calculations in 1.3 and hope to have minimized cases where traders run out of jump energy. The action selection logic now goes:
1. Buy a jumpdrive if don't have one
2. Refuel if below 15% of reserve energy
3. Go to SY for repair if below 100% hull
4. Select trade mission
5. If cannot jump from here to destination then on to an energy source, then refuel.

When refuelling it performs a 'find nearest' search using max 75% of ware price. This should promote shorter hops to refuel.

The logic surrounding trade mission selection is now common to both homebased and free traders, whereas it was previously a little quirky. Free traders would always sell wares before refuelling for example, and homebased traders wouldn't refuel anywhere other than their homebase.

There may be edge cases to discover and weed out with mission redirection and fleeing, but in the main I'm happy with that logic, it brings more intelligence to the party than 1.2.3.
Last edited by Shimrod on Wed, 12. Jun 13, 02:38, edited 1 time in total.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Wed, 12. Jun 13, 02:37

It sounds all good, Shimrod.

Why limit the price for buying fuel? The trader cannot safely move without it, and energy cells can be far away in some sectors. If the trader needs it, then he needs it, regardless of the price.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 12. Jun 13, 02:43

I guess the 75% price was really an easy way of wanting at least 25% stock in the station, to help ensure a decent refill even from a small SPP.

Using the price point fits the code without having to significantly change Find.Station, since it doesn't currently factor stock level into the station finding APIs.

Though having thought about it military outposts will always sell for average price even with hardly having any stock, so and amount-based minimum equivalent to something arbitrary like 5 jumps minimum may be more sensible.
Last edited by Shimrod on Wed, 12. Jun 13, 02:49, edited 1 time in total.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Wed, 12. Jun 13, 02:48

A thousand energy cells would be a lot for most traders, and almost nothing at all for a Solar Power Plant. Also, SPP's produce quickly. So do you really need to check for how much they have on hand?

If the trader lands at an SPP that does not have enough ecells, then it could safely wait until there are enough. It will not take long.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 12. Jun 13, 03:01

Need to be careful of military outposts and odd docks that cell ecells though, they don't produce ecells fast and the majority of them are usually empty.

If we can be confident using the factory vs dock finding APIs as exposed by X-Studio (which differ from the real script APIs) can reliably be used to differentiate searching guaranteed quick producers, then no limits could be supplied when using 'find factory', while some arbitrary multiple of unit jump energy could be supplied as a minimum when searching docks.

I do recall in ages past deploying crystal free SPPs and finding they produced rather slowly, though I can't think of any relevant example of a slow energy producer outside of docks in my recent experience.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Wed, 12. Jun 13, 03:03

Shimrod wrote:I can't think of any relevant example of a slow energy producer outside of docks in my recent experience.
Neither can I.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Wed, 12. Jun 13, 10:35

I recall from build SPP station missions that they retain their crystal resource when handed over to NPCs. Traders will also buy at player stations that require resources. I'm worried that a trader could stall in a non-producing SPP as it's the nearest, while it never produces any energy.

One approach might be to to require a minimum stock level when searching for an energy provider along the orignal lines, providing amount input on the find APIs works as anticipated.

Another would be to exclude a minimum stock level in the search, but apply a filter to the results that a) factory is not a dock, d) producer has no resource ware entries. If true then assume ecells will appear (so it's ok to stay parked there until energy hits desired level), otherwise require that the station/dock has some minimum amount.

There are perhaps still edge cases for the last like factory production tasks being disabled, that might result in waiting on fuel from a non-producer indefinitely, but unless a real world example manifests I'm inclined to go with your suggestion of leaving stock level aside in the sxearch, while including the producer test in the search result filtering as a sanity check and falling back to requiring some amount.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 13. Jun 13, 20:37

consider an insta-emergency jump.
I find there are cases when the trader picks up agro immediately at a jumpgate, or when it flies near some roaming pirates before getting targetted, so that it starts taking OOS damage quickly before the jump countdown completes. Insta-jumping would certainly help but I'm keen on keeping the simulation legit or at least introduce an acceptable tradeoff.

It's often the case in movies that ships perform blind emergency jumps with risk attached. I think it'd be acceptable for a ship to have percentage chance of mis-jump. Side-effects might include:
- Ship materializes in a random sector
- Ship disappears never to return
- Jumpdrive is destroyed
- All fuel consumed

It's something I'll consider for the future, particularly if more demand for it manifests.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Thu, 13. Jun 13, 20:42

Shimrod wrote:- Ship disappears never to return
*Chuckle*... oooh, that would be nasty. Just before the jump, better send an emergency mess... <no further communication from OK Trader 122>

:)

Traders are pretty defenseless on their own. If they do suffer emergency jump damage, then perhaps they should fly to the nearest friendly station and radio the player for help?

Vayde
Posts: 849
Joined: Fri, 6. Feb 04, 21:02
x3tc

Post by Vayde » Thu, 13. Jun 13, 21:06

Think I've found a bug/feature.

During a trade run one of my traders was targeted before she could deliver the wares, she jumped clear. Instead of continuing with the run she started looking for another buy option.

She is now running around the universe with 274 Terran MRE on board. I can stop her and sell via best buy/sell software but would like to have them do this on their own.
Still life in the old dog yet...

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”