Some questions about math

The place to discuss scripting and game modifications for X4: Foundations.

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

User avatar
ubuntufreakdragon
Posts: 5226
Joined: Thu, 23. Jun 11, 14:57
x4

Some questions about math

Post by ubuntufreakdragon »

I could use the squareroot function in a non distance usecase for calculating priorities (it moves values close to one but lower together)
btw. what is the value range of relprice, I guess -1 to 1, am I correct?
The idea:

Code: Select all

<set_value name="$offer.sortvalue" exact="offer.relprice+0.25*sqrt($offer.price/$storedmaxprice)" />
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Re: Some questions about math

Post by w.evans »

looks like -2 to 2. normal range -1 to 1, but extends to -2, +2 taking discounts and commissions into account.
User avatar
ubuntufreakdragon
Posts: 5226
Joined: Thu, 23. Jun 11, 14:57
x4

Re: Some questions about math

Post by ubuntufreakdragon »

is there a diffence between buy an selloffers?
so for both -1 means minprice +1 max price of the ware?
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Re: Some questions about math

Post by w.evans »

ubuntufreakdragon wrote: Fri, 28. Dec 18, 19:13 is there a diffence between buy an selloffers?
so for both -1 means minprice +1 max price of the ware?
Doesn't look like there's a difference. And, yup, -1 minprice, +1 maxprice, 0 average, < -1 below min, > +1 above max.

0 being average is important, i think. Would mean that if there were a ware defined so that the average price is not the mean between min and max, the points at which relprice shifts down vs up wouldn't be symmetrical.
User avatar
ubuntufreakdragon
Posts: 5226
Joined: Thu, 23. Jun 11, 14:57
x4

Re: Some questions about math

Post by ubuntufreakdragon »

Are construction offers genereatet by the CV or the station?
If I want to get explicitly construction resource offers by <match_buyer> how would I do it.
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
User avatar
ubuntufreakdragon
Posts: 5226
Joined: Thu, 23. Jun 11, 14:57
x4

Re: Some questions about math

Post by ubuntufreakdragon »

do I need to use the xml replace system if I change the hole file?
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
Tyrant597
Posts: 299
Joined: Wed, 9. Apr 08, 05:52
x4

Re: Some questions about math

Post by Tyrant597 »

ubuntufreakdragon wrote: Fri, 28. Dec 18, 19:43 Are construction offers genereatet by the CV or the station?
If I want to get explicitly construction resource offers by <match_buyer> how would I do it.
I'm not at home right now, but I think
<match_class class.buildstorage
You don't talks about X:Rebirth...
X4 Mods: Collect Inventory Wares Stations Supply Build Storage Mass Move Marines
User avatar
ubuntufreakdragon
Posts: 5226
Joined: Thu, 23. Jun 11, 14:57
x4

Re: Some questions about math

Post by ubuntufreakdragon »

how to write a diff which replaces the hole file? (for testing) (I know how to write normal diffs but this one allways gives me node not found if I try to use replace

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<aiscript name="trade.find.commander" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="aiscripts.xsd">
  <params>
  ....
</aiscript>
This now works:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<diff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > 
  <replace sel="//aiscript">
<aiscript name="trade.find.commander" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="aiscripts.xsd">
  <params>
  ....
</aiscript>
  </replace>
</diff>
edit found it, I forgott about the //for the root :roll:
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
Vim Razz
Posts: 1842
Joined: Tue, 2. Nov 10, 02:20
x4

Re: Some questions about math

Post by Vim Razz »

w.evans wrote: Fri, 28. Dec 18, 19:26
ubuntufreakdragon wrote: Fri, 28. Dec 18, 19:13 is there a diffence between buy an selloffers?
so for both -1 means minprice +1 max price of the ware?
Doesn't look like there's a difference. And, yup, -1 minprice, +1 maxprice, 0 average, < -1 below min, > +1 above max.

0 being average is important, i think. Would mean that if there were a ware defined so that the average price is not the mean between min and max, the points at which relprice shifts down vs up wouldn't be symmetrical.
Can confirm. I've been chasing down problems with trade.find.free for the last two weeks (spoiler: 3 logic issues, and some structural stuff), so this is still pretty fresh to me.

It's also worth noting that discounts are not factored into $offer.relativeprice or $offer.unitprice. I haven't checked to see if or when they get applied later, but I would assume that if they do that it's at the time of purchase/sales?

As a side note: the relativeprice range is something that's changed in X4 compared to Rebirth (where it's 0 to 2, with 1 being average).
Tyrant597 wrote: Fri, 28. Dec 18, 20:16
ubuntufreakdragon wrote: Fri, 28. Dec 18, 19:43 Are construction offers genereatet by the CV or the station?
If I want to get explicitly construction resource offers by <match_buyer> how would I do it.
I'm not at home right now, but I think
<match_class class.buildstorage
Is match_class a valid search expression? I'm not familiar with that one.

