示例#1
0
        IEnumerable <ThingWithComps> GetFacilitiesBetweenThisAndChamber(Chamber chamber)
        {
            Rot4 rot = parent.Rotation;

            IEnumerable <Thing> list =
                parent.GetComp <CompAffectedByFacilities>().LinkedFacilitiesListForReading
                .OrderBy(thing =>
                         rot == Rot4.North ? thing.Position.z :
                         rot == Rot4.South ? -thing.Position.z :
                         rot == Rot4.East ? thing.Position.x :
                         -thing.Position.x
                         );

            foreach (var v in list)
            {
                ThingWithComps thing = v as ThingWithComps;
                if (thing == null)
                {
                    continue;
                }

                if (parent.Rotation.IsHorizontal && !MathHelper.IsBetween(thing.Position.x, parent.Position.x, chamber.Position.x))
                {
                    continue;
                }
                if (!parent.Rotation.IsHorizontal && !MathHelper.IsBetween(thing.Position.z, parent.Position.z, chamber.Position.z))
                {
                    continue;
                }
                yield return(thing);
            }

            yield break;
        }
        public override void PostDraw()
        {
            Chamber chamber = parent.Linked <Chamber>();

            if (chamber == null)
            {
                return;
            }

            updateValues();

            if (unfilledMat == null)
            {
                unfilledMat = SolidColorMaterials.SimpleSolidColorMaterial(new Color(107 / 255f, 107 / 255f, 107 / 255f), false);
                filledMat   = new Material[] {
                    SolidColorMaterials.SimpleSolidColorMaterial(new Color(255 / 255f, 110 / 255f, 26 / 255f), false),
                    SolidColorMaterials.SimpleSolidColorMaterial(new Color(29 / 255f, 179 / 255f, 139 / 255f), false),
                    SolidColorMaterials.SimpleSolidColorMaterial(new Color(169 / 255f, 58 / 255f, 255 / 255f), false),
                };
            }

            for (int i = 0; i < 3; i++)
            {
                GenDraw.FillableBarRequest r = default(GenDraw.FillableBarRequest);
                r.center      = parent.DrawPos + new Vector3((-8f + 14 * i) / 64, 0.1f, -4f / 64);
                r.size        = barSize;
                r.fillPercent = values[i];
                r.filledMat   = filledMat[i];
                r.unfilledMat = unfilledMat;
                r.margin      = 0;
                r.rotation    = Rot4.West;
                GenDraw.DrawFillableBar(r);
            }
        }
示例#3
0
        void assignAllParts()
        {
            allParts.Clear();

            List <Thing> irradiators = facility.LinkedBuildings();
            Building     building    = irradiators.FirstOrDefault(x => (x as Building).GetComp <CompIrradiator>() != null) as Building;

            if (building == null)
            {
                return;
            }

            CompIrradiator comp    = building.GetComp <CompIrradiator>();
            Chamber        chamber = comp.parent.Linked <Chamber>();

            if (chamber == null)
            {
                return;
            }

            var partsThatCanBeIrradiated       = chamber.def.bodyParts.Select(x => x.part);
            IEnumerable <BodyPartRecord> parts = bodyDef.AllParts.Where(x => partsThatCanBeIrradiated.Contains(x.def));

            foreach (var v in parts)
            {
                allParts.Add(v);
            }
        }
示例#4
0
        public BodyPartRecord GetBodyPart(Chamber chamber, Pawn pawn)
        {
            if (pawn == null)
            {
                return(null);
            }

            return(pawn.health.hediffSet.GetNotMissingParts().RandomElementByWeight(x => chamber.def.GetPartWeight(pawn, x)));
        }
        bool CheckJob(Pawn pawn, Thing t, bool forced, out Chamber chamberRef, ref string reason)
        {
            Pawn prisoner = t as Pawn;

            chamberRef = null;

            if (!prisoner.IsPrisoner)
            {
                return(false);
            }

            if (!prisoner.Awake())
            {
                reason = reasonSleeping;
                return(false);
            }

            if (prisoner.Downed)
            {
                reason = reasonDowned;
                return(false);
            }

            if (!ShouldTakeCareOfPrisoner(pawn, prisoner))
            {
                reason = reasonPrisonerInaccessible;
                return(false);
            }

            if (prisoner.CurJob != null && prisoner.CurJob.GetCachedDriver(prisoner) is IPrisonerAllowedJob)
            {
                return(false);
            }

            foreach (Chamber chamber in pawn.Map.listerBuildings.AllBuildingsColonistOfClass <Chamber>())
            {
                string currentReason = chamber.CanIrradiateNow(prisoner);
                if (currentReason == null && pawn.CanReserve(chamber, 1, -1, null, forced))
                {
                    chamberRef = chamber;
                    return(true);
                }

                reason = reason ?? currentReason;
            }

            return(false);
        }
