예제 #1
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);
                }
            }
        }