detecting system map use query

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

Thu Oct 11, 2018 3:30 am

Is there a way of detecting when a system map ROM has been used or is being used in a system?
It would be good if the Commander' s Log mod could show the player if a map ROM, either civilian or military, has been used in a system. This would save the player either guessing or making a note somewhere so they didn't use two in the same system.

The only possibility I can see is using <OnInvokedByPlayer>. But it looks like that event has to be inside another type.
Or overriding the map ROM types, but It would be better if there was another way.
Something that recognizes the attribute 'systemMap'?
Or checks if one of the four Text ids used by map ROMs has been displayed?
Is there an event which runs whenever the player 'u'ses an item? TIA.

NMS
Militia Commander
Militia Commander
Posts: 475
Joined: Tue Mar 05, 2013 8:26 am

Thu Oct 11, 2018 6:30 am

I don't think there's currently a way to do this without modifying the code of the items. There's no event like OnGlobalPlayerUsedItem, although it could be useful. And OnInvokedByPlayer only works for powers. Technically, a mod could use XML functions to add code to their Invoke events without changing what's there, by enclosing it in a new block, so it would be compatible with other mods.

But maybe there's enough interest in this information that we should just add it to core. I'd have to do some research to figure out how to add information to the galactic map panel for a system. But it would be easy to add something like (sysSetData 'mapROMUsed true) to the map ROM code (and something similar for military) so that mods could access this information.

Link to your related Ministry ticket

relanat
Militia Captain
Militia Captain
Posts: 608
Joined: Tue Nov 05, 2013 9:56 am

Fri Oct 19, 2018 1:34 am

Excellent. I've added code to the map ROMs using xml functions and it works great. Map ROM usage shows in the screen description. I wasn't sure what you meant at first about new blocks but when I saw the Invoke code it clicked.

For others the map ROMs uses an XML element called <Invoke>. This contains a single block of tLisp which runs the map ROM code.
By adding "(block Nil" at the beginning of this code and "(sysSetData (sysGetNode) 'mapROMUsed True))" (note the extra bracket) at the end, the existing code remains unchanged but the new code is also added and runs at the same time. This only works in this case because the added code is independent of any of the existing code.

Great stuff, NMS. This greatly reduces any chance of interfering with other modifications to the ROMs.
Also using sysData is clever. It remains set throughout the game and can be accessed in other systems.
I also used your suggestion (from somewhere, not sure which topic) about placing text in XML blocks and adding it from them rather than trying to format it as text. Thanks. Much easier.

Code: Select all

<Events>
	<OnGlobalTypesInit>
			;We add code to the map ROM types at game creation to allow us to check if
			;	a map ROM has been used in a system so the player knows not to use a
			;	second ROM in that system.
		(block Nil
			(block (
					;System map ROM XML.
				(sysMapXML (typGetXML &itSystemMapROM;))
					;Invoke XML of map ROM XML.
				(invokeXML (xmlGetSubElement sysMapXML 'Invoke))
					;XML of the first lot of text to be added (see below).
					;Note that this and the other XML blocks are outside of the Events
					;	block. This makes them easier to access.
					;Used in both system map and military map ROMs.
				(firstTextXML (xmlGetSubElement (typGetXML &evD789CommLogOverwrites;) 'FirstText))
					;Text of that first XML element.
				(firstText (xmlGetText firstTextXML 0))
					;XML of the second lot of map ROM text to be added (see below).
				(mapTextXML (xmlGetSubElement (typGetXML &evD789CommLogOverwrites;) 'MapText))
					;Text of that second XML element.
				(mapText (xmlGetText mapTextXML 0))
					;The text (code) that is already in the map ROM Invoke XML.
				(existingText (xmlGetText invokeXML 0))
					;We set the text as the first text to be added followed by the existing text.
				(firstReplaceText (cat firstText existingText))
					;We then add the second lot of text to be added to the end of that.
				(secondReplaceText (cat firstReplaceText mapText))
				)
					;We insert the new text into the Invoke XML of the map ROM.
				(xmlSetText invokeXML secondReplaceText)
					;And set the new map ROM XML for use in the game.
				(typCreate &itSystemMapROM; sysMapXML)
			)
			(block (
					;Military map ROM XML.
				(milMapXML (typGetXML &itMilitaryMapROM;))
					;Invoke XML of military ROM XML.
				(invokeXML (xmlGetSubElement milMapXML 'Invoke))
					;XML of the first lot of text to be added (see below).
					;	Used in both system map and military map ROMs.
				(firstTextXML (xmlGetSubElement (typGetXML &evD789CommLogOverwrites;) 'FirstText))
					;Text of that first XML element.
				(firstText (xmlGetText firstTextXML 0))
					;XML of the second lot of mil ROM text to be added (see below).
				(milTextXML (xmlGetSubElement (typGetXML &evD789CommLogOverwrites;) 'MilText))
					;Text of that second XML element.
				(milText (xmlGetText milTextXML 0))
					;The text (code) that is already in the mil ROM Invoke XML.
				(existingText (xmlGetText invokeXML 0))
					;We set the text as the first text to be added followed by the existing text.
				(firstReplaceText (cat firstText existingText))
					;We then add the second lot of text to be added to the end of that.
				(secondReplaceText (cat firstReplaceText milText))
				)
					;We insert the new text into the Invoke XML of the mil ROM.
				(xmlSetText invokeXML secondReplaceText)
					;And set the new mil ROM XML for use in the game.
				(typCreate &itMilitaryMapROM; milMapXML)
			)
		)
	</OnGlobalTypesInit>
</Events>

<FirstText>
	(block Nil
</FirstText>

<MapText>
	(sysSetData (sysGetNode) 'mapROMUsed True))
</MapText>

<MilText>
	(sysSetData (sysGetNode) 'milROMUsed True))
</MilText>
I don't really know if there is any interest in this. It's just something that was inconvenient back when I spent more time playing than modding. I used to have a text document for every game which listed info that was useful but not available to the player. Like whether I had used a map ROM in a system. It's frustrating when you're not sure, use one just in case and have nothing new appear. D'oh.
I've also added Trading Post order status to the mod so the player can tell if that particular Trading Post's order has been used. Again, easier to tell than having to dock at every station to check.

The good part is that a lot more information is now available to the player. So much that I look forward to the Captain's/Commander's Log mods becoming obsolete in the near future.

Post Reply