private static int GetDamageOverlaysCount(Building b, int hp)
        {
            float num   = (float)hp / (float)b.MaxHitPoints;
            int   count = BuildingsDamageSectionLayerUtility.GetAvailableOverlays(b).Count;

            return(count - Mathf.FloorToInt((float)count * num));
        }
        public static List <DamageOverlay> GetOverlays(Building b)
        {
            BuildingsDamageSectionLayerUtility.overlays.Clear();
            BuildingsDamageSectionLayerUtility.overlaysWorkingList.Clear();
            BuildingsDamageSectionLayerUtility.overlaysWorkingList.AddRange(BuildingsDamageSectionLayerUtility.GetAvailableOverlays(b));
            if (!BuildingsDamageSectionLayerUtility.overlaysWorkingList.Any <DamageOverlay>())
            {
                return(BuildingsDamageSectionLayerUtility.overlays);
            }
            Rand.PushState();
            Rand.Seed = Gen.HashCombineInt(b.thingIDNumber, 1958376471);
            int damageOverlaysCount = BuildingsDamageSectionLayerUtility.GetDamageOverlaysCount(b, b.HitPoints);

            for (int i = 0; i < damageOverlaysCount; i++)
            {
                if (!BuildingsDamageSectionLayerUtility.overlaysWorkingList.Any <DamageOverlay>())
                {
                    break;
                }
                DamageOverlay item = BuildingsDamageSectionLayerUtility.overlaysWorkingList.RandomElement <DamageOverlay>();
                BuildingsDamageSectionLayerUtility.overlaysWorkingList.Remove(item);
                BuildingsDamageSectionLayerUtility.overlays.Add(item);
            }
            Rand.PopState();
            return(BuildingsDamageSectionLayerUtility.overlays);
        }
        private void DrawLinkableCornersAndEdges(Building b)
        {
            if (b.def.graphicData == null)
            {
                return;
            }
            DamageGraphicData damageData = b.def.graphicData.damageData;

            if (damageData == null)
            {
                return;
            }
            float damageTexturesAltitude  = GetDamageTexturesAltitude(b);
            List <DamageOverlay> overlays = BuildingsDamageSectionLayerUtility.GetOverlays(b);
            IntVec3 position = b.Position;
            Vector3 vector   = new Vector3((float)position.x + 0.5f, damageTexturesAltitude, (float)position.z + 0.5f);
            float   x        = Rand.Range(0.4f, 0.6f);
            float   z        = Rand.Range(0.4f, 0.6f);
            float   x2       = Rand.Range(0.4f, 0.6f);
            float   z2       = Rand.Range(0.4f, 0.6f);

            for (int i = 0; i < overlays.Count; i++)
            {
                switch (overlays[i])
                {
                case DamageOverlay.TopEdge:
                    Printer_Plane.PrintPlane(this, vector + new Vector3(x, 0f, 0f), Vector2.one, damageData.edgeTopMat, 0f, flipUv: false, null, null, 0f);
                    break;

                case DamageOverlay.RightEdge:
                    Printer_Plane.PrintPlane(this, vector + new Vector3(0f, 0f, z), Vector2.one, damageData.edgeRightMat, 90f, flipUv: false, null, null, 0f);
                    break;

                case DamageOverlay.BotEdge:
                    Printer_Plane.PrintPlane(this, vector + new Vector3(x2, 0f, 0f), Vector2.one, damageData.edgeBotMat, 180f, flipUv: false, null, null, 0f);
                    break;

                case DamageOverlay.LeftEdge:
                    Printer_Plane.PrintPlane(this, vector + new Vector3(0f, 0f, z2), Vector2.one, damageData.edgeLeftMat, 270f, flipUv: false, null, null, 0f);
                    break;

                case DamageOverlay.TopLeftCorner:
                    Printer_Plane.PrintPlane(this, vector, Vector2.one, damageData.cornerTLMat, 0f, flipUv: false, null, null, 0f);
                    break;

                case DamageOverlay.TopRightCorner:
                    Printer_Plane.PrintPlane(this, vector, Vector2.one, damageData.cornerTRMat, 90f, flipUv: false, null, null, 0f);
                    break;

                case DamageOverlay.BotRightCorner:
                    Printer_Plane.PrintPlane(this, vector, Vector2.one, damageData.cornerBRMat, 180f, flipUv: false, null, null, 0f);
                    break;

                case DamageOverlay.BotLeftCorner:
                    Printer_Plane.PrintPlane(this, vector, Vector2.one, damageData.cornerBLMat, 270f, flipUv: false, null, null, 0f);
                    break;
                }
            }
        }
