コード例 #1
0
        public static int SpawnSinglePawn(this CorpseProduct CP, Pawn ParentPawn, IntVec3 SpawnPos, Map map, bool MyDebug = false)
        {
            string DebugStr = MyDebug ? "SpawnSinglePawn " : null;

            PawnGenOption PGO = CP.pawnKind.RandomElementByWeight(p => p.selectionWeight);

            if (PGO == null)
            {
                if (MyDebug)
                {
                    Log.Warning(DebugStr + " No PawnGenOption found");
                }
                return(0);
            }

            PawnKindDef PKD           = PGO.kind;
            Faction     RandomFaction = CP.HasWeightedFaction ? CP.forcedFaction?.GetFaction(ParentPawn) : null;

            if (PKD == null)
            {
                if (MyDebug)
                {
                    Log.Warning(DebugStr + " No PKD found");
                }
                return(0);
            }
            if (MyDebug)
            {
                Log.Warning(DebugStr + "PKD:" + PKD.label + " faction:" + RandomFaction);
            }

            bool wantNewBorn = Rand.Chance(CP.newBornChance);

            float combatPowerMultiplier = wantNewBorn ? CP.newBornCombatPowerRatio : 1;

            PawnGenerationRequest request =
                new PawnGenerationRequest(
                    kind: PKD, faction: RandomFaction, context: PawnGenerationContext.NonPlayer, tile: -1, forceGenerateNewPawn: false,
                    newborn: wantNewBorn, colonistRelationChanceFactor: 0, allowAddictions: false, allowFood: false, relationWithExtraPawnChanceFactor: 0
                    );
            Pawn NewPawn = PawnGenerator.GeneratePawn(request);

            GenSpawn.Spawn(NewPawn, SpawnPos, map, WipeMode.Vanish);

            if (CP.HasRelevantManhunterChance && Rand.Chance(CP.manhunterChance))
            {
                NewPawn.MakeManhunter(MyDebug);
            }

            if (CP.inheritSettingsFromParent && NewPawn.InheritParentSettings(ParentPawn, RandomFaction) && MyDebug)
            {
                Log.Warning(DebugStr + "applied parent settings");
            }

            if (CP.setRelationsWithParent && NewPawn.AddParentRelations(ParentPawn) && MyDebug)
            {
                Log.Warning(DebugStr + "added relations");
            }

            return((int)(combatPowerMultiplier * NewPawn.kindDef.combatPower));
        }
コード例 #2
0
        public static void SpawnConsumptionProduct(this CorpseProduct CP, Corpse corpse, Pawn ParentPawn, IntVec3 SpawnPos, bool MyDebug = false)
        {
            Map map = ParentPawn.Map;

            string DebugStr = MyDebug? ParentPawn.ThingID + " SpawnConsumptionProduct " : null;

            //Log.Warning("SpawnConsumptionProduct");
            //PawnKindDef PKD = CP.pawnKind.RandomElementByWeight()
            if (CP == null)
            {
                if (MyDebug)
                {
                    Log.Warning(DebugStr + "No CorpseProduct found");
                }
                return;
            }

            if (CP.HasRelevantCombatPowerPerMass)
            {
                if (MyDebug)
                {
                    Log.Warning(DebugStr + "CombatPowerPerMass");
                }
                int potentialCP         = (int)(corpse.GetStatValue(StatDefOf.Mass) * CP.combatPowerPerMass);
                int NewCombatPowerLimit = CP.HasRelevantCombatPowerLimit ? Math.Min(CP.combatPowerLimit, potentialCP) : potentialCP;

                if (MyDebug)
                {
                    Log.Warning(DebugStr + "corpse:" + corpse.Label + "potentialCP:" + potentialCP + " NewCombatPowerLimit:" + NewCombatPowerLimit);
                }

                int CombatPowerSoFar = 0;
                int loopBreaker      = 20;
                do
                {
                    CombatPowerSoFar += CP.SpawnSinglePawn(ParentPawn, SpawnPos, map, MyDebug);
                    if (MyDebug)
                    {
                        Log.Warning(DebugStr + "Spawned " + CombatPowerSoFar + "/" + NewCombatPowerLimit);
                    }
                    loopBreaker--;
                } while (loopBreaker > 0 && CombatPowerSoFar <= NewCombatPowerLimit);

                if (MyDebug && loopBreaker <= 0)
                {
                    Log.Warning(DebugStr + "Got stuck in an infinite loop, had to break it");
                }
            }
            else if (CP.HasRelevantCombatPowerLimit)
            {
                if (MyDebug)
                {
                    Log.Warning(DebugStr + "CombatPowerLimit");
                }

                int CombatPowerSoFar = 0;
                int loopBreaker      = 20;
                do
                {
                    CombatPowerSoFar += CP.SpawnSinglePawn(ParentPawn, SpawnPos, map, MyDebug);
                    if (MyDebug)
                    {
                        Log.Warning(DebugStr + "Spawned " + CombatPowerSoFar + "/" + CP.combatPowerLimit);
                    }
                    loopBreaker--;
                } while (loopBreaker > 0 && CombatPowerSoFar <= CP.combatPowerLimit);

                if (MyDebug && loopBreaker <= 0)
                {
                    Log.Warning(DebugStr + "Got stuck in an infinite loop, had to break it");
                }
            }
            else
            {
                int SpawnedPawnNum = CP.pawnNum.RandomInRange;
                for (int i = 0; i < SpawnedPawnNum; i++)
                {
                    CP.SpawnSinglePawn(ParentPawn, SpawnPos, map, MyDebug);
                }
            }
        }