示例#1
0
        public void ApplyWhirlwindDamage(DamageInfo dinfo)
        {
            bool flag = !dinfo.InstantPermanentInjury;

            if (flag)
            {
                bool flag2 = dinfo.Instigator != null;
                if (flag2)
                {
                    int  num2  = Mathf.RoundToInt(dinfo.Amount);
                    bool flag3 = pawn != null && base.Position != default(IntVec3);
                    if (flag3)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            IntVec3 intVec       = base.Position + GenAdj.AdjacentCells[i];
                            Pawn    cleaveVictim = new Pawn();
                            cleaveVictim = intVec.GetFirstPawn(base.Map);
                            if (cleaveVictim != null && cleaveVictim.Faction != pawn.Faction)
                            {
                                cleaveVictim.TakeDamage(dinfo);
                                MoteMaker.ThrowMicroSparks(cleaveVictim.Position.ToVector3(), base.Map);
                                CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();
                                MightPowerSkill      ver  = comp.MightData.MightPowerSkill_Whirlwind.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Whirlwind_ver");
                                verVal = ver.level;
                                if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless))
                                {
                                    MightPowerSkill mver = comp.MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                                    verVal = mver.level;
                                }
                                DamageInfo    dinfo2 = new DamageInfo(TMDamageDefOf.DamageDefOf.TM_Whirlwind, weaponDmg, 0, (float)-1, pawn, null, null, DamageInfo.SourceCategory.ThingOrUnknown);
                                System.Random random = new System.Random();
                                int           rnd    = GenMath.RoundRandom(random.Next(0, 100));
                                if (rnd < (verVal * 5))
                                {
                                    cleaveVictim.TakeDamage(dinfo2);
                                    MoteMaker.ThrowMicroSparks(cleaveVictim.Position.ToVector3(), base.Map);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private void Tick(int interval)
        {
            if (!Active)
            {
                return;
            }

            float previousProgress = RotProgress;

            // Do rotting progress according to temperature
            float cellTemp = parent.AmbientTemperature;
            float rotRate  = GenTemperature.RotRateAtTemperature(cellTemp);

            RotProgress += rotRate * interval;

            //Destroy if needed
            //Should this be in StageChanged?
            if (Stage == RotStage.Rotting && PropsRot.rotDestroys)
            {
                if (parent.IsInAnyStorage() && parent.SpawnedOrAnyParentSpawned)
                {
                    Messages.Message("MessageRottedAwayInStorage".Translate(parent.Label, parent).CapitalizeFirst(), new TargetInfo(parent.PositionHeld, parent.MapHeld), MessageTypeDefOf.NegativeEvent);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                }

                parent.Destroy();
                return;
            }

            //Once per day...
            bool isNewDay = Mathf.FloorToInt(previousProgress / GenDate.TicksPerDay) != Mathf.FloorToInt(RotProgress / GenDate.TicksPerDay);

            if (isNewDay && ShouldTakeRotDamage())
            {
                if (Stage == RotStage.Rotting && PropsRot.rotDamagePerDay > 0)
                {
                    parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(PropsRot.rotDamagePerDay)));
                }
                else if (Stage == RotStage.Dessicated && PropsRot.dessicatedDamagePerDay > 0)
                {
                    parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(PropsRot.dessicatedDamagePerDay)));
                }
            }
        }
示例#3
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map = (Map)parms.target;
            IntVec3 intVec;

            if (!this.TryFindEntryCell(map, out intVec))
            {
                return(false);
            }
            PawnKindDef thrumbo = PawnKindDefOf.Thrumbo;
            float       num     = StorytellerUtility.DefaultThreatPointsNow(map);
            int         num2    = GenMath.RoundRandom(num / thrumbo.combatPower);
            int         max     = Rand.RangeInclusive(2, 4);

            num2 = Mathf.Clamp(num2, 1, max);
            int     num3    = Rand.RangeInclusive(90000, 150000);
            IntVec3 invalid = IntVec3.Invalid;

            if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(intVec, map, 10f, out invalid))
            {
                invalid = IntVec3.Invalid;
            }
            Pawn pawn = null;

            for (int i = 0; i < num2; i++)
            {
                IntVec3 loc = CellFinder.RandomClosewalkCellNear(intVec, map, 10, null);
                pawn = PawnGenerator.GeneratePawn(thrumbo, null);
                GenSpawn.Spawn(pawn, loc, map, Rot4.Random, WipeMode.Vanish, false);
                pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + num3;
                if (invalid.IsValid)
                {
                    pawn.mindState.forcedGotoPosition = CellFinder.RandomClosewalkCellNear(invalid, map, 10, null);
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelThrumboPasses".Translate(new object[]
            {
                thrumbo.label
            }).CapitalizeFirst(), "LetterThrumboPasses".Translate(new object[]
            {
                thrumbo.label
            }), LetterDefOf.PositiveEvent, pawn, null, null);
            return(true);
        }
