// Register guard to the closest Control Tower
// When CT dies, so do all the guards that it controls
if (getSiegeGuardManager().getSiegeGuardSpawn().size() > 0 && _controlTowers.size() > 0)
{
L2ControlTowerInstance closestCt;
double distance, x, y, z;
double distanceClosest = 0;
for (L2Spawn spawn : getSiegeGuardManager().getSiegeGuardSpawn())
{
if (spawn == null) continue;
closestCt = null;
distanceClosest = 0;
for (L2ControlTowerInstance ct : _controlTowers)
{
if (ct == null) continue;
x = (spawn.getLocx() - ct.getX());
y = (spawn.getLocy() - ct.getY());
z = (spawn.getLocz() - ct.getZ());
distance = (x * x) + (y * y) + (z * z);
if (closestCt == null || distance < distanceClosest)
{
closestCt = ct;
distanceClosest = distance;
}
}
if (closestCt != null) closestCt.registerGuard(spawn);
}
}
}