"generateCommonality" and "generateAllowChance"

Started by Nigeroid, December 28, 2017, 02:36:41 AM

Previous topic - Next topic

Nigeroid

What difference between these two parameters? I can't find any information about both of them.
If any actual B18 knowledge base exist in Internet?

CannibarRechter

Many people working on advanced RimWorld mods decompile the RimWorld code, and then treat that as their documentation.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Nigeroid

Quote from: CannibarRechter on December 28, 2017, 07:16:40 AM
Many people working on advanced RimWorld mods decompile the RimWorld code, and then treat that as their documentation.
But I didn't find anything. May be no one pay attention to these parameters? So question is still actual for me.

dburgdorf

Quote from: Nigeroid on December 28, 2017, 07:45:10 AMBut I didn't find anything....

As CR just explained, you're not likely *to* find anything, since most modders just use the code itself as their documentation.

That said, a quick look at the code suggests -- and this is based purely on a search for the parameters, with no attempt to look at any broader contexts -- that, as the names themselves suggest, "generateCommonality" influences how often a particular material will be used in a weapon, while "generateAllowChance" influences how often pawns will be *equipped* with a weapon made with a particular material. So I'd assume that lets you set up "common" weapon materials that nonetheless aren't often used by pawns, though I can't, off the top of my head, see why you'd want to do it. *Shrug*

Take that with a grain of salt, though. As I said, it's based on a two-minute search for the parameters, with no attempt to look for any broader context, and without the benefit of any caffeine to get my brain working yet this morning. :D
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?

Nigeroid

#4
Quote from: dburgdorf on December 28, 2017, 08:18:40 AM
As CR just explained, you're not likely *to* find anything, since most modders just use the code itself as their documentation.

That said, a quick look at the code suggests -- and this is based purely on a search for the parameters, with no attempt to look at any broader contexts -- that, as the names themselves suggest, "generateCommonality" influences how often a particular material will be used in a weapon, while "generateAllowChance" influences how often pawns will be *equipped* with a weapon made with a particular material. So I'd assume that lets you set up "common" weapon materials that nonetheless aren't often used by pawns, though I can't, off the top of my head, see why you'd want to do it. *Shrug*

Take that with a grain of salt, though. As I said, it's based on a two-minute search for the parameters, with no attempt to look for any broader context, and without the benefit of any caffeine to get my brain working yet this morning. :D

Arr.. It's difficult to understand English for me. Several years without practice in foreign language)
So, problem is that "generateCommonality" refers to whole weapon not to it's material.

Quote
  <ThingDef ParentName="BaseHumanMakeableGun">
    <defName>Gun_Revolver</defName>
    <label>revolver</label>
    <description>Ancient pattern double-action revolver. Somewhat weak, medium range, quick.</description>
    <graphicData>
      <texPath>Things/Item/Equipment/WeaponRanged/Revolver</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <soundInteract>InteractRevolver</soundInteract>
    <generateCommonality>0.1</generateCommonality>
    <statBases>
      <WorkToMake>15000</WorkToMake>
      <Mass>1.4</Mass>
      <AccuracyTouch>0.91</AccuracyTouch>
      <AccuracyShort>0.71</AccuracyShort>
      <AccuracyMedium>0.50</AccuracyMedium>
      <AccuracyLong>0.32</AccuracyLong>
      <RangedWeapon_Cooldown>1.38</RangedWeapon_Cooldown>
      <Weapon_Bulk>0.5</Weapon_Bulk>
    </statBases>
    <weaponTags>
      <li>SimpleGun</li>
    </weaponTags>
    <costList>
      <Steel>30</Steel>
      <Component>2</Component>
    </costList>
    <verbs>
      <li>
        <verbClass>Verb_Shoot</verbClass>
        <hasStandardCommand>true</hasStandardCommand>
        <defaultProjectile>Bullet_Revolver</defaultProjectile>
        <warmupTime>0.3</warmupTime>
        <range>26</range>
        <soundCast>ShotRevolver</soundCast>
        <soundCastTail>GunTail_Light</soundCastTail>
        <muzzleFlashScale>9</muzzleFlashScale>
      </li>
    </verbs>
    <tools>
      <li>
        <label>grip</label>
        <capacities>
          <li>Blunt</li>
        </capacities>
        <power>8</power>
        <cooldownTime>1.6</cooldownTime>
      </li>
      <li>
        <label>barrel</label>
        <capacities>
          <li>Blunt</li>
          <li>Poke</li>
        </capacities>
        <power>8</power>
        <cooldownTime>1.6</cooldownTime>
      </li>
    </tools>
  </ThingDef>

"generateAllowChance" also refers to whole thing - apparel.

Quote
  <ThingDef ParentName="ApparelBase">
    <thingClass>SmokepopBelt</thingClass>
    <defName>Apparel_SmokepopBelt</defName>
    <label>smokepop belt</label>
    <description>An automatic defensive smokescreen. It will release a thick cloud of smoke if the wearer is hit by a projectile, providing line-of-sight cover and preventing turrets from locking on. Single-use.</description>
    <techLevel>Industrial</techLevel>
    <recipeMaker>
      <unfinishedThingDef>UnfinishedBelt</unfinishedThingDef>
      <researchPrerequisite>SmokepopBelt</researchPrerequisite>
      <recipeUsers>
        <li>TableMachining</li>
      </recipeUsers>
      <workSpeedStat>SmithingSpeed</workSpeedStat>
      <workSkill>Crafting</workSkill>
      <effectWorking>Smith</effectWorking>
      <soundWorking>Recipe_Smith</soundWorking>
    </recipeMaker>
    <costList>
      <Chemfuel>75</Chemfuel>
      <Component>1</Component>
      <Steel>25</Steel>
    </costList>
    <graphicData>
      <texPath>Things/Pawn/Humanlike/Apparel/SmokepopBelt/SmokepopBelt</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <tickerType>Normal</tickerType>
    <statBases>
      <WorkToMake>3500</WorkToMake>
      <Mass>3</Mass>
      <SmokepopBeltRadius>4</SmokepopBeltRadius>
    </statBases>
    <thingCategories>
      <li>Apparel</li>
    </thingCategories>
    <generateAllowChance>0.15</generateAllowChance>
    <apparel>
      <careIfWornByCorpse>false</careIfWornByCorpse>
      <bodyPartGroups>
        <li>Waist</li>
      </bodyPartGroups>
      <layers>
        <li>Belt</li>
      </layers>
      <tags>
        <li>BeltDefensePop</li>
      </tags>
    </apparel>
    <colorGenerator Class="ColorGenerator_Options">
      <options>
        <li>
          <weight>10</weight>
          <only>RGBA(0.6,0.4,0.4,1)</only>
        </li>
        <li>
          <weight>10</weight>
          <only>RGBA(0.6,0.6,0.4,1)</only>
        </li>
        <li>
          <weight>6</weight>
          <min>RGBA(0.3,0.3,0.3,1)</min>
          <max>RGBA(0.5,0.5,0.5,1)</max>
        </li>
        <li>
          <weight>10</weight>
          <only>RGBA(0.33,0.33,0.33,1)</only>
        </li>
      </options>
    </colorGenerator>
  </ThingDef>

So there are several questions:
1. "generateCommonality" is for weapon, "generateAllowChance" - for apparel?
2. Do both these parameters define how common these things appear in the game (in markets, equipped by raiders and so on)?

jamaicancastle

Both of these operate on both apparel and weapons. The difference appears to be in how the random factor is applied.

GenerateCommonality uses a weighted pool system. All possible apparel/weapon items are pooled together and a random selection is made using their commonality. That means that if e.g. you have a lot of apparel items with a commonality of 1, and another one is added by a mod, it is given equal weight with the existing items in terms of creation.

Incidentally, a stuff - a building material that other items can inherit properties from - has a "commonality" stuffprop that works exactly the same way. When the code looks at weapons, say, it generates the commonality of a steel shortsword by multiplying the shortsword value and the steel value together.