示例#4
0
        private Action PrepDrawRoad(Map map, TerrainDef rockDef, IntVec3 start, IntVec3 end, RoadDef roadDef, RoadPathingDef pathingDef, out IntVec3 centerpoint)
        {
            centerpoint = IntVec3.Invalid;
            PawnPath pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoorsOrWater, Danger.Deadly, false), PathEndMode.OnCell);

            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), PathEndMode.OnCell);
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThingsNotWater, Danger.Deadly, false), PathEndMode.OnCell);
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThings, Danger.Deadly, false), PathEndMode.OnCell);
            }
            if (pawnPath == PawnPath.NotFound)
            {
                return(null);
            }
            List <IntVec3> list = this.RefinePath(pawnPath.NodesReversed, map);

            pawnPath.ReleaseToPool();
            IntVec3 size  = map.Size;
            int     x     = size.x;
            IntVec3 size2 = map.Size;

            DistanceElement[,] distance = new DistanceElement[x, size2.z];
            int count            = list.Count;
            int centerpointIndex = Mathf.RoundToInt(Rand.Range(0.3f, 0.7f) * (float)count);
            int num = Mathf.Max(1, GenMath.RoundRandom((float)count / (float)roadDef.tilesPerSegment));

            for (int i = 0; i < num; i++)
            {
                int pathStartIndex = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)i);
                int pathEndIndex   = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)(i + 1));
                this.DrawCurveSegment(distance, list, pathStartIndex, pathEndIndex, pathingDef, map, centerpointIndex, ref centerpoint);
            }
            return(delegate
            {
                this.ApplyDistanceField(distance, map, rockDef, roadDef, pathingDef);
            });
        }
