✨ Reactor, and enemies attacking the tiles
This commit is contained in:
@@ -67,6 +67,9 @@ public partial class NaturalResourceGenerator : Node2D
|
||||
}
|
||||
|
||||
GD.Print($"{LogPrefix} NaturalResourceGenerator ready, SpawnEnemyNest = {SpawnEnemyNest}");
|
||||
|
||||
GD.Print($"{LogPrefix} Spawning the core reactor...");
|
||||
SpawnCoreReactor();
|
||||
|
||||
if (SpawnEnemyNest)
|
||||
{
|
||||
@@ -393,6 +396,12 @@ public partial class NaturalResourceGenerator : Node2D
|
||||
GD.Print($"{LogPrefix} Finished placing vein - placed {placedCount}/{maxSize} {tileType} tiles");
|
||||
}
|
||||
|
||||
private void SpawnCoreReactor()
|
||||
{
|
||||
// Place the reactor tile at the center of the map
|
||||
PlaceTile("reactor", new Vector2I(0, 0));
|
||||
}
|
||||
|
||||
private void SpawnRandomEnemyNest()
|
||||
{
|
||||
// Generate a random position within the specified distance from origin
|
||||
@@ -402,7 +411,7 @@ public partial class NaturalResourceGenerator : Node2D
|
||||
var nestPosition = new Vector2I((int)offset.X, (int)offset.Y);
|
||||
|
||||
// Try to find a valid position for the nest
|
||||
int attempts = 0;
|
||||
var attempts = 0;
|
||||
const int maxAttempts = 10;
|
||||
|
||||
while (attempts < maxAttempts)
|
||||
@@ -428,25 +437,18 @@ public partial class NaturalResourceGenerator : Node2D
|
||||
{
|
||||
try
|
||||
{
|
||||
// For enemy nest, we want to place it on top of existing ground
|
||||
if (tileType != "enemy_nest")
|
||||
{
|
||||
// Original behavior for other tile types
|
||||
Grid.FreeArea(cell, Vector2I.One, 0f, GridLayer.Ground);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For enemy nest, check if there's ground below (skip for now)
|
||||
GD.Print($"{LogPrefix} Attempting placing nest at {cell}.");
|
||||
}
|
||||
|
||||
var building = Registry.GetBuilding(tileType);
|
||||
if (building == null)
|
||||
{
|
||||
GD.PrintErr($"{LogPrefix} Building type not found in registry: {tileType}");
|
||||
return false;
|
||||
}
|
||||
// GD.Print($"{LogPrefix} Found building in registry: {tileType}");
|
||||
|
||||
// Free area for ground layer if needed
|
||||
if (building.Layer == GridLayer.Ground)
|
||||
Grid.FreeArea(cell, building.Size, 0f, GridLayer.Ground);
|
||||
else
|
||||
GD.Print($"{LogPrefix} Attempting placing building tile {tileType} at {cell}.");
|
||||
|
||||
var scene = building.Scene;
|
||||
if (scene == null)
|
||||
@@ -454,29 +456,24 @@ public partial class NaturalResourceGenerator : Node2D
|
||||
GD.PrintErr($"{LogPrefix} Scene is null for building type: {tileType}");
|
||||
return false;
|
||||
}
|
||||
// GD.Print($"{LogPrefix} Scene loaded for {tileType}");
|
||||
|
||||
if (scene.Instantiate() is not BaseTile instance)
|
||||
{
|
||||
GD.PrintErr($"{LogPrefix} Failed to instantiate scene for: {tileType}");
|
||||
return false;
|
||||
}
|
||||
// GD.Print($"{LogPrefix} Successfully instantiated {tileType}");
|
||||
|
||||
// Use the same positioning logic as PlacementManager
|
||||
// Calculate position with proper offset based on building size
|
||||
var rotatedSize = building.GetRotatedSize(0f);
|
||||
var offset = GridUtils.GetCenterOffset(rotatedSize, 0f);
|
||||
|
||||
instance.ZIndex = (int)building.Layer;
|
||||
instance.GlobalPosition = GridUtils.GridToWorld(cell) + offset;
|
||||
instance.Grid = Grid;
|
||||
AddChild(instance);
|
||||
|
||||
// For enemy nest, use Building layer
|
||||
var layer = tileType == "enemy_nest" ? GridLayer.Building : building.Layer;
|
||||
Grid.OccupyArea(cell, instance, building.Size, 0f, layer);
|
||||
// Occupy the appropriate area based on building size
|
||||
Grid.OccupyArea(cell, instance, building.Size, 0f, building.Layer);
|
||||
|
||||
// GD.Print($"{LogPrefix} Successfully placed {tileType} at {cell} on layer {layer}");
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
Reference in New Issue
Block a user