modding:xml:templatetype
Overview
A TemplateType is a DesignType that can be used to generate randomized, dynamic types. Unlike static types (which are defined in the same way in every single game), dynamic types can vary dramatically by game. For instance, the following template creates a weapon that shoots either positron, plasma or antimatter.
<TemplateType UNID="&itArchCannon;"> <StaticData> <Template><![CDATA[ <ItemType name= "Arch's Cannon" level= "12" value= "700000" mass= "12000" frequency= "notRandom" attributes= "MajorItem; Military; NotForSale" description= "Many variations of the legendary Archenemy Blaster have existed over the years, but this is the only iteration that has not yet been lost to time." > <Weapon type= "particles" damage= "%damagetype%:350-500; WMD:4" fireRate= "30" hitPoints= "10" powerUse= "4800" sound= "&snRecoillessCannon;" > <ParticleSystem style= "comet" emitLifetime= "1" emitRate= "100" emitSpeed= "35-45" emitWidth= "50" spreadAngle= "3" particleLifetime= "60" particleEffect= "&efPlasmaParticleDefault;" > </ParticleSystem> <Effect> <ParticleSystem style= "jet" fixedPos= "true" emitRate= "2-4" tangentSpeed= "-8-8" particleLifetime= "10" XformTime= "30" > <ParticleEffect> <Orb instance= "owner" style= "smooth" animate= "fade" radius= "20" lifetime= "10" intensity= "20" blendMode= "screen" primaryColor= "#feff00" secondaryColor= "#ff7f00" /> </ParticleEffect> </ParticleSystem> </Effect> </Weapon> </ItemType> ]]></Template> </StaticData> <Events> <GetTypeSource><![CDATA[ (subst (typGetStaticData &itRandomWeapon; "Template") { damagetype: (random (list "positron" "plasma" "antimatter")) } ) ]]></GetTypeSource> </Events> </TemplateType>
TemplateType randomization can go further than that. For instance, the following code generates a laser weapon with three possible variations.
<TemplateType UNID="&itLaserRepeater;"> <StaticData> <Template><![CDATA[ <ItemType name= "laser repeater" attributes= "commonwealth, energyWeapon, majorItem" level= "1" frequency= "common" value= "380" mass= "1000" description= "The Moromisato Company often makes repeating versions of existing weapon designs. This weapon is based on the %name%." > %weapon% </ItemType> ]]></Template> </StaticData> <Events> <GetTypeSource><![CDATA[ (block ( (weaponBase (random (list "Bolide laster blaster" "dual laser cannon" "fast-fire laser cannon"))) ) (subst (typGetStaticData &itRandomWeapon; "Template") { name: weaponBase weapon: (@ (struct "Bolide laser blaster" " <Weapon type= 'beam' damage= 'laser:1d6' fireRate= '10' lifetime= '30' powerUse= '20' repeating= '3' effect= '&efLaserBeamDefault;' sound= '&snLaserCannon;' > </Weapon> " "dual laser cannon" " <Weapon type= 'beam' configuration= 'dual' damage= 'laser:1d4' fireRate= '10' lifetime= '30' powerUse= '30' repeating= '2' effect= '&efLaserBeamDefault;' sound= '&snLaserCannon;' > </Weapon> " "fast-fire laser cannon" " <Weapon type= 'beam' damage= 'laser:1d4' fireRate= '6' lifetime= '30' powerUse= '30' repeating= '4' effect= '&efLaserBeamDefault;' sound= '&snLaserCannon;' > </Weapon> " ) weaponBase ) } ) ]]></GetTypeSource> </Events> </TemplateType>
The CDATA block escapes the angle brackets and the elements use apostrophes rather than quotation marks to avoid string problems. The event <GetTypeSource> returns the entire XML that will be used to define the resulting type.
References
modding/xml/templatetype.txt · Last modified: 2017/01/21 19:00 by 0xabcdef