示例#5
0
        public int GetMaxZombieCount()
        {
            if (map == null || map.mapPawns == null)
            {
                return(0);
            }
            if (Constants.DEBUG_MAX_ZOMBIE_COUNT >= 0)
            {
                return(Constants.DEBUG_MAX_ZOMBIE_COUNT);
            }
            var colonists = Tools.CapableColonists(map);
            var perColonistZombieCount = GenMath.LerpDouble(0f, 4f, 5, 30, (float)Math.Min(4, Math.Sqrt(colonists)));
            var colonistMultiplier     = Math.Sqrt(colonists) * 2;
            var baseStrengthFactor     = GenMath.LerpDouble(0, 1000, 1f, 4f, Math.Min(1000, currentColonyPoints));
            var difficultyMultiplier   = Find.Storyteller.difficulty.threatScale;
            var count = (int)(perColonistZombieCount * colonistMultiplier * baseStrengthFactor * difficultyMultiplier);

            return(Math.Min(ZombieSettings.Values.maximumNumberOfZombies, count));
        }
        public static Toil TryTrain(TargetIndex traineeInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                Pawn pawn  = (Pawn)actor.jobs.curJob.GetTarget(traineeInd).Thing;
                if (pawn.Spawned && pawn.Awake() && actor.interactions.TryInteractWith(pawn, InteractionDefOf.TrainAttempt))
                {
                    float statValue = actor.GetStatValue(StatDefOf.TrainAnimalChance, true);
                    statValue *= Mathf.Max(0.05f, GenMath.LerpDouble(0f, 1f, 2f, 0f, pawn.RaceProps.wildness));
                    if (actor.relations.DirectRelationExists(PawnRelationDefOf.Bond, pawn))
                    {
                        statValue = (float)(statValue * 1.5);
                    }
                    statValue = Mathf.Clamp01(statValue);
                    TrainableDef trainableDef = pawn.training.NextTrainableToTrain();
                    string       text;
                    if (Rand.Value < statValue)
                    {
                        pawn.training.Train(trainableDef, actor);
                        if (pawn.caller != null)
                        {
                            pawn.caller.DoCall();
                        }
                        text = "TextMote_TrainSuccess".Translate(trainableDef.LabelCap, statValue.ToStringPercent());
                        RelationsUtility.TryDevelopBondRelation(actor, pawn, 0.007f);
                        TaleRecorder.RecordTale(TaleDefOf.TrainedAnimal, actor, pawn, trainableDef);
                    }
                    else
                    {
                        text = "TextMote_TrainFail".Translate(trainableDef.LabelCap, statValue.ToStringPercent());
                    }
                    string text2 = text;
                    text = text2 + "\n" + pawn.training.GetSteps(trainableDef) + " / " + trainableDef.steps;
                    MoteMaker.ThrowText((actor.DrawPos + pawn.DrawPos) / 2f, actor.Map, text, 5f);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 100;
            return(toil);
        }
        public override double GetValue(double x, double y, double z)
        {
            float  num   = Vector3.Angle(this.viewCenter, new Vector3((float)x, (float)y, (float)z));
            double value = base.modules[0].GetValue(x, y, z);
            float  num2  = Mathf.Max(2.5f, (float)(this.viewAngle * 0.25));
            float  num3  = Mathf.Max(0.8f, (float)(this.viewAngle * 0.10000000149011612));

            if (num < this.viewAngle - num2)
            {
                return(value);
            }
            float num4 = GenMath.LerpDouble(this.viewAngle - num2, this.viewAngle - num3, 0f, 0.62f, num);

            if (value > -0.11999999731779099)
            {
                return((value - -0.11999999731779099) * (1.0 - num4 * 0.699999988079071) - num4 * 0.30000001192092896 + -0.11999999731779099);
            }
            return(value - num4 * 0.30000001192092896);
        }
示例#8
0
        public static LatitudeSection GetDominantLatitudeSection(float latitude)
        {
            float num;
            float num2;
            float num3;

            LatitudeSectionUtility.GetLatitudeSection(latitude, out num, out num2, out num3);
            LatitudeSection result;

            if (num == 0f && num2 == 0f && num3 == 0f)
            {
                result = LatitudeSection.Undefined;
            }
            else
            {
                result = GenMath.MaxBy <LatitudeSection>(LatitudeSection.Equatorial, num, LatitudeSection.Seasonal, num2, LatitudeSection.Polar, num3);
            }
            return(result);
        }
示例#9
0
 public static void GiveRandomFood(Pawn p)
 {
     if (p.kindDef.invNutrition > 0.001f)
     {
         ThingDef def;
         if (p.kindDef.invFoodDef != null)
         {
             def = p.kindDef.invFoodDef;
         }
         else
         {
             float value = Rand.Value;
             def = ((value < 0.5f) ? ThingDefOf.MealSimple : ((!((double)value < 0.75)) ? ThingDefOf.MealSurvivalPack : ThingDefOf.MealFine));
         }
         Thing thing = ThingMaker.MakeThing(def);
         thing.stackCount = GenMath.RoundRandom(p.kindDef.invNutrition / thing.GetStatValue(StatDefOf.Nutrition));
         p.inventory.TryAddItemNotForSale(thing);
     }
 }
        internal static void                _CompTickRare(this CompRottable obj)
        {
            if (obj.InRefrigerator())
            {
                return;
            }
            float num = obj.rotProgress;

            obj.rotProgress += (float)Mathf.RoundToInt(1f * GenTemperature.RotRateAtTemperature(GenTemperature.GetTemperatureForCell(obj.parent.PositionHeld)) * 250f);
            if (
                (obj.Stage == RotStage.Rotting) &&
                (obj.PropsRot().rotDestroys)
                )
            {
                obj.parent.Destroy(DestroyMode.Vanish);
            }
            else
            {
                if (Mathf.FloorToInt(num / 60000f) == Mathf.FloorToInt(obj.rotProgress / 60000f))
                {
                    return;
                }
                if (
                    (obj.Stage == RotStage.Rotting) &&
                    (obj.PropsRot().rotDamagePerDay > 0.0f)
                    )
                {
                    obj.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(obj.PropsRot().rotDamagePerDay), (Thing)null, new BodyPartDamageInfo?(), (ThingDef)null));
                }
                else
                {
                    if (
                        (obj.Stage != RotStage.Dessicated) ||
                        (obj.PropsRot().dessicatedDamagePerDay <= 0.0f) ||
                        (!obj.ShouldTakeDessicateDamage())
                        )
                    {
                        return;
                    }
                    obj.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(obj.PropsRot().dessicatedDamagePerDay), (Thing)null, new BodyPartDamageInfo?(), (ThingDef)null));
                }
            }
        }
