Sandbox Development

Freeform discussion about anything related to modding Transcendence.
shanejfilomena
Fleet Officer
Fleet Officer
Posts: 1533
Joined: Tue Mar 22, 2011 8:43 pm
Location: Alaska
Contact:

i totally was not alive: ignore my earlier self
Last edited by shanejfilomena on Sat Aug 27, 2011 1:27 am, edited 1 time in total.
Flying Irresponsibly In Eridani......

I don't like to kill pirates in cold blood ..I do it.. but I don't like it..
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

RPC wrote:I wanted to know how to add a check to see if a player has a mining license when selling ore.
You would need to overwrite the sell screen.
Get your own Galactic Omni Device
Get it now. It's free!!
Image
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Ok, new,related, question:
What does this mean? O.O

Code: Select all

(comShowSellScreen
									"*"						; items bought from player
									)
and

Code: Select all

(setq comShowSellScreen (lambda (itemsToBuy returnScreen screenOptions)
				(block Nil
					; Generate the function that computes price and availability
					(switch
						(isfunction itemsToBuy)
							(setq gMargin itemsToBuy)
							
						; If itemsToBuy is set, then combine with station's Trade descriptors
						(and itemsToBuy (not (eq itemsToBuy "*")))
							(setq gMargin 
								(lambda (theItem)
									(switch
										(not (itmMatches theItem itemsToBuy))
											Nil
											
										(intComputeBuyPrice theItem)
										)
									)
								)
							
						; Otherwise, rely on station's Trade descriptors
						(setq gMargin intComputeBuyPrice)
						)

					; Handle some options (Nil is OK)
					(setq gTitle (item screenOptions 0))
					(setq gMaxPrice (item screenOptions 1))
					
					; Result
					(setq gResult 0)

					; Show the screen
					(scrShowScreen gScreen "&dsExchangeSell;")
					)
				))
Alterecco: you mean the dsExchangeSell?
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

So... the sell/buy screens are a little complicated. I will try to explain.

In your first code block, you see a call to comShowSellScreen, passing a single argument `*`.

The second code block is the function itself. You might notice that the function has three arguments, but it is the first that is most interesting (the second one is deprecated). Most of the comShowSellScreen function deals with handling the itemsToBuy argument. The two screens dsExchangeSell and dsExchangeBuy are generic, and rely on some global variables to function. These variables are what this function sets. The most important of these variables is gMargin.

gMargin is used to determine if the screen will display the item for trade and at what price. It can be a function or a criteria.

gMargin as function: gMargin can be a function that takes an item as an argument, and returns Nil if the item can not be bought at the station, or the price of the item if it can be bought. An example of this (one that would support your ore-license thingy) would be:

Code: Select all

(comShowSellScreen (lambda (theItem)
    (switch

        (and (itmMatches theItem "* +Ore") (not ([test for mining license])))
            Nil

        (intComputeBuyPrice theItem)
    )
))
That call to comShowSellScreen passes a function along as the itemsToBuy argument. The function will be called once for every possible item the station can buy. If the item is ore, and the player does not have a license, then the function returns Nil, and the item will not be shown in the list. If the item passes that test, then it's price will be computed by a standard function that is also in Transcendence.xml (intComputeBuyPrice). It would of course be possible to add multiple checks to that function.

gMargin as criteria: The simplest way to use gMargin is to just pass in a item criteria (as in your first code block). If the criteria passed in is `*`, then the stations Trade descriptors (the stuff in the <Trade> tag) take charge. If the station has no Trade descriptors, then everything is for sale valued at 100%. If the criteria is not `*`, but something more complex, then comShowSellScreen sets gMargin to a function and leaves the handing to that function (as described above). That function checks if the item matches the criteria, and returns nil if not. Else it returns the buy price as computed by intComputeBuyPrice.

screenOptions is a list that can be passed in as well. The first element of that list will be used as the title of the Buy screen (gTitle), the second argument will be used as gMaxPrice, which determines the maximum price the station will pay for any item. Both values are optional, and the entire argument can be left out.

Finally, the comShowSellScreen function ends with displaying the actual screen.

comShowSellScreen has a twin, comShowBuyScreen. It works in a similar fashion.


I hope that was clear enough. Just ask and I will try to clear up any unclear points.
Get your own Galactic Omni Device
Get it now. It's free!!
Image
Post Reply