$offer.buyer.isclass.buildstorage is the Boolean. No Idea how that fits into a match expression, though.

@ubuntufreakdragon : also, buy offers are issued by the build storage unit itself, not the station or the CV.
Tyrant597
Posts: 299
Joined: Wed, 9. Apr 08, 05:52
x4

Re: Some questions about math

Post by Tyrant597 »

Vim Razz wrote: Fri, 28. Dec 18, 22:43
Is match_class a valid search expression? I'm not familiar with that one.

$offer.buyer.isclass.buildstorage is the Boolean. No Idea how that fits into a match expression, though.

@ubuntufreakdragon : also, buy offers are issued by the build storage unit itself, not the station or the CV.
My bad <match class="class.buildstorage"/>
You don't talks about X:Rebirth...
X4 Mods: Collect Inventory Wares Stations Supply Build Storage Mass Move Marines
User avatar
ubuntufreakdragon
Posts: 5226
Joined: Thu, 23. Jun 11, 14:57
x4

Re: Some questions about math

Post by ubuntufreakdragon »

Than I'm lucky my usecase excludes discounts and the range itself I only needed to know how much the values could differ.
btw. I'm working on trade.find.comander can I see your trade.find.free?
here is mine (wip version) https://www.dropbox.com/s/hg2cf15p8760m ... er.7z?dl=1
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
Vim Razz
Posts: 1842
Joined: Tue, 2. Nov 10, 02:20
x4

Re: Some questions about math

Post by Vim Razz »

ubuntufreakdragon wrote: Sat, 29. Dec 18, 02:14 btw. I'm working on trade.find.comander can I see your trade.find.free?
here is mine (wip version) https://www.dropbox.com/s/hg2cf15p8760m ... er.7z?dl=1
Sure, later tonight or tomorrow after I've had a chance to clean it up a little. A the moment it's still a bit... messy... with a lot of outdated comments and stuff.

EDIT: I do very much appreciate that you removed that obnoxious relative price filter from line 145 (v1.5 release). I've seen more confused complaints here and on reddit resulting from the effects that has than any other single line of code than I can think of. Aside from that, I'd been meaning to look at trade.find.commander after trade.find.free, but I haven't got there yet, so I don't know much about it.
User avatar
ubuntufreakdragon
Posts: 5226
Joined: Thu, 23. Jun 11, 14:57
x4

Re: Some questions about math

Post by ubuntufreakdragon »

any idea about the squareroot?
My X3 Mods

XRebirth, things left to patch:
In General; On Firing NPC's; In De Vries; Out Of Zone; And the Antiwishlist
Vim Razz
Posts: 1842
Joined: Tue, 2. Nov 10, 02:20
x4

Re: Some questions about math

Post by Vim Razz »

sqrt() is listed as a standard math operator in the MD Script guide, so I don't know of any reason why it might not work there.

Have you been having problems with it? tbh, I'm not really sure what your question is

Also, I'll be sending a link for my current trade.find.free experiment in a pm. It's still very "WIP - Testing Only", so I'm not interested in someone randomly downloading it and complaining about all the debuglog spam (which there is still a lot of right now... :shock: ). Or worse, trying to use it in their normal game -- it's not ready for that sort of thing yet.
User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13489
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Some questions about math

Post by euclid »

Vim Razz is right, the sqrt is part of the math section in the MD Guide and for me to works just fine. However, I'm not entirely sure on what you want to do with it. For numbers the result is unique

Code: Select all

sqrt test:  sqrt(2) = 1.41421 sqrt(1254/397) = 1.73205
but for values that have a dimension (like time, credits, length) the result depends of the input format

Code: Select all

sqrt test:  sqrt($AmountS/$AmountB) = 0  sqrt(($AmountS)f/($AmountB)f) = 0.310851
Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786
ApoxNM
Posts: 783
Joined: Wed, 5. Dec 18, 06:17
x4

Re: Some questions about math

Post by ApoxNM »

Vim Razz wrote: Sat, 29. Dec 18, 03:54
ubuntufreakdragon wrote: Sat, 29. Dec 18, 02:14 btw. I'm working on trade.find.comander can I see your trade.find.free?
here is mine (wip version) https://www.dropbox.com/s/hg2cf15p8760m ... er.7z?dl=1
Sure, later tonight or tomorrow after I've had a chance to clean it up a little. A the moment it's still a bit... messy... with a lot of outdated comments and stuff.

EDIT: I do very much appreciate that you removed that obnoxious relative price filter from line 145 (v1.5 release). I've seen more confused complaints here and on reddit resulting from the effects that has than any other single line of code than I can think of. Aside from that, I'd been meaning to look at trade.find.commander after trade.find.free, but I haven't got there yet, so I don't know much about it.
Hi there, I have been following this post, have you made any progressions on your script?

Return to “X4: Foundations - Scripts and Modding”