[Work In Progress] Functional Trader + stable supply/demand (0.22 final WIP)

The place to discuss scripting and game modifications for X Rebirth.

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

Bobucles
Posts: 2259
Joined: Fri, 25. Dec 09, 03:56
x3tc

Post by Bobucles »

Once i have a functioning economy with the shipyard wasting ressources, (and fixed players trades), ill be working on the fight part of it assuming i cant find another mod that fix it to a state where i can enjoy it.
Wasting resources at shipyards is a bad idea. The trade system is set up so that a construction project's required resources are the trade offers. If you complete one trade, then take an hour to complete the next trade, your project will never get built because it's dissolving everything you put into it.

Shipyards are already excellent resource sinks. Leave them be.

Consider this instead:
- Civilian vessels are the "eaters"
- They go to any resource producer, buy stuff
- goods get consumed. Nom nom.
- Fly to next station and repeat.

This lets you use a whole network of existing ships that currently don't do much. They don't have to be particularly smart or generous, but they can be weighted to consume surplus goods and can even "magic spawn" rare goods to keep the economy stable. In addition it creates a large amount of natural highway traffic, so that you can ditch the ghost ships.
Last edited by Bobucles on Thu, 28. Nov 13, 15:42, edited 1 time in total.
DWORD
Posts: 5
Joined: Thu, 28. Nov 13, 15:24

Post by DWORD »

Jey, thank you a lot! Since yesterday I discovered this mod and game looks playable again.

I wanted to ask you few questions regarding the mod
  • Will you consider making trading galaxy wide or are there any specific reasons you would like not to do that (besides performance).
  • Could you consider increasing number of locations where cargo is being sold by stations - due to really big demand? However I am unsure if you could even do it since perhaps there are limits on game engine wise.
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

the number of docks is an entirely separated thing, and not really needed (the initial rush is simply because you had a build up, once thats past, the number of docks is generally sufficient).

Yes, i do plan on making it galaxy wide, but not on every ships, only a few specific "xl" that can actually defend themself in case of fights (since going to another galaxy mean high risk of meeting enemy factions).

It just is easier to work for the bug fix / tracking etc if i go step by step, i still have quite a few things to fix in the zone and sector before hitting the galaxy wide one.
DWORD
Posts: 5
Joined: Thu, 28. Nov 13, 15:24

Post by DWORD »

Thanks for the quick reply. What's your take on the way prices are made?

Currently I see so many locations carving for energy cells and they are buying them for -20% wtf? Same goes for many other materials, the prices act like there is so big supply of materials. Meanwhile suppliers are acting like they are unable to count their clients. So I am in a situation where I must buy for +20% and sell it for -20%. Could this be the result of turning on galaxy wide trading (mentioned few posts back).

Edit: language.
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

I did not see the case your talking off here, starving location end up buying at +15-20% here and locations filled to the brim sell in the -15% range.

Altho on the vanilla (and the currently available wip which is using vanilla code for the traderoute checks) favorize selling cargo to location paying the least >_> lol, which well, in turn can cause some very weird prices going on.

I have it fixed in my cleaned version, where i rewrote entirely the findfreetrade functionality to be a lot more performance friendly and economy friendly, all the while to be less penalizing to the player traders (since right now, ai reserve the stuff out of the stations, so even if the trader is far from the trade, the station immediatly stop buying the stuff from the players). In my new code (the one not available yet), the player can "steal" an ai traderoute since player still reserve the trade, and ai cannot do the trade if the ware ended up reserved heh.


There also dont seem to be a requirement to dock at the precise dock where the trade is visible on the station, the ai will dock at any docking port sharing the same station i believe, so it can get a confusing when you start at an ai trading and try to check the docking port offer xD.
DWORD
Posts: 5
Joined: Thu, 28. Nov 13, 15:24

Post by DWORD »

Can't wait for your next update!
lysol
Posts: 12
Joined: Thu, 20. Jul 06, 04:53
x3

Post by lysol »

Jey123456 wrote:lol, no. I'm actually the lead programmer for a small space mmo called Star Sonata.

I just enjoy fixing XRebirth when i have a few hours free.
Love that game. Thanks for you and your teams work on it.
User avatar
BurnIt!
EGOSOFT
EGOSOFT
Posts: 5114
Joined: Wed, 6. Nov 02, 20:31
x4

Post by BurnIt! »

We appreciate your efforts and are certainly looking forward to what comes next, however allow me to add a cautionary word of warning here:

We are of course also working on fixing the issues that plague trading in the game and using these modified scripts will almost certainly cause problems going forward as many will be changed with the next update.
Savegames created with these scripts active may not work with the upcoming 1.18 patch. Or in your own words:
Jey123456 wrote:I also strongly suggest you backup your save file, as there is a chance it will **** it up
BurnIt!
In der Ruhe liegt die Kraft. / In peace lies strength.
mikeck
Posts: 98
Joined: Sat, 22. May 10, 21:20

Post by mikeck »

