X4: Foundations
0 of 0

File information

Last updated

Original upload

Created by

Ramokthan

Uploaded by

Ramokthan

Virus scan

Safe to use

Tags for this mod

About this mod

Provides an interface for a custom sort use cases

Permissions and credits
Changelogs
The plugin will provide a possibility for mod scripts to utilize the imo most efficient (in terms of speed and memory usage) sorting algorithm existing.

It will not change any parameter or things ingame.
This mod is solely ment for developer to work with.



Please be aware following decriptions is for developer which intend to use this mod:

Mod developer can use the sorter by calling the 'quicksort' script.
It will sort the given objects list by its given values ascending

Example of use:
<run_script name="'quicksort'">
<param name="objects" value="$UnsortedObjects"/>
<param name="values" value="$UnsortedValues"/>
<save_retval name="sortedobject" variable="$SortedObjects" /> 
<save_retval name="sortedvalue" variable="$SortedValues" /> 
</run_script>


While $UnsortedObjects contain the Object which are not sorted $UnsortedValues contain the values after which are to be sorted.

$UnsortedObjects can contain any value, no matter which type.
$UnsortedValues has to contain a float or integer type value.

$UnsortedObjects and $UnsortedValues have to contain the same amount of entries.

$SortedObjects and $SortedValues contain the sorted values of the respective input after script has finished.


How does it work:

Lets give another example:
Lets assume $UnsortedObjects has following data [wareY,wareZ,wareX]
and $UnsortedValues has following data [2,3,1]

Each element of both lists on the same index are refering to each other, which means for the sort algorithm the first value of
$UnsortedObjects (wareY) has the value of the first element of $UnsortedValues (2) and so on.

This gets important when we know it all of them will be sorted ascending by their values.

Result in this case after running the sort script would be:
$SortedObjects [wareX,wareY,wareZ]
$SortedValues [1,2,3]

Elements are now sorted while $SortedValues contain their values ascending, and their respective objects in their partner list changed their order respectively.

This will work for lists of ANY size.

Example usecase:


You want to sort a bunch of stations for their cargo size (for example).

This is how:

First iterate your station list to set the value list to sort after:

<create_list name="$UnsortedStationValues" />
<do_all exact="$UnsortedStations.count" counter="$b">
<append_to_list name="$UnsortedStationValues" exact="$UnsortedStations.{$b}.cargo.capacity.all"/>
</do_all>

        
Now we got all the values in the same order (important) then our $UnsortedStations in a seperate list.
The first element of $UnsortedStations will have its respective value in the first element of $UnsortedStationValues, the second element has its respective value in the second element of $UnsortedStationValues and so on.
Now we run the sort script:

 <run_script name="'quicksort'">
<param name="objects" value="$UnsortedStations"/>
<param name="values" value="$UnsortedStationValues"/>
<save_retval name="sortedobject" variable="$SortedStations" /> 
<save_retval name="sortedvalue" variable="$SortedStationValues" /> 
 </run_script>


After that $SortedStationValues will contain the values sorted ascending and $SortedStations elements will have changed the same way.
If you iterate the resulting list now again and printing the StationObjects cargo.capacity you will find them sorted ascending.