示例#11
0
 public override void Generate(Map map, GenStepParams parms)
 {
     if (Find.Storyteller.difficulty.allowCaveHives)
     {
         MapGenFloatGrid caves     = MapGenerator.Caves;
         MapGenFloatGrid elevation = MapGenerator.Elevation;
         float           num       = 0.7f;
         int             num2      = 0;
         rockCells.Clear();
         foreach (IntVec3 allCell in map.AllCells)
         {
             if (elevation[allCell] > num)
             {
                 rockCells.Add(allCell);
             }
             if (caves[allCell] > 0f)
             {
                 num2++;
             }
         }
         List <IntVec3> list = (from c in map.AllCells
                                where map.thingGrid.ThingsAt(c).Any((Thing thing) => thing.Faction != null)
                                select c).ToList();
         GenMorphology.Dilate(list, 50, map);
         HashSet <IntVec3> hashSet = new HashSet <IntVec3>(list);
         int num3 = GenMath.RoundRandom((float)num2 / 1000f);
         GenMorphology.Erode(rockCells, 10, map);
         possibleSpawnCells.Clear();
         for (int i = 0; i < rockCells.Count; i++)
         {
             if (caves[rockCells[i]] > 0f && !hashSet.Contains(rockCells[i]))
             {
                 possibleSpawnCells.Add(rockCells[i]);
             }
         }
         spawnedHives.Clear();
         for (int j = 0; j < num3; j++)
         {
             TrySpawnHive(map);
         }
         spawnedHives.Clear();
     }
 }
        public override void CompTick()
        {
            if (!this.parent.Spawned)
            {
                return;
            }
            if (!this.parent.GetComp <CompBreakdownable>().BrokenDown)
            {
                ticksActive = 0;
                return;
            }
            if (this.parent.Map.gameConditionManager.ElectricityDisabled)
            {
                ticksActive = 0;
                return;
            }


            ticksActive++;

            this.ticksToPlantHarm--;
            if (this.ticksToPlantHarm <= 0)
            {
                float currentRadius = this.CurrentRadius;
                float num           = 3.14159274f * currentRadius * currentRadius * this.PropsPlantHarmRadius.harmFrequencyPerArea;
                float num2          = 60f / num;
                int   num3;
                if (num2 >= 1f)
                {
                    this.ticksToPlantHarm = GenMath.RoundRandom(num2);
                    num3 = 1;
                }
                else
                {
                    this.ticksToPlantHarm = 1;
                    num3 = GenMath.RoundRandom(1f / num2);
                }
                for (int i = 0; i < num3; i++)
                {
                    this.HarmRandomPlantInRadius(currentRadius);
                }
            }
        }
        private void TakeWearoutDamageForDay(Thing ap)
        {
            int num = GenMath.RoundRandom(ap.def.apparel.wearPerDay);

            if (num > 0)
            {
                ap.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, num, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
            }
            if (ap.Destroyed && PawnUtility.ShouldSendNotificationAbout(this.pawn) && !this.pawn.Dead)
            {
                string text = "MessageWornApparelDeterioratedAway".Translate(new object[]
                {
                    GenLabel.ThingLabel(ap.def, ap.Stuff, 1),
                    this.pawn
                });
                text = text.CapitalizeFirst();
                Messages.Message(text, this.pawn, MessageTypeDefOf.NegativeEvent);
            }
        }
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            // If the 'construction' of the unfinished building is 'failed', treat it like cancelling the unfinished thing but with construction failure percentages
            if (mode == DestroyMode.FailConstruction)
            {
                foreach (Thing ingredient in ingredients)
                {
                    int ingredientCountLeft = GenMath.RoundRandom(ingredient.stackCount * 0.5f);
                    if (ingredientCountLeft > 0)
                    {
                        ingredient.stackCount = ingredientCountLeft;
                        GenPlace.TryPlaceThing(ingredient, Position, Map, ThingPlaceMode.Near);
                    }
                }
                ingredients.Clear();
            }

            base.Destroy(mode);
        }
示例#15
0
        public static void ApplyCleaveDamage(DamageInfo dinfo, Pawn caster, Pawn target, Map map, int ver)
        {
            bool flag = !dinfo.InstantPermanentInjury;

            if (flag)
            {
                bool flag2 = dinfo.Instigator != null;
                if (flag2)
                {
                    bool flag3 = caster != null && caster.PositionHeld != default(IntVec3) && !caster.Downed;
                    if (flag3)
                    {
                        System.Random random = new System.Random();
                        int           rnd    = GenMath.RoundRandom(random.Next(0, 100));
                        if (rnd < (ver * 15))
                        {
                            target.TakeDamage(dinfo);
                            MoteMaker.ThrowMicroSparks(target.Position.ToVector3(), map);
                        }
                        target.TakeDamage(dinfo);
                        MoteMaker.ThrowMicroSparks(target.Position.ToVector3(), map);
                        for (int i = 0; i < 8; i++)
                        {
                            IntVec3 intVec       = target.PositionHeld + GenAdj.AdjacentCells[i];
                            Pawn    cleaveVictim = new Pawn();
                            cleaveVictim = intVec.GetFirstPawn(map);
                            if (cleaveVictim != null && cleaveVictim.Faction != caster.Faction)
                            {
                                cleaveVictim.TakeDamage(dinfo);
                                MoteMaker.ThrowMicroSparks(cleaveVictim.Position.ToVector3(), map);
                                rnd = GenMath.RoundRandom(random.Next(0, 100));
                                if (rnd < (ver * 15))
                                {
                                    cleaveVictim.TakeDamage(dinfo);
                                    MoteMaker.ThrowMicroSparks(cleaveVictim.Position.ToVector3(), map);
                                }
                                DrawCleaving(cleaveVictim, caster, 10);
                            }
                        }
                    }
                }
            }
        }
