Fuel question…

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
AssumedPseudonym
Fleet Officer
Fleet Officer
Posts: 1190
Joined: Thu Aug 29, 2013 5:18 am
Location: On the other side of the screen.

 I’m trying to access how much fuel is available in a fuel item. I can see in the XML that there’s a field called “data” in the <ItemType> tag, but is there a way to get hold of that value via tLISP?
Image

Mod prefixes: 0xA010 (registered) and 0xDCC8 (miscellaneous)

My mods on Xelerus: Click here!

Of all the things I’ve lost in life, I miss my mind the least. (I’m having a lot more fun without it!)
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

The pteravore overlay appears to use (itmGetTypeData theItem).
User avatar
AssumedPseudonym
Fleet Officer
Fleet Officer
Posts: 1190
Joined: Thu Aug 29, 2013 5:18 am
Location: On the other side of the screen.

 That is exactly what I was looking for, thanks. I never would have thought to have checked there. And there even appears to be a corresponding itmSetTypeData function. Score! ^.^

EDIT: So… how do I use itmSetTypeData to set that value? Trying to use it in the same manner as itmGetTypeData in the above example returns an “identifier expected” error, and (itmSetTypeData theItem 'data value) doesn’t access the same value.
Image

Mod prefixes: 0xA010 (registered) and 0xDCC8 (miscellaneous)

My mods on Xelerus: Click here!

Of all the things I’ve lost in life, I miss my mind the least. (I’m having a lot more fun without it!)
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

Here's the most relevant part of the C code that handles those functions:

Code: Select all

		case FN_ITEM_GET_TYPE_DATA:
			{
			//	Because of backwards compatibility, if we only have one argument
			//	then we assume that we want type data.

			if (pArgs->GetCount() == 1)
				pResult = pCC->Link(pType->GetData(), 0, NULL);

			//	Otherwise, we get global data from the design type

			else
				{
				CString sData = pType->GetGlobalData(pArgs->GetElement(1)->GetStringValue());
				pResult = pCC->Link(sData, 0, NULL);
				}

			break;
			}

		case FN_ITEM_SET_GLOBAL_DATA:
			{
			CString sAttrib = pArgs->GetElement(1)->GetStringValue();
			if (sAttrib.IsBlank())
				{
				pResult = pCC->CreateNil();
				break;
				}

			CString sData = CreateDataFromItem(*pCC, pArgs->GetElement(2));
			pType->SetGlobalData(sAttrib, sData);
			pResult = pCC->CreateTrue();
			break;
			}
And some other relevant things:

Code: Select all

 		inline const CString &GetData (void) const { return m_sData; }

Code: Select all

ALERROR CItemType::OnCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc)

//	OnCreateFromXML
//
//	Load data from XML
...
	m_sData = pDesc->GetAttribute(DATA_ATTRIB);
So, I'd say you can't change the value of the built-in data field that's loaded from the XML.

But you can set your own data with (itmSetTypeData item 'variable value) and retrieve it with (itmGetTypeData item 'variable)
Last edited by NMS on Sun Jan 03, 2016 10:40 am, edited 1 time in total.
User avatar
AssumedPseudonym
Fleet Officer
Fleet Officer
Posts: 1190
Joined: Thu Aug 29, 2013 5:18 am
Location: On the other side of the screen.

 Yeah, I already gathered as much, and even ticketed it on the Ministry. My major issue is that using the attribute argument in itmSetTypeData would wind up with me having to basically rewrite the entirety of the refueling code for the idea I had in mind — which, while doable, is something I’d really rather avoid. I’d prefer not to have to reinvent the wheel, as it were.
 …I was sort of expecting a block of C from you, heh. Thanks for doing the digging on that; there’s no way I could have made heads or tails of it, myself.
Image

Mod prefixes: 0xA010 (registered) and 0xDCC8 (miscellaneous)

My mods on Xelerus: Click here!

Of all the things I’ve lost in life, I miss my mind the least. (I’m having a lot more fun without it!)
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

I was editing my post to be slightly more informative as you were posting yours.

You're welcome. I've found it interesting to search through the code. Downloading the source with the Git desktop client and using Notepad++'s find in files feature makes it reasonably practical to answer questions like this with a few searches. It's pretty amazing that one person could create a massive project like this involving three different languages (plus whatever's involved in compiling it).

Now that I think about it, it seems like it would be possible to change the code that loads the type from the XML so that it stores the data field using the same funtion as (itmSetTypeData). Then it would be changeable like any other data that's been added.
Post Reply