[DLL] Get the list of blueprints in an area

Started by Rikiki, August 11, 2014, 08:40:12 AM

Previous topic - Next topic

Rikiki

Hello all!

I am working on a PlacementRestricter for a custom building. I want to forbid 2 instances of the same building to be too close from each other.
I can easily check the presence of an already built building with this code:

IEnumerable<Building> potentialDeepdrillerMachineList = Find.ListerBuildings.AllBuildingsColonistOfType(EntityType.Building_WorkTable);
foreach (Building building in potentialDeepdrillerMachineList)
{
if ((building.def.defName == "DeepdrillerMachine") && (loc.WithinHorizontalDistanceOf(building.Position, 10)))
{
return new AcceptanceReport("An other Deepdriller machine is too close.");
}
}

The problem is I can place 2 blueprints of this machine next to each other.
I did not found any nice way to get all the blueprints in an area.

I can still check for every cell in range with this

if (Find.ThingGrid.ThingAt(currentCell, EntityType.Blueprint) != null)

but I fear this could really crush the game performances when checking with a wide range.

Any refined idea to get a list of those blueprints ? :)

Thanks!