Searching multiple structs suggestions pelase.

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

The Commander's Log mod saves info on stations and systems so they can be accessed out of system. eg items in stations can be searched so you can find where to buy a specific item even if you are 10 systems away.
The mod currently uses a struct which uses the station objectID as a key with the items and their price added as values. Additional stations just get added on and the whole lot gets searched to look for items.

Code: Select all

	(setq logSetItem (lambda (value)
		(typSetData &evD789CommandersLog; 'itemsStruct value)
	))

	(logSetItem
		(set@ (logGetItem)
			(convertTo 'string (objGetID theObject))
			(map (objGetItems theObject '*U) theItem
				(itmSetData theItem 'price (objGetSellPrice theObject theItem))
			)
		)
	)

Unfortunately this gets so large it breaks the game.

I had an idea of using a separate struct for each station using the objectID as the struct name which would give many smaller structs.
Something like:

Code: Select all

(set@ (typeSetData &unidForItems; (objectID convereted to string) 'itemList)
Or maybe have a struct for all of the stations in each system. This would give bigger structs but not so large as to kil the game.
So use the nodeID as the key with the stations and items as values.

But I'm not sure how you could search these. I think a list of either objectIDs would be needed for the first idea or a list of nodeIDs for the second.
Then enum through the each struct somehow to search for an item.

Anyone know if this is possible?
Or got any other simpler ideas?
TIA.
Stupid code. Do what I want, not what I typed in!
User avatar
Aury
Fleet Admiral
Fleet Admiral
Posts: 5465
Joined: Tue Feb 05, 2008 1:10 am
Location: At the VSS Shipyards in the frontier, designing new ships.

How big is the struct when it kills the game?
(shpOrder gPlayership 'barrelRoll)

<New tutorials, modding resources, and official extension stuff coming to this space soon!>
relanat
Militia Captain
Militia Captain
Posts: 954
Joined: Tue Nov 05, 2013 9:56 am

Aury wrote:
Thu Dec 12, 2024 8:12 pm
How big is the struct when it kills the game?
I'm not real computer savvy and have no idea how to measure it but the Windows error messages suggested about 2 gig but I think this included all the memory used by playing, not just the struct. Another member said this is a 32bit restriction that only allows a certain amount of memory to be used regardless of how much is available (I think).

The code I ended up using used the station ID as the key for the struct:

Code: Select all

							
	(block (
		(objectID (objGetID theObject))
		(itemStationIDsList (typGetData &evD789CommandersLog; 'itemStationIDs))
		)
			(if (not (find itemStationIDsList objectID))
				(lnkAppend itemStationIDsList objectID)
			)
			(typSetData &evD789CommandersLog; 'itemStationIDs itemStationIDsList)
			(typSetData &evD789CommandersLog; (convertTo 'string objectID)
				{
				ID:objectID
				items:(map (objGetItems theObject '*U) theItem
					(itmSetData theItem 'price (objGetSellPrice theObject theItem))
				)
												
				}
			)
	)
So a different struct is created for every station. We also create a list of all the stations for which we have saved the itemlist.
We then 'enum' through the many structs looking for the selected item.

Code: Select all

	(enum (typGetData &evD789CommandersLog; 'itemStationIDs) theEntry
		(block 
			(setq theStructEntry (typGetData &evD789CommandersLog; (convertTo 'string theEntry)))
			(enum (@ theStructEntry 'items) theItem
				(if (eq (itmGetType theItem) (itmGetType (@ gData 'searchItem)))
					(lnkAppend idList (@ theStructEntry 'id))
				)
			)
		)
	)

Stupid code. Do what I want, not what I typed in!
User avatar
Aury
Fleet Admiral
Fleet Admiral
Posts: 5465
Joined: Tue Feb 05, 2008 1:10 am
Location: At the VSS Shipyards in the frontier, designing new ships.

Is there a specific requirement for storing the IDs as strings? Keeping it as an int should at least reduce the size used by a bit

You can get away with storing the prices of an ItemType per StationType, rather than each individual item per stationObj.
Also I'm not sure off-hand if objGetItems stacks identical items or not, but if it isnt, then if theres say, 3000 rounds of smartcannon ammo on a station, it looks like you are storing the price for each round of ammo on the round of ammo itself, and then storing a reference to that instance of ammo in your map.
(shpOrder gPlayership 'barrelRoll)

<New tutorials, modding resources, and official extension stuff coming to this space soon!>
relanat
Militia Captain
Militia Captain
Posts: 954
Joined: Tue Nov 05, 2013 9:56 am

Aury wrote:
Mon Dec 23, 2024 12:53 am
Is there a specific requirement for storing the IDs as strings? Keeping it as an int should at least reduce the size used by a bit
Not sure. The key to a struct has to be a string. Otherwise I'm clueless.
Keep in mind that I don''t know what I'm doing when I write code. Everything I have done is an adaptation of existing game code or suggestions from other modders. I don't have the knowledge to do much except bash away at code, little by little, until it works regardless of how revolting it appears to professionals!
Aury wrote:
Mon Dec 23, 2024 12:53 am
You can get away with storing the prices of an ItemType per StationType, rather than each individual item per stationObj.
I have no idea what that means! :D
Aury wrote:
Mon Dec 23, 2024 12:53 am
Also I'm not sure off-hand if objGetItems stacks identical items or not, but if it isnt, then if theres say, 3000 rounds of smartcannon ammo on a station, it looks like you are storing the price for each round of ammo on the round of ammo itself, and then storing a reference to that instance of ammo in your map.
Thanks for the tip. I checked and an arms dealer had 26 different items for sale and the struct had 26 items listed so it looks like they stack.

There is a similar feature which lists all shipbroker ships for sale. Although nowhere near as large, it is laggy after you visit enough shipbrokers. I was thinking of doing the same type of code for it but if there is a better way I'm all ears.

Code: Select all

									
	(block (
			;Create a list of station IDs which sell ships.
			;The list must be a variable to append to it.
		(brokerStationIDsList (typGetData &evD789CommLogShipUNID; 'brokerStationIDs))
		)
		(if (not (find brokerStationIDsList (objGetID theObject)))
			(lnkAppend brokerStationIDsList (objGetID theObject))
		)
		(typSetData &evD789CommLogShipUNID; 'brokerStationIDs brokerStationIDsList)
			;Map the shipList IDs.
		(typSetData &evD789CommLogShipUNID; (convertTo 'string (objGetID theObject))
			(map ships theID
				(block (
					(theShip (objGetObjByID theID))
					(theShipType (objGetType theShip))
					)
					{
					title: (objGetName theShip '(generic titleCapitalize))
					icon: (shpGetImageDesc theShipType { rotation:90 })
					largeIcon: (shpGetImageDesc theShipType { type:'schematic })
					details: (rpgGetShipDetails theShip { })
						;Add these for use in the screen description.
					price: (objGetShipSellPrice theObject theShip)
					currency: (obj@ theObject 'currency)
					shipDesc: (obj@ theShip 'playerDesc)
					shipType: theShipType
					stationName: (objGetName gSource)
					nodeID: (sysGetNode)
					}
				)
			)
		)
			;Create another struct to search for ships.
			;Use ship name as the key and values with IDs, etc.
		(enum ships theID
			(block (
				(theShip (objGetObjByID theID))
				)
				(logSetShips
				(set@ (logGetShips)
					(convertTo 'string theID)
						{
						shipName: (objGetName theShip)
						id: theID
						price: (objGetShipSellPrice theObject theShip)
						currency: (objGetProperty theObject 'currency)
						nodeID: (sysGetNode)
						brokerName: (objGetName theObject)
						}
					)
				)
			)
		)
	)
From your comments I'm thinking a lot of these details can be taken from the ShipType when the search is done instead of storing them all.
Stupid code. Do what I want, not what I typed in!
Post Reply