Editing Modding Tutorials/MayRequire
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:MayRequire}} | {{DISPLAYTITLE:MayRequire}} | ||
− | {{ | + | {{:Modding_Tutorials/Under_Review}} |
<code>MayRequire</code> is an [[Modding_Tutorials/Introduction_to_XML|XML attribute]] introduced alongside the [[Royalty DLC]] that allows for easy conditional loading of XML content. <code>MayRequire</code> makes it easier to load content that is optionally dependent on DLCs or other mods. | <code>MayRequire</code> is an [[Modding_Tutorials/Introduction_to_XML|XML attribute]] introduced alongside the [[Royalty DLC]] that allows for easy conditional loading of XML content. <code>MayRequire</code> makes it easier to load content that is optionally dependent on DLCs or other mods. | ||
Line 13: | Line 13: | ||
* Ideology: <code>Ludeon.RimWorld.Ideology</code> | * Ideology: <code>Ludeon.RimWorld.Ideology</code> | ||
* Biotech: <code>Ludeon.RimWorld.Biotech</code> | * Biotech: <code>Ludeon.RimWorld.Biotech</code> | ||
− | |||
The <code>packageId</code> for mods can be found in their [[About.xml]] file. | The <code>packageId</code> for mods can be found in their [[About.xml]] file. | ||
Line 20: | Line 19: | ||
By default, <code>MayRequire</code> will only allow the use of that node if ''all'' of the DLCs or mods it designates are loaded. If you instead want to load the specified node if ''any'' of the specified DLCs or mods are loaded, you can use <code>MayRequireAnyOf</code> instead. | By default, <code>MayRequire</code> will only allow the use of that node if ''all'' of the DLCs or mods it designates are loaded. If you instead want to load the specified node if ''any'' of the specified DLCs or mods are loaded, you can use <code>MayRequireAnyOf</code> instead. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== List Entries == | == List Entries == | ||
Line 71: | Line 62: | ||
Note that the use of <code>MayRequire</code> on the list nodes of the <code><applyToRecipes></code> is technically unnecessary as the entire outcome node would not have loaded without [[Biotech]] active. | Note that the use of <code>MayRequire</code> on the list nodes of the <code><applyToRecipes></code> is technically unnecessary as the entire outcome node would not have loaded without [[Biotech]] active. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| <source lang="xml"> | | <source lang="xml"> | ||
Line 147: | Line 109: | ||
</div> | </div> | ||
− | == | + | === Lists of Defs === |
− | <code>MayRequire</code> | + | Unlike other usages of <code>MayRequire</code>, lists of Defs have a special behavior: when used to filter lists of [[Modding_Tutorials/Defs|Defs]], <code>MayRequire</code> only serves to suppress cross-resolution errors if the targeted DLC or mod is not loaded. '''If RimWorld finds the targeted Def, it will be loaded into the list regardless of whether the specified DLC or mod is loaded or not.''' |
− | |||
− | |||
<div class="TutorialTableWrapper"> | <div class="TutorialTableWrapper"> | ||
{| class="TutorialCodeTable" | {| class="TutorialCodeTable" | ||
! XML Example !! Description | ! XML Example !! Description | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| <source lang="xml"> | | <source lang="xml"> | ||
Line 208: | Line 151: | ||
| class="TutorialCodeTable-description" | | | class="TutorialCodeTable-description" | | ||
<code>MayRequire</code> is used in the Human [[Modding_Tutorials/ThingDef|ThingDef]] to set surgery recipes that are only relevant to specific DLCs. Without <code>MayRequire</code>, these would cause errors as the specified [[Modding_Tutorials/Defs|Defs]] only exist in their respective DLCs. | <code>MayRequire</code> is used in the Human [[Modding_Tutorials/ThingDef|ThingDef]] to set surgery recipes that are only relevant to specific DLCs. Without <code>MayRequire</code>, these would cause errors as the specified [[Modding_Tutorials/Defs|Defs]] only exist in their respective DLCs. | ||
+ | |- | ||
+ | | <source lang="xml"> | ||
+ | <DesignationCategoryDef> | ||
+ | <defName>Zone</defName> | ||
+ | <label>zone</label> | ||
+ | <order>800</order> | ||
+ | <specialDesignatorClasses> | ||
+ | <li>Designator_Cancel</li> | ||
+ | <li>Designator_Deconstruct</li> | ||
+ | <li>Designator_ZoneAddStockpile_Resources</li> | ||
+ | <li>Designator_ZoneAddStockpile_Dumping</li> | ||
+ | <li>Designator_ZoneAdd_Growing</li> | ||
+ | <li>Designator_ZoneDelete</li> | ||
+ | <li>Designator_AreaHomeExpand</li> | ||
+ | <li>Designator_AreaHomeClear</li> | ||
+ | <li>Designator_AreaAllowedExpand</li> | ||
+ | <li>Designator_AreaAllowedClear</li> | ||
+ | <li>Designator_AreaBuildRoof</li> | ||
+ | <li>Designator_AreaNoRoof</li> | ||
+ | <li>Designator_AreaIgnoreRoof</li> | ||
+ | <li>Designator_AreaSnowClearExpand</li> | ||
+ | <li>Designator_AreaSnowClearClear</li> | ||
+ | <li MayRequire="Ludeon.RimWorld.Biotech">Designator_AreaPollutionClearExpand</li> | ||
+ | <li MayRequire="Ludeon.RimWorld.Biotech">Designator_AreaPollutionClearClear</li> | ||
+ | </specialDesignatorClasses> | ||
+ | </DesignationCategoryDef> | ||
+ | </source> | ||
+ | | class="TutorialCodeTable-description" | | ||
+ | <code>MayRequire</code> is used in the DesignationCategoryDef for the "Zone" architect menu to add designators for pollution clearing areas. | ||
+ | |- | ||
+ | |} | ||
+ | </div> | ||
+ | |||
+ | == Stat Blocks == | ||
+ | |||
+ | <code>MayRequire</code> can be used by any <code>StatModifier</code> list, which includes all <code>statBases</code>, <code>statOffsets</code>, <code>statFactors</code>, and <code>equippedStatOffsets</code> nodes: | ||
+ | |||
+ | <div class="TutorialTableWrapper"> | ||
+ | {| class="TutorialCodeTable" | ||
+ | ! XML !! Description | ||
+ | |- | ||
+ | | <source lang="xml"> | ||
+ | <ThingDef ParentName="ApparelMakeableBase"> | ||
+ | <defName>Apparel_Duster</defName> | ||
+ | |||
+ | <!-- irrelevant tags omitted --> | ||
+ | |||
+ | <equippedStatOffsets> | ||
+ | <SlaveSuppressionOffset MayRequire="Ludeon.RimWorld.Ideology">-0.05</SlaveSuppressionOffset> | ||
+ | </equippedStatOffsets> | ||
+ | |||
+ | <!-- irrelevant tags omitted --> | ||
+ | </ThingDef> | ||
+ | </source> | ||
+ | | class="TutorialCodeTable-description" | | ||
+ | <code>MayRequire</code> is used by several vanilla apparel [[Modding_Tutorial/ThingDef|ThingDef]]s to apply stats that are only relevant to DLCs, such as the [[Slavery|SlaveSuppressionOffset]] stat from [[Ideology]]. | ||
|- | |- | ||
| <source lang="xml"> | | <source lang="xml"> | ||
Line 229: | Line 228: | ||
</source> | </source> | ||
| class="TutorialCodeTable-description" | | | class="TutorialCodeTable-description" | | ||
− | <code>MayRequire</code> | + | <code>MayRequire</code> is used by several vanilla buildings such as the torch lamp to determine how much that particular building influences the overall style of the room it is in. This is also an [[Ideology]] feature. |
+ | |- | ||
+ | |} | ||
+ | </div> | ||
+ | |||
+ | == Optional Defs == | ||
+ | |||
+ | <code>MayRequire</code> can be used to conditionally load entire Defs. This is far easier to use than the prior option of using [[Modding_Tutorials/PatchOperations|PatchOperations]] to inject new Defs. | ||
+ | |||
+ | <div class="TutorialTableWrapper"> | ||
+ | {| class="TutorialCodeTable" | ||
+ | ! XML !! Description | ||
+ | |- | ||
+ | | <source lang="xml"> | ||
+ | <ThingDef MayRequire="Ludeon.RimWorld.Ideology" ParentName="Brazier"> | ||
+ | <defName>DarklightBrazier</defName> | ||
+ | <label>darklight brazier</label> | ||
+ | <description>A specially treated brazier that illuminates its surroundings with darklight and creates heat. These satisfy royal brazier requirements.</description> | ||
+ | |||
+ | <!-- irrelevant content omitted --> | ||
+ | |||
+ | </ThingDef> | ||
+ | </source> | ||
+ | | class="TutorialCodeTable-description" | | ||
+ | <code>MayRequire</code> is used to activate [[Royalty]]'s darklight brazier stat if [[Ideology]] is also loaded. | ||
|- | |- | ||
| <source lang="xml"> | | <source lang="xml"> | ||
− | < | + | <StatDef ParentName="MeditationFocusBase" MayRequireAnyOf="Ludeon.RimWorld.Royalty,Ludeon.RimWorld.Biotech"> |
− | <defName> | + | <defName>MeditationFocusGain</defName> |
+ | <label>meditation psyfocus gain</label> | ||
+ | |||
+ | <!-- irrelevant content omitted --> | ||
− | + | </StatDef> | |
+ | </source> | ||
+ | | class="TutorialCodeTable-description" | | ||
+ | <code>MayRequireAnyOf</code> is used to activate the MeditationFocusGain stat if either [[Royalty]] or [[Biotech]] is loaded. | ||
+ | |- | ||
+ | | <source lang="xml"> | ||
+ | <ThingDef ParentName="ApparelMakeableBase" MayRequireAnyOf="Ludeon.RimWorld.Royalty,Ludeon.RimWorld.Biotech"> | ||
+ | <defName>Apparel_Cape</defName> | ||
+ | <label>cape</label> | ||
− | < | + | <!-- irrelevant content omitted --> |
− | |||
− | |||
− | |||
</ThingDef> | </ThingDef> | ||
</source> | </source> | ||
| class="TutorialCodeTable-description" | | | class="TutorialCodeTable-description" | | ||
− | <code> | + | <code>MayRequireAnyOf</code> is used to activate the [[Cape]] apparel if either [[Royalty]] or [[Biotech]] is loaded. |
+ | |- | ||
+ | |} | ||
+ | </div> | ||
+ | |||
+ | == Miscellaneous == | ||
+ | |||
+ | The following are specific, non-standard usages of <code>MayRequire</code>. Some of these are technically lists with special parsing, some are fields that were coded specifically to accept the <code>MayRequire</code> attribute. | ||
+ | |||
+ | <div class="TutorialTableWrapper"> | ||
+ | {| class="TutorialCodeTable" | ||
+ | ! XML !! Description | ||
|- | |- | ||
| <source lang="xml"> | | <source lang="xml"> | ||
Line 335: | Line 377: | ||
| class="TutorialCodeTable-description" | | | class="TutorialCodeTable-description" | | ||
<code>MayRequire</code> must be used for xenotype references in <code>FactionDef</code> entries, as they only exist if [[Biotech]] is loaded. | <code>MayRequire</code> must be used for xenotype references in <code>FactionDef</code> entries, as they only exist if [[Biotech]] is loaded. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| <source lang="xml"> | | <source lang="xml"> | ||
Line 433: | Line 416: | ||
* <code>MayRequire</code> does '''NOT''' work on top-level XML nodes that are not <code>Def</code>s. This means that <code>Operation</code> tags cannot use <code>MayRequire</code>, though as previous indicated, <code>PatchOperationSequence</code> lists can. Again, this is not recommended because <code>PatchOperationSequence</code> can obfuscate errors. | * <code>MayRequire</code> does '''NOT''' work on top-level XML nodes that are not <code>Def</code>s. This means that <code>Operation</code> tags cannot use <code>MayRequire</code>, though as previous indicated, <code>PatchOperationSequence</code> lists can. Again, this is not recommended because <code>PatchOperationSequence</code> can obfuscate errors. | ||
− | * | + | * When used with lists of <code>Def</code>s, including stat blocks and other custom parsers, <code>MayRequire</code> only blocks errors caused by missing <code>Def</code>s. If the target <code>Def</code> exists outside of the mod(s) being targeted by <code>MayRequire</code>, then those entries will still be loaded. |
[[Category:Modding]] | [[Category:Modding]] | ||
[[Category:Modding tutorials]] | [[Category:Modding tutorials]] |