SortedNumberOf

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderator: Committer

Post Reply
Message
Author
dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

SortedNumberOf

#1 Post by dbenage-cx » Wed Nov 23, 2016 8:09 am

Will likely take me a few days to thoroughly test, so I wanted to check if this was a correct use:

Code: Select all

MaximumNumberOf Number = 1 SortKey = Source.Planet.Happiness Condition = And [
    Planet
    InSystem id = Source.SystemID
    OwnedBy empire = Source.Owner
    Contains
        Building name = "BLD_SHIPYARD_ORBITAL_DRYDOCK"
]
The intent here is to get the owned planet in the system with the highest happiness (and has a drydock).
I'm not sure on this, since SortKey is only passing a double.
I assume the "property_name" is gathered from the scripting context (I don't see any reference to property other than in comments)
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12268
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: SortedNumberOf

#2 Post by Geoff the Medio » Wed Nov 23, 2016 4:07 pm

dbenage-cx wrote:

Code: Select all

SortKey = Source.Planet.Happiness
This doesn't make sense. The source object will always be the same, so the sort key will always evaluate to the same result for every object being tested, so nothing will be sorted. You want / need to sort by objects that mach the sampling condition. What you probably want to do is refer to LocalCandiate.Happiness, since the sampling condition matches planets, the objects whose sort keys are calculated will be planets, and when evalulating the sort key on objects that have be matched by the sampling condition, each object can be referred to as the local candidate while the sort key is being evaluated on it.

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: SortedNumberOf

#3 Post by dbenage-cx » Fri Nov 25, 2016 3:46 am

Thank you Geoff, in that context it makes more sense ;)

Post Reply