Added some checks for Map-Presence for Queen Genes, language keys

This commit is contained in:
Vegapnk 2023-04-23 07:37:48 +02:00
parent b5121b0a04
commit 085f572780
9 changed files with 70 additions and 9 deletions

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<StatsReport_QueenCloseBy>queen in proximity</StatsReport_QueenCloseBy>
<StatsReport_QueenAbsent>queen absent</StatsReport_QueenAbsent>
<StatsReport_MultipleQueens>multiple queens present</StatsReport_MultipleQueens>
</LanguageData>

View File

@ -21,6 +21,9 @@ namespace RJW_Genes
{
if (req.Pawn == null || !req.Pawn.Spawned)
return false;
// If the pawn is not on Map (e.g. caravan), no mali
if (!HiveUtility.PawnIsOnHomeMap(req.Pawn))
return false;
if (GeneUtility.HasGeneNullCheck(req.Pawn, GeneDefOf.rjw_genes_zealous_loyalty))
{

View File

@ -26,6 +26,9 @@ namespace RJW_Genes
{
if (req.Pawn == null || !req.Pawn.Spawned)
return false;
// If the pawn is not on Map (e.g. caravan), no mali
if (!HiveUtility.PawnIsOnHomeMap(req.Pawn))
return false;
// Case A: Check for Loyal Pawns if their One Queen is nearby
if (GeneUtility.HasGeneNullCheck(req.Pawn, GeneDefOf.rjw_genes_zealous_loyalty) && HiveUtility.QueensOnMap() == 1)

View File

@ -10,6 +10,13 @@ namespace RJW_Genes
{
internal class HiveUtility
{
/// <summary>
/// Checks for existance of the RJW-Gene `queen`, if the pawn is spawned and if the pawn has reached adulthood.
/// Despite the naming, a Queen can also be male.
/// </summary>
/// <param name="pawn">The pawn that could be an Adult Queen</param>
/// <returns>Whether the pawn is an adult queen.</returns>
public static bool IsAdultQueen(Pawn pawn)
{
@ -24,16 +31,41 @@ namespace RJW_Genes
return false;
}
public static int QueensOnMap()
{
List<Pawn> playersPawns = Find.CurrentMap.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer);
return playersPawns.Count(pawn => pawn.Spawned && IsAdultQueen(pawn));
}
public static int QueensOnMap() => GetQueensOnMap().Count;
/// <summary>
/// Checks for all pawns on the Players Home Map if they are an adult queen.
/// Adultness is determined by Base-Game Logic, Queen is determined by the rjw_genes_queen GeneDefOf (Not Xenotype).
/// </summary>
/// <returns>A list of queens on the players HomeMap</returns>
public static List<Pawn> GetQueensOnMap()
{
List<Pawn> playersPawns = Find.CurrentMap.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer);
return playersPawns.FindAll(pawn => pawn.Spawned && IsAdultQueen(pawn));
Map map = Find.Maps.Where(mapCandidate => mapCandidate.IsPlayerHome).First();
if (map != null)
{
List<Pawn> playersPawns = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer);
return playersPawns.FindAll(pawn => pawn.Spawned && IsAdultQueen(pawn));
}
// Fallback: Something is wrong with Map
return new List<Pawn>();
}
/// <summary>
/// Checks if the pawn is on the players home map.
///
/// Reason is that drones should only be punished for absence of queen if they are on the map and there is no queen.
/// If they are on a mission, transport-pod etc. they should not get boni or mali.
/// </summary>
/// <param name="pawn">The pawn for which to check map-presence.</param>
/// <returns>True if the pawn is on the home-map, False otherwise.</returns>
public static bool PawnIsOnHomeMap(Pawn pawn)
{
Map homeMap = Find.Maps.Where(mapCandidate => mapCandidate.IsPlayerHome).First();
return
homeMap != null && pawn != null
&& pawn.Spawned
&& pawn.Map == homeMap;
}
}
}

View File

@ -23,9 +23,11 @@ namespace RJW_Genes
// Only check if they are spawned
if (!p.Spawned || !other.Spawned)
{
return (ThoughtState)false;
}
// If the pawn is not on Map (e.g. caravan), no mali
if (!HiveUtility.PawnIsOnHomeMap(p))
return (ThoughtState)false;
if (GeneUtility.HasGeneNullCheck(p, GeneDefOf.rjw_genes_zealous_loyalty) && HiveUtility.QueensOnMap() == 1)
{

View File

@ -19,6 +19,9 @@ namespace RJW_Genes
if (!RelationsUtility.PawnsKnowEachOther(p, other))
return (ThoughtState)false;
// If the pawn is not on Map (e.g. caravan), no mali
if (!HiveUtility.PawnIsOnHomeMap(p))
return (ThoughtState)false;
// Only check if they are spawned
if (!p.Spawned || !other.Spawned)

View File

@ -20,6 +20,9 @@ namespace RJW_Genes
// Queens cannot have loyalty thoughts
if (GeneUtility.HasGeneNullCheck(p, GeneDefOf.rjw_genes_queen))
return (ThoughtState)false;
// If the pawn is not on Map (e.g. caravan), no mali
if (!HiveUtility.PawnIsOnHomeMap(p))
return (ThoughtState)false;
if (GeneUtility.HasGeneNullCheck(p, GeneDefOf.rjw_genes_zealous_loyalty) && HiveUtility.QueensOnMap() == 0)
{

View File

@ -20,6 +20,9 @@ namespace RJW_Genes
// Queens cannot have loyalty thoughts
if (GeneUtility.HasGeneNullCheck(p, GeneDefOf.rjw_genes_queen))
return (ThoughtState)false;
// If the pawn is not on Map (e.g. caravan), no mali
if (!HiveUtility.PawnIsOnHomeMap(p))
return (ThoughtState)false;
if (GeneUtility.HasGeneNullCheck(p, GeneDefOf.rjw_genes_zealous_loyalty) && HiveUtility.QueensOnMap() == 1)
{

View File

@ -16,6 +16,9 @@ namespace RJW_Genes
{
if (p == null || !p.Spawned)
return (ThoughtState) false;
// If the pawn is not on Map (e.g. caravan), no mali
if (!HiveUtility.PawnIsOnHomeMap(p))
return (ThoughtState)false;
if (HiveUtility.IsAdultQueen(p) && HiveUtility.QueensOnMap() >= 2)
{