Example #1
0
        private bool SpawnMeat()
        {
            if (!Props.spawnMeat)
            {
                return(false);
            }

            if (!IsPawn && Props.meatToSpawn == null)
            {
                if (MyDebug)
                {
                    Log.Warning("parent is not pawn but tried to spawn meat while there is no Props.meatToSpawn, use spawnThing instead, maybe");
                }
                return(false);
            }

            if (Props.meatToSpawn == null && pawn.RaceProps.meatDef == null)
            {
                if (MyDebug)
                {
                    Log.Warning("Found no meat def for pawn or stat of meatamount is <= 0");
                }
                return(false);
            }

            int meatAmount = GetMeatAmount();

            if (meatAmount <= 0)
            {
                if (MyDebug)
                {
                    Log.Warning("Calculated meat amount is <= 0, nothing to do");
                }
                return(false);
            }

            ThingDef thingToSpawn = null;

            if (IsPawn)
            {
                thingToSpawn = (Props.meatToSpawn == null) ? pawn.RaceProps.meatDef : Props.meatToSpawn;
            }
            else if (IsBuilding || IsThing)
            {
                thingToSpawn = Props.meatToSpawn;
            }

            if (thingToSpawn == null)
            {
                if (MyDebug)
                {
                    Log.Warning("ThingToSpawn is null, cant work");
                }
                return(false);
            }

            int pileNum = Props.meatPilesIntRange.RandomInRange;

            if (MyDebug)
            {
                Log.Warning("Trying to spawn " + pileNum + " piles of " + thingToSpawn + "(x" + meatAmount + ")");
            }
            int loopBreaker = 20;

            for (int i = 0; i < pileNum; i++)
            {
                if (MyDebug)
                {
                    Log.Warning(i + "/" + pileNum + " meat left: " + meatAmount);
                }
                if (loopBreaker-- < 0)
                {
                    if (MyDebug)
                    {
                        Log.Warning("Had to break the meat loop, bc it would not end");
                    }
                    return(false);
                }

                int currentPileAmount = Rand.Range(1, meatAmount);
                meatAmount -= currentPileAmount;

                if (MyDebug)
                {
                    Log.Warning(i + "/" + pileNum + " spawning: " + currentPileAmount);
                }
                bool Didit = false;

                Didit = Lifespan_Utility.TryDoSpawn(parent, thingToSpawn, currentPileAmount, Props.spawnMaxAdjacent, Props.tryToUnstack, Props.inheritFaction, Props.spawnForbidden, Props.showMessageIfOwned);

                if (!Didit)
                {
                    if (MyDebug)
                    {
                        Log.Warning("Had to break the meat loop, bc it cant spawn things");
                    }
                    return(false);
                }

                if (meatAmount <= 0)
                {
                    if (MyDebug)
                    {
                        Log.Warning("Had to break the meat loop, bc it did its job");
                    }
                    break;
                }
            }

            return(true);
        }
Example #2
0
        private bool SpawnThing()
        {
            if (!Props.spawnThing)
            {
                return(false);
            }

            int thingAmount = GeThingAmount();

            if (thingAmount <= 0)
            {
                if (MyDebug)
                {
                    Log.Warning("calculated thingAmount was <= 0, cant spawn things");
                }
                return(false);
            }


            int pileNum = Props.thingPilesIntRange.RandomInRange;

            if (MyDebug)
            {
                Log.Warning("Trying to spawn " + pileNum + " piles of " + Props.thingToSpawn + "(x" + thingAmount + ")");
            }
            int loopBreaker = 20;

            for (int i = 0; i < pileNum; i++)
            {
                if (MyDebug)
                {
                    Log.Warning(i + "/" + pileNum + " meat left: " + thingAmount);
                }
                if (loopBreaker-- < 0)
                {
                    if (MyDebug)
                    {
                        Log.Warning("Had to break the thing loop, bc it would not end");
                    }
                    return(false);
                }
                int currentPileAmount = Rand.Range(1, thingAmount);
                thingAmount -= currentPileAmount;
                bool DidIt = false;
                DidIt = Lifespan_Utility.TryDoSpawn(parent, Props.thingToSpawn, currentPileAmount, Props.spawnMaxAdjacent, Props.tryToUnstack, Props.inheritFaction, Props.spawnForbidden, Props.showMessageIfOwned);

                if (!DidIt)
                {
                    if (MyDebug)
                    {
                        Log.Warning("Had to break the thing loop, bc it cant spawn things");
                    }
                    return(false);
                }

                if (thingAmount <= 0)
                {
                    if (MyDebug)
                    {
                        Log.Warning("Had to break the thing loop, bc it did its job");
                    }
                    break;
                }
            }

            return(true);
        }