Cargo Count in Buy Screens mod

A place to discuss mods in development and concepts for new mods.
Post Reply
relanat
Militia Commander
Militia Commander
Posts: 454
Joined: Tue Nov 05, 2013 9:56 am

Mon Jan 15, 2018 2:44 am

Thanks to a great idea by tarbos in a Ministry ticket, https://ministry.kronosaur.com/record.hexm?id=57130.

This mod is an overwrite of the standard game screen 'dsRPGCommoditiesExchangeBuy'.

When in a 'buy' screen a line is added to the screen description which tells you how many of the selected item are currently in your cargo hold. Nice one, tarbos. Very handy.

Only works in 1.8a4a (API 39) ATM. Would probably work in previous versions but I didn't check. And there hasn't been much testing. I'll backdate any future upgrades as far as possible.


Any ideas on how to do this without an override would be appreciated.
Something like scrAddAction but changing the screen desc instead.
Possibly scrSetDesc in <OnGlobalPaneInit>. Not sure if that would work.
Otherwise changing the text ID="decsItemStats" with XML functions will work but something a bit simpler would be nice.
Attachments
CargoCountInBuyScreen.xml
(14.55 KiB) Downloaded 3 times
cargo count in buy screens.JPG
cargo count in buy screens.JPG (100.22 KiB) Viewed 118 times

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

Mon Jan 15, 2018 11:27 pm

That's really nice!
relanat wrote:
Mon Jan 15, 2018 2:44 am
Any ideas on how to do this without an override would be appreciated.
Something like scrAddAction but changing the screen desc instead.
Possibly scrSetDesc in <OnGlobalPaneInit>. Not sure if that would work.
Otherwise changing the text ID="decsItemStats" with XML functions will work but something a bit simpler would be nice.
Yes, using scrSetDesc in OnGlobalPaneInit works if you're OK with adding it to the end, rather than before the line about how many you can fit/afford (if present). I also made it only show if you have any, and extend unidRPGLibrary, so it works in Part 2. Using XML functions and/or inserting it in the middle would be possible, but certainly trickier.

Of course, the best solution is probably to add this to the base game (and maybe rewrite the screen to separate the code and text in the process).

Code: Select all

<!DOCTYPE TranscendenceExtension [
	<!ENTITY unidRPGLibrary				"0x00010000">
	
	<!ENTITY unidCargoCount		    	"0xE127B360">
	<!ENTITY evCargoCount		    	"0xE127B361">
]>

<TranscendenceExtension UNID="&unidCargoCount;"
	name=			"Cargo Count in Buy Screens (NMS)"
	extends=		"&unidRPGLibrary;"
	apiVersion=		"39"
	version=		"1.0"
	credits=		"Nathaniel Stalberg (NMS)"
