private static void CheckBodyForAddedParts(Hediff hediff, CompBodyAnimator anim, BodyPartRecord leftHand,
                                                   BodyPartRecord rightHand, BodyPartRecord leftFoot, BodyPartRecord rightFoot)
        {
            if (anim == null)
            {
                return;
            }

            if (anim.Props.bipedWithHands)
            {
                if (hediff.Part.parts.Contains(leftHand))
                {
                    anim.BodyStat.HandLeft = PartStatus.Artificial;
                }

                if (hediff.Part.parts.Contains(rightHand))
                {
                    anim.BodyStat.HandRight = PartStatus.Artificial;
                }
            }

            if (hediff.Part.parts.Contains(leftFoot))
            {
                anim.BodyStat.FootLeft = PartStatus.Artificial;
            }

            if (hediff.Part.parts.Contains(rightFoot))
            {
                anim.BodyStat.FootRight = PartStatus.Artificial;
            }
        }
        public override Quaternion QuatHead(Rot4 rotation)
        {
            float      num    = 1f;
            Quaternion asQuat = rotation.AsQuat;
            float      x      =
                1f * Mathf.Sin(num * (this.CompFace.HeadRotator.CurrentMovement * 0.1f) % (2 * Mathf.PI));
            float z =
                1f * Mathf.Cos(num * (this.CompFace.HeadRotator.CurrentMovement * 0.1f) % (2 * Mathf.PI));

            asQuat.SetLookRotation(new Vector3(x, 0f, z), Vector3.up);
            return(asQuat);

            // remove the body rotation
            CompBodyAnimator animator = this.CompAnimator;

            if (animator != null && (animator.IsMoving && Controller.settings.UseFeet))
            {
                WalkCycleDef walkCycle = this.CompAnimator?.WalkCycle;
                if (this.BodyFacing.IsHorizontal)
                {
                    asQuat *= Quaternion.AngleAxis(
                        (this.BodyFacing == Rot4.West ? 1 : -1)
                        * walkCycle?.BodyAngle.Evaluate(this.CompAnimator.MovedPercent) ?? 0f,
                        Vector3.up);
                }

                asQuat *= Quaternion.AngleAxis(
                    (this.BodyFacing == Rot4.South ? 1 : -1)
                    * walkCycle?.BodyAngleVertical
                    .Evaluate(this.CompAnimator.MovedPercent) ?? 0f,
                    Vector3.up);
            }

            return(asQuat);
        }
Beispiel #3
0
        private static void CheckBodyForAddedParts(Hediff hediff, CompBodyAnimator anim, BodyPartRecord leftHand,
                                                   BodyPartRecord rightHand, BodyPartRecord leftFoot, BodyPartRecord rightFoot)
        {
            Log.Message("Checking wether the colonist is ok or not");

            if (anim == null)
            {
                return;
            }

            if (anim.Props.bipedWithHands)
            {
                Log.Message("We've got one with hands");

                if (hediff.Part.parts.Contains(leftHand))
                {
                    anim.BodyStat.HandLeft = PartStatus.Artificial;
                }

                if (hediff.Part.parts.Contains(rightHand))
                {
                    anim.BodyStat.HandRight = PartStatus.Artificial;
                }
            }

            if (hediff.Part.parts.Contains(leftFoot))
            {
                anim.BodyStat.FootLeft = PartStatus.Artificial;
            }

            if (hediff.Part.parts.Contains(rightFoot))
            {
                anim.BodyStat.FootRight = PartStatus.Artificial;
            }
        }