示例#16
0
        private void Forage()
        {
            ThingDef foragedFood = caravan.Biome.foragedFood;

            if (foragedFood != null)
            {
                float foragedFoodCountPerInterval = ForagedFoodPerDayCalculator.GetForagedFoodCountPerInterval(caravan);
                int   a = GenMath.RoundRandom(foragedFoodCountPerInterval);
                int   b = Mathf.FloorToInt((caravan.MassCapacity - caravan.MassUsage) / foragedFood.GetStatValueAbstract(StatDefOf.Mass));
                a = Mathf.Min(a, b);
                while (a > 0)
                {
                    Thing thing = ThingMaker.MakeThing(foragedFood);
                    thing.stackCount = Mathf.Min(a, foragedFood.stackLimit);
                    a -= thing.stackCount;
                    CaravanInventoryUtility.GiveThing(caravan, thing);
                }
            }
        }
 public static void GiveRandomFood(Pawn p)
 {
     if (p.kindDef.invNutrition > 0.0010000000474974513)
     {
         ThingDef thingDef;
         if (p.kindDef.invFoodDef != null)
         {
             thingDef = p.kindDef.invFoodDef;
         }
         else
         {
             float value = Rand.Value;
             thingDef = ((!(value < 0.5)) ? ((!((double)value < 0.75)) ? ThingDefOf.MealSurvivalPack : ThingDefOf.MealFine) : ThingDefOf.MealSimple);
         }
         Thing thing = ThingMaker.MakeThing(thingDef, null);
         thing.stackCount = GenMath.RoundRandom(p.kindDef.invNutrition / thingDef.ingestible.nutrition);
         p.inventory.TryAddItemNotForSale(thing);
     }
 }
        protected virtual float SpringChance(Pawn p)
        {
            float num;

            if (this.KnowsOfTrap(p))
            {
                num = 0.004f;
            }
            else
            {
                num = this.GetStatValue(StatDefOf.TrapSpringChance, true);
            }
            num *= GenMath.LerpDouble(0.4f, 0.8f, 0f, 1f, p.BodySize);
            if (p.RaceProps.Animal)
            {
                num *= 0.1f;
            }
            return(Mathf.Clamp01(num));
        }
示例#19
0
        public static bool PsychologyException(InteractionWorker_MarriageProposal __instance, ref float __result, Pawn initiator, Pawn recipient)
        {
            PsychologyPawn realRecipient = recipient as PsychologyPawn;

            if (realRecipient != null)
            {
                float num = 1.2f;
                num *= Mathf.InverseLerp(0f, 0.75f, realRecipient.psyche.GetPersonalityRating(PersonalityNodeDefOf.Romantic));
                if (PsychologyBase.ActivateKinsey())
                {
                    num *= realRecipient.sexuality.AdjustedRomanticDrive;
                }
                num     *= Mathf.Clamp01(GenMath.LerpDouble(-20f, 60f, 0f, 1f, (float)recipient.relations.OpinionOf(initiator)));
                __result = Mathf.Clamp01(num);
                return(false);
                /* If the recipient is a PsychologyPawn, the mod takes over AcceptanceChance for them and the normal method will be ignored. */
            }
            return(true);
        }
