diff --git a/Content/Blueprint/Level/Actor/Static/BP_Carrot.uasset b/Content/Blueprint/Level/Actor/Static/BP_Carrot.uasset new file mode 100644 index 0000000..17e6384 Binary files /dev/null and b/Content/Blueprint/Level/Actor/Static/BP_Carrot.uasset differ diff --git a/Content/Blueprint/Level/Actor/Static/BP_Stone.uasset b/Content/Blueprint/Level/Actor/Static/BP_Stone.uasset new file mode 100644 index 0000000..6a06298 Binary files /dev/null and b/Content/Blueprint/Level/Actor/Static/BP_Stone.uasset differ diff --git a/Content/Blueprint/Level/BP_LevelMap.uasset b/Content/Blueprint/Level/BP_LevelMap.uasset index 7d1edeb..0ebd6c3 100644 Binary files a/Content/Blueprint/Level/BP_LevelMap.uasset and b/Content/Blueprint/Level/BP_LevelMap.uasset differ diff --git a/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset b/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset index 744625c..2d95f72 100644 Binary files a/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset and b/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset differ diff --git a/Content/Level/FalconPlain.umap b/Content/Level/FalconPlain.umap index 1730f37..9c30d3d 100644 Binary files a/Content/Level/FalconPlain.umap and b/Content/Level/FalconPlain.umap differ diff --git a/Content/Resource/Spine/PlacedItems/Carrot/Carrot.uasset b/Content/Resource/Spine/PlacedItems/Carrot/Carrot.uasset new file mode 100644 index 0000000..1fab8e4 Binary files /dev/null and b/Content/Resource/Spine/PlacedItems/Carrot/Carrot.uasset differ diff --git a/Content/Resource/Spine/PlacedItems/Carrot/CarrotData.uasset b/Content/Resource/Spine/PlacedItems/Carrot/CarrotData.uasset new file mode 100644 index 0000000..f844f95 Binary files /dev/null and b/Content/Resource/Spine/PlacedItems/Carrot/CarrotData.uasset differ diff --git a/Content/Resource/Spine/PlacedItems/Carrot/Textures/Carrot.uasset b/Content/Resource/Spine/PlacedItems/Carrot/Textures/Carrot.uasset new file mode 100644 index 0000000..59f9d56 Binary files /dev/null and b/Content/Resource/Spine/PlacedItems/Carrot/Textures/Carrot.uasset differ diff --git a/Content/Resource/Spine/PlacedItems/Stone/Stone.uasset b/Content/Resource/Spine/PlacedItems/Stone/Stone.uasset new file mode 100644 index 0000000..03954fe Binary files /dev/null and b/Content/Resource/Spine/PlacedItems/Stone/Stone.uasset differ diff --git a/Content/Resource/Spine/PlacedItems/Stone/StoneData.uasset b/Content/Resource/Spine/PlacedItems/Stone/StoneData.uasset new file mode 100644 index 0000000..878c364 Binary files /dev/null and b/Content/Resource/Spine/PlacedItems/Stone/StoneData.uasset differ diff --git a/Content/Resource/Spine/PlacedItems/Stone/Textures/Stone.uasset b/Content/Resource/Spine/PlacedItems/Stone/Textures/Stone.uasset new file mode 100644 index 0000000..abc48a3 Binary files /dev/null and b/Content/Resource/Spine/PlacedItems/Stone/Textures/Stone.uasset differ diff --git a/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp index 16c0ee8..35d622e 100644 --- a/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp +++ b/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp @@ -3,14 +3,14 @@ #include "Level/Actor/BusyStaticResource.h" #include "Utils/MitchellBestCandidate.h" -static FName GetOneOfAlwaysPresent(TMap& AlwaysPresentResource) +static FName PeekOneOfAlwaysPresent(TMap& AlwaysPresentResource) { TArray NeedRemoveKeys; for (auto& Pair : AlwaysPresentResource) { if (Pair.Value <= 0) { - NeedRemoveKeys.AddUnique(Pair.Key); + NeedRemoveKeys.Add(Pair.Key); } } for (auto& RemovedKey : NeedRemoveKeys) @@ -22,12 +22,27 @@ static FName GetOneOfAlwaysPresent(TMap& AlwaysPresentResource) { return FName(); } - auto &Pair = *AlwaysPresentResource.begin(); - Pair.Value -= 1; + const auto &Pair = *AlwaysPresentResource.begin(); return Pair.Key; } +static void ConsumeOneOfAlwaysPresent(TMap& AlwaysPresentResource, const FName &ResourceName) +{ + if (const int32 *RemainCount = AlwaysPresentResource.Find(ResourceName)) + { + if (*RemainCount > 0) + { + AlwaysPresentResource[ResourceName] = *RemainCount - 1; + return; + } + } + UE_LOG(LogMapGenerate, Error, TEXT("ConsumeOneOfAlwaysPresent %s failed"), *ResourceName.ToString()); +} + + + + inline static IGameMapInterface * GetMapActor(const UActorComponent* Component) { AActor *Owner = Component->GetOwner(); @@ -92,6 +107,10 @@ void UStaticResourceLayerComponent::GetAlwaysPresentResourceList(TMapMinGenerateCount > 0) { OutAlwaysPresentResource.Add(Pair.Key, RowData->MinGenerateCount); + UE_LOG(LogMapGenerate, Log, + TEXT("UStaticResourceLayerComponent::GetAlwaysPresentResourceList %s: %d"), + *Pair.Key.ToString(), RowData->MinGenerateCount + ); } } } @@ -108,8 +127,12 @@ bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray& for (int i = ResourcePoints.Num() - 1; i >= 0; i--) // 遍历所有的资源点尝试生成资源 { - FName CurrentSelected = GetOneOfAlwaysPresent(AlwaysPresentResource); - if (CurrentSelected.IsNone()) break; // 必须生成的资源已经全部生成了,则结束 + FName CurrentSelected = PeekOneOfAlwaysPresent(AlwaysPresentResource); + if (CurrentSelected.IsNone()) // 必须生成的资源已经全部生成了,则结束 + { + UE_LOG(LogMapGenerate, Log, TEXT("UStaticResourceLayerComponent::GenerateAlwaysPresentInfo All Always present created.")) + break; + } const FVector2D& CurrentPoint = ResourcePoints[i]; FGameplayTag CurrentTerrain = MapInterface->Execute_GetTerrainAt(Owner, CurrentPoint.X, CurrentPoint.Y); // 获取这个资源点的地形类型 @@ -120,15 +143,20 @@ bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray& if (Config->TerrainTypes.HasTag(CurrentTerrain)) // 资源的地形配置包含当前的地形,则添加进生成的列表 { - GeneratedResourcePoints.Add(TTuple( - CurrentSelected, - FVector2D(ResourcePoints[i].X, ResourcePoints[i].Y)) - ); + GeneratedResourcePoints.Add(TTuple(CurrentSelected, FVector2D(ResourcePoints[i].X, ResourcePoints[i].Y))); + ConsumeOneOfAlwaysPresent(AlwaysPresentResource, CurrentSelected); ResourcePoints[i].X = ResourcePoints[i].Y = -1; + UE_LOG(LogMapGenerate, Log, TEXT("UStaticResourceLayerComponent::GenerateAlwaysPresentInfo Create %s at (%d, %d)"), + *CurrentSelected.ToString(), int32(ResourcePoints[i].X), int32(ResourcePoints[i].Y)) + } + else + { + UE_LOG(LogMapGenerate, Log, TEXT("UStaticResourceLayerComponent::GenerateAlwaysPresentInfo Failed create %s at (%d,%d) in %s"), + *CurrentSelected.ToString(), int32(ResourcePoints[i].X), int32(ResourcePoints[i].Y), *CurrentTerrain.ToString()); } } - if (!GetOneOfAlwaysPresent(AlwaysPresentResource).IsNone()) // 如果还有必须要生成的没有生成,则生成失败 + if (!PeekOneOfAlwaysPresent(AlwaysPresentResource).IsNone()) // 如果还有必须要生成的没有生成,则生成失败 { GeneratedResourcePoints.Empty(); return false; diff --git a/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp b/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp index c44578a..eb492af 100644 --- a/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp +++ b/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp @@ -1,6 +1,7 @@ #include "Level/Map/GameMapActor.h" #include "Level/Map/Components/StaticResourceLayerComponent.h" +DEFINE_LOG_CATEGORY(LogMapGenerate); AGameMapActor::AGameMapActor() { diff --git a/Source/BusyRabbit/Public/Level/Map/GameMapActor.h b/Source/BusyRabbit/Public/Level/Map/GameMapActor.h index 933ed5d..0dc9e82 100644 --- a/Source/BusyRabbit/Public/Level/Map/GameMapActor.h +++ b/Source/BusyRabbit/Public/Level/Map/GameMapActor.h @@ -6,6 +6,8 @@ #include "GameMapActor.generated.h" +DECLARE_LOG_CATEGORY_EXTERN(LogMapGenerate, Log, All); + UINTERFACE() class UGameMapInterface : public UInterface {