示例#6
0
        IEnumerable <T> GetModifiers <T, X>(Chamber chamber) where X : class where T : ThingComp
        {
            foreach (ThingWithComps thing in GetFacilitiesBetweenThisAndChamber(chamber))
            {
                foreach (T comp in thing.GetComps <T>())
                {
                    X x = comp as X;
                    if (x != null)
                    {
                        yield return(comp);
                    }
                }
            }

            yield break;
        }
示例#7
0
        public bool IsHealthyEnoughForIrradiation(Chamber chamber, Pawn pawn)
        {
            var pawnParts = pawn.health.hediffSet.GetNotMissingParts();
            var parts     = chamber.def.bodyParts.Join(pawnParts, left => left.part, right => right.def, (left, right) => right);

            foreach (var part in parts)
            {
                float health = PawnCapacityUtility.CalculatePartEfficiency(pawn.health.hediffSet, part, false, null);
                if (health < damageThreshold)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#8
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(false);
            }

            Chamber chamber = t as Chamber;

            if (chamber == null)
            {
                return(false);
            }

            string reason = chamber.CanIrradiateNow(pawn);

            if (reason != null)
            {
                JobFailReason.Is(string.Format(reason.Translate(), pawn.Name), null);
                return(false);
            }

            if (chamber.IsForbidden(pawn))
            {
                return(false);
            }
            if (!chamber.AssignedAnything(pawn))
            {
                return(false);
            }

            LocalTargetInfo target = chamber;

            if (!pawn.CanReserve(target, 1, -1, null, forced))
            {
                return(false);
            }

            return(true);
        }
示例#9
0
        public HediffRadiation GetHediffRadition(BodyPartRecord part, Chamber chamber, Pawn pawn)
        {
            if (part == null)
            {
                return(null);
            }

            foreach (var v in pawn.health.hediffSet.GetHediffs <HediffRadiation>())
            {
                if (v.Part == part)
                {
                    return(v);
                }
            }
            HediffRadiation hediff = HediffMaker.MakeHediff(HediffDefOf.RadiologyRadiation, pawn, part) as HediffRadiation;

            if (hediff == null)
            {
                return(hediff);
            }

            pawn.health.AddHediff(hediff, null, null, null);
            return(hediff);
        }
        void updateValues()
        {
            Chamber chamber = parent.Linked <Chamber>();

            if (chamber == null)
            {
                values[0] = values[0] * 0.9f;
                values[1] = values[1] * 0.9f;
                values[2] = values[2] * 0.9f;
                return;
            }

            var tr  = chamber.radiationTracker;
            var sum = tr.burn + tr.normal + tr.rare;

            if (sum == 0)
            {
                sum = 1;
            }

            values[0] = tr.burn / sum;
            values[1] = tr.normal / sum;
            values[2] = tr.rare / sum;
        }