Beispiel #4
0
        private static void CheckPart(List <BodyPartRecord> body, Hediff hediff, [CanBeNull] CompFace face,
                                      [CanBeNull]                                           CompBodyAnimator anim, bool missing)
        {
            if (body.NullOrEmpty() || hediff.def == null)
            {
                Log.Message("Body list or hediff.def is null or empty");
                return;
            }

            if (!hediff.Visible)
            {
                return;
            }

            BodyPartRecord leftEye  = body.Find(x => x.def == BodyPartDefOf.Eye && x.customLabel.Contains("left"));
            BodyPartRecord rightEye = body.Find(x => x.def == BodyPartDefOf.Eye && x.customLabel.Contains("right"));
            BodyPartRecord jaw      = body.Find(x => x.def == BodyPartDefOf.Jaw);


            //BodyPartRecord leftArm = body.Find(x => x.def == BodyPartDefOf.LeftArm);
            //BodyPartRecord rightArm = body.Find(x => x.def == DefDatabase<BodyPartDef>.GetNamed("RightShoulder"));
            BodyPartRecord leftHand  = body.Find(x => x.def == BodyPartDefOf.Hand && x.customLabel.Contains("left"));
            BodyPartRecord rightHand = body.Find(x => x.def == BodyPartDefOf.Hand && x.customLabel.Contains("right"));

            BodyPartRecord leftFoot  = body.Find(x => x.def == DefDatabase <BodyPartDef> .GetNamed("Foot") && x.customLabel.Contains("left"));
            BodyPartRecord rightFoot = body.Find(x => x.def == DefDatabase <BodyPartDef> .GetNamed("Foot") && x.customLabel.Contains("right"));

            if (missing)
            {
                CheckMissingParts(new BodyProps(hediff, face, anim, leftEye, rightEye, leftHand, rightHand, leftFoot,
                                                rightFoot));
                return;
            }

            // Missing parts first, hands and feet can be replaced by arms/legs
            //  Log.Message("Checking missing parts.");
            AddedBodyPartProps addedPartProps = hediff.def?.addedPartProps;

            if (addedPartProps == null)
            {
                //    Log.Message("No added parts found.");
                return;
            }

            if (hediff.def?.defName == null)
            {
                return;
            }

            //  Log.Message("Checking face for added parts.");
            if (anim != null && anim.Pawn.RaceProps.Humanlike && face != null)
            {
                CheckFaceForAddedParts(hediff, face, leftEye, rightEye, jaw);
            }

            //  Log.Message("Checking body for added parts.");

            CheckBodyForAddedParts(hediff, anim, leftHand, rightHand, leftFoot, rightFoot);
        }
 public BodyProps(Hediff hediff, CompFace face, CompBodyAnimator anim, BodyPartRecord leftEye, BodyPartRecord rightEye, BodyPartRecord leftHand, BodyPartRecord rightHand, BodyPartRecord leftFoot, BodyPartRecord rightFoot)
 {
     this._hediff    = hediff;
     this._face      = face;
     this._anim      = anim;
     this._leftEye   = leftEye;
     this._rightEye  = rightEye;
     this._leftHand  = leftHand;
     this._rightHand = rightHand;
     this._leftFoot  = leftFoot;
     this._rightFoot = rightFoot;
 }
        public override void Tick(Rot4 bodyFacing, Rot4 headFacing, PawnGraphicSet graphics)
        {
            base.Tick(bodyFacing, headFacing, graphics);

            CompBodyAnimator animator = this.CompAnimator;

            if (animator == null)
            {
            }

            // var curve = bodyFacing.IsHorizontal ? this.walkCycle.BodyOffsetZ : this.walkCycle.BodyOffsetVerticalZ;
        }
        public override void BaseHeadOffsetAt(ref Vector3 offset, bool portrait)
        {
            Pawn    pawn          = this.Pawn;
            Vector2 headOffset    = pawn.story.bodyType.headOffset;
            float   horHeadOffset = headOffset.x;
            float   verHeadOffset = headOffset.y;

            CompBodyAnimator animator = this.CompAnimator;

            if (animator != null && MainTabWindow_PoseAnimator.IsOpen)
            {
                horHeadOffset += MainTabWindow_WalkAnimator.HorHeadOffset;
                verHeadOffset += MainTabWindow_WalkAnimator.VerHeadOffset;
            }

            switch (this.BodyFacing.AsInt)
            {
            case 0:
                offset = new Vector3(0f, 0f, verHeadOffset);
                break;

            case 1:
                offset = new Vector3(horHeadOffset, 0f, verHeadOffset);
                break;

            case 2:
                offset = new Vector3(0f, 0f, verHeadOffset);
                break;

            case 3:
                offset = new Vector3(-horHeadOffset, 0f, verHeadOffset);
                break;

            default:
                Log.Error("BaseHeadOffsetAt error in " + pawn);
                offset = Vector3.zero;
                return;
            }

            if (!portrait)
            {
                CompBodyAnimator bodyAnimator = this.CompAnimator;
                if (bodyAnimator != null && bodyAnimator.IsMoving)
                {
                    // Let's try a slightly stiffy head
                    CompBodyAnimator compAnimator = this.CompAnimator;
                    if (compAnimator != null)
                    {
                        offset.z -= 0.25f * compAnimator.BodyOffsetZ;
                    }
                }
            }
        }
        public override void BaseHeadOffsetAt(ref Vector3 offset, bool portrait, Pawn pawn1)
        {
            Pawn    pawn          = this.Pawn;
            Vector2 headOffset    = pawn.story.bodyType.headOffset;
            float   horHeadOffset = headOffset.x;
            float   verHeadOffset = headOffset.y;

            CompBodyAnimator animator = this.CompAnimator;

            if (animator.BodyAnim != null)
            {
                horHeadOffset += animator.BodyAnim.headOffset.x;
                verHeadOffset += animator.BodyAnim.headOffset.y;
            }

            switch (this.BodyFacing.AsInt)
            {
            case 0:
                offset = new Vector3(0f, 0f, verHeadOffset);
                break;

            case 1:
                offset = new Vector3(horHeadOffset, 0f, verHeadOffset);
                break;

            case 2:
                offset = new Vector3(0f, 0f, verHeadOffset);
                break;

            case 3:
                offset = new Vector3(-horHeadOffset, 0f, verHeadOffset);
                break;

            default:
                Log.Error("BaseHeadOffsetAt error in " + pawn);
                offset = Vector3.zero;
                return;
            }

            if (!portrait || HarmonyPatchesFS.AnimatorIsOpen())
            {
                CompBodyAnimator bodyAnimator = this.CompAnimator;
                if (bodyAnimator != null && (bodyAnimator.IsMoving || HarmonyPatchesFS.AnimatorIsOpen()))
                {
                    // Let's try a slightly stiffy head
                    {
                        offset.z -= 0.25f * bodyAnimator.BodyOffsetZ;
                        offset.z += bodyAnimator.HeadffsetZ;
                    }
                }
            }
        }