示例#4
0
        private void DrawFullThingCorners(Building b)
        {
            if (b.def.graphicData == null)
            {
                return;
            }
            if (b.def.graphicData.damageData == null)
            {
                return;
            }
            Rect     damageRect             = BuildingsDamageSectionLayerUtility.GetDamageRect(b);
            float    damageTexturesAltitude = this.GetDamageTexturesAltitude(b);
            float    num = Mathf.Min(Mathf.Min(damageRect.width, damageRect.height), 1.5f);
            Material mat;
            Material mat2;
            Material mat3;
            Material mat4;

            BuildingsDamageSectionLayerUtility.GetCornerMats(out mat, out mat2, out mat3, out mat4, b);
            float num2 = num * Rand.Range(0.9f, 1f);
            float num3 = num * Rand.Range(0.9f, 1f);
            float num4 = num * Rand.Range(0.9f, 1f);
            float num5 = num * Rand.Range(0.9f, 1f);
            List <DamageOverlay> overlays = BuildingsDamageSectionLayerUtility.GetOverlays(b);

            for (int i = 0; i < overlays.Count; i++)
            {
                switch (overlays[i])
                {
                case DamageOverlay.TopLeftCorner:
                {
                    Rect rect = new Rect(damageRect.xMin, damageRect.yMax - num2, num2, num2);
                    Printer_Plane.PrintPlane(this, new Vector3(rect.center.x, damageTexturesAltitude, rect.center.y), rect.size, mat, 0f, false, null, null, 0f, 0f);
                    break;
                }

                case DamageOverlay.TopRightCorner:
                {
                    Rect rect2 = new Rect(damageRect.xMax - num3, damageRect.yMax - num3, num3, num3);
                    Printer_Plane.PrintPlane(this, new Vector3(rect2.center.x, damageTexturesAltitude, rect2.center.y), rect2.size, mat2, 90f, false, null, null, 0f, 0f);
                    break;
                }

                case DamageOverlay.BotLeftCorner:
                {
                    Rect rect3 = new Rect(damageRect.xMin, damageRect.yMin, num5, num5);
                    Printer_Plane.PrintPlane(this, new Vector3(rect3.center.x, damageTexturesAltitude, rect3.center.y), rect3.size, mat4, 270f, false, null, null, 0f, 0f);
                    break;
                }

                case DamageOverlay.BotRightCorner:
                {
                    Rect rect4 = new Rect(damageRect.xMax - num4, damageRect.yMin, num4, num4);
                    Printer_Plane.PrintPlane(this, new Vector3(rect4.center.x, damageTexturesAltitude, rect4.center.y), rect4.size, mat3, 180f, false, null, null, 0f, 0f);
                    break;
                }
                }
            }
        }
        private void PrintScratches(Building b)
        {
            int num = 0;
            List <DamageOverlay> overlays = BuildingsDamageSectionLayerUtility.GetOverlays(b);

            for (int i = 0; i < overlays.Count; i++)
            {
                if (overlays[i] == DamageOverlay.Scratch)
                {
                    num++;
                }
            }
            if (num == 0)
            {
                return;
            }
            Rect  damageRect = BuildingsDamageSectionLayerUtility.GetDamageRect(b);
            float num2       = Mathf.Min(0.5f * Mathf.Min(damageRect.width, damageRect.height), 1f);

            damageRect = damageRect.ContractedBy(num2 / 2f);
            if (damageRect.width <= 0f || damageRect.height <= 0f)
            {
                return;
            }
            float minDist = Mathf.Max(damageRect.width, damageRect.height) * 0.7f;

            scratches.Clear();
            Rand.PushState();
            Rand.Seed = b.thingIDNumber * 3697;
            for (int j = 0; j < num; j++)
            {
                AddScratch(b, damageRect.width, damageRect.height, ref minDist);
            }
            Rand.PopState();
            float            damageTexturesAltitude = GetDamageTexturesAltitude(b);
            IList <Material> scratchMats            = BuildingsDamageSectionLayerUtility.GetScratchMats(b);

            Rand.PushState();
            Rand.Seed = b.thingIDNumber * 7;
            for (int k = 0; k < scratches.Count; k++)
            {
                float x    = scratches[k].x;
                float y    = scratches[k].y;
                float rot  = Rand.Range(0f, 360f);
                float num3 = num2;
                if (damageRect.width > 0.95f && damageRect.height > 0.95f)
                {
                    num3 *= Rand.Range(0.85f, 1f);
                }
                Vector3 center = new Vector3(damageRect.xMin + x, damageTexturesAltitude, damageRect.yMin + y);
                Printer_Plane.PrintPlane(this, center, new Vector2(num3, num3), scratchMats.RandomElement(), rot, flipUv: false, null, null, 0f);
            }
            Rand.PopState();
        }