示例#20
0
        private void TryProducePortion(float yieldPct)
        {
            ThingDef resDef;
            int      countPresent;
            IntVec3  cell;
            bool     nextResource = GetNextResource(out resDef, out countPresent, out cell);

            if (resDef != null)
            {
                int num = Mathf.Min(countPresent, resDef.deepCountPerPortion);
                if (nextResource)
                {
                    parent.Map.deepResourceGrid.SetAt(cell, resDef, countPresent - num);
                }
                int   stackCount = Mathf.Max(1, GenMath.RoundRandom((float)num * yieldPct));
                Thing thing      = ThingMaker.MakeThing(resDef);
                thing.stackCount = stackCount;
                GenPlace.TryPlaceThing(thing, parent.InteractionCell, parent.Map, ThingPlaceMode.Near);
                if (nextResource && !ValuableResourcesPresent())
                {
                    if (DeepDrillUtility.GetBaseResource(parent.Map) == null)
                    {
                        Messages.Message("DeepDrillExhaustedNoFallback".Translate(), parent, MessageTypeDefOf.TaskCompletion);
                    }
                    else
                    {
                        Messages.Message("DeepDrillExhausted".Translate(Find.ActiveLanguageWorker.Pluralize(DeepDrillUtility.GetBaseResource(parent.Map).label)), parent, MessageTypeDefOf.TaskCompletion);
                        for (int i = 0; i < 9; i++)
                        {
                            IntVec3 c = cell + GenRadial.RadialPattern[i];
                            if (c.InBounds(parent.Map))
                            {
                                ThingWithComps firstThingWithComp = c.GetFirstThingWithComp <CompDeepDrill>(parent.Map);
                                if (firstThingWithComp != null && !firstThingWithComp.GetComp <CompDeepDrill>().ValuableResourcesPresent())
                                {
                                    firstThingWithComp.SetForbidden(value: true);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void IndividualityValueSetup()
        {
            Pawn pawn = parent as Pawn;

            if (parent.def.defName == "ChjDroid")
            {
                if (sexuality == Sexuality.Undefined)
                {
                    sexuality = Sexuality.Asexual;
                }
                if (RomanceFactor == -1f)
                {
                    RomanceFactor = 0f;
                }
                if (PsychicFactor == -2f)
                {
                    PsychicFactor = RandomPsychicFactor();
                }
            }
            else if (parent.def.defName == "Harpy")
            {
                if (sexuality == Sexuality.Undefined)
                {
                    sexuality = Sexuality.Bisexual;
                }
            }
            if (sexuality == Sexuality.Undefined)
            {
                sexuality = RandomSexualityByWeight();
            }
            if (RomanceFactor == -1f)
            {
                RomanceFactor = GenMath.RoundTo(Rand.Range(0.1f, 1f), 0.1f);
            }
            if (PsychicFactor == -2f)
            {
                PsychicFactor = RandomPsychicFactor();
            }
            if (pawn != null && BodyWeight == -29)
            {
                BodyWeight = RandomBodyWeightByBodyType(pawn);
            }
        }
示例#22
0
        public override double GetValue(double x, double y, double z)
        {
            float  num   = Vector3.Angle(this.viewCenter, new Vector3((float)x, (float)y, (float)z));
            double value = this.modules[0].GetValue(x, y, z);
            float  num2  = Mathf.Max(2.5f, this.viewAngle * 0.25f);
            float  num3  = Mathf.Max(0.8f, this.viewAngle * 0.1f);

            if (num < this.viewAngle - num2)
            {
                return(value);
            }
            float num4 = GenMath.LerpDouble(this.viewAngle - num2, this.viewAngle - num3, 0f, 0.62f, num);

            if (value > -0.11999999731779099)
            {
                return((value - -0.11999999731779099) * (double)(1f - num4 * 0.7f) - (double)(num4 * 0.3f) + -0.11999999731779099);
            }
            return(value - (double)(num4 * 0.3f));
        }
示例#23
0
        public static float Postfix(float __result, HediffSet diffSet, PawnCapacityDef capacity,
                                    ref List <PawnCapacityUtility.CapacityImpactor> impactors)
        {
            if (capacity.zeroIfCannotBeAwake && !diffSet.pawn.health.capacities.CanBeAwake)
            {
                return(__result);
            }

            var max          = 999f;
            var originalMult = 1f;

            foreach (var hediff in diffSet.hediffs)
            {
                var capMod = hediff.CapMods?.Find(mod => mod.capacity == capacity);
                if (capMod == null)
                {
                    continue;
                }

                originalMult *= capMod.postFactor;
                if (capMod.setMax < max)
                {
                    max = capMod.setMax;
                }
            }

            var offset = diffSet.pawn.PsiTracker().GetTotalOffsetOfCapacity(capacity);
            var mult   = diffSet.pawn.PsiTracker().GetTotalFactorOfCapacity(capacity);

            if (impactors != null)
            {
                var abilities = diffSet.pawn.PsiTracker().GetAllAbilitiesImpactingCapacity(capacity);
                impactors.AddRange(abilities.Select(ab => new CapacityImpactorPsychic {
                    ability = ab
                }));
            }

            var newResult = __result * mult + offset * originalMult * mult;

            __result = Mathf.Min(newResult, max);

            return(GenMath.RoundedHundredth(Mathf.Max(__result, capacity.minValue)));
        }
 public override void Generate(Map map)
 {
     if (Find.Storyteller.difficulty.allowCaveHives)
     {
         CompProperties_TemperatureDamaged compProperties = ThingDefOf.Hive.GetCompProperties <CompProperties_TemperatureDamaged>();
         if (compProperties.safeTemperatureRange.Includes(map.mapTemperature.OutdoorTemp))
         {
             MapGenFloatGrid caves     = MapGenerator.Caves;
             MapGenFloatGrid elevation = MapGenerator.Elevation;
             float           num       = 0.7f;
             int             num2      = 0;
             this.rockCells.Clear();
             foreach (IntVec3 allCell in map.AllCells)
             {
                 if (elevation[allCell] > num)
                 {
                     this.rockCells.Add(allCell);
                 }
                 if (caves[allCell] > 0.0)
                 {
                     num2++;
                 }
             }
             int num3 = GenMath.RoundRandom((float)((float)num2 / 1000.0));
             GenMorphology.Erode(this.rockCells, 10, map, null);
             this.possibleSpawnCells.Clear();
             for (int i = 0; i < this.rockCells.Count; i++)
             {
                 if (caves[this.rockCells[i]] > 0.0)
                 {
                     this.possibleSpawnCells.Add(this.rockCells[i]);
                 }
             }
             this.spawnedHives.Clear();
             for (int j = 0; j < num3; j++)
             {
                 this.TrySpawnHive(map);
             }
             this.spawnedHives.Clear();
         }
     }
 }
 public static void ExpandableWorldObjectsOnGUI()
 {
     if (TransitionPct != 0f)
     {
         tmpWorldObjects.Clear();
         tmpWorldObjects.AddRange(Find.WorldObjects.AllWorldObjects);
         SortByExpandingIconPriority(tmpWorldObjects);
         WorldTargeter      worldTargeter          = Find.WorldTargeter;
         List <WorldObject> worldObjectsUnderMouse = null;
         if (worldTargeter.IsTargeting)
         {
             worldObjectsUnderMouse = GenWorldUI.WorldObjectsUnderMouse(UI.MousePositionOnUI);
         }
         for (int i = 0; i < tmpWorldObjects.Count; i++)
         {
             try
             {
                 WorldObject worldObject = tmpWorldObjects[i];
                 if (worldObject.def.expandingIcon && !worldObject.HiddenBehindTerrainNow())
                 {
                     Color expandingIconColor = worldObject.ExpandingIconColor;
                     expandingIconColor.a = TransitionPct;
                     if (worldTargeter.IsTargetedNow(worldObject, worldObjectsUnderMouse))
                     {
                         float num = GenMath.LerpDouble(-1f, 1f, 0.7f, 1f, Mathf.Sin(Time.time * 8f));
                         expandingIconColor.r *= num;
                         expandingIconColor.g *= num;
                         expandingIconColor.b *= num;
                     }
                     GUI.color = expandingIconColor;
                     GUI.DrawTexture(ExpandedIconScreenRect(worldObject), worldObject.ExpandingIcon);
                 }
             }
             catch (Exception ex)
             {
                 Log.Error("Error while drawing " + tmpWorldObjects[i].ToStringSafe() + ": " + ex);
             }
         }
         tmpWorldObjects.Clear();
         GUI.color = Color.white;
     }
 }
示例#26
0
 public static void DebugDraw()
 {
     if (DebugViewSettings.drawInfestationChance)
     {
         Map      visibleMap = Find.VisibleMap;
         CellRect cellRect   = Find.CameraDriver.CurrentViewRect;
         cellRect.ClipInsideMap(visibleMap);
         cellRect = cellRect.ExpandedBy(1);
         InfestationCellFinder.CalculateTraversalDistancesToUnroofed(visibleMap);
         InfestationCellFinder.CalculateClosedAreaSizeGrid(visibleMap);
         InfestationCellFinder.CalculateDistanceToColonyBuildingGrid(visibleMap);
         float num = 0.001f;
         for (int i = 0; i < visibleMap.Size.z; i++)
         {
             for (int j = 0; j < visibleMap.Size.x; j++)
             {
                 IntVec3 cell    = new IntVec3(j, 0, i);
                 float   scoreAt = InfestationCellFinder.GetScoreAt(cell, visibleMap);
                 if (scoreAt > num)
                 {
                     num = scoreAt;
                 }
             }
         }
         for (int k = 0; k < visibleMap.Size.z; k++)
         {
             for (int l = 0; l < visibleMap.Size.x; l++)
             {
                 IntVec3 intVec = new IntVec3(l, 0, k);
                 if (cellRect.Contains(intVec))
                 {
                     float scoreAt2 = InfestationCellFinder.GetScoreAt(intVec, visibleMap);
                     if (scoreAt2 > 0f)
                     {
                         float a = GenMath.LerpDouble(7.5f, num, 0f, 1f, scoreAt2);
                         CellRenderer.RenderCell(intVec, SolidColorMaterials.SimpleSolidColorMaterial(new Color(0f, 0f, 1f, a), false));
                     }
                 }
             }
         }
     }
 }
        public override IEnumerable Regenerate()
        {
            IEnumerator enumerator = this.< Regenerate > __BaseCallProxy0().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object result = enumerator.Current;
                    yield return(result);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            Rand.PushState();
            Rand.Seed = Find.World.info.Seed;
            for (int i = 0; i < 1500; i++)
            {
                Vector3      unitVector = Rand.UnitVector3;
                Vector3      pos        = unitVector * 10f;
                LayerSubMesh subMesh    = base.GetSubMesh(WorldMaterials.Stars);
                float        num        = WorldLayer_Stars.StarsDrawSize.RandomInRange;
                Vector3      rhs        = (!this.UseStaticRotation) ? Vector3.forward : GenCelestial.CurSunPositionInWorldSpace().normalized;
                float        num2       = Vector3.Dot(unitVector, rhs);
                if (num2 > 0.8f)
                {
                    num *= GenMath.LerpDouble(0.8f, 1f, 1f, 0.35f, num2);
                }
                WorldRendererUtility.PrintQuadTangentialToPlanet(pos, num, 0f, subMesh, true, true, true);
            }
            this.calculatedForStartingTile   = ((Find.GameInitData == null) ? -1 : Find.GameInitData.startingTile);
            this.calculatedForStaticRotation = this.UseStaticRotation;
            Rand.PopState();
            base.FinalizeMesh(MeshParts.All);
            yield break;
        }
示例#28
0
        private static Func <int, int> GetBuildingResourcesLeaveCalculator(Thing destroyedThing, DestroyMode mode)
        {
            if (!GenLeaving.CanBuildingLeaveResources(destroyedThing, mode))
            {
                return((int count) => 0);
            }
            if (mode == DestroyMode.Deconstruct && typeof(Frame).IsAssignableFrom(destroyedThing.GetType()))
            {
                mode = DestroyMode.Cancel;
            }
            switch (mode)
            {
            case DestroyMode.Vanish: {
                return((int count) => 0);
            }

            case DestroyMode.WillReplace: {
                return((int count) => 0);
            }

            case DestroyMode.KillFinalize: {
                return((int count) => GenMath.RoundRandom((float)count * 0.5f));
            }

            case DestroyMode.Deconstruct: {
                return((int count) => GenMath.RoundRandom(Mathf.Min((float)count * destroyedThing.def.resourcesFractionWhenDeconstructed, (float)(count - 1))));
            }

            case DestroyMode.FailConstruction: {
                return((int count) => GenMath.RoundRandom((float)count * 0.5f));
            }

            case DestroyMode.Cancel: {
                return((int count) => GenMath.RoundRandom((float)count * 1f));
            }

            case DestroyMode.Refund: {
                return((int count) => count);
            }
            }
            throw new ArgumentException(string.Concat("Unknown destroy mode ", mode));
        }
示例#29
0
        public static Season GetReportedSeason(float yearPct, float latitude)
        {
            float by   = default(float);
            float by2  = default(float);
            float by3  = default(float);
            float by4  = default(float);
            float num  = default(float);
            float num2 = default(float);

            SeasonUtility.GetSeason(yearPct, latitude, out by, out by2, out by3, out by4, out num, out num2);
            if (num == 1.0)
            {
                return(Season.PermanentSummer);
            }
            if (num2 == 1.0)
            {
                return(Season.PermanentWinter);
            }
            return(GenMath.MaxBy(Season.Spring, by, Season.Summer, by2, Season.Fall, by3, Season.Winter, by4));
        }
示例#30
0
        public static Season GetReportedSeason(float yearPct, float latitude)
        {
            float by;
            float by2;
            float by3;
            float by4;
            float num;
            float num2;

            SeasonUtility.GetSeason(yearPct, latitude, out by, out by2, out by3, out by4, out num, out num2);
            if (num == 1f)
            {
                return(Season.PermanentSummer);
            }
            if (num2 == 1f)
            {
                return(Season.PermanentWinter);
            }
            return(GenMath.MaxBy <Season>(Season.Spring, by, Season.Summer, by2, Season.Fall, by3, Season.Winter, by4));
        }