customPicker list counting query

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

Still working on the Find Ship/Find Station code for the GodPlayerShip. Many thanks to those that have already helped.
The current code returns a sorted cut-down unvFindObject list as appears in the image below. This format gets a bit cumbersome if there are many ships of the selected type in the galaxy. Some of the Ares Sentries can number up to 100 which makes the list too long.
Here's the list code. gData 'decType is a decimal ship UNID set in a previous screen.

Code: Select all

(block (shipsInGalaxy nameList)
	(setq shipsInGalaxy (filter (unvFindObject "s") unvEntry (eq (@ unvEntry 1) (@ gData 'decType))))
	(setq sortedShipsInGalaxy (sortByLambda shipsInGalaxy (lambda (entry) (sysGetTopologyDistance (@ entry 2) "G2")) 'descending))
	(setq nameList (map sortedShipsInGalaxy filteredUnvEntry (sysGetName (@ filteredUnvEntry 2))))
)
What I would like to do is have a list like the second part of the image with the system name followed by the number of ships or stations in that system. Then the list could only ever contain (in SOTP) about 2 dozen entries. A much more manageable number although the list may need to be split for larger topologies. Note: the desired list format is a list of text entries, they're not generated by code.

I'm not sure how to count the number of list entries for each system though. I can see a couple of ways to do this, either split the list according to system name and then count list entries to give the number of stations, or count the list until the system name changes and then use that value as the station number. Unfortunately I have no idea how to do any of this with code.
I also need to be able to create a list of system names that only has one entry for each system name. So somehow exclude repeating entries in the list.

Anyone got any ideas on how to do this? TIA.
Attachments
unvList use.jpg
unvList use.jpg (49.75 KiB) Viewed 2210 times
Stupid code. Do what I want, not what I typed in!
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

Code: Select all

(enum (unvFindObject (cat "t +unid:" theUnid ";")) theEntry
	(set@ result (@ theEntry 2) (lnkAppend (@ result (@ theEntry 2)) theEntry))
	)
Assuming result is Nil to start, this should set it to a struct where each key is a node and the corresponding value is a list of the entries returned by unvFindObject that are stations with UNID theUnid located in that node.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

I hadn't thought of using a struct and couldn't have worked out the code either.

(@ result) gives the list of non-repeating nodes needed to create the list and (count (@ result node) ) gives the number of stations.

Wth this and some code ideas from The Final Strike I've managed to get rid of all the global variables in the object section of the God playership. Many thanks to both of you.
Stupid code. Do what I want, not what I typed in!
Post Reply