Add vegetation ignition risk checks
This commit is contained in:
@@ -106,3 +106,53 @@ int32 AAgrarianFoliagePatch::GetGrassInstanceCount() const
|
||||
{
|
||||
return GrassInstances ? GrassInstances->GetInstanceCount() : 0;
|
||||
}
|
||||
|
||||
void AAgrarianFoliagePatch::GetFuelCountsNearLocation(
|
||||
const FVector& WorldLocation,
|
||||
float Radius,
|
||||
int32& OutGrassCount,
|
||||
int32& OutShrubCount,
|
||||
int32& OutTreeCount) const
|
||||
{
|
||||
SCOPE_CYCLE_COUNTER(STAT_AgrarianFoliageInstanceMutation);
|
||||
TRACE_CPUPROFILER_EVENT_SCOPE(AgrarianFoliageFuelCountsNearLocation);
|
||||
|
||||
OutGrassCount = CountInstancesNearLocation(GrassInstances, WorldLocation, Radius);
|
||||
OutShrubCount = CountInstancesNearLocation(ShrubInstances, WorldLocation, Radius);
|
||||
OutTreeCount = CountInstancesNearLocation(TreeInstances, WorldLocation, Radius);
|
||||
}
|
||||
|
||||
float AAgrarianFoliagePatch::GetDryVegetationFuelScoreNearLocation(const FVector& WorldLocation, float Radius) const
|
||||
{
|
||||
int32 GrassCount = 0;
|
||||
int32 ShrubCount = 0;
|
||||
int32 TreeCount = 0;
|
||||
GetFuelCountsNearLocation(WorldLocation, Radius, GrassCount, ShrubCount, TreeCount);
|
||||
|
||||
return static_cast<float>(GrassCount) + (static_cast<float>(ShrubCount) * 2.0f) + (static_cast<float>(TreeCount) * 4.0f);
|
||||
}
|
||||
|
||||
int32 AAgrarianFoliagePatch::CountInstancesNearLocation(
|
||||
const UHierarchicalInstancedStaticMeshComponent* Component,
|
||||
const FVector& WorldLocation,
|
||||
float Radius) const
|
||||
{
|
||||
if (!Component || Radius <= 0.0f)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float RadiusSquared = FMath::Square(Radius);
|
||||
int32 Count = 0;
|
||||
for (int32 Index = 0; Index < Component->GetInstanceCount(); ++Index)
|
||||
{
|
||||
FTransform InstanceTransform;
|
||||
if (Component->GetInstanceTransform(Index, InstanceTransform, true)
|
||||
&& FVector::DistSquared2D(InstanceTransform.GetLocation(), WorldLocation) <= RadiusSquared)
|
||||
{
|
||||
++Count;
|
||||
}
|
||||
}
|
||||
|
||||
return Count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user