How to override types on using TypCreate

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
User avatar
RPC
Fleet Admiral
Fleet Admiral
Posts: 2834
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

How to override types on using TypCreate

Post by RPC » Thu May 19, 2016 5:39 am

It came to my attention that George was not very clear in this thread about TypCreate and overriding preexisting XML.

Here's George's multiverse post on TypCreate.

Here's a step-by-step manual on how to override XML objects in Transcendence.

Rules:
1. You can only override objects once, in OnGlobalTypesInit. OnGlobalTypesInit is run at the very beginning of the game. If you want to override an object after this time, well the next best option is cloning that item and using TypCreate to create a modified clone while getting rid of the original.

2. Since our new xml* functions rely on finding the UNID of particular objects, we need to be careful on how we find the UNID. Currently the two ways I know of having the UNID of a particular item accessible at OnGlobalTypesInit is

*Knowing the UNID beforehand, manually inputting the hex number in code.
*Using TypFind.

Plan:
1. We stick OnGlobalTypesInit in the <Events> of whatever item or spaceobject that's in our mod.
2. We then look for the unid using TypFind and magical boolean or logic switches.
In addition to the TypFind syntax, we have a couple tricks in our sleeves.

Code: Select all

(typFind criteria) -> list of UNIDs

criteria

a AdventureDesc
b ItemTable
c EffectType
d DockScreen
e SpaceEnvironmenType
f OverlayType
h ShipTable
i ItemType
m Image
n MissionType
p Power
q SystemTable
s ShipClass
t StationType
u Sound
v Sovereign
y SystemType
z SystemMap
$ EconomyType
+/-{attrib} Require/exclude types with given attribute
For example in the Settings.xml of Civilian Crafts, we can use tricks like

Code: Select all

(typFind (cat "* +unid:" &scDanu; ))


to find a particular unid without knowing the hex number.

We can also use the knowledge of certain properties to narrow our search.
In this thread, we can enumerate through all the items in the game, then use an if switch to sort out all the items we want, namely weapons

Code: Select all

(eq (itmGetProperty (itmcreate theUNID 1) 'category) "weapon")
that are not launchers

Code: Select all

(not (typGetProperty theUNID 'launcher))
and are not energyweapons

Code: Select all

(not (itmHasAttribute (itmCreate theUNID 1) "energyWeapon"))

I have tested that itmEnumTypes and (itmGetTypes "*") do not work in OnGlobalTypesInit in the same thread, so we're left with TypFind as our only option.

3. Now we can use all of our xml* functions to manipulate and create the new xml we want. I can't go over details because everything is a case by case basis but if there are any pressing questions feel free to ask them in this thread.

General tips:
I myself like to build things from the ground up. One useful function for doing that is (xmlAppendSubElement xml xmlToAdd [index]).
The general game plan is this:
*Create a generic template, such as <Ship or <Station
*Then create all the details, such as <Player or <Dockscreens
*Then using xmlAppendSubElement, I can (xmlAppendSubElement genericTemplateXml detailXmlToAdd [index of where I want that detail to be])
If you're having trouble, always know that you can do (PrintTo 'log XML) and check what your XML looks like in the debuglog at various stages in your code.

4. Once you're done creating the right XML, all you have to do is (TypCreate unidoftheitemyouwanttoreplace xmloftheitemyouwantittobe).
Then that's it.

*edit: added link to George's post on multiverse.
Tutorial List on the Wiki and Installing Mods
Image<----- click to get to #Transcendence IRC on Freenode
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.

gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Re: How to override types on using TypCreate

Post by gunship256 » Fri May 20, 2016 1:04 am

Thanks for posting this, RPC. You've figured out a solution to a problem that's stumped the rest of us for quite a while.

Someone really needs to sticky this thread.

User avatar
RPC
Fleet Admiral
Fleet Admiral
Posts: 2834
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Re: How to override types on using TypCreate

Post by RPC » Fri May 20, 2016 1:25 am

No problem gunship256. I think I was working with TypCreate back when there was no xml* functions so all I had to rely on were stupid CDATA blocks of <weapon and <playership and cat to stitch everything together :P

I really do think though that what we have now doesn't currently modify ingame xml since we can only override xml in OnGlobalTypesInit.

Also stickied thread since TypCreate is tricky and due to request.
Tutorial List on the Wiki and Installing Mods
Image<----- click to get to #Transcendence IRC on Freenode
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.

gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Re: How to override types on using TypCreate

Post by gunship256 » Fri May 20, 2016 12:49 pm

RPC wrote:I really do think though that what we have now doesn't currently modify ingame xml since we can only override xml in OnGlobalTypesInit.
Yes. There's an additional problem: typGetXML doesn't pull up any XML for typCreated items. It just returns Nil. So even typCreating a new type based on an older one and replacing all of the old items with new ones doesn't always work because that method will break for types created ingame.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests