Wall sections are updated after resizing a structure
This commit is contained in:
@@ -104,6 +104,19 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
get { return prefab.MaxHealth; }
|
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)
|
public override void Move(Vector2 amount)
|
||||||
{
|
{
|
||||||
@@ -130,15 +143,6 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
convexHulls.ForEach(x => x.Move(amount));
|
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)
|
public Structure(Rectangle rectangle, StructurePrefab sp, Submarine submarine)
|
||||||
@@ -173,37 +177,8 @@ namespace Barotrauma
|
|||||||
bodies.Add(newBody);
|
bodies.Add(newBody);
|
||||||
|
|
||||||
WallList.Add(this);
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -245,6 +220,39 @@ namespace Barotrauma
|
|||||||
InsertToList();
|
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()
|
private void GenerateConvexHull()
|
||||||
{
|
{
|
||||||
// If not null and not empty , remove the hulls from the system
|
// If not null and not empty , remove the hulls from the system
|
||||||
|
|||||||
Reference in New Issue
Block a user