protected void UpdateClusterPosition()
{
Room clusterRoom = this.GetRoom();
int size = 0;
IntVec3 center = IntVec3.Zero;
// We only check with clusterSpawnRadius (+ a small offset). No need to check entire cluster exclusivity area.
IEnumerable<IntVec3> cellsInCluster = GenRadial.RadialCellsAround(this.Position, this.plantDef.clusterSpawnRadius + 3f, true);
foreach (IntVec3 cell in cellsInCluster)
{
if ((cell.GetRoom() == clusterRoom)
&& (Find.ThingGrid.ThingAt(cell, this.plantDef) != null))
{
size++;
center += cell;
}
}
center.x = (int)Mathf.Round(center.x / (float)size);
center.z = (int)Mathf.Round(center.z / (float)size);
if (center.x < 0)
{
center.x = 0;
}
else if (center.x > Find.Map.Size.x)
{
center.x = Find.Map.Size.x;
}
if (center.z < 0)
{
center.z = 0;
}
else if (center.z > Find.Map.Size.z)
{
center.z = Find.Map.Size.z;
}
this.Position = center;
this.actualSize = size;
}