Beispiel #9
0
        private static void CheckMissingParts(Hediff hediff, CompFace face, CompBodyAnimator anim,
                                              BodyPartRecord leftEye,
                                              BodyPartRecord rightEye, BodyPartRecord leftHand,
                                              BodyPartRecord rightHand,
                                              BodyPartRecord leftFoot, BodyPartRecord rightFoot)
        {
            if (hediff.def == HediffDefOf.MissingBodyPart)
            {
                if (face != null && face.Props.hasEyes)
                {
                    if (leftEye != null && hediff.Part == leftEye)
                    {
                        face.BodyStat.EyeLeft = PartStatus.Missing;
                        face.TexPathEyeLeft   = face.EyeTexPath(Side.Left, EyeDefOf.Missing);
                    }

                    // ReSharper disable once InvertIf
                    if (rightEye != null && hediff.Part == rightEye)
                    {
                        face.BodyStat.EyeRight = PartStatus.Missing;
                        face.TexPathEyeRight   = face.EyeTexPath(Side.Right, EyeDefOf.Missing);
                    }
                }

                if (anim != null && anim.Props.bipedWithHands)
                {
                    if (hediff.Part == leftHand)
                    {
                        anim.BodyStat.HandLeft = PartStatus.Missing;
                    }

                    if (hediff.Part == rightHand)
                    {
                        anim.BodyStat.HandRight = PartStatus.Missing;
                    }

                    if (hediff.Part == leftFoot)
                    {
                        anim.BodyStat.FootLeft = PartStatus.Missing;
                    }

                    if (hediff.Part == rightFoot)
                    {
                        anim.BodyStat.FootRight = PartStatus.Missing;
                    }
                }
            }
        }
