From 0b2a5d57715a5fe5400f8e2330c88c1a5bb958e0 Mon Sep 17 00:00:00 2001 From: Regalis Date: Mon, 29 Aug 2016 17:25:17 +0300 Subject: [PATCH] Wall sections are updated after resizing a structure --- Subsurface/Source/Map/Structure.cs | 86 ++++++++++++++++-------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 0a3954af4..02eb7c023 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -104,6 +104,19 @@ namespace Barotrauma { get { return prefab.MaxHealth; } } + + public override Rectangle Rect + { + get + { + return base.Rect; + } + set + { + base.Rect = value; + if (prefab.HasBody) CreateSections(); + } + } public override void Move(Vector2 amount) { @@ -130,15 +143,6 @@ namespace Barotrauma { convexHulls.ForEach(x => x.Move(amount)); } - //if (gaps != null) - //{ - // foreach (Gap g in gaps) - // { - // g.Move(amount); - // //g.position.X += amount.X; - // //g.position.Y -= amount.Y; - // } - //} } public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine) @@ -173,37 +177,8 @@ namespace Barotrauma bodies.Add(newBody); WallList.Add(this); - - int xsections = 1; - int ysections = 1; - int width, height; - if (isHorizontal) - { - xsections = (int)Math.Ceiling((float)rect.Width / wallSectionSize); - sections = new WallSection[xsections]; - width = (int)wallSectionSize; - height = rect.Height; - } - else - { - ysections = (int)Math.Ceiling((float)rect.Height / wallSectionSize); - sections = new WallSection[ysections]; - width = rect.Width; - height = (int)wallSectionSize; - } - - for (int x = 0; x < xsections; x++ ) - { - for (int y = 0; y < ysections; y++) - { - Rectangle sectionRect = new Rectangle(rect.X + x * width, rect.Y - y * height, width, height); - sectionRect.Width -= (int)Math.Max((sectionRect.X + sectionRect.Width) - (rect.X + rect.Width), 0.0f); - sectionRect.Height -= (int)Math.Max((rect.Y - rect.Height)-(sectionRect.Y - sectionRect.Height), 0.0f); - - sections[x+y] = new WallSection(sectionRect); - } - } + CreateSections(); } else { @@ -245,6 +220,39 @@ namespace Barotrauma InsertToList(); } + private void CreateSections() + { + int xsections = 1, ysections = 1; + int width, height; + + if (isHorizontal) + { + xsections = (int)Math.Ceiling((float)rect.Width / wallSectionSize); + sections = new WallSection[xsections]; + width = (int)wallSectionSize; + height = rect.Height; + } + else + { + ysections = (int)Math.Ceiling((float)rect.Height / wallSectionSize); + sections = new WallSection[ysections]; + width = rect.Width; + height = (int)wallSectionSize; + } + + for (int x = 0; x < xsections; x++) + { + for (int y = 0; y < ysections; y++) + { + Rectangle sectionRect = new Rectangle(rect.X + x * width, rect.Y - y * height, width, height); + sectionRect.Width -= (int)Math.Max((sectionRect.X + sectionRect.Width) - (rect.X + rect.Width), 0.0f); + sectionRect.Height -= (int)Math.Max((rect.Y - rect.Height) - (sectionRect.Y - sectionRect.Height), 0.0f); + + sections[x + y] = new WallSection(sectionRect); + } + } + } + private void GenerateConvexHull() { // If not null and not empty , remove the hulls from the system