mirror of
https://github.com/vegapnk/RJW-Genes.git
synced 2024-08-15 00:23:31 +00:00
Added a Def to control queen offspring chances
This commit is contained in:
parent
c8dfa8fc89
commit
df513f8c09
7 changed files with 97 additions and 11 deletions
23
Source/Genes/Hive/Defs/HiveOffspringChanceDef.cs
Normal file
23
Source/Genes/Hive/Defs/HiveOffspringChanceDef.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Verse;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
public class HiveOffspringChanceDef : Def
|
||||
{
|
||||
|
||||
public string queenXenotype;
|
||||
|
||||
// Chance of the below should be 1 when summed up!
|
||||
// Otherwise the roll-logic fails.
|
||||
|
||||
public double queenChance;
|
||||
public double droneChance;
|
||||
public double workerChance;
|
||||
|
||||
}
|
||||
}
|
|
@ -128,8 +128,6 @@ namespace RJW_Genes
|
|||
Dictionary<XenotypeDef,List<GeneDef>> dict = new Dictionary<XenotypeDef, List<GeneDef>>();
|
||||
IEnumerable<QueenWorkerMappingDef> mappingDefs = DefDatabase<QueenWorkerMappingDef>.AllDefs;
|
||||
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"Found {mappingDefs.Count()} Queen-Worker mappings in defs");
|
||||
|
||||
// Dev-Note: I first a nice lambda here, but I used nesting in favour of logging.
|
||||
foreach (QueenWorkerMappingDef mappingDef in mappingDefs)
|
||||
{
|
||||
|
@ -204,5 +202,27 @@ namespace RJW_Genes
|
|||
return DefDatabase<XenotypeDef>.AllDefs.Where(type => type.genes.Contains(GeneDefOf.rjw_genes_drone));
|
||||
}
|
||||
|
||||
|
||||
public static HiveOffspringChanceDef LookupDefaultHiveInheritanceChances()
|
||||
{
|
||||
IEnumerable<HiveOffspringChanceDef> offspringChanceDefs = DefDatabase<HiveOffspringChanceDef>.AllDefs;
|
||||
|
||||
List<GeneDef> workerGenes = new List<GeneDef>();
|
||||
|
||||
var defaultChance = offspringChanceDefs.First(m => m.defName == "rjw_genes_default_hive_offspring_chances");
|
||||
|
||||
if (defaultChance == null)
|
||||
ModLog.Warning("Did not find `rjw_genes_default_hive_offspring_chances`. Someone likely changed the defname!");
|
||||
|
||||
return defaultChance;
|
||||
}
|
||||
|
||||
public static HiveOffspringChanceDef LookupHiveInheritanceChances(XenotypeDef queenDef)
|
||||
{
|
||||
IEnumerable<HiveOffspringChanceDef> offspringChanceDefs = DefDatabase<HiveOffspringChanceDef>.AllDefs;
|
||||
|
||||
return offspringChanceDefs.FirstOrFallback(t => t.queenXenotype == queenDef.defName, LookupDefaultHiveInheritanceChances());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,6 @@ namespace RJW_Genes
|
|||
[HarmonyPatch(typeof(PregnancyUtility), nameof(PregnancyUtility.ApplyBirthOutcome))]
|
||||
public class Patch_BirthOutcome_SetHiveGenes
|
||||
{
|
||||
const double QUEEN_CHANCE = 0.01f;
|
||||
const double DRONE_CHANCE = 0.49f;
|
||||
const double WORKER_CHANCE = 1 - QUEEN_CHANCE - DRONE_CHANCE;
|
||||
|
||||
|
||||
[HarmonyPostfix]
|
||||
|
@ -45,6 +42,8 @@ namespace RJW_Genes
|
|||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"PostFix PregnancyUtility::ApplyBirthOutcome - Checking Hive Inheritance because {pawn} has a queen parent.");
|
||||
|
||||
XenotypeDef queenDef = TryFindParentQueenXenotype(pawn);
|
||||
HiveOffspringChanceDef hiveOffspringChanceDef = HiveUtility.LookupHiveInheritanceChances(queenDef);
|
||||
|
||||
// Case 1: Mother is Queen, Father is something else. Produce Worker.
|
||||
if (!hasDroneParent)
|
||||
{
|
||||
|
@ -56,22 +55,22 @@ namespace RJW_Genes
|
|||
{
|
||||
double roll = (new Random()).NextDouble();
|
||||
// Case 2.a: New Queen born
|
||||
if (roll < QUEEN_CHANCE)
|
||||
if (roll < hiveOffspringChanceDef.queenChance)
|
||||
{
|
||||
pawn.genes.SetXenotype(queenDef);
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"{pawn} born as a new queen with xenotype {queenDef.defName} ({QUEEN_CHANCE*100}% chance,rolled {roll})");
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"{pawn} born as a new queen with xenotype {queenDef.defName} ({hiveOffspringChanceDef.queenChance * 100}% chance,rolled {roll})");
|
||||
// TODO: Make a letter ?
|
||||
}
|
||||
// Case 2.b: New Drone born
|
||||
else if (roll < DRONE_CHANCE + QUEEN_CHANCE)
|
||||
else if (roll < hiveOffspringChanceDef.droneChance + hiveOffspringChanceDef.queenChance)
|
||||
{
|
||||
XenotypeDef droneDef = TryFindParentDroneXenotype(pawn);
|
||||
pawn.genes.SetXenotype(droneDef);
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"{pawn} born as a new drone with xenotype {droneDef.defName} ({(DRONE_CHANCE + QUEEN_CHANCE) * 100}% chance,rolled {roll}))");
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"{pawn} born as a new drone with xenotype {droneDef.defName} ({(hiveOffspringChanceDef.droneChance + hiveOffspringChanceDef.queenChance) * 100}% chance,rolled {roll}))");
|
||||
}
|
||||
// Case 2.c: Worker
|
||||
else {
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"{pawn} born as a worker ({(WORKER_CHANCE) * 100}% chance,rolled {roll}))");
|
||||
if (RJW_Genes_Settings.rjw_genes_detailed_debug) ModLog.Message($"{pawn} born as a worker ({(hiveOffspringChanceDef.workerChance) * 100}% chance,rolled {roll}))");
|
||||
MakeWorker(pawn, queenDef);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue