MapMaker2Controller.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using UnityEngine;
  2. /// <summary>
  3. /// Clean MapMaker2 controller - handles only the new system
  4. /// </summary>
  5. public class MapMaker2Controller : MonoBehaviour
  6. {
  7. [Header("Map References")]
  8. public MapMaker2 mapMaker;
  9. public SimpleTeamPlacement teamPlacement;
  10. [Header("Debug")]
  11. public bool debug = false;
  12. void Start()
  13. {
  14. SetupMapMaker2System();
  15. }
  16. private void SetupMapMaker2System()
  17. {
  18. // Find MapMaker2 if not assigned
  19. if (mapMaker == null)
  20. {
  21. mapMaker = FindFirstObjectByType<MapMaker2>();
  22. }
  23. // Find SimpleTeamPlacement if not assigned
  24. if (teamPlacement == null)
  25. {
  26. teamPlacement = FindFirstObjectByType<SimpleTeamPlacement>();
  27. }
  28. // Create SimpleTeamPlacement if it doesn't exist
  29. if (teamPlacement == null)
  30. {
  31. Debug.Log("Creating SimpleTeamPlacement...");
  32. GameObject teamPlacementObj = new GameObject("SimpleTeamPlacement");
  33. teamPlacement = teamPlacementObj.AddComponent<SimpleTeamPlacement>();
  34. // Configure the team placement
  35. teamPlacement.markerSize = 1.5f;
  36. teamPlacement.markerHeight = 0.5f;
  37. teamPlacement.markerColor = Color.green;
  38. teamPlacement.enableBlinking = true;
  39. }
  40. if (debug)
  41. {
  42. Debug.Log("=== MapMaker2 System Status ===");
  43. Debug.Log($"MapMaker2: {(mapMaker != null ? "✅ Found" : "❌ Missing")}");
  44. Debug.Log($"SimpleTeamPlacement: {(teamPlacement != null ? "✅ Found" : "❌ Missing")}");
  45. if (mapMaker != null)
  46. {
  47. Debug.Log($"Map Size: {mapMaker.initialMapSize}x{mapMaker.initialMapSize}");
  48. Debug.Log($"Seed: {mapMaker.seed}");
  49. Debug.Log($"MapVisualizer: {(mapMaker.mapVisualizer != null ? "✅ Assigned" : "❌ Missing")}");
  50. }
  51. }
  52. }
  53. [ContextMenu("Regenerate Map")]
  54. public void RegenerateMap()
  55. {
  56. if (mapMaker != null)
  57. {
  58. // Change seed for variety
  59. mapMaker.seed = Random.Range(1000, 9999);
  60. mapMaker.RegenerateMap();
  61. if (debug)
  62. {
  63. Debug.Log($"🎲 Map regenerated with new seed: {mapMaker.seed}");
  64. }
  65. }
  66. else
  67. {
  68. Debug.LogError("❌ MapMaker2 not found!");
  69. }
  70. }
  71. [ContextMenu("Debug River Paths Info")]
  72. public void DebugRiverPathsInfo()
  73. {
  74. if (mapMaker?.GetMapData() == null)
  75. {
  76. Debug.LogError("❌ No map data available");
  77. return;
  78. }
  79. var mapData = mapMaker.GetMapData();
  80. int riverPathsCount = 0;
  81. int forestCount = 0;
  82. int riverCount = 0;
  83. // Count rivers that have forests around them (creating paths)
  84. for (int x = 0; x < mapData.Width; x++)
  85. {
  86. for (int y = 0; y < mapData.Height; y++)
  87. {
  88. var tile = mapData.GetTile(x, y);
  89. switch (tile.terrainType)
  90. {
  91. case TerrainType.Forest:
  92. forestCount++;
  93. break;
  94. case TerrainType.River:
  95. riverCount++;
  96. // Check if this river has forests nearby (creating a path effect)
  97. bool hasNearbyForest = false;
  98. for (int dx = -1; dx <= 1; dx++)
  99. {
  100. for (int dy = -1; dy <= 1; dy++)
  101. {
  102. if (dx == 0 && dy == 0) continue;
  103. int checkX = x + dx, checkY = y + dy;
  104. if (mapData.IsValidPosition(checkX, checkY))
  105. {
  106. if (mapData.GetTile(checkX, checkY).terrainType == TerrainType.Forest)
  107. {
  108. hasNearbyForest = true;
  109. break;
  110. }
  111. }
  112. }
  113. if (hasNearbyForest) break;
  114. }
  115. if (hasNearbyForest) riverPathsCount++;
  116. break;
  117. }
  118. }
  119. }
  120. Debug.Log("=== RIVER PATHS ANALYSIS ===");
  121. Debug.Log($"🌊 Total River tiles: {riverCount}");
  122. Debug.Log($"🌲 Forest tiles: {forestCount}");
  123. Debug.Log($"🛤️ River paths through forests: {riverPathsCount}");
  124. Debug.Log($"💡 Rivers create clear blue paths through green forests");
  125. if (riverPathsCount > 0)
  126. {
  127. Debug.Log($"✅ SUCCESS: Found {riverPathsCount} river paths through forests! Look for blue waterways cutting through green forest areas.");
  128. }
  129. else
  130. {
  131. Debug.Log("❓ No river paths found. Try regenerating the map with a different seed.");
  132. }
  133. }
  134. void Update()
  135. {
  136. // Debug keys
  137. if (Input.GetKeyDown(KeyCode.F5))
  138. {
  139. RegenerateMap();
  140. }
  141. if (Input.GetKeyDown(KeyCode.F6))
  142. {
  143. DebugRiverPathsInfo();
  144. }
  145. }
  146. }