Beispiel #10
0
        private static void CheckPart(List <BodyPartRecord> body, Hediff hediff, [CanBeNull] CompFace face,
                                      [CanBeNull]                                           CompBodyAnimator anim)
        {
            if (body.NullOrEmpty() || hediff.def == null)
            {
                return;
            }

            if (!hediff.Visible)
            {
                return;
            }

            BodyPartRecord leftEye  = body.Find(x => x.def == BodyPartDefOf.LeftEye);
            BodyPartRecord rightEye = body.Find(x => x.def == BodyPartDefOf.RightEye);
            BodyPartRecord jaw      = body.Find(x => x.def == BodyPartDefOf.Jaw);


            BodyPartRecord leftArm   = body.Find(x => x.def == BodyPartDefOf.LeftArm);
            BodyPartRecord rightArm  = body.Find(x => x.def == DefDatabase <BodyPartDef> .GetNamed("RightShoulder"));
            BodyPartRecord leftHand  = body.Find(x => x.def == DefDatabase <BodyPartDef> .GetNamed("LeftShoulder"));
            BodyPartRecord rightHand = body.Find(x => x.def == BodyPartDefOf.RightHand);
            BodyPartRecord leftLeg   = body.Find(x => x.def == BodyPartDefOf.LeftLeg);
            BodyPartRecord rightLeg  = body.Find(x => x.def == BodyPartDefOf.RightLeg);
            BodyPartRecord leftFoot  = body.Find(x => x.def == DefDatabase <BodyPartDef> .GetNamed("LeftFoot"));
            BodyPartRecord rightFoot = body.Find(x => x.def == DefDatabase <BodyPartDef> .GetNamed("RightFoot"));


            // Missing parts first, hands and feet can be replaced by arms/legs
            CheckMissingParts(hediff, face, anim, leftEye, rightEye, leftHand, rightHand, leftFoot, rightFoot);

            AddedBodyPartProps addedPartProps = hediff.def?.addedPartProps;

            if (addedPartProps == null)
            {
                return;
            }

            if (hediff.def?.defName == null || hediff.Part.parts.NullOrEmpty())
            {
                return;
            }

            CheckFace(hediff, face, leftEye, rightEye, jaw);

            CheckBody(hediff, anim, leftHand, rightHand, leftFoot, rightFoot);
        }
 public static bool GetCompAnim([NotNull] this Pawn pawn, [NotNull] out CompBodyAnimator compAnim)
 {
     compAnim = pawn.GetComp <CompBodyAnimator>();
     return(compAnim != null);
 }
        public override void DrawHairAndHeadGear(Vector3 hairLoc, Vector3 headgearLoc,
                                                 RotDrawMode bodyDrawType,
                                                 Quaternion headQuat,
                                                 bool renderBody,
                                                 bool portrait, Vector3 hatInFrontOfFace)
        {
            Mesh hairMesh = this.GetPawnHairMesh(portrait);
            List <ApparelGraphicRecord> apparelGraphics  = this.Graphics.apparelGraphics;
            List <ApparelGraphicRecord> headgearGraphics = null;

            if (!apparelGraphics.NullOrEmpty())
            {
                headgearGraphics = apparelGraphics
                                   .Where(x => x.sourceApparel.def.apparel.LastLayer == ApparelLayerDefOf.Overhead ||
                                          x.sourceApparel.def.apparel.LastLayer == DefDatabase <ApparelLayerDef> .GetNamedSilentFail("OnHead") ||
                                          x.sourceApparel.def.apparel.LastLayer == DefDatabase <ApparelLayerDef> .GetNamedSilentFail("StrappedHead") ||
                                          x.sourceApparel.def.apparel.LastLayer == DefDatabase <ApparelLayerDef> .GetNamedSilentFail("MiddleHead")).ToList();
            }

            CompBodyAnimator animator = this.CompAnimator;

            bool noRenderGoggles = Controller.settings.FilterHats;

            bool showRoyalHeadgear = this.Pawn.royalty?.MostSeniorTitle != null && Controller.settings.ShowRoyalHeadgear;
            bool noRenderRoofed    = animator != null && animator.HideHat && !showRoyalHeadgear;
            bool noRenderBed       = Controller.settings.HideHatInBed && !renderBody && !showRoyalHeadgear;

            if (!headgearGraphics.NullOrEmpty())
            {
                bool filterHeadgear = portrait && Prefs.HatsOnlyOnMap || !portrait && noRenderRoofed;

                // Draw regular hair if appparel or environment allows it (FS feature)
                if (bodyDrawType != RotDrawMode.Dessicated)
                {
                    // draw full or partial hair
                    bool apCoversFullHead =
                        headgearGraphics.Any(
                            x => x.sourceApparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf
                                                                                     .FullHead) &&
                            !x.sourceApparel.def.apparel.hatRenderedFrontOfFace);

                    bool apCoversUpperHead =
                        headgearGraphics.Any(
                            x => x.sourceApparel.def.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf
                                                                                     .UpperHead) &&
                            !x.sourceApparel.def.apparel.hatRenderedFrontOfFace);

                    if (this.CompFace.Props.hasOrganicHair || noRenderBed || filterHeadgear ||
                        (!apCoversFullHead && !apCoversUpperHead && noRenderGoggles))
                    {
                        Material mat = this.Graphics.HairMatAt(this.HeadFacing);
                        GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, mat, portrait);
                    }
                    else if (Controller.settings.MergeHair) // && !apCoversFullHead)
                    {
                        // If not, display the hair cut
                        HairCutPawn hairPawn   = CutHairDB.GetHairCache(this.Pawn);
                        Material    hairCutMat = hairPawn.HairCutMatAt(this.HeadFacing);
                        if (hairCutMat != null)
                        {
                            GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, hairCutMat, portrait);
                        }
                    }
                }
                else
                {
                    filterHeadgear = false;
                }

                if (filterHeadgear)
                {
                    // Filter the head gear to only show non-hats, show nothing while in bed
                    if (noRenderGoggles)
                    {
                        headgearGraphics = headgearGraphics
                                           .Where(
                            x =>
                            !x.sourceApparel.def.apparel.bodyPartGroups
                            .Contains(BodyPartGroupDefOf.FullHead) &&
                            !x.sourceApparel.def.apparel.bodyPartGroups.Contains(
                                BodyPartGroupDefOf
                                .UpperHead))
                                           .ToList();
                    }
                    else
                    {
                        // Clear if nothing to show
                        headgearGraphics?.Clear();
                    }
                }

                if (noRenderBed && !showRoyalHeadgear)
                {
                    headgearGraphics?.Clear();
                }

                // headgearGraphics = headgearGraphics
                // .OrderBy(x => x.sourceApparel.def.apparel.bodyPartGroups.Max(y => y.listOrder)).ToList();
                if (headgearGraphics.NullOrEmpty())
                {
                    return;
                }

                for (int index = 0; index < headgearGraphics?.Count; index++)
                {
                    ApparelGraphicRecord headgearGraphic = headgearGraphics[index];
                    Material             headGearMat     = headgearGraphic.graphic.MatAt(this.HeadFacing);
                    headGearMat = this.Graphics.flasher.GetDamagedMat(headGearMat);

                    if (headgearGraphic.sourceApparel.def.apparel.hatRenderedFrontOfFace)
                    {
                        headgearLoc = hatInFrontOfFace;
                    }

                    GenDraw.DrawMeshNowOrLater(hairMesh, headgearLoc, headQuat, headGearMat, portrait);
                    headgearLoc.y += Offsets.YOffsetInterval_Clothes;
                }
            }
            else
            {
                // Draw regular hair if no hat worn
                if (bodyDrawType != RotDrawMode.Dessicated)
                {
                    Material hairMat = this.Graphics.HairMatAt(this.HeadFacing);
                    GenDraw.DrawMeshNowOrLater(hairMesh, hairLoc, headQuat, hairMat, portrait);
                }
            }
        }