示例#6
0
        private void PrintScratches(Building b)
        {
            int num = 0;
            List <DamageOverlay> overlays = BuildingsDamageSectionLayerUtility.GetOverlays(b);

            for (int i = 0; i < overlays.Count; i++)
            {
                if (overlays[i] == DamageOverlay.Scratch)
                {
                    num++;
                }
            }
            if (num != 0)
            {
                Rect  rect = BuildingsDamageSectionLayerUtility.GetDamageRect(b);
                float num2 = Mathf.Min((float)(0.5 * Mathf.Min(rect.width, rect.height)), 1f);
                rect = rect.ContractedBy((float)(num2 / 2.0));
                if (!(rect.width <= 0.0) && !(rect.height <= 0.0))
                {
                    float num3 = (float)(Mathf.Max(rect.width, rect.height) * 0.699999988079071);
                    SectionLayer_BuildingsDamage.scratches.Clear();
                    Rand.PushState();
                    Rand.Seed = b.thingIDNumber * 3697;
                    for (int j = 0; j < num; j++)
                    {
                        this.AddScratch(b, rect.width, rect.height, ref num3);
                    }
                    Rand.PopState();
                    float            damageTexturesAltitude = this.GetDamageTexturesAltitude(b);
                    IList <Material> scratchMats            = BuildingsDamageSectionLayerUtility.GetScratchMats(b);
                    Rand.PushState();
                    Rand.Seed = b.thingIDNumber * 7;
                    for (int k = 0; k < SectionLayer_BuildingsDamage.scratches.Count; k++)
                    {
                        Vector2 vector  = SectionLayer_BuildingsDamage.scratches[k];
                        float   x       = vector.x;
                        Vector2 vector2 = SectionLayer_BuildingsDamage.scratches[k];
                        float   y       = vector2.y;
                        float   rot     = Rand.Range(0f, 360f);
                        float   num4    = num2;
                        if (rect.width > 0.949999988079071 && rect.height > 0.949999988079071)
                        {
                            num4 *= Rand.Range(0.85f, 1f);
                        }
                        Vector3 center = new Vector3(rect.xMin + x, damageTexturesAltitude, rect.yMin + y);
                        Printer_Plane.PrintPlane(this, center, new Vector2(num4, num4), scratchMats.RandomElement(), rot, false, null, null, 0f);
                    }
                    Rand.PopState();
                }
            }
        }
 private void PrintCornersAndEdges(Building b)
 {
     Rand.PushState();
     Rand.Seed = b.thingIDNumber * 3;
     if (BuildingsDamageSectionLayerUtility.UsesLinkableCornersAndEdges(b))
     {
         DrawLinkableCornersAndEdges(b);
     }
     else
     {
         DrawFullThingCorners(b);
     }
     Rand.PopState();
 }
 public static List <DamageOverlay> GetAvailableOverlays(Building b)
 {
     BuildingsDamageSectionLayerUtility.availableOverlays.Clear();
     if (BuildingsDamageSectionLayerUtility.GetScratchMats(b).Any <Material>())
     {
         int   num        = 3;
         Rect  damageRect = BuildingsDamageSectionLayerUtility.GetDamageRect(b);
         float num2       = damageRect.width * damageRect.height;
         if (num2 > 4f)
         {
             num += Mathf.RoundToInt((num2 - 4f) * 0.54f);
         }
         for (int i = 0; i < num; i++)
         {
             BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.Scratch);
         }
     }
     if (BuildingsDamageSectionLayerUtility.UsesLinkableCornersAndEdges(b))
     {
         if (b.def.graphicData != null && b.def.graphicData.damageData != null)
         {
             IntVec3           position   = b.Position;
             DamageGraphicData damageData = b.def.graphicData.damageData;
             if (damageData.edgeTopMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x, position.z + 1) && BuildingsDamageSectionLayerUtility.SameAndDamagedAt(b, position.x + 1, position.z) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x + 1, position.z + 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.TopEdge);
             }
             if (damageData.edgeRightMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x + 1, position.z) && BuildingsDamageSectionLayerUtility.SameAndDamagedAt(b, position.x, position.z + 1) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x + 1, position.z + 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.RightEdge);
             }
             if (damageData.edgeBotMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x, position.z - 1) && BuildingsDamageSectionLayerUtility.SameAndDamagedAt(b, position.x + 1, position.z) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x + 1, position.z - 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.BotEdge);
             }
             if (damageData.edgeLeftMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x - 1, position.z) && BuildingsDamageSectionLayerUtility.SameAndDamagedAt(b, position.x, position.z + 1) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x - 1, position.z + 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.LeftEdge);
             }
             if (damageData.cornerTLMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x - 1, position.z) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x, position.z + 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.TopLeftCorner);
             }
             if (damageData.cornerTRMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x + 1, position.z) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x, position.z + 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.TopRightCorner);
             }
             if (damageData.cornerBRMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x + 1, position.z) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x, position.z - 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.BotRightCorner);
             }
             if (damageData.cornerBLMat != null && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x - 1, position.z) && BuildingsDamageSectionLayerUtility.DifferentAt(b, position.x, position.z - 1))
             {
                 BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.BotLeftCorner);
             }
         }
     }
     else
     {
         Material x;
         Material x2;
         Material x3;
         Material x4;
         BuildingsDamageSectionLayerUtility.GetCornerMats(out x, out x2, out x3, out x4, b);
         if (x != null)
         {
             BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.TopLeftCorner);
         }
         if (x2 != null)
         {
             BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.TopRightCorner);
         }
         if (x4 != null)
         {
             BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.BotLeftCorner);
         }
         if (x3 != null)
         {
             BuildingsDamageSectionLayerUtility.availableOverlays.Add(DamageOverlay.BotRightCorner);
         }
     }
     return(BuildingsDamageSectionLayerUtility.availableOverlays);
 }
 public static void Notify_BuildingHitPointsChanged(Building b, int oldHitPoints)
 {
     if (!b.Spawned || !b.def.useHitPoints || b.HitPoints == oldHitPoints || !b.def.drawDamagedOverlay || BuildingsDamageSectionLayerUtility.GetDamageOverlaysCount(b, b.HitPoints) == BuildingsDamageSectionLayerUtility.GetDamageOverlaysCount(b, oldHitPoints))
     {
         return;
     }
     b.Map.mapDrawer.MapMeshDirty(b.Position, MapMeshFlag.BuildingsDamage);
 }
 public static void Notify_BuildingHitPointsChanged(Building b, int oldHitPoints)
 {
     if (b.Spawned && b.def.useHitPoints && b.HitPoints != oldHitPoints && b.def.drawDamagedOverlay && BuildingsDamageSectionLayerUtility.GetDamageOverlaysCount(b, b.HitPoints) != BuildingsDamageSectionLayerUtility.GetDamageOverlaysCount(b, oldHitPoints))
     {
         b.Map.mapDrawer.MapMeshDirty(b.Position, MapMeshFlag.BuildingsDamage);
     }
 }
        private void DrawFullThingCorners(Building b)
        {
            if (b.def.graphicData != null)
            {
                DamageGraphicData damageData = b.def.graphicData.damageData;
                if (damageData != null)
                {
                    Rect  damageRect             = BuildingsDamageSectionLayerUtility.GetDamageRect(b);
                    float damageTexturesAltitude = GetDamageTexturesAltitude(b);
                    float num = Mathf.Min(Mathf.Min(damageRect.width, damageRect.height), 1.5f);
                    BuildingsDamageSectionLayerUtility.GetCornerMats(out Material topLeft, out Material topRight, out Material botRight, out Material botLeft, b);
                    float num2 = num * Rand.Range(0.9f, 1f);
                    float num3 = num * Rand.Range(0.9f, 1f);
                    float num4 = num * Rand.Range(0.9f, 1f);
                    float num5 = num * Rand.Range(0.9f, 1f);
                    List <DamageOverlay> overlays = BuildingsDamageSectionLayerUtility.GetOverlays(b);
                    for (int i = 0; i < overlays.Count; i++)
                    {
                        switch (overlays[i])
                        {
                        case DamageOverlay.TopLeftCorner:
                        {
                            Rect    rect4   = new Rect(damageRect.xMin, damageRect.yMax - num2, num2, num2);
                            Vector2 center7 = rect4.center;
                            float   x4      = center7.x;
                            float   y4      = damageTexturesAltitude;
                            Vector2 center8 = rect4.center;
                            Printer_Plane.PrintPlane(this, new Vector3(x4, y4, center8.y), rect4.size, topLeft, 0f, flipUv: false, null, null, 0f);
                            break;
                        }

                        case DamageOverlay.TopRightCorner:
                        {
                            Rect    rect3   = new Rect(damageRect.xMax - num3, damageRect.yMax - num3, num3, num3);
                            Vector2 center5 = rect3.center;
                            float   x3      = center5.x;
                            float   y3      = damageTexturesAltitude;
                            Vector2 center6 = rect3.center;
                            Printer_Plane.PrintPlane(this, new Vector3(x3, y3, center6.y), rect3.size, topRight, 90f, flipUv: false, null, null, 0f);
                            break;
                        }

                        case DamageOverlay.BotRightCorner:
                        {
                            Rect    rect2   = new Rect(damageRect.xMax - num4, damageRect.yMin, num4, num4);
                            Vector2 center3 = rect2.center;
                            float   x2      = center3.x;
                            float   y2      = damageTexturesAltitude;
                            Vector2 center4 = rect2.center;
                            Printer_Plane.PrintPlane(this, new Vector3(x2, y2, center4.y), rect2.size, botRight, 180f, flipUv: false, null, null, 0f);
                            break;
                        }

                        case DamageOverlay.BotLeftCorner:
                        {
                            Rect    rect    = new Rect(damageRect.xMin, damageRect.yMin, num5, num5);
                            Vector2 center  = rect.center;
                            float   x       = center.x;
                            float   y       = damageTexturesAltitude;
                            Vector2 center2 = rect.center;
                            Printer_Plane.PrintPlane(this, new Vector3(x, y, center2.y), rect.size, botLeft, 270f, flipUv: false, null, null, 0f);
                            break;
                        }
                        }
                    }
                }
            }
        }