I'm sure your right...i always start a new game with a new big patch. Just edit the new game save to give me the cash to buy what I had accumulated in the last save
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

savegame created with it already kinda mess up on 1.17 if you remove it so not exactly a big surprise here xD.

While your here, any idea on how force the game to stop the script when the version changed ? I tried using the sinceversion tag but all it did is cause a ton of error about incompatible script id and the parent script also died (even tho the parent was still compatible and without the sinceversion to the runscripts inside, it works, but as expected, issues shows up since the scripts changed midrun).

Altho i dont expect 1.18 to actually break my mod, my mod will simply ignore the changes (unless there is a major structural change), since in the cleaned version, any file i did major changes to end up in a new script with only a redirection added to the original ones (so that all new calls to it end up calling mine).

The script "crashing" problem is basicly one of the last issues i want to fix before i can push it, since right now, any update i push require a new game or things go awfully wrong heh.

Essentially, i need it to abort the child scripts without aborting the parent, so that the parent loop can just restart it on the new version.
User avatar
BurnIt!
EGOSOFT
EGOSOFT
Posts: 5114
Joined: Wed, 6. Nov 02, 20:31
x4

Post by BurnIt! »

Unlike in previous games a script doesn't need to be restarted to run the updated code.
There is currently no way to access the real game version from scripts, maybe we'll add that later.

The midrun-change situation can be a challenge sometimes since you need to code the script in a way that it can cope with some variables simply not being defined yet. <do_if value="not $myvariable?">...</do_if> (note the ? at the end) will do something when the variable is undefined.

(ab)using that you could do something like this:
in the script that is currently running increment the version attribute in the root node and add a new variable in the <init></init> block (above <attention.. />).
Further down after the code that may be currently running (after blocking actions like <wait>, <move_to> etc.) you can then check if this variable exists. If it doesn't then you know that the script was running at the time the version changed.
Next would be to use <signal_objects /> to send a notification to "this", param could be something like 'jey123456_script_abort'.
Adding a handler for <event_object_signalled /> with a check for that param to the root script you could then call <abort_called_scripts /> from its <actions> node and even let your root script resume at a label of your choice.

Now this is not exactly "best practices" but a way that should work with the tools available.
BurnIt!
In der Ruhe liegt die Kraft. / In peace lies strength.
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

mmm, alright so i take it "sinceversion" is currently not functional on runscript then ? its accepted since its a blocking action, but if you use it, then any save that now "conflict" with that version (on normal blocking action, it seem to just cancel the action and continue), but on a runscript, it cause the game to go a bit crazy, refusing to ever run the script, and crashing the script containing the runscript with sinceversion heh.


Which bring me to the reason why i tried to use sinceversion on a runscript.

When adding new scripts in the middle of everything, i ended up with a lot of issues like, untouched scripts (move.generic for instance), complain on return that it did not provide a return parameter that was expected, but that return param is not expected on move.generic, but on one of my new script.

The only way i found to fix those is to start on a new universe.
User avatar
BurnIt!
EGOSOFT
EGOSOFT
Posts: 5114
Joined: Wed, 6. Nov 02, 20:31
x4

Post by BurnIt! »

The sinceversion attribute is to indicate in which version of a script a blocking action was added, hence whenever such an action is added the scriptversion must be incremented as well (at least every time the script is made available to others)
Otherwise it'll get confused which of the blocking actions it is currently in when restoring from a save. (it saves in which blocking action it is currently in with an index number which is basically a counter for blocking actions)

example:
Your script is version 1.
You have these blocking actions in it:

<wait />
<move_to>
<wait />

now you want to add a <run_script /> before the <move_to />
You should increment the version attribute of the <aiscript /> node to 2 and change your code to look like this:

<wait />
<run_script sinceversion="2" />
<move_to>
<wait />

Also another potential trap is removing blocking actions. Currently you can't just take one out because that'll cause issues with the saved index of where the script was. So you need to "neutralize" that action.
Either wrap it in <do_if value="false" >.. or add a chance="0" attribute so it is not executed.
BurnIt!
In der Ruhe liegt die Kraft. / In peace lies strength.
Jey123456
Posts: 259
Joined: Sat, 23. Nov 13, 09:48
x4

Post by Jey123456 »

ahhh, the removal part might be the problem then. Thanks, ill keep it in mind as i finish cleaning that up tomorrow.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

thanks for these Infos on Blockingactions and Versions BurnIt! - i bet it will be useful :)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)
User avatar
BurnIt!
EGOSOFT
EGOSOFT
Posts: 5114
Joined: Wed, 6. Nov 02, 20:31
x4

Post by BurnIt! »

I wish we'd have had more time to get a proper modding documentation ready for you guys, but unfortunately the focus had (and still has) to be on making sure the unmodded game works correctly.
BurnIt!
In der Ruhe liegt die Kraft. / In peace lies strength.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

well, as you can see from the growing page size we are figuring it all out ourselves, we just neeed the proper tools (and some hints how to use them) ;)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)
Nerevar38
Posts: 16
Joined: Sat, 16. May 09, 14:48
x3tc

