mirror of
https://github.com/vegapnk/RJW-Genes.git
synced 2024-08-15 00:23:31 +00:00
Fixed and improved prioritization of racegenedefs
Added an priority option to xml which decides the racegenedef to choose if an animal is present in multiple racegenedefs (under the same variable (racegroups, racenames or kinddefs
This commit is contained in:
parent
cc43a5a5aa
commit
8a7138106a
4 changed files with 26 additions and 27 deletions
Binary file not shown.
|
@ -42,7 +42,7 @@ namespace RJW_BGS
|
||||||
public static List<GeneDef> SelectGenes(Pawn pawn)
|
public static List<GeneDef> SelectGenes(Pawn pawn)
|
||||||
{
|
{
|
||||||
List<GeneDef> genelist = new List<GeneDef>();
|
List<GeneDef> genelist = new List<GeneDef>();
|
||||||
RaceGeneDef raceGeneDef = RJWcopy.GetRaceGeneDefInternal(pawn);
|
RaceGeneDef raceGeneDef = RaceGeneDef_Helper.GetRaceGeneDefInternal(pawn);
|
||||||
if (raceGeneDef != null)
|
if (raceGeneDef != null)
|
||||||
{
|
{
|
||||||
foreach (BestialityGeneInheritanceDef gene in raceGeneDef.genes)
|
foreach (BestialityGeneInheritanceDef gene in raceGeneDef.genes)
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace RJW_BGS
|
||||||
{
|
{
|
||||||
public class RaceGeneDef : Def
|
public class RaceGeneDef : Def
|
||||||
{
|
{
|
||||||
|
public int priority;
|
||||||
public String raceGroup;
|
public String raceGroup;
|
||||||
public List<string> raceNames;
|
public List<string> raceNames;
|
||||||
public List<string> pawnKindNames;
|
public List<string> pawnKindNames;
|
||||||
|
|
|
@ -9,31 +9,48 @@ using RimWorld;
|
||||||
|
|
||||||
namespace RJW_BGS
|
namespace RJW_BGS
|
||||||
{
|
{
|
||||||
internal class RJWcopy
|
public class RaceGeneDef_Helper
|
||||||
{
|
{
|
||||||
//code based on racegroupdefinternal which has a similar function
|
//code based on racegroupdefinternal which has a similar function
|
||||||
public static RaceGeneDef GetRaceGeneDefInternal(Pawn pawn)
|
public static RaceGeneDef GetRaceGeneDefInternal(Pawn pawn)
|
||||||
{
|
{
|
||||||
|
List<RaceGeneDef> Valids = ValidRaceGeneDefs(pawn);
|
||||||
|
if (Valids.Count > 0)
|
||||||
|
{
|
||||||
|
RaceGeneDef result = Valids.MaxBy(r => r.priority);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
//First check if there is a matching pawnkinddef then race, then racegroup
|
||||||
|
|
||||||
|
}
|
||||||
|
public static List<RaceGeneDef> ValidRaceGeneDefs(Pawn pawn)
|
||||||
|
{
|
||||||
PawnKindDef kindDef = pawn.kindDef;
|
PawnKindDef kindDef = pawn.kindDef;
|
||||||
if (kindDef == null)
|
if (kindDef == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
string raceName = kindDef.race.defName;
|
string raceName = kindDef.race.defName;
|
||||||
string pawnKindName = kindDef.defName;
|
string pawnKindName = kindDef.defName;
|
||||||
IEnumerable<RaceGeneDef> allDefs = DefDatabase<RaceGeneDef>.AllDefs;
|
|
||||||
PawnData pawnData = SaveStorage.DataStore.GetPawnData(pawn);
|
PawnData pawnData = SaveStorage.DataStore.GetPawnData(pawn);
|
||||||
RaceGroupDef raceGroupDef = pawnData.RaceSupportDef;
|
RaceGroupDef raceGroupDef = pawnData.RaceSupportDef;
|
||||||
|
|
||||||
|
IEnumerable<RaceGeneDef> allDefs = DefDatabase<RaceGeneDef>.AllDefs;
|
||||||
List<RaceGeneDef> pawnKindDefs = allDefs.Where(delegate (RaceGeneDef group)
|
List<RaceGeneDef> pawnKindDefs = allDefs.Where(delegate (RaceGeneDef group)
|
||||||
{
|
{
|
||||||
List<string> pawnKindNames = group.pawnKindNames;
|
List<string> pawnKindNames = group.pawnKindNames;
|
||||||
return pawnKindNames != null && pawnKindNames.Contains(pawnKindName);
|
return pawnKindNames != null && pawnKindNames.Contains(pawnKindName);
|
||||||
}).ToList<RaceGeneDef>();
|
}).ToList<RaceGeneDef>();
|
||||||
|
if (pawnKindDefs.Count() > 0)
|
||||||
|
return pawnKindDefs;
|
||||||
List<RaceGeneDef> raceKindDefs = allDefs.Where(delegate (RaceGeneDef group)
|
List<RaceGeneDef> raceKindDefs = allDefs.Where(delegate (RaceGeneDef group)
|
||||||
{
|
{
|
||||||
List<string> raceNames = group.raceNames;
|
List<string> raceNames = group.raceNames;
|
||||||
return raceNames != null && raceNames.Contains(raceName);
|
return raceNames != null && raceNames.Contains(raceName);
|
||||||
}).ToList<RaceGeneDef>();
|
}).ToList<RaceGeneDef>();
|
||||||
|
if (raceKindDefs.Count() > 0)
|
||||||
|
return raceKindDefs;
|
||||||
List<RaceGeneDef> raceGroupDefs = new List<RaceGeneDef>();
|
List<RaceGeneDef> raceGroupDefs = new List<RaceGeneDef>();
|
||||||
if (raceGroupDef != null)
|
if (raceGroupDef != null)
|
||||||
{
|
{
|
||||||
|
@ -43,27 +60,9 @@ namespace RJW_BGS
|
||||||
return raceGroupDefName != null && raceGroupDefName == raceGroupDef.defName;
|
return raceGroupDefName != null && raceGroupDefName == raceGroupDef.defName;
|
||||||
}).ToList<RaceGeneDef>();
|
}).ToList<RaceGeneDef>();
|
||||||
}
|
}
|
||||||
RaceGeneDef result = null;
|
if (raceGroupDefs.Count() > 0)
|
||||||
//First check if there is a matching pawnkinddef then race, then racegroup
|
return raceGroupDefs;
|
||||||
if (pawnKindDefs.Any())
|
return new List<RaceGeneDef>();
|
||||||
{
|
|
||||||
result = pawnKindDefs.RandomElement();
|
|
||||||
}
|
|
||||||
else if (raceKindDefs.Any() && result == null)
|
|
||||||
{
|
|
||||||
result = raceKindDefs.RandomElement();
|
|
||||||
}
|
|
||||||
else if (raceGroupDefs.Any() && result == null)
|
|
||||||
{
|
|
||||||
result = raceGroupDefs.RandomElement();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue