erdelf / AlienRaces

Rimworld mod alien race framework
MIT License
103 stars 69 forks source link

Pawn generation ignores fixedGender tag value in PawnKindDef #61

Closed sumghai closed 2 years ago

sumghai commented 2 years ago

Issue Description

When spawning pawns with the HAR framework, their PawnKindDef's fixedGender tag is ignored.

This means that if, for example, a custom human or alien pawnkind is set to be female-only via <fixedGender>Female</fixedGender>, both males and females are still spawned at the default gender ratio for that race.

Expected Behaviour

HAR should account for the PawnKindDef's fixedGender value, and ensure than human/alien pawns strict gender requirements are spawned correctly.

Steps to Reproduce

  1. Baseline behaviour a. Start a new savegame with only Core active b. Using the dev mode debug actions menu > Spawn Pawn button, spawn 20 Grenadier_Destructive pawns onto the map c. Observe that there is a mix of both male and female grenadier pawns

  2. Modified Core files a. Open RimWorld\Data\Core\Defs\PawnKindDefs_Humanlikes\PawnKinds_Mercenary.xml in a text editor b. Add <fixedGender>Female</fixedGender> to the definition for Grenadier_Destructive c. Save all changes d. Start a new savegame with only (the modified) Core active e. Using the dev mode debug actions menu > Spawn Pawn button, spawn 20 Grenadier_Destructive pawns onto the map f. Observe that all grenadiers are female, as expected and desired

  3. Modified Core files + HAR a. Start a new savegame with the modified Core (from section 2) and HAR b. Using the dev mode debug actions menu > Spawn Pawn button, spawn 20 Grenadier_Destructive pawns onto the map c. Observe that there is a mix of both male and female grenadier pawns, despite fixedGender being set to Female

Additional Information

Verse.PawnGenerator.TryGenerateNewPawnInternal() is where request.KindDef.fixedGender.Value is used, so this might be a good place to start investigating.

System and Game Configuration

Operating System: Microsoft Windows 10 (64-bit), Version 21H1 (OS Build 19043.1237) Physical RAM: 16.0 GB RimWorld base game version: 1.3.3117 RimWorld DLCs loaded: none Mod list:

Euphoric commented 2 years ago

I believe I know where is the problem. In GenerateRandomAgePrefix, there is an if statement to stop the method early if pawn has fixed gender.

if (request.FixedGender.HasValue || !pawn.RaceProps.hasGenders) return;

But this condition ignores the KindDef value in the request. The whole condition should probably look like this:

if (request.FixedGender.HasValue || request.KindDef.fixedGender.HasValue || !pawn.RaceProps.hasGenders) return;

Euphoric commented 2 years ago

I see that the bug has been fixed. So this issue can be closed.

sumghai commented 2 years ago

I've confirmed that 8897ea6 works in my own race mod. Thanks @erdelf and @Euphoric!