sorting node IDs edgeward to coreward query

Freeform discussion about anything related to modding Transcendence.
Post Reply
relanat
Militia Commander
Militia Commander
Posts: 383
Joined: Tue Nov 05, 2013 9:56 am

sorting node IDs edgeward to coreward query

Post by relanat » Tue Mar 14, 2017 1:22 am

I've got a couple of mods which would benefit from a list of systems running from Edgeward to Coreward.

The node IDs are generated by unvFindObject which doesn't run them in order. In SOTP it starts at C1 and tacks SE onto the end.

So I'm looking to sort an unvFindObject list by sysGetTopologyDistance (and work out how to use sort in general inside other code).

The furthest system from "G2" will be first on the list, followed by the second most distant, etc etc. (or the other way from SE, both should work).

I can get the topology distances and generate a list of them. But if I sort that list I lose the node IDs from unvFindObject which are needed in the mod code.

Code: Select all

(map (unvFindObject "t +unid:0xD7892102;") unvEntry (sysGetTopologyDistance (@ unvEntry 2) "G2"))
gives (18 13 12 11 8 7 6 2 1 23) which equates to ("C4" "C6" CD "C7" "C9" "A1" EC "A7" "G1" SE).

I've tried any number of ways of putting 'sort' in there, either inside the 'exp' part of map or around the whole lot but all I've managed to do is swap the order of the list from "C4" to SE to SE to "C4".

Can 'sort' be used in there somehow? Or is it a case of checking the list and extracting the highest (or lowest) topology distance, adding that to a list, removing it from the original list and running throught the reduced list again and again until all values are sorted?

I've used a hack job to get around this in the short term by stripping any SE entries and appending the remaining list back onto the SE entry but this doesn't work in VOTG or custom topologies.

TIA for any suggestions.
Last edited by relanat on Tue Mar 14, 2017 11:18 pm, edited 1 time in total.

User avatar
0xABCDEF
Commonwealth Pilot
Commonwealth Pilot
Posts: 75
Joined: Thu May 19, 2016 12:58 am
Location: Was destroyed by a Phobos-class dreadnought in the Eridani system

Re: sorting node IDs edgeward to coreward query

Post by 0xABCDEF » Tue Mar 14, 2017 2:20 am

I have a helper function called sortByLambda. It takes in a list, a lambda, and either 'ascending or 'descending. It sorts each element by what the lambda returns with the element as its argument

Code: Select all

;theOrder is a required argument
(setq sortByLambda (lambda (theList theLambda theOrder)
	;Remove the lambda result from each entry and return the list
	(map
		;Sort by lambda result
		(sort
			;Append each entry with the result of its lambda
			(map
				theList
				theEntry
				(list
					theEntry
					(theLambda theEntry)
					)
				)
			theOrder
			1
			)
		theEntry
		(@ theEntry 0)
		)
	))
You could use this code:

Code: Select all

(sortByLambda (unvFindObject "t +unid:0xD7892102;") (lambda (entry) (sysGetTopologyDistance (@ entry 2) "G2")) 'descending)

Code: Select all

<OnFireWeapon>
	(gamEnd Nil "encountered an unexpected error")
</OnFireWeapon>
-Command Screen Library: RTS in a dockscreen
-Extended Justice: A safer Commonwealth for all
-Playership Bones: Revisit your old ship wrecks!
-Please help out our official Documentarist (me) by editing the wiki

relanat
Militia Commander
Militia Commander
Posts: 383
Joined: Tue Nov 05, 2013 9:56 am

Re: sorting node IDs edgeward to coreward query

Post by relanat » Tue Mar 14, 2017 2:32 am

That sounds ideal. Thank you VM.

relanat
Militia Commander
Militia Commander
Posts: 383
Joined: Tue Nov 05, 2013 9:56 am

Re: sorting node IDs edgeward to coreward query

Post by relanat » Tue Jul 18, 2017 11:10 am

I've used sortByLambda twice now. The second time to sort armor repair items by level. It is invaluable. Just wanted to say thanks again. :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest