Cargo Contracts MOD for Oolite v1.77 and v1.79!

For test results, bug reports, announcements of new builds etc.

Moderators: another_commander, winston, Getafix

Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

Yes, Cargo Contracts Mod seems broken in some ways when attempting to use it with Oolite v1.80 and later.

I may try to make a later version, but I still cannot figure out how to generate lowest and highest possible prices for a remote system or even the system I'm in!
Instead i get a bunch of sample prices and just pick the lowest and highest ones of the bunch.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD still broken!

Post by Switeck »

Now using Oolite v1.88!

I still cannot figure out how to generate lowest and highest possible prices for a remote system or even the system I'm in!
Instead i get a bunch of sample prices and just pick the lowest and highest ones of the bunch.
Lowest price for starting system, highest price at destination.
Subtract starting cost from destination amount to get "max" profit, which can be pretty pathetic because even 20 random samples may not be within 90% of the real max or min.

I have to use an arbitrary money cheat to make this work -- multiply the profit results by up to 150% for high cargo reputation, which even still may be less than theoretical max profit.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

This mod is still broken, as my workaround causes multi-second-long game freezes on entering a system as it tries to calculate new cargo contracts using a loop that makes 100+ very slow Oolite library calls.
The workaround also is less profitable than the original was. :(
hiran
---- E L I T E ----
---- E L I T E ----
Posts: 764
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by hiran »

Switeck wrote: Wed Nov 24, 2021 11:39 pm This mod is still broken, as my workaround causes multi-second-long game freezes on entering a system as it tries to calculate new cargo contracts using a loop that makes 100+ very slow Oolite library calls.
The workaround also is less profitable than the original was. :(
Would it be feasible to trigger a thread on entering a system, and this thread would run the 100+ Oolite calls in it's own time, while the original thread returns and allows the game to move on? I doubt a player needs all contracts in the event the ship emerges from witchspace.
I have not failed. I've just found 10,000 ways that won't work. [Thomas Edison]
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

I wouldn't know.
Most of my modified cargo contract .js file is identical to the original file due to my limited programming skills. :P

I'm vaguely familiar with callback: function ...but only because I've seen it in a couple other OXP's .js files.

There is internal logic for this that is .js accessible that would be much faster...I just can't get it to work.
hiran
---- E L I T E ----
---- E L I T E ----
Posts: 764
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by hiran »

Switeck wrote: Tue Nov 30, 2021 4:24 am I wouldn't know.
Most of my modified cargo contract .js file is identical to the original file due to my limited programming skills. :P

I'm vaguely familiar with callback: function ...but only because I've seen it in a couple other OXP's .js files.

There is internal logic for this that is .js accessible that would be much faster...I just can't get it to work.
I am no JavaScript expert. But Google brought me to
https://stackoverflow.com/questions/737 ... new-thread

Maybe that helps?
I have not failed. I've just found 10,000 ways that won't work. [Thomas Edison]
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

The script already does something like that.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

Here is the testing form of my Cargo Contracts MOD for Oolite v1.8 and later:

Oolite Cargo Contract Mod Script
https://controlc.com/6b7a3bfe

It is set to try to return 20 cargo contracts at every system, does not try to pick sensible commodities, and does not try to pick sensible or nearby destinations.
This is strictly for testing, with most of the important results in Oolite's Latest.log file.

It no longer gets NaN (Not a Number) errors or Division By Zero errors...but the prices generated using efactor for commodities is still obviously wrong.
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 2414
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty (currently plague-ridden)
Contact:

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Cholmondely »

Can I do anything to help?

GalCop Health Warning: In an entire year and a half of play I've taken one parcel contract (but failed to get there on time) and no cargo/passenger contracts. And three of Phkb's GalCop contracts (black boxes and stuff - and flubbed one of those too!), and the Start Advice.oxp mission!
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte

Oolite BB Topic icons guide
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

When testing cargo contracts, it's helpful to have both a ship capable of carrying a LOT of stuff and also being able to easily/quickly jump everywhere using cheats. LongRangeScanner OXP (found at https://app.boxcn.net/s/bpl582x1hu ) is just the sort of cheat to have to do this...but I use others as well.

But even if you play at all and don't do any cargo contracts, if you have that script loaded into Oolite...it will generate latest.log information for cargo contracts every time you jump to a new system. Has to do it even if you don't visit the main station because I found an exploit for that by reloading from savegame to get the contracts I wanted. :P

Still, the Latest.log won't be terribly useful...since I already know the estimates for commodities prices are wrong.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

Switeck wrote: Wed Dec 29, 2021 8:31 amHere is the testing form of my Cargo Contracts MOD for Oolite v1.80 and later:

Oolite Cargo Contract Mod Script
https://controlc.com/6b7a3bfe

It is set to try to return 20 cargo contracts at every system, does not try to pick sensible commodities, and does not try to pick sensible or nearby destinations.
This is strictly for testing, with most of the important results in Oolite's Latest.log file.

It no longer gets NaN (Not a Number) errors or Division By Zero errors...but the prices generated using efactor for commodities is still obviously wrong.
Now the updated Oolite Cargo Contract Mod Script for Oolite v1.80 or later...
https://controlc.com/5456e0c0

It should be a fully-working script...but still uses the slow looping method for comparing to the new method.
It tries to pick sensible commodities and tries to pick sensible destinations.

It is for testing but should be useful as a replacement for the original cargo contract script.
It still logs a lot of info to Oolit's Latest.log file...but understanding the output isn't a given.

The "PrDif=" value in the Latest.log file entries for it should show whether the new profit method you helped me build is more profitable than the original method used by the game.
Positive = mine is more profitable, Negative = original method was more profitable

What remains for me to do is remove the old profit-calculating methods, clean up the script of other now-irrelevant parts, and hopefully get it turned into an OXZ.

Anyone trying this?
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 2414
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty (currently plague-ridden)
Contact:

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Cholmondely »

I'm a dumb pilot rather than a programmer.

What should I be doing with the script?
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte

Oolite BB Topic icons guide
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

You have to save the contents of the script into:
oolite-contracts-cargo.js
...which on my computer is found inside:
C:\Oolite\oolite.app\Resources\Scripts

Make a copy/Back up the original before you do.
cag
Deadly
Deadly
Posts: 156
Joined: Fri Mar 17, 2017 1:49 am

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by cag »

Switeck wrote: Wed Nov 24, 2021 11:39 pm This mod is still broken, as my workaround causes multi-second-long game freezes on entering a system as it tries to calculate new cargo contracts using a loop that makes 100+ very slow Oolite library calls.
...
Switeck wrote: Sun Jan 02, 2022 6:54 pm ...
It should be a fully-working script...but still uses the slow looping method for comparing to the new method.
It tries to pick sensible commodities and tries to pick sensible destinations.
...
Once you're satisfied it does what you want it do, I could help you optimize the code to get rid of part of the long freezes. Many oxp's do heavy lifting when exiting witchspace; it's not just you. Try testing with most of your oxp's removed and it's not so bad. I profiled _initialiseCargoContractsForSystem and it took about 200 ms (1/5 sec).

By caching the static references, I was able to reduce execution time by about 20%. More savings could be realized by spreading out the workload. You don't need all the contracts the instant you exit witchspace. The work can be done in chunks spread over a few seconds w/ a Timer (or over frames using a frameCallback, which is probably overkill in this situation).
"Better to be thought a fool, boy, than to open your trap and remove all doubt." - Grandma [over time, just "Shut your trap... fool"]
"The only stupid questions are the ones you fail to ask." - Dad
How do I...? Nevermind.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2032
Joined: Mon May 31, 2010 11:11 pm

Re: Cargo Contracts MOD for Oolite v1.77 and v1.79!

Post by Switeck »

The slow looping part is where it uses random price checks to try to find the lowest and highest prices.
I'll be removing that part in final release, which should greatly reduce the slowdowns.
They're just still in the script for legacy checking reasons...to make sure the new method is always better/more profitable. :)
Post Reply