示例#11
0
        public void Irradiate(RadiationInfo info, int ticks)
        {
            Chamber chamber = parent.Linked <Chamber>();

            SoundDefOf.RadiologyIrradiateBasic.PlayOneShot(new TargetInfo(parent.Position, parent.Map, false));
            ticksCooldown = ticks;

            if (info.pawn.IsShielded())
            {
                return;
            }

            info.part   = GetBodyPart(info.chamber, info.pawn);
            info.burn   = props.burn.perSecond.RandomInRange;
            info.normal = props.mutate.perSecond.RandomInRange;
            info.rare   = props.mutateRare.perSecond.RandomInRange;
            if (info.secondHand)
            {
                info.rare /= 2;
            }

            motesReflectAt.Clear();
            foreach (ThingComp comp in GetModifiers <ThingComp, IRadiationModifier>(info.chamber))
            {
                if (comp is CompBlocker)
                {
                    motesReflectAt.Add((parent.Rotation.IsHorizontal ? comp.parent.Position.x : comp.parent.Position.z) + 0.5f);
                }

                if (info.secondHand)
                {
                    continue;
                }

                IRadiationModifier modifier = comp as IRadiationModifier;
                modifier.Modify(ref info);
            }

            if (info.burn <= 0 && info.normal <= 0 && info.rare <= 0)
            {
                return;
            }

            HediffRadiation radiation = GetHediffRadition(info.part, info.chamber, info.pawn);

            if (radiation == null)
            {
                return;
            }

            radiation.burn   += info.burn;
            radiation.normal += info.normal;
            radiation.rare   += info.rare;

            float burnThreshold = info.chamber.def.burnThreshold.RandomInRange;
            float burnAmount    = radiation.burn - burnThreshold;

            if (burnAmount > 0)
            {
                radiation.burn -= info.chamber.def.burnThreshold.min;

                DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, burnAmount * props.burn.multiplier, 999999f, -1f, info.chamber, radiation.Part, null, DamageInfo.SourceCategory.ThingOrUnknown, null);
                info.pawn.TakeDamage(dinfo);

                if (chamber != null)
                {
                    RadiologyEffectSpawnerDef.Spawn(chamber.def.burnEffect, info.pawn);
                }
            }

            float mutateThreshold = info.chamber.def.mutateThreshold.RandomInRange;
            float mutateAmount    = radiation.normal + radiation.rare - mutateThreshold;

            if (mutateAmount > 0)
            {
                float ratio = radiation.rare / (radiation.normal + radiation.rare);
                radiation.rare   -= info.chamber.def.mutateThreshold.min * ratio;
                radiation.normal -= info.chamber.def.mutateThreshold.min * (1f - ratio);

                Mutation mutation;
                var      mutatedParts = RadiationHelper.MutatePawn(info.pawn, radiation, mutateAmount * props.mutate.multiplier, ratio, out mutation);
                if (mutatedParts != null)
                {
                    foreach (var anotherRadiation in info.pawn.health.hediffSet.GetHediffs <HediffRadiation>())
                    {
                        if (mutatedParts.Contains(anotherRadiation.Part) && radiation != anotherRadiation)
                        {
                            anotherRadiation.normal -= info.chamber.def.mutateThreshold.min * (1f - ratio);
                            anotherRadiation.rare   -= info.chamber.def.mutateThreshold.min * ratio;
                        }
                    }
                }
            }
        }
示例#12
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            if (parent.Faction != Faction.OfPlayer)
            {
                yield break;
            }

            yield return(new Command_Action
            {
                defaultLabel = "burn",
                defaultDesc = "Play the burn effect.",
                icon = ContentFinder <Texture2D> .Get("Radiology/Effects/Burn", true),
                action = delegate()
                {
                    Chamber chamber = parent.Linked <Chamber>();
                    if (chamber != null && chamber.def.burnEffect != null)
                    {
                        chamber.def.burnEffect.Spawn(parent.Map, parent.Position.ToVector3());
                    }
                },
                hotKey = KeyBindingDefOf.Misc3
            });

            yield return(new Command_Action
            {
                defaultLabel = "mutate",
                defaultDesc = "Play the mutate effect.",
                icon = ContentFinder <Texture2D> .Get("Radiology/Effects/Mutate", true),
                action = delegate()
                {
                    if (HediffDefOf.MutationFastLegs.spawnEffect != null)
                    {
                        HediffDefOf.MutationFastLegs.spawnEffect.Spawn(parent.Map, parent.Position.ToVector3());
                    }
                },
                hotKey = KeyBindingDefOf.Misc3
            });

            yield return(new Command_Action
            {
                defaultLabel = "cancer male",
                defaultDesc = "Play the cancer male effect.",
                icon = ContentFinder <Texture2D> .Get("Radiology/Effects/Cancer", true),
                action = delegate()
                {
                    Chamber chamber = parent.Linked <Chamber>();
                    if (HediffDefOf.RadiologyCancer.spawnEffect != null)
                    {
                        HediffDefOf.RadiologyCancer.spawnEffect.Spawn(parent.Map, parent.Position.ToVector3());
                    }
                },
                hotKey = KeyBindingDefOf.Misc3
            });

            yield return(new Command_Action
            {
                defaultLabel = "cancer female",
                defaultDesc = "Play the cancer female effect.",
                icon = ContentFinder <Texture2D> .Get("Radiology/Effects/Cancer", true),
                action = delegate()
                {
                    if (HediffDefOf.RadiologyCancer.spawnEffectFemale != null)
                    {
                        HediffDefOf.RadiologyCancer.spawnEffectFemale.Spawn(parent.Map, parent.Position.ToVector3());
                    }
                },
                hotKey = KeyBindingDefOf.Misc3
            });


            yield break;
        }
示例#13
0
 void updateValues()
 {
     chamber = parent.Linked <Chamber>();
 }