Load specific defs when specific mods loaded.

Started by BrokenValkyrie, January 25, 2018, 02:52:26 AM

Previous topic - Next topic

BrokenValkyrie

Currently I have a hacky solution where I create skeletal Defs, that gets replaced with xpath when certain mods are detected.

At the moment I have projectile that are dependent on Range Animal Framework base definition. I can't refer to those definition without causing error and I am unable to patch in new a whole new ThingDef.

Is there a better way to do this? How can I load specific def when certain mods are detected?

This is my current solution

Skeletal Def

<Defs>
<!--This is a hacky way of handling mod dependency. These are empty, patch replace will fill these in.-->
<ThingDef>
<defName>ARA_DragonFireBreathAlpha</defName>
<label>None</label>
<thingClass>Projectile_Explosive</thingClass>
  </ThingDef>
 
   <ThingDef>
<defName>ARA_DragonFireBreathBeta</defName>
<label>None</label>
<thingClass>Projectile_Explosive</thingClass>
  </ThingDef>

   <ThingDef>
<defName>ARA_DragonFireBreathOmega</defName>
<label>None</label>
<thingClass>Projectile_Explosive</thingClass>
  </ThingDef>

  <ThingDef >
<defName>ARA_DragonCryo</defName>
<label>None</label>
<thingClass>Projectile_Explosive</thingClass>
  </ThingDef>
</Defs>


Patch operation

<Patch>
<!--Patch in projectile def if Framework detected.-->
<Operation Class="PatchOperationSequence">
<success>Always</success>
<operations>
<li Class="ModCheck.isModLoaded">
<modName>Combat Extended</modName>
<yourMod>Dragon Mod</yourMod>
<success>Invert</success>
</li>
<li Class="ModCheck.isModLoaded">
<modName>Range Animal Framework</modName>
<yourMod>Dragon Mod</yourMod>
<customMessageSuccess>Range Animal Framework: Adding Range attack to Dragon Mod.</customMessageSuccess>
</li>
<li Class="ModCheck.FindFile">
<modName>Dragon Mod</modName>
<file>Projectile_Dragon.xml</file>
</li>
<li Class="PatchOperationReplace">
<xpath>Defs/ThingDef[defName = "ARA_DragonFireBreathAlpha"]</xpath>
<value>
<ThingDef ParentName="ARA_FireProjectile">
<defName>ARA_DragonFireBreathAlpha</defName>
<graphicData>
<shaderType>TransparentPostLight</shaderType>
<texPath>Things/Special/Fire/FireA</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<projectile>
<flyOverhead>false</flyOverhead>
<speed>16</speed>
<damageDef>Flame</damageDef>
<damageAmountBase>3</damageAmountBase>
<explosionRadius>0.5</explosionRadius>
<explosionChanceToStartFire>0.1</explosionChanceToStartFire>
<soundExplode>FlameThrower</soundExplode>
</projectile>
</ThingDef>
</value>
</li>
<li Class="PatchOperationReplace">
<xpath>Defs/ThingDef[defName = "ARA_DragonFireBreathBeta"]</xpath>
<value>
<ThingDef ParentName="ARA_FireProjectile">
<defName>ARA_DragonFireBreathBeta</defName>
<graphicData>
<shaderType>TransparentPostLight</shaderType>
<texPath>Things/Special/Fire/FireA</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<projectile>
<flyOverhead>false</flyOverhead>
<speed>18</speed>
<damageDef>Flame</damageDef>
<damageAmountBase>4</damageAmountBase>
<explosionRadius>0.6</explosionRadius>
<explosionChanceToStartFire>0.125</explosionChanceToStartFire>
<soundExplode>FlameThrower</soundExplode>
</projectile>
</ThingDef>
</value>
</li>
<li Class="PatchOperationReplace">
<xpath>Defs/ThingDef[defName = "ARA_DragonFireBreathOmega"]</xpath>
<value>
<!--Most dangerous of firebreath for only the most dangerous of creature-->
<ThingDef ParentName="ARA_FireProjectile">
<defName>ARA_DragonFireBreathOmega</defName>
<graphicData>
<shaderType>TransparentPostLight</shaderType>
<texPath>Things/Special/Fire/FireA</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<projectile>
<flyOverhead>false</flyOverhead>
<speed>20</speed>
<damageDef>Flame</damageDef>
<damageAmountBase>5</damageAmountBase>
<explosionRadius>0.7</explosionRadius>
<explosionChanceToStartFire>0.15</explosionChanceToStartFire>
<soundExplode>FlameThrower</soundExplode>
</projectile>
</ThingDef>
</value>
</li>
<li Class="PatchOperationReplace">
<xpath>Defs/ThingDef[defName = "ARA_DragonCryo"]</xpath>
<value>
<!--We can have some fun with projectile, fireball, cryo flame-->
<ThingDef ParentName="ARA_ExplodeProjectile">
<defName>ARA_DragonCryo</defName>
<label>cryo_flame</label>
<graphicData>
<shaderType>TransparentPostLight</shaderType>
<texPath>AnimalProjectile/CryoFireModel</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<projectile>
<flyOverhead>false</flyOverhead>
<speed>18</speed>
<damageDef>Frostbite</damageDef>
<damageAmountBase>4</damageAmountBase>
<explosionRadius>0.6</explosionRadius>
<soundExplode>FlameThrower</soundExplode>
</projectile>
</ThingDef>
</value>
</li>
</operations>
</Operation>
</Patch>

sulusdacor

rimfire has an option in modsettings to disable guns. maybe it is using a better solution?

BrokenValkyrie

Rimfire didn't address my problem, it disable guns by modifying PawnWeaponGenerator. Which still leaves the problem of loading appropriate defs.

Thanks for suggesting anyway.