GenerateAllowChance, on the other hand, is a per-pawn probability. (This means it depends on the pawn's ID number, so the result never changes no matter how many times it gets looked up.) As far as I can tell it applies only to things, never to stuff. It's a strict probability: if an item has an allow chance less than 1.0 (100%), it has that percent chance of being allowed to show up. It will still respect commonality; allow chance determines whether it is put into the common pool in the first place.

As far as I can tell the only base item to actually use generateAllowChance is the smokepop belt, which suggests a strong use case for it: an item that you want to only show up some of the time, but does not conflict with any other items (or very few other items). GenerateCommonality on the other hand is useful for managing commonality when there's a large pool of possible items.

So if you want a rare weapon, use commonality, because the commonalities of the other possible weapons will crowd it out. But if you want a rare item that isn't easily categorized, such as the smokepop belt, or where the category is small and lacks any "filler" items (that is, everything in the category is rare), allow chance is more appropriate.

Note that this applies to pawns being equipped directly with weapons and armor. As far as I can tell, neither generateCommonality nor generateAllowChance are used at all by trader inventories (although stuff commonality is). If you want to change the odds of showing up in inventories, you'll have to monkey around with stockGenerators, which is another matter entirely. :(

Nigeroid

Quote from: jamaicancastle on December 28, 2017, 02:29:33 PM
Both of these operate on both apparel and weapons. The difference appears to be in how the random factor is applied.

GenerateCommonality uses a weighted pool system. All possible apparel/weapon items are pooled together and a random selection is made using their commonality. That means that if e.g. you have a lot of apparel items with a commonality of 1, and another one is added by a mod, it is given equal weight with the existing items in terms of creation.

Incidentally, a stuff - a building material that other items can inherit properties from - has a "commonality" stuffprop that works exactly the same way. When the code looks at weapons, say, it generates the commonality of a steel shortsword by multiplying the shortsword value and the steel value together.

GenerateAllowChance, on the other hand, is a per-pawn probability. (This means it depends on the pawn's ID number, so the result never changes no matter how many times it gets looked up.) As far as I can tell it applies only to things, never to stuff. It's a strict probability: if an item has an allow chance less than 1.0 (100%), it has that percent chance of being allowed to show up. It will still respect commonality; allow chance determines whether it is put into the common pool in the first place.

As far as I can tell the only base item to actually use generateAllowChance is the smokepop belt, which suggests a strong use case for it: an item that you want to only show up some of the time, but does not conflict with any other items (or very few other items). GenerateCommonality on the other hand is useful for managing commonality when there's a large pool of possible items.

So if you want a rare weapon, use commonality, because the commonalities of the other possible weapons will crowd it out. But if you want a rare item that isn't easily categorized, such as the smokepop belt, or where the category is small and lacks any "filler" items (that is, everything in the category is rare), allow chance is more appropriate.

Note that this applies to pawns being equipped directly with weapons and armor. As far as I can tell, neither generateCommonality nor generateAllowChance are used at all by trader inventories (although stuff commonality is). If you want to change the odds of showing up in inventories, you'll have to monkey around with stockGenerators, which is another matter entirely. :(

Thank you for such detailed response! So, if I want to add or remove thise weapon or apparel to/from trader can i make it through TraderKindDefs and don't touch stockGenerators?

jamaicancastle

You don't need to do anything special to make them appear on traders. As long as they are basic weapons and apparel, the existing stock generators should pick them up automatically. If you don't want them to show up on traders, adjust their "tradeability" tag to "Sellable" (can be sold to traders, but not bought from them) or "Never" (never bought or sold). You would only need custom stock generators if you want to adjust the relative probability of your modded weapons/clothes showing up - otherwise they'll default to having the same probability as normal weapons/clothes.

Nigeroid

Quote from: jamaicancastle on December 28, 2017, 03:14:26 PM
You don't need to do anything special to make them appear on traders. As long as they are basic weapons and apparel, the existing stock generators should pick them up automatically. If you don't want them to show up on traders, adjust their "tradeability" tag to "Sellable" (can be sold to traders, but not bought from them) or "Never" (never bought or sold). You would only need custom stock generators if you want to adjust the relative probability of your modded weapons/clothes showing up - otherwise they'll default to having the same probability as normal weapons/clothes.
Thank you for answer) Again)