Post by Nerevar38 »

Hi Jey123456,

Maybe I have found something concerning your actual topic.
I've just discovered the file "libraries/aicompat.xml", which looks a lot like a list of blocking actions and their locations within all the aiscripts.
I thought it was a bit odd to have them referenced by line-numbers, or that the file is not autogenerated at all.
Anyway, my original thought about this list was that it is used to determine locations where a script can be safely interrupted.
It also might define locations where to continue execution after an interrupt/block.

I would suggest updating this file to reflect your changes and maybe it could solve some of your problems.

I hope this can help you a little bit.

Here is a "small" snippet of that file.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<compatibility>

...snip...

  <aiscript name="move.unpark" version="0">
    <attention min="unknown">
      <run_script line="14" label="start"/>
      <wait line="26" label="start"/>
      <move_strafe line="28" label="start"/>
      <move_to line="34" label="start"/>
      <move_to line="40" label="start"/>
      <move_to line="52" label="start"/>
      <wait line="68" label="start"/>
    </attention>
  </aiscript>
  <aiscript name="player.default" version="2">
    <attention min="unknown">
      <wait_for_prev_script line="171" sinceversion="1" label="init"/>
      <run_script line="176" sinceversion="1" label="init"/>
      <run_script line="189" label="init"/>
      <run_script line="195" sinceversion="2" label="loop"/>
      <run_script line="202" label="loop"/>
      <wait line="210" sinceversion="2" label="loop"/>
    </attention>
  </aiscript>
  
...snip...

  <aiscript name="trade.performplayertraderun" version="1" priority="60">
    <attention min="unknown">
      <wait line="11"/>
      <run_script line="83" label="move to target object"/>
      <wait line="106" label="move to target object"/>
      <run_script line="109" label="move to target object"/>
      <run_script line="124" label="move to target object"/>
      <wait line="129" label="move to target object"/>
      <run_script line="167" label="check trade"/>
      <run_script line="188" label="check trade"/>
      <run_script line="224" label="check trade"/>
      <run_script line="243" label="check trade"/>
      <execute_custom_trade line="272" label="perform trade"/>
      <execute_custom_trade line="282" label="perform trade"/>
      <detach_from_masstraffic line="294" sinceversion="1" label="perform trade"/>
      <detach_from_masstraffic line="300" label="perform trade"/>
      <detach_from_masstraffic line="304" label="perform trade"/>
      <detach_from_masstraffic line="308" sinceversion="1" label="perform trade"/>
      <wait line="373" label="perform trade"/>
      <run_script line="391" label="waitfororders"/>
    </attention>
  </aiscript>
  <aiscript name="trade.performtraderun" version="0">
    <attention min="unknown">
      <run_script line="44" label="check trade offers"/>
      <run_script line="65" label="move to target object"/>
      <run_script line="91" label="move to target object"/>
      <run_script line="105" label="move to target object"/>
      <execute_trade line="142" label="perform trade"/>
      <detach_from_masstraffic line="154" label="perform trade"/>
      <wait line="171" label="perform trade"/>
      <run_script line="183" label="finish"/>
      <run_script line="200" label="finish"/>
    </attention>
  </aiscript>
  <aiscript name="trade.ship" version="1">
    <attention min="unknown">
      <wait line="30" label="start"/>
      <run_script line="31" sinceversion="1" label="start"/>
      <wait line="73" label="find trade run"/>
      <run_script line="75" label="find trade run"/>
      <run_script line="84" label="perform trade run"/>
    </attention>
  </aiscript>
  
...snip...

</compatibility>

P.S.: Just wanted to say that I really like your work.
Exsilium
Posts: 14
Joined: Fri, 8. Jul 11, 23:10
x4

Post by Exsilium »

I ran the game for over 12 hours straight from a fresh start after installing this mod. Things I have noticed:

Traders do stuff. Yay! Problem is, it seems the game cant handle it. I have noticed that after a while the majority of ships just warp away somewhere.


After a few minutes most of these warped away.
[ external image ]

These stayed here for a long time. This is a jump node so even while some were moving away new ones were jumping in. It was constantly like this.
[ external image ]

Ships mating with stations.
[ external image ]
Exsilium
Posts: 14
Joined: Fri, 8. Jul 11, 23:10
x4

Post by Exsilium »

Two other problems I have noticed is:

1. Negative resource count for a zone, like -12345678/-12345678. That cant be right. I changed the first number to positive, but could not find a place to change the second number.

2. Stations dont always have a place to sell their wares. One specific example was a water treatment plant, had lots of ICE, but had limited energy, so was never actually producing anything. It is possible that the SELL point doesnt appear on the base until after it has something to sell, not sure about that.

3. ENERGY!!! EVERY station seems to be starving for energy. It seems to be the single most important bottleneck for the entire economy, and is probably why after a while there is nothing left to buy...

Return to “X Rebirth - Scripts and Modding”