MapMaker2.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public class MapMaker2 : MonoBehaviour
  4. {
  5. [Header("Map Settings")]
  6. public int initialMapSize = 150;
  7. public int expansionSize = 50;
  8. public float playerDistanceThreshold = 20f;
  9. [Header("Simple Mode")]
  10. [Tooltip("Use simple static map generation (no exploration/expansion)")]
  11. public bool useSimpleMode = true;
  12. [Header("Exploration Settings")]
  13. [Tooltip("Use exploration system instead of expansion")]
  14. public bool useExplorationSystem = true;
  15. public void SetMapData(MapData newMapData)
  16. {
  17. mapData = newMapData;
  18. Debug.Log($"📊 Map data updated to size: {mapData.Width}x{mapData.Height}");
  19. // Update the visualization
  20. if (mapVisualizer != null)
  21. {
  22. mapVisualizer.VisualizeMap(mapData);
  23. Debug.Log("🗺️ Map visualization updated");
  24. }
  25. else
  26. {
  27. Debug.LogWarning("⚠️ MapVisualizer is null, cannot update visualization");
  28. }
  29. }
  30. public MapData GetMapData()
  31. {
  32. return mapData;
  33. }
  34. [Header("Exploration Settings")]
  35. public int explorationMapSize = 300;
  36. public int explorationInitialVisible = 80;
  37. [Header("Expansion Settings")]
  38. [Tooltip("Cooldown time between map expansions in seconds")]
  39. public float expansionCooldown = 5f;
  40. [Tooltip("Chance for terrain to continue from existing edge (0-1)")]
  41. [Range(0f, 1f)]
  42. public float terrainContinuityChance = 0.7f;
  43. [Header("Generation Settings")]
  44. public int seed = 12345;
  45. [Header("Visualization")]
  46. public MapVisualizer mapVisualizer;
  47. private MapData mapData;
  48. private TerrainGenerator terrainGenerator;
  49. private FeatureGenerator featureGenerator;
  50. private ExpansionManager expansionManager;
  51. private ExplorationManager explorationManager;
  52. private Transform player;
  53. private float lastExpansionTime = 0f;
  54. void Start()
  55. {
  56. Debug.Log($"🚀 MapMaker2 starting - useSimpleMode: {useSimpleMode}, useExplorationSystem: {useExplorationSystem}");
  57. InitializeMap();
  58. if (useSimpleMode)
  59. {
  60. Debug.Log("🎮 Starting with Simple Mode - Full map generation with team marker placement");
  61. GenerateCompleteMapWithTeamMarker();
  62. }
  63. else if (useExplorationSystem)
  64. {
  65. Debug.Log("🔍 Starting with Exploration System");
  66. InitializeExplorationSystem();
  67. }
  68. else
  69. {
  70. Debug.Log("📏 Starting with Expansion System");
  71. GenerateInitialMap();
  72. }
  73. }
  74. void Update()
  75. {
  76. // In simple mode, no expansion or exploration updates needed
  77. if (useSimpleMode)
  78. {
  79. // Only handle finding the player reference if missing
  80. if (player == null)
  81. {
  82. GameObject teamMarker = GameObject.Find("TeamMarker");
  83. if (teamMarker != null)
  84. {
  85. player = teamMarker.transform;
  86. }
  87. }
  88. return;
  89. }
  90. // Only handle finding the player reference, not continuous exploration checks
  91. if (player == null)
  92. {
  93. // Debug log every few seconds to show player reference status
  94. if (Time.time % 3f < Time.deltaTime)
  95. {
  96. Debug.LogWarning($"🚫 MapMaker2 Update: Player reference is null! useExplorationSystem: {useExplorationSystem}");
  97. // Try to find TeamMarker if not found
  98. GameObject teamMarker = GameObject.Find("TeamMarker");
  99. if (teamMarker != null)
  100. {
  101. Debug.Log($"🎯 Found TeamMarker at {teamMarker.transform.position}, setting as player reference");
  102. player = teamMarker.transform;
  103. }
  104. }
  105. }
  106. else if (!useExplorationSystem)
  107. {
  108. // Only run expansion checks for the old system
  109. CheckForExpansion();
  110. }
  111. // Exploration system is now event-driven, no Update checks needed!
  112. }
  113. private void InitializeMap()
  114. {
  115. Random.InitState(seed);
  116. mapData = new MapData(initialMapSize, initialMapSize);
  117. terrainGenerator = new TerrainGenerator();
  118. featureGenerator = new FeatureGenerator();
  119. expansionManager = new ExpansionManager(this);
  120. explorationManager = new ExplorationManager(this);
  121. // Find player object - try multiple approaches
  122. GameObject playerObj = GameObject.FindGameObjectWithTag("Player");
  123. // If no "Player" tag found, try finding by name patterns
  124. if (playerObj == null)
  125. {
  126. // Try common player names
  127. string[] playerNames = { "TeamMarker", "Player", "PlayerCharacter", "Team", "MainCharacter" };
  128. foreach (string name in playerNames)
  129. {
  130. playerObj = GameObject.Find(name);
  131. if (playerObj != null)
  132. {
  133. Debug.LogWarning($"Found player object by name '{name}' but it doesn't have 'Player' tag. Consider adding the tag.");
  134. break;
  135. }
  136. }
  137. }
  138. if (playerObj != null)
  139. {
  140. player = playerObj.transform;
  141. Debug.Log($"Player found: {playerObj.name} at position {player.position}");
  142. }
  143. else
  144. {
  145. Debug.LogWarning("No player object found! Trying to find any object that might be the player...");
  146. Debug.Log("Available GameObjects:");
  147. GameObject[] allObjects = FindObjectsByType<GameObject>(FindObjectsSortMode.None);
  148. foreach (GameObject obj in allObjects)
  149. {
  150. Debug.Log($"- {obj.name} (Tag: {obj.tag})");
  151. }
  152. }
  153. // Initialize visualizer if not set
  154. if (mapVisualizer == null)
  155. mapVisualizer = GetComponent<MapVisualizer>();
  156. }
  157. private void GenerateInitialMap()
  158. {
  159. // Generate base terrain
  160. terrainGenerator.GenerateTerrain(mapData);
  161. // Generate features
  162. featureGenerator.GenerateFeatures(mapData);
  163. // Visualize the map
  164. VisualizeMap();
  165. }
  166. /// <summary>
  167. /// Generate complete map with team marker placement - Simple Mode
  168. /// </summary>
  169. private void GenerateCompleteMapWithTeamMarker()
  170. {
  171. Debug.Log("🗺️ Generating complete map with beautiful terrain...");
  172. // Generate the full beautiful map using original generators
  173. terrainGenerator.GenerateTerrain(mapData);
  174. featureGenerator.GenerateFeatures(mapData);
  175. Debug.Log("🎯 Placing team marker on a settlement...");
  176. // Find a good settlement for team marker placement
  177. Vector2Int? settlementPos = FindBestSettlementForTeamMarker();
  178. if (settlementPos.HasValue)
  179. {
  180. // PlaceTeamMarkerAt(settlementPos.Value);
  181. Debug.Log($"✅ Team marker placed at settlement: {settlementPos.Value}");
  182. }
  183. else
  184. {
  185. // Fallback to center if no settlements found
  186. Vector2Int centerPos = new Vector2Int(mapData.Width / 2, mapData.Height / 2);
  187. // PlaceTeamMarkerAt(centerPos);
  188. Debug.LogWarning($"⚠️ No settlements found, placed team marker at center: {centerPos}");
  189. }
  190. // Visualize the map
  191. VisualizeMap();
  192. Debug.Log("🎮 Simple mode map generation complete!");
  193. }
  194. /// <summary>
  195. /// Find the best settlement position for team marker placement
  196. /// </summary>
  197. private Vector2Int? FindBestSettlementForTeamMarker()
  198. {
  199. List<Vector2Int> settlements = new List<Vector2Int>();
  200. // Find all towns and villages
  201. for (int x = 0; x < mapData.Width; x++)
  202. {
  203. for (int y = 0; y < mapData.Height; y++)
  204. {
  205. MapTile tile = mapData.GetTile(x, y);
  206. if (tile != null && (tile.featureType == FeatureType.Town || tile.featureType == FeatureType.Village))
  207. {
  208. settlements.Add(new Vector2Int(x, y));
  209. }
  210. }
  211. }
  212. if (settlements.Count == 0) return null;
  213. // Prefer towns over villages, and those closer to center
  214. Vector2 center = new Vector2(mapData.Width / 2f, mapData.Height / 2f);
  215. Vector2Int bestSettlement = settlements[0];
  216. float bestScore = float.MinValue;
  217. foreach (Vector2Int settlement in settlements)
  218. {
  219. MapTile tile = mapData.GetTile(settlement.x, settlement.y);
  220. float score = 0;
  221. // Prefer towns (higher score)
  222. if (tile.featureType == FeatureType.Town) score += 100;
  223. else score += 50; // Village
  224. // Prefer locations closer to center (but not exactly center)
  225. float distanceToCenter = Vector2.Distance(settlement, center);
  226. score += Mathf.Max(0, 50 - distanceToCenter); // Closer to center = higher score
  227. if (score > bestScore)
  228. {
  229. bestScore = score;
  230. bestSettlement = settlement;
  231. }
  232. }
  233. Debug.Log($"🏛️ Found {settlements.Count} settlements, selected {mapData.GetTile(bestSettlement.x, bestSettlement.y).featureType} at {bestSettlement}");
  234. return bestSettlement;
  235. }
  236. /// <summary>
  237. /// Place team marker at specified map coordinates
  238. /// </summary>
  239. private void PlaceTeamMarkerAt(Vector2Int mapPos)
  240. {
  241. // Remove existing team marker
  242. GameObject existingMarker = GameObject.Find("TeamMarker");
  243. if (existingMarker != null)
  244. {
  245. DestroyImmediate(existingMarker);
  246. Debug.Log("🗑️ Removed existing team marker");
  247. }
  248. // Create new team marker
  249. GameObject teamMarker = new GameObject("TeamMarkerMapMaker2");
  250. // Position it correctly in world space
  251. teamMarker.transform.position = new Vector3(mapPos.x, 0.5f, mapPos.y);
  252. // Add visual representation
  253. GameObject visualMarker = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  254. visualMarker.transform.SetParent(teamMarker.transform);
  255. visualMarker.transform.localPosition = Vector3.zero;
  256. visualMarker.transform.localScale = Vector3.one * 0.8f;
  257. // Make it green and distinctive
  258. Renderer renderer = visualMarker.GetComponent<Renderer>();
  259. if (renderer != null)
  260. {
  261. renderer.material.color = Color.green;
  262. }
  263. // Add a tag for easy finding
  264. teamMarker.tag = "Player";
  265. Debug.Log($"📍 Team marker created at world position: {teamMarker.transform.position} (map {mapPos})");
  266. // Update player reference
  267. player = teamMarker.transform;
  268. }
  269. private void CheckForExpansion()
  270. {
  271. // Check if mapVisualizer is available and has valid tileSize
  272. if (mapVisualizer == null)
  273. {
  274. Debug.LogWarning("MapVisualizer is null! Cannot check for expansion.");
  275. return;
  276. }
  277. float tileSize = mapVisualizer.tileSize;
  278. if (tileSize <= 0)
  279. {
  280. Debug.LogWarning($"Invalid tile size: {tileSize}. Using default value of 1.");
  281. tileSize = 1f;
  282. }
  283. // Debug player position
  284. Vector2 playerPos = new Vector2(player.position.x / tileSize, player.position.z / tileSize);
  285. // Debug log every few seconds
  286. if (Time.time % 2f < Time.deltaTime) // Log every 2 seconds
  287. {
  288. Debug.Log($"Player world position: {player.position}");
  289. Debug.Log($"Player tile position: {playerPos} (using tileSize: {tileSize})");
  290. Debug.Log($"Map size: {mapData.Width}x{mapData.Height}");
  291. Debug.Log($"Distance to edges - Left: {playerPos.x:F1}, Right: {(mapData.Width - playerPos.x):F1}, Top: {(mapData.Height - playerPos.y):F1}, Bottom: {playerPos.y:F1}");
  292. Debug.Log($"Expansion threshold: {playerDistanceThreshold}");
  293. }
  294. // Check cooldown to prevent rapid expansions
  295. if (Time.time - lastExpansionTime < expansionCooldown)
  296. return;
  297. if (expansionManager.ShouldExpand(playerPos, mapData))
  298. {
  299. Debug.Log($"Expansion triggered! Player position: {playerPos}");
  300. ExpandMap(playerPos);
  301. }
  302. }
  303. private void ExpandMap(Vector2 playerPos)
  304. {
  305. lastExpansionTime = Time.time;
  306. Debug.Log("Expanding map due to player proximity to edge...");
  307. expansionManager.ExpandMap(mapData, playerPos, expansionSize);
  308. VisualizeMap(); // Update visualization
  309. }
  310. private void VisualizeMap()
  311. {
  312. if (mapVisualizer != null)
  313. {
  314. mapVisualizer.VisualizeMap(mapData);
  315. }
  316. Debug.Log($"Map generated with size: {mapData.Width}x{mapData.Height}");
  317. Debug.Log($"Towns: {mapData.GetTowns().Count}, Villages: {mapData.GetVillages().Count}");
  318. }
  319. public TerrainGenerator GetTerrainGenerator() => terrainGenerator;
  320. public FeatureGenerator GetFeatureGenerator() => featureGenerator;
  321. public ExplorationManager GetExplorationManager() => explorationManager;
  322. // Public method to manually set player reference if automatic detection fails
  323. public void SetPlayer(Transform playerTransform)
  324. {
  325. player = playerTransform;
  326. Debug.Log($"Player manually set to: {player.name}");
  327. }
  328. /// <summary>
  329. /// Enable Simple Mode - Beautiful map generation without exploration/expansion
  330. /// </summary>
  331. [ContextMenu("🎮 Enable Simple Mode (Beautiful Map + Team Marker)")]
  332. public void EnableSimpleMode()
  333. {
  334. Debug.Log("🎮 Switching to Simple Mode...");
  335. useSimpleMode = true;
  336. useExplorationSystem = false;
  337. // Clear existing map visualization
  338. if (mapVisualizer != null)
  339. mapVisualizer.ClearAllTiles();
  340. // Regenerate with simple mode
  341. mapData = new MapData(initialMapSize, initialMapSize);
  342. GenerateCompleteMapWithTeamMarker();
  343. Debug.Log("✅ Simple Mode enabled - Beautiful map with team marker placement!");
  344. }
  345. // For debugging - regenerate map
  346. [ContextMenu("Regenerate Map")]
  347. public void RegenerateMap()
  348. {
  349. if (mapVisualizer != null)
  350. mapVisualizer.ClearAllTiles();
  351. // Preserve current map size instead of resetting to initial size
  352. int currentWidth = mapData != null ? mapData.Width : initialMapSize;
  353. int currentHeight = mapData != null ? mapData.Height : initialMapSize;
  354. Debug.Log($"Regenerating map with current size: {currentWidth}x{currentHeight}");
  355. Random.InitState(seed);
  356. mapData = new MapData(currentWidth, currentHeight);
  357. terrainGenerator = new TerrainGenerator();
  358. featureGenerator = new FeatureGenerator();
  359. GenerateInitialMap();
  360. }
  361. // For debugging - reset to original size
  362. [ContextMenu("Reset to Original Size")]
  363. public void ResetToOriginalSize()
  364. {
  365. if (mapVisualizer != null)
  366. mapVisualizer.ClearAllTiles();
  367. Debug.Log($"Resetting map to original size: {initialMapSize}x{initialMapSize}");
  368. InitializeMap();
  369. GenerateInitialMap();
  370. }
  371. // For debugging - force map expansion
  372. [ContextMenu("Force Map Expansion")]
  373. public void ForceExpansion()
  374. {
  375. Vector2 playerPos;
  376. if (player != null)
  377. {
  378. float tileSize = mapVisualizer != null && mapVisualizer.tileSize > 0 ? mapVisualizer.tileSize : 1f;
  379. playerPos = new Vector2(player.position.x / tileSize, player.position.z / tileSize);
  380. }
  381. else
  382. {
  383. // If no player, expand from center-right edge to test the system
  384. playerPos = new Vector2(mapData.Width - 10, mapData.Height / 2);
  385. Debug.LogWarning("No player found, using test position for forced expansion");
  386. }
  387. lastExpansionTime = 0f; // Reset cooldown
  388. Debug.Log($"Forcing expansion from position: {playerPos}");
  389. ExpandMap(playerPos);
  390. }
  391. // For debugging - manually set TeamMarker as player
  392. [ContextMenu("Set TeamMarker as Player")]
  393. public void SetTeamMarkerAsPlayer()
  394. {
  395. GameObject teamMarker = GameObject.Find("TeamMarker");
  396. if (teamMarker != null)
  397. {
  398. SetPlayer(teamMarker.transform);
  399. Debug.Log("TeamMarker set as player successfully!");
  400. }
  401. else
  402. {
  403. Debug.LogError("TeamMarker object not found!");
  404. }
  405. }
  406. // === Exploration System Methods ===
  407. private void InitializeExplorationSystem()
  408. {
  409. Debug.Log("🔍 Initializing Exploration System...");
  410. if (explorationManager == null)
  411. {
  412. Debug.LogError("❌ ExplorationManager is null! Cannot initialize exploration system.");
  413. return;
  414. }
  415. explorationManager.fullMapWidth = explorationMapSize;
  416. explorationManager.fullMapHeight = explorationMapSize;
  417. explorationManager.initialVisibleSize = explorationInitialVisible;
  418. explorationManager.InitializeExploration();
  419. Debug.Log("✅ Exploration System initialization complete");
  420. }
  421. private void ExploreNewAreas(Vector2 playerPos)
  422. {
  423. lastExpansionTime = Time.time;
  424. Debug.Log("🌍 Exploring new areas due to team movement...");
  425. explorationManager.ExploreNewAreas(playerPos, mapData);
  426. VisualizeMap(); // Update visualization
  427. }
  428. // === Public Methods for Event-Driven Exploration ===
  429. /// <summary>
  430. /// Check for exploration when team position changes (event-driven)
  431. /// </summary>
  432. public void OnTeamPositionChanged(Vector2Int newPosition)
  433. {
  434. if (!useExplorationSystem || explorationManager == null)
  435. return;
  436. // Optimization: Only check if team moved a significant distance or cooldown passed
  437. if (Time.time - lastExpansionTime < expansionCooldown)
  438. return;
  439. // Convert tile position to world position for exploration system
  440. Vector2 worldPos = new Vector2(newPosition.x, newPosition.y);
  441. Debug.Log($"🚶 Team moved to {newPosition} - checking for exploration...");
  442. if (explorationManager.ShouldExplore(worldPos, mapData))
  443. {
  444. Debug.Log($"🔍 Exploration triggered by team movement to {newPosition}!");
  445. ExploreNewAreas(worldPos);
  446. }
  447. }
  448. // === Methods needed by ExplorationManager ===
  449. public void GenerateCompleteMap(MapData targetMapData)
  450. {
  451. // Generate base terrain
  452. terrainGenerator.GenerateTerrain(targetMapData);
  453. // Generate features
  454. featureGenerator.GenerateFeatures(targetMapData);
  455. Debug.Log($"✅ Complete map generated: {targetMapData.Width}x{targetMapData.Height}");
  456. }
  457. [ContextMenu("Enable Exploration System")]
  458. public void EnableExplorationSystem()
  459. {
  460. useExplorationSystem = true;
  461. Debug.Log("🔍 Exploration system enabled! Restart the scene to take effect.");
  462. }
  463. [ContextMenu("Test Exploration Now")]
  464. public void TestExplorationNow()
  465. {
  466. if (!useExplorationSystem)
  467. {
  468. Debug.LogWarning("⚠️ Exploration system is not enabled! Enable it first.");
  469. return;
  470. }
  471. // Debug player detection
  472. Debug.Log($"🔍 Player object: {(player != null ? player.name : "NULL")}");
  473. Debug.Log($"🔍 ExplorationManager: {(explorationManager != null ? "EXISTS" : "NULL")}");
  474. if (player == null)
  475. {
  476. // Try to find player again
  477. GameObject playerObj = GameObject.FindGameObjectWithTag("Player");
  478. if (playerObj == null)
  479. {
  480. playerObj = GameObject.Find("TeamMarker");
  481. }
  482. if (playerObj != null)
  483. {
  484. player = playerObj.transform;
  485. Debug.Log($"✅ Found player: {playerObj.name}");
  486. }
  487. else
  488. {
  489. Debug.LogError("❌ Cannot find player object! Make sure TeamMarker has 'Player' tag or is named 'TeamMarker'");
  490. return;
  491. }
  492. }
  493. if (explorationManager == null)
  494. {
  495. Debug.LogError("❌ ExplorationManager is null! This should be created in InitializeMap()");
  496. return;
  497. }
  498. float tileSize = mapVisualizer != null && mapVisualizer.tileSize > 0 ? mapVisualizer.tileSize : 1f;
  499. Vector2 playerPos = new Vector2(player.position.x / tileSize, player.position.z / tileSize);
  500. Debug.Log($"🧪 MANUAL EXPLORATION TEST");
  501. Debug.Log($"Player world position: {player.position}");
  502. Debug.Log($"Player tile position: {playerPos}");
  503. Debug.Log($"Current map size: {mapData.Width}x{mapData.Height}");
  504. Debug.Log($"Tile size: {tileSize}");
  505. // Force exploration regardless of cooldown
  506. lastExpansionTime = 0f;
  507. ExploreNewAreas(playerPos);
  508. }
  509. [ContextMenu("DEBUG: Show Full 300x300 Map")]
  510. public void ShowFullMap()
  511. {
  512. if (!useExplorationSystem || explorationManager == null)
  513. {
  514. Debug.LogError("❌ Exploration system not enabled or null!");
  515. return;
  516. }
  517. explorationManager.ShowFullMap();
  518. }
  519. [ContextMenu("DEBUG: Show Exploration State")]
  520. public void DebugExplorationState()
  521. {
  522. if (!useExplorationSystem || explorationManager == null)
  523. {
  524. Debug.LogError("❌ Exploration system not enabled or null!");
  525. return;
  526. }
  527. if (player == null)
  528. {
  529. GameObject teamMarker = GameObject.Find("TeamMarker");
  530. if (teamMarker != null) player = teamMarker.transform;
  531. }
  532. if (player == null)
  533. {
  534. Debug.LogError("❌ No player/team marker found!");
  535. return;
  536. }
  537. float tileSize = mapVisualizer != null && mapVisualizer.tileSize > 0 ? mapVisualizer.tileSize : 1f;
  538. Vector2 playerPos = new Vector2(player.position.x / tileSize, player.position.z / tileSize);
  539. explorationManager.DebugExplorationState(playerPos, mapData);
  540. }
  541. [ContextMenu("Disable Exploration System")]
  542. public void DisableExplorationSystem()
  543. {
  544. useExplorationSystem = false;
  545. Debug.Log("📏 Expansion system enabled! Restart the scene to take effect.");
  546. }
  547. [ContextMenu("PERF: Toggle Performance Mode")]
  548. public void TogglePerformanceMode()
  549. {
  550. if (explorationManager != null)
  551. {
  552. explorationManager.TogglePerformanceMode();
  553. }
  554. else
  555. {
  556. Debug.LogError("❌ Exploration manager not available!");
  557. }
  558. }
  559. [ContextMenu("PERF: Test 500x500 Map")]
  560. public void TestLargeMap500()
  561. {
  562. if (explorationManager != null)
  563. {
  564. explorationManager.SetMapSize(500, 500);
  565. Debug.Log("🗺️ Testing 500x500 map - will use LOD level 4 for performance");
  566. }
  567. else
  568. {
  569. Debug.LogError("❌ Exploration manager not available!");
  570. }
  571. }
  572. [ContextMenu("PERF: Test 1000x1000 Map")]
  573. public void TestMassiveMap1000()
  574. {
  575. if (explorationManager != null)
  576. {
  577. explorationManager.SetMapSize(1000, 1000);
  578. Debug.Log("🗺️ Testing 1000x1000 map - maximum LOD will be applied");
  579. }
  580. else
  581. {
  582. Debug.LogError("❌ Exploration manager not available!");
  583. }
  584. }
  585. [ContextMenu("PERF: Reset to 300x300")]
  586. public void ResetToStandardSize()
  587. {
  588. if (explorationManager != null)
  589. {
  590. explorationManager.SetMapSize(300, 300);
  591. Debug.Log("🗺️ Reset to standard 300x300 map");
  592. }
  593. else
  594. {
  595. Debug.LogError("❌ Exploration manager not available!");
  596. }
  597. }
  598. [ContextMenu("FIX: Synchronize Team Marker Position")]
  599. public void SynchronizeTeamMarkerPosition()
  600. {
  601. if (explorationManager != null)
  602. {
  603. explorationManager.SynchronizeTeamMarkerPosition();
  604. Debug.Log("🔄 Team marker position synchronized between coordinate systems");
  605. }
  606. else
  607. {
  608. Debug.LogError("❌ Exploration manager not available!");
  609. }
  610. }
  611. [ContextMenu("TEST: Debug Full Map Coordinate Fix")]
  612. public void TestFullMapCoordinateFix()
  613. {
  614. if (!useExplorationSystem || explorationManager == null)
  615. {
  616. Debug.LogError("❌ Exploration system not enabled or null!");
  617. return;
  618. }
  619. GameObject teamMarker = GameObject.Find("TeamMarker");
  620. if (teamMarker == null)
  621. {
  622. Debug.LogError("❌ Team marker not found!");
  623. return;
  624. }
  625. Vector3 worldPos = teamMarker.transform.position;
  626. Vector2Int worldTilePos = new Vector2Int(
  627. Mathf.RoundToInt(worldPos.x),
  628. Mathf.RoundToInt(worldPos.y)
  629. );
  630. Debug.Log("🧪 COORDINATE FIX TEST - Before showing full map:");
  631. Debug.Log($" Team marker world position: {worldPos}");
  632. Debug.Log($" Team marker tile position: {worldTilePos}");
  633. Debug.Log($" Current map size: {mapData?.Width ?? 0}x{mapData?.Height ?? 0}");
  634. // Show full map and check if position is preserved
  635. explorationManager.ShowFullMap();
  636. // Check position after full map is shown
  637. Vector3 newWorldPos = teamMarker.transform.position;
  638. Vector2Int newWorldTilePos = new Vector2Int(
  639. Mathf.RoundToInt(newWorldPos.x),
  640. Mathf.RoundToInt(newWorldPos.y)
  641. );
  642. Debug.Log("🧪 COORDINATE FIX TEST - After showing full map:");
  643. Debug.Log($" Team marker world position: {newWorldPos}");
  644. Debug.Log($" Team marker tile position: {newWorldTilePos}");
  645. Debug.Log($" Position preserved: {(worldTilePos == newWorldTilePos ? "✅ YES" : "❌ NO")}");
  646. if (worldTilePos != newWorldTilePos)
  647. {
  648. Debug.LogError($"❌ COORDINATE FIX FAILED: Position changed from {worldTilePos} to {newWorldTilePos}");
  649. }
  650. else
  651. {
  652. Debug.Log("✅ COORDINATE FIX SUCCESS: Team marker position preserved when showing full map");
  653. }
  654. }
  655. [ContextMenu("FIX: Reset Team Marker to Map Center")]
  656. public void ResetTeamMarkerToCenter()
  657. {
  658. if (!useExplorationSystem || explorationManager == null)
  659. {
  660. Debug.LogError("❌ Exploration system not enabled or null!");
  661. return;
  662. }
  663. explorationManager.ResetTeamMarkerToMapCenter();
  664. Debug.Log("🎯 Team marker has been reset to the center of the map");
  665. }
  666. [ContextMenu("FIX: Clear Saved Team Position")]
  667. public void ClearSavedTeamPosition()
  668. {
  669. // Clear saved position from PlayerPrefs
  670. string keyX = $"TeamPosition_{seed}_X";
  671. string keyY = $"TeamPosition_{seed}_Y";
  672. if (PlayerPrefs.HasKey(keyX)) PlayerPrefs.DeleteKey(keyX);
  673. if (PlayerPrefs.HasKey(keyY)) PlayerPrefs.DeleteKey(keyY);
  674. PlayerPrefs.Save();
  675. Debug.Log($"🗑️ Cleared saved team position for seed {seed}");
  676. Debug.Log($" Deleted keys: {keyX}, {keyY}");
  677. Debug.Log(" Restart the scene to use default center position");
  678. }
  679. [ContextMenu("DEBUG: Show Coordinate State")]
  680. public void DebugCoordinateState()
  681. {
  682. if (explorationManager != null)
  683. {
  684. explorationManager.DebugCoordinateState();
  685. }
  686. else
  687. {
  688. Debug.LogError("❌ Exploration manager not available!");
  689. }
  690. }
  691. [ContextMenu("FIX: Force Coordinate Sync")]
  692. public void ForceCoordinateSync()
  693. {
  694. if (explorationManager != null)
  695. {
  696. explorationManager.ForceCoordinateSync();
  697. }
  698. else
  699. {
  700. Debug.LogError("❌ Exploration manager not available!");
  701. }
  702. }
  703. [ContextMenu("TEST: Simple Coordinate Conversion")]
  704. public void TestSimpleCoordinateConversion()
  705. {
  706. if (!useExplorationSystem || explorationManager == null)
  707. {
  708. Debug.LogError("❌ Exploration system not enabled or null!");
  709. return;
  710. }
  711. explorationManager.TestSimpleCoordinateConversion();
  712. }
  713. [ContextMenu("TEST: Positioning After Fix")]
  714. public void TestPositioningAfterFix()
  715. {
  716. if (!useExplorationSystem || explorationManager == null)
  717. {
  718. Debug.LogError("❌ Exploration system not enabled or null!");
  719. return;
  720. }
  721. explorationManager.TestPositioningAfterFix();
  722. }
  723. [ContextMenu("TEST: Full Map Tile Coverage")]
  724. public void TestFullMapTileCoverage()
  725. {
  726. if (!useExplorationSystem || explorationManager == null)
  727. {
  728. Debug.LogError("❌ Exploration system not enabled or null!");
  729. return;
  730. }
  731. explorationManager.TestFullMapTileCoverage();
  732. }
  733. [ContextMenu("TEST: Visual Tile Rendering")]
  734. public void TestVisualTileRendering()
  735. {
  736. if (!useExplorationSystem || explorationManager == null)
  737. {
  738. Debug.LogError("❌ Exploration system not enabled or null!");
  739. return;
  740. }
  741. explorationManager.TestVisualTileRendering();
  742. }
  743. [ContextMenu("TEST: Detailed Coordinate Conversion")]
  744. public void TestDetailedCoordinateConversion()
  745. {
  746. if (!useExplorationSystem || explorationManager == null)
  747. {
  748. Debug.LogError("❌ Exploration system not enabled or null!");
  749. return;
  750. }
  751. explorationManager.TestCoordinateConversion();
  752. }
  753. /// <summary>
  754. /// Public method to synchronize team position - can be called by travel system
  755. /// </summary>
  756. public void SyncTeamPosition()
  757. {
  758. if (useExplorationSystem && explorationManager != null)
  759. {
  760. explorationManager.SynchronizeTeamMarkerPosition();
  761. }
  762. }
  763. // Expose map size properties for ExplorationManager
  764. public int mapWidth
  765. {
  766. get => mapData?.Width ?? initialMapSize;
  767. set { /* Can be used by exploration system */ }
  768. }
  769. public int mapHeight
  770. {
  771. get => mapData?.Height ?? initialMapSize;
  772. set { /* Can be used by exploration system */ }
  773. }
  774. }