>
	
	<Type UNID="&evCargoCount;">
		<Events>
			<OnGlobalPaneInit>
				(block (theCount desc)
					(if (and (eq aScreen "0x0001002C")
							(eq aPane 'Default)
							(setq theCount (objHasItem gPlayerShip (scrGetItem gScreen) 1))
							)
						(scrSetDesc gScreen (cat (setq desc (scrGetDesc gScreen))
												(if (neq (subset desc (- (count desc) 1)) "\n") "\n")
												"You have " theCount " in your cargo hold."
												)
							)
						)
					)
			</OnGlobalPaneInit>
		</Events>
	</Type>
	
</TranscendenceExtension>
Attachments
Cargo Count in Buy Screens (NMS).xml
(979 Bytes) Downloaded 3 times

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

Fri Jan 19, 2018 2:35 am

Easy when you know how! A nice neat useful mod.

And I now know what 'scrGetDesc' does and have a working example of 'subset' too. Thanks.

My preference is to have a set size of screen description for any dockscreen as it stops the actions moving up and down. This makes it easier to use the mouse. But a rewite would be the way to go. Wherever the extra text goes it doesn't really fit well. Merging the fit/afford lines would be best IMO. So "You have 4 in your cargo hold and can only fit 2 more." or similar. Rather than the two separate lines one after the other.

'objHasItem' had me stuck for a while (Whadda ya mean "List expected" :? ). Until the xelerus functionlist pointed out that it needs an itemStruct not an item. If you are doing any function help updating that might be worth adding in there.


And now, if I may, a few questions! (Bet you didn't see that coming :lol:)

In the 'subset' code you use.

Code: Select all

(subset desc (- (count desc) 1)) 
I think this is to correct for the 0-based numbering used by the game and 'subset' (I think). This is needed because count doesn't use the same 0-based system. It starts at '1'. Is that right? So this gives the last (in this case, text) character from the screen description.

In one example the screen description is 69 characters long. So this means the 'pos' of the code needs to be '68' because the first character is pos '0', not pos '1'. So pos '68' will give the 69th character.


Also how does extending unidRPGLibrary allow VOTG to use this?
I can see that RPGCommoditesExchange.xml (which contains &dsRPGCommoditiesExchangeBuy;) is a module of unidRPGLibrary in RPGLibrary.xml. So this mod needs to access unidRPGLibrary to get the dockscreen. But how does this allow VOTG to get to it.

I'm assuming it has something to do with unidRPGLibrary being a library in the unidExtension of VOTG in VaultOfTheGalaxy.xml.

But I seriously don't understand the reasoning or pathway that is used!
There is a topic somewhere detailing what the game does and in what order but I can't remember where it is.
I think the main block to my thinking is the difference between how SOTP can access anything and other adventures need access to be granted.


And because it was too hot to do anything else here's another version of the same mod using XML functions to change Text id="descItemStats". I manually looked up the position of the text id because with the space between 'Text' and 'id' it became too confusing on how to format the tag/name. Also the colons after "Unit price", etc, have been replaced with dashes. They were generating "Must be inside quotes" errors. Is there a way of using them without generating errors? Many thanks for the forum topic, "XML Modification Tutorial". It's a wee ripper!
Attachments
XML Change Cargo Count Text id.xml
(3.1 KiB) Downloaded 3 times

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

Fri Jan 19, 2018 4:01 am

relanat wrote:
Fri Jan 19, 2018 2:35 am
My preference is to have a set size of screen description for any dockscreen as it stops the actions moving up and down. This makes it easier to use the mouse. But a rewite would be the way to go. Wherever the extra text goes it doesn't really fit well. Merging the fit/afford lines would be best IMO. So "You have 4 in your cargo hold and can only fit 2 more." or similar. Rather than the two separate lines one after the other.
Well, the fit/afford line already only appears if you can't buy all of them, so I don't think that helps much.
relanat wrote:
Fri Jan 19, 2018 2:35 am
'objHasItem' had me stuck for a while (Whadda ya mean "List expected" :? ). Until the xelerus functionlist pointed out that it needs an itemStruct not an item. If you are doing any function help updating that might be worth adding in there.
Yeah, there are definitely still some functions that could use better documentation. In TLisp functions, an item is a list consisting of the UNID of the item type and data about the quantity and status of the item. Some functions accept just a UNID, but not this one, I guess.

relanat wrote:
Fri Jan 19, 2018 2:35 am
In the 'subset' code you use.

Code: Select all

(subset desc (- (count desc) 1)) 
I think this is to correct for the 0-based numbering used by the game and 'subset' (I think). This is needed because count doesn't use the same 0-based system. It starts at '1'. Is that right? So this gives the last (in this case, text) character from the screen description.

In one example the screen description is 69 characters long. So this means the 'pos' of the code needs to be '68' because the first character is pos '0', not pos '1'. So pos '68' will give the 69th character.
Right. Note that "\n" counts as one character (a newline), so this line is adding a newline if the existing description doesn't already end with one.

relanat wrote:
Fri Jan 19, 2018 2:35 am
Also how does extending unidRPGLibrary allow VOTG to use this?
I can see that RPGCommoditesExchange.xml (which contains &dsRPGCommoditiesExchangeBuy;) is a module of unidRPGLibrary in RPGLibrary.xml. So this mod needs to access unidRPGLibrary to get the dockscreen. But how does this allow VOTG to get to it.

I'm assuming it has something to do with unidRPGLibrary being a library in the unidExtension of VOTG in VaultOfTheGalaxy.xml.

But I seriously don't understand the reasoning or pathway that is used!
There is a topic somewhere detailing what the game does and in what order but I can't remember where it is.
I think the main block to my thinking is the difference between how SOTP can access anything and other adventures need access to be granted.
See http://ministry.kronosaur.com/record.hexm?id=62046. I think George's thinking is that most mods either won't do much in Part 2, or will introduce a Part 1 library, causing tons of Part 1 stuff to appear in any game that uses them.

relanat wrote:
Fri Jan 19, 2018 2:35 am
And because it was too hot to do anything else here's another version of the same mod using XML functions to change Text id="descItemStats". I manually looked up the position of the text id because with the space between 'Text' and 'id' it became too confusing on how to format the tag/name. Also the colons after "Unit price", etc, have been replaced with dashes. They were generating "Must be inside quotes" errors. Is there a way of using them without generating errors? Many thanks for the forum topic, "XML Modification Tutorial". It's a wee ripper!
Maybe the parser thinks the quotes end at the \" so the text between it and the next " is not in quotes? You could probably substitute an ascii character entity, in this case &#58;. But if you're not planning to modify what you're inserting, I think it's generally easier to write it as you would normally and put it inside an XML element in your own type. Then get what you want from the XML of your own type, and put it in the XML of the type